Skip to content

Conversation

@jiashengguo
Copy link
Member

@jiashengguo jiashengguo commented Jun 13, 2025

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 13, 2025

📝 Walkthrough

Walkthrough

The update refines the loadAdditionalDocuments method in the ZModelWorkspaceManager class to dynamically locate and load the standard library document. It now searches for the stdlib within workspace folders' node_modules/zenstack packages, falling back to the bundled version if not found, and adds error handling and logging for the resolution process.

Changes

File(s) Change Summary
packages/schema/src/language-server/zmodel-workspace-manager.ts Enhanced stdlib resolution in loadAdditionalDocuments to search workspace node_modules/zenstack before fallback, with error handling and logging.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ZModelWorkspaceManager
    participant WorkspaceFolders
    participant NodeModules
    participant ExtensionResources

    User->>ZModelWorkspaceManager: loadAdditionalDocuments()
    ZModelWorkspaceManager->>WorkspaceFolders: For each folder, try to resolve zenstack/package.json
    alt zenstack found in node_modules
        ZModelWorkspaceManager->>NodeModules: Construct stdlib path in zenstack package
        NodeModules-->>ZModelWorkspaceManager: Return stdlib path if exists
        ZModelWorkspaceManager->>ZModelWorkspaceManager: Use resolved stdlib path
    else zenstack not found
        ZModelWorkspaceManager->>ExtensionResources: Use bundled stdlib path
    end
    ZModelWorkspaceManager->>ZModelWorkspaceManager: Load stdlib document
    ZModelWorkspaceManager-->>User: Return loaded documents
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jiashengguo jiashengguo changed the title fix(vscode): try to load stdlib firstly from the installed zenstack p… fix(vscode): try to load stdlib firstly from the installed zenstack package Jun 13, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/schema/src/language-server/zmodel-workspace-manager.ts (3)

36-39: Replace blocking fs.existsSync with the async variant or Langium’s FS provider

fs.existsSync blocks the event loop; in a VS Code extension this can delay the language server, especially in large multi-root workspaces. Using an asynchronous check (or this.fileSystemProvider.exists(uri)) keeps the extension responsive.

-                if (fs.existsSync(candidateStdlibPath)) {
+                /* prefer async IO to avoid blocking the extension host */
+                if (await fs.promises
+                    .access(candidateStdlibPath, fs.constants.F_OK)
+                    .then(() => true)
+                    .catch(() => false)) {

Alternatively, leverage Langium’s fileSystemProvider.exists for consistency with the rest of the codebase.


29-34: Guard against false-positive resolutions

require.resolve('zenstack/package.json', { paths: [folderPath] }) throws any resolution error (including package.json missing). Consider checking error.code === 'MODULE_NOT_FOUND' before logging to avoid alarming stack traces for the normal “not found” case.

-            } catch (error) {
+            } catch (error: unknown) {
+                if ((error as NodeJS.ErrnoException)?.code !== 'MODULE_NOT_FOUND') {
+                    console.error(
+                        `Unexpected error while resolving zenstack in ${folder.uri}:`,
+                        error
+                    );
+                }

Reduces noisy logs while still surfacing genuine issues.


22-23: Nit: _folders/_collector prefix implies “unused” but they are used

The leading underscore conventionally signals an intentionally unused parameter. Since both variables are actively referenced, consider dropping the prefix to avoid confusion.

-    protected async loadAdditionalDocuments(
-        _folders: WorkspaceFolder[],
-        _collector: (document: LangiumDocument) => void
+    protected async loadAdditionalDocuments(
+        folders: WorkspaceFolder[],
+        collector: (document: LangiumDocument) => void

Adjust internal references accordingly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8cbfbb and c775d6f.

📒 Files selected for processing (1)
  • packages/schema/src/language-server/zmodel-workspace-manager.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/schema/src/language-server/zmodel-workspace-manager.ts

[error] 45-45: Unnecessary continue statement

Unsafe fix: Delete the unnecessary continue statement

(lint/correctness/noUnnecessaryContinue)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build-test (20.x)
  • GitHub Check: dependency-review
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: build-test (20.x)
  • GitHub Check: OSSAR-Scan
  • GitHub Check: build-test (20.x)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/schema/src/language-server/zmodel-workspace-manager.ts (1)

42-45: Drop the redundant continue; Biome still flags it

The for … of loop naturally proceeds to the next iteration after the catch block, so the continue is unnecessary and still triggers noUnnecessaryContinue.

-        } catch (error) {
-            // Package not found or other error, continue to next folder
-            continue;
-        }
+        } catch (error) {
+            // Package not found or other error – move on to the next folder
+        }
🧰 Tools
🪛 Biome (1.9.4)

[error] 44-44: Unnecessary continue statement

Unsafe fix: Delete the unnecessary continue statement

(lint/correctness/noUnnecessaryContinue)

🧹 Nitpick comments (2)
packages/schema/src/language-server/zmodel-workspace-manager.ts (2)

36-41: Replace blocking fs.existsSync with the async FS API

fs.existsSync is synchronous and blocks the event-loop, which can hurt responsiveness inside the VS Code extension host. Use an async check (or just attempt to readFile/stat and swallow ENOENT) instead.

-                if (fs.existsSync(candidateStdlibPath)) {
-                    installedStdlibPath = candidateStdlibPath;
-                    console.log(`Found installed zenstack package stdlib at ${installedStdlibPath}`);
-                    break;
-                } 
+                try {
+                    await fs.promises.access(candidateStdlibPath, fs.constants.R_OK);
+                    installedStdlibPath = candidateStdlibPath;
+                    console.log(`Found installed zenstack package stdlib at ${installedStdlibPath}`);
+                    break;
+                } catch {
+                    /* not readable / not present – continue searching */
+                }

30-35: Consider using the extension’s logger instead of console.log

Raw console.log writes go to the shared extension host output and can be noisy. If the project has a dedicated logging facility (e.g. VS Code OutputChannel or console wrapper), prefer that for consistency and log-level control.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c775d6f and 8a72be5.

📒 Files selected for processing (1)
  • packages/schema/src/language-server/zmodel-workspace-manager.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/schema/src/language-server/zmodel-workspace-manager.ts

[error] 44-44: Unnecessary continue statement

Unsafe fix: Delete the unnecessary continue statement

(lint/correctness/noUnnecessaryContinue)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: OSSAR-Scan
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
  • GitHub Check: dependency-review
  • GitHub Check: build-test (20.x)
  • GitHub Check: Analyze (javascript-typescript)

@ymc9 ymc9 merged commit 94f9d2a into dev Jun 15, 2025
11 checks passed
@ymc9 ymc9 deleted the jiasheng-fix branch June 15, 2025 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants