Skip to content

Commit 766a20e

Browse files
committed
fix: address Copilot review comments (round 4)
- Update AsyncSerializer JSDoc to document rejection behavior: the returned promise can reject, rethrowing the first error after all pending executions have been processed - Wrap reloadMkdocsConfig body in try/catch to prevent unhandled promise rejections from propagating to the extension host; errors are logged to the output channel and shown as a user-friendly message - Rename coalescing test to 'should coalesce multiple pending calls into a single additional execution' for accuracy
1 parent 6e78204 commit 766a20e

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

src/asyncSerializer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export class AsyncSerializer {
3535
* @returns A promise that resolves when this call has been acknowledged
3636
* (either executed immediately or queued for a coalesced re-run). Awaiting
3737
* this promise does not guarantee a distinct execution of {@link fn} for
38-
* this call; coalesced calls share execution cycles.
38+
* this call; coalesced calls share execution cycles. The promise rejects
39+
* if any execution performed during this cycle throws, and rethrows the
40+
* first error encountered after pending executions have been processed.
3941
*/
4042
async execute(fn: () => Promise<void>): Promise<void> {
4143
// If already executing, store latest fn for the coalesced re-run and return immediately

src/extension.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,25 @@ export async function activate(context: vscode.ExtensionContext) {
5050

5151
// Reload config and refresh diagnostics when mkdocs config changes
5252
const reloadMkdocsConfig = async () => {
53-
await configReloadSerializer.execute(async () => {
54-
const currentFolders = vscode.workspace.workspaceFolders;
55-
if (currentFolders && currentFolders.length > 0) {
56-
await diagnosticManager.loadMkdocsConfig(currentFolders[0].uri.fsPath);
57-
58-
// Refresh diagnostics for all open markdown files
59-
vscode.window.visibleTextEditors
60-
.filter(editor => editor.document.languageId === 'markdown')
61-
.forEach(editor => {
62-
diagnosticManager.updateDiagnostics(editor.document);
63-
});
64-
}
65-
});
53+
try {
54+
await configReloadSerializer.execute(async () => {
55+
const currentFolders = vscode.workspace.workspaceFolders;
56+
if (currentFolders && currentFolders.length > 0) {
57+
await diagnosticManager.loadMkdocsConfig(currentFolders[0].uri.fsPath);
58+
59+
// Refresh diagnostics for all open markdown files
60+
vscode.window.visibleTextEditors
61+
.filter(editor => editor.document.languageId === 'markdown')
62+
.forEach(editor => {
63+
diagnosticManager.updateDiagnostics(editor.document);
64+
});
65+
}
66+
});
67+
} catch (error) {
68+
const errorMessage = error instanceof Error ? error.message : String(error);
69+
outputChannel.appendLine(`Failed to reload MkDocs configuration: ${errorMessage}`);
70+
void vscode.window.showErrorMessage('Failed to reload MkDocs configuration. See output for details.');
71+
}
6672
};
6773

6874
mkdocsWatcher.onDidCreate(reloadMkdocsConfig);

src/test/unit/asyncSerializer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('AsyncSerializer', () => {
4040
assert.strictEqual(maxInFlight, 1, 'At most one execution should be in flight at a time');
4141
});
4242

43-
it('should coalesce multiple pending calls into single execution', async () => {
43+
it('should coalesce multiple pending calls into a single additional execution', async () => {
4444
const serializer = new AsyncSerializer();
4545
let executionCount = 0;
4646

0 commit comments

Comments
 (0)