diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/.classpath b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/.classpath new file mode 100644 index 00000000000..eca7bdba8f0 --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/.project b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/.project new file mode 100644 index 00000000000..40593687885 --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.lsp4e.cpp.language.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/.settings/org.eclipse.jdt.core.prefs b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..0c68a61dca8 --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/META-INF/MANIFEST.MF b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..6df0060ac65 --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/META-INF/MANIFEST.MF @@ -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 diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/build.properties b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/build.properties new file mode 100644 index 00000000000..34d2e4d2dad --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/src/org/eclipse/lsp4e/cpp/language/tests/cquery/CqueryJsonParseTest.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/src/org/eclipse/lsp4e/cpp/language/tests/cquery/CqueryJsonParseTest.java new file mode 100644 index 00000000000..f0abdb53268 --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language.tests/src/org/eclipse/lsp4e/cpp/language/tests/cquery/CqueryJsonParseTest.java @@ -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 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 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 ranges1 = new ArrayList<>(); + List 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 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); + } +} diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/META-INF/MANIFEST.MF b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/META-INF/MANIFEST.MF index d581d5016fc..eda7dd83d96 100644 --- a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/META-INF/MANIFEST.MF +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/META-INF/MANIFEST.MF @@ -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 diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml index d0370eae59d..5e1621c5a56 100644 --- a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml @@ -16,7 +16,8 @@ + label="%server.label" + clientImpl="org.eclipse.lsp4e.cpp.language.Server2ClientProtocolExtension" > inactiveRegions; + + public CqueryInactiveRegions(URI uri, List inactiveRegions) { + this.uri = uri; + this.inactiveRegions = inactiveRegions; + } + + public URI getUri() { + return uri; + } + public List getInactiveRegions() { + return inactiveRegions; + } +} diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/CquerySemanticHighlights.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/CquerySemanticHighlights.java new file mode 100644 index 00000000000..2917e9551cd --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/CquerySemanticHighlights.java @@ -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 symbols; + + public URI getUri() { + return uri; + } + + public List getSymbols() { + return symbols; + } + + public CquerySemanticHighlights(URI uri, List symbols) { + this.uri = uri; + this.symbols = symbols; + } +} diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/CquerySymbolKind.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/CquerySymbolKind.java new file mode 100644 index 00000000000..bc25f37a8b6 --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/CquerySymbolKind.java @@ -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$ + } + } +} \ No newline at end of file diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/ExtendedSymbolKindType.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/ExtendedSymbolKindType.java new file mode 100644 index 00000000000..0632f26fc85 --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/ExtendedSymbolKindType.java @@ -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, JsonSerializer { + @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()); + } +} + diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/HighlightSymbol.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/HighlightSymbol.java new file mode 100644 index 00000000000..b17b6a5346a --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/HighlightSymbol.java @@ -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 ranges; + + public HighlightSymbol(int stableId, ExtendedSymbolKindType parentKind, ExtendedSymbolKindType kind, + StorageClass storage, List 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 getRanges() { + return ranges; + } +} \ No newline at end of file diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/IndexingProgressStats.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/IndexingProgressStats.java new file mode 100644 index 00000000000..6a3a9baf485 --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/IndexingProgressStats.java @@ -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; + } +} \ No newline at end of file diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/StorageClass.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/StorageClass.java new file mode 100644 index 00000000000..ff3b885e1f9 --- /dev/null +++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/cquery/StorageClass.java @@ -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]; + } +} \ No newline at end of file