-
Notifications
You must be signed in to change notification settings - Fork 29k
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
auto complete should replace if the response returns a text edit with range value #85741
Comments
Pretty sure this isn't us. Having |
Actually the same Java extension works at 1.39.0. This issue just appears in the latest VS Code version 1.40.2. Looks like a regression in VS Code. |
Ping on #85741 (comment) |
Pretty sure that Java uses |
To be honest, i didn't fully get what you mean. Is there any bug to explain why changed the behavior in recent 1.40? |
I don't recall any change that would affect this (and be unnoticed for the long time 1.40 is out). What I am trying to say is that I am certain that this is an issue with the Java extension. |
I'm curious that this Java feature is implemented a long long time ago, and it always works. For example, in previous 1.39, it also shows Besides, is there any documentation to explain the expected behavior for the dot case? In case someone else gets the same error, and wants a reference. Because from the lsp documentation about completion, it just says the range in the text edit should contains the position at which the completion has been requested. It didn't say the range cannot contain the prefix before dot (e.g. java.).
|
I can actually reproduce with insiders and Java dev containers but I don't understand what's going on. With a completion item like below (vscode.dts-land) I get what's expected, e.g after
|
I cannot reproduce using the lsp-sample and this LSP suggestion
@testforstephen Can you reproduce with the lsp-sample? What message do I need to send to reproduce this? |
// This handler provides the initial list of the completion items.
connection.onCompletion(
(_textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
// The pass parameter contains the position of the text document in
// which code complete got requested. For the example we ignore this
// info and always provide the same completion items.
return [
{
label: 'TypeScript',
kind: CompletionItemKind.Text,
data: 1
},
{
label: 'JavaScript',
kind: CompletionItemKind.Text,
data: 2
},
{
label: 'java.awt',
kind: CompletionItemKind.Module,
data: 3
}
];
}
);
// This handler resolves additional information for the item selected in
// the completion list.
connection.onCompletionResolve(
(item: CompletionItem): CompletionItem => {
if (item.data === 1) {
item.detail = 'TypeScript details';
item.documentation = 'TypeScript documentation';
} else if (item.data === 2) {
item.detail = 'JavaScript details';
item.documentation = 'JavaScript documentation';
}
else if (item.data === 3) {
item.detail = 'Java details';
item.documentation = 'Java documentation';
item.textEdit = { newText: 'java.awt', range: { start: { line: 1, character: 7 }, end: { line: 1, character: 12 } } };
}
return item;
}
); Stop at |
Oh, it happens when resolving... But it seem that you only set the textEdit/range when resolving. That's not really supported because it will change the ranking and sorting and it will yield in unexpected results. Resolve should only be used for details/doc and for nothing that influences the insert behaviour. Has your extension always been doing that? |
Yes, the Java extension doesn't calculate textEdit property during completion response, and it will lazy set it during resolving. |
That's not good and you are lucky that this has been working in the past. I believe it was a coincidence because in the past we didn't cache ranges of completion items - something that we have changed for #10266. For sorting and filtering the range (derived from the edit) is needed because it defines what leading text to compare with. Also there is no guarantee that resolve is called at all, and when inserting/accepting an item we do not await resolving (this is some background why we cannot do that). There is doc about that but I will make sure this is more clear and that we print warnings when resolve is doing too much. For the Java-extension the only way out is to return items that are ready to be inserted when |
got that, thanks for the discussion. |
Closing this as question. I have also created #86122 follow-up on our side to be more explicit (telemetry, logging) about this. |
We have a great developer community over on slack where extension authors help each other. This is a great place for you to ask questions and find support. Happy Coding! |
VS Code version:
When i manually type
import java.
in Java file, it didn't replace the words. See the gif.Below is the completion response returned by the Java LS. Actually it returns a textEdit to replace the target range with the newText, but looks like VS Code didn't apply the TextEdit well.
The text was updated successfully, but these errors were encountered: