From 92e86b85730028b6949911c952e2c3b9f332b78d Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 17 Oct 2025 13:18:03 -0700 Subject: [PATCH 1/4] fix(vscode): filter out non-file doc uri in stage change hook --- packages/ide/vscode/package.json | 2 +- packages/language/src/module.ts | 38 +++++++++++++++++--------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/packages/ide/vscode/package.json b/packages/ide/vscode/package.json index 44f22fcc..634044c6 100644 --- a/packages/ide/vscode/package.json +++ b/packages/ide/vscode/package.json @@ -1,7 +1,7 @@ { "name": "zenstack-v3", "publisher": "zenstack", - "version": "3.0.9", + "version": "3.0.11", "displayName": "ZenStack V3 Language Tools", "description": "VSCode extension for ZenStack (v3) ZModel language", "private": true, diff --git a/packages/language/src/module.ts b/packages/language/src/module.ts index cff4ac0e..e69c0833 100644 --- a/packages/language/src/module.ts +++ b/packages/language/src/module.ts @@ -94,25 +94,27 @@ export function createZModelLanguageServices( // when documents reach Parsed state, inspect plugin declarations and load corresponding // plugin zmodel docs - shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.Parsed, async (documents) => { - for (const doc of documents) { - if (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0) { - // balk if there are lexer or parser errors - continue; - } + shared.workspace.DocumentBuilder.onDocumentPhase(DocumentState.Parsed, async (doc) => { + if (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0) { + // balk if there are lexer or parser errors + return; + } + + if (doc.uri.scheme !== 'file') { + return; + } - const schemaPath = fileURLToPath(doc.uri.toString()); - const pluginSchemas = getPluginDocuments(doc.parseResult.value as Model, schemaPath); - for (const plugin of pluginSchemas) { - // load the plugin model document - const pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument( - URI.file(path.resolve(plugin)), - ); - // add to indexer so the plugin model's definitions are globally visible - shared.workspace.IndexManager.updateContent(pluginDoc); - if (logToConsole) { - console.log(`Loaded plugin model: ${plugin}`); - } + const schemaPath = fileURLToPath(doc.uri.toString()); + const pluginSchemas = getPluginDocuments(doc.parseResult.value as Model, schemaPath); + for (const plugin of pluginSchemas) { + // load the plugin model document + const pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument( + URI.file(path.resolve(plugin)), + ); + // add to indexer so the plugin model's definitions are globally visible + shared.workspace.IndexManager.updateContent(pluginDoc); + if (logToConsole) { + console.log(`Loaded plugin model: ${plugin}`); } } }); From d54e667648ee6c06619b54bd86d741c4de94fb37 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 17 Oct 2025 13:23:18 -0700 Subject: [PATCH 2/4] update --- packages/language/src/module.ts | 42 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/language/src/module.ts b/packages/language/src/module.ts index e69c0833..0a154b0e 100644 --- a/packages/language/src/module.ts +++ b/packages/language/src/module.ts @@ -94,27 +94,31 @@ export function createZModelLanguageServices( // when documents reach Parsed state, inspect plugin declarations and load corresponding // plugin zmodel docs - shared.workspace.DocumentBuilder.onDocumentPhase(DocumentState.Parsed, async (doc) => { - if (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0) { - // balk if there are lexer or parser errors - return; - } + // Note we must use `noBuildPhase` instead of `onDocumentPhase` here because the latter is + // not called when not running inside a language server. + shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.Parsed, async (documents) => { + for (const doc of documents) { + if (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0) { + // balk if there are lexer or parser errors + return; + } - if (doc.uri.scheme !== 'file') { - return; - } + if (doc.uri.scheme !== 'file') { + return; + } - const schemaPath = fileURLToPath(doc.uri.toString()); - const pluginSchemas = getPluginDocuments(doc.parseResult.value as Model, schemaPath); - for (const plugin of pluginSchemas) { - // load the plugin model document - const pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument( - URI.file(path.resolve(plugin)), - ); - // add to indexer so the plugin model's definitions are globally visible - shared.workspace.IndexManager.updateContent(pluginDoc); - if (logToConsole) { - console.log(`Loaded plugin model: ${plugin}`); + const schemaPath = fileURLToPath(doc.uri.toString()); + const pluginSchemas = getPluginDocuments(doc.parseResult.value as Model, schemaPath); + for (const plugin of pluginSchemas) { + // load the plugin model document + const pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument( + URI.file(path.resolve(plugin)), + ); + // add to indexer so the plugin model's definitions are globally visible + shared.workspace.IndexManager.updateContent(pluginDoc); + if (logToConsole) { + console.log(`Loaded plugin model: ${plugin}`); + } } } }); From 8030afc11fcb4a12c90c1469c24b28606b76e3e1 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 17 Oct 2025 13:26:44 -0700 Subject: [PATCH 3/4] update --- packages/language/src/module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/language/src/module.ts b/packages/language/src/module.ts index 0a154b0e..be37fe4f 100644 --- a/packages/language/src/module.ts +++ b/packages/language/src/module.ts @@ -100,11 +100,11 @@ export function createZModelLanguageServices( for (const doc of documents) { if (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0) { // balk if there are lexer or parser errors - return; + continue; } if (doc.uri.scheme !== 'file') { - return; + continue; } const schemaPath = fileURLToPath(doc.uri.toString()); From 347dc8fbbce7c05738278abcdca59222aaa6423e Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Fri, 17 Oct 2025 13:27:17 -0700 Subject: [PATCH 4/4] update --- packages/language/src/module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language/src/module.ts b/packages/language/src/module.ts index be37fe4f..df83d4e0 100644 --- a/packages/language/src/module.ts +++ b/packages/language/src/module.ts @@ -94,7 +94,7 @@ export function createZModelLanguageServices( // when documents reach Parsed state, inspect plugin declarations and load corresponding // plugin zmodel docs - // Note we must use `noBuildPhase` instead of `onDocumentPhase` here because the latter is + // Note we must use `onBuildPhase` instead of `onDocumentPhase` here because the latter is // not called when not running inside a language server. shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.Parsed, async (documents) => { for (const doc of documents) {