use of org.eclipse.lsp4e.LanguageServersRegistry in project lsp4e by eclipse.
the class CreateAndRegisterContentTypeLSPLaunchConfigMapping method earlyStartup.
@Override
public void earlyStartup() {
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType externalType = launchManager.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE);
LanguageServersRegistry registry = LanguageServersRegistry.getInstance();
try {
String externalProcessLaunchName = "Mock external LS";
ILaunchConfiguration mockServerLauch = null;
for (ILaunchConfiguration launch : launchManager.getLaunchConfigurations(externalType)) {
if (launch.getName().equals(externalProcessLaunchName)) {
mockServerLauch = launch;
}
}
if (mockServerLauch == null) {
ILaunchConfigurationWorkingCopy workingCopy = externalType.newInstance(null, externalProcessLaunchName);
// some common config
workingCopy.setAttribute(IExternalToolConstants.ATTR_LAUNCH_IN_BACKGROUND, true);
workingCopy.setAttribute(IExternalToolConstants.ATTR_BUILDER_ENABLED, false);
workingCopy.setAttribute(IExternalToolConstants.ATTR_SHOW_CONSOLE, false);
workingCopy.setAttribute(IExternalToolConstants.ATTR_BUILD_SCOPE, "${none}");
workingCopy.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, true);
String exe = "";
if (Platform.OS_WIN32.equals(Platform.getOS())) {
exe = ".exe";
}
workingCopy.setAttribute(IExternalToolConstants.ATTR_LOCATION, new File(System.getProperty("java.home"), "bin/java" + exe).getAbsolutePath());
workingCopy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, "-cp " + getClassPath(MockLanguageServer.class) + " " + MockLanguageServer.class.getName());
mockServerLauch = workingCopy.doSave();
registry.registerAssociation(contentTypeManager.getContentType("org.eclipse.lsp4e.test.content-type2"), LaunchConfigurationStreamProvider.findLaunchConfiguration(IExternalToolConstants.ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE, mockServerLauch.getName()), Collections.singleton(ILaunchManager.RUN_MODE));
}
} catch (CoreException e) {
LanguageServerPlugin.logError(e);
}
}
Aggregations