Browse Source

[display] cleanup module symbols

haxe-languageserver change incoming
Dan Korostelev 9 years ago
parent
commit
90961136e4
5 changed files with 34 additions and 49 deletions
  1. 27 42
      src/display/display.ml
  2. 3 3
      src/main.ml
  3. 1 1
      src/typing/common.ml
  4. 2 2
      src/typing/typeload.ml
  5. 1 1
      src/typing/typer.ml

+ 27 - 42
src/display/display.ml

@@ -18,7 +18,7 @@ type identifier_type =
 	| ITType of module_type
 	| ITPackage of string
 
-exception DocumentSymbols of string
+exception ModuleSymbols of string
 exception DisplaySignatures of t list
 exception DisplayType of t * pos
 exception DisplayPosition of Ast.pos list
@@ -128,59 +128,45 @@ let display_field dm cf p = match dm with
 
 module SymbolKind = struct
 	type t =
-		| File
-		| Module
-		| Namespace
-		| Package
 		| Class
-		| Method
-		| Property
+		| Interface
+		| Enum
+		| Typedef
+		| Abstract
 		| Field
+		| Property
+		| Method
 		| Constructor
-		| Enum
-		| Interface
 		| Function
 		| Variable
-		| Constant
-		| String
-		| Number
-		| Boolean
-		| Array
 
 	let to_int = function
-		| File -> 1
-		| Module -> 2
-		| Namespace -> 3
-		| Package -> 4
-		| Class -> 5
-		| Method -> 6
+		| Class -> 1
+		| Interface -> 2
+		| Enum -> 3
+		| Typedef -> 4
+		| Abstract -> 5
+		| Field -> 6
 		| Property -> 7
-		| Field -> 8
+		| Method -> 8
 		| Constructor -> 9
-		| Enum -> 10
-		| Interface -> 11
-		| Function -> 12
-		| Variable -> 13
-		| Constant -> 14
-		| String -> 15
-		| Number -> 16
-		| Boolean -> 17
-		| Array -> 18
+		| Function -> 10
+		| Variable -> 11
 end
 
 module SymbolInformation = struct
 	type t = {
 		name : string;
 		kind : SymbolKind.t;
-		location : pos;
-		containerName : string option;
+		pos : pos;
+		container_name : string option;
 	}
 
-	let make name kind location containerName = {
+	let make name kind pos container_name = {
 		name = name;
 		kind = kind;
-		location = location;
-		containerName = containerName;
+		pos = pos;
+		container_name = container_name;
 	}
 end
 
@@ -188,19 +174,18 @@ open SymbolKind
 open SymbolInformation
 open Json
 
-let pos_to_json_location p =
+let pos_to_json_range p =
 	if p.pmin = -1 then
 		JNull
 	else
 		let l1, p1, l2, p2 = Lexer.get_pos_coords p in
 		let to_json l c = JObject [("line", JInt l); ("character", JInt c)] in
 		JObject [
-			("file", JString (Common.unique_full_path p.pfile));
 			("start", to_json l1 p1);
 			("end", to_json l2 p2);
 		]
 
-let print_document_symbols (pack,decls) =
+let print_module_symbols (pack,decls) =
 	let l = DynArray.create() in
 	let add name kind location parent =
 		let si = SymbolInformation.make name kind location (match parent with None -> None | Some si -> Some si.name) in
@@ -278,21 +263,21 @@ let print_document_symbols (pack,decls) =
 				ignore (add (fst ef.ec_name) Method ef.ec_pos (Some si_type))
 			) d.d_data
 		| ETypedef d ->
-			let si_type = add (fst d.d_name) Interface p si_pack in
+			let si_type = add (fst d.d_name) Typedef p si_pack in
 			(match d.d_data with
 			| CTAnonymous fields,_ ->
 				List.iter (field si_type) fields
 			| _ -> ())
 		| EAbstract d ->
-			let si_type = add (fst d.d_name) Class p si_pack in
+			let si_type = add (fst d.d_name) Abstract p si_pack in
 			List.iter (field si_type) d.d_data
 	) decls;
 	let jl = List.map (fun si ->
 		let l =
 			("name",JString si.name) ::
 			("kind",JInt (to_int si.kind)) ::
-			("location", pos_to_json_location si.location) ::
-			(match si.containerName with None -> [] | Some s -> ["containerName",JString s])
+			("range", pos_to_json_range si.pos) ::
+			(match si.container_name with None -> [] | Some s -> ["containerName",JString s])
 		in
 		JObject l
 	) (DynArray.to_list l) in

+ 3 - 3
src/main.ml

@@ -1273,9 +1273,9 @@ try
 					| "toplevel" ->
 						Common.define com Define.NoCOpt;
 						DMToplevel
-					| "document-symbols" ->
+					| "module-symbols" ->
 						Common.define com Define.NoCOpt;
-						DMDocumentSymbols;
+						DMModuleSymbols;
 					| "" ->
 						DMDefault
 					| _ ->
@@ -1817,7 +1817,7 @@ with
 				raise (Completion c)
 			| _ ->
 				error ctx ("Could not load module " ^ (Ast.s_type_path (p,c))) Ast.null_pos)
-	| Display.DocumentSymbols s ->
+	| Display.ModuleSymbols s ->
 		raise (Completion s)
 	| Interp.Sys_exit i ->
 		ctx.flush();

+ 1 - 1
src/typing/common.ml

@@ -98,7 +98,7 @@ type display_mode =
 	| DMToplevel
 	| DMResolve of string
 	| DMType
-	| DMDocumentSymbols
+	| DMModuleSymbols
 
 type compiler_callback = {
 	mutable after_typing : (module_type list -> unit) list;

+ 2 - 2
src/typing/typeload.ml

@@ -230,8 +230,8 @@ 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
-	if com.display = DMDocumentSymbols && Common.unique_full_path file = (!Parser.resume_display).pfile then
-		raise (Display.DocumentSymbols(Display.print_document_symbols data));
+	if com.display = DMModuleSymbols && Common.unique_full_path file = (!Parser.resume_display).pfile then
+		raise (Display.ModuleSymbols(Display.print_module_symbols data));
 	t();
 	Common.log com ("Parsed " ^ file);
 	data

+ 1 - 1
src/typing/typer.ml

@@ -3831,7 +3831,7 @@ and handle_display ctx e_ast iscall with_type p =
 		raise (Display.DisplayPosition pl);
 	| DMToplevel ->
 		collect_toplevel_identifiers ctx;
-	| DMDefault | DMNone | DMDocumentSymbols ->
+	| DMDefault | DMNone | DMModuleSymbols ->
 		let opt_args args ret = TFun(List.map(fun (n,o,t) -> n,true,t) args,ret) in
 		let e,tl_overloads = match e.eexpr with
 			| TField (e1,fa) ->