Browse Source

Add Context.getDisplayMode() (#10807)

* Add Context.getDisplayMode()

* Group Rename/References DisplayMode as Usage

* References sounds better though

Co-authored-by: Simon Krajewski <[email protected]>
Rudy Ges 3 years ago
parent
commit
835ada5a6b

+ 2 - 1
src/macro/eval/evalEncode.ml

@@ -182,6 +182,7 @@ let encode_enum i pos index pl =
 		| IImportMode -> key_haxe_macro_ImportMode
 		| IImportMode -> key_haxe_macro_ImportMode
 		| IQuoteStatus -> key_haxe_macro_QuoteStatus
 		| IQuoteStatus -> key_haxe_macro_QuoteStatus
 		| IDisplayKind -> key_haxe_macro_DisplayKind
 		| IDisplayKind -> key_haxe_macro_DisplayKind
+		| IDisplayMode -> key_haxe_macro_DisplayMode
 		| IMessage -> key_haxe_macro_Message
 		| IMessage -> key_haxe_macro_Message
 		| IFunctionKind -> key_haxe_macro_FunctionKind
 		| IFunctionKind -> key_haxe_macro_FunctionKind
 		| IStringLiteralKind -> key_haxe_macro_StringLiteralKind
 		| IStringLiteralKind -> key_haxe_macro_StringLiteralKind
@@ -326,4 +327,4 @@ let encode_option encode_value o =
 let encode_nullable encode_value o =
 let encode_nullable encode_value o =
 	match o with
 	match o with
 	| Some v -> encode_value v
 	| Some v -> encode_value v
-	| None -> VNull
+	| None -> VNull

+ 2 - 1
src/macro/eval/evalHash.ml

@@ -115,6 +115,7 @@ let key_haxe_macro_AnonStatus = hash "haxe.macro.AnonStatus"
 let key_haxe_macro_ImportMode = hash "haxe.macro.ImportMode"
 let key_haxe_macro_ImportMode = hash "haxe.macro.ImportMode"
 let key_haxe_macro_QuoteStatus = hash "haxe.macro.QuoteStatus"
 let key_haxe_macro_QuoteStatus = hash "haxe.macro.QuoteStatus"
 let key_haxe_macro_DisplayKind = hash "haxe.macro.DisplayKind"
 let key_haxe_macro_DisplayKind = hash "haxe.macro.DisplayKind"
+let key_haxe_macro_DisplayMode = hash "haxe.macro.DisplayMode"
 let key_haxe_macro_Message = hash "haxe.macro.Message"
 let key_haxe_macro_Message = hash "haxe.macro.Message"
 let key_haxe_macro_FunctionKind = hash "haxe.macro.FunctionKind"
 let key_haxe_macro_FunctionKind = hash "haxe.macro.FunctionKind"
 let key_haxe_macro_StringLiteralKind = hash "haxe.macro.StringLiteralKind"
 let key_haxe_macro_StringLiteralKind = hash "haxe.macro.StringLiteralKind"
@@ -203,4 +204,4 @@ let key_physical = hash "physical"
 let key_address = hash "address"
 let key_address = hash "address"
 let key_netmask = hash "netmask"
 let key_netmask = hash "netmask"
 let key_previous = hash "previous"
 let key_previous = hash "previous"
-let key_current = hash "current"
+let key_current = hash "current"

+ 21 - 0
src/macro/macroApi.ml

@@ -1,4 +1,5 @@
 open Ast
 open Ast
+open DisplayTypes.DisplayMode
 open Type
 open Type
 open Common
 open Common
 
 
@@ -85,6 +86,7 @@ type enum_type =
 	| IQuoteStatus
 	| IQuoteStatus
 	| IImportMode
 	| IImportMode
 	| IDisplayKind
 	| IDisplayKind
+	| IDisplayMode
 	| IMessage
 	| IMessage
 	| IFunctionKind
 	| IFunctionKind
 	| IStringLiteralKind
 	| IStringLiteralKind
@@ -381,6 +383,22 @@ and encode_display_kind dk =
 	in
 	in
 	encode_enum ~pos:None IDisplayKind tag pl
 	encode_enum ~pos:None IDisplayKind tag pl
 
 
+and encode_display_mode dm =
+	let tag, pl = match dm with
+		| DMNone -> 0, []
+		| DMDefault -> 1, []
+		| DMDefinition -> 2, []
+		| DMTypeDefinition -> 3, []
+		| DMImplementation -> 4, []
+		| DMPackage -> 5, []
+		| DMHover -> 6, []
+		| DMUsage (withDefinition,findDescendants,findBase) -> 7, [(vbool withDefinition); (vbool findDescendants); (vbool findBase)]
+		| DMModuleSymbols None -> 8, []
+		| DMModuleSymbols (Some s) -> 9, [(encode_string s)]
+		| DMSignature -> 10, []
+	in
+	encode_enum ~pos:None IDisplayMode tag pl
+
 and encode_message (msg,p,_,sev) =
 and encode_message (msg,p,_,sev) =
 	let tag, pl = match sev with
 	let tag, pl = match sev with
 		| Globals.MessageSeverity.Information -> 0, [(encode_string msg); (encode_pos p)]
 		| Globals.MessageSeverity.Information -> 0, [(encode_string msg); (encode_pos p)]
@@ -1952,6 +1970,9 @@ let macro_api ccom get_api =
 			else
 			else
 				encode_obj ["file",encode_string p.Globals.pfile;"pos",vint p.Globals.pmin]
 				encode_obj ["file",encode_string p.Globals.pfile;"pos",vint p.Globals.pmin]
 		);
 		);
+		"get_display_mode", vfun0 (fun() ->
+			encode_display_mode !Parser.display_mode
+		);
 		"apply_params", vfun3 (fun tpl tl t ->
 		"apply_params", vfun3 (fun tpl tl t ->
 			let tl = List.map decode_type (decode_array tl) in
 			let tl = List.map decode_type (decode_array tl) in
 			let tpl = List.map (fun v ->
 			let tpl = List.map (fun v ->

+ 4 - 0
std/haxe/macro/Context.hx

@@ -127,6 +127,10 @@ class Context {
 		return load("contains_display_position", 1)(pos);
 		return load("contains_display_position", 1)(pos);
 	}
 	}
 
 
+	public static function getDisplayMode():DisplayMode {
+		return load("get_display_mode", 0)();
+	}
+
 	/**
 	/**
 		Returns the position at which the macro was called.
 		Returns the position at which the macro was called.
 	**/
 	**/

+ 15 - 0
std/haxe/macro/DisplayMode.hx

@@ -0,0 +1,15 @@
+package haxe.macro;
+
+enum DisplayMode {
+	None;
+	Default;
+	Definition;
+	TypeDefinition;
+	Implementation;
+	Package;
+	Hover;
+	References(withDefinition:Bool, findDescendants:Bool, findBase:Bool);
+	ModuleSymbols;
+	WorkspaceSymbols(filter:String);
+	Signature;
+}