浏览代码

[display] use JsonPath for completion modules

Simon Krajewski 7 年之前
父节点
当前提交
c1a3842c06

+ 1 - 1
src/compiler/displayOutput.ml

@@ -376,7 +376,7 @@ module TypePathHandler = struct
 			(abort ("No classes found in " ^ String.concat "." p) null_pos)
 		else
 			let packs = List.map (fun n -> make_ci_package (p,n) []) packs in
-			let modules = List.map (fun n -> make_ci_module n) modules in
+			let modules = List.map (fun n -> make_ci_module (p,n)) modules in
 			Some (packs @ modules)
 
 	(** raise field completion listing module sub-types and static fields *)

+ 5 - 1
src/compiler/main.ml

@@ -1032,7 +1032,11 @@ with
 			| Some (f,_) ->
 				let ctx = DisplayJson.create_json_context false in
 				let pos = Parser.cut_pos_at_display pos in
-				let kind = CRField ((CompletionItem.make_ci_module (String.concat "." p),pos)) in
+				let path = match List.rev p with
+					| name :: pack -> List.rev pack,name
+					| [] -> [],""
+				in
+				let kind = CRField ((CompletionItem.make_ci_module path,pos)) in
 				f (DisplayException.fields_to_json ctx fields kind None);
 			| _ -> raise (DisplayOutput.Completion (DisplayOutput.print_fields fields))
 			end

+ 1 - 1
src/context/display/displayException.ml

@@ -34,7 +34,7 @@ let raise_fields ckl cr po = raise (DisplayException(DisplayFields(ckl,cr,po)))
 let raise_package sl = raise (DisplayException(DisplayPackage sl))
 
 (* global state *)
-let last_completion_result = ref (Array.make 0 (CompletionItem.make (ITModule "") None))
+let last_completion_result = ref (Array.make 0 (CompletionItem.make (ITModule ([],"")) None))
 
 let fields_to_json ctx fields kind po =
 	let ja = List.map (CompletionItem.to_json ctx) fields in

+ 9 - 7
src/core/display/completionItem.ml

@@ -272,7 +272,7 @@ type t_kind =
 	| ITEnumAbstractField of tabstract * CompletionClassField.t
 	| ITType of CompletionModuleType.t * ImportStatus.t
 	| ITPackage of path * (string * PackageContentKind.t) list
-	| ITModule of string
+	| ITModule of path
 	| ITLiteral of string
 	| ITTimer of string * string
 	| ITMetadata of string * documentation
@@ -297,7 +297,7 @@ let make_ci_enum_abstract_field a ccf t = make (ITEnumAbstractField(a,ccf)) (Som
 let make_ci_enum_field cef t = make (ITEnumField cef) (Some t)
 let make_ci_type mt import_status t = make (ITType(mt,import_status)) t
 let make_ci_package path l = make (ITPackage(path,l)) None
-let make_ci_module s = make (ITModule s) None
+let make_ci_module path = make (ITModule path) None
 let make_ci_literal lit t = make (ITLiteral lit) (Some t)
 let make_ci_timer name value = make (ITTimer(name,value)) None
 let make_ci_metadata s doc = make (ITMetadata(s,doc)) None
@@ -354,8 +354,8 @@ let get_sort_index item p = match item.ci_kind with
 		i,(s_type_path (cmt.pack,cmt.name))
 	| ITPackage(path,_) ->
 		40,s_type_path path
-	| ITModule name ->
-		40,name
+	| ITModule path ->
+		40,s_type_path path
 	| ITLiteral name ->
 		50,name
 	| ITKeyword name ->
@@ -379,7 +379,7 @@ let legacy_sort item = match item.ci_kind with
 		| _ -> 0,ef.ef_name
 		end
 	| ITType(cm,_) -> 2,cm.name
-	| ITModule s -> 3,s
+	| ITModule path -> 3,snd path
 	| ITPackage(path,_) -> 4,snd path
 	| ITMetadata(s,_) -> 5,s
 	| ITTimer(s,_) -> 6,s
@@ -396,7 +396,7 @@ let get_name item = match item.ci_kind with
 	| ITEnumField ef -> ef.efield.ef_name
 	| ITType(cm,_) -> cm.name
 	| ITPackage(path,_) -> snd path
-	| ITModule s -> s
+	| ITModule path -> snd path
 	| ITLiteral s -> s
 	| ITTimer(s,_) -> s
 	| ITMetadata(s,_) -> s
@@ -467,7 +467,9 @@ let to_json ctx item =
 				"path",generate_path path;
 				"contents",jlist generate_package_content contents;
 			]
-		| ITModule s -> "Module",jstring s
+		| ITModule path -> "Module",jobject [
+			"path",generate_path path;
+		]
 		| ITLiteral s -> "Literal",jobject [
 			"name",jstring s;
 			"type",jopt (generate_type ctx) item.ci_type; (* TODO: remove *)

+ 1 - 2
src/typing/typerDisplay.ml

@@ -367,8 +367,7 @@ let handle_display ctx e_ast dk with_type =
 		else raise_toplevel ctx with_type (Some (Parser.cut_pos_at_display p)) p
 	| Error ((Type_not_found (path,_) | Module_not_found path),_) as err when ctx.com.display.dms_kind = DMDefault ->
 		if ctx.com.json_out = None then	begin try
-			let s = s_type_path path in
-			raise_fields (DisplayFields.get_submodule_fields ctx path) (CRField((make_ci_module s),p)) None
+			raise_fields (DisplayFields.get_submodule_fields ctx path) (CRField((make_ci_module path),p)) None
 		with Not_found ->
 			raise err
 		end else