2
0
Эх сурвалжийг харах

[display] support go to implementation inside expressions

closes #9087
Simon Krajewski 5 жил өмнө
parent
commit
3a5ebdadbd

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

@@ -248,7 +248,7 @@ module ExprPreprocessing = struct
 
 
 	let process_expr com e = match com.display.dms_kind with
-		| DMDefinition | DMTypeDefinition | DMUsage _ | DMHover | DMDefault -> find_before_pos com.display.dms_kind e
+		| DMDefinition | DMTypeDefinition | DMUsage _ | DMImplementation | DMHover | DMDefault -> find_before_pos com.display.dms_kind e
 		| DMSignature -> find_display_call e
 		| _ -> e
 end

+ 2 - 2
src/typing/typerDisplay.ml

@@ -300,7 +300,7 @@ and display_expr ctx e_ast e dk with_type p =
 	| DMHover ->
 		let item = completion_item_of_expr ctx e in
 		raise_hover item (Some with_type) e.epos
-	| DMUsage _ ->
+	| DMUsage _ | DMImplementation ->
 		let rec loop e = match e.eexpr with
 		| TField(_,FEnum(_,ef)) ->
 			Display.ReferencePosition.set (ef.ef_name,ef.ef_name_pos,SKEnumField ef);
@@ -416,7 +416,7 @@ and display_expr ctx e_ast e dk with_type p =
 					raise_toplevel ctx dk with_type (name,p)
 				end
 		end
-	| DMDefault | DMNone | DMModuleSymbols _ | DMDiagnostics _ | DMStatistics | DMImplementation ->
+	| DMDefault | DMNone | DMModuleSymbols _ | DMDiagnostics _ | DMStatistics ->
 		let fields = DisplayFields.collect ctx e_ast e dk with_type p in
 		let item = completion_item_of_expr ctx e in
 		let iterator = try

+ 26 - 0
tests/server/src/DisplayTests.hx

@@ -356,4 +356,30 @@ typedef Foo = {
 			}
 		});
 	}
+
+	function testIssue9087() {
+		var content = getTemplate("issues/Issue9087/A.hx");
+		var transform = Marker.extractMarkers(content);
+		vfs.putContent("A.hx", transform.source);
+		var args = ["A", "-js", "main.js"];
+		function parseGotoDefintion():GotoDefinitionResult {
+			return haxe.Json.parse(lastResult.stderr).result;
+		}
+		runHaxeJson(args, DisplayMethods.GotoImplementation, {file: new FsPath("A.hx"), offset: transform.markers[1], contents: transform.source});
+		var result = parseGotoDefintion().result;
+		// TODO: We should use the markers, but I forgot how to get lines and characters from offsets
+		// Also That Assert.same doesn't work
+		Assert.equals(9, result[0].range.start.line);
+		Assert.equals(1, result[0].range.start.character);
+		Assert.equals(11, result[0].range.end.line);
+		Assert.equals(2, result[0].range.end.character);
+		// Assert.same([
+		// 	{
+		// 		range: {
+		// 			start: {line: 9, character: 1},
+		// 			end: {line: 11, character: 2}
+		// 		}
+		// 	}
+		// ], result);
+	}
 }

+ 13 - 0
tests/server/test/templates/issues/Issue9087/A.hx

@@ -0,0 +1,13 @@
+class A {
+	public function new() {
+		in{-1-}it(); // "go to implementation" from the call site currently yields nothing
+	}
+
+	function init() {}
+}
+
+class B extends A {
+	override function {-2-}init{-3-}() {
+		super.init();
+	}
+}