1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 558660 - Isolate cquery-related code of the org.eclipse.cdt.lsp.core

Moved cquery-related code to "org.eclipse.cdt.cquery" namespace.
Why not "org.eclipse.cdt.lsp.cquery"? Because here we are focusing on
"cquery" support for CDT, and it looks like a separate component to be
wrapped by its own feature later.

Change-Id: Iddfff2d4341d090ccdeca562ea16c584c0fcdd76
Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
Alexander Fedorov 2019-12-28 15:54:11 +03:00
parent ca4413f0ab
commit 6da6e91cc1
18 changed files with 164 additions and 91 deletions

View file

@ -16,14 +16,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.cquery.CqueryInactiveRegions;
import org.eclipse.cdt.cquery.CquerySemanticHighlights;
import org.eclipse.cdt.cquery.ExtendedSymbolKindType;
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.lsp.core.cquery.CqueryInactiveRegions;
import org.eclipse.cdt.lsp.core.cquery.CquerySemanticHighlights;
import org.eclipse.cdt.lsp.core.cquery.ExtendedSymbolKindType;
import org.eclipse.cdt.lsp.core.cquery.HighlightSymbol;
import org.eclipse.cdt.lsp.core.cquery.IndexingProgressStats;
import org.eclipse.cdt.lsp.core.cquery.StorageClass;
import org.eclipse.cdt.lsp.core.cquery.SymbolRole;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod;

View file

@ -22,8 +22,11 @@ Require-Bundle: com.google.gson;bundle-version="2.8.2",
org.eclipse.cdt.ui
Import-Package: org.eclipse.ui.editors.text,
org.eclipse.ui.texteditor
Export-Package: org.eclipse.cdt.lsp.core;x-friends:="org.eclipse.cdt.lsp.ui",
org.eclipse.cdt.lsp.core.cquery;x-friends:="org.eclipse.cdt.lsp.ui",
Export-Package: org.eclipse.cdt.cquery;x-friends:="org.eclipse.cdt.lsp.ui",
org.eclipse.cdt.internal.cquery;x-internal:=true,
org.eclipse.cdt.internal.cquery.core;x-internal:=true,
org.eclipse.cdt.internal.cquery.ui;x-internal:=true,
org.eclipse.cdt.lsp.core;x-friends:="org.eclipse.cdt.lsp.ui",
org.eclipse.cdt.lsp.internal.core;x-internal:=true
Bundle-Activator: org.eclipse.cdt.lsp.core.Activator
Bundle-ActivationPolicy: lazy

View file

@ -9,7 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.cdt.lsp.core.cquery;
package org.eclipse.cdt.cquery;
import java.net.URI;
import java.util.List;

View file

@ -9,7 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.cdt.lsp.core.cquery;
package org.eclipse.cdt.cquery;
import java.net.URI;
import java.util.List;

View file

@ -13,10 +13,11 @@
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 558516
*******************************************************************************/
package org.eclipse.cdt.lsp.core.cquery;
package org.eclipse.cdt.cquery;
import java.lang.reflect.Type;
import org.eclipse.cdt.internal.cquery.CquerySymbolKind;
import org.eclipse.lsp4j.SymbolKind;
import com.google.gson.JsonDeserializationContext;

View file

@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2018 Manish Khurana , Nathan Ridge 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
*******************************************************************************/
package org.eclipse.cdt.cquery;
import java.util.List;
import org.eclipse.lsp4j.Range;
public class HighlightSymbol {
private int stableId;
private ExtendedSymbolKindType parentKind;
private ExtendedSymbolKindType kind;
private StorageClass storage;
private List<Range> ranges;
private Integer role;
public HighlightSymbol(int stableId, ExtendedSymbolKindType parentKind, ExtendedSymbolKindType kind,
StorageClass storage, Integer role, List<Range> ranges) {
this.stableId = stableId;
this.parentKind = parentKind;
this.kind = kind;
this.storage = storage;
this.role = role;
this.ranges = ranges;
}
public int getStableId() {
return stableId;
}
public ExtendedSymbolKindType getParentKind() {
return parentKind;
}
public ExtendedSymbolKindType getKind() {
return kind;
}
public StorageClass getStorage() {
return storage;
}
public Integer getRole() {
return role;
}
public List<Range> getRanges() {
return ranges;
}
}

View file

@ -9,7 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.cdt.lsp.core.cquery;
package org.eclipse.cdt.cquery;
public class IndexingProgressStats {
private int indexRequestCount;

View file

@ -13,9 +13,9 @@
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 558516
*******************************************************************************/
package org.eclipse.cdt.lsp.core.cquery;
package org.eclipse.cdt.cquery;
import org.eclipse.cdt.lsp.internal.core.LspCoreMessages;
import org.eclipse.cdt.internal.cquery.CqueryMessages;
import org.eclipse.osgi.util.NLS;
public enum StorageClass {
@ -34,7 +34,7 @@ public enum StorageClass {
public static StorageClass forValue(int value) {
StorageClass[] allValues = StorageClass.values();
if (value < 1 || value > allValues.length) {
throw new IllegalArgumentException(NLS.bind(LspCoreMessages.StorageClass_e_illegal_value, value));
throw new IllegalArgumentException(NLS.bind(CqueryMessages.StorageClass_e_illegal_value, value));
}
return allValues[value - 1];
}

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.lsp.core.cquery;
package org.eclipse.cdt.cquery;
/**
* A class to contain constants that represent different roles

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2019 Eclipse Foundation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - initial API and implementatin
*******************************************************************************/
package org.eclipse.cdt.internal.cquery;
import org.eclipse.osgi.util.NLS;
public class CqueryMessages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.cquery.CqueryMessages"; //$NON-NLS-1$
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, CqueryMessages.class);
}
public static String CquerySymbolKind_e_illegal_value;
public static String Server2ClientProtocolExtension_cquery_busy;
public static String Server2ClientProtocolExtension_cquery_idle;
public static String StorageClass_e_illegal_value;
private CqueryMessages() {
}
}

View file

@ -0,0 +1,18 @@
###############################################################################
# Copyright (c) 2019 Eclipse Foundation and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0/.
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Eclipse Foundation - initial API and implementation
# Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 558484
###############################################################################
CquerySymbolKind_e_illegal_value=Illegal value {0} for cquery symbol kind
Server2ClientProtocolExtension_cquery_busy=CQuery : Busy | {0} Jobs
Server2ClientProtocolExtension_cquery_idle=CQuery : Idle
StorageClass_e_illegal_value=Illegal enum value: {0}

View file

@ -13,12 +13,11 @@
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 558516
*******************************************************************************/
package org.eclipse.cdt.lsp.core.cquery;
package org.eclipse.cdt.internal.cquery;
import org.eclipse.cdt.lsp.internal.core.LspCoreMessages;
import org.eclipse.osgi.util.NLS;
enum CquerySymbolKind {
public enum CquerySymbolKind {
Unknown(0), TypeAlias(252), Parameter(253), StaticMethod(254), Macro(255);
private int value;
@ -44,7 +43,7 @@ enum CquerySymbolKind {
case 255:
return CquerySymbolKind.Macro;
default:
throw new IllegalArgumentException(NLS.bind(LspCoreMessages.CquerySymbolKind_e_illegal_value, value));
throw new IllegalArgumentException(NLS.bind(CqueryMessages.CquerySymbolKind_e_illegal_value, value));
}
}
}

View file

@ -9,11 +9,12 @@
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.cdt.lsp.core;
package org.eclipse.cdt.internal.cquery.core;
import java.net.URI;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.lsp.core.ICPPLanguageServer;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

View file

@ -1,32 +1,28 @@
/*******************************************************************************
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
* Copyright (c) 2018-2019 Manish Khurana, Nathan Ridge 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/
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.cdt.lsp.core.cquery;
package org.eclipse.cdt.internal.cquery.ui;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.cquery.ExtendedSymbolKindType;
import org.eclipse.cdt.cquery.StorageClass;
import org.eclipse.cdt.cquery.SymbolRole;
import org.eclipse.cdt.internal.cquery.CquerySymbolKind;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightings;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.SymbolKind;
public class HighlightSymbol {
private int stableId;
private ExtendedSymbolKindType parentKind;
private ExtendedSymbolKindType kind;
private StorageClass storage;
private List<Range> ranges;
private Integer role;
public static Map<Integer, String> semanticHighlightSymbolsMap = new HashMap<>();
//FIXME: AF: rework this compilation unit from a container of static functions to a normal type
public class HighlightingNames {
private static Map<Integer, String> semanticHighlightSymbolsMap = new HashMap<>();
static {
semanticHighlightSymbolsMap.put(SymbolKind.Namespace.getValue(), SemanticHighlightings.NAMESPACE);
@ -43,10 +39,6 @@ public class HighlightSymbol {
semanticHighlightSymbolsMap.put(CquerySymbolKind.Macro.getValue(), SemanticHighlightings.MACRO_DEFINITION);
}
public static boolean isDeclaration(int role) {
return (role & SymbolRole.Declaration) != 0 || (role & SymbolRole.Definition) != 0;
}
public static String getHighlightingName(ExtendedSymbolKindType kind, ExtendedSymbolKindType parentKind,
StorageClass storage, int role) {
// semanticHighlightSymbolsMap contains mappings where the color is determined entirely
@ -82,37 +74,8 @@ public class HighlightSymbol {
return highlightingName;
}
public HighlightSymbol(int stableId, ExtendedSymbolKindType parentKind, ExtendedSymbolKindType kind,
StorageClass storage, Integer role, List<Range> ranges) {
this.stableId = stableId;
this.parentKind = parentKind;
this.kind = kind;
this.storage = storage;
this.role = role;
this.ranges = ranges;
private static boolean isDeclaration(int role) {
return (role & SymbolRole.Declaration) != 0 || (role & SymbolRole.Definition) != 0;
}
public int getStableId() {
return stableId;
}
public ExtendedSymbolKindType getParentKind() {
return parentKind;
}
public ExtendedSymbolKindType getKind() {
return kind;
}
public StorageClass getStorage() {
return storage;
}
public Integer getRole() {
return role;
}
public List<Range> getRanges() {
return ranges;
}
}
}

View file

@ -22,6 +22,7 @@ import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.internal.cquery.core.CqueryLanguageServer;
import org.eclipse.cdt.lsp.internal.core.LspCoreMessages;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
@ -45,6 +46,7 @@ public class CPPStreamConnectionProvider extends ProcessStreamConnectionProvider
public static final String CQUERY_ID = "cquery"; //$NON-NLS-1$
//FIXME: AF: the list of available servers should be extracted from some service
public CPPStreamConnectionProvider() throws UnsupportedOperationException {
List<String> commands = new ArrayList<>();
if (store.getString(PreferenceConstants.P_SERVER_CHOICE).equals(CQUERY_ID)) {

View file

@ -19,13 +19,14 @@ import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.cquery.CqueryInactiveRegions;
import org.eclipse.cdt.cquery.CquerySemanticHighlights;
import org.eclipse.cdt.cquery.HighlightSymbol;
import org.eclipse.cdt.cquery.IndexingProgressStats;
import org.eclipse.cdt.internal.cquery.CqueryMessages;
import org.eclipse.cdt.internal.cquery.ui.HighlightingNames;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightedPosition;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightingStyle;
import org.eclipse.cdt.lsp.core.cquery.CqueryInactiveRegions;
import org.eclipse.cdt.lsp.core.cquery.CquerySemanticHighlights;
import org.eclipse.cdt.lsp.core.cquery.HighlightSymbol;
import org.eclipse.cdt.lsp.core.cquery.IndexingProgressStats;
import org.eclipse.cdt.lsp.internal.core.LspCoreMessages;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.core.resources.IFile;
@ -52,6 +53,7 @@ import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchWindow;
//FIXME: AF: currently this extension is cquery-specific and it should be contributed from cquery-specific part
@SuppressWarnings("restriction")
public class Server2ClientProtocolExtension extends LanguageClientImpl {
@ -71,8 +73,8 @@ public class Server2ClientProtocolExtension extends LanguageClientImpl {
statusLine.add(cqueryStatusField);
}
String msg = stats.getTotalJobs() > 0
? NLS.bind(LspCoreMessages.Server2ClientProtocolExtension_cquery_busy, stats.getTotalJobs())
: LspCoreMessages.Server2ClientProtocolExtension_cquery_idle;
? NLS.bind(CqueryMessages.Server2ClientProtocolExtension_cquery_busy, stats.getTotalJobs())
: CqueryMessages.Server2ClientProtocolExtension_cquery_idle;
cqueryStatusField.setText(msg);
}
});
@ -170,7 +172,7 @@ public class Server2ClientProtocolExtension extends LanguageClientImpl {
for (HighlightSymbol highlight : highlights.getSymbols()) {
String highlightingName = HighlightSymbol.getHighlightingName(highlight.getKind(),
String highlightingName = HighlightingNames.getHighlightingName(highlight.getKind(),
highlight.getParentKind(), highlight.getStorage(), highlight.getRole());
String colorKey = PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + highlightingName
+ PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX;

View file

@ -24,10 +24,6 @@ public class LspCoreMessages extends NLS {
}
public static String CPPStreamConnectionProvider_e_unsupported;
public static String CquerySymbolKind_e_illegal_value;
public static String Server2ClientProtocolExtension_cquery_busy;
public static String Server2ClientProtocolExtension_cquery_idle;
public static String StorageClass_e_illegal_value;
private LspCoreMessages() {
}

View file

@ -13,7 +13,3 @@
###############################################################################
CPPStreamConnectionProvider_e_unsupported=Unsupported Language Server
CquerySymbolKind_e_illegal_value=Illegal value {0} for cquery symbol kind
Server2ClientProtocolExtension_cquery_busy=CQuery : Busy | {0} Jobs
Server2ClientProtocolExtension_cquery_idle=CQuery : Idle
StorageClass_e_illegal_value=Illegal enum value: {0}