Skip to content

Commit

Permalink
Fix a potential race between didChange and didOpen (#13209)
Browse files Browse the repository at this point in the history
  • Loading branch information
Colengms authored Jan 28, 2025
1 parent 99864b0 commit e3bb8a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,13 @@ export async function activate(): Promise<void> {
getCustomConfigProviders().forEach(provider => void client.onRegisterCustomConfigurationProvider(provider));
});

disposables.push(vscode.workspace.onDidChangeConfiguration(onDidChangeSettings));
// These handlers for didChangeTextDocument and didOpenTextDocument are intentionally synchronous and are
// intended primarily to maintain openFileVersions with the most recent versions of files, as quickly as
// possible, without being delayed by awaits or queued behind other LSP messages, etc..
disposables.push(vscode.workspace.onDidChangeTextDocument(onDidChangeTextDocument));
disposables.push(vscode.workspace.onDidOpenTextDocument(onDidOpenTextDocument));

disposables.push(vscode.workspace.onDidChangeConfiguration(onDidChangeSettings));
disposables.push(vscode.window.onDidChangeTextEditorVisibleRanges((e) => clients.ActiveClient.enqueue(async () => onDidChangeTextEditorVisibleRanges(e))));
disposables.push(vscode.window.onDidChangeActiveTextEditor((e) => clients.ActiveClient.enqueue(async () => onDidChangeActiveTextEditor(e))));
ui.didChangeActiveEditor(); // Handle already active documents (for non-cpp files that we don't register didOpen).
Expand Down Expand Up @@ -303,6 +308,11 @@ function onDidChangeTextDocument(event: vscode.TextDocumentChangeEvent): void {
me.onDidChangeTextDocument(event);
}

function onDidOpenTextDocument(document: vscode.TextDocument): void {
const me: Client = clients.getClientFor(document.uri);
me.onDidOpenTextDocument(document);
}

let noActiveEditorTimeout: NodeJS.Timeout | undefined;

async function onDidChangeTextEditorVisibleRanges(event: vscode.TextEditorVisibleRangesChangeEvent): Promise<void> {
Expand Down
1 change: 0 additions & 1 deletion Extension/src/LanguageServer/protocolFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export function createProtocolFilter(): Middleware {
return;
}
// client.takeOwnership() will call client.TrackedDocuments.add() again, but that's ok. It's a Set.
client.onDidOpenTextDocument(document);
client.takeOwnership(document);
void sendMessage(document);
}
Expand Down

0 comments on commit e3bb8a7

Please sign in to comment.