From afd020ce9cb35d91d3492c6650b2e06f9789e3e9 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Fri, 17 Nov 2023 14:25:10 +0100 Subject: [PATCH 1/5] Adapt to latest LSP4E --- org.eclipse.corrosion/META-INF/MANIFEST.MF | 3 +- .../eclipse/corrosion/CorrosionPlugin.java | 7 +++ .../org/eclipse/corrosion/RustManager.java | 3 +- .../ImplementationsSearchQuery.java | 4 +- .../test/actions/OpenTestAction.java | 52 ++++++++++--------- repository/corrosion.product | 2 +- 6 files changed, 40 insertions(+), 31 deletions(-) diff --git a/org.eclipse.corrosion/META-INF/MANIFEST.MF b/org.eclipse.corrosion/META-INF/MANIFEST.MF index 3b8314d..2d7e0dd 100644 --- a/org.eclipse.corrosion/META-INF/MANIFEST.MF +++ b/org.eclipse.corrosion/META-INF/MANIFEST.MF @@ -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", @@ -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 diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPlugin.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPlugin.java index eb1bb83..a3ab03c 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPlugin.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/CorrosionPlugin.java @@ -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; @@ -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$ + } } diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java index 1444acb..073fbce 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java @@ -177,8 +177,7 @@ private static void sendDidChangeConfigurationsMessage(Map 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)); } } diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/extensions/ImplementationsSearchQuery.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/extensions/ImplementationsSearchQuery.java index 8c1003c..09d175d 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/extensions/ImplementationsSearchQuery.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/extensions/ImplementationsSearchQuery.java @@ -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) { diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/test/actions/OpenTestAction.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/test/actions/OpenTestAction.java index 675853c..d8d8dc8 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/test/actions/OpenTestAction.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/test/actions/OpenTestAction.java @@ -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; @@ -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; @@ -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; @@ -69,13 +70,17 @@ public void run() { if (project == null) { return; } - List 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 result = getQualifiedSymbols(languageServers, fTestElement.getTestName(), kind); + List result = getQualifiedSymbols(languageServer, fTestElement.getTestName(), kind); if (result == null || result.isEmpty()) { return; } @@ -108,7 +113,7 @@ private static IProject getProject(ITestElement element) { return null; } - private static List getQualifiedSymbols(List languageServers, String path, + private static List getQualifiedSymbols(LanguageServerWrapper languageServer, String path, SymbolKind kind) { List result = new ArrayList<>(); @@ -123,7 +128,7 @@ private static List getQualifiedSymbols(List String parent = i > 0 ? pathArray[i - 1] : null; SymbolKind expectedKind = i < pathArray.length - 1 ? SymbolKind.Module : kind; - List symbols = getSymbols(languageServers, name, parent, expectedKind); + List symbols = getSymbols(languageServer, name, parent, expectedKind); List currents; if (parents != null) { List matches = new ArrayList<>(); @@ -150,30 +155,27 @@ private static List getQualifiedSymbols(List return parents; } - private static List getSymbols(List languageServers, String name, String parent, + private static List getSymbols(LanguageServerWrapper languageServer, final String name, String parent, SymbolKind kind) { List result = new ArrayList<>(); - for (LanguageServer server : languageServers) { - WorkspaceSymbolParams params = new WorkspaceSymbolParams(name); - CompletableFuture, List>> 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, List>> 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; } diff --git a/repository/corrosion.product b/repository/corrosion.product index c9184a8..369c991 100644 --- a/repository/corrosion.product +++ b/repository/corrosion.product @@ -201,7 +201,7 @@ United States, other countries, or both. - + From 03f1f5df33d55c0e8df05360ca17517889932828 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Fri, 17 Nov 2023 15:26:04 +0100 Subject: [PATCH 2/5] Abort tests on timeout --- Jenkinsfile | 4 +++- .../src/org/eclipse/corrosion/tests/TestLSPExtensions.java | 4 ++++ .../src/org/eclipse/corrosion/tests/TestLSPIntegration.java | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1654c25..a4f820f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,7 +4,7 @@ pipeline { } options { buildDiscarder(logRotator(numToKeepStr:'10')) - timeout(time: 1, unit: 'HOURS') + timeout(time: 30, unit: 'MINUTES') } environment { PATH = "$HOME/.local/bin:$HOME/.cargo/bin/:$PATH" @@ -31,9 +31,11 @@ pipeline { wrap([$class: 'Xvnc', useXauthority: true]) { sh './mvnw -Dmaven.repo.local=$WORKSPACE/.m2 clean verify -Dmaven.test.error.ignore=true -Dmaven.test.failure.ignore=true -Dtycho.showEclipseLog=true -Psign -Dsurefire.timeout=1800' } + sh 'rust-analyzer --version' } post { always { + sh 'rust-analyzer --version' junit '*/target/surefire-reports/TEST-*.xml' archiveArtifacts artifacts: '*/target/work/data/.metadata/.log' } diff --git a/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/tests/TestLSPExtensions.java b/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/tests/TestLSPExtensions.java index 4d4ff08..26e9762 100644 --- a/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/tests/TestLSPExtensions.java +++ b/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/tests/TestLSPExtensions.java @@ -16,6 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import java.time.Duration; +import java.util.concurrent.TimeUnit; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.jobs.IJobManager; @@ -24,6 +25,7 @@ import org.eclipse.corrosion.extensions.ProgressParams; import org.eclipse.swt.widgets.Display; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; class TestLSPExtensions extends AbstractCorrosionTest { @@ -31,6 +33,7 @@ class TestLSPExtensions extends AbstractCorrosionTest { private static final String PROGRESS_ID_2 = "progress_2"; @Test + @Timeout(value = 3, unit = TimeUnit.MINUTES) void testBuildingMessages() { String jobType = "Building"; RLSClientImplementation clientImplementation = new RLSClientImplementation(); @@ -50,6 +53,7 @@ void testBuildingMessages() { } @Test + @Timeout(value = 3, unit = TimeUnit.MINUTES) void testIndexingMessages() { String jobType = "Indexing"; RLSClientImplementation clientImplementation = new RLSClientImplementation(); diff --git a/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/tests/TestLSPIntegration.java b/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/tests/TestLSPIntegration.java index 00402cd..d704bd1 100644 --- a/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/tests/TestLSPIntegration.java +++ b/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/tests/TestLSPIntegration.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.time.Duration; import java.util.Arrays; +import java.util.concurrent.TimeUnit; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; @@ -29,10 +30,12 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; class TestLSPIntegration extends AbstractCorrosionTest { @Test + @Timeout(value = 3, unit = TimeUnit.MINUTES) void testLSWorks() throws IOException, CoreException { IProject project = getProject(BASIC_ERRORS_PROJECT_NAME); IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); From 07a65099f6974b691c6a1d7ffc084dc84ea19894 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Fri, 17 Nov 2023 21:25:53 +0100 Subject: [PATCH 3/5] More log in tests and build --- Jenkinsfile | 2 ++ .../src/org/eclipse/corrosion/RustManager.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index a4f820f..94fb736 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,6 +35,8 @@ pipeline { } post { always { + sh 'which rustup' + sh 'which rust-analyzer' sh 'rust-analyzer --version' junit '*/target/surefire-reports/TEST-*.xml' archiveArtifacts artifacts: '*/target/work/data/.metadata/.log' diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java index 073fbce..b9f07fc 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java @@ -326,6 +326,7 @@ public static CompletableFuture downloadAndInstallRustAnalyzer(DoubleConsu // Use retrieve to initiate file transfer File archiveFile = new File(RUST_ANALYZER_DEFAULT_LOCATION.getParentFile(), filename); + CorrosionPlugin.getDefault().getLog().log(Status.info("Downloading to " + archiveFile)); //$NON-NLS-1$ try { CompletableFuture res = new CompletableFuture<>(); IFileID id = FileIDFactory.getDefault().createFileID(retrieve.getRetrieveNamespace(), URI.create(url)); @@ -370,6 +371,7 @@ public static void decompressGzip(File input, File output) throws IOException { try (FileOutputStream out = new FileOutputStream(output)) { in.transferTo(out); output.setExecutable(true); + CorrosionPlugin.getDefault().getLog().info("UnGZipped to " + output); //$NON-NLS-1$ input.delete(); } } From 9edc1141c4cd2e46b01acea4abdd1db65c8e189c Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Fri, 17 Nov 2023 22:23:13 +0100 Subject: [PATCH 4/5] Change default path for rust-analyzer Assume standard installation is via rustup and use the .cargo path instead --- .../src/org/eclipse/corrosion/RustManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java index b9f07fc..caef93d 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/RustManager.java @@ -64,7 +64,7 @@ public class RustManager { * Set according to rust-analyzer documentation */ static final File RUST_ANALYZER_DEFAULT_LOCATION = new File(System.getProperty("user.home"), //$NON-NLS-1$ - ".local/bin/rust-analyzer"); //$NON-NLS-1$ + ".cargo/bin/rust-analyzer"); //$NON-NLS-1$ public static final String RLS_VERSION_FORMAT_REGEX = "^(rls|rust-analyzer).*$"; //$NON-NLS-1$ public static final String CARGO_VERSION_FORMAT_REGEX = "^cargo .*$"; //$NON-NLS-1$ public static final String RUSTUP_VERSION_FORMAT_REGEX = "^rustup .*$"; //$NON-NLS-1$ @@ -146,7 +146,7 @@ protected IStatus run(IProgressMonitor monitor) { toolchainId)); jobs.add(createRustupCommandJob(Messages.RustManager_addingRustAnalysisRustSrc, Messages.RustManager_unableToAddComponent, "component", //$NON-NLS-1$ - "add", "rust-analysis")); //$NON-NLS-1$ //$NON-NLS-2$ + "add", "rust-analysis", "rust-analyzer")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ for (CommandJob commandJob : jobs) { currentCommandJob = commandJob; From e81fcc32b83662a6553f430d31317bca5f33746d Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Fri, 17 Nov 2023 22:30:53 +0100 Subject: [PATCH 5/5] Directly install rust-analyzer from Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 94fb736..c6d1841 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,7 +19,7 @@ pipeline { sh 'org.eclipse.corrosion/scripts/rustup-init.sh -y' sh 'rustup install stable-x86_64-unknown-linux-gnu' sh 'rustup default stable-x86_64-unknown-linux-gnu' - sh 'mkdir -p ~/.local/bin' + sh 'rustup component add rust-analyzer' sh 'echo $PATH' } }