Skip to content
Open
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
15 changes: 13 additions & 2 deletions internal/ls/findallreferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -1905,9 +1905,12 @@ func (state *refState) getReferencesAtLocation(sourceFile *ast.SourceFile, posit
}

parent := referenceLocation.Parent
if parent.Kind == ast.KindImportSpecifier && parent.PropertyName() == referenceLocation {
if parent.Kind == ast.KindImportSpecifier && search.comingFrom == ImpExpKindExport {
propName := parent.PropertyName()
// This is added through `singleReferences` in ImportsResult. If we happen to see it again, don't add it again.
return
if propName == referenceLocation || (propName == nil && parent.Name() == referenceLocation) {
return
}
}

if parent.Kind == ast.KindExportSpecifier {
Expand Down Expand Up @@ -2159,6 +2162,14 @@ func (state *refState) shouldAddSingleReference(singleRef *ast.Node) bool {
if !state.hasMatchingMeaning(singleRef) {
return false
}
// Check if this node is already in any reference group to avoid duplicates
for _, symbolAndEntries := range state.result {
for _, ref := range symbolAndEntries.references {
if ref.node == singleRef {
return false
}
}
}
if state.options.use != referenceUseRename {
return true
}
Expand Down
5 changes: 5 additions & 0 deletions internal/ls/importTracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ func getSearchesFromDirectImports(
} else {
localSymbol = checker.GetSymbolAtLocation(name)
}
// Include import specifiers as references to the exported symbol.
// Export specifiers are handled by getReferencesAtExportSpecifier, so skip them here.
if !ast.IsExportSpecifier(element) {
singleReferences = append(singleReferences, name)
}
addSearch(name, localSymbol)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// === Code Lenses ===
// === /exports.ts ===
// let callCount = 0;
// export function /*CODELENS: 3 references*/foo(n: number): void {
// export function /*CODELENS: 4 references*/foo(n: number): void {
// callCount++;
// if (n > 0) {
// [|foo|](n - 1);
Expand All @@ -17,7 +17,7 @@
//

// === /importer.ts ===
// import { foo, bar } from "./exports";
// import { [|foo|], bar } from "./exports";
//
// [|foo|](5);
// console.log(bar);
Expand All @@ -27,7 +27,7 @@

// === Code Lenses ===
// === /importer.ts ===
// import { foo, bar } from "./exports";
// import { foo, [|bar|] } from "./exports";
//
// foo(5);
// console.log([|bar|]);
Expand All @@ -38,5 +38,5 @@
//
// foo(5);
//
// export const /*CODELENS: 1 reference*/bar = 123;
// export const /*CODELENS: 2 references*/bar = 123;
//
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

// === Code Lenses ===
// === /classPointable.ts ===
// import { Pointable } from "./pointable";
// import { [|Pointable|] } from "./pointable";
//
// class Point implements [|Pointable|] {
// getX(): number {
Expand All @@ -98,7 +98,7 @@
// --- (line: 7) skipped ---

// === /objectPointable.ts ===
// import { Pointable } from "./pointable";
// import { [|Pointable|] } from "./pointable";
//
// let x = 0;
// let y = 0;
Expand All @@ -109,7 +109,7 @@
// --- (line: 9) skipped ---

// === /pointable.ts ===
// export interface /*CODELENS: 2 references*/Pointable {
// export interface /*CODELENS: 4 references*/Pointable {
// getX(): number;
// getY(): number;
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
// new D();

// === /b.ts ===
// import { C } from "./a";
// import { [|C|] } from "./a";
// new [|C|]();

// === /c.ts ===
// import { C } from "./a";
// import { [|C|] } from "./a";
// class D extends C {
// constructor() {
// [|super|]();
Expand Down Expand Up @@ -50,11 +50,11 @@
// new D();

// === /b.ts ===
// import { C } from "./a";
// import { [|C|] } from "./a";
// new [|C|]();

// === /c.ts ===
// import { C } from "./a";
// import { [|C|] } from "./a";
// class D extends C {
// constructor() {
// [|super|]();
Expand Down Expand Up @@ -86,11 +86,11 @@
// new D();

// === /b.ts ===
// import { C } from "./a";
// import { [|C|] } from "./a";
// new [|C|]();

// === /c.ts ===
// import { C } from "./a";
// import { [|C|] } from "./a";
// class D extends C {
// constructor() {
// [|super|]();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// export { [|B|] as [|B1|] } from "./f";

// === /b.ts ===
// import B, { B1 } from "./a";
// import B, { [|B1|] } from "./a";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems wrong, given _submodules/TypeScript/tests/baselines/reference/findAllRefsOfConstructor_multipleFiles.baseline.jsonc does not include it

// const d = new [|B|]("b");
// const d1 = new [|B1|]("b1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,23 +296,23 @@ Config::

// === Code Lenses ===
// === /projects/container/compositeExec/index.ts ===
// import { Pointable } from "../lib";
// import { [|Pointable|] } from "../lib";
// class Point2 implements [|Pointable|] {
// getX(): number {
// return 0;
// }
// --- (line: 6) skipped ---

// === /projects/container/exec/index.ts ===
// import { Pointable } from "../lib";
// import { [|Pointable|] } from "../lib";
// class Point1 implements [|Pointable|] {
// getX(): number {
// return 0;
// }
// --- (line: 6) skipped ---

// === /projects/container/lib/bar.ts ===
// import { Pointable } from "./index";
// import { [|Pointable|] } from "./index";
// class Point implements [|Pointable|] {
// getX(): number {
// return 0;
Expand All @@ -321,7 +321,7 @@ Config::

// === /projects/container/lib/index.ts ===
//
// export interface /*CODELENS: 3 references*/Pointable {
// export interface /*CODELENS: 6 references*/Pointable {
// getX(): number;
// getY(): number;
// }
Expand Down
Loading