mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Bug 558664 - Cquery integration should be extracted from LSP Core
Part 3: Convert ContributedLanguageServers to OSGi component and switch usages to its interface. Convert LanguageServerConfiguration implementations to OSGi components. Change-Id: Ic22fa26a7abfd40a959ae0189a63b9a04d1ac4e0 Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
parent
05ae2a8185
commit
3705069ef2
13 changed files with 117 additions and 25 deletions
|
@ -20,6 +20,11 @@
|
||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.pde.ds.core.builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
<nature>org.eclipse.pde.PluginNature</nature>
|
<nature>org.eclipse.pde.PluginNature</nature>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
classpath=true
|
||||||
|
dsVersion=V1_3
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
enabled=true
|
||||||
|
generateBundleActivationPolicyLazy=true
|
||||||
|
path=OSGI-INF
|
||||||
|
validationErrorLevel=error
|
||||||
|
validationErrorLevel.missingImplicitUnbindMethod=error
|
|
@ -18,6 +18,7 @@ Require-Bundle: com.google.gson;bundle-version="2.8.2",
|
||||||
org.eclipse.lsp4j,
|
org.eclipse.lsp4j,
|
||||||
org.eclipse.lsp4e,
|
org.eclipse.lsp4e,
|
||||||
org.eclipse.lsp4j.jsonrpc,
|
org.eclipse.lsp4j.jsonrpc,
|
||||||
|
org.eclipse.osgi.services;bundle-version="3.9.0";resolution:=optional,
|
||||||
org.eclipse.cdt.core,
|
org.eclipse.cdt.core,
|
||||||
org.eclipse.cdt.ui
|
org.eclipse.cdt.ui
|
||||||
Import-Package: org.eclipse.ui.editors.text,
|
Import-Package: org.eclipse.ui.editors.text,
|
||||||
|
@ -31,3 +32,6 @@ Export-Package: org.eclipse.cdt.cquery;x-friends:="org.eclipse.cdt.lsp.ui",
|
||||||
org.eclipse.cdt.lsp.internal.text;x-friends:="org.eclipse.cdt.lsp.ui"
|
org.eclipse.cdt.lsp.internal.text;x-friends:="org.eclipse.cdt.lsp.ui"
|
||||||
Bundle-Activator: org.eclipse.cdt.lsp.core.Activator
|
Bundle-Activator: org.eclipse.cdt.lsp.core.Activator
|
||||||
Bundle-ActivationPolicy: lazy
|
Bundle-ActivationPolicy: lazy
|
||||||
|
Service-Component: OSGI-INF/org.eclipse.cdt.lsp.internal.core.ContributedLanguageServers.xml,
|
||||||
|
OSGI-INF/org.eclipse.cdt.internal.clangd.ClangdLanguageServer.xml,
|
||||||
|
OSGI-INF/org.eclipse.cdt.internal.cquery.CqueryLanguageServer.xml
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.cdt.internal.clangd.ClangdLanguageServer">
|
||||||
|
<service>
|
||||||
|
<provide interface="org.eclipse.cdt.lsp.LanguageServerConfiguration"/>
|
||||||
|
</service>
|
||||||
|
<implementation class="org.eclipse.cdt.internal.clangd.ClangdLanguageServer"/>
|
||||||
|
</scr:component>
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.cdt.internal.cquery.CqueryLanguageServer">
|
||||||
|
<service>
|
||||||
|
<provide interface="org.eclipse.cdt.lsp.LanguageServerConfiguration"/>
|
||||||
|
</service>
|
||||||
|
<implementation class="org.eclipse.cdt.internal.cquery.CqueryLanguageServer"/>
|
||||||
|
</scr:component>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.cdt.lsp.internal.core.ContributedLanguageServers">
|
||||||
|
<service>
|
||||||
|
<provide interface="org.eclipse.cdt.lsp.SupportedLanguageServers"/>
|
||||||
|
</service>
|
||||||
|
<reference bind="register" cardinality="0..n" interface="org.eclipse.cdt.lsp.LanguageServerConfiguration" name="register" unbind="unregister"/>
|
||||||
|
<implementation class="org.eclipse.cdt.lsp.internal.core.ContributedLanguageServers"/>
|
||||||
|
</scr:component>
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
|
* Copyright (c) 2018, 2020 Manish Khurana , Nathan Ridge and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -14,9 +14,12 @@ package org.eclipse.cdt.internal.clangd;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.eclipse.cdt.lsp.LanguageServerConfiguration;
|
import org.eclipse.cdt.lsp.LanguageServerConfiguration;
|
||||||
|
import org.osgi.service.component.annotations.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class ClangdLanguageServer implements LanguageServerConfiguration {
|
public class ClangdLanguageServer implements LanguageServerConfiguration {
|
||||||
|
|
||||||
|
//FIXME: remove this constant, it is not needed outside the class
|
||||||
public static final String CLANGD_ID = "clangd"; //$NON-NLS-1$
|
public static final String CLANGD_ID = "clangd"; //$NON-NLS-1$
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
|
* Copyright (c) 2018, 2020 Manish Khurana , Nathan Ridge and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -18,11 +18,14 @@ import org.eclipse.cdt.lsp.LanguageServerConfiguration;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.osgi.service.component.annotations.Component;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class CqueryLanguageServer implements LanguageServerConfiguration {
|
public class CqueryLanguageServer implements LanguageServerConfiguration {
|
||||||
|
|
||||||
|
//FIXME: remove this constant, it is not needed outside the class
|
||||||
public static final String CQUERY_ID = "cquery"; //$NON-NLS-1$
|
public static final String CQUERY_ID = "cquery"; //$NON-NLS-1$
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,6 +24,6 @@ public interface SupportedLanguageServers {
|
||||||
|
|
||||||
Collection<LanguageServerConfiguration> all();
|
Collection<LanguageServerConfiguration> all();
|
||||||
|
|
||||||
LanguageServerConfiguration preferred() throws IllegalStateException;
|
LanguageServerConfiguration preferred();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,14 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.lsp.LanguageServerConfiguration;
|
import org.eclipse.cdt.lsp.LanguageServerConfiguration;
|
||||||
import org.eclipse.cdt.lsp.internal.core.ContributedLanguageServers;
|
import org.eclipse.cdt.lsp.SupportedLanguageServers;
|
||||||
import org.eclipse.cdt.utils.CommandLineUtil;
|
import org.eclipse.cdt.utils.CommandLineUtil;
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResourceChangeListener;
|
import org.eclipse.core.resources.IResourceChangeListener;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.ServiceCaller;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
|
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
|
||||||
|
|
||||||
|
@ -46,8 +47,7 @@ public class CPPStreamConnectionProvider extends ProcessStreamConnectionProvider
|
||||||
private final LanguageServerConfiguration configuration;
|
private final LanguageServerConfiguration configuration;
|
||||||
|
|
||||||
public CPPStreamConnectionProvider() throws UnsupportedOperationException {
|
public CPPStreamConnectionProvider() throws UnsupportedOperationException {
|
||||||
//FIXME: should obtain an instance of interface
|
configuration = configuration();
|
||||||
configuration = new ContributedLanguageServers().preferred();
|
|
||||||
File defaultLSLocation = getDefaultLSLocation(configuration.identifier());
|
File defaultLSLocation = getDefaultLSLocation(configuration.identifier());
|
||||||
if (defaultLSLocation != null) {
|
if (defaultLSLocation != null) {
|
||||||
store.setDefault(PreferenceConstants.P_SERVER_PATH, defaultLSLocation.getAbsolutePath());
|
store.setDefault(PreferenceConstants.P_SERVER_PATH, defaultLSLocation.getAbsolutePath());
|
||||||
|
@ -67,6 +67,13 @@ public class CPPStreamConnectionProvider extends ProcessStreamConnectionProvider
|
||||||
setCommands(commands);
|
setCommands(commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LanguageServerConfiguration configuration() {
|
||||||
|
final LanguageServerConfiguration[] configs = new LanguageServerConfiguration[1];
|
||||||
|
ServiceCaller.callOnce(CPPStreamConnectionProvider.class, SupportedLanguageServers.class,
|
||||||
|
x -> configs[0] = x.preferred());
|
||||||
|
return configs[0];
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
super.stop();
|
super.stop();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
|
* Copyright (c) 2018, 2020 Manish Khurana , Nathan Ridge and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -12,7 +12,8 @@
|
||||||
package org.eclipse.cdt.lsp.core;
|
package org.eclipse.cdt.lsp.core;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.core.runtime.preferences.DefaultScope;
|
||||||
|
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class used to initialize default preference values for C/C++ Preference Page.
|
* Class used to initialize default preference values for C/C++ Preference Page.
|
||||||
|
@ -21,9 +22,9 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initializeDefaultPreferences() {
|
public void initializeDefaultPreferences() {
|
||||||
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
|
IEclipsePreferences node = DefaultScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||||
store.setDefault(PreferenceConstants.P_SERVER_CHOICE, "clangd"); //$NON-NLS-1$
|
node.put(PreferenceConstants.P_SERVER_CHOICE, "clangd"); //$NON-NLS-1$
|
||||||
store.setDefault(PreferenceConstants.P_SERVER_OPTIONS, ""); //$NON-NLS-1$
|
node.put(PreferenceConstants.P_SERVER_OPTIONS, ""); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,26 +16,27 @@ package org.eclipse.cdt.lsp.internal.core;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.clangd.ClangdLanguageServer;
|
|
||||||
import org.eclipse.cdt.internal.cquery.CqueryLanguageServer;
|
|
||||||
import org.eclipse.cdt.lsp.LanguageServerConfiguration;
|
import org.eclipse.cdt.lsp.LanguageServerConfiguration;
|
||||||
import org.eclipse.cdt.lsp.SupportedLanguageServers;
|
import org.eclipse.cdt.lsp.SupportedLanguageServers;
|
||||||
import org.eclipse.cdt.lsp.core.PreferenceConstants;
|
import org.eclipse.cdt.lsp.core.PreferenceConstants;
|
||||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.preferences.IScopeContext;
|
||||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||||
import org.osgi.framework.FrameworkUtil;
|
import org.osgi.framework.FrameworkUtil;
|
||||||
|
import org.osgi.service.component.annotations.Component;
|
||||||
|
import org.osgi.service.component.annotations.Reference;
|
||||||
|
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||||
|
|
||||||
//FIXME ok, not really contributed at the moment, but will be
|
@Component
|
||||||
public final class ContributedLanguageServers implements SupportedLanguageServers {
|
public final class ContributedLanguageServers implements SupportedLanguageServers {
|
||||||
|
|
||||||
|
private final LanguageServerConfiguration undefined;
|
||||||
private final Map<String, LanguageServerConfiguration> configs;
|
private final Map<String, LanguageServerConfiguration> configs;
|
||||||
|
|
||||||
public ContributedLanguageServers() {
|
public ContributedLanguageServers() {
|
||||||
configs = new LinkedHashMap<>();
|
configs = new LinkedHashMap<>();
|
||||||
register(new ClangdLanguageServer());
|
undefined = new UndefinedLanguageServer();
|
||||||
register(new CqueryLanguageServer());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,6 +44,7 @@ public final class ContributedLanguageServers implements SupportedLanguageServer
|
||||||
return configs.values();
|
return configs.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MULTIPLE)
|
||||||
public void register(LanguageServerConfiguration configuration) {
|
public void register(LanguageServerConfiguration configuration) {
|
||||||
configs.put(configuration.identifier(), configuration);
|
configs.put(configuration.identifier(), configuration);
|
||||||
}
|
}
|
||||||
|
@ -52,13 +54,13 @@ public final class ContributedLanguageServers implements SupportedLanguageServer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LanguageServerConfiguration preferred() throws IllegalStateException {
|
public LanguageServerConfiguration preferred() {
|
||||||
return Optional.ofNullable(InstanceScope.INSTANCE.getNode(nodeQualifier()))//
|
return configs.getOrDefault(preferredIdentifier(), undefined);
|
||||||
.filter(IEclipsePreferences.class::isInstance)//
|
}
|
||||||
.map(IEclipsePreferences.class::cast)//
|
|
||||||
.flatMap(x -> Optional.ofNullable(x.get(nodePath(), null)))//
|
private String preferredIdentifier() {
|
||||||
.map(configs::get)//
|
return Platform.getPreferencesService().getString(nodeQualifier(), nodePath(), undefined.identifier(),
|
||||||
.orElseThrow(() -> new IllegalStateException("No preferred server was found"));
|
new IScopeContext[] { InstanceScope.INSTANCE });
|
||||||
}
|
}
|
||||||
|
|
||||||
private String nodeQualifier() {
|
private String nodeQualifier() {
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2020 ArSysOp and others.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* https://www.eclipse.org/legal/epl-2.0/
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Alexander Fedorov (ArSysOp) - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.lsp.internal.core;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.lsp.LanguageServerConfiguration;
|
||||||
|
|
||||||
|
final class UndefinedLanguageServer implements LanguageServerConfiguration {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String identifier() {
|
||||||
|
return ""; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String label() {
|
||||||
|
return "<undefined>";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object options(Object defaults, URI uri) {
|
||||||
|
return defaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue