Skip to content

Commit

Permalink
Adapt to latest LSP4E
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelistria committed Nov 17, 2023
1 parent 29f6fad commit 3ed5d71
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
3 changes: 2 additions & 1 deletion org.eclipse.corrosion/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Bundle-Vendor: %Bundle-Vendor
Require-Bundle: org.eclipse.core.contenttype,
org.eclipse.ui.genericeditor;bundle-version="1.0.1",
org.eclipse.ui,
org.eclipse.lsp4e;bundle-version="0.9.0",
org.eclipse.lsp4e;bundle-version="0.17.0",
org.eclipse.tm4e.core,
org.eclipse.tm4e.ui,
org.eclipse.core.runtime;bundle-version="3.22.0",
Expand Down Expand Up @@ -51,3 +51,4 @@ Export-Package: org.eclipse.corrosion;x-friends:="org.eclipse.corrosion.tests",
org.eclipse.corrosion.snippet;x-friends:="org.eclipse.corrosion.tests",
org.eclipse.corrosion.wizards.export;x-friends:="org.eclipse.corrosion.tests",
org.eclipse.corrosion.wizards.newproject;x-friends:="org.eclipse.corrosion.tests"
Import-Package: org.eclipse.jdt.annotation
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.ecf.filetransfer.service.IRetrieveFileTransfer;
import org.eclipse.ecf.filetransfer.service.IRetrieveFileTransferFactory;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.lsp4e.LanguageServersRegistry;
import org.eclipse.lsp4e.LanguageServersRegistry.LanguageServerDefinition;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
Expand Down Expand Up @@ -361,4 +364,8 @@ private static boolean startBundle(String bundleId) {
}
return false;
}

public static @NonNull LanguageServerDefinition languageServerDefinition() {
return LanguageServersRegistry.getInstance().getDefinition("org.eclipse.corrosion.rls"); //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ private static void sendDidChangeConfigurationsMessage(Map<String, String> updat
params.setSettings(updatedSettings);
LSPDocumentInfo info = infoFromOpenEditors();
if (info != null) {
info.getInitializedLanguageClient()
.thenAccept(languageServer -> languageServer.getWorkspaceService().didChangeConfiguration(params));
info.getLanguageServerWrapper().sendNotification(languageServer -> languageServer.getWorkspaceService().didChangeConfiguration(params));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public IStatus run(IProgressMonitor monitor) {
params.setContext(new ReferenceContext(true));
params.setTextDocument(new TextDocumentIdentifier(info.getFileUri().toString()));
params.setPosition(position);
info.getInitializedLanguageClient()
.thenCompose(languageServer -> ((RLSServerInterface) languageServer).implementations(params))
info.getLanguageServerWrapper()
.execute(languageServer -> ((RLSServerInterface) languageServer).implementations(params))
.thenAccept(locs -> {
// Loop for each LSP Location and convert it to Match search.
for (Location loc : locs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.corrosion.test.actions;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand All @@ -29,6 +30,7 @@
import org.eclipse.jface.action.Action;
import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.lsp4e.LanguageServerPlugin;
import org.eclipse.lsp4e.LanguageServerWrapper;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Position;
Expand All @@ -38,7 +40,6 @@
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.unittest.model.ITestCaseElement;
Expand Down Expand Up @@ -69,13 +70,17 @@ public void run() {
if (project == null) {
return;
}
List<LanguageServer> languageServers = LanguageServiceAccessor.getLanguageServers(project,
capabilities -> Boolean.TRUE.equals(capabilities.getWorkspaceSymbolProvider().get()));
if (languageServers != null && languageServers.isEmpty()) {
LanguageServerWrapper languageServer = null;
try {
languageServer = LanguageServiceAccessor.getLSWrapper(project, CorrosionPlugin.languageServerDefinition());
} catch (IOException ex) {
CorrosionPlugin.logError(ex);
}
if (languageServer == null) {
return;
}
SymbolKind kind = fTestElement instanceof ITestCaseElement ? SymbolKind.Function : SymbolKind.Module;
List<SymbolInformation> result = getQualifiedSymbols(languageServers, fTestElement.getTestName(), kind);
List<SymbolInformation> result = getQualifiedSymbols(languageServer, fTestElement.getTestName(), kind);
if (result == null || result.isEmpty()) {
return;
}
Expand Down Expand Up @@ -108,7 +113,7 @@ private static IProject getProject(ITestElement element) {
return null;
}

private static List<SymbolInformation> getQualifiedSymbols(List<LanguageServer> languageServers, String path,
private static List<SymbolInformation> getQualifiedSymbols(LanguageServerWrapper languageServer, String path,
SymbolKind kind) {
List<SymbolInformation> result = new ArrayList<>();

Expand All @@ -123,7 +128,7 @@ private static List<SymbolInformation> getQualifiedSymbols(List<LanguageServer>
String parent = i > 0 ? pathArray[i - 1] : null;
SymbolKind expectedKind = i < pathArray.length - 1 ? SymbolKind.Module : kind;

List<SymbolInformation> symbols = getSymbols(languageServers, name, parent, expectedKind);
List<SymbolInformation> symbols = getSymbols(languageServer, name, parent, expectedKind);
List<SymbolInformation> currents;
if (parents != null) {
List<SymbolInformation> matches = new ArrayList<>();
Expand All @@ -150,30 +155,27 @@ private static List<SymbolInformation> getQualifiedSymbols(List<LanguageServer>
return parents;
}

private static List<SymbolInformation> getSymbols(List<LanguageServer> languageServers, String name, String parent,
private static List<SymbolInformation> getSymbols(LanguageServerWrapper languageServer, final String name, String parent,
SymbolKind kind) {
List<SymbolInformation> result = new ArrayList<>();

for (LanguageServer server : languageServers) {
WorkspaceSymbolParams params = new WorkspaceSymbolParams(name);
CompletableFuture<Either<List<? extends SymbolInformation>, List<? extends WorkspaceSymbol>>> symbols = server
.getWorkspaceService().symbol(params);

try {
List<?> items = (List<?>) symbols.get(10, TimeUnit.SECONDS).get();
if (items != null) {
for (Object item : items) {
SymbolInformation match = getMatchingItem(item, name, parent, kind);
if (match != null) {
result.add(match);
}
WorkspaceSymbolParams params = new WorkspaceSymbolParams(name);
CompletableFuture<Either<List<? extends SymbolInformation>, List<? extends WorkspaceSymbol>>> symbols = languageServer.execute(ls -> ls.getWorkspaceService().symbol(params));

try {
List<?> items = (List<?>) symbols.get(10, TimeUnit.SECONDS).get();
if (items != null) {
for (Object item : items) {
SymbolInformation match = getMatchingItem(item, name, parent, kind);
if (match != null) {
result.add(match);
}
}
} catch (ExecutionException | TimeoutException e) {
LanguageServerPlugin.logError(e);
} catch (InterruptedException e) {
LanguageServerPlugin.logError(e);
}
} catch (ExecutionException | TimeoutException e) {
LanguageServerPlugin.logError(e);
} catch (InterruptedException e) {
LanguageServerPlugin.logError(e);
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion repository/corrosion.product
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ United States, other countries, or both.
</plugins>

<features>
<feature id="org.eclipse.epp.package.common.feature" version="4.28.0.qualifier"/>
<feature id="org.eclipse.epp.package.common.feature"/>
<feature id="org.eclipse.platform"/>
<feature id="org.eclipse.epp.mpc" installMode="root"/>
<feature id="org.eclipse.justj.openjdk.hotspot.jre.full" installMode="root"/>
Expand Down

0 comments on commit 3ed5d71

Please sign in to comment.