-
Notifications
You must be signed in to change notification settings - Fork 401
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
Only do context sensitive import rewrite when resolving completion items #2453
Conversation
- fix the performance downgrade introduced by eclipse-jdtls#2232. With that change, triggering completion via keyboard shortcut will take a long time. Now with the change, it will only do context sensitive import rewrite when resolving completion items. Signed-off-by: Sheng Chen <[email protected]>
@jdneo You may want to take a look at
|
@snjeza Yes, I noticed that as well. And that really makes me a little bit confused. My understand for that is all other properties can be updated during resolve except for sortText, filterText, insertText and textEdit. |
I think you can define these properties using
You should add |
AFAIK If I remember clearly, vscode doesn't guarentee you have correct behavior in some edge cases. But personally I'm ok with the "tradeoff" if it speeds up the completion a lot. |
...rc/org/eclipse/jdt/ls/core/internal/contentassist/CompletionProposalReplacementProvider.java
Outdated
Show resolved
Hide resolved
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.
Change works well for me.
Feel free to merge once comments are addressed.
Signed-off-by: sheche <[email protected]>
One more update for the LSP spec. See the discussion here: microsoft/language-server-protocol#1669. This discussion shows that, the correctness of textedit for each completion item is not a hard requirement anymore. It can be updated during the I feel that there is some chance here to make the completion perf great again! 🤣 |
This change fixes the performance downgrade introduced by #2232.
How to reproduce the performance downgrade?
ctrl
+space
) afterS
S
, the time is normal.Why same completion requests can result different performance?
The request is the same, but at the server side, state of
SharedASTProviderCore
is different.S
, the document is changed,SharedASTProviderCore
is not ready to give a parsed AST tree.ctrl
+space
, usually theSharedASTProviderCore
is readyThis causes the argument passed to
importRewrite.addImport()
are different.To verify this, we can set a breakpoint at
https://github.com/eclipse/eclipse.jdt.ls/blob/438e6192cc327960f82d3086bc5f374a5cfaeca7/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/CompletionProposalReplacementProvider.java#L1039
Usually, if the
textDocument/completion
request is sent by typingS
, the breakpoint won't be hit.It raises another question: if the
context
isnull
when the completion is triggered by typing events, why the fix still works?The answer is: The text edit will be corrected during
completionItem/resolve
request. When the resolving request comes, especially when the item is not the first one,SharedASTProviderCore
has enough time to prepare the AST, so the context won't benull
.Same thing applies to triggering completion via
ctrl
+space
. Thisnon-null
context causes much more calculation to get a more accurate completion. As a tradeoff, we lose the performance.About LSP violation
Unfortunately, updating text edit during
completionItem/resolve
request violates the LSP spec.A direct idea is to append additional text edit during resolve request to avoid such violation. Unfortunately, this is still unacceptable:
So far, I couldn't figure out a way to fix the perf downgrade as well as the spec violation. Current change fixes the perf issue but the spec violation is still there.
Considering that the case mentioned in #2232 is a rare case, and usually the resolve response should be arrived before user commits a completion item. I think it's acceptable.
Signed-off-by: Sheng Chen [email protected]