Skip to content

Commit

Permalink
feat: provide LSP API support
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Oct 2, 2024
1 parent 5da7f64 commit b68473d
Show file tree
Hide file tree
Showing 78 changed files with 3,309 additions and 712 deletions.
460 changes: 460 additions & 0 deletions docs/LSPApi.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static void connectToLanguageServer(@NotNull VirtualFile file, @NotNull
// Server capabilities filter is set to null to avoid waiting
// for the start of the server when server capabilities are checked
LanguageServiceAccessor.getInstance(project)
.getLanguageServers(file, null);
.getLanguageServers(file, null, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.intellij.openapi.project.Project;
import com.redhat.devtools.lsp4ij.client.LanguageClientImpl;
import com.redhat.devtools.lsp4ij.server.StreamConnectionProvider;
import com.redhat.devtools.lsp4ij.client.features.LSPClientFeatures;
import org.eclipse.lsp4j.services.LanguageServer;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -50,4 +51,7 @@ public interface LanguageServerFactory {
return LanguageServer.class;
}

@NotNull default LSPClientFeatures createClientFeatures() {
return new LSPClientFeatures();
}
}
26 changes: 22 additions & 4 deletions src/main/java/com/redhat/devtools/lsp4ij/LanguageServerItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package com.redhat.devtools.lsp4ij;

import com.intellij.psi.PsiFile;
import com.redhat.devtools.lsp4ij.client.features.LSPClientFeatures;
import com.redhat.devtools.lsp4ij.features.semanticTokens.SemanticTokensColorsProvider;
import org.eclipse.lsp4j.*;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
Expand Down Expand Up @@ -52,6 +53,15 @@ public LanguageServerWrapper getServerWrapper() {
return serverWrapper;
}

/**
* Returns the LSP client features.
*
* @return the LSP client features.
*/
public LSPClientFeatures getClientFeatures() {
return getServerWrapper().getClientFeatures();
}

/**
* Returns the server capabilities of the language server.
*
Expand Down Expand Up @@ -340,12 +350,12 @@ public static boolean isImplementationSupported(@Nullable ServerCapabilities ser
}

/**
* Returns true if the language server can support folding and false otherwise.
* Returns true if the language server can support folding range and false otherwise.
*
* @param serverCapabilities the server capabilities.
* @return true if the language server can support folding and false otherwise.
* @return true if the language server can support folding range and false otherwise.
*/
public static boolean isFoldingSupported(@Nullable ServerCapabilities serverCapabilities) {
public static boolean isFoldingRangeSupported(@Nullable ServerCapabilities serverCapabilities) {
return serverCapabilities != null &&
hasCapability(serverCapabilities.getFoldingRangeProvider());
}
Expand Down Expand Up @@ -510,7 +520,7 @@ private static boolean hasCapability(Boolean capability) {
}

public SemanticTokensColorsProvider getSemanticTokensColorsProvider() {
return getServerWrapper().getServerDefinition().getSemanticTokensColorsProvider();
return getClientFeatures().getSemanticTokensFeature();
}

/**
Expand Down Expand Up @@ -542,4 +552,12 @@ public static boolean isWorkspaceSymbolSupported(@Nullable ServerCapabilities se
return serverCapabilities != null &&
hasCapability(serverCapabilities.getWorkspaceSymbolProvider());
}

public static boolean isUsageSupported(ServerCapabilities serverCapabilities) {
return LanguageServerItem.isDeclarationSupported(serverCapabilities) ||
LanguageServerItem.isTypeDefinitionSupported(serverCapabilities) ||
LanguageServerItem.isDefinitionSupported(serverCapabilities) ||
LanguageServerItem.isReferencesSupported(serverCapabilities) ||
LanguageServerItem.isImplementationSupported(serverCapabilities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.redhat.devtools.lsp4ij.lifecycle.LanguageServerLifecycleManager;
import com.redhat.devtools.lsp4ij.lifecycle.NullLanguageServerLifecycleManager;
import com.redhat.devtools.lsp4ij.server.*;
import com.redhat.devtools.lsp4ij.client.features.LSPClientFeatures;
import com.redhat.devtools.lsp4ij.server.definition.LanguageServerDefinition;
import org.eclipse.lsp4j.*;
import org.eclipse.lsp4j.jsonrpc.Launcher;
Expand Down Expand Up @@ -108,6 +109,8 @@ public class LanguageServerWrapper implements Disposable {

private FileOperationsManager fileOperationsManager;

private LSPClientFeatures clientFeatures;

/* Backwards compatible constructor */
public LanguageServerWrapper(@NotNull Project project, @NotNull LanguageServerDefinition serverDefinition) {
this(project, serverDefinition, null);
Expand Down Expand Up @@ -408,6 +411,9 @@ public void dispose() {
this.disposed = true;
stop();
stopDispatcher();
if (clientFeatures != null) {
clientFeatures.dispose();
}
}

public boolean isDisposed() {
Expand Down Expand Up @@ -708,7 +714,7 @@ public void disconnect(URI path, boolean stopIfNoOpenedFiles) {
synchronizer.getDocument().removeDocumentListener(synchronizer);
synchronizer.documentClosed();
}
if (stopIfNoOpenedFiles && this.connectedDocuments.isEmpty()) {
if (getClientFeatures().isServerStoppingRequiredWhenFilesClosed() && stopIfNoOpenedFiles && this.connectedDocuments.isEmpty()) {
if (this.serverDefinition.getLastDocumentDisconnectedTimeout() != 0 && !ApplicationManager.getApplication().isUnitTestMode()) {
removeStopTimer(true);
startStopTimer();
Expand Down Expand Up @@ -1174,4 +1180,20 @@ public boolean isSignatureTriggerCharactersSupported(String charTyped) {
}
return triggerCharacters.contains(charTyped);
}

public LSPClientFeatures getClientFeatures() {
if (clientFeatures == null) {
clientFeatures = getOrCreateClientFeatures();
}
return clientFeatures;
}

private synchronized LSPClientFeatures getOrCreateClientFeatures() {
if (clientFeatures != null) {
return clientFeatures;
}
LSPClientFeatures clientFeatures = getServerDefinition().createClientFeatures();
clientFeatures.setServerWrapper(this);
return clientFeatures;
}
}
Loading

0 comments on commit b68473d

Please sign in to comment.