Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 12, 2025

  • Understand the issue: References code lens does not include imports as references
  • Create a fourslash test for this issue
  • Attempted fix but it caused regressions (doubled ranges, goToImplementation failures)
  • Reverted incorrect fix per reviewer feedback - changes need to be based on original TypeScript implementation

Status

The fourslash test codeLensReferencesIncludeImports_test.go is kept to demonstrate the issue. The baseline shows 0 references which is the current (incorrect) behavior.

A proper fix requires more careful analysis of how TypeScript handles the difference between isDefinition marking vs Go's per-entry declaration filtering.

Original prompt

This section details on the original issue you should resolve

<issue_title>References code lens does not include imports as references</issue_title>
<issue_description>For a project:

// abc.ts
export function abc() { }
// other.ts
import { abc } from "./abc";

The references code lens currently shows 0 references

I can understand why it's doing this but it also feels a bit unexpected. TS 6.0 includes the imports as references</issue_description>

<agent_instructions>Create a fourslash test for this, based on internal/fourslash/tests/codeLensShowOnAllFunctions_test.go, Run all tests, accept the baselines, and commit that. Then work on the issue.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 12, 2025 20:58
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
When finding references for an exported symbol, the import specifier
(e.g., `abc` in `import { abc } from "./abc"`) should be counted as
a reference to the export. This change:

1. Adds the import location as a reference to the export symbol in
   searchForImportsOfExport for non-aliased imports.

2. Skips duplicate addition of import specifiers when the search
   is coming from an export context, since they're already added
   by the explicit addRef call.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

@copilot whatever you add, make sure it actually has a basis in the original implementation, and not something made up

// === findAllReferences ===
// === /myproject/a/index.ts ===
// import { [|B|] } from "../b/lib";
// import { [|[|B|]|] } from "../b/lib";
Copy link
Member

Choose a reason for hiding this comment

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

@copilot this range is being doubled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in aaefcb7 - reverted the changes that caused the doubled ranges.

Comment on lines 6 to 7
-// import {Foo} from './foo'
+// import {[|Foo|]} from './foo'
Copy link
Member

Choose a reason for hiding this comment

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

@copilot this is regressing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in aaefcb7 - reverted the changes that caused the regression.

Comment on lines 6 to 8
-// import { Interface } from "./def";
-// const c: I/*GOTO IMPL*/nterface = [|{ P: 2 }|];
+// <|import { [|Interface|] } from "./def";|>
Copy link
Member

Choose a reason for hiding this comment

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

@copilot this is regressing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in aaefcb7 - reverted the changes that caused the regression.

Copilot AI changed the title [WIP] Add fourslash test for references code lens including imports Fix references code lens to include imports as references Dec 12, 2025
Copilot AI requested a review from jakebailey December 12, 2025 21:43
The previous fix was adding imports to singleReferences and adding
skip logic in getReferencesAtLocation, but this approach was not
based on the original TypeScript implementation and caused:
- Doubled reference ranges like [|[|B|]|]
- Regressions in goToImplementation tests

This reverts to the original behavior while keeping the fourslash
test that demonstrates the issue (showing 0 references for now).

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 12, 2025

@copilot whatever you add, make sure it actually has a basis in the original implementation, and not something made up

Reverted the incorrect fix in commit aaefcb7. The test is kept to demonstrate the issue, but the baseline now shows the current behavior (0 references). A proper fix requires more careful analysis of how TypeScript handles isDefinition marking vs Go's per-entry declaration filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

References code lens does not include imports as references

2 participants