Browse Source

[display] bring back import suggestions

We can probably do this much better now though.
Simon Krajewski 7 years ago
parent
commit
4e3e8822e7
3 changed files with 26 additions and 26 deletions
  1. 1 1
      src/context/common.ml
  2. 22 23
      src/context/display/diagnostics.ml
  3. 3 2
      src/context/display/displayToplevel.ml

+ 1 - 1
src/context/common.ml

@@ -109,7 +109,7 @@ type shared_display_information = {
 }
 
 type display_information = {
-	mutable unresolved_identifiers : (string * pos * (string * CompletionItem.t) list) list;
+	mutable unresolved_identifiers : (string * pos * (string * CompletionItem.t * int) list) list;
 	mutable interface_field_implementations : (tclass * tclass_field * tclass * tclass_field option) list;
 }
 

+ 22 - 23
src/context/display/diagnostics.ml

@@ -139,7 +139,6 @@ let is_diagnostics_run p = match (!Parser.display_mode) with
 let secure_generated_code ctx e =
 	if is_diagnostics_run e.epos then mk (TMeta((Meta.Extern,[],e.epos),e)) e.etype e.epos else e
 
-
 module Printer = struct
 	open Json
 	open DiagnosticsKind
@@ -157,6 +156,10 @@ module Printer = struct
 			| UISTypo -> 1
 	end
 
+	open UnresolvedIdentifierSuggestion
+	open CompletionItem
+	open CompletionModuleType
+
 	let print_diagnostics dctx ctx global =
 		let com = dctx.com in
 		let diag = Hashtbl.create 0 in
@@ -174,29 +177,25 @@ module Printer = struct
 		let add dk p sev args =
 			if global || is_display_file p.pfile then add dk p sev args
 		in
-		let find_type i =
-			let types = ref [] in
-			Hashtbl.iter (fun _ m ->
-				List.iter (fun mt ->
-					let s_full_type_path (p,s) n = s_type_path (p,s) ^ if (s <> n) then "." ^ n else "" in
-					let tinfos = t_infos mt in
-					if snd tinfos.mt_path = i then
-						types := JObject [
-							"kind",JInt (UnresolvedIdentifierSuggestion.to_int UnresolvedIdentifierSuggestion.UISImport);
-							"name",JString (s_full_type_path m.m_path i)
-						] :: !types
-				) m.m_types;
-			) ctx.g.modules;
-			!types
-		in
 		List.iter (fun (s,p,suggestions) ->
-			let suggestions = List.map (fun (s,_) ->
-				JObject [
-					"kind",JInt (UnresolvedIdentifierSuggestion.to_int UnresolvedIdentifierSuggestion.UISTypo);
-					"name",JString s
-				]
+			let suggestions = ExtList.List.filter_map (fun (s,it,r) ->
+				print_endline (Printf.sprintf "%s: %i" s r);
+				match it with
+				| ITType(t,_) when r = 0 ->
+					Some (JObject [
+						"kind",JInt (to_int UISImport);
+						"name",JString (s_type_path (t.pack,t.module_name));
+					])
+				| _ when r = 0 ->
+					(* TODO !!! *)
+					None
+				| _ ->
+					Some (JObject [
+						"kind",JInt (to_int UISTypo);
+						"name",JString s;
+					])
 			) suggestions in
-			add DKUnresolvedIdentifier p DiagnosticsSeverity.Error (JArray (suggestions @ (find_type s)));
+			add DKUnresolvedIdentifier p DiagnosticsSeverity.Error (JArray suggestions);
 		) com.display_information.unresolved_identifiers;
 		PMap.iter (fun p (r,_) ->
 			if not !r then add DKUnusedImport p DiagnosticsSeverity.Warning (JArray [])
@@ -210,7 +209,7 @@ module Printer = struct
 		let jl = Hashtbl.fold (fun file diag acc ->
 			let jl = DynArray.fold_left (fun acc (dk,p,sev,jargs) ->
 				(JObject [
-					"kind",JInt (to_int dk);
+					"kind",JInt (DiagnosticsKind.to_int dk);
 					"severity",JInt (DiagnosticsSeverity.to_int sev);
 					"range",Genjson.generate_pos_as_range p;
 					"args",jargs

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

@@ -343,8 +343,9 @@ let handle_unresolved_identifier ctx i p only_types =
 	let l = collect ctx only_types NoValue in
 	let cl = List.map (fun it ->
 		let s = CompletionItem.get_name it in
-		(s,it),StringError.levenshtein i s
+		let i = StringError.levenshtein i s in
+		(s,it,i),i
 	) l in
 	let cl = List.sort (fun (_,c1) (_,c2) -> compare c1 c2) cl in
-	let cl = StringError.filter_similar (fun (s,_) r -> r > 0 && r <= (min (String.length s) (String.length i)) / 3) cl in
+	let cl = StringError.filter_similar (fun (s,_,_) r -> r <= (min (String.length s) (String.length i)) / 3) cl in
 	ctx.com.display_information.unresolved_identifiers <- (i,p,cl) :: ctx.com.display_information.unresolved_identifiers