Skip to content

Commit f12931b

Browse files
fix(vscode): await schema registry initialization before validating documents
- Change ValidationService.register() to async and await schema initialization - Prevents race condition where documents might be validated before schemas are loaded - Particularly important if schema loading becomes remote in the future Addresses PR feedback from @willosborne regarding void promise handling
1 parent 81f859b commit f12931b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

calm-plugins/vscode/src/calm-extension-controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ export class CalmExtensionController {
8585

8686
new CommandRegistrar(context, store).registerAll()
8787

88-
// Initialize validation service
88+
// Initialize validation service (await to ensure schemas are loaded before validating documents)
8989
const validationService = new ValidationService(log, configService)
90-
validationService.register(context)
90+
await validationService.register(context)
9191

9292
const storeReactionMediator = new StoreReactionMediator(
9393
store,

calm-plugins/vscode/src/features/validation/validation-service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ export class ValidationService implements vscode.Disposable {
4141

4242
/**
4343
* Register document listeners to trigger validation on save.
44+
* Async to ensure schema registry is fully initialized before validating documents.
4445
*/
45-
register(context: vscode.ExtensionContext): void {
46+
async register(context: vscode.ExtensionContext): Promise<void> {
4647
// Initialize the schema registry with bundled schemas
4748
this.schemaRegistry = new CalmSchemaRegistry(context.extensionUri, this.logger, this.config)
48-
void this.schemaRegistry.initialize()
49+
await this.schemaRegistry.initialize()
4950

5051
// Listen for configuration changes to reset schema registry
5152
this.disposables.push(

0 commit comments

Comments
 (0)