-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Include replacementSpan in member completions
#57480
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
Include replacementSpan in member completions
#57480
Conversation
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 have confirmed manually that those were broken in the very same way as the referenced issue - the existing modifiers were not removed and since the insertText had them the new source text of the file was broken because they got duplicated
src/services/completions.ts
Outdated
| } | ||
|
|
||
| return { insertText, filterText, isSnippet, importAdder, eraseRange }; | ||
| return { insertText, filterText, isSnippet, importAdder, replacementSpan: eraseRange && createTextSpanFromBounds(eraseRange.pos, eraseRange.end) }; |
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.
The first commit is much smaller because it just includes converting the eraseRange to replacementSpan at one call site. However, I concluded that since we are in getEntryForMemberCompletion and completions are replacementSpan-oriented it should return replacementSpan and the other caller should become responsible for converting it back to a range (before passing it to tracker.deleteRange)
|
@typescript-bot pack this |
|
Hey @iisaduan, 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 |
iisaduan
left a comment
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.
Thanks for finding the other cases that break in the same way!
However, I don't think this is the correct fix, as when I try to use this version in the editor, it completely removes the completions from (all) the marked locations.

I did by chance happen to be in an old version of TS where the first test case worked, so with some quick checking, the bug seems to be a regression bug that happened between 5.1.6 and 5.2.2.
|
Interesting, I'll take another look at this soon. |
…ryForMemberCompletion`" This reverts commit 7545dcd.
|
Thanks for testing this out in VS Code. I made the mistake of assuming that this would just work - the local tests here looked alright and this exact thing ( However, it turns out... that it can't work today in this form. VS Code assumes certain things about the replace ranges. So while this technically could be a fine change in TS... it just doesn't work well when integrating with VS Code. For starters, replace ranges can't span multiple lines (see the check here). The range computed by But that's still not good. VS Code also assumes that the replacement range contains part of the "word" that is meant to be replaced. Since the target word here is I could fight this by adjusting the So my next bet was to use code actions to do this. I pushed out draft changes doing that (without adjusting the test cases, I hope that it's not the problem at this stage) so you could test it out. It's far from perfect right now. The
I either didn't find the correct combination of things to do this correctly today or there is some API gap here that would have to be filled. I somewhat doubt that VS Code would be able to change their assumptions about replacement ranges right now (no support for multiline and treating that whole range as part of the target word). |
This reverts commit dc270ed.
|
I have implemented this using |
|
@typescript-bot pack this |
|
Starting jobs; this comment will be updated as builds start and complete.
|
|
Hey @iisaduan, 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 |
From what I remember, if we include modifiers in the The other course of action I can think of to fix this is to omit existing modifiers from the completion, but now if the modifier order is wrong or you need to add a modifier before the existing one, you can't. It really does look like what we need is to use a |
That would be the most straightforward thing to do here (with the best UX and DX) - on this end at least :p So I very much agree that if that's the possibility then it would be great to explore it. |
|
We discussed offline, and our current plan is to accept #57643 with the code action, leave Thank you for such a thorough investigation! |
fixes #57301