Skip to content

Commit

Permalink
[#220] Support environment variables in clangd options
Browse files Browse the repository at this point in the history
  • Loading branch information
ddscharfe authored and ghentschke committed Oct 25, 2023
1 parent 3b9393b commit a41e165
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions bundles/org.eclipse.cdt.lsp.clangd/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ Require-Bundle: org.eclipse.cdt.lsp;bundle-version="0.0.0",
org.eclipse.ui.editors;bundle-version="0.0.0",
org.eclipse.ui.ide;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.ClangdPlugin
org.eclipse.ui.workbench.texteditor;bundle-version="0.0.0",
org.eclipse.core.variables
Service-Component: OSGI-INF/org.eclipse.cdt.lsp.clangd.BuiltinClangdOptionsDefaults.xml,
OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdConfigurationAccess.xml,
OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdFallbackManager.xml,
OSGI-INF/org.eclipse.cdt.lsp.internal.clangd.ClangdMetadataDefaults.xml
Bundle-Activator: org.eclipse.cdt.lsp.internal.clangd.editor.ClangdPlugin
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.eclipse.cdt.lsp.clangd.ClangdConfiguration;
import org.eclipse.cdt.lsp.clangd.ClangdFallbackFlags;
import org.eclipse.cdt.lsp.editor.Configuration;
import org.eclipse.cdt.lsp.editor.LanguageServerEnable;
import org.eclipse.cdt.lsp.server.ICLanguageServerProvider;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ServiceCaller;
import org.eclipse.core.variables.VariablesPlugin;

public final class ClangdLanguageServerProvider implements ICLanguageServerProvider {

Expand All @@ -47,10 +50,19 @@ public Object getInitializationOptions(URI rootUri) {
@Override
public List<String> getCommands(URI rootUri) {
List<String> result = new ArrayList<>();
configuration.call(c -> result.addAll(c.commands(rootUri)));
configuration.call(c -> result.addAll(c.commands(rootUri).stream()
.map(ClangdLanguageServerProvider::resolveVariables).collect(Collectors.toList())));
return result;
}

private static String resolveVariables(String cmd) {
try {
return VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(cmd);
} catch (CoreException e) {
return cmd;
}
}

@Override
public boolean isEnabledFor(IProject project) {
boolean[] enabled = new boolean[1];
Expand Down

0 comments on commit a41e165

Please sign in to comment.