Skip to content

Commit 80e287b

Browse files
authored
fix(1898): adjust location handling in find-refs (#1901)
1 parent 5207eb8 commit 80e287b

File tree

79 files changed

+960
-320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+960
-320
lines changed

internal/ls/documenthighlights.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (l *LanguageService) ProvideDocumentHighlights(ctx context.Context, documen
5151
}
5252

5353
func (l *LanguageService) getSemanticDocumentHighlights(ctx context.Context, position int, node *ast.Node, program *compiler.Program, sourceFile *ast.SourceFile) []*lsproto.DocumentHighlight {
54-
options := refOptions{use: referenceUseReferences}
54+
options := refOptions{use: referenceUseNone}
5555
referenceEntries := l.getReferencedSymbolsForNode(ctx, position, node, program, []*ast.SourceFile{sourceFile}, options, &collections.Set[string]{})
5656
if referenceEntries == nil {
5757
return nil

internal/ls/findallreferences.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,10 @@ func (l *LanguageService) getReferencedSymbolsForNode(ctx context.Context, posit
611611
}
612612
}
613613

614+
if options.use == referenceUseReferences || options.use == referenceUseRename {
615+
node = getAdjustedLocation(node, options.use == referenceUseRename, ast.GetSourceFileOfNode(node))
616+
}
617+
614618
checker, done := program.GetTypeChecker(ctx)
615619
defer done()
616620

internal/ls/utilities.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ func getAdjustedLocation(node *ast.Node, forRename bool, sourceFile *ast.SourceF
917917
// specially by `getSymbolAtLocation`.
918918
isModifier := func(node *ast.Node) bool {
919919
if ast.IsModifier(node) && (forRename || node.Kind != ast.KindDefaultKeyword) {
920-
return ast.CanHaveModifiers(parent) && slices.Contains(parent.Modifiers().NodeList.Nodes, node)
920+
return ast.CanHaveModifiers(parent) && parent.Modifiers() != nil && slices.Contains(parent.Modifiers().NodeList.Nodes, node)
921921
}
922922
switch node.Kind {
923923
case ast.KindClassKeyword:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// === findAllReferences ===
22
// === /constructorFindAllReferences1.ts ===
33
// export class C {
4-
// /*FIND ALL REFS*/public constructor() { }
4+
// /*FIND ALL REFS*/public [|constructor|]() { }
55
// public foo() { }
66
// }
77
//
8-
// new C().foo();
8+
// new [|C|]().foo();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// === findAllReferences ===
22
// === /constructorFindAllReferences2.ts ===
33
// export class C {
4-
// /*FIND ALL REFS*/private constructor() { }
4+
// /*FIND ALL REFS*/private [|constructor|]() { }
55
// public foo() { }
66
// }
77
//
8-
// new C().foo();
8+
// new [|C|]().foo();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// === findAllReferences ===
22
// === /constructorFindAllReferences4.ts ===
33
// export class C {
4-
// /*FIND ALL REFS*/protected constructor() { }
4+
// /*FIND ALL REFS*/protected [|constructor|]() { }
55
// public foo() { }
66
// }
77
//
8-
// new C().foo();
8+
// new [|C|]().foo();

testdata/baselines/reference/fourslash/findAllReferences/findAllReferencesDynamicImport1.baseline.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// === /foo.ts ===
1919
// export function foo() { return "foo"; }
2020
// import("./foo")
21-
// /*FIND ALL REFS*/var x = import("./foo")
21+
// /*FIND ALL REFS*/var [|x|] = import("./foo")
2222

2323

2424

testdata/baselines/reference/fourslash/findAllReferences/findAllReferencesOfJsonModule.baseline.jsonc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// === findAllReferences ===
22
// === /foo.ts ===
3-
// /*FIND ALL REFS*/import settings from "./settings.json";
4-
// settings;
3+
// /*FIND ALL REFS*/import [|settings|] from "./settings.json";
4+
// [|settings|];
55

66

77

testdata/baselines/reference/fourslash/findAllReferences/findAllRefsDeclareClass.baseline.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// === findAllReferences ===
22
// === /findAllRefsDeclareClass.ts ===
3-
// /*FIND ALL REFS*/declare class C {
3+
// /*FIND ALL REFS*/declare class [|C|] {
44
// static m(): void;
55
// }
66

testdata/baselines/reference/fourslash/findAllReferences/findAllRefsEnumAsNamespace.baseline.jsonc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// === findAllReferences ===
22
// === /findAllRefsEnumAsNamespace.ts ===
3-
// /*FIND ALL REFS*/enum E { A }
4-
// let e: E.A;
3+
// /*FIND ALL REFS*/enum [|E|] { A }
4+
// let e: [|E|].A;
55

66

77

0 commit comments

Comments
 (0)