-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Include source node inferences in string literal completions #54121
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
Conversation
a236333
to
ef50d45
Compare
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.
Code LGTM though I'll leave it to Andrew as to whether or not this is the better approach (I assume it is)
A couple of my merged PRs related to completions are using a similar "double request" technique. One notable difference is that this PR here always performs the double request whereas those other PRs use the second request as a fallback - only if the first one didn't return anything useful. Out of curiosity, I wonder:
|
@typescript-bot user test tsserver |
Heya @jakebailey, I've started to run the diff-based top-repos suite (tsserver) on this PR at ef50d45. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the diff-based user code test suite (tsserver) on this PR at ef50d45. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the tarball bundle task on this PR at ef50d45. You can monitor the build here. |
Hey @jakebailey, 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 |
@jakebailey Here are the results of running the user test suite comparing Everything looks good! |
@jakebailey Here are the results of running the top-repos suite comparing Everything looks good! |
I kinda already answered my own questions:
I think that there is a way to avoid the second request here by smartly providing |
@@ -1839,17 +1838,41 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||
typeHasCallOrConstructSignatures, | |||
}; | |||
|
|||
function getCandidateSignaturesForStringLiteralCompletions(call: CallLikeExpression, editingArgument: 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.
nit: other "double requests" are performed outside of the checker - it's the caller's responsibility to "probe" both type of contextual types (with and without inference blocking). Is this a problem? Perhaps that other code should be moved to the checker?
Yes, the first request is returning candidates that result in
This is the simplest solution to the problem. In essence, we want completions that take into account what the user has already typed, but not to the extent that we filter out valid completions such as those that #48410 addressed. We are also considering a more comprehensive solution long term, but that may require more in-depth change to inference and needs further time for consideration and discussion. |
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.
Let’s pull in the extra test cases from @Andarist and then I’m good with this.
@andrewbranch perhaps it would be good to pull this into 5.1? I have some further improvements in mind for this, my tests might very well just get merged as part of those - I'm just waiting for this one to land to start working on a follow-up |
5.2* It’s @rbuckton’s PR to merge whenever he’s ready. |
Since this PR has conflicts and I was working on the code that created them, I resolved them cause I knew exactly how they should be resolved - but since I can't push to this branch I prepared a PR for you here: #54668 |
@rbuckton friendly 🏓 |
Is there anything left to do here? It's got conflicts, but it's approved by two people. |
I'm updating the PR, but it may have been broken by some of the changes in #53996 as it's no longer giving the expected results. I'm working out what the issue is and will post an update once that's been resolved. |
This issue appears to be that we no longer skip type argument inference from arguments when checking for string literal completions, and end up inferring
That PR lists 5000+ file changes and is too large for GitHub to render in the UI, so I'm not sure what changes you may have made. At least, that was an immediate difference that I noticed between when this PR was drafted and main. The change is here: https://github.com/microsoft/TypeScript/pull/53996/files#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8L32511-R32515 |
We can compare that branch directly against The only difference is in this expectation. This is basically the same test case that was introduced in #53996 and it could be removed from this PR to avoid duplication. I understand that perhaps the current expactation from this PR might be considered better but it isn't noticeable for the majority of end users. So maybe it's worth landing this PR without fixing it (as the PR's focus was to fix a different case anyway) and to open an issue about it? The expected results are at least consistent right now between both markers (see here) and I think that the ideal result is that they always should be the same. The only reason why they are different here is that the code path used for object property values completions is quite different from the code path used for string completions directly at argument positions. It's not because they should behave differently - they just happen to behave differently (maybe because it's a design limitation since it might be more complex to do what argument completions do within objects but still). |
I had to make other changes than what you've illustrated to get the expectations from the tests I added to pass, reverting a number of places where |
23628eb
to
c667870
Compare
Or not, it looks like it's still not quite correct. |
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.
this file can be removed since this test already got its way to the main
branch:
https://github.com/microsoft/TypeScript/blob/main/tests/cases/fourslash/stringCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes.ts
That's interesting! It turns out that for this one test the |
I managed to get it working again without those reverts. The proposed change also brings back your expected results for the That change is somewhat significant and perhaps bikesheddable so it might be best to leave it for a follow-up PR that I can open once this one lands. |
The change in Andarist@26c1127 doesn't seem too complex, but I agree we can tackle it in a follow-on PR. @andrewbranch can you take a quick look at this again before I merge? |
@andrewbranch, @jakebailey can one of you take a look over the latest changes? |
I'll fix the merge conflict with checker shortly |
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.
Still seems good to me.
This adopts the proposed fix mentioned in #49680 (comment). This is a different approach than the one taken by @Andarist in #52997, as that PR attempted to pre-filter results.
Fixes #49680
Supersedes #52997