GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Find Source Definition by andrewbranch · Pull Request #48264 · microsoft/TypeScript

Conversation

@andrewbranch

@andrewbranch Andrew Branch (andrewbranch) commented Mar 14, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This PR adds a new command similar to Go To Definition, but includes locations in JS files that would normally not be considered, excludes all ambient locations, and potentially uses some heuristics to find likely results in JS files that cannot be analyzed with our binder and type checker due to complex module wrappers or other constructs we don’t understand. The process when invoked is:

  1. Run go-to-definition on something. If it returns only ambient definitions that are alias targets, or stops at import aliases that couldn’t resolve to anything, continue with next steps. Otherwise, return any non-ambient definitions found.
  2. Spin up a temporary project with a single root file, the one in the requesting location, using a new internal compiler setting that prevents module resolution from considering .d.ts files. This lets us resolve to JS files that would normally be “shadowed” by .d.ts declarations.
  3. With that project, try go-to-def again, this time skipping any non-alias work and returning best-effort file results for things like imports where the module specifier resolved, but the specific export wasn’t found, or the target file wasn’t even recognized as a module.
  4. For any results that were “unverified” (those best-effort file results), see if the requesting location gave us a strong indicator of what the declaration name we’re looking for is (i.e., can we locally resolve to a named import). If so, try a find-all-refs-like text search on the file returned, and from those results get the top-most declarations by that name. (This is obviously highly approximate and needs some vetting as to whether it’s worth doing at all—at the very least, it needs corresponding editor UI to indicate that these results are not much better than a text search. I attempted to filter these declarations further by symbol flags and/or basic type analysis, but that immediately proved unreliable in the face of exports created by factory functions with poor JSDoc annotations.)

I attempted to tack this onto go-to-implementation instead of its own command, but go-to-implementation is extremely weird and did not play nicely with this code. This is much more go-to-definition-like, but I don’t think we can simply augment or replace go-to-definition because we want go-to-def to be super fast and reliable, and I think we don’t want this command returning anything ambient. However, for purposes of gathering public feedback in the meantime, I think I’m going to make a build that replaces go-to-def with this logic. (Otherwise, users would have to use a special build of VS Code in order to send the new command.)

Fixes #6209
Fixes #38474

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tonivj5, tschaub, johnfn, niyarlatotep, alexeyr-c, 99linesofcode, and ironm00n reacted with thumbs up emoji tonivj5, thomasballinger, shayded-exe, 99linesofcode, and kubk reacted with heart emoji
All reactions
  • 👍 7 reactions
  • ❤️ 5 reactions
Andrew Branch (andrewbranch) added 15 commits February 25, 2022 11:50
@andrewbranch
Prototype resolving to JS when go-to-def aliases all resolve to ambie…
81ec4fd
…nt declarations
@andrewbranch
Add test infrastructure
422d845
@andrewbranch
Start fleshing out test coverage
1b43352
@andrewbranch
Fix some go-to-def stuff
7aeb92f
@andrewbranch
Finish lodash test case
f2915e6
@andrewbranch
Make go-to-implementation never return ambient results
309c4bb
@andrewbranch
Build new functionality into go-to-implementation
381799d
@andrewbranch
Update baselines
0727702
@andrewbranch
Two more test cases
ebeda0b
@andrewbranch
Refine definition searches for unresolved imports
03ea413
@andrewbranch
Revert "Build new functionality into go-to-implementation"
e5556b8
This reverts commit 381799d.
@andrewbranch
Fix tests
6104a5c
@andrewbranch
Merge branch 'main' into go-to-js
bea3de0
@andrewbranch
Revert go-to-implementation changes
4e64659
@andrewbranch
Wow a bunch of code was unnecessary
1cb2ba6
@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 14, 2022

Copy link
Copy Markdown
Contributor

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping Sheetal Nandi (@sheetalkamat), Andrew Casey (@amcasey), Matt Bierner (@mjbvz), Mine Starks (@minestarks) for you. Feel free to loop in other consumers/maintainers if necessary

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot TypeScript Bot (typescript-bot) assigned Andrew Branch (andrewbranch) Mar 14, 2022
@typescript-bot TypeScript Bot (typescript-bot) added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Mar 14, 2022
@andrewbranch Andrew Branch (andrewbranch) mentioned this pull request Mar 15, 2022
Enable Go to Implementation in Typescript Editors #6209
Closed
@amcasey

Andrew Casey (amcasey) commented Mar 16, 2022

Copy link
Copy Markdown
Member

One case to consider as we think about how this functionality should be triggered is what ctrl-click should do.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Andrew Branch (andrewbranch) added 3 commits March 16, 2022 16:12
@andrewbranch
Update baselines and go-to-def test
7e57890
@andrewbranch
Fix navigation on symbols that are not aliases but resolve through al…
43c01e2
…iases in chain
@andrewbranch
Temporarily replace go-to-def with new command implementation
34c6cfd
@andrewbranch
Andrew Branch (andrewbranch) force-pushed the go-to-js branch from 034bfe5 to 34c6cfd Compare March 16, 2022 23:13
@microsoft Microsoft (microsoft) deleted a comment from TypeScript Bot (typescript-bot) Mar 16, 2022
@microsoft Microsoft (microsoft) deleted a comment from TypeScript Bot (typescript-bot) Mar 16, 2022
@andrewbranch

Andrew Branch (andrewbranch) commented Mar 16, 2022

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) pack this

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 16, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Andrew Branch (@andrewbranch), I've started to run the tarball bundle task on this PR at 34c6cfd. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewbranch
Revert "Temporarily replace go-to-def with new command implementation"
7357593
This reverts commit 34c6cfd.
@andrewbranch
Andrew Branch (andrewbranch) requested review from Andrew Casey (amcasey) and Wesley Wigham (weswigham) and removed request for Andrew Casey (amcasey) April 7, 2022 22:42
sheetalkamat
Sheetal Nandi (sheetalkamat) requested changes Apr 13, 2022
View reviewed changes
Comment thread src/server/project.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/server/project.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/server/project.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Andrew Branch (andrewbranch) added 2 commits April 13, 2022 09:42
@andrewbranch
PR feedback
24c0d8a
@andrewbranch
Update API baseline
f6bd9d8
@andrewbranch
Andrew Branch (andrewbranch) requested a review from Sheetal Nandi (sheetalkamat) April 13, 2022 17:06
sheetalkamat
Sheetal Nandi (sheetalkamat) approved these changes Apr 13, 2022
View reviewed changes

@sheetalkamat Sheetal Nandi (sheetalkamat) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Just need to make some of the methods internal

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/server/project.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/server/project.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Andrew Branch (andrewbranch) added 3 commits April 13, 2022 13:42
@andrewbranch
Mark scheduleInvalidateResolutionsOfFailedLookupLocations internal
2cb2048
@andrewbranch
Use same heuristics on property accesses of loosely-resolvable aliase…
f9f4592
…s as unresolvable named imports
@andrewbranch
Rename command, and no need to return the bound span
e302f56
@andrewbranch Andrew Branch (andrewbranch) changed the title Go To Source Definition Find Source Definition Apr 14, 2022
@andrewbranch

Andrew Branch (andrewbranch) commented Apr 14, 2022

Copy link
Copy Markdown
Member Author

Latest commits

  • make _./*|*/add work when _ itself can only be resolved with heuristics
  • rename the command FindSourceDefinition, dropping the bound span part of the response as it’s not needed.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Andrew Branch (andrewbranch) added 2 commits April 14, 2022 14:59
@andrewbranch
Update API baseline
3f15ed3
@andrewbranch
Merge branch 'main' into go-to-js
f80c9ef
@andrewbranch
Andrew Branch (andrewbranch) merged commit 8bd7ce6 into microsoft:main Apr 14, 2022
@andrewbranch Andrew Branch (andrewbranch) mentioned this pull request Apr 15, 2022
[typescript-language-features] Add command and editor context menu contribution for Find Source Definition microsoft/vscode#147532
Closed
Jack Works (Jack-Works) pushed a commit to Jack-Works/TypeScript that referenced this pull request Apr 22, 2022
@andrewbranch @Jack-Works
Find Source Definition (microsoft#48264)
890a318
* Prototype resolving to JS when go-to-def aliases all resolve to ambient declarations

* Add test infrastructure

* Start fleshing out test coverage

* Fix some go-to-def stuff

* Finish lodash test case

* Make go-to-implementation never return ambient results

* Build new functionality into go-to-implementation

* Update baselines

* Two more test cases

* Refine definition searches for unresolved imports

* Revert "Build new functionality into go-to-implementation"

This reverts commit 381799d.

* Fix tests

* Revert go-to-implementation changes

* Wow a bunch of code was unnecessary

* Update baselines and go-to-def test

* Fix navigation on symbols that are not aliases but resolve through aliases in chain

* Temporarily replace go-to-def with new command implementation

* Revert "Temporarily replace go-to-def with new command implementation"

This reverts commit 34c6cfd.

* Revert "Wow a bunch of code was unnecessary"

This reverts commit 1cb2ba6.

* Bring back some deleted code needed for a new test case

* Clean up a little

* Rename more stuff

* Update test

* Update API baseline

* Temporarily replace go-to-def with new command implementation

* PR review fixes

* Fix getTopMostDeclarationNamesInFile

* Rename local

* Use hash set

* Remove option from commandLineParser

* Keep noDtsResolution project around

* Handle AuxiliaryProject kind in ScriptInfo getDefaultProject etc.

* Do not run updateGraph in the background for AuxiliaryProject

* Don’t create auxiliary project outside of semantic mode

* No-op on scheduled invalidation

* Add comments to unit test

* Sync compiler options to auxiliary project

* Fix case sensitivity

* Update extensionIsOk with new file extensions

* PR feedback

* Update API baseline

* Mark scheduleInvalidateResolutionsOfFailedLookupLocations internal

* Use same heuristics on property accesses of loosely-resolvable aliases as unresolvable named imports

* Rename command, and no need to return the bound span

* Update API baseline
@johnsoncodehk

Johnson Chu (johnsoncodehk) commented Apr 23, 2022

Copy link
Copy Markdown

Could we expose findSourceDefinition for language service API to make it available for LSP?

MichaelGitArt and Sengulair reacted with heart emoji MichaelGitArt and Sengulair reacted with rocket emoji MichaelGitArt and Sengulair reacted with eyes emoji
All reactions
  • ❤️ 2 reactions
  • 🚀 2 reactions
  • 👀 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewbranch

Andrew Branch (andrewbranch) commented Apr 25, 2022

Copy link
Copy Markdown
Member Author

Unfortunately not—if you look at the implementation here, Find Source Definition happens by orchestrating multiple different language services to call Go To Definition with different module resolution options. What are you hoping to integrate it into?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewbranch
Andrew Branch (andrewbranch) deleted the go-to-js branch April 25, 2022 16:14
@johnsoncodehk

Johnson Chu (johnsoncodehk) commented Apr 25, 2022

Copy link
Copy Markdown

Andrew Branch (@andrewbranch) I hope it can use in embedded typescript language for Vue. (For example: https://github.com/johnsoncodehk/volar-starter/blob/e4f6d9808181f4533811c1aafc4b6afea1f68598/src/components/HelloWorld.vue#L26-L30)

For Go to Definition and Go to Type Definition features, I using getDefinitionAndBoundSpan and getTypeDefinitionAtPosition API of TS language service implemented.

  • https://github.com/johnsoncodehk/volar/blob/90d370e82817afe011c8b8bd0a7d645464d45101/packages/typescript-language-service/src/services/definition.ts#L21
  • https://github.com/johnsoncodehk/volar/blob/90d370e82817afe011c8b8bd0a7d645464d45101/packages/typescript-language-service/src/services/typeDefinition.ts#L20

I'm also expected a new getSourceDefinitionAndBoundSpan or getSourceDefinitionAtPosition API.

(btw Go to Source Definition is not specification of LSP, so I need to implement it bypass LSP.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewbranch

Andrew Branch (andrewbranch) commented Apr 25, 2022

Copy link
Copy Markdown
Member Author

It’s simply not possible to put this functionality on the LanguageService object (or, it would be a significant violation of the LS’s scope of concerns). At minimum you would need to create a second language service (which creates a second Program and TypeChecker!). It would take a bit of work on our end to abstract what I put directly into TS Server into some kind of public API that could be used independently of the project system. This is an experimental API so it’s not going to happen right now, but if you want to open a new suggestion issue for doing this, we’ll keep an eye on it and could discuss some of the design challenges. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@johnsoncodehk

Johnson Chu (johnsoncodehk) commented Apr 25, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

At minimum you would need to create a second language service (which creates a second Program and TypeChecker!).

Actually this is absolutely acceptable 😅, we already have multiple language server & language service instances in order to prevent auto-complete request from being blocked by unfinished diagnostics request. (vuejs/language-tools#393 (reply in thread))

Great to see it experimentally added to the language service API, this feature will be very welcome in the Vue community, it solves some common DX issues in Vue projects (For example: vuejs/language-tools#1226). It doesn't matter if it will be removed anytime in the future, I can adapt the code quickly.

if you want to open a new suggestion issue for doing this, we’ll keep an eye on it and could discuss some of the design challenges.

Of course, thanks in advance!

andrewbranch, niyarlatotep, and harrisoncramer reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@johnsoncodehk Johnson Chu (johnsoncodehk) mentioned this pull request Apr 29, 2022
Support for Find Source Definition vuejs/language-tools#1245
Closed
@andrewbranch Andrew Branch (andrewbranch) mentioned this pull request May 6, 2022
Go To Source Definition feedback thread #49003
Closed
@RedBeard0531 Mathias Stearn (RedBeard0531) mentioned this pull request Jun 15, 2022
Support new "Go to Source Definition" feature in TS 4.7 neoclide/coc-tsserver#383
Closed
@rchl Rafał Chłodnicki (rchl) mentioned this pull request Jul 3, 2022
Possibility of including Go to Source Definition? typescript-language-server/typescript-language-server#507
Closed
@Buckwich Simon (Buckwich) mentioned this pull request Jun 16, 2025
Generate declaration maps bpmn-io/diagram-js#977
Merged
2 of 4 tasks
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@sheetalkamat Sheetal Nandi (sheetalkamat) sheetalkamat approved these changes
@sandersn Nathan Shively-Sanders (sandersn) Awaiting requested review from sandersn
@weswigham Wesley Wigham (weswigham) Awaiting requested review from weswigham
+1 more reviewer
@amcasey Andrew Casey (amcasey) amcasey left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@andrewbranch Andrew Branch (andrewbranch)

Labels

Author: Team For Milestone Bug PRs that fix a bug with a specific milestone

Projects

PR Backlog
Archived in project

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Go to definition for nodejs javascript file broken by existance of .d.ts Enable Go to Implementation in Typescript Editors

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@andrewbranch @typescript-bot @amcasey @johnsoncodehk @weswigham @sheetalkamat
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.