[typescript-language-features] Support replacing Go to Definition with Go to Source Definition by preference #178840
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.
When a new preference is enabled, Go To Definition shows definitions from Go To Source Definition when available, instead of its typical results.
This is achievable without TS Server changes, allowing it to work on TypeScript versions as old as 4.7, but perhaps not optimally so. As it is now,
definitionAndBoundSpan
is still called first, becausefindSourceDefinition
does not return the text span used to draw the underline, and it also does not return fallback results to type declarations, which I think we would want if Go To Definition is fully replaced.findSourceDefinition
is called subsequently, and the definitions it returns replace the ones returned bydefinitionAndBoundSpan
. IffindSourceDefinition
returns no results, the response fromdefinitionAndBoundSpan
is used as a fallback.definitionAndBoundSpan
is typically very cheap, so this might be acceptable. But there are two ways we could improve performance:findSourceDefinition
can be considerably more expensive thandefinitionAndBoundSpan
, so it would be nice to trigger the latter when hovering with ctrl/cmd, and then trigger the former once the user clicks.