Skip to content

Commit

Permalink
Remove recursive file watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
rapgenic committed Sep 27, 2020
1 parent 3677675 commit c1ac952
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/config-file-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ export function activate(context: vscode.ExtensionContext) {
}

class ConfigFileWatcher {
private databaseWatcher = vscode.workspace.createFileSystemWatcher(
'**/{compile_commands.json,compile_flags.txt,.clang-tidy}');
private databaseWatcher: vscode.FileSystemWatcher = undefined;

constructor(private context: vscode.ExtensionContext) {
context.subscriptions.push(this.databaseWatcher.onDidChange(
this.createFileSystemWatcher();
context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders(
() => { this.createFileSystemWatcher(); }));
}

createFileSystemWatcher() {
if (this.databaseWatcher)
this.databaseWatcher.dispose();
this.databaseWatcher = vscode.workspace.createFileSystemWatcher(
'{' +
vscode.workspace.workspaceFolders.map(f => f.uri.fsPath).join(',') +
'}/{build/compile_commands.json,compile_commands.json,compile_flags.txt,.clang-tidy}');
this.context.subscriptions.push(this.databaseWatcher.onDidChange(
this.handleConfigFilesChanged.bind(this)));
context.subscriptions.push(this.databaseWatcher.onDidCreate(
this.context.subscriptions.push(this.databaseWatcher.onDidCreate(
this.handleConfigFilesChanged.bind(this)));
context.subscriptions.push(this.databaseWatcher);
this.context.subscriptions.push(this.databaseWatcher);
}

async handleConfigFilesChanged(uri: vscode.Uri) {
Expand All @@ -29,13 +40,6 @@ class ConfigFileWatcher {
if ((await vscode.workspace.fs.stat(uri)).size <= 0)
return;

let relativePath = vscode.workspace.asRelativePath(uri, false);
let baseName = path.basename(uri.fsPath);

if (relativePath != baseName &&
relativePath != 'build/compile_commands.json')
return;

switch (config.get<string>('onConfigChanged')) {
case 'restart':
vscode.commands.executeCommand('clangd.restart');
Expand Down

0 comments on commit c1ac952

Please sign in to comment.