Browse Source

prepare for workspace symbols

Simon Krajewski 9 years ago
parent
commit
2b7acc7686
5 changed files with 55 additions and 20 deletions
  1. 12 4
      src/display/display.ml
  2. 6 3
      src/main.ml
  3. 30 5
      src/typing/common.ml
  4. 6 7
      src/typing/typeload.ml
  5. 1 1
      src/typing/typer.ml

+ 12 - 4
src/display/display.ml

@@ -251,13 +251,21 @@ module DocumentSymbols = struct
 
 	let print_module_symbols com symbols filter =
 		let regex = Option.map Str.regexp filter in
-		let matches s = match regex with
-			| None -> true
-			| Some regex -> (try ignore(Str.search_forward regex s 0); true with Not_found -> false)
+		let reported = Hashtbl.create 0 in
+		let add si =
+			if Hashtbl.mem reported si.pos then false
+			else begin
+				let b = match regex with
+					| None -> true
+					| Some regex -> (try ignore(Str.search_forward regex si.name 0); true with Not_found -> false)
+				in
+				Hashtbl.replace reported si.pos true;
+				b
+			end
 		in
 		let ja = List.fold_left (fun acc (file,l) ->
 			let jl = ExtList.List.filter_map (fun si ->
-				if not (matches si.name) then
+				if not (add si) then
 					None
 				else begin
 					let l =

+ 6 - 3
src/main.ml

@@ -692,7 +692,7 @@ and wait_loop verbose accept =
 		| _ ->
 			let sign = get_signature com2 in
 			let ftime = file_time ffile in
-			let fkey = ffile ^ "!" ^ sign in
+			let fkey = (ffile,sign) in
 			try
 				let time, data = Hashtbl.find cache.c_files fkey in
 				if time <> ftime then raise Not_found;
@@ -848,7 +848,7 @@ and wait_loop verbose accept =
 				Parser.display_error := (fun e p -> has_parse_error := true; ctx.com.error (Parser.error_msg e) p);
 				if ctx.com.display.dms_display then begin
 					let file = (!Parser.resume_display).Ast.pfile in
-					let fkey = file ^ "!" ^ get_signature ctx.com in
+					let fkey = (file,get_signature ctx.com) in
 					(* force parsing again : if the completion point have been changed *)
 					Hashtbl.remove cache.c_files fkey;
 					(* force module reloading (if cached) *)
@@ -1302,7 +1302,7 @@ try
 						DMToplevel
 					| "module-symbols" ->
 						Common.define com Define.NoCOpt;
-						DMModuleSymbols;
+						DMModuleSymbols None;
 					| "diagnostics" ->
 						Common.define com Define.NoCOpt;
 						DMDiagnostics false;
@@ -1646,6 +1646,9 @@ try
 			| DMStatistics ->
 				let stats = Display.Statistics.collect_statistics tctx in
 				raise (Display.Statistics (Display.StatisticsPrinter.print_statistics stats))
+			| DMModuleSymbols filter ->
+				let symbols = com.shared.shared_display_information.document_symbols in
+				raise (Display.ModuleSymbols(Display.DocumentSymbols.print_module_symbols com symbols filter))
 			| _ -> ()
 		end;
 		Filters.run com tctx main;

+ 30 - 5
src/typing/common.ml

@@ -100,7 +100,7 @@ module DisplayMode = struct
 		| DMResolve of string
 		| DMPackage
 		| DMType
-		| DMModuleSymbols
+		| DMModuleSymbols of string option
 		| DMDiagnostics of bool (* true = global, false = only in display file *)
 		| DMStatistics
 
@@ -118,6 +118,7 @@ module DisplayMode = struct
 		dms_kind : t;
 		dms_display : bool;
 		dms_full_typing : bool;
+		dms_force_macro_typing : bool;
 		dms_error_policy : error_policy;
 		dms_is_diagnostics_run : bool;
 		dms_collect_data : bool;
@@ -131,6 +132,7 @@ module DisplayMode = struct
 		dms_kind = DMDefault;
 		dms_display = true;
 		dms_full_typing = false;
+		dms_force_macro_typing = false;
 		dms_error_policy = EPIgnore;
 		dms_is_diagnostics_run = false;
 		dms_collect_data = false;
@@ -144,6 +146,7 @@ module DisplayMode = struct
 		dms_kind = DMNone;
 		dms_display = false;
 		dms_full_typing = true;
+		dms_force_macro_typing = true;
 		dms_error_policy = EPShow;
 		dms_is_diagnostics_run = false;
 		dms_collect_data = false;
@@ -165,9 +168,10 @@ module DisplayMode = struct
 				dms_exit_during_typing = false
 			}
 		| DMToplevel -> { settings with dms_full_typing = true; }
-		| DMModuleSymbols -> { settings with
-				dms_display_file_policy = DFPAlso;
-				dms_exit_during_typing = false
+		| DMModuleSymbols _ -> { settings with
+				dms_display_file_policy = DFPOnly;
+				dms_exit_during_typing = false;
+				dms_force_macro_typing = true;
 			}
 		| DMDiagnostics _ -> { settings with
 				dms_full_typing = true;
@@ -185,6 +189,21 @@ module DisplayMode = struct
 				dms_display_file_policy = DFPAlso;
 				dms_exit_during_typing = false
 			}
+
+	let to_string = function
+		| DMNone -> "none"
+		| DMDefault -> "default"
+		| DMPosition -> "position"
+		| DMResolve s -> "resolve " ^ s
+		| DMPackage -> "package"
+		| DMType -> "type"
+		| DMUsage true -> "rename"
+		| DMUsage false -> "references"
+		| DMToplevel -> "toplevel"
+		| DMModuleSymbols None -> "module-symbols"
+		| DMModuleSymbols (Some s) -> "workspace-symbols " ^ s
+		| DMDiagnostics b -> (if b then "global " else "") ^ "diagnostics"
+		| DMStatistics -> "statistics"
 end
 
 type compiler_callback = {
@@ -216,6 +235,7 @@ type shared_display_information = {
 	mutable import_positions : (pos,bool ref * placed_name list) PMap.t;
 	mutable diagnostics_messages : (string * pos * DisplayTypes.DiagnosticsSeverity.t) list;
 	mutable type_hints : (pos,Type.t) Hashtbl.t;
+	mutable document_symbols : (string * DisplayTypes.SymbolInformation.t DynArray.t) list;
 }
 
 type display_information = {
@@ -289,7 +309,7 @@ let display_default = ref DisplayMode.DMNone
 
 type cache = {
 	mutable c_haxelib : (string list, string list) Hashtbl.t;
-	mutable c_files : (string, float * Ast.package) Hashtbl.t;
+	mutable c_files : ((string * string), float * Ast.package) Hashtbl.t;
 	mutable c_modules : (path * string, module_def) Hashtbl.t;
 }
 
@@ -818,6 +838,7 @@ let create version s_version args =
 				import_positions = PMap.empty;
 				diagnostics_messages = [];
 				type_hints = Hashtbl.create 0;
+				document_symbols = [];
 			}
 		};
 		display_information = {
@@ -891,6 +912,10 @@ let clone com =
 		file_lookup_cache = Hashtbl.create 0;
 		parser_cache = Hashtbl.create 0 ;
 		callbacks = create_callbacks();
+		display_information = {
+			unresolved_identifiers = [];
+			interface_field_implementations = [];
+		};
 	}
 
 let file_time file =

+ 6 - 7
src/typing/typeload.ml

@@ -237,10 +237,10 @@ let parse_file_from_lexbuf com file p lexbuf =
 	Lexer.init file true;
 	incr stats.s_files_parsed;
 	let data = (try Parser.parse com lexbuf with e -> t(); raise e) in
-    begin match com.display.dms_kind with
-        | DMModuleSymbols when Display.is_display_file file ->
+    begin match !display_default with
+        | DMModuleSymbols None when Display.is_display_file file ->
             let ds = Display.DocumentSymbols.collect_module_symbols data in
-            raise (Display.ModuleSymbols(Display.DocumentSymbols.print_module_symbols com [file,ds] None))
+			com.shared.shared_display_information.document_symbols <- (file,ds) :: com.shared.shared_display_information.document_symbols;
         | _ ->
             ()
     end;
@@ -2145,10 +2145,9 @@ module ClassInitializer = struct
 					(* is_lib ? *)
 					cctx.delayed_expr <- (ctx,Some r) :: cctx.delayed_expr;
 				end
-		end else begin
-			(*| DMDiagnostics false ->
-				handle_display_field()
-			| _ ->*)
+		end else if ctx.com.display.dms_force_macro_typing then
+			handle_display_field()
+		else begin
 			if fctx.is_display_field then begin
 				handle_display_field()
 			end else begin

+ 1 - 1
src/typing/typer.ml

@@ -3953,7 +3953,7 @@ and handle_display ctx e_ast iscall with_type =
 		raise (Display.DisplayPosition pl);
 	| DMToplevel ->
 		raise (Display.DisplayToplevel (ToplevelCollecter.run ctx))
-	| DMDefault | DMNone | DMModuleSymbols | DMDiagnostics _ | DMStatistics ->
+	| DMDefault | DMNone | DMModuleSymbols _ | DMDiagnostics _ | DMStatistics ->
 		let opt_args args ret = TFun(List.map(fun (n,o,t) -> n,true,t) args,ret) in
 		let e,tl_overloads,doc = match e.eexpr with
 			| TField (e1,fa) ->