Skip to content

Conversation

lambdalisue
Copy link
Member

@lambdalisue lambdalisue commented Aug 12, 2025

Summary

  • Fixed JSONC parsing issue by removing trailing comma from imports in deno.jsonc
  • This resolves potential compatibility issues with strict JSONC parsers

Test plan

  • Verified deno.jsonc is valid JSONC format
  • Confirmed denops loads correctly with the fix

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added support for loading local import maps from JSONC files (e.g., deno.jsonc, import_map.jsonc), enabling comments and trailing commas.
  • Bug Fixes

    • Improved robustness when loading local import maps with stricter parsing and validation to reduce errors from malformed configurations.
  • Chores

    • Updated dependencies, including import-map handling library.
    • Added a JSONC parsing library for configuration handling.

Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

Updated deno.jsonc to bump an importer dependency and add @std/jsonc. Modified plugin.ts to load local import maps via a JSONC parser and schema check by supplying a custom loader to loadImportMap; remote script handling remains unchanged. No public API changes.

Changes

Cohort / File(s) Summary
Config: Import map dependencies
denops/@denops-private/deno.jsonc
Bumped @lambdalisue/import-map-importer to ^0.5.0 and added dependency "@std/jsonc@^1.0.2".
Plugin: Local import map loading
denops/@denops-private/plugin.ts
Added imports (isImportMap, ensure, parseJsonc). Introduced loader that reads file, parses JSONC, and validates as ImportMap. Wired loader into tryLoadImportMap for local files (deno.json[c], import_map.json[c]). No API/type changes.

Sequence Diagram(s)

sequenceDiagram
  participant Plugin
  participant FS as File System
  participant JSONC as JSONC Parser
  participant Validator as ImportMap Validator

  Plugin->>FS: readText(import_map path)
  FS-->>Plugin: file content
  Plugin->>JSONC: parse(content)
  JSONC-->>Plugin: parsed object
  Plugin->>Validator: ensure(obj, isImportMap)
  Validator-->>Plugin: ImportMap or error
  Plugin-->>Plugin: loadImportMap({ loader })
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

Poem

A rabbit nibbles maps of imports neat,
JSONC leaves, a typed and tidy treat.
It sniffs, ensures, then hops along,
The plugin hums a parsing song.
With crisp new paths and versions bright—
All carrots lined, the code feels right. 🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-jsonc

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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@lambdalisue lambdalisue changed the title Fix JSONC trailing comma issue Fix JSONC loading issue Aug 12, 2025
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.77%. Comparing base (f63fa7f) to head (48bf0e2).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #454      +/-   ##
==========================================
+ Coverage   96.50%   96.77%   +0.27%     
==========================================
  Files          11       11              
  Lines         915      962      +47     
  Branches      142      143       +1     
==========================================
+ Hits          883      931      +48     
+ Misses         30       28       -2     
- Partials        2        3       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lambdalisue lambdalisue merged commit b0ee649 into main Aug 12, 2025
14 checks passed
@lambdalisue lambdalisue deleted the fix-jsonc branch August 12, 2025 01:36
Copy link

@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

🧹 Nitpick comments (2)
denops/@denops-private/plugin.ts (2)

171-176: Add tests for JSONC (comments/trailing commas) import map loading

This is a behavior change and worth pinning via tests to prevent regressions. I can draft a minimal test harness that writes a temporary deno.jsonc with trailing commas and verifies tryLoadImportMap resolves an ImportMap.

Do you want me to provide a test snippet leveraging the existing test setup?


171-176: Wrap loader errors for clearer diagnostics while preserving NotFound
The custom loader correctly handles JSONC and allows the outer loop to skip missing files. To make parse failures more actionable, catch non-NotFound errors and rethrow with file path context:

       return await loadImportMap(importMapPath, {
         loader: (path: string) => {
-          const content = Deno.readTextFileSync(path);
-          return ensure(parseJsonc(content), isImportMap);
+          try {
+            const content = Deno.readTextFileSync(path);
+            return ensure(parseJsonc(content), isImportMap);
+          } catch (err) {
+            if (err instanceof Deno.errors.NotFound) {
+              throw err; // let the outer loop try the next pattern
+            }
+            const msg = err instanceof Error ? err.message : String(err);
+            throw new Error(`Failed to parse import map (${path}): ${msg}`);
+          }
         },
       });

• Confirm whether loadImportMap accepts an async loader (i.e. one that returns a Promise). If it does, consider switching to the non-blocking await Deno.readTextFile(path) inside an async loader function.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f63fa7f and 48bf0e2.

📒 Files selected for processing (2)
  • denops/@denops-private/deno.jsonc (1 hunks)
  • denops/@denops-private/plugin.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Milly
PR: vim-denops/denops.vim#418
File: tests/denops/runtime/functions/plugin/check_type_test.ts:6-6
Timestamp: 2024-09-14T17:09:30.174Z
Learning: In this project, import paths prefixed with `/denops-testdata/` are defined in `deno.jsonc` via an import map, and these import paths are valid.
📚 Learning: 2024-09-14T17:09:30.174Z
Learnt from: Milly
PR: vim-denops/denops.vim#418
File: tests/denops/runtime/functions/plugin/check_type_test.ts:6-6
Timestamp: 2024-09-14T17:09:30.174Z
Learning: In this project, import paths prefixed with `/denops-testdata/` are defined in `deno.jsonc` via an import map, and these import paths are valid.

Applied to files:

  • denops/@denops-private/deno.jsonc
  • denops/@denops-private/plugin.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: test (ubuntu-latest, 2.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (ubuntu-latest, 1.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (macos-latest, 2.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (macos-latest, 1.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (windows-latest, 2.x, v9.1.0448, v0.10.0)
  • GitHub Check: test (ubuntu-latest, 1.45.0, v9.1.0448, v0.10.0)
  • GitHub Check: test (windows-latest, 1.45.0, v9.1.0448, v0.10.0)
  • GitHub Check: test (macos-latest, 1.45.0, v9.1.0448, v0.10.0)
  • GitHub Check: test (windows-latest, 1.x, v9.1.0448, v0.10.0)
🔇 Additional comments (5)
denops/@denops-private/deno.jsonc (2)

17-17: Adding @std/jsonc import mapping is appropriate

Enables robust JSONC parsing (comments/trailing commas) used in plugin.ts. Looks good.


9-9: @lambdalisue/import-map-importer ^0.5.0 bump compatibility confirmed
Only denops/@denops-private/plugin.ts imports and calls loadImportMap with the new loader callback signature introduced in v0.5.0. There are no other references to pre-0.5 behavior in the codebase.

denops/@denops-private/plugin.ts (3)

5-7: Importing isImportMap to type-guard parsed import maps is a solid addition

This ensures only valid ImportMap objects flow into the importer.


8-8: Bringing in ensure from unknownutil is appropriate

Keeps runtime validation explicit and typed.


13-13: Using @std/jsonc.parse is the right choice for JSONC files

This will handle comments and trailing commas reliably.

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.

1 participant