fix: Autocomplete wasn't being done by intellij
This commit is contained in:
parent
b8aa355392
commit
7754e8f2c8
2 changed files with 1 additions and 37 deletions
|
@ -27,6 +27,7 @@ Changelog structure reference:
|
||||||
|
|
||||||
- LSP
|
- LSP
|
||||||
- The registry IDs of some of the LSP handlers were colliding with the Rust intellij plugin
|
- The registry IDs of some of the LSP handlers were colliding with the Rust intellij plugin
|
||||||
|
- Autocompletion insertion is now fully handled by intellij, this should fix some of the weirdness
|
||||||
|
|
||||||
- Zig
|
- Zig
|
||||||
- Indent support for function parameters and struct initializers
|
- Indent support for function parameters and struct initializers
|
||||||
|
|
|
@ -764,8 +764,6 @@ public class EditorEventManager {
|
||||||
|
|
||||||
if (addTextEdits != null) {
|
if (addTextEdits != null) {
|
||||||
builder = builder.withInsertHandler((InsertionContext context, LookupElement lookupElement) -> invokeLater(() -> {
|
builder = builder.withInsertHandler((InsertionContext context, LookupElement lookupElement) -> invokeLater(() -> {
|
||||||
applyInitialTextEdit(item, context, lookupString);
|
|
||||||
|
|
||||||
if (format == InsertTextFormat.Snippet) {
|
if (format == InsertTextFormat.Snippet) {
|
||||||
context.commitDocument();
|
context.commitDocument();
|
||||||
prepareAndRunSnippet(lookupString);
|
prepareAndRunSnippet(lookupString);
|
||||||
|
@ -779,8 +777,6 @@ public class EditorEventManager {
|
||||||
}));
|
}));
|
||||||
} else if (command != null) {
|
} else if (command != null) {
|
||||||
builder = builder.withInsertHandler((InsertionContext context, LookupElement lookupElement) -> {
|
builder = builder.withInsertHandler((InsertionContext context, LookupElement lookupElement) -> {
|
||||||
applyInitialTextEdit(item, context, lookupString);
|
|
||||||
|
|
||||||
if (format == InsertTextFormat.Snippet) {
|
if (format == InsertTextFormat.Snippet) {
|
||||||
context.commitDocument();
|
context.commitDocument();
|
||||||
prepareAndRunSnippet(lookupString);
|
prepareAndRunSnippet(lookupString);
|
||||||
|
@ -790,8 +786,6 @@ public class EditorEventManager {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
builder = builder.withInsertHandler((InsertionContext context, LookupElement lookupElement) -> {
|
builder = builder.withInsertHandler((InsertionContext context, LookupElement lookupElement) -> {
|
||||||
applyInitialTextEdit(item, context, lookupString);
|
|
||||||
|
|
||||||
if (format == InsertTextFormat.Snippet) {
|
if (format == InsertTextFormat.Snippet) {
|
||||||
context.commitDocument();
|
context.commitDocument();
|
||||||
prepareAndRunSnippet(lookupString);
|
prepareAndRunSnippet(lookupString);
|
||||||
|
@ -802,37 +796,6 @@ public class EditorEventManager {
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyInitialTextEdit(CompletionItem item, InsertionContext context, String lookupString) {
|
|
||||||
if (item.getTextEdit() != null) {
|
|
||||||
// remove intellij edit, server is controlling insertion
|
|
||||||
writeAction(() -> {
|
|
||||||
Runnable runnable = () -> this.editor.getDocument().deleteString(context.getStartOffset(), context.getTailOffset());
|
|
||||||
|
|
||||||
CommandProcessor.getInstance()
|
|
||||||
.executeCommand(project, runnable, "Removing Intellij Completion", "LSPPlugin", editor.getDocument());
|
|
||||||
});
|
|
||||||
context.commitDocument();
|
|
||||||
|
|
||||||
if(item.getTextEdit().isLeft()) {
|
|
||||||
item.getTextEdit().getLeft().setNewText(getLookupStringWithoutPlaceholders(item, lookupString));
|
|
||||||
}
|
|
||||||
|
|
||||||
applyEdit(Integer.MAX_VALUE, Collections.singletonList(item.getTextEdit()), "text edit", false, true);
|
|
||||||
} else {
|
|
||||||
// client handles insertion, determine a prefix (to allow completions of partially matching items)
|
|
||||||
int prefixLength = getCompletionPrefixLength(context.getStartOffset());
|
|
||||||
|
|
||||||
writeAction(() -> {
|
|
||||||
Runnable runnable = () -> this.editor.getDocument().deleteString(context.getStartOffset() - prefixLength, context.getStartOffset());
|
|
||||||
|
|
||||||
CommandProcessor.getInstance()
|
|
||||||
.executeCommand(project, runnable, "Removing Prefix", "LSPPlugin", editor.getDocument());
|
|
||||||
});
|
|
||||||
context.commitDocument();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getCompletionPrefixLength(int offset) {
|
private int getCompletionPrefixLength(int offset) {
|
||||||
return getCompletionPrefix(this.editor, offset).length();
|
return getCompletionPrefix(this.editor, offset).length();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue