瀏覽代碼

[display] support `legacyCompletion = true` in server/configure

Simon Krajewski 6 年之前
父節點
當前提交
c70bbf9e81

+ 16 - 14
src/compiler/main.ml

@@ -1163,20 +1163,22 @@ with
 				error ctx msg p;
 				error ctx msg p;
 				None
 				None
 		in
 		in
-		begin match fields with
-		| None -> ()
-		| Some fields ->
-			begin match ctx.com.json_out with
-			| Some api ->
-				let ctx = DisplayJson.create_json_context api.jsonrpc false in
-				let path = match List.rev p with
-					| name :: pack -> List.rev pack,name
-					| [] -> [],""
-				in
-				let kind = CRField ((CompletionItem.make_ci_module path,pos,None,None)) in
-				api.send_result (DisplayException.fields_to_json ctx fields kind (DisplayTypes.make_subject None pos));
-			| _ -> raise (DisplayOutput.Completion (DisplayOutput.print_fields fields))
-			end
+		begin match ctx.com.json_out,fields with
+		| None,None ->
+			()
+		| None,Some fields ->
+			raise (DisplayOutput.Completion (DisplayOutput.print_fields fields))
+		| Some api,None when is_legacy_completion com ->
+			api.send_result JNull
+		| Some api,fields ->
+			let fields = Option.default [] fields in
+			let ctx = DisplayJson.create_json_context api.jsonrpc false in
+			let path = match List.rev p with
+				| name :: pack -> List.rev pack,name
+				| [] -> [],""
+			in
+			let kind = CRField ((CompletionItem.make_ci_module path,pos,None,None)) in
+			api.send_result (DisplayException.fields_to_json ctx fields kind (DisplayTypes.make_subject None pos));
 		end
 		end
 	| Parser.SyntaxCompletion(kind,subj) ->
 	| Parser.SyntaxCompletion(kind,subj) ->
 		DisplayOutput.handle_syntax_completion com kind subj;
 		DisplayOutput.handle_syntax_completion com kind subj;

+ 2 - 1
src/compiler/serverConfig.ml

@@ -1 +1,2 @@
-let do_not_check_modules = ref false
+let do_not_check_modules = ref false
+let legacy_completion = ref false

+ 4 - 0
src/context/common.ml

@@ -860,3 +860,7 @@ let adapt_defines_to_macro_context defines =
 	values := PMap.foldi (fun k v acc -> if List.mem k to_remove then acc else PMap.add k v acc) !values PMap.empty;
 	values := PMap.foldi (fun k v acc -> if List.mem k to_remove then acc else PMap.add k v acc) !values PMap.empty;
 	values := PMap.add "macro" "1" !values;
 	values := PMap.add "macro" "1" !values;
 	{values = !values; defines_signature = None }
 	{values = !values; defines_signature = None }
+
+let is_legacy_completion com = match com.json_out with
+	| None -> true
+	| Some api -> !ServerConfig.legacy_completion

+ 6 - 0
src/context/display/displayJson.ml

@@ -230,6 +230,12 @@ let handler =
 				l := jstring ("Module checks " ^ (if b then "disabled" else "enabled")) :: !l;
 				l := jstring ("Module checks " ^ (if b then "disabled" else "enabled")) :: !l;
 				()
 				()
 			) ();
 			) ();
+			hctx.jsonrpc#get_opt_param (fun () ->
+				let b = hctx.jsonrpc#get_bool_param "legacyCompletion" in
+				ServerConfig.legacy_completion := b;
+				l := jstring ("Legacy completion " ^ (if b then "enabled" else "disabled")) :: !l;
+				()
+			) ();
 			hctx.send_result (jarray !l)
 			hctx.send_result (jarray !l)
 		);
 		);
 		"server/memory",(fun hctx ->
 		"server/memory",(fun hctx ->

+ 1 - 1
src/typing/typer.ml

@@ -1365,7 +1365,7 @@ and handle_efield ctx e p mode =
 									let sl = List.map (fun (n,_,_) -> n) (List.rev acc) in
 									let sl = List.map (fun (n,_,_) -> n) (List.rev acc) in
 									(* if there was no module name part, last guess is that we're trying to get package completion *)
 									(* if there was no module name part, last guess is that we're trying to get package completion *)
 									if ctx.in_display then begin
 									if ctx.in_display then begin
-										if ctx.com.json_out = None then raise (Parser.TypePath (sl,None,false,p))
+										if is_legacy_completion ctx.com then raise (Parser.TypePath (sl,None,false,p))
 										else DisplayToplevel.collect_and_raise ctx TKType WithType.no_value (CRToplevel None) (String.concat "." sl,p0) p0
 										else DisplayToplevel.collect_and_raise ctx TKType WithType.no_value (CRToplevel None) (String.concat "." sl,p0) p0
 									end;
 									end;
 									raise e)
 									raise e)

+ 2 - 2
src/typing/typerDisplay.ml

@@ -517,10 +517,10 @@ let handle_display ?resume_typing ctx e_ast dk with_type =
 		| None -> type_expr ctx e_ast with_type
 		| None -> type_expr ctx e_ast with_type
 		| Some fn -> fn ctx e_ast with_type
 		| Some fn -> fn ctx e_ast with_type
 	with Error (Unknown_ident n,_) when ctx.com.display.dms_kind = DMDefault ->
 	with Error (Unknown_ident n,_) when ctx.com.display.dms_kind = DMDefault ->
-        if dk = DKDot && ctx.com.json_out = None then raise (Parser.TypePath ([n],None,false,p))
+        if dk = DKDot && is_legacy_completion ctx.com then raise (Parser.TypePath ([n],None,false,p))
 		else raise_toplevel ctx dk with_type (n,p)
 		else raise_toplevel ctx dk with_type (n,p)
 	| Error ((Type_not_found (path,_) | Module_not_found path),_) as err when ctx.com.display.dms_kind = DMDefault ->
 	| 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
+		if is_legacy_completion ctx.com then begin try
 			raise_fields (DisplayFields.get_submodule_fields ctx path) (CRField((make_ci_module path),p,None,None)) (make_subject None (pos e_ast))
 			raise_fields (DisplayFields.get_submodule_fields ctx path) (CRField((make_ci_module path),p,None,None)) (make_subject None (pos e_ast))
 		with Not_found ->
 		with Not_found ->
 			raise err
 			raise err

+ 1 - 0
std/haxe/display/Server.hx

@@ -72,6 +72,7 @@ typedef ConfigurePrintParams = {
 
 
 typedef ConfigureParams = {
 typedef ConfigureParams = {
 	final ?noModuleChecks:Bool;
 	final ?noModuleChecks:Bool;
+	final ?legacyCompletion:Bool;
 	final ?print:ConfigurePrintParams;
 	final ?print:ConfigurePrintParams;
 }
 }