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 8af924d7d2e..5abb02789c1 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 b4947d8e913..edc62e5f8c4 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 dd1417acb0c..b8c36497eb2 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"> + + + + + + + + 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 00000000000..8485e477d01 --- /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 24435caa24b..d2ce3b42f1c 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 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 00000000000..6069e51a5d8 --- /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 00000000000..925db4ef1ca --- /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 00000000000..b671b9824d8 --- /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 00000000000..ec964848eda --- /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 00000000000..c2dc5fc571a --- /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$ + } + +}