mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Bug 535632. Set a cache directory for CQuery LS
Change-Id: I80b88f48207b5091fe1c634c730a8fd6983f40b9 Signed-off-by: Manish Khurana <mkmanishkhurana98@gmail.com>
This commit is contained in:
parent
2818a473bd
commit
e02e28eec1
8 changed files with 92 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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) ;
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue