-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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: no variable suggestions without semicolon #54656
fix: no variable suggestions without semicolon #54656
Conversation
I'm not sure, probably const a = 1
/**/ |
@typescript-bot pack this |
Heya @DanielRosenwasser, I've started to run the diff-based top-repos suite (tsserver) on this PR at 862807b. You can monitor the build here. Update: The results are in! |
Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at 862807b. You can monitor the build here. |
Heya @DanielRosenwasser, I've started to run the diff-based user code test suite (tsserver) on this PR at 862807b. You can monitor the build here. Update: The results are in! |
Hey @DanielRosenwasser, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
@DanielRosenwasser Here are the results of running the user test suite comparing Everything looks good! |
@@ -5516,14 +5516,18 @@ function isModuleSpecifierMissingOrEmpty(specifier: ModuleReference | Expression | |||
return !tryCast(isExternalModuleReference(specifier) ? specifier.expression : specifier, isStringLiteralLike)?.text; | |||
} | |||
|
|||
function getVariableOrParameterDeclaration(contextToken: Node | undefined) { | |||
function getVariableOrParameterDeclaration(contextToken: Node | undefined, location: Node) { | |||
if (!contextToken) return; |
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.
Should we still return early if contextToken
is undefined? Can we have a valid case where contextToken
is undefined but location
is defined?
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.
Actually I didn't think about it when I opened this PR. Though for me its obvious that it can be undefined
only when there is no tokens behind the requesting position at all (as essentially contextToken
is previousToken
). Otherwise it will be something like OpenBraceToken.
if (!contextToken) return; | ||
|
||
const declaration = findAncestor(contextToken, node => | ||
const possiblyParameterDeclaration = findAncestor(contextToken, node => |
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.
I know that the existing code already uses findAncestor
, but is this really needed @DanielRosenwasser? Can't we restrict the scope of this search?
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.
Do you mean do we really need two walks? I'm not sure; we could probably rewrite this to only do the second walk if the first fails though.
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.
Another way to do this is to check whether the contextToken
ever becomes the location
, and only then to start checking for variable declarations.
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.
Do you mean do we really need two walks? I'm not sure; we could probably rewrite this to only do the second walk if the first fails though.
I'm not sure I'm following initial request here. Why we can't have two walks here? (since it uses existing ast and we also do it only once per completionInfo request)
@DanielRosenwasser Here are the results of running the top-repos suite comparing Everything looks good! |
@typescript-bot perf test this |
Heya @DanielRosenwasser, I've started to run the perf test suite on this PR at 4c2bcc9. You can monitor the build here. Update: The results are in! |
@DanielRosenwasser Here they are:
CompilerComparison Report - main..54656
System
Hosts
Scenarios
TSServerComparison Report - main..54656
System
Hosts
Scenarios
StartupComparison Report - main..54656
System
Hosts
Scenarios
Developer Information: |
@typescript-bot cherry-pick this to release-5.1 |
Heya @DanielRosenwasser, I've started to run the task to cherry-pick this into |
Hey @DanielRosenwasser, I've opened #54782 for you. |
…e-5.1 (#54782) Co-authored-by: Vitaly Turovsky <vital2580@icloud.com>
don't use contextToken for finding closest variable declaration
Fixes #54654
I think there could be a better fix (rather than using location and contextToken at the same time)