Browse Source

Fix local statics vs display requests (#11849)

* Local statics cannot be found in class decls

* Add test

* Update test

* Fix test for CI
Rudy Ges 8 months ago
parent
commit
bfb7a1e681

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

@@ -75,7 +75,7 @@ let check_display_field ctx sc c cf =
 
 let check_display_class ctx decls c =
 	let check_field sc cf =
-		if display_position#enclosed_in cf.cf_pos then
+		if not (has_class_field_flag cf CfNoLookup) && display_position#enclosed_in cf.cf_pos then
 			check_display_field ctx sc c cf;
 		DisplayEmitter.check_display_metadata ctx cf.cf_meta
 	in

+ 24 - 0
tests/server/src/cases/issues/Issue11849.hx

@@ -0,0 +1,24 @@
+package cases.issues;
+
+class Issue11849 extends TestCase {
+	function test(_) {
+		var content = getTemplate("issues/Issue11849/Main.hx");
+		var transform = Markers.parse(content);
+		vfs.putContent("Main.hx", transform.source);
+
+		var args = ["-main", "Main"];
+		runHaxe(args);
+		assertSuccess();
+
+		runHaxeJsonCb(args, DisplayMethods.Hover, {file: new FsPath("Main.hx"), offset: transform.offset(1)}, res -> {
+			switch (res.item.kind) {
+				case Local:
+					Assert.equals("bar", res.item.args.name);
+
+				case kind:
+					Assert.fail("unexpected item kind: " + kind);
+			}
+		});
+		assertSuccess();
+	}
+}

+ 7 - 0
tests/server/test/templates/issues/Issue11849/Main.hx

@@ -0,0 +1,7 @@
+class Main {
+	static function main() {}
+
+	function foo() {
+		static var b{-1-}ar = 0;
+	}
+}