-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
Investigate resolving and inserting additional text edits async #96779
Comments
The first version for this is now merged to master, it's a pragmatic approach that's better then not resolving but worst than (costly) upfront resolving. Items to followup on
|
/cc @jdneo - My understanding is that Java resolves all items upfront, e.g compute additional text edits during "provide", and that it is quite expensive and therefore Java only returns a small amount of items. Is that correct? Could Java return results faster when additional text edits are computed during resolve (and therefore only for selected items)? |
Yes.
I think so! @Eskibear is the dev who was working on Java completion. I believe he can provide more insights toward this topic. // cc @akaroml @testforstephen @fbricon |
@jrieken this is exactly the behavior that jdt.ls used to have, ie compute all the completion items first (fast), then the text edits were computed during resolveCompletion. We were asked to not do that as it was not spec'ed that way and changed to return a small subset of completion items (with incomplete=true), with full text edits computed upfront. The user experience is definitely not as good as with our initial implementation. |
To be clear, computing any Java textedit upfront is costly when returning 100+ items (and we can return several thousands items). We'd prefer if the async insertion of textedits covered all textedits, not just the additional ones. |
The requirements discussed in eclipse-jdtls/eclipse.jdt.ls#465 are still true and there are no plans to change that. There is |
When exactly does I only need to generate I assume no one would need to generate Is there any kind of completion applied event we can hook into to work around this for the time being? |
That's exactly what this issue is about 🔝. Today, there is no guarantee that
Well, this is the problem if you do not generate them upfront.
Solutions:
(*) "if possible" is currently defined as "no edit has occurred before the first additional edit". That works well if you use additional edits for things like imports or prefixes (which is the indented use-case) but won't work if additional text edits change the main edit, like appending a call-operators with arguments etc |
I mean JS can't block but ignoring typing while awaiting is possible -- I was imagining that VSCode would keep the completions menu open and ignore any typing until Obviously this would be bad if resolving takes a long time, but the API has cancelation tokens already, so the UI would just need to show a spinner/cancel icon, and also cancel if the user presses ESC or navigates to a different editor, for a decent UX. I think this would be less confusing for users too; it's the only way it would be clear when VSCode is completely done applying the completion. I think many users would be confused if imports usually get added but not when they resume typing too soon. FWIW I can syncronously generate the additional text edits I need, so I'd be happy if there were an API to synchronously generate them when the completion item is accepted. I know not everyone would be able to generate them sync though. |
Also I know my questions may have seemed redundant, but I hadn't seen anyone on this thread point out that it would be ideal to avoid ever computing additional text edits (or even the primary insert text) for unselected completions. Since |
The golden rule is that "you can always type inside the editor". Ignoring typing is not a good solution and will bug users. Just think of quick suggest and auto accept characters - you don't want the editor to stop typing just because an extension is taking a little longer (+50ms).
To be precise you should have written "typing at or before the offset at which additional edits are going to happen"
I honestly think the majority can generate them synchronously but this happens in the extension host process or the language server process, and all of that might happen on a different machine and there is no way to synchronously transport that into the UI. |
@fbricon re #96779 (comment) with the current changes you should be able to have a "simple insert text", say |
@jrieken that might actually be a good idea ;-) In practice though, we might need to revisit the way the principal TextEdit is computed (i.e rewrite a bunch of stuff from upstream JDT) |
I get the desire to be able to always be able to type inside the editor and agree that's an important principle. The only reason I think this case is an exception is that:
On the other hand, I guess it's unlikely that the additional text edits would overlap whatever the user continues typing... |
I hadn't thought about auto accept characters though, that's a good point. That's something I don't have experience with. Also considering that VSCode could pop up a warning if it has to bail on inserting additional edits, it's not a big deal if it ever happens |
@Eskibear I remember that we have some new data points regarding the time consumption in different stages of code completion in jdt.ls. Can you share that data and see how we can tune it with this change? |
I just realized that |
Closing as we haven't seen issues with the new pragmatic approach and the plan is to stick with it. |
@jrieken so how do servers know that clients support lazy-loading of additional textedits? Surely this should be a client capability advertised by vscode (that needs to be specced in the LSP) |
@dbaeumer is the right person for that ☝️ and you should probably create a follow up issue in the LSP land |
corresponding LSP feature request created here microsoft/language-server-protocol#1003 please add more details if I miss anything. |
Thanks @Eskibear |
To verify:
|
This is somewhat the opposite of #87187 and the acknowledgement that computing additional text edits for all items upfront is too demanding. This issue is only about
additionalTextEdits
and the goal is a pragmatic solution, similar to the one that we have for format on type. IdeaThe text was updated successfully, but these errors were encountered: