瀏覽代碼

[display] add non-primary-type modules to document symbols

closes #9462
Simon Krajewski 5 年之前
父節點
當前提交
a057103bab
共有 4 個文件被更改,包括 13 次插入3 次删除
  1. 1 1
      src/compiler/displayOutput.ml
  2. 9 1
      src/context/display/documentSymbols.ml
  3. 2 0
      src/core/displayTypes.ml
  4. 1 1
      src/typing/typeloadParse.ml

+ 1 - 1
src/compiler/displayOutput.ml

@@ -431,7 +431,7 @@ let process_global_display_mode com tctx =
 				List.fold_left (fun acc (file_key,cfile) ->
 					let file = cfile.CompilationServer.c_file_path in
 					if (filter <> None || DisplayPosition.display_position#is_in_file file) then
-						(file,DocumentSymbols.collect_module_symbols (filter = None) (cfile.c_package,cfile.c_decls)) :: acc
+						(file,DocumentSymbols.collect_module_symbols (Some (file,get_module_name_of_cfile file cfile)) (filter = None) (cfile.c_package,cfile.c_decls)) :: acc
 					else
 						acc
 				) [] l

+ 9 - 1
src/context/display/documentSymbols.ml

@@ -2,7 +2,7 @@ open Ast
 open Globals
 open DisplayTypes.SymbolKind
 
-let collect_module_symbols with_locals (pack,decls) =
+let collect_module_symbols mname with_locals (pack,decls) =
 	let l = DynArray.create() in
 	let add name kind location parent deprecated =
 		let si = DisplayTypes.SymbolInformation.make name kind location (if parent = "" then None else Some parent) deprecated in
@@ -67,6 +67,7 @@ let collect_module_symbols with_locals (pack,decls) =
 	let field parent parent_kind cff =
 		field' parent parent_kind cff.cff_name cff.cff_kind cff.cff_access cff.cff_pos cff.cff_meta
 	in
+	let type_decls = Hashtbl.create 0 in
 	List.iter (fun (td,p) ->
 		let get_decl_path d =
 			let module_name = Path.module_name_of_file p.pfile in
@@ -78,6 +79,7 @@ let collect_module_symbols with_locals (pack,decls) =
 		let string_of_path l = String.concat "." l in
 		let add_type d kind =
 			let type_path, type_name = get_decl_path d in
+			Hashtbl.add type_decls type_name ();
 			add type_name kind p (string_of_path type_path) (is_deprecated d.d_meta);
 			string_of_path (type_path @ [type_name])
 		in
@@ -110,6 +112,12 @@ let collect_module_symbols with_locals (pack,decls) =
 			let dotpath = string_of_path (path @ [name]) in
 			field' dotpath Class d.d_name d.d_data d.d_flags p d.d_meta
 	) decls;
+	begin match mname with
+	| Some(file,mname) when not (Hashtbl.mem type_decls mname) ->
+		add mname Module {pfile = file; pmin = 0; pmax = 0} (String.concat "." pack) false
+	| _ ->
+		()
+	end;
 	l
 
 module Printer = struct

+ 2 - 0
src/core/displayTypes.ml

@@ -23,6 +23,7 @@ module SymbolKind = struct
 		| Operator
 		| EnumMember
 		| Constant
+		| Module
 
 	let to_int = function
 		| Class -> 1
@@ -41,6 +42,7 @@ module SymbolKind = struct
 		| Operator -> 14
 		| EnumMember -> 15
 		| Constant -> 16
+		| Module -> 17
 end
 
 module SymbolInformation = struct

+ 1 - 1
src/typing/typeloadParse.ml

@@ -48,7 +48,7 @@ let parse_file_from_lexbuf com file p lexbuf =
 	begin match !Parser.display_mode,parse_result with
 		| DMModuleSymbols (Some ""),_ -> ()
 		| DMModuleSymbols filter,(ParseSuccess(data,_,_)) when filter = None && DisplayPosition.display_position#is_in_file file ->
-			let ds = DocumentSymbols.collect_module_symbols (filter = None) data in
+			let ds = DocumentSymbols.collect_module_symbols None (filter = None) data in
 			DisplayException.raise_module_symbols (DocumentSymbols.Printer.print_module_symbols com [file,ds] filter);
 		| _ ->
 			()