Skip to content

Commit

Permalink
API: Port hover to use new API
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedneilhussain committed Jan 23, 2023
1 parent 2dcd922 commit c127214
Showing 1 changed file with 11 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
import org.eclipse.jface.text.Region;
import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.lsp4e.LanguageServerPlugin;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4e.LanguageServers;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.HoverParams;
import org.eclipse.lsp4j.MarkedString;
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
Expand Down Expand Up @@ -193,28 +194,15 @@ public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
private void initiateHoverRequest(@NonNull ITextViewer viewer, int offset) {
final IDocument document = viewer.getDocument();
this.lastViewer = viewer;
this.request = LanguageServiceAccessor
.getLanguageServers(document, capabilities -> LSPEclipseUtils.hasCapability(capabilities.getHoverProvider()))
.thenApplyAsync(languageServers -> // Async is very important here, otherwise the LS Client thread is in
// deadlock and doesn't read bytes from LS
languageServers.stream()
.map(languageServer -> {
try {
return languageServer.getTextDocumentService()
.hover(LSPEclipseUtils.toHoverParams(offset, document))
.get(GET_TIMEOUT_MS, TimeUnit.MILLISECONDS);
} catch (ExecutionException | BadLocationException e) {
LanguageServerPlugin.logError(e);
return null;
} catch (InterruptedException e) {
LanguageServerPlugin.logError(e);
Thread.currentThread().interrupt();
return null;
} catch (TimeoutException e) {
LanguageServerPlugin.logWarning("Could not get hover due to timeout after " + GET_TIMEOUT_MS + " miliseconds", e); //$NON-NLS-1$ //$NON-NLS-2$
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList()));
try {
HoverParams params = LSPEclipseUtils.toHoverParams(offset, document);

this.request = LanguageServers.forDocument(document)
.withFilter(capabilities -> LSPEclipseUtils.hasCapability(capabilities.getHoverProvider()))
.collectAll((wapper, server) -> server.getTextDocumentService().hover(params));
} catch (BadLocationException e) {
LanguageServerPlugin.logError(e);
}
}

@Override
Expand Down

0 comments on commit c127214

Please sign in to comment.