-
Notifications
You must be signed in to change notification settings - Fork 147
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
fix: wrong import completion when insert/replace supported #592
Conversation
if (isSnippet && !features.completionSnippets) { | ||
return null; | ||
} | ||
if (features.completionSnippets && (isSnippet || entry.isImportStatementCompletion || item.kind === lsp.CompletionItemKind.Function || item.kind === lsp.CompletionItemKind.Method)) { | ||
if (features.completionSnippets && (isSnippet || item.kind === lsp.CompletionItemKind.Function || item.kind === lsp.CompletionItemKind.Method)) { |
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 entry.isImportStatementCompletion
check was removed as it's only provided by TS for telemetry reasons and isSnippet
check covers that case already.
return item; | ||
} | ||
|
||
function getRangeFromReplacementSpan( |
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 function is pretty similar to what VS Code does:
// vscode/extensions/typescript-language-features/src/languageFeatures/completions.ts
private getRangeFromReplacementSpan(tsEntry: Proto.CompletionEntry, completionContext: CompletionContext) {
if (!tsEntry.replacementSpan) {
return;
}
let replaceRange = typeConverters.Range.fromTextSpan(tsEntry.replacementSpan);
// Make sure we only replace a single line at most
if (!replaceRange.isSingleLine) {
replaceRange = new vscode.Range(replaceRange.start.line, replaceRange.start.character, replaceRange.start.line, completionContext.line.length);
}
// If TS returns an explicit replacement range, we should use it for both types of completion
return {
inserting: replaceRange,
replacing: replaceRange,
};
}
So basically if an entry has a replacementSpan, VS Code uses that replacementSpan for both insert and replace.
You took a little different approach, but it works.
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.
VSCode doesn't use LSP so we can't use exactly same code but yes, it's based on VSCode's logic.
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 fixes the regression ✅
Fixes regression for clients that have
insertReplaceSupport
where completing:would result in incorrect insert:
The TextEdit in this case would be:
and the problem would be in the
insert
range.We should not be providing both insert and replace ranges when TS completion entry has its own
replacementSpan
provided as in that case it's the only valid option.@predragnikolic