Skip to content

Commit

Permalink
feat: resolve possible symlinks before db modification watching
Browse files Browse the repository at this point in the history
Watching a symlink instead of the target file won't actually trigger a
db reloading if the symlinked file changes
  • Loading branch information
BenjaminNavarro committed May 9, 2020
1 parent e00cdc3 commit 8b9c58c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
11 changes: 8 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
},
"dependencies": {
"vscode-languageclient": "^5.2.1",
"ws": "^6.2.1"
"ws": "^6.2.1",
"fs": "^0.0.1-security"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -741,5 +742,10 @@
}
}
}
},
"__metadata": {
"id": "8e21d425-1e30-4072-8436-786a9017e5c7",
"publisherDisplayName": "ccls-project",
"publisherId": "c8f976c9-da3f-47d4-a344-bc810b73caed"
}
}
9 changes: 7 additions & 2 deletions src/serverContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as cp from "child_process";
import * as fs from 'fs';
import {
CancellationToken,
CodeLens,
Expand Down Expand Up @@ -304,7 +305,11 @@ export class ServerContext implements Disposable {
let db_dir = config.get('misc.compilationDatabaseDirectory');
if (!db_dir || db_dir === '')
db_dir = this.cwd;
const db_watcher = workspace.createFileSystemWatcher(db_dir + '/compile_commands.json', false, false, false);
const db_path = db_dir + '/compile_commands.json';
// resolve db_path in case it is a symlink, otherwise the file system watcher
// won't catch modifications of the linked file
const db_real_path = fs.realpathSync(db_path);
const db_watcher = workspace.createFileSystemWatcher(db_real_path, false, false, false);
this._dispose.push(db_watcher);
db_watcher.onDidChange((e: Uri) => {
this.client.sendNotification("workspace/didChangeConfiguration");
Expand Down Expand Up @@ -465,7 +470,7 @@ export class ServerContext implements Disposable {
documentSelector: ['c', 'cpp', 'objective-c', 'objective-cpp'],
// synchronize: {
// configurationSection: 'ccls',
// fileEvents: workspace.createFileSystemWatcher('**/.cc')
// fileEvents: workspace.createfsWatcher('**/.cc')
// },
errorHandler: new CclsErrorHandler(config),
initializationFailedHandler: (e) => {
Expand Down

0 comments on commit 8b9c58c

Please sign in to comment.