Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bundles/org.eclipse.cdt.lsp.clangd/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ Require-Bundle: org.eclipse.cdt.lsp;bundle-version="0.0.0",
org.eclipse.ui.workbench;bundle-version="0.0.0",
org.eclipse.ui.workbench.texteditor;bundle-version="0.0.0"
Bundle-Activator: org.eclipse.cdt.lsp.internal.clangd.editor.LspEditorUiPlugin
Service-Component: OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdFallbackManager.xml
Service-Component: OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdConfigurationAccess.xml,
OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdFallbackManager.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="org.eclipse.cdt.lsp.internal.clangd.ClangdConfigurationAccess">
<service>
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdConfiguration"/>
</service>
<reference cardinality="1..1" field="preferences" interface="org.eclipse.core.runtime.preferences.IPreferencesService" name="preferences"/>
<reference cardinality="1..1" field="workspace" interface="org.eclipse.core.resources.IWorkspace" name="workspace"/>
<implementation class="org.eclipse.cdt.lsp.internal.clangd.ClangdConfigurationAccess"/>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
</service>
<reference cardinality="1..1" field="build" interface="org.eclipse.cdt.core.build.ICBuildConfigurationManager" name="build"/>
<reference cardinality="1..1" field="uri" interface="org.eclipse.cdt.lsp.InitialUri" name="uri"/>
<reference cardinality="1..1" field="workspace" interface="org.eclipse.core.resources.IWorkspace" name="workspace"/>
<implementation class="org.eclipse.cdt.lsp.internal.clangd.ClangdFallbackManager"/>
</scr:component>
6 changes: 6 additions & 0 deletions bundles/org.eclipse.cdt.lsp.clangd/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
SPDX-License-Identifier: EPL-2.0
-->
<plugin>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="org.eclipse.cdt.lsp.internal.clangd.ClangdPreferenceInitializer">
</initializer>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<!-- FIXME: AF: Exract clangd-specific preferences -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,12 @@

package org.eclipse.cdt.lsp.clangd;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.cdt.lsp.server.ICLanguageServerProvider;
import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;

/**
* Base class for a clangd language server provider. Can be extended by vendors.
*
*/
public abstract class BaseClangdLanguageServerProvider implements ICLanguageServerProvider {
public static final String CLANG_TIDY = "--clang-tidy"; //$NON-NLS-1$
public static final String BACKGROUND_INDEX = "--background-index"; //$NON-NLS-1$
public static final String COMPLETION_STYLE = "--completion-style=detailed"; //$NON-NLS-1$
public static final String PRETTY = "--pretty"; //$NON-NLS-1$
public static final String QUERY_DRIVER = "--query-driver="; //$NON-NLS-1$

protected List<String> commands;

public BaseClangdLanguageServerProvider() {
commands = createCommands();
}

@Override
public List<String> getCommands() {
return commands;
}

@Override
public void setCommands(List<String> commands) {
this.commands = commands;
}

protected List<String> createCommands() {
List<String> commands = new ArrayList<>();
IPath clangdLocation = PathUtil.findProgramLocation("clangd", null); //$NON-NLS-1$
//in case pathStr is null environment variable ${PATH} is inspected
if (clangdLocation != null) {
commands.add(clangdLocation.toOSString());
commands.add(CLANG_TIDY);
commands.add(BACKGROUND_INDEX);
commands.add(COMPLETION_STYLE);
commands.add(PRETTY);
// clangd will execute drivers and fetch necessary include paths to compile your code:
IPath compilerLocation = PathUtil.findProgramLocation("gcc", null); //$NON-NLS-1$
if (compilerLocation != null) {
commands.add(QUERY_DRIVER + compilerLocation.removeLastSegments(1).append(IPath.SEPARATOR + "*")); //$NON-NLS-1$
}
}
return commands;
}

@Override
public boolean isEnabledFor(IProject project) {
// check if server has been defined:
return !getCommands().isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2023 ArSysOp.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alexander Fedorov (ArSysOp) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.clangd;

import java.net.URI;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.preferences.IPreferenceMetadataStore;
import org.eclipse.core.runtime.preferences.IScopeContext;

/**
* Provides access to the clangd options according to the required scope
*
* @see ClangdOptions
* @see IScopeContext
*
*/
public interface ClangdConfiguration {

/**
* Returns the clangd options for the given context like {@link IResource} or {@link URI}, must not return <code>null</code>
* @param context to be adapter to the proper scope
*
* @return clangd options
*/
ClangdOptions options(Object context);

/**
* Returns the clangd preference store for the given context like {@link IResource} or {@link URI}, must not return <code>null</code>
* @param context to be adapter to the proper scope
*
* @return preference store
*/
IPreferenceMetadataStore storage(Object context);

/**
* Return the metadata for clangd options, must not return <code>null</code>
*
* @return the clangd option metadata
*/
ClangdMetadata metadata();

/**
* Default qualifier to use for preference storage
* @return preference qualifier
*/
String qualifier();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*******************************************************************************
* Copyright (c) 2023 ArSysOp.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alexander Fedorov (ArSysOp) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.clangd;

import org.eclipse.core.runtime.preferences.PreferenceMetadata;

/**
* The metadata for options to configure clangd
*
* @see ClangdOptions
*
*/
public interface ClangdMetadata {

/**
* Returns the metadata for the "Prefer clangd" option, must not return <code>null</code>.
*
* @return the metadata for the "Prefer clangd" option
*
* @see ClangdOptions#preferClangd()
*/
PreferenceMetadata<Boolean> preferClangd();

/**
* Returns the metadata for the "Clangd path" option, must not return <code>null</code>.
*
* @return the metadata for the "Clangd path" option
*
* @see ClangdOptions#clangdPath()
*/
PreferenceMetadata<String> clangdPath();

/**
* Returns the metadata for the "Enable clang-tidy" option, must not return <code>null</code>.
*
* @return the metadata for the "Enable clang-tidy" option
*
* @see ClangdOptions#useTidy()
*/
PreferenceMetadata<Boolean> useTidy();

/**
* Returns the metadata for the "Background index" option, must not return <code>null</code>.
*
* @return the metadata for the "Background index" option
*
* @see ClangdOptions#useBackgroundIndex()
*/
PreferenceMetadata<Boolean> useBackgroundIndex();

/**
* Returns the metadata for the "Completion style" option, must not return <code>null</code>.
*
* @return the metadata for the "Completion style" option
*
* @see ClangdOptions#completionStyle()
*/
PreferenceMetadata<String> completionStyle();

/**
* Returns the metadata for the "Pretty print" option, must not return <code>null</code>.
*
* @return the metadata for the "Pretty print" option
*
* @see ClangdOptions#prettyPrint()
*/
PreferenceMetadata<Boolean> prettyPrint();

/**
* Returns the metadata for the "Query driver" option, must not return <code>null</code>.
*
* @return the metadata for the "Query driver" option
*
* @see ClangdOptions#queryDriver()
*/
PreferenceMetadata<String> queryDriver();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*******************************************************************************
* Copyright (c) 2023 ArSysOp.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alexander Fedorov (ArSysOp) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.clangd;

import java.util.List;

import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;

/**
* Options to configure clangd
*
*/
public interface ClangdOptions {

/**
* Prefer to use clangd language server and related editor implementation
*
* @return if clangd language server should be preferred
*/
boolean preferClangd();

/**
* Path to clangd executable to be launched, must not return <code>null</code>
*
* @return path to clangd
*/
String clangdPath();

/**
* Use clang-tidy diagnostics
*
* @return if clang-tidy diagnostics is enabled
*/
boolean useTidy();

/**
* Index project code in the background and persist index on disk
*
* @return if background index is enabled
*/
boolean useBackgroundIndex();

/**
* Granularity of code completion suggestions either <code>detailed</code> or <code>bundled</code>, must not return <code>null</code>
*
* @return granularity of code completion suggestions
*/
String completionStyle();

/**
* Pretty-print JSON output
*
* @return if pretty-print for JSON output is enabled
*/
boolean prettyPrint();

/**
* Comma separated list of globs for white-listing gcc-compatible drivers that are safe to execute, must not return <code>null</code>
*
* @return comma separated list of globs
*/
String queryDriver();

/**
* Provides list of commands suitable for {@link ProcessStreamConnectionProvider}
*
* @return list of commands
*/
List<String> toList();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2023 ArSysOp.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alexander Fedorov (ArSysOp) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.lsp.clangd;

import java.util.function.Supplier;

public final class ClangdQualifier implements Supplier<String> {

@Override
public String get() {
return "org.eclipse.cdt.lsp.clangd"; //$NON-NLS-1$
}

}
Loading