Search in sources :

Example 1 with LanguageServersRegistry

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);
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) LanguageServersRegistry(org.eclipse.lsp4e.LanguageServersRegistry) File(java.io.File)

Aggregations

File (java.io.File)1 CoreException (org.eclipse.core.runtime.CoreException)1 IContentTypeManager (org.eclipse.core.runtime.content.IContentTypeManager)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1 ILaunchManager (org.eclipse.debug.core.ILaunchManager)1 LanguageServersRegistry (org.eclipse.lsp4e.LanguageServersRegistry)1