Skip to content

Commit

Permalink
Issue #32: Compute best path for node and VSCode language servers
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelistria committed Sep 29, 2016
1 parent 5f826e6 commit c5ef849
Showing 1 changed file with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
*******************************************************************************/
package org.eclipse.languageserver.languages;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
Expand Down Expand Up @@ -61,7 +66,7 @@ public void earlyStartup() {
workingCopy.setAttribute(IExternalToolConstants.ATTR_SHOW_CONSOLE, false);
workingCopy.setAttribute(IExternalToolConstants.ATTR_BUILD_SCOPE, "${none}");
workingCopy.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, true);
workingCopy.setAttribute(IExternalToolConstants.ATTR_LOCATION, "/usr/bin/node");
workingCopy.setAttribute(IExternalToolConstants.ATTR_LOCATION, getNodeJsLocation());
workingCopy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, "/home/mistria/git/omnisharp-node-client/languageserver/server.js");
workingCopy.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);
Map<String, String> environment = new HashMap<>(1);
Expand Down Expand Up @@ -90,10 +95,10 @@ public void earlyStartup() {
workingCopy.setAttribute(IExternalToolConstants.ATTR_SHOW_CONSOLE, false);
workingCopy.setAttribute(IExternalToolConstants.ATTR_BUILD_SCOPE, "${none}");
workingCopy.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, true);
workingCopy.setAttribute(IExternalToolConstants.ATTR_LOCATION, "/usr/bin/node");
workingCopy.setAttribute(IExternalToolConstants.ATTR_LOCATION, getNodeJsLocation());
// Assume node is already installed on machine and uses it
// TODO: implement smarter and multi-platform discovery
workingCopy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, "/usr/share/code/resources/app/extensions/css/server/out/cssServerMain.js --stdio");
workingCopy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, getVSCodeLocation() + "/resources/app/extensions/css/server/out/cssServerMain.js --stdio");
omniSharpLauch = workingCopy.doSave();
registry.registerAssociation(contentTypeManager.getContentType("org.eclipse.wst.css.core.csssource"), LaunchConfigurationStreamProvider.findLaunchConfiguration(IExternalToolConstants.ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE, InitializeLaunchConfigurations.VSCODE_CSS_NAME));
}
Expand All @@ -117,10 +122,10 @@ public void earlyStartup() {
workingCopy.setAttribute(IExternalToolConstants.ATTR_SHOW_CONSOLE, false);
workingCopy.setAttribute(IExternalToolConstants.ATTR_BUILD_SCOPE, "${none}");
workingCopy.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, true);
workingCopy.setAttribute(IExternalToolConstants.ATTR_LOCATION, "/usr/bin/node");
workingCopy.setAttribute(IExternalToolConstants.ATTR_LOCATION, getNodeJsLocation());
// Assume node is already installed on machine and uses it
// TODO: implement smarter and multi-platform discovery
workingCopy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, "/usr/share/code/resources/app/extensions/json/server/out/jsonServerMain.js --stdio");
workingCopy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, getVSCodeLocation() + "/resources/app/extensions/json/server/out/jsonServerMain.js --stdio");
omniSharpLauch = workingCopy.doSave();
registry.registerAssociation(contentTypeManager.getContentType("org.eclipse.wst.jsdt.core.jsonSource"), LaunchConfigurationStreamProvider.findLaunchConfiguration(IExternalToolConstants.ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE, InitializeLaunchConfigurations.VSCODE_JSON_NAME));
}
Expand All @@ -129,4 +134,38 @@ public void earlyStartup() {
}
}

private String getVSCodeLocation() {
String res = null;
if (Platform.getOS().equals(Platform.OS_LINUX)) {
res = "/usr/share/code";
} else if (Platform.getOS().equals(Platform.OS_WIN32)) {
res = "C:/Program Files (x86)/Microsoft VS Code";
} else if (Platform.getOS().equals(Platform.OS_MACOSX)) {
res = "/usr/share/code";
}
if (new File(res).isDirectory()) {
return res;
}
return "/unknown/path/to/VSCode";
}

private String getNodeJsLocation() {
String res = "/path/to/node";
String[] command = new String[] {"/bin/bash", "-c", "which node"};
if (Platform.getOS().equals(Platform.OS_WIN32)) {
command = new String[] {"cmd", "/c", "where node"};
}
BufferedReader reader = null;
try {
Process p = Runtime.getRuntime().exec(command);
reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
res = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(reader);
}
return res;
}

}

0 comments on commit c5ef849

Please sign in to comment.