summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormanish2018-05-27 06:13:06 -0400
committerNathan Ridge2018-06-06 09:05:31 -0400
commit44101234374f645b5404a3bee5a6e698418af680 (patch)
tree99c001f52c48a59020a38eb73e7a172c0d9d65e4
parent4d5204c771954f422ac029606809f1e23b47c1d7 (diff)
downloadorg.eclipse.cdt-44101234374f645b5404a3bee5a6e698418af680.tar.gz
org.eclipse.cdt-44101234374f645b5404a3bee5a6e698418af680.tar.xz
org.eclipse.cdt-44101234374f645b5404a3bee5a6e698418af680.zip
Bug 534669. Added Preference Page for LSP4E-CPP
Change-Id: I8ad9be37643c6de4591db9161fbe60589ff92f07 Signed-off-by: manish <mkmanishkhurana98@gmail.com>
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/META-INF/MANIFEST.MF2
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/OSGI-INF/l10n/bundle.properties3
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml15
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Activator.java38
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPLanguageServer.java42
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPLanguageServerPreferencePage.java51
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Messages.java22
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Messages.properties12
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/PreferenceConstants.java22
-rw-r--r--lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/PreferenceInitializer.java32
10 files changed, 229 insertions, 10 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 8af924d7d2..5abb02789c 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
@@ -19,3 +19,5 @@ Require-Bundle: org.apache.commons.io,
org.eclipse.core.resources
Bundle-Vendor: %Bundle-Vendor
Export-Package: org.eclipse.lsp4e.cpp.language
+Bundle-Activator: org.eclipse.lsp4e.cpp.language.Activator
+Bundle-ActivationPolicy: lazy
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/OSGI-INF/l10n/bundle.properties b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/OSGI-INF/l10n/bundle.properties
index b4947d8e91..edc62e5f8c 100644
--- a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/OSGI-INF/l10n/bundle.properties
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/OSGI-INF/l10n/bundle.properties
@@ -5,4 +5,5 @@ content-type.name = C/C++
server.label = C/C++ Language Server
reindex.command.name = Reindex
-reindex.command.label = Reindex \ No newline at end of file
+reindex.command.label = Reindex
+PreferencePageTitle=C/C++ Language Server \ No newline at end of file
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml
index dd1417acb0..b8c36497eb 100644
--- a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/plugin.xml
@@ -93,4 +93,19 @@
type="java.lang.Object">
</propertyTester>
</extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ class="org.eclipse.lsp4e.cpp.language.CPPLanguageServerPreferencePage"
+ category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
+ id="org.eclipse.lsp4e.cpp.language.CPPLanguageServerPreferencePage"
+ name="%PreferencePageTitle">
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.eclipse.lsp4e.cpp.language.PreferenceInitializer">
+ </initializer>
+ </extension>
</plugin>
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Activator.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Activator.java
new file mode 100644
index 0000000000..8485e477d0
--- /dev/null
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Activator.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+public class Activator extends AbstractUIPlugin {
+
+ public Activator() {
+ }
+
+ public static final String PLUGIN_ID = "org.eclipse.lsp4e.cpp.language"; //$NON-NLS-1$
+
+ private static Activator plugin;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ public static Activator getDefault() {
+ return plugin;
+ }
+}
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/CPPLanguageServer.java
index 24435caa24..d2ce3b42f1 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/CPPLanguageServer.java
@@ -22,23 +22,32 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
public class CPPLanguageServer extends ProcessStreamConnectionProvider {
public static final String ID = "org.eclipse.lsp4e.languages.cpp"; //$NON-NLS-1$
- private static final String CLANG_LANGUAGE_SERVER = "clangd"; //$NON-NLS-1$
-
private IResourceChangeListener fResourceListener;
+ private static final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
public CPPLanguageServer() {
List<String> commands = new ArrayList<>();
- File clangServerLocation = getClangServerLocation();
+ File defaultLSLocation = getDefaultLSLocation(store.getString(PreferenceConstants.P_SERVER_CHOICE));
+ if(defaultLSLocation != null) {
+ store.setDefault(PreferenceConstants.P_SERVER_PATH, defaultLSLocation.getAbsolutePath());
+ }
+ File languageServerLocation = getLanguageServerLocation();
String parent = ""; //$NON-NLS-1$
- if (clangServerLocation != null) {
- commands.add(clangServerLocation.getAbsolutePath());
- parent = clangServerLocation.getParent();
+ String flags = store.getString(PreferenceConstants.P_SERVER_OPTIONS);
+ if (languageServerLocation != null) {
+ commands.add(languageServerLocation.getAbsolutePath());
+ if (!flags.isEmpty()) {
+ commands.add(flags);
+ }
+ parent = languageServerLocation.getParent();
}
setWorkingDirectory(parent);
setCommands(commands);
@@ -86,11 +95,25 @@ public class CPPLanguageServer extends ProcessStreamConnectionProvider {
return "C/C++ Language Server: " + super.toString(); //$NON-NLS-1$
}
- private static File getClangServerLocation() {
+ private static File getLanguageServerLocation() {
+ String path = store.getString(PreferenceConstants.P_SERVER_PATH);
+
+ if (path.isEmpty()) {
+ return null;
+ }
+ File f = new File(path);
+ if (f.canExecute()) {
+ return f;
+ }
+
+ return null;
+ }
+
+ private static File getDefaultLSLocation(String selectedLanguageServer) {
String res = null;
- String[] command = new String[] {"/bin/bash", "-c", "which " + CLANG_LANGUAGE_SERVER}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String[] command = new String[] {"/bin/bash", "-c", "which " + selectedLanguageServer}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (Platform.getOS().equals(Platform.OS_WIN32)) {
- command = new String[] {"cmd", "/c", "where " + CLANG_LANGUAGE_SERVER}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ command = new String[] {"cmd", "/c", "where " + selectedLanguageServer}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
BufferedReader reader = null;
try {
@@ -115,3 +138,4 @@ public class CPPLanguageServer extends ProcessStreamConnectionProvider {
return null;
}
}
+
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
new file mode 100644
index 0000000000..6069e51a5d
--- /dev/null
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPLanguageServerPreferencePage.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.jface.preference.*;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.IWorkbench;
+
+/**
+ * This class represents the preference page for C/C++ Language Server.
+ */
+
+public class CPPLanguageServerPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ private FileFieldEditor serverPath;
+ private RadioGroupFieldEditor serverChoice;
+ private StringFieldEditor serverOptions;
+
+ public CPPLanguageServerPreferencePage() {
+ super(GRID);
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ setDescription(Messages.PreferencePageDescription);
+ }
+
+ @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$
+ addField(serverChoice);
+
+ serverPath = new FileFieldEditor(PreferenceConstants.P_SERVER_PATH, Messages.ServerPathLabel,
+ getFieldEditorParent());
+ addField(serverPath);
+
+ serverOptions = new StringFieldEditor(PreferenceConstants.P_SERVER_OPTIONS, Messages.ServerOptionsLabel,
+ getFieldEditorParent());
+ addField(serverOptions);
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ }
+} \ No newline at end of file
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Messages.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Messages.java
new file mode 100644
index 0000000000..925db4ef1c
--- /dev/null
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Messages.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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.osgi.util.NLS;
+
+public class Messages extends NLS {
+ public static String PreferencePageDescription;
+ public static String ServerChoiceLabel;
+ public static String ServerPathLabel;
+ public static String ServerOptionsLabel;
+
+ static {
+ NLS.initializeMessages(Messages.class.getName(), Messages.class);
+ }
+}
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Messages.properties b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Messages.properties
new file mode 100644
index 0000000000..b671b9824d
--- /dev/null
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/Messages.properties
@@ -0,0 +1,12 @@
+################################################################################
+# 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
+#################################################################################
+
+PreferencePageDescription=Preferences for the C/C++ Language Server\n\n
+ServerChoiceLabel=Please select the C/C++ Language Server you want to use in Eclipse :
+ServerPathLabel=Browse path to the server executable
+ServerOptionsLabel=Enter any command-line options for the server \ No newline at end of file
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/PreferenceConstants.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/PreferenceConstants.java
new file mode 100644
index 0000000000..ec964848ed
--- /dev/null
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/PreferenceConstants.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Constant definitions for LSP4E-CPP plug-in preferences.
+ */
+public class PreferenceConstants {
+
+ public static final String P_SERVER_PATH = "org.eclipse.cdt.lsp.serverPathPreference"; //$NON-NLS-1$
+
+ public static final String P_SERVER_CHOICE = "org.eclipse.cdt.lsp.serverChoicePreference"; //$NON-NLS-1$
+
+ public static final String P_SERVER_OPTIONS = "org.eclipse.cdt.lsp.serverOptionsPreference"; //$NON-NLS-1$
+
+}
diff --git a/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/PreferenceInitializer.java b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/PreferenceInitializer.java
new file mode 100644
index 0000000000..c2dc5fc571
--- /dev/null
+++ b/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/PreferenceInitializer.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+/**
+ * Class used to initialize default preference values for C/C++ Preference Page.
+ */
+public class PreferenceInitializer extends AbstractPreferenceInitializer {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#
+ * initializeDefaultPreferences()
+ */
+ @Override
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ store.setDefault(PreferenceConstants.P_SERVER_CHOICE, "clangd"); //$NON-NLS-1$
+ store.setDefault(PreferenceConstants.P_SERVER_OPTIONS, ""); //$NON-NLS-1$
+ }
+
+}