1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 01:45:33 +02:00

Bug 534669. Added Preference Page for LSP4E-CPP

Change-Id: I8ad9be37643c6de4591db9161fbe60589ff92f07
Signed-off-by: manish <mkmanishkhurana98@gmail.com>
This commit is contained in:
manish 2018-05-27 15:43:06 +05:30 committed by Nathan Ridge
parent 4d5204c771
commit 4410123437
10 changed files with 229 additions and 10 deletions

View file

@ -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

View file

@ -5,4 +5,5 @@ content-type.name = C/C++
server.label = C/C++ Language Server
reindex.command.name = Reindex
reindex.command.label = Reindex
reindex.command.label = Reindex
PreferencePageTitle=C/C++ Language Server

View file

@ -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>

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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) {
}
}

View file

@ -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);
}
}

View file

@ -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

View file

@ -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$
}

View file

@ -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$
}
}