From 24d92f586879e91fe9e684fc560ecab92e3a72d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=8C=AF=E4=BC=9F?= Date: Tue, 15 Oct 2024 09:23:16 +0800 Subject: [PATCH 1/3] Update package.json Add scope:language-overridable for "clangd.fallbackFlags" --- package.json | 1 + 1 file changed, 1 insertion(+) 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" }, From 52c1e33fe659c114b34e2b81bfa2c24cadfaafe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=8C=AF=E4=BC=9F?= Date: Tue, 15 Oct 2024 11:15:50 +0800 Subject: [PATCH 2/3] Modify ClangdContext to use current language scope for fallback flags --- src/clangd-context.ts | 12 ++++++++++-- src/config.ts | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) 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..c140de4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,8 +3,16 @@ 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) { + return substitute( + vscode.workspace.getConfiguration("clangd", scope).get(key)! + ); + } + return substitute(vscode.workspace.getConfiguration("clangd").get(key)!); } // Sets the config value `clangd.`. Does not apply substitutions. From 3d1449d6eb23b4f617931849c62ea53ab19ca770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=8C=AF=E4=BC=9F?= Date: Tue, 15 Oct 2024 12:58:04 +0800 Subject: [PATCH 3/3] Refactor config.ts to use current language scope for fallback flags --- src/config.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/config.ts b/src/config.ts index c140de4..015469a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -8,9 +8,10 @@ export function get( scope?: vscode.ConfigurationScope | null ): T { if (key === "fallbackFlags" && scope) { - return substitute( - vscode.workspace.getConfiguration("clangd", scope).get(key)! - ); + const scopedConfig = vscode.workspace.getConfiguration("clangd", scope).get(key); + if (scopedConfig) { + return substitute(scopedConfig); + } } return substitute(vscode.workspace.getConfiguration("clangd").get(key)!); }