Skip to content

Commit

Permalink
Issue eclipse-acute#66: Run dotnet restore before starting LS
Browse files Browse the repository at this point in the history
Re-add previously removed workaround for
OmniSharp/omnisharp-node-client#265

Signed-off-by: Lucas Bullen <[email protected]>
  • Loading branch information
Lucas Bullen committed Nov 21, 2017
1 parent ff46e87 commit 0ec977a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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();
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down

0 comments on commit 0ec977a

Please sign in to comment.