Skip to content

Commit

Permalink
Method/function completions don't (consistently?) use an insert handler
Browse files Browse the repository at this point in the history
with parens for args

Fixes redhat-developer#610

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Nov 25, 2024
1 parent 714810b commit f9f7a9a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ public LSPClientFeatures getClientFeatures() {
}

private synchronized LSPClientFeatures getOrCreateClientFeatures() {
if (clientFeatures != null) {
if (clientFeatures != null && !clientFeatures.isDisposed()) {
return clientFeatures;
}
LSPClientFeatures clientFeatures = getServerDefinition().createClientFeatures();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1193,4 +1193,7 @@ public TextDocumentServerCapabilityRegistry<? extends TextDocumentRegistrationOp
return null;
}

public boolean isDisposed() {
return serverWrapper == null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public LSPCompletionProposal(@NotNull CompletionItem item,

@Override
public void handleInsert(@NotNull InsertionContext context) {
updateCompletionItemFromResolved();
Template template = null;
if (item.getInsertTextFormat() == InsertTextFormat.Snippet) {
// Insert text has snippet syntax, ex : ${1:name}
Expand Down Expand Up @@ -137,6 +138,22 @@ public void handleInsert(@NotNull InsertionContext context) {
}
}

private void updateCompletionItemFromResolved() {
CompletionItem resolved = resolvedCompletionItemFuture != null ? resolvedCompletionItemFuture.getNow(null) : null;
if(resolved == null) {
return;
}
if (resolved.getInsertTextFormat() != null) {
item.setInsertTextFormat(resolved.getInsertTextFormat());
}
if (resolved.getInsertText() != null) {
item.setInsertText(resolved.getInsertText());
}
if (resolved.getInsertTextMode() != null) {
item.setInsertTextMode(resolved.getInsertTextMode());
}
}

/**
* Returns true if the given template must be executed and false otherwise.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public void refreshEditorFeature(@NotNull VirtualFile file,
})
.coalesceBy(file, featureType, clearLSPCache)
.finishOnUiThread(ModalityState.any(), context -> {
if (context == null) {
// No opened editors associated from any language servers.
return;
}
DaemonCodeAnalyzer.getInstance(project).restart(context.file());
for (var runnable : context.runnables()) {
runnable.run();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"completions": {
"completeFunctionCalls": true
},
"typescript": {
"inlayHints": {
"includeInlayEnumMemberValueHints": true,
Expand Down

0 comments on commit f9f7a9a

Please sign in to comment.