summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManish Khurana2018-06-09 01:57:11 -0400
committerNathan Ridge2018-06-11 00:35:20 -0400
commite02e28eec1d7b08a85021f383d2ecc945540e98c (patch)
tree9e141d8b21b2035f0a6860f96260b3630791ad5f
parent2818a473bd623605f03805418cc0ef43a43e240a (diff)
downloadorg.eclipse.cdt-e02e28eec1d7b08a85021f383d2ecc945540e98c.tar.gz
org.eclipse.cdt-e02e28eec1d7b08a85021f383d2ecc945540e98c.tar.xz
org.eclipse.cdt-e02e28eec1d7b08a85021f383d2ecc945540e98c.zip
Bug 535632. Set a cache directory for CQuery LS
Change-Id: I80b88f48207b5091fe1c634c730a8fd6983f40b9 Signed-off-by: Manish Khurana <mkmanishkhurana98@gmail.com>
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/META-INF/MANIFEST.MF3
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml2
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPLanguageServerPreferencePage.java7
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPResourceChangeListener.java2
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPStreamConnectionProvider.java (renamed from lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPLanguageServer.java)21
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/ClangdLanguageServer.java20
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CqueryLanguageServer.java27
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/ICPPLanguageServer.java19
8 files changed, 92 insertions, 9 deletions
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 5abb02789c..d581d5016f 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
@@ -16,7 +16,8 @@ Require-Bundle: org.apache.commons.io,
org.eclipse.lsp4j,
org.eclipse.core.commands,
org.eclipse.core.expressions,
- org.eclipse.core.resources
+ org.eclipse.core.resources,
+ com.google.gson;bundle-version="2.8.2"
Bundle-Vendor: %Bundle-Vendor
Export-Package: org.eclipse.lsp4e.cpp.language
Bundle-Activator: org.eclipse.lsp4e.cpp.language.Activator
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml
index b8c36497eb..d0370eae59 100644
--- a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml
@@ -14,7 +14,7 @@
<extension
point="org.eclipse.lsp4e.languageServer">
<server
- class="org.eclipse.lsp4e.cpp.language.CPPLanguageServer"
+ class="org.eclipse.lsp4e.cpp.language.CPPStreamConnectionProvider"
id="org.eclipse.lsp4e.languages.cpp"
label="%server.label">
</server>
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPLanguageServerPreferencePage.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPLanguageServerPreferencePage.java
index 6069e51a5d..0c1258f425 100644
--- a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPLanguageServerPreferencePage.java
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPLanguageServerPreferencePage.java
@@ -31,9 +31,10 @@ public class CPPLanguageServerPreferencePage extends FieldEditorPreferencePage i
@Override
public void createFieldEditors() {
- serverChoice = new RadioGroupFieldEditor(PreferenceConstants.P_SERVER_CHOICE,
- Messages.ServerChoiceLabel, 1,
- new String[][] { { "ClangD", "clangd" }, { "CQuery", "cquery" } }, getFieldEditorParent()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ serverChoice = new RadioGroupFieldEditor(PreferenceConstants.P_SERVER_CHOICE, Messages.ServerChoiceLabel, 1,
+ new String[][] { { "ClangD", CPPStreamConnectionProvider.CLANGD_ID }, //$NON-NLS-1$
+ { "CQuery", CPPStreamConnectionProvider.CQUERY_ID } }, //$NON-NLS-1$
+ getFieldEditorParent());
addField(serverChoice);
serverPath = new FileFieldEditor(PreferenceConstants.P_SERVER_PATH, Messages.ServerPathLabel,
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPResourceChangeListener.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPResourceChangeListener.java
index 18524e9fd6..a2dcda0734 100644
--- a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPResourceChangeListener.java
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPResourceChangeListener.java
@@ -42,7 +42,7 @@ final class CPPResourceChangeListener implements IResourceChangeListener {
@Override
public void resourceChanged(IResourceChangeEvent event) {
- LanguageServerDefinition definition = LanguageServersRegistry.getInstance().getDefinition(CPPLanguageServer.ID);
+ LanguageServerDefinition definition = LanguageServersRegistry.getInstance().getDefinition(CPPStreamConnectionProvider.ID);
ProjectSpecificLanguageServerWrapper wrapper = getLanguageSeverWrapper(definition);
if (event.getType() != IResourceChangeEvent.POST_CHANGE || !isRelevantDelta(event.getDelta())
|| wrapper == null) {
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPLanguageServer.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPStreamConnectionProvider.java
index d2ce3b42f1..ba773e3a53 100644
--- a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPLanguageServer.java
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPStreamConnectionProvider.java
@@ -25,7 +25,8 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
-public class CPPLanguageServer extends ProcessStreamConnectionProvider {
+
+public class CPPStreamConnectionProvider extends ProcessStreamConnectionProvider {
public static final String ID = "org.eclipse.lsp4e.languages.cpp"; //$NON-NLS-1$
@@ -33,8 +34,21 @@ public class CPPLanguageServer extends ProcessStreamConnectionProvider {
private static final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
- public CPPLanguageServer() {
+ private ICPPLanguageServer languageServer;
+
+ public static final String CLANGD_ID = "clangd"; //$NON-NLS-1$
+
+ public static final String CQUERY_ID = "cquery"; //$NON-NLS-1$
+
+ public CPPStreamConnectionProvider() throws UnsupportedOperationException {
List<String> commands = new ArrayList<>();
+ if (store.getString(PreferenceConstants.P_SERVER_CHOICE).equals(CQUERY_ID)) {
+ languageServer = new CqueryLanguageServer();
+ } else if (store.getString(PreferenceConstants.P_SERVER_CHOICE).equals(CLANGD_ID)) {
+ languageServer = new ClangdLanguageServer();
+ } else {
+ throw new UnsupportedOperationException("Unsupported Language Server"); //$NON-NLS-1$
+ }
File defaultLSLocation = getDefaultLSLocation(store.getString(PreferenceConstants.P_SERVER_CHOICE));
if(defaultLSLocation != null) {
store.setDefault(PreferenceConstants.P_SERVER_PATH, defaultLSLocation.getAbsolutePath());
@@ -65,7 +79,8 @@ public class CPPLanguageServer extends ProcessStreamConnectionProvider {
@Override
public Object getInitializationOptions(URI rootPath) {
installResourceChangeListener(rootPath);
- return super.getInitializationOptions(rootPath);
+ Object defaultInitOptions = super.getInitializationOptions(rootPath);
+ return languageServer.getLSSpecificInitializationOptions(defaultInitOptions, rootPath);
}
private void installResourceChangeListener(URI rootPath) {
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/ClangdLanguageServer.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/ClangdLanguageServer.java
new file mode 100644
index 0000000000..79c436f3c3
--- /dev/null
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/ClangdLanguageServer.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * 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 java.net.URI;
+
+public class ClangdLanguageServer implements ICPPLanguageServer {
+
+ @Override
+ public Object getLSSpecificInitializationOptions(Object defaultInitOptions, URI rootPath) {
+ return defaultInitOptions;
+ }
+
+}
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CqueryLanguageServer.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CqueryLanguageServer.java
new file mode 100644
index 0000000000..8f153e9efb
--- /dev/null
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CqueryLanguageServer.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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 java.net.URI;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import com.google.gson.JsonObject;
+
+public class CqueryLanguageServer implements ICPPLanguageServer {
+
+ @Override
+ public Object getLSSpecificInitializationOptions(Object defaultInitOptions, URI rootPath) {
+// TODO: Allow user to specify cache directory path
+ IPath cacheDirectory = Path.fromOSString(rootPath.getPath()).append(".cquery/cquery_index"); //$NON-NLS-1$
+ JsonObject result = (defaultInitOptions instanceof JsonObject) ? (JsonObject) defaultInitOptions : new JsonObject();
+ result.addProperty("cacheDirectory", cacheDirectory.toString()); //$NON-NLS-1$
+ return result;
+ }
+
+}
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/ICPPLanguageServer.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/ICPPLanguageServer.java
new file mode 100644
index 0000000000..35d6a3eab3
--- /dev/null
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/ICPPLanguageServer.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * 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 java.net.URI;
+/*
+ * Encapsulates functionality specific to a particular C++ language server (e.g., CQuery)
+ */
+public interface ICPPLanguageServer {
+
+ public Object getLSSpecificInitializationOptions(Object defaultInitOptions, URI rootPath) ;
+
+}