1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 17:25:38 +02:00

Bug 535629. Add empty implementation for unsupported CQuery notifications

Change-Id: Ic1c91acd00f6d3aca64c82d4abffd8c41396b15c
Signed-off-by: Manish Khurana <mkmanishkhurana98@gmail.com>
This commit is contained in:
Manish Khurana 2018-06-25 12:16:13 +05:30 committed by Nathan Ridge
parent 48838766e9
commit 527c2d64a5
16 changed files with 512 additions and 3 deletions

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.lsp4e.cpp.language.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View file

@ -0,0 +1,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: "Tests for LSP4E C/C++ Support"
Bundle-SymbolicName: org.eclipse.lsp4e.cpp.language.tests
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: org.eclipse.lsp4e.cpp.language.tests
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.lsp4e,
org.eclipse.lsp4j,
org.eclipse.lsp4j.jsonrpc,
org.eclipse.lsp4e.cpp.language,
com.google.gson;bundle-version="2.8.2",
org.junit

View file

@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.

View file

@ -0,0 +1,114 @@
/*******************************************************************************
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.lsp4e.cpp.language.tests.cquery;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.eclipse.lsp4e.cpp.language.Server2ClientProtocolExtension;
import org.eclipse.lsp4e.cpp.language.cquery.*;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod;
import org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler;
import org.eclipse.lsp4j.jsonrpc.messages.*;
import org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints;
import org.junit.Assert;
import org.junit.Test;
public class CqueryJsonParseTest {
Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(Server2ClientProtocolExtension.class);
private MessageJsonHandler jsonHandler = new MessageJsonHandler(methods);
private void assertParse(final String json, final NotificationMessage expectedResult) {
Assert.assertEquals(expectedResult.toString(), jsonHandler.parseMessage(json).toString());
}
@Test
public void testProgress(){
String json = "{\"jsonrpc\": \"2.0\",\"method\": \"$cquery/progress\",\"params\": {" //$NON-NLS-1$
+ "\"indexRequestCount\": 4,\"doIdMapCount\": 5,\"loadPreviousIndexCount\": 6," //$NON-NLS-1$
+ "\"onIdMappedCount\": 7,\"onIndexedCount\": 8,\"activeThreads\": 9}}"; //$NON-NLS-1$
IndexingProgressStats expectedIndex = new IndexingProgressStats(4, 5, 6, 7, 8, 9);
NotificationMessage expectedResult = new NotificationMessage();
expectedResult.setJsonrpc("2.0"); //$NON-NLS-1$
expectedResult.setMethod("$cquery/progress"); //$NON-NLS-1$
expectedResult.setParams(expectedIndex);
assertParse(json, expectedResult);
}
@Test
public void testSetInactiveRegions() {
String json = "{\"jsonrpc\": \"2.0\",\"method\": \"$cquery/setInactiveRegions\",\"params\": {" //$NON-NLS-1$
+ "\"uri\": \"file:///home/foobar.cpp\",\"inactiveRegions\": [{\"start\": {\"line\": " //$NON-NLS-1$
+ "25,\"character\": 4},\"end\": {\"line\": 25,\"character\": 10}},{\"start\": {\"line\"" //$NON-NLS-1$
+ ": 35,\"character\": 8},\"end\": {\"line\": 35,\"character\": 15}}]}}"; //$NON-NLS-1$
URI uri = URI.create("file:///home/foobar.cpp"); //$NON-NLS-1$
Position pos1 = new Position(25, 4);
Position pos2 = new Position(25, 10);
Position pos3 = new Position(35, 8);
Position pos4 = new Position(35, 15);
Range range1 = new Range(pos1,pos2);
Range range2 = new Range(pos3,pos4);
List<Range> regions = new ArrayList<>();
regions.add(range1);
regions.add(range2);
CqueryInactiveRegions expectedRegions = new CqueryInactiveRegions(uri, regions);
NotificationMessage expectedResult = new NotificationMessage();
expectedResult.setJsonrpc("2.0"); //$NON-NLS-1$
expectedResult.setMethod("$cquery/setInactiveRegions"); //$NON-NLS-1$
expectedResult.setParams(expectedRegions);
assertParse(json, expectedResult);
}
@Test
public void testPublishSemanticHighlighting() {
String json = "{\"jsonrpc\": \"2.0\",\"method\": \"$cquery/publishSemanticHighlighting\"," //$NON-NLS-1$
+ "\"params\": {\"uri\": \"file:///home/foobar.cpp\",\"symbols\": [{\"stableId\": 21," //$NON-NLS-1$
+ "\"parentKind\": 8,\"kind\": 0,\"storage\": 3,\"ranges\": [{\"start\": {\"line\": 41," //$NON-NLS-1$
+ "\"character\": 1},\"end\": {\"line\": 41,\"character\": 5}}]},{\"stableId\": 19," //$NON-NLS-1$
+ "\"parentKind\": 12,\"kind\": 253,\"storage\": 5,\"ranges\": [{\"start\": {\"line\": 39," //$NON-NLS-1$
+ "\"character\": 9},\"end\": {\"line\": 39,\"character\": 10}}]}]}}"; //$NON-NLS-1$
URI uri = URI.create("file:///home/foobar.cpp"); //$NON-NLS-1$
Position pos1 = new Position(41, 1);
Position pos2 = new Position(41, 5);
Position pos3 = new Position(39, 9);
Position pos4 = new Position(39, 10);
Range range1 = new Range(pos1,pos2);
Range range2 = new Range(pos3,pos4);
List<Range> ranges1 = new ArrayList<>();
List<Range> ranges2 = new ArrayList<>();
ranges1.add(range1);
ranges2.add(range2);
ExtendedSymbolKindType parentKind1 = new ExtendedSymbolKindType(8);
ExtendedSymbolKindType parentKind2 = new ExtendedSymbolKindType(12);
ExtendedSymbolKindType kind1 = new ExtendedSymbolKindType(0);
ExtendedSymbolKindType kind2 = new ExtendedSymbolKindType(253);
StorageClass storage1 = StorageClass.Static;
StorageClass storage2 = StorageClass.Auto;
HighlightSymbol symbol1 = new HighlightSymbol(21, parentKind1, kind1, storage1, ranges1);
HighlightSymbol symbol2 = new HighlightSymbol(19, parentKind2, kind2, storage2, ranges2);
List<HighlightSymbol> symbols = new ArrayList<>();
symbols.add(symbol1);
symbols.add(symbol2);
CquerySemanticHighlights exceptedHighlights = new CquerySemanticHighlights(uri, symbols);
NotificationMessage expectedResult = new NotificationMessage();
expectedResult.setJsonrpc("2.0"); //$NON-NLS-1$
expectedResult.setMethod("$cquery/publishSemanticHighlighting"); //$NON-NLS-1$
expectedResult.setParams(exceptedHighlights);
assertParse(json, expectedResult);
}
}

View file

@ -17,8 +17,10 @@ Require-Bundle: org.apache.commons.io,
org.eclipse.core.commands,
org.eclipse.core.expressions,
org.eclipse.core.resources,
com.google.gson;bundle-version="2.8.2"
com.google.gson;bundle-version="2.8.2",
org.eclipse.lsp4j.jsonrpc
Bundle-Vendor: %Bundle-Vendor
Export-Package: org.eclipse.lsp4e.cpp.language
Export-Package: org.eclipse.lsp4e.cpp.language,
org.eclipse.lsp4e.cpp.language.cquery
Bundle-Activator: org.eclipse.lsp4e.cpp.language.Activator
Bundle-ActivationPolicy: lazy

View file

@ -16,7 +16,8 @@
<server
class="org.eclipse.lsp4e.cpp.language.CPPStreamConnectionProvider"
id="org.eclipse.lsp4e.languages.cpp"
label="%server.label">
label="%server.label"
clientImpl="org.eclipse.lsp4e.cpp.language.Server2ClientProtocolExtension" >
</server>
<contentTypeMapping
contentType="org.eclipse.lsp4e.languages.cpp"

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.lsp4e.cpp.language;
import org.eclipse.lsp4e.LanguageClientImpl;
import org.eclipse.lsp4e.cpp.language.cquery.CqueryInactiveRegions;
import org.eclipse.lsp4e.cpp.language.cquery.CquerySemanticHighlights;
import org.eclipse.lsp4e.cpp.language.cquery.IndexingProgressStats;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
public class Server2ClientProtocolExtension extends LanguageClientImpl {
@JsonNotification("$cquery/progress")
public final void indexingProgress(IndexingProgressStats stats) {
// TODO: Implement
}
@JsonNotification("$cquery/setInactiveRegions")
public final void setInactiveRegions(CqueryInactiveRegions regions) {
// TODO: Implement
}
@JsonNotification("$cquery/publishSemanticHighlighting")
public final void semanticHighlights(CquerySemanticHighlights highlights) {
// TODO: Implement
}
}

View file

@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.lsp4e.cpp.language.cquery;
import java.net.URI;
import java.util.List;
import org.eclipse.lsp4j.Range;
public class CqueryInactiveRegions {
private URI uri;
private List<Range> inactiveRegions;
public CqueryInactiveRegions(URI uri, List<Range> inactiveRegions) {
this.uri = uri;
this.inactiveRegions = inactiveRegions;
}
public URI getUri() {
return uri;
}
public List<Range> getInactiveRegions() {
return inactiveRegions;
}
}

View file

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.lsp4e.cpp.language.cquery;
import java.net.URI;
import java.util.List;
public class CquerySemanticHighlights {
private URI uri;
private List<HighlightSymbol> symbols;
public URI getUri() {
return uri;
}
public List<HighlightSymbol> getSymbols() {
return symbols;
}
public CquerySemanticHighlights(URI uri, List<HighlightSymbol> symbols) {
this.uri = uri;
this.symbols = symbols;
}
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.lsp4e.cpp.language.cquery;
enum CquerySymbolKind {
Unknown(0), TypeAlias(252), Parameter(253), StaticMethod(254), Macro(255);
private int value;
public int getValue() {
return value;
}
private CquerySymbolKind(int value) {
this.value = value;
}
public static CquerySymbolKind forValue(int value) {
switch (value) {
case 0:
return CquerySymbolKind.Unknown;
case 252:
return CquerySymbolKind.TypeAlias;
case 253:
return CquerySymbolKind.Parameter;
case 254:
return CquerySymbolKind.StaticMethod;
case 255:
return CquerySymbolKind.Macro;
default:
throw new IllegalArgumentException("Illegal value for cquery symbol kind"); //$NON-NLS-1$
}
}
}

View file

@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.lsp4e.cpp.language.cquery;
import java.lang.reflect.Type;
import org.eclipse.lsp4j.SymbolKind;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.annotations.JsonAdapter;
@JsonAdapter(ExtendedSymbolKindParsers.class)
public class ExtendedSymbolKindType {
int value;
transient boolean isProtocolSymbol;
public ExtendedSymbolKindType(int _v) {
try {
SymbolKind.forValue(_v);
value = _v;
isProtocolSymbol = true;
} catch (IllegalArgumentException e) {
try {
CquerySymbolKind.forValue(_v);
value = _v;
isProtocolSymbol = false;
} catch (IllegalArgumentException y) {
throw new IllegalArgumentException("Illegal value for SymbolKind"); //$NON-NLS-1$
}
}
}
public int getValue() {
return value;
}
}
class ExtendedSymbolKindParsers
implements JsonDeserializer<ExtendedSymbolKindType>, JsonSerializer<ExtendedSymbolKindType> {
@Override
public ExtendedSymbolKindType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
int symbolKindValue = json.getAsInt();
return new ExtendedSymbolKindType(symbolKindValue);
}
@Override
public JsonElement serialize(ExtendedSymbolKindType src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.getValue());
}
}

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.lsp4e.cpp.language.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;
public HighlightSymbol(int stableId, ExtendedSymbolKindType parentKind, ExtendedSymbolKindType kind,
StorageClass storage, List<Range> ranges) {
this.stableId = stableId;
this.parentKind = parentKind;
this.kind = kind;
this.storage = storage;
this.ranges = ranges;
}
public int getStableId() {
return stableId;
}
public ExtendedSymbolKindType getParentKind() {
return parentKind;
}
public ExtendedSymbolKindType getKind() {
return kind;
}
public StorageClass getStorage() {
return storage;
}
public List<Range> getRanges() {
return ranges;
}
}

View file

@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.lsp4e.cpp.language.cquery;
public class IndexingProgressStats {
private int indexRequestCount;
private int doIdMapCount;
private int loadPreviousIndexCount;
private int onIdMappedCount;
private int onIndexedCount;
private int activeThreads;
public IndexingProgressStats(int indexRequestCount, int doIdMapCount, int loadPreviousIndexCount, int onIdMappedCount,
int onIndexedCount, int activeThreads) {
this.indexRequestCount = indexRequestCount;
this.doIdMapCount = doIdMapCount;
this.loadPreviousIndexCount = loadPreviousIndexCount;
this.onIdMappedCount = onIdMappedCount;
this.onIndexedCount = onIndexedCount;
this.activeThreads = activeThreads;
}
public int getIndexRequestCount() {
return indexRequestCount;
}
public int getDoIdMapCount() {
return doIdMapCount;
}
public int getLoadPreviousIndexCount() {
return loadPreviousIndexCount;
}
public int getOnIdMappedCount() {
return onIdMappedCount;
}
public int getOnIndexedCount() {
return onIndexedCount;
}
public int getActiveThreads() {
return activeThreads;
}
}

View file

@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2018 Manish Khurana , Nathan Ridge and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.lsp4e.cpp.language.cquery;
public enum StorageClass {
Invalid(0), None(1), Extern(2), Static(3), PrivateExtern(4), Auto(5), Register(6);
private int value;
public int getValue() {
return value;
}
StorageClass(int value) {
this.value = value;
}
public static StorageClass forValue(int value) {
StorageClass[] allValues = StorageClass.values();
if (value < 1 || value > allValues.length) {
throw new IllegalArgumentException("Illegal enum value: " + value); //$NON-NLS-1$
}
return allValues[value - 1];
}
}