Skip to content
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

Fix bug where an interface definition had a conflicting symbol with a const in the same file #206

Merged
merged 4 commits into from
Nov 16, 2022

Conversation

olafurpg
Copy link
Member

@olafurpg olafurpg commented Nov 11, 2022

Reported via Slack https://sourcegraph.slack.com/archives/CHXHX7XAS/p1668157176918589?thread_ts=1668128629.962219&cid=CHXHX7XAS

Test plan

See the snapshot test for a minimized reproduction. I also manually verified the bug has been fixed by indexing microsoft/vscode with a local build and uploading the index to https://sourcegraph.com/github.com/microsoft/vscode@9984da1/-/blob/src/vs/workbench/services/workspaces/common/workspaceEditing.ts?L13:18#tab=implementations_typescript

// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst.
// documentation ```ts\ninterface ConflictingConst\n```
export interface ConflictingConst {}
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst.
Copy link
Member Author

Choose a reason for hiding this comment

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

The expected behavior

Suggested change
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst.
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`conflicting-const-interface.ts`/ConflictingConst#

@olafurpg olafurpg changed the title Reproduce issue with conflicting const/interface Fix bug where an interface definition had a conflicting symbol with a const in the same file Nov 11, 2022
@olafurpg olafurpg marked this pull request as ready for review November 11, 2022 12:27
Comment on lines +40 to +43
// Uncomment below if you want to skip certain files for local development.
// if (!this.sourceFile.fileName.includes('conflicting-const')) {
// return
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why add these special comments for particular test cases? We could potentially add a test filter regex or something if that's desired, this seems a little strange.

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't figured out yet how to implement this kind of filtering from the test framework so I prefer to keep it as a comment until we figure out a better solution.

Comment on lines 111 to 113
const declarations = isDefinitionNode
? [node.parent] // Don't emit ambiguous definition at definition-site
: sym?.declarations || []
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment doesn't properly explain what is going on. Why does sym?.declarations lead to ambiguity? Can we trust it for non-definition nodes? It seems like there is something unusual going on with the AST structure here which needs more explanation.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can reproduce the ambiguous definition with tsserver

export const Conflict = 42
interface Conflict {}
          ^^^^^^^^ Go to definition here shows two results: the const and the interface

I updated the comment to give this example and link to this PR.

Can we trust it for non-definition nodes?

sym.declarations is what tsserver uses so I think we need to trust it except for odd-cases like this one where it seems like the API has a bug.

@olafurpg olafurpg merged commit fcce15e into main Nov 16, 2022
@olafurpg olafurpg deleted the olafurpg/interface-const-conflict branch November 16, 2022 14:56
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.

3 participants