Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Language-Specific Overrides for clangd.fallbackFlags #701

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"clangd.fallbackFlags": {
"type": "array",
"default": [],
"scope": "language-overridable",
"items": {
"type": "string"
},
Expand Down
12 changes: 10 additions & 2 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,20 @@ export class ClangdContext implements vscode.Disposable {
}
const serverOptions: vscodelc.ServerOptions = clangd;

const editor = vscode.window.activeTextEditor;
const currentLanguageScope: vscode.ConfigurationScope | undefined = editor
? { languageId: editor.document.languageId}
: undefined;

const clientOptions: vscodelc.LanguageClientOptions = {
// Register the server for c-family and cuda files.
documentSelector: clangdDocumentSelector,
initializationOptions: {
clangdFileStatus: true,
fallbackFlags: config.get<string[]>('fallbackFlags')
fallbackFlags: config.get<string[]>(
"fallbackFlags",
currentLanguageScope
),
},
outputChannel: outputChannel,
// Do not switch to output window when clangd returns output.
Expand Down Expand Up @@ -201,4 +209,4 @@ export class ClangdContext implements vscode.Disposable {
this.client.stop();
this.subscriptions = []
}
}
}
13 changes: 11 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ import * as path from 'path';
import * as vscode from 'vscode';

// Gets the config value `clangd.<key>`. Applies ${variable} substitutions.
export function get<T>(key: string): T {
return substitute(vscode.workspace.getConfiguration('clangd').get<T>(key)!);
export function get<T>(
key: string,
scope?: vscode.ConfigurationScope | null
): T {
if (key === "fallbackFlags" && scope) {
const scopedConfig = vscode.workspace.getConfiguration("clangd", scope).get<T>(key);
if (scopedConfig) {
return substitute(scopedConfig);
}
}
return substitute(vscode.workspace.getConfiguration("clangd").get<T>(key)!);
}

// Sets the config value `clangd.<key>`. Does not apply substitutions.
Expand Down