Browse Source

[display] patch filter string with subject + display pos

Simon Krajewski 6 years ago
parent
commit
b45c0c4008
2 changed files with 24 additions and 2 deletions
  1. 16 2
      src/context/display/displayException.ml
  2. 8 0
      tests/server/src/DisplayTests.hx

+ 16 - 2
src/context/display/displayException.ml

@@ -97,9 +97,24 @@ let filter_somehow ctx items kind subj =
 	) acc_types;
 	DynArray.to_list ret,DynArray.length ret
 
+let patch_completion_subject subj =
+	let p = Parser.cut_pos_at_display subj.s_insert_pos in
+	match subj.s_name with
+	| Some name ->
+		let delta = p.pmax - p.pmin in
+		let name = if delta > 0 && delta < String.length name then
+			String.sub name 0 delta
+		else
+			name
+		in
+		{subj with s_name = Some name;s_insert_pos = p}
+	| None ->
+		{subj with s_insert_pos = p}
+
 let fields_to_json ctx fields kind subj =
 	last_completion_result := Array.of_list fields;
 	let needs_filtering = !max_completion_items > 0 && Array.length !last_completion_result > !max_completion_items in
+	let subj = patch_completion_subject subj in
 	let ja,num_items = if needs_filtering then
 		filter_somehow ctx fields kind subj
 	else
@@ -108,7 +123,6 @@ let fields_to_json ctx fields kind subj =
 	let did_filter = num_items = !max_completion_items in
 	if did_filter then last_completion_pos := Some subj.s_start_pos;
 	let filter_string = (match subj.s_name with None -> "" | Some name -> name) in
-	let p = Parser.cut_pos_at_display subj.s_insert_pos in
 	(* print_endline (Printf.sprintf "FIELDS OUTPUT:\n\tfilter_string: %s\n\t    num items: %i\n\t     position: %s\n\t   before cut: %s"
 		filter_string
 		num_items
@@ -120,7 +134,7 @@ let fields_to_json ctx fields kind subj =
 		("isIncomplete",jbool did_filter) ::
 		("mode",CompletionResultKind.to_json ctx kind) ::
 		("filterString",jstring filter_string) ::
-		("replaceRange",generate_pos_as_range p) ::
+		("replaceRange",generate_pos_as_range subj.s_insert_pos) ::
 		[]
 	in
 	jobject fl

+ 8 - 0
tests/server/src/DisplayTests.hx

@@ -405,6 +405,14 @@ typedef Foo = {
 		complete("class Main { static function main() { var t:{-1-}Cl{-2-} }}", 2);
 		checkReplaceRange(markers, 1, 2, response);
 		equals("Cl", response.filterString);
+
+		complete("class Main { static function main() { var t:{-1-}String{-2-} }}", 2);
+		checkReplaceRange(markers, 1, 2, response);
+		equals("String", response.filterString);
+
+		complete("class Main { static function main() { var t:{-1-}Str{-2-}ing }}", 2);
+		checkReplaceRange(markers, 1, 2, response);
+		equals("Str", response.filterString);
 	}
 
 	function testIssue8669_typeParameter() {