diff --git a/package.json b/package.json index 163607b..024e22f 100644 --- a/package.json +++ b/package.json @@ -121,6 +121,7 @@ "clangd.fallbackFlags": { "type": "array", "default": [], + "scope": "language-overridable", "items": { "type": "string" }, diff --git a/src/clangd-context.ts b/src/clangd-context.ts index 9fc40a4..8ef5f6f 100644 --- a/src/clangd-context.ts +++ b/src/clangd-context.ts @@ -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('fallbackFlags') + fallbackFlags: config.get( + "fallbackFlags", + currentLanguageScope + ), }, outputChannel: outputChannel, // Do not switch to output window when clangd returns output. @@ -201,4 +209,4 @@ export class ClangdContext implements vscode.Disposable { this.client.stop(); this.subscriptions = [] } -} +} \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index 6364e77..015469a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,8 +3,17 @@ import * as path from 'path'; import * as vscode from 'vscode'; // Gets the config value `clangd.`. Applies ${variable} substitutions. -export function get(key: string): T { - return substitute(vscode.workspace.getConfiguration('clangd').get(key)!); +export function get( + key: string, + scope?: vscode.ConfigurationScope | null +): T { + if (key === "fallbackFlags" && scope) { + const scopedConfig = vscode.workspace.getConfiguration("clangd", scope).get(key); + if (scopedConfig) { + return substitute(scopedConfig); + } + } + return substitute(vscode.workspace.getConfiguration("clangd").get(key)!); } // Sets the config value `clangd.`. Does not apply substitutions.