From d7ba5416e97d1a41092936cd544380d3bb624feb Mon Sep 17 00:00:00 2001 From: Giulio Girardi Date: Mon, 14 Dec 2020 16:15:25 +0100 Subject: [PATCH] Add watcher on settings to restart clangd if needed --- src/config-watcher.ts | 18 ++++++++++++++++++ src/extension.ts | 4 ++++ 2 files changed, 22 insertions(+) create mode 100644 src/config-watcher.ts diff --git a/src/config-watcher.ts b/src/config-watcher.ts new file mode 100644 index 00000000..9b153256 --- /dev/null +++ b/src/config-watcher.ts @@ -0,0 +1,18 @@ +import * as vscode from 'vscode'; + +const WATCHED_SETTINGS: String[] = + ['path', 'arguments', 'trace', 'fallbackFlags', 'semanticHighlighting']; + +async function handleConfigurationChanged(e: vscode.ConfigurationChangeEvent) { + for (let setting of WATCHED_SETTINGS) { + if (e.affectsConfiguration(`clangd.${setting}`)) { + vscode.commands.executeCommand('clangd.restart'); + break; + } + } +} + +export function activate(context: vscode.ExtensionContext) { + context.subscriptions.push( + vscode.workspace.onDidChangeConfiguration(handleConfigurationChanged)) +} diff --git a/src/extension.ts b/src/extension.ts index 78fdbe29..117cd7ab 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,6 +1,7 @@ import * as vscode from 'vscode'; import {ClangdContext} from './clangd-context'; +import * as ConfigWatcher from './config-watcher'; /** * This method is called when the extension is activated. The extension is @@ -13,6 +14,9 @@ export async function activate(context: vscode.ExtensionContext) { const clangdContext = new ClangdContext; context.subscriptions.push(clangdContext); + // Listen for settings changes + ConfigWatcher.activate(context); + // An empty place holder for the activate command, otherwise we'll get an // "command is not registered" error. context.subscriptions.push(