From 0ec977a14569e0c02ca645bf09bf311d578dd2ac Mon Sep 17 00:00:00 2001 From: Lucas Bullen Date: Tue, 21 Nov 2017 10:11:32 -0500 Subject: [PATCH] Issue #66: Run `dotnet restore` before starting LS Re-add previously removed workaround for https://github.com/OmniSharp/omnisharp-node-client/issues/265 Signed-off-by: Lucas Bullen --- .../acute/tests/TestLSPIntegration.java | 24 +++---------------- .../OmnisharpStreamConnectionProvider.java | 24 ++++++++++++++++++- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/org.eclipse.acute.tests/src/org/eclipse/acute/tests/TestLSPIntegration.java b/org.eclipse.acute.tests/src/org/eclipse/acute/tests/TestLSPIntegration.java index 303af048..510297ce 100644 --- a/org.eclipse.acute.tests/src/org/eclipse/acute/tests/TestLSPIntegration.java +++ b/org.eclipse.acute.tests/src/org/eclipse/acute/tests/TestLSPIntegration.java @@ -10,18 +10,15 @@ *******************************************************************************/ package org.eclipse.acute.tests; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -import java.io.ByteArrayInputStream; import java.util.concurrent.TimeUnit; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Platform; import org.eclipse.lsp4e.LanguageServiceAccessor; import org.eclipse.lsp4j.Hover; import org.eclipse.lsp4j.Position; @@ -32,9 +29,7 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor; import org.eclipse.ui.tests.harness.util.DisplayHelper; -import org.eclipse.ui.texteditor.AbstractTextEditor; import org.junit.Assert; import org.junit.Test; @@ -45,21 +40,9 @@ public void setUp() throws Exception { super.setUp(); } - private void dotnetRestore(IProject project) throws Exception { - String[] command = new String[] {"/bin/bash", "-c", "dotnet restore"}; - if (Platform.getOS().equals(Platform.OS_WIN32)) { - command = new String[] {"cmd", "/c", "dotnet restore"}; - } - ProcessBuilder builder = new ProcessBuilder(command); - builder.directory(project.getLocation().toFile()); - Process dotnetRestoreProcess = builder.start(); - dotnetRestoreProcess.waitFor(); - } - @Test public void testLSFound() throws Exception { IProject project = getProject("basic"); - dotnetRestore(project); IFile csharpSourceFile = project.getFile("test.cs"); LanguageServer languageServer = LanguageServiceAccessor.getLanguageServers(csharpSourceFile, capabilities -> capabilities.getHoverProvider() != null).iterator().next(); String uri = csharpSourceFile.getLocationURI().toString(); @@ -77,11 +60,10 @@ public void testLSFoundWithCSProj() throws Exception { Assert.assertNotNull(hover); Assert.assertFalse(hover.getContents().isEmpty()); } - + @Test public void testLSWorks() throws Exception { IProject project = getProject("basicWithError"); - dotnetRestore(project); IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart editor = null; IFile file = project.getFile("testError.cs"); diff --git a/org.eclipse.acute/src/org/eclipse/acute/OmnisharpStreamConnectionProvider.java b/org.eclipse.acute/src/org/eclipse/acute/OmnisharpStreamConnectionProvider.java index 8c33265d..0e1cd56b 100644 --- a/org.eclipse.acute/src/org/eclipse/acute/OmnisharpStreamConnectionProvider.java +++ b/org.eclipse.acute/src/org/eclipse/acute/OmnisharpStreamConnectionProvider.java @@ -45,10 +45,32 @@ public OmnisharpStreamConnectionProvider() { @Override public void start() throws IOException { + // workaround for https://github.com/OmniSharp/omnisharp-node-client/issues/265 + String[] command; + try { + command = new String[] { "/bin/bash", "-c", AcutePlugin.getDotnetCommand(), "restore" }; + if (Platform.getOS().equals(Platform.OS_WIN32)) { + command = new String[] { "cmd", "/c", AcutePlugin.getDotnetCommand(), "restore" }; + } + Process restoreProcess = Runtime.getRuntime().exec(command); + try { + restoreProcess.waitFor(); + } catch (InterruptedException e) { + AcutePlugin.logError(e); + } + } catch (IllegalStateException e) { + AcutePlugin.getDefault().getLog().log(new Status(IStatus.ERROR, + AcutePlugin.getDefault().getBundle().getSymbolicName(), + "`dotnet restore` not performed!\n" + + "Main issue and remediation: The `dotnet` path is not set in the .NET Core preferences. Please set it.\n" + + "Possible alternative remediation:\n" + + "* `dotnet` (v2.0 or later) is a prerequisite. Install it on your system if missing.")); + } + String commandLine = System.getenv("OMNISHARP_LANGUAGE_SERVER_COMMAND"); String omnisharpLocation = System.getenv("OMNISHARP_LANGUAGE_SERVER_LOCATION"); if (commandLine != null) { - String[] command = new String[] {"/bin/bash", "-c", commandLine}; + command = new String[] {"/bin/bash", "-c", commandLine}; if (Platform.getOS().equals(Platform.OS_WIN32)) { command = new String[] {"cmd", "/c", commandLine}; }