Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around issue with getting stale contents from openTextDocument #3545

Merged
merged 5 commits into from
Apr 29, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ export class CppProperties {
this.propertiesFile = null;
}

this.configFileWatcher = vscode.workspace.createFileSystemWatcher(path.join(this.configFolder, this.configurationGlobPattern));
let settingsPath: string = path.join(this.configFolder, this.configurationGlobPattern);
this.configFileWatcher = vscode.workspace.createFileSystemWatcher(settingsPath);
this.disposables.push(this.configFileWatcher);
this.configFileWatcher.onDidCreate((uri) => {
this.propertiesFile = uri;
Expand All @@ -187,7 +188,24 @@ export class CppProperties {
});

this.configFileWatcher.onDidChange(() => {
this.handleConfigurationChange();
// If the file is one of the textDocument's vscode is tracking, we need to wait for an
// onDidChangeTextDocument event, or we may get old/cached contents when we open it.
let alreadyTracking: boolean = false;
for (let i: number = 0; i < vscode.workspace.textDocuments.length; i++) {
if (vscode.workspace.textDocuments[i].uri.fsPath === settingsPath) {
alreadyTracking = true;
break;
}
}
if (!alreadyTracking) {
this.handleConfigurationChange();
}
});

vscode.workspace.onDidChangeTextDocument((e: vscode.TextDocumentChangeEvent) => {
if (e.document.uri.fsPath === settingsPath) {
this.handleConfigurationChange();
}
});

this.handleConfigurationChange();
Expand Down