Browse Source

[display] don't full_pos null_pos

see #9140
Simon Krajewski 2 years ago
parent
commit
af1ebf5a31

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

@@ -101,7 +101,7 @@ let rec collect_reference_positions com (name,pos,kind) =
 				| [] -> [cf,c]
 				| pairs -> pairs
 			in
-			let full_pos p = { p with pfile = Path.get_full_path p.pfile } in
+			let full_pos p = if p = null_pos then null_pos else { p with pfile = Path.get_full_path p.pfile } in
 			if find_descendants then
 				let extends child_cls (_,c) = extends child_cls c in
 				List.fold_left (fun acc t ->

+ 61 - 0
tests/server/src/cases/display/issues/Issue9140.hx

@@ -0,0 +1,61 @@
+package cases.display.issues;
+
+class Issue9140 extends DisplayTestCase {
+	/**
+		class Main {
+			static function main() {
+				var c = new C();
+				var f {-1-}= c.field{-2-};
+		{-3-}		c.field{-4-} = f;
+			}
+		}
+
+		class C implements I {
+			public var field(g{-5-}et,s{-6-}et):Int;
+			public function new() {}
+
+			function get{-7-}_field() return 10;
+			function set_f{-8-}ield(value:Int) return value;
+		}
+
+		interface I {
+			var field(get,set):Int;
+		}
+	**/
+	function test(_) {
+		// TODO: The starting positions are off by 4. This comes from patch_string_pos in
+		// statistics.ml subtracting the length of get_/set_, while the syntax has the plain
+		// field. This is not a new issue though.
+		runHaxeJson([], DisplayMethods.FindReferences, {
+			file: file,
+			kind: WithBaseAndDescendants,
+			offset: offset(5)
+		});
+		var result = parseGotoDefinitionLocations();
+		Assert.same([range(1, 2)], result.map(l -> l.range));
+
+		runHaxeJson([], DisplayMethods.FindReferences, {
+			file: file,
+			kind: WithBaseAndDescendants,
+			offset: offset(7)
+		});
+		var result = parseGotoDefinitionLocations();
+		Assert.same([range(1, 2)], result.map(l -> l.range));
+
+		runHaxeJson([], DisplayMethods.FindReferences, {
+			file: file,
+			kind: WithBaseAndDescendants,
+			offset: offset(6)
+		});
+		var result = parseGotoDefinitionLocations();
+		Assert.same([range(3, 4)], result.map(l -> l.range));
+
+		runHaxeJson([], DisplayMethods.FindReferences, {
+			file: file,
+			kind: WithBaseAndDescendants,
+			offset: offset(8)
+		});
+		var result = parseGotoDefinitionLocations();
+		Assert.same([range(3, 4)], result.map(l -> l.range));
+	}
+}