Skip to content

fix(1342): adjust node ranges to ignore trivia #1355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/ls/findallreferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (l *LanguageService) convertSymbolAndEntryToLocation(s *SymbolAndEntries) [
for _, ref := range s.references {
if ref.textRange == nil {
sourceFile := ast.GetSourceFileOfNode(ref.node)
ref.textRange = l.createLspRangeFromNode(ref.node, ast.GetSourceFileOfNode(ref.node))
ref.textRange = l.getRangeOfNode(ref.node, sourceFile, nil /*endNode*/)
ref.fileName = sourceFile.FileName()
}
locations = append(locations, &lsproto.Location{
Expand Down
13 changes: 13 additions & 0 deletions internal/ls/findallreferences_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ class C extends [|/*3*/Base|] { }`,
"3": collections.NewSetFromItems("2", "3"),
},
},
{
title: "findAllRefsTrivia",
input: `export interface A {
/** Comment */
[|/*m1*/method|](): string;
/** Comment */
[|/*m2*/method|](format: string): string;
}`,
expectedLocations: map[string]*collections.Set[string]{
"m1": collections.NewSetFromItems("m1", "m2"),
"m2": collections.NewSetFromItems("m1", "m2"),
},
},
}

for _, testCase := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion internal/ls/findallreferencesexport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (l *LanguageService) GetExpectedReferenceFromMarker(fileName string, pos in
node := astnav.GetTouchingPropertyName(sourceFile, pos)
return &lsproto.Location{
Uri: FileNameToDocumentURI(fileName),
Range: *l.createLspRangeFromNode(node, sourceFile),
Range: *l.getRangeOfNode(node, sourceFile, nil /*endNode*/),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// === findAllReferences ===
// === /home/src/workspaces/project/a/index.d.ts ===

// declare class[| A|] {
// declare class [|A|] {
// }
// //# sourceMappingURL=index.d.ts.map


// === /home/src/workspaces/project/b/b.ts ===

// /// <reference path="../a/index.d.ts" />
// new A/*FIND ALL REFS*/[| A|]();
// new A/*FIND ALL REFS*/[|A|]();
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// === findAllReferences ===
// === /constructorFindAllReferences3.ts ===

// export class[| C|] {
// export class [|C|] {
// /*FIND ALL REFS*/constructor() { }
// public foo() { }
// }
//
// new[| C|]().foo();
// new [|C|]().foo();
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// === /abc.d.ts ===

// declare module "a" {
// export const /*FIND ALL REFS*/[| x|]: number;
// export const /*FIND ALL REFS*/[|x|]: number;
// }


Expand All @@ -17,5 +17,5 @@
// === /abc.d.ts ===

// declare module "a" {
// export const[| x|]: number;
// export const [|x|]: number;
// }
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// === /a.d.ts ===

// export as namespace abc;
// export const /*FIND ALL REFS*/[| x|]: number;
// export const /*FIND ALL REFS*/[|x|]: number;



Expand All @@ -16,7 +16,7 @@
// === /a.d.ts ===

// export as namespace abc;
// export const[| x|]: number;
// export const [|x|]: number;


// === /b.ts ===
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// === findAllReferences ===
// === /findAllReferencesFilteringMappedTypeProperty.ts ===

// const obj = { /*FIND ALL REFS*/[| a|]: 1, b: 2 };
// const obj = { /*FIND ALL REFS*/[|a|]: 1, b: 2 };
// const filtered: { [P in keyof typeof obj as P extends 'b' ? never : P]: 0; } = { a: 0 };
// filtered.[|a|];

Expand All @@ -12,7 +12,7 @@
// === /findAllReferencesFilteringMappedTypeProperty.ts ===

// const obj = { a: 1, b: 2 };
// const filtered: { [P in keyof typeof obj as P extends 'b' ? never : P]: 0; } = { /*FIND ALL REFS*/[| a|]: 0 };
// const filtered: { [P in keyof typeof obj as P extends 'b' ? never : P]: 0; } = { /*FIND ALL REFS*/[|a|]: 0 };
// filtered.a;


Expand All @@ -21,6 +21,6 @@
// === findAllReferences ===
// === /findAllReferencesFilteringMappedTypeProperty.ts ===

// const obj = {[| a|]: 1, b: 2 };
// const obj = { [|a|]: 1, b: 2 };
// const filtered: { [P in keyof typeof obj as P extends 'b' ? never : P]: 0; } = { a: 0 };
// filtered./*FIND ALL REFS*/[|a|];
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// === findAllReferences ===
// === /findAllReferencesFromLinkTagReference1.ts ===

// enum E {[|
// enum E {
// /** {@link /*FIND ALL REFS*/[|A|]} */
// A|]
// [|A|]
// }
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// === findAllReferences ===
// === /a.ts ===

// enum E {[|
// enum E {
// /** {@link /*FIND ALL REFS*/[|Foo|]} */
// Foo|]
// [|Foo|]
// }
// interface Foo {
// foo: E.[|Foo|];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// === /b.ts ===

// enum E {[|
// enum E {
// /** {@link /*FIND ALL REFS*/[|Foo|]} */
// Foo|]
// [|Foo|]
// }
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

// enum E {
// /** {@link /*FIND ALL REFS*/[|B|]} */
// A,[|
// B|]
// A,
// [|B|]
// }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// === findAllReferences ===
// === /findAllReferencesFromLinkTagReference5.ts ===

// enum E {[|
// enum E {
// /** {@link E./*FIND ALL REFS*/[|A|]} */
// A|]
// [|A|]
// }
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// === /Foo.js ===

// /** @type {function (this: string, string): string} */
// var f = function (s) { return /*FIND ALL REFS*/[| this|] + s; }
// var f = function (s) { return /*FIND ALL REFS*/[|this|] + s; }
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
// * @returns {unknown}
// */
// function foo(x/*FIND ALL REFS*/[|x|]) {
// return[| x|];
// return [|x|];
// }
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// === findAllReferences ===
// === /bar.js ===

// const { /*FIND ALL REFS*/[| foo|]: bar } = require('./foo');
// const { /*FIND ALL REFS*/[|foo|]: bar } = require('./foo');


// === /foo.js ===

// module.exports = {[|
// foo|]: '1'
// module.exports = {
// [|foo|]: '1'
// };
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// === findAllReferences ===
// === /X.js ===

// module.exports = {[| x|]: 1 };
// module.exports = { [|x|]: 1 };


// === /Y.js ===

// const { /*FIND ALL REFS*/[| x|]: { y } } = require("./X");
// const { /*FIND ALL REFS*/[|x|]: { y } } = require("./X");
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// === findAllReferences ===
// === /findAllReferencesLinkTag1.ts ===

// class C {[|
// m|]/*FIND ALL REFS*/() { }
// class C {
// m/*FIND ALL REFS*/[|m|]() { }
// n = 1
// static s() { }
// /**
Expand All @@ -25,8 +25,8 @@
// === /findAllReferencesLinkTag1.ts ===

// class C {
// m() { }[|
// n|]/*FIND ALL REFS*/ = 1
// m() { }
// n/*FIND ALL REFS*/[|n|] = 1
// static s() { }
// /**
// * {@link m}
Expand All @@ -52,7 +52,7 @@
// class C {
// m() { }
// n = 1
// static s/*FIND ALL REFS*/[| s|]() { }
// static s/*FIND ALL REFS*/[|s|]() { }
// /**
// * {@link m}
// * @see {m}
Expand All @@ -75,12 +75,11 @@
// === findAllReferences ===
// === /findAllReferencesLinkTag1.ts ===

// --- (line: 32) skipped ---
// r() { }
// --- (line: 33) skipped ---
// }
//
// interface I {[|
// a|]/*FIND ALL REFS*/()
// interface I {
// a/*FIND ALL REFS*/[|a|]()
// b: 1
// /**
// * {@link a}
Expand All @@ -92,12 +91,11 @@
// === findAllReferences ===
// === /findAllReferencesLinkTag1.ts ===

// --- (line: 33) skipped ---
// }
// --- (line: 34) skipped ---
//
// interface I {
// a()[|
// b|]/*FIND ALL REFS*/: 1
// a()
// b/*FIND ALL REFS*/[|b|]: 1
// /**
// * {@link a}
// * @see {a}
Expand All @@ -117,7 +115,7 @@
// function ref() { }
// /** @see {r2} */
// function d3() { }
// function r2/*FIND ALL REFS*/[| r2|]() { }
// function r2/*FIND ALL REFS*/[|r2|]() { }
// }


Expand All @@ -126,7 +124,7 @@
// === findAllReferences ===
// === /findAllReferencesLinkTag1.ts ===

// class C/*FIND ALL REFS*/[| C|] {
// class C/*FIND ALL REFS*/[|C|] {
// m() { }
// n = 1
// static s() { }
Expand Down Expand Up @@ -171,7 +169,7 @@
// r() { }
// }
//
// interface I/*FIND ALL REFS*/[| I|] {
// interface I/*FIND ALL REFS*/[|I|] {
// a()
// b: 1
// /**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// export class Consider {
// This = class {
// show() { }
// }[|
// m|]/*FIND ALL REFS*/() { }
// }
// m/*FIND ALL REFS*/[|m|]() { }
// }
// /**
// * @see {Consider.prototype.m}
Expand All @@ -20,8 +20,8 @@

// namespace NPR {
// export class Consider {
// This = class {[|
// show|]/*FIND ALL REFS*/() { }
// This = class {
// show/*FIND ALL REFS*/[|show|]() { }
// }
// m() { }
// }
Expand All @@ -34,8 +34,8 @@
// === /findAllReferencesLinkTag2.ts ===

// namespace NPR {
// export class Consider {[|
// This|]/*FIND ALL REFS*/ = class {
// export class Consider {
// This/*FIND ALL REFS*/[|This|] = class {
// show() { }
// }
// m() { }
Expand All @@ -48,7 +48,7 @@
// === /findAllReferencesLinkTag2.ts ===

// namespace NPR {
// export class Consider/*FIND ALL REFS*/[| Consider|] {
// export class Consider/*FIND ALL REFS*/[|Consider|] {
// This = class {
// show() { }
// }
Expand Down Expand Up @@ -80,7 +80,7 @@
// === findAllReferences ===
// === /findAllReferencesLinkTag2.ts ===

// namespace NPR/*FIND ALL REFS*/[| NPR|] {
// namespace NPR/*FIND ALL REFS*/[|NPR|] {
// export class Consider {
// This = class {
// show() { }
Expand Down
Loading
Loading