浏览代码

[display] exclude filters for toplevel completion (#8156)

* [display] exclude filters for toplevel completion

* some cleanup
Jens Fischer 6 年之前
父节点
当前提交
55cf01843c
共有 2 个文件被更改,包括 50 次插入34 次删除
  1. 2 0
      src/context/display/displayJson.ml
  2. 48 34
      src/context/display/displayToplevel.ml

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

@@ -87,6 +87,8 @@ let handler =
 	let l = [
 		"initialize", (fun hctx ->
 			supports_resolve := hctx.jsonrpc#get_opt_param (fun () -> hctx.jsonrpc#get_bool_param "supportsResolve") false;
+			let exclude = hctx.jsonrpc#get_opt_param (fun () -> hctx.jsonrpc#get_array_param "exclude") [] in
+			DisplayToplevel.exclude := List.map (fun e -> match e with JString s -> s | _ -> assert false) exclude;
 			let methods = Hashtbl.fold (fun k _ acc -> (jstring k) :: acc) h [] in
 			hctx.send_result (JObject [
 				"methods",jarray methods;

+ 48 - 34
src/context/display/displayToplevel.ml

@@ -26,38 +26,47 @@ open ClassFieldOrigin
 open DisplayTypes
 open DisplayEmitter
 open Genjson
+open Globals
+
+let exclude : string list ref = ref []
 
 let explore_class_paths com timer class_paths recusive f_pack f_module =
 	let rec loop dir pack =
-		try
-			let entries = Sys.readdir dir in
-			Array.iter (fun file ->
-				match file with
-					| "." | ".." ->
-						()
-					| _ when Sys.is_directory (dir ^ file) && file.[0] >= 'a' && file.[0] <= 'z' ->
-						begin try
-							begin match PMap.find file com.package_rules with
-								| Forbidden | Remap _ -> ()
-								| _ -> raise Not_found
+		let dot_path = (String.concat "." (List.rev pack)) in
+		begin
+			if (List.mem dot_path !exclude) then
+				()
+			else try
+				let entries = Sys.readdir dir in
+				Array.iter (fun file ->
+					match file with
+						| "." | ".." ->
+							()
+						| _ when Sys.is_directory (dir ^ file) && file.[0] >= 'a' && file.[0] <= 'z' ->
+							begin try
+								begin match PMap.find file com.package_rules with
+									| Forbidden | Remap _ -> ()
+									| _ -> raise Not_found
+								end
+							with Not_found ->
+								f_pack (List.rev pack,file);
+								if recusive then loop (dir ^ file ^ "/") (file :: pack)
 							end
-						with Not_found ->
-							f_pack (List.rev pack,file);
-							if recusive then loop (dir ^ file ^ "/") (file :: pack)
-						end
-					| _ ->
-						let l = String.length file in
-						if l > 3 && String.sub file (l - 3) 3 = ".hx" then begin
-							try
-								let name = String.sub file 0 (l - 3) in
-								let path = (List.rev pack,name) in
-								f_module path;
-							with _ ->
-								()
-						end
-			) entries;
-		with Sys_error _ ->
-			()
+						| _ ->
+							let l = String.length file in
+							if l > 3 && String.sub file (l - 3) 3 = ".hx" then begin
+								try
+									let name = String.sub file 0 (l - 3) in
+									let path = (List.rev pack,name) in
+									let dot_path = if dot_path = "" then name else dot_path ^ "." ^ name in
+									if (List.mem dot_path !exclude) then () else f_module path;
+								with _ ->
+									()
+							end
+				) entries;
+			with Sys_error _ ->
+				()
+		end
 	in
 	let t = Timer.timer (timer @ ["class path exploration"]) in
 	List.iter (fun dir -> loop dir []) class_paths;
@@ -362,12 +371,17 @@ let collect ctx tk with_type =
 		let files = List.sort (fun (_,i1) (_,i2) -> -compare i1 i2) files in
 		List.iter (fun ((file,cfile),_) ->
 			let module_name = CompilationServer.get_module_name_of_cfile file cfile in
-			begin match List.rev cfile.c_package with
-				| [] -> ()
-				| s :: sl -> add_package (List.rev sl,s)
-			end;
-			Hashtbl.replace ctx.com.module_to_file (cfile.c_package,module_name) file;
-			process_decls cfile.c_package module_name cfile.c_decls
+			let dot_path = s_type_path (cfile.c_package,module_name) in
+			if (List.exists (fun e -> ExtString.String.starts_with dot_path (e ^ ".")) !exclude) then
+				()
+			else begin
+				begin match List.rev cfile.c_package with
+					| [] -> ()
+					| s :: sl -> add_package (List.rev sl,s)
+				end;
+				Hashtbl.replace ctx.com.module_to_file (cfile.c_package,module_name) file;
+				process_decls cfile.c_package module_name cfile.c_decls
+			end
 		) files
 	end;