Skip to content

Commit

Permalink
New api: Add support for direct use of branched server capabilities P…
Browse files Browse the repository at this point in the history
…OJOs

Implement review actions/tidy null checks
  • Loading branch information
ahmedneilhussain committed Jan 23, 2023
1 parent c127214 commit 38bab6b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 11 additions & 0 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServers.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.text.IDocument;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageServer;

/**
Expand Down Expand Up @@ -182,6 +183,16 @@ public E withFilter(final @NonNull Predicate<ServerCapabilities> filter) {
return (E)this;
}

/**
* Specifies the capabilities that a server must have to process this request
* @param serverCapabilities
* @return
*/
public E withCapability(final @NonNull Function<ServerCapabilities, Either<Boolean, ? extends Object>> serverCapabilities) {
this.filter = f -> LSPEclipseUtils.hasCapability(serverCapabilities.apply(f));
return (E)this;
}

/**
*
* @return Predicate that will be used to determine which servers this executor will use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.lsp4j.HoverParams;
import org.eclipse.lsp4j.MarkedString;
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.mylyn.wikitext.markdown.MarkdownLanguage;
import org.eclipse.mylyn.wikitext.parser.MarkupParser;
Expand All @@ -62,7 +63,7 @@ public class LSPTextHover implements ITextHover, ITextHoverExtension {

private IRegion lastRegion;
private ITextViewer lastViewer;
private CompletableFuture<List<Hover>> request;
private CompletableFuture<@NonNull List<@NonNull Hover>> request;

@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
Expand Down Expand Up @@ -193,13 +194,16 @@ public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
*/
private void initiateHoverRequest(@NonNull ITextViewer viewer, int offset) {
final IDocument document = viewer.getDocument();
if (document == null) {
return;
}
this.lastViewer = viewer;
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));
.withCapability(ServerCapabilities::getHoverProvider)
.collectAll(server -> server.getTextDocumentService().hover(params));
} catch (BadLocationException e) {
LanguageServerPlugin.logError(e);
}
Expand Down

0 comments on commit 38bab6b

Please sign in to comment.