浏览代码

[display] run TypecoreParser.parse_module without display_position (fixes #8110)

Alexander Kuzmenko 6 年之前
父节点
当前提交
73d5d0eb61

+ 11 - 0
src/context/display/display.ml

@@ -2,6 +2,7 @@ open Ast
 open Common
 open DisplayTypes
 open DisplayMode
+open DisplayPosition
 open CompletionItem
 open CompletionResultKind
 open Type
@@ -10,6 +11,16 @@ open Globals
 open Genjson
 open DisplayPosition
 
+
+let merge_core_doc ctx mtype =
+	display_position#run_outside (fun () -> Typecore.merge_core_doc ctx mtype)
+
+let parse_module' com m p =
+	display_position#run_outside (fun () -> TypeloadParse.parse_module' com m p)
+
+let parse_module ctx m p =
+	display_position#run_outside (fun () -> TypeloadParse.parse_module ctx m p)
+
 module ReferencePosition = struct
 	let reference_position = ref ("",null_pos,KVar)
 	let set (s,p,k) = reference_position := (s,{p with pfile = Path.unique_full_path p.pfile},k)

+ 4 - 4
src/context/display/displayFields.ml

@@ -127,7 +127,7 @@ let collect ctx e_ast e dk with_type p =
 		| TInst(c0,tl) ->
 			(* For classes, browse the hierarchy *)
 			let fields = TClass.get_all_fields c0 tl in
-			merge_core_doc ctx (TClassDecl c0);
+			Display.merge_core_doc ctx (TClassDecl c0);
 			PMap.foldi (fun k (c,cf) acc ->
 				if should_access c cf false && is_new_item acc cf.cf_name then begin
 					let origin = if c == c0 then Self(TClassDecl c) else Parent(TClassDecl c) in
@@ -151,7 +151,7 @@ let collect ctx e_ast e dk with_type p =
 				items
 			end;
 		| TAbstract({a_impl = Some c} as a,tl) ->
-			merge_core_doc ctx (TAbstractDecl a);
+			Display.merge_core_doc ctx (TAbstractDecl a);
 			(* Abstracts should show all their @:impl fields minus the constructor. *)
 			let items = List.fold_left (fun acc cf ->
 				if Meta.has Meta.Impl cf.cf_meta && not (Meta.has Meta.Enum cf.cf_meta) && should_access c cf false && is_new_item acc cf.cf_name then begin
@@ -204,13 +204,13 @@ let collect ctx e_ast e dk with_type p =
 							else
 								acc;
 						| Statics c ->
-							merge_core_doc ctx (TClassDecl c);
+							Display.merge_core_doc ctx (TClassDecl c);
 							if should_access c cf true then add (Self (TClassDecl c)) make_ci_class_field else acc;
 						| EnumStatics en ->
 							let ef = PMap.find name en.e_constrs in
 							PMap.add name (make_ci_enum_field (CompletionEnumField.make ef (Self (TEnumDecl en)) true) (cf.cf_type,ct)) acc
 						| AbstractStatics a ->
-							merge_core_doc ctx (TAbstractDecl a);
+							Display.merge_core_doc ctx (TAbstractDecl a);
 							let check = match a.a_impl with
 								| None -> true
 								| Some c -> allow_static_abstract_access c cf

+ 3 - 3
src/context/display/displayToplevel.ml

@@ -75,7 +75,7 @@ let explore_class_paths com timer class_paths recusive f_pack f_module =
 let read_class_paths com timer =
 	let sign = Define.get_signature com.defines in
 	explore_class_paths com timer (List.filter ((<>) "") com.class_path) true (fun _ -> ()) (fun path ->
-		let file,_,pack,_ = TypeloadParse.parse_module' com path Globals.null_pos in
+		let file,_,pack,_ = Display.parse_module' com path Globals.null_pos in
 		match CompilationServer.get() with
 		| Some cs when pack <> fst path ->
 			let file = Path.unique_full_path file in
@@ -156,7 +156,7 @@ let collect ctx tk with_type =
 			let mname = snd (t_infos mt).mt_module.m_path in
 			let path = if snd path = mname then path else (fst path @ [mname],snd path) in
 			if not (path_exists cctx path) then begin
-				merge_core_doc ctx mt;
+				Display.merge_core_doc ctx mt;
 				let is = get_import_status cctx true path in
 				if not (Meta.has Meta.NoCompletion (t_infos mt).mt_meta) then begin
 					add (make_ci_type (CompletionModuleType.of_module_type mt) is None) (Some (snd path));
@@ -352,7 +352,7 @@ let collect ctx tk with_type =
 		let class_paths = List.filter (fun s -> s <> "") class_paths in
 		explore_class_paths ctx.com ["display";"toplevel"] class_paths true add_package (fun path ->
 			if not (path_exists cctx path) then begin
-				let _,decls = TypeloadParse.parse_module ctx path Globals.null_pos in
+				let _,decls = Display.parse_module ctx path Globals.null_pos in
 				process_decls (fst path) (snd path) decls
 			end
 		)

+ 1 - 1
src/core/display/displayPosition.ml

@@ -49,7 +49,7 @@ class display_position_container =
 		(**
 			Temporarily reset display position, run `fn` and then restore display position.
 		*)
-		method run_outside (fn:unit->unit) =
+		method run_outside : 'a . (unit->'a) -> 'a = fun fn ->
 			let display_pos = self#get in
 			self#reset;
 			Std.finally (fun () -> self#set display_pos) fn ()

+ 5 - 8
src/typing/typerDisplay.ml

@@ -21,9 +21,6 @@ let convert_function_signature ctx values (args,ret) = match DisplayEmitter.comp
 	| CompletionType.CTFunction ctf -> ((args,ret),ctf)
 	| _ -> assert false
 
-let merge_core_doc ctx mtype =
-	DisplayPosition.display_position#run_outside (fun () -> Typecore.merge_core_doc ctx mtype)
-
 let completion_item_of_expr ctx e =
 	let retype e s t =
 		try
@@ -51,7 +48,7 @@ let completion_item_of_expr ctx e =
 	let rec loop e = match e.eexpr with
 		| TLocal v | TVar(v,_) -> make_ci_local v (tpair ~values:(get_value_meta v.v_meta) v.v_type)
 		| TField(e1,FStatic(c,cf)) ->
-			merge_core_doc ctx (TClassDecl c);
+			Display.merge_core_doc ctx (TClassDecl c);
 			let decl = decl_of_class c in
 			let origin = match c.cl_kind,e1.eexpr with
 				| KAbstractImpl _,_ when Meta.has Meta.Impl cf.cf_meta -> Self decl
@@ -64,7 +61,7 @@ let completion_item_of_expr ctx e =
 			in
 			of_field e origin cf CFSStatic make_ci
 		| TField(e1,(FInstance(c,_,cf) | FClosure(Some(c,_),cf))) ->
-			merge_core_doc ctx (TClassDecl c);
+			Display.merge_core_doc ctx (TClassDecl c);
 			let origin = match follow e1.etype with
 			| TInst(c',_) when c != c' ->
 				Parent (TClassDecl c)
@@ -84,12 +81,12 @@ let completion_item_of_expr ctx e =
 				| _ -> itexpr e
 			end
 		| TTypeExpr (TClassDecl {cl_kind = KAbstractImpl a}) ->
-			merge_core_doc ctx (TAbstractDecl a);
+			Display.merge_core_doc ctx (TAbstractDecl a);
 			let t = TType(abstract_module_type a (List.map snd a.a_params),[]) in
 			let t = tpair t in
 			make_ci_type (CompletionModuleType.of_module_type (TAbstractDecl a)) ImportStatus.Imported (Some t)
 		| TTypeExpr mt ->
-			merge_core_doc ctx mt;
+			Display.merge_core_doc ctx mt;
 			let t = tpair e.etype in
 			make_ci_type (CompletionModuleType.of_module_type mt) ImportStatus.Imported (Some t) (* TODO *)
 		| TConst (TThis | TSuper) -> itexpr e (* TODO *)
@@ -100,7 +97,7 @@ let completion_item_of_expr ctx e =
 				| _ -> itexpr e
 			end
 		| TNew(c,tl,_) ->
-			merge_core_doc ctx (TClassDecl c);
+			Display.merge_core_doc ctx (TClassDecl c);
 			(* begin match fst e_ast with
 			| EConst (Regexp (r,opt)) ->
 				let present,absent = List.partition (String.contains opt) ['g';'i';'m';'s';'u'] in