Skip to content

Commit

Permalink
Fix NPE if the property ResolveProvider is null (#1001)
Browse files Browse the repository at this point in the history
Fix NPE if the property ResolveProvider is null
  • Loading branch information
rubenporras authored May 16, 2024
1 parent cb95569 commit b1fd992
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.eclipse.lsp4j.InsertTextMode;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.swt.SWT;
Expand Down Expand Up @@ -326,11 +327,8 @@ protected IInformationControl doCreateInformationControl(Shell parent) {

@Override
public String getAdditionalProposalInfo(IProgressMonitor monitor) {
if (languageServerWrapper.isActive()) {
CompletionOptions completionProvider = languageServerWrapper.getServerCapabilities().getCompletionProvider();
if (completionProvider != null && completionProvider.getResolveProvider()) {
resolveItem();
}
if (languageServerWrapper.isActive() && resolvesCompletionItem(languageServerWrapper.getServerCapabilities())) {
resolveItem();
}

final var res = new StringBuilder();
Expand All @@ -350,6 +348,17 @@ public String getAdditionalProposalInfo(IProgressMonitor monitor) {
return res.toString();
}

private boolean resolvesCompletionItem(final ServerCapabilities capabilities) {
if (capabilities != null) {
CompletionOptions completionProvider = capabilities.getCompletionProvider();
if (completionProvider != null) {
Boolean hasResolveProvider = completionProvider.getResolveProvider();
return hasResolveProvider != null && hasResolveProvider;
}
}
return false;
}

private void resolveItem() {
try {
languageServerWrapper.execute(ls -> ls.getTextDocumentService().resolveCompletionItem(item).thenAccept(this::updateCompletionItem))
Expand Down

0 comments on commit b1fd992

Please sign in to comment.