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 7: Extract CQuery protocol extension to its package and declare it as a LanguageProtocolExtension component. Remove custom "clientImpl" from LSP extension point, as we can use standard one. Declare DelegatingLauncherBuilder to collect and register language extensions for the preferred language server. Change-Id: I88be0456bbb53d24a6a0df2578c145649268b028 Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
parent
3efcecf379
commit
58e1b69c80
6 changed files with 78 additions and 11 deletions
|
@ -23,7 +23,7 @@ import org.eclipse.cdt.cquery.HighlightSymbol;
|
|||
import org.eclipse.cdt.cquery.IndexingProgressStats;
|
||||
import org.eclipse.cdt.cquery.StorageClass;
|
||||
import org.eclipse.cdt.cquery.SymbolRole;
|
||||
import org.eclipse.cdt.lsp.core.Server2ClientProtocolExtension;
|
||||
import org.eclipse.cdt.internal.cquery.ui.CqueryProtocolExtension;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod;
|
||||
|
@ -34,7 +34,7 @@ import org.junit.Assert;
|
|||
import org.junit.Test;
|
||||
|
||||
public class CqueryJsonParseTest {
|
||||
Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(Server2ClientProtocolExtension.class);
|
||||
Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(CqueryProtocolExtension.class);
|
||||
private MessageJsonHandler jsonHandler = new MessageJsonHandler(methods);
|
||||
|
||||
private void assertParse(final String json, final NotificationMessage expectedResult) {
|
||||
|
|
|
@ -36,4 +36,5 @@ 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,
|
||||
OSGI-INF/org.eclipse.cdt.lsp.internal.core.ContributedProtocolExtensions.xml
|
||||
OSGI-INF/org.eclipse.cdt.lsp.internal.core.ContributedProtocolExtensions.xml,
|
||||
OSGI-INF/org.eclipse.cdt.internal.cquery.ui.CqueryProtocolExtension.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.cquery.ui.CqueryProtocolExtension">
|
||||
<service>
|
||||
<provide interface="org.eclipse.cdt.lsp.LanguageProtocolExtension"/>
|
||||
</service>
|
||||
<implementation class="org.eclipse.cdt.internal.cquery.ui.CqueryProtocolExtension"/>
|
||||
</scr:component>
|
|
@ -30,7 +30,7 @@
|
|||
class="org.eclipse.cdt.lsp.core.CPPStreamConnectionProvider"
|
||||
id="org.eclipse.cdt.lsp.core"
|
||||
label="%server.label"
|
||||
clientImpl="org.eclipse.cdt.lsp.core.Server2ClientProtocolExtension" >
|
||||
launcherBuilder="org.eclipse.cdt.lsp.internal.core.DelegatingLauncherBuilder">
|
||||
</server>
|
||||
<contentTypeMapping
|
||||
contentType="org.eclipse.cdt.lsp.core"
|
||||
|
|
|
@ -8,33 +8,37 @@
|
|||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.lsp.core;
|
||||
package org.eclipse.cdt.internal.cquery.ui;
|
||||
|
||||
import org.eclipse.cdt.cquery.CqueryInactiveRegions;
|
||||
import org.eclipse.cdt.cquery.CquerySemanticHighlights;
|
||||
import org.eclipse.cdt.cquery.IndexingProgressStats;
|
||||
import org.eclipse.cdt.internal.cquery.CqueryMessages;
|
||||
import org.eclipse.cdt.internal.cquery.ui.PublishSemanticHighlighting;
|
||||
import org.eclipse.cdt.lsp.LanguageProtocolExtension;
|
||||
import org.eclipse.cdt.lsp.internal.core.ShowStatus;
|
||||
import org.eclipse.cdt.lsp.internal.text.SetInactiveRegions;
|
||||
import org.eclipse.cdt.lsp.internal.ui.StatusLineMessage;
|
||||
import org.eclipse.lsp4e.LanguageClientImpl;
|
||||
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
|
||||
//FIXME: AF: currently this extension is cquery-specific and it should be contributed from cquery-specific part
|
||||
@SuppressWarnings("restriction")
|
||||
public class Server2ClientProtocolExtension extends LanguageClientImpl {
|
||||
@Component
|
||||
public class CqueryProtocolExtension implements LanguageProtocolExtension {
|
||||
|
||||
private final ShowStatus progress;
|
||||
private final SetInactiveRegions inactive;
|
||||
private final PublishSemanticHighlighting highlighting;
|
||||
|
||||
public Server2ClientProtocolExtension() {
|
||||
public CqueryProtocolExtension() {
|
||||
this.progress = new ShowStatus(() -> CqueryMessages.CqueryLanguageServer_label, new StatusLineMessage());
|
||||
this.inactive = new SetInactiveRegions();
|
||||
this.highlighting = new PublishSemanticHighlighting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String targetIdentifier() {
|
||||
return "cquery"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@JsonNotification("$cquery/progress")
|
||||
public final void indexingProgress(IndexingProgressStats stats) {
|
||||
progress.accept(stats::getTotalJobs);
|
|
@ -0,0 +1,55 @@
|
|||
/*******************************************************************************
|
||||
* 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.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.lsp.LanguageProtocolExtension;
|
||||
import org.eclipse.cdt.lsp.SupportedProtocolExtensions;
|
||||
import org.eclipse.core.runtime.ServiceCaller;
|
||||
import org.eclipse.lsp4e.LanguageClientImpl;
|
||||
import org.eclipse.lsp4j.jsonrpc.Launcher;
|
||||
import org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod;
|
||||
import org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public final class DelegatingLauncherBuilder extends Launcher.Builder<LanguageClientImpl> {
|
||||
|
||||
private final ResolvePreferredServer server;
|
||||
|
||||
public DelegatingLauncherBuilder() {
|
||||
this.server = new ResolvePreferredServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, JsonRpcMethod> getSupportedMethods() {
|
||||
Map<String, JsonRpcMethod> methods = new LinkedHashMap<>(super.getSupportedMethods());
|
||||
extensions().stream()//
|
||||
.map(x -> x.getClass())//
|
||||
.map(ServiceEndpoints::getSupportedMethods)//
|
||||
.forEach(methods::putAll);
|
||||
return methods;
|
||||
}
|
||||
|
||||
private List<LanguageProtocolExtension> extensions() {
|
||||
List<LanguageProtocolExtension> extensions = new ArrayList<>();
|
||||
ServiceCaller.callOnce(getClass(), SupportedProtocolExtensions.class,
|
||||
x -> extensions.addAll(x.applicable(server.apply(getClass()))));
|
||||
return extensions;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue