[typescript-language-features] Support replacing Go to Definition with Go to Source Definition by preference#178840
Merged
mjbvz merged 3 commits intomicrosoft:mainfrom Apr 5, 2023
Conversation
c63de3b to
b10af0d
Compare
mjbvz
requested changes
Apr 4, 2023
| "description": "%configuration.preferGoToSourceDefinition%", | ||
| "scope": "window" | ||
| }, | ||
| "javascript.preferGoToSourceDefinition": { |
extensions/typescript-language-features/src/languageFeatures/definitions.ts
Show resolved
Hide resolved
Collaborator
|
As discussed, we'll merge this as is since it seems good enough. In future TS release, we may update the source definition request to return a span |
mjbvz
approved these changes
Apr 5, 2023
aeschli
approved these changes
Apr 5, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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,
definitionAndBoundSpanis still called first, becausefindSourceDefinitiondoes 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.findSourceDefinitionis called subsequently, and the definitions it returns replace the ones returned bydefinitionAndBoundSpan. IffindSourceDefinitionreturns no results, the response fromdefinitionAndBoundSpanis used as a fallback.definitionAndBoundSpanis typically very cheap, so this might be acceptable. But there are two ways we could improve performance:findSourceDefinitioncan 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.