-
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
Skip invalid completion check immediately after newline #55061
Conversation
@microsoft-github-policy-service agree |
@sandersn could we expect this to be in TypeScript 5.3 or at least in 5.4? This is really needed for DX. |
@typescript-bot pack this |
4 similar comments
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
@typescript-bot pack this |
Hey @gabritto, 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 |
cool |
absolutely insane |
This comment was marked as duplicate.
This comment was marked as duplicate.
@typescript-bot user test tsserver |
Heya @gabritto, I've started to run the diff-based user code test suite (tsserver) on this PR at 6eb4ff3. You can monitor the build here. Update: The results are in! |
Heya @gabritto, I've started to run the regular perf test suite on this PR at 6eb4ff3. You can monitor the build here. Update: The results are in! |
Heya @gabritto, I've started to run the diff-based top-repos suite (tsserver) on this PR at 6eb4ff3. You can monitor the build here. Update: The results are in! |
@gabritto Here are the results of running the user test suite comparing Everything looks good! |
src/services/completions.ts
Outdated
function isCompletionListBlocker(contextToken: Node): boolean { | ||
const start = timestamp(); | ||
const result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || | ||
isSolelyIdentifierDefinitionLocation(contextToken) || | ||
// GH#54729 ignore this case when current position is in a newline |
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 think, if we wanted to be more precise in when we allow completions, this check of isInDifferentLineWithContextToken
should be done inside isSolelyIdentifierDefinitionLocation
, and should be done case-by-case, because I don't think we want to allow completions in a newline for every possible case isSolelyIdentifierDefinitionLocation
returns true.
For instance, isSolelyIdentifierDefinitionLocation
returns true on the following position:
var [x, y
|
It doesn't look like you'd actually want completions at that position.
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.
Thank you! Tried to fix this, @gabritto plz take a look at the new code :)
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.
Thank you for the contribution, and I apologize for the spam while trying to get the bot to work!
The change in general seems good, but we should probably use the check to alter isSolelyIdentifierDefinitionLocation
instead of patching over its result.
src/services/completions.ts
Outdated
// GH#54729 ignore this case when current position is in a newline | ||
(isSolelyIdentifierDefinitionLocation(contextToken) && !isInDifferentLineWithContextToken(contextToken, position)) || |
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.
// GH#54729 ignore this case when current position is in a newline | |
(isSolelyIdentifierDefinitionLocation(contextToken) && !isInDifferentLineWithContextToken(contextToken, position)) || | |
isSolelyIdentifierDefinitionLocation(contextToken) || | |
IMO it makes more sense to put the isInDifferentLineWithContextToken
check into the return statement of isSolelyIdentifierDefinitionLocation
, so we don't unblock too many cases.
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.
Thank you! gonna fix it
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.
Fixed, and now the logic looks less messy
@gabritto Here they are:
CompilerComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
tsserverComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
StartupComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@gabritto Here are the results of running the top-repos suite comparing Everything looks good! |
Co-authored-by: Isabel Duan <[email protected]>
Co-authored-by: Isabel Duan <[email protected]>
Co-authored-by: Isabel Duan <[email protected]>
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.
Looks good!
Note: this change only adds the newline after variable declarations
Fixes #54729
Demo: