瀏覽代碼

[display] return empty results instead of a "no completion point found" error

see vshaxe/vshaxe#358
Jens Fischer 6 年之前
父節點
當前提交
a9f03ed770
共有 5 個文件被更改,包括 28 次插入17 次删除
  1. 8 3
      src/compiler/main.ml
  2. 15 9
      src/context/display/displayException.ml
  3. 2 2
      src/typing/typeload.ml
  4. 1 1
      src/typing/typeloadCheck.ml
  5. 2 2
      src/typing/typerDisplay.ml

+ 8 - 3
src/compiler/main.ml

@@ -934,7 +934,12 @@ try
 			if ctx.has_next || ctx.has_error then raise Abort;
 			(* If we didn't find a completion point, load the display file in macro mode. *)
 			ignore(load_display_module_in_macro true);
-			failwith "No completion point was found";
+			match ctx.com.display.dms_kind with
+			| DMDefault -> 
+			| DMSignature -> raise (DisplayException(DisplaySignatures None)) 
+			| DMHover -> raise (DisplayException(DisplayHover None))
+			| DMDefinition | DMTypeDefinition -> raise_positions []
+			| _ -> failwith "No completion point was found";
 		end;
 		let t = Timer.timer ["filters"] in
 		let main, types, modules = run_or_diagnose Finalization.generate tctx in
@@ -1064,11 +1069,11 @@ with
 				DisplayOutput.print_fields fields
 		in
 		raise (DisplayOutput.Completion s)
-	| DisplayException(DisplayHover ({hitem = {CompletionItem.ci_type = Some (t,_)}} as hover)) ->
+	| DisplayException(DisplayHover Some ({hitem = {CompletionItem.ci_type = Some (t,_)}} as hover)) ->
 		DisplayPosition.display_position#reset;
 		let doc = CompletionItem.get_documentation hover.hitem in
 		raise (DisplayOutput.Completion (DisplayOutput.print_type t hover.hpos doc))
-	| DisplayException(DisplaySignatures(signatures,_,display_arg,_)) ->
+	| DisplayException(DisplaySignatures Some (signatures,_,display_arg,_)) ->
 		DisplayPosition.display_position#reset;
 		if ctx.com.display.dms_kind = DMSignature then
 			raise (DisplayOutput.Completion (DisplayOutput.print_signature signatures display_arg))

+ 15 - 9
src/context/display/displayException.ml

@@ -20,10 +20,10 @@ type kind =
 	| Statistics of string
 	| ModuleSymbols of string
 	| Metadata of string
-	| DisplaySignatures of ((tsignature * CompletionType.ct_function) * documentation) list * int * int * signature_kind
-	| DisplayHover of hover_result
+	| DisplaySignatures of (((tsignature * CompletionType.ct_function) * documentation) list * int * int * signature_kind) option
+	| DisplayHover of hover_result option
 	| DisplayPositions of pos list
-	| DisplayFields of CompletionItem.t list * CompletionResultKind.t * pos option (* insert pos *)
+	| DisplayFields of (CompletionItem.t list * CompletionResultKind.t * pos option (* insert pos *)) option
 	| DisplayPackage of string list
 
 exception DisplayException of kind
@@ -32,10 +32,10 @@ let raise_diagnostics s = raise (DisplayException(Diagnostics s))
 let raise_statistics s = raise (DisplayException(Statistics s))
 let raise_module_symbols s = raise (DisplayException(ModuleSymbols s))
 let raise_metadata s = raise (DisplayException(Metadata s))
-let raise_signatures l isig iarg kind = raise (DisplayException(DisplaySignatures(l,isig,iarg,kind)))
-let raise_hover item expected p = raise (DisplayException(DisplayHover({hitem = item;hpos = p;hexpected = expected})))
+let raise_signatures l isig iarg kind = raise (DisplayException(DisplaySignatures(Some(l,isig,iarg,kind))))
+let raise_hover item expected p = raise (DisplayException(DisplayHover(Some {hitem = item;hpos = p;hexpected = expected})))
 let raise_positions pl = raise (DisplayException(DisplayPositions pl))
-let raise_fields ckl cr po = raise (DisplayException(DisplayFields(ckl,cr,po)))
+let raise_fields ckl cr po = raise (DisplayException(DisplayFields(Some(ckl,cr,po))))
 let raise_package sl = raise (DisplayException(DisplayPackage sl))
 
 (* global state *)
@@ -56,7 +56,9 @@ let to_json ctx de =
 	| Statistics _
 	| ModuleSymbols _
 	| Metadata _ -> assert false
-	| DisplaySignatures(sigs,isig,iarg,kind) ->
+	| DisplaySignatures None ->
+		jnull
+	| DisplaySignatures Some(sigs,isig,iarg,kind) ->
 		(* We always want full info for signatures *)
 		let ctx = Genjson.create_context GMFull in
 		let fsig ((_,signature),doc) =
@@ -74,7 +76,9 @@ let to_json ctx de =
 			"signatures",jlist fsig sigs;
 			"kind",jint sigkind;
 		]
-	| DisplayHover hover ->
+	| DisplayHover None ->
+		jnull
+	| DisplayHover (Some hover) ->
 		let name_source_kind_to_int = function
 			| WithType.FunctionArgument -> 0
 			| WithType.StructureField -> 1
@@ -99,7 +103,9 @@ let to_json ctx de =
 		]
 	| DisplayPositions pl ->
 		jarray (List.map generate_pos_as_location pl)
-	| DisplayFields(fields,kind,po) ->
+	| DisplayFields None ->
+		jnull
+	| DisplayFields Some(fields,kind,po) ->
 		fields_to_json ctx fields kind po
 	| DisplayPackage pack ->
 		jarray (List.map jstring pack)

+ 2 - 2
src/typing/typeload.ml

@@ -370,7 +370,7 @@ and load_complex_type' ctx allow_display (t,p) =
 		let tl = List.map (fun (t,pn) ->
 			try
 				load_complex_type ctx allow_display (t,pn)
-			with DisplayException(DisplayFields(l,CRTypeHint,p)) ->
+			with DisplayException(DisplayFields Some(l,CRTypeHint,p)) ->
 				let l = List.filter (fun item -> match item.ci_kind with
 					| ITType({kind = Struct},_) -> true
 					| _ -> false
@@ -412,7 +412,7 @@ and load_complex_type' ctx allow_display (t,p) =
 			let il = List.map (fun (t,pn) ->
 				try
 					load_instance ctx ~allow_display (t,pn) false
-				with DisplayException(DisplayFields(l,CRTypeHint,p)) ->
+				with DisplayException(DisplayFields Some(l,CRTypeHint,p)) ->
 					let l = List.filter (fun item -> match item.ci_kind with
 						| ITType({kind = Struct},_) -> true
 						| _ -> false

+ 1 - 1
src/typing/typeloadCheck.ml

@@ -471,7 +471,7 @@ module Inheritance = struct
 			try
 				let t = try
 					Typeload.load_instance ~allow_display:true ctx (ct,p) false
-				with DisplayException(DisplayFields(l,CRTypeHint,p)) ->
+				with DisplayException(DisplayFields Some(l,CRTypeHint,p)) ->
 					(* We don't allow `implements` on interfaces. Just raise fields completion with no fields. *)
 					if not is_extends && c.cl_interface then raise_fields [] CRImplements p;
 					let l = List.filter (fun item -> match item.ci_kind with

+ 2 - 2
src/typing/typerDisplay.ml

@@ -493,7 +493,7 @@ let handle_display ctx e_ast dk with_type =
 			raise err
 		end else
 			raise_toplevel ctx dk with_type (Some p) p
-	| DisplayException(DisplayFields(l,CRTypeHint,p)) when (match fst e_ast with ENew _ -> true | _ -> false) ->
+	| DisplayException(DisplayFields Some(l,CRTypeHint,p)) when (match fst e_ast with ENew _ -> true | _ -> false) ->
 		let timer = Timer.timer ["display";"toplevel";"filter ctors"] in
 		ctx.pass <- PBuildClass;
 		let l = List.filter (fun item ->
@@ -587,7 +587,7 @@ let handle_edisplay ctx e dk with_type =
 	| DKPattern outermost,DMDefault ->
 		begin try
 			handle_display ctx e dk with_type
-		with DisplayException(DisplayFields(l,CRToplevel _,p)) ->
+		with DisplayException(DisplayFields Some(l,CRToplevel _,p)) ->
 			raise_fields l (CRPattern ((get_expected_type ctx with_type),outermost)) p
 		end
 	| _ -> handle_display ctx e dk with_type