Skip to content

Conversation

tiye
Copy link
Member

@tiye tiye commented Sep 25, 2025

No description provided.

@tiye tiye requested review from a team and Copilot September 25, 2025 17:49
Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds docs-aware execution and error reporting, preloads embedded calcit-core.cirru into the dependency cache, stores per-definition docs and examples in program/snapshot data, refactors MCP namespace lookup to consult current module then dependencies, introduces a CLI check-examples flow, and bumps package versions to 0.9.20.

Changes

Cohort / File(s) Summary
Version bump
Cargo.toml, package.json, src/mcp/mcp_handlers.rs
Update package/server version strings from 0.9.180.9.20.
Docs-aware execution & error display
src/lib.rs, src/bin/cr.rs, src/call_stack.rs
Add run_program_with_docs; refactor run_program to delegate; add display_stack_with_docs (and make display_stack delegate); replace stack-display calls to include documentation and examples; integrate docs-aware runner into CLI flow and check-examples.
Program data: defs with docs & examples
src/program.rs
Introduce ProgramDefEntry { code, doc, examples }; change per-file defs map to HashMap<Arc<str>, ProgramDefEntry>; add lookup_def_doc and lookup_def_examples; update extraction, lookup, apply-code-changes, and has_def_code accordingly.
Snapshot & CodeEntry examples
src/snapshot.rs, src/detailed_snapshot.rs
Add pub examples: Vec<Cirru>/Vec<String> to CodeEntry with serde default; include examples in Edn conversions and TryFrom/From implementations; initialize examples as empty where constructed; tests added for parsing/serialization; From<DetailedCodeEntry> sets examples: vec![].
MCP dependency/core preloading & APIs
src/mcp/state_manager.rs
Always preload embedded calcit-core.cirru via include_bytes!; update load_core_module to use embedded content; add find_namespace_in_dependencies() and get_all_dependency_namespaces(); ensure core cached during dependency setup; tests added.
MCP read/definition handlers
src/mcp/read_handlers.rs, src/mcp/definition_handlers.rs
list_namespace_definitions now prefers current module then falls back to dependencies and returns source marker; read_definition_doc and read/upsert flows propagate and expose examples alongside docs; error messages enhanced.
Core language docs & examples
src/cirru/calcit-core.cirru
Expand many placeholder docstrings into extensive documentation and executable :examples blocks across macros, functions, and primitives; documentation and examples embedded without changing runtime semantics.
CLI args / check-examples
src/cli_args.rs, src/bin/cr.rs
Add check-examples subcommand and CheckExamplesCommand; implement CLI handling and run_check_examples orchestration that synthesizes a :calcit:check-examples function and runs it via docs-aware runner.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CLI as CLI / cr
  participant Lib as lib::run_program_with_docs
  participant PP as Preprocessor
  participant Eval as Evaluator
  participant CS as call_stack::display_stack_with_docs
  note over CLI,Lib: Docs-aware run entry (new)
  CLI->>Lib: run_program_with_docs(ns, def, params)
  Lib->>PP: preprocess()
  alt preprocessing ok
    Lib->>Eval: evaluate(ns, def, params)
    alt success
      Eval-->>Lib: result
      Lib-->>CLI: result
    else failure
      Eval-->>Lib: error(stack, location)
      Lib->>CS: display_stack_with_docs(failure, stack, location)
      CS-->>Lib: printed snapshot + docs/examples
      Lib-->>CLI: error
    end
  else preprocessing error
    PP-->>Lib: error(stack, location)
    Lib->>CS: display_stack_with_docs(...)
    CS-->>Lib: printed snapshot + docs/examples
    Lib-->>CLI: error
  end
Loading
sequenceDiagram
  autonumber
  participant Client as MCP Client
  participant Read as mcp::read_handlers
  participant SM as StateManager
  note over Client,Read: List namespace definitions (current → deps fallback)
  Client->>Read: list_namespace_definitions(ns)
  Read->>SM: with_current_module(ns)?
  alt found in current module
    SM-->>Read: file data
    Read-->>Client: {source: "current", data}
  else not found
    Read->>SM: find_namespace_in_dependencies(ns)
    alt found in deps
      SM-->>Read: (pkg, file data)
      Read-->>Client: {source: "dependency", package: pkg, data}
    else not found
      Read->>SM: get_all_dependency_namespaces()
      SM-->>Read: namespaces
      Read-->>Client: error with suggestions
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

In burrows of code I twitch my nose,
I bump to 0.9.20 where the call stack goes.
Docs and examples tucked in tight,
Core bundled close, no missing light.
I hop, I check, I nudge with delight—errors teach by moonlit byte. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request has no description, which provides no context or summary of the extensive changes made across multiple modules. Without any description, it is difficult to quickly understand the scope and intent of the updates. Please add a brief description summarizing the objectives of the pull request, including key refactorings, documentation enhancements, CLI additions, and version bumps to aid reviewers in understanding its scope.
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The pull request title “Refine tools, getting more docs” is overly broad and does not clearly convey the introduction of documentation and examples support across the codebase, new CLI subcommands, and version updates. It uses vague terminology and fails to highlight the primary objectives of the changeset. Please update the title to more precisely reflect the main changes, such as adding documentation and examples support, introducing the check-examples CLI subcommand, and bumping the package version.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refine-tools

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the Calcit tooling by adding documentation support throughout the codebase. The main purpose is to improve the developer experience by providing better error messages with documentation context and extending MCP (Model Context Protocol) capabilities to handle dependency namespaces.

  • Refactored program data structures to include documentation alongside code definitions
  • Enhanced error handling and call stack display to show function documentation
  • Added comprehensive documentation to built-in Calcit core functions and syntax elements

Reviewed Changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/program.rs Added ProgramDefEntry struct to store code with documentation and updated related functions
src/mcp/state_manager.rs Enhanced MCP state management with calcit-core module loading and dependency namespace queries
src/mcp/read_handlers.rs Improved namespace definition listing to search both current project and dependencies
src/mcp/mcp_handlers.rs Updated version number to 0.9.19
src/lib.rs Added run_program_with_docs function and updated error handling to use documentation-aware stack display
src/cirru/calcit-core.cirru Added extensive documentation for built-in functions and syntax elements
src/call_stack.rs Enhanced stack display to include documentation when available
package.json Version bump to 0.9.19
Cargo.toml Version bump to 0.9.19

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +130 to +134
let doc = if entry.doc.is_empty() {
Arc::from("")
} else {
Arc::from(entry.doc.as_str())
};
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

The conditional check and Arc creation is redundant. You can simplify this to Arc::from(entry.doc.as_str()) since Arc::from("") and Arc::from(entry.doc.as_str()) when entry.doc is empty will produce equivalent results.

Suggested change
let doc = if entry.doc.is_empty() {
Arc::from("")
} else {
Arc::from(entry.doc.as_str())
};
let doc = Arc::from(entry.doc.as_str());

Copilot uses AI. Check for mistakes.

let calcit_code = code_to_calcit(code, ns, def, coord0.to_owned())?;
let entry = ProgramDefEntry {
code: calcit_code,
doc: Arc::from(""), // No doc info in changes, use empty string
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

Consider using a constant for the empty documentation string to avoid code duplication. This magic string appears multiple times in the code and could be extracted to a constant like const EMPTY_DOC: &str = \"\";.

Copilot uses AI. Check for mistakes.

let calcit_code = code_to_calcit(code, ns, def, coord0.to_owned())?;
let entry = ProgramDefEntry {
code: calcit_code,
doc: Arc::from(""), // No doc info in changes, use empty string
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

This is the same magic string as in the previous comment. Consider using a constant for the empty documentation string to improve maintainability.

Copilot uses AI. Check for mistakes.

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: 4

🧹 Nitpick comments (13)
src/mcp/mcp_handlers.rs (1)

218-221: Avoid hardcoding version; derive from Cargo metadata.

Use env!("CARGO_PKG_VERSION") to prevent drift across files.

Apply this diff:

       server_info: ServerInfo {
         name: "calcit-mcp-server".to_string(),
-        version: "0.9.19".to_string(),
+        version: env!("CARGO_PKG_VERSION").to_string(),
       },
src/bin/cr.rs (5)

272-274: Comment-only addition.

If this is a TODO, consider marking explicitly to aid tracking.


339-341: Don’t let stack display failure short-circuit error handling.

Avoid ? so we still write COMPILE_ERRORS_FILE and return the original failure.

Apply this diff:

-      call_stack::display_stack_with_docs(&failure.msg, &failure.stack, failure.location.as_ref())?;
+      if let Err(e) = call_stack::display_stack_with_docs(&failure.msg, &failure.stack, failure.location.as_ref()) {
+        eprintln!("failed to display stack: {e}");
+      }

357-359: Same: avoid propagating display failure in preprocessing reload path.

-      call_stack::display_stack_with_docs(&failure.msg, &failure.stack, failure.location.as_ref())?;
+      if let Err(e) = call_stack::display_stack_with_docs(&failure.msg, &failure.stack, failure.location.as_ref()) {
+        eprintln!("failed to display stack: {e}");
+      }

375-378: Same: codegen(IR) error path shouldn’t be blocked by display failure.

-        call_stack::display_stack_with_docs(&failure, &gen_stack::get_gen_stack(), None)?;
+        if let Err(e) = call_stack::display_stack_with_docs(&failure, &gen_stack::get_gen_stack(), None) {
+          eprintln!("failed to display stack: {e}");
+        }

385-388: Same: codegen(JS) error path shouldn’t be blocked by display failure.

-        call_stack::display_stack_with_docs(&failure, &gen_stack::get_gen_stack(), None)?;
+        if let Err(e) = call_stack::display_stack_with_docs(&failure, &gen_stack::get_gen_stack(), None) {
+          eprintln!("failed to display stack: {e}");
+        }
src/lib.rs (2)

55-58: Don’t propagate stack display failure; preserve original error.

Using ? can return a different error type and lose the original failure context.

Apply this diff:

-      call_stack::display_stack_with_docs(&failure.msg, &failure.stack, failure.location.as_ref())?;
+      if let Err(e) = call_stack::display_stack_with_docs(&failure.msg, &failure.stack, failure.location.as_ref()) {
+        eprintln!("failed to display stack: {e}");
+      }

79-81: Same concern in function-execution failure branch.

-            call_stack::display_stack_with_docs(&failure.msg, &failure.stack, failure.location.as_ref())?;
+            if let Err(e) = call_stack::display_stack_with_docs(&failure.msg, &failure.stack, failure.location.as_ref()) {
+              eprintln!("failed to display stack: {e}");
+            }
src/call_stack.rs (1)

137-142: Avoid repeated global lookups inside hot loop.

lookup_def_doc acquires a read lock on PROGRAM_CODE_DATA every time we iterate a stack frame. For a deep stack this adds avoidable contention. Cache the PROGRAM_CODE_DATA snapshot once before the loop and reuse it when you enrich each frame.

src/mcp/state_manager.rs (2)

414-428: Surface core load failures to callers.

Swallowing the load_core_module error with a println means tooling can’t detect when the embedded core failed to load (e.g. due to corrupted assets), leading to confusing downstream errors. Bubble the error up instead so the caller can decide whether to abort or report loudly.


635-669: Replace printlns in tests with assertions/logging macros.

Tests should avoid println! noise; use assertions to verify expectations or eprintln! guarded by a feature flag if you need diagnostics.

src/program.rs (2)

127-136: Don’t promote borrowed doc strings to empty Arc constants unnecessarily.

When entry.doc is empty we can skip allocating a brand-new Arc<str> and reuse Arc::<str>::default() (or leave it as Arc<str> created once). Consider retaining the shared empty arc rather than creating a new allocation per definition.


167-173: Clarify doc lifetime when returning String.

Returning Some(entry.doc.to_string()) clones the doc on every lookup. If we expect hot-path reads, consider returning Arc<str> (or Cow<'static, str>) instead to avoid repeated allocations.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36743bc and 0968e50.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • Cargo.toml (1 hunks)
  • package.json (1 hunks)
  • src/bin/cr.rs (7 hunks)
  • src/call_stack.rs (2 hunks)
  • src/cirru/calcit-core.cirru (3 hunks)
  • src/lib.rs (2 hunks)
  • src/mcp/mcp_handlers.rs (1 hunks)
  • src/mcp/read_handlers.rs (1 hunks)
  • src/mcp/state_manager.rs (4 hunks)
  • src/program.rs (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (6)
src/lib.rs (1)
src/call_stack.rs (1)
  • display_stack_with_docs (111-163)
src/call_stack.rs (3)
src/calcit.rs (1)
  • tag (696-698)
src/data/cirru.rs (3)
  • s (90-90)
  • s (92-92)
  • calcit_to_cirru (240-274)
src/program.rs (1)
  • lookup_def_doc (168-173)
src/mcp/read_handlers.rs (2)
src/mcp/definition_handlers.rs (1)
  • snapshot (775-775)
src/mcp/state_manager.rs (1)
  • new (60-66)
src/mcp/state_manager.rs (2)
src/mcp/read_handlers.rs (2)
  • snapshot (61-61)
  • list_namespace_definitions (6-89)
src/snapshot.rs (1)
  • load_snapshot_data (110-123)
src/program.rs (2)
src/data/cirru.rs (4)
  • code_to_calcit (8-161)
  • s (90-90)
  • s (92-92)
  • xs (254-254)
src/snapshot.rs (6)
  • from (32-37)
  • from (48-50)
  • from (67-72)
  • from (76-84)
  • from (197-231)
  • from (235-238)
src/bin/cr.rs (3)
src/lib.rs (1)
  • run_program_with_docs (48-87)
src/call_stack.rs (1)
  • display_stack_with_docs (111-163)
src/codegen/emit_js/gen_stack.rs (1)
  • get_gen_stack (37-40)
⏰ 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). (1)
  • GitHub Check: Publish to cargo
🔇 Additional comments (6)
Cargo.toml (1)

4-4: Cargo version updated — LGTM.

src/bin/cr.rs (2)

168-171: Switch to docs-aware run path — LGTM.


296-300: Docs-aware reload run — LGTM.

src/lib.rs (2)

45-46: Keep run_program delegating — LGTM.


48-58: ? compatibility on display_stack_with_docs is verified

impl From<String> for CalcitErr exists, so the ? on display_stack_with_docs (also at lines 79–81) compiles correctly.

package.json (1)

3-3: Version consistency confirmed. package.json, Cargo.toml, and MCP server all at 0.9.19.

Comment on lines 475 to 476
:code $ quote
defn + (x & ys) (reduce ys x &+)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Ensure docstring wording matches actual behavior.

The new docstring for + claims the function “requires at least one argument,” but (+) still works (returns 0). Adjust the notes to avoid misleading users.

🤖 Prompt for AI Agents
In src/cirru/calcit-core.cirru around lines 475 to 476, the docstring for the +
function incorrectly states it “requires at least one argument” while the
implementation still allows zero-arity (+) returning 0; update the docstring to
accurately reflect behavior (either state that it accepts zero or more arguments
and returns 0 for no args, or change wording to “accepts zero or more
arguments”); ensure the notes align with the implementation so users are not
misled.

Comment on lines +45 to +46
let definitions: Vec<String> = file_data.defs.keys().cloned().collect();
ResponseJson(serde_json::json!({
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix type mismatch when collecting definition names.

file_data.defs.keys().cloned().collect() now yields Arc<str> items, but the target type is Vec<String>. This no longer compiles since String doesn’t implement From<Arc<str>>. Convert each key explicitly (e.g. map(|k| k.to_string())) before collecting.

-      let definitions: Vec<String> = file_data.defs.keys().cloned().collect();
+      let definitions: Vec<String> = file_data
+        .defs
+        .keys()
+        .map(|k| k.to_string())
+        .collect();
🤖 Prompt for AI Agents
In src/mcp/read_handlers.rs around lines 45-46, collecting definition names uses
file_data.defs.keys().cloned().collect() which now yields Arc<str> items and
doesn't match the target Vec<String>; change the collection to convert each key
to a String (e.g. map over keys and call to_string() or to_owned() before
collect) so the resulting type is Vec<String>.

⚠️ Potential issue | 🔴 Critical

Apply the same fix when returning dependency namespaces.

This branch has the identical Vec<String> collection pattern and will hit the same compile-time error; apply the same to_string conversion there.

-      let definitions: Vec<String> = file_data.defs.keys().cloned().collect();
+      let definitions: Vec<String> = file_data
+        .defs
+        .keys()
+        .map(|k| k.to_string())
+        .collect();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let definitions: Vec<String> = file_data.defs.keys().cloned().collect();
ResponseJson(serde_json::json!({
let definitions: Vec<String> = file_data
.defs
.keys()
.map(|k| k.to_string())
.collect();
ResponseJson(serde_json::json!({
🤖 Prompt for AI Agents
In src/mcp/read_handlers.rs around lines 45-46, the code collects map keys into
a Vec<String> using keys().cloned().collect(), which fails when keys are &str or
non-String; apply the same fix used elsewhere by mapping each key to an owned
String before collecting (e.g., replace keys().cloned() with keys().map(|k|
k.to_string())) so the dependency namespaces are returned as Vec<String> without
compile errors.

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: 2

🧹 Nitpick comments (1)
src/bin/cr.rs (1)

507-510: Consider restoring program data after running the examples

We overwrite PROGRAM_CODE_DATA with the synthetic &calcit:check-examples entry and leave it in place. Even though check-examples currently exits immediately, keeping the mutated program state around could surprise future flows if this utility ever runs before other tasks (e.g. watch mode). I'd snapshot and restore the original program data—even on early returns—to keep globals deterministic.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0968e50 and 6b43eae.

📒 Files selected for processing (7)
  • src/bin/cr.rs (9 hunks)
  • src/call_stack.rs (2 hunks)
  • src/cirru/calcit-core.cirru (10 hunks)
  • src/cli_args.rs (2 hunks)
  • src/detailed_snapshot.rs (1 hunks)
  • src/mcp/definition_handlers.rs (4 hunks)
  • src/snapshot.rs (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/cli_args.rs
  • src/call_stack.rs
  • src/detailed_snapshot.rs
🧰 Additional context used
🧬 Code graph analysis (1)
src/bin/cr.rs (3)
src/lib.rs (1)
  • run_program_with_docs (48-87)
src/call_stack.rs (2)
  • display_stack_with_docs (111-159)
  • len (69-71)
src/program.rs (1)
  • extract_program_data (140-149)
🔇 Additional comments (1)
src/cirru/calcit-core.cirru (1)

478-484: Docstring contradicts zero-arity behavior.

Implementation still allows (+) with no args returning 0, so the note “requires at least one argument” is misleading. Please align the wording with the actual behavior.

Comment on lines 472 to 475
ResponseJson(serde_json::json!({
"documentation": def_entry.doc,
"examples": def_entry.examples,
"source": "dependency",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Clone doc/examples before serializing dependency response.

def_entry is only borrowed here, so moving def_entry.doc / def_entry.examples into the JSON response fails to compile (“cannot move out of def_entry because it is borrowed”). Clone the fields before inserting them into json!.

-            "documentation": def_entry.doc,
-            "examples": def_entry.examples,
+            "documentation": def_entry.doc.clone(),
+            "examples": def_entry.examples.clone(),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ResponseJson(serde_json::json!({
"documentation": def_entry.doc,
"examples": def_entry.examples,
"source": "dependency",
ResponseJson(serde_json::json!({
"documentation": def_entry.doc.clone(),
"examples": def_entry.examples.clone(),
"source": "dependency",
🤖 Prompt for AI Agents
In src/mcp/definition_handlers.rs around lines 472 to 475, the code attempts to
move def_entry.doc and def_entry.examples into serde_json::json!, but def_entry
is only borrowed so this causes a move error; fix it by cloning those fields
before constructing the JSON (e.g., use def_entry.doc.clone() and
def_entry.examples.clone() or assign cloned values to locals and insert those
into the json! macro) so the borrow remains valid.

Comment on lines +346 to +347
let snapshot: Snapshot = load_snapshot_data(&edn_data, "calcit-core.cirru").expect("Failed to parse snapshot");

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix: use the actual file path when calling load_snapshot_data.

Line 346 currently passes only "calcit-core.cirru", so gen_meta_ns receives a path whose parent() is None and the call panics at runtime. This makes the new test fail every time. Pass the full "src/cirru/calcit-core.cirru" path (or otherwise ensure a parent directory exists) before landing this.

-    let snapshot: Snapshot = load_snapshot_data(&edn_data, "calcit-core.cirru").expect("Failed to parse snapshot");
+    let snapshot: Snapshot = load_snapshot_data(&edn_data, "src/cirru/calcit-core.cirru").expect("Failed to parse snapshot");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let snapshot: Snapshot = load_snapshot_data(&edn_data, "calcit-core.cirru").expect("Failed to parse snapshot");
let snapshot: Snapshot = load_snapshot_data(&edn_data, "src/cirru/calcit-core.cirru").expect("Failed to parse snapshot");
🤖 Prompt for AI Agents
In src/snapshot.rs around lines 346-347, the call to load_snapshot_data uses
only "calcit-core.cirru", causing gen_meta_ns to receive a path without a parent
and panic at runtime; change the argument to the full relative path
"src/cirru/calcit-core.cirru" (or otherwise pass a Path with an existing parent)
so load_snapshot_data receives a path whose parent() is Some, preventing the
panic and fixing the failing test.

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7923274 and 0487d75.

📒 Files selected for processing (3)
  • src/call_stack.rs (2 hunks)
  • src/program.rs (4 hunks)
  • src/snapshot.rs (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/call_stack.rs
🧰 Additional context used
🧬 Code graph analysis (1)
src/program.rs (2)
src/data/cirru.rs (4)
  • code_to_calcit (8-161)
  • s (90-90)
  • s (92-92)
  • xs (254-254)
src/snapshot.rs (6)
  • from (32-37)
  • from (71-73)
  • from (92-101)
  • from (105-114)
  • from (232-266)
  • from (270-273)
🔇 Additional comments (1)
src/snapshot.rs (1)

341-348: Pass the real path into load_snapshot_data.

gen_meta_ns calls Path::parent().expect(...). Providing only "calcit-core.cirru" yields None, so this test will always panic instead of verifying examples. Use the same "src/cirru/calcit-core.cirru" path you read from.

-    let snapshot: Snapshot = load_snapshot_data(&edn_data, "calcit-core.cirru").expect("Failed to parse snapshot");
+    let snapshot: Snapshot =
+      load_snapshot_data(&edn_data, "src/cirru/calcit-core.cirru").expect("Failed to parse snapshot");

Comment on lines +298 to 305
let calcit_code = code_to_calcit(code, ns, def, coord0.to_owned())?;
let entry = ProgramDefEntry {
code: calcit_code,
doc: Arc::from(""), // No doc info in changes, use empty string
examples: vec![], // No examples info in changes, use empty vector
};
file.defs.insert(def.to_owned().into(), entry);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Preserve docs/examples when updating changed defs.

info.changed_defs currently overwrites every entry with blank doc and examples, so hot reloads silently discard previously stored documentation and usage snippets. That breaks the doc-aware tooling added in this PR. Reuse the existing metadata when reinserting the updated code.

     for (def, code) in &info.changed_defs {
       let calcit_code = code_to_calcit(code, ns, def, coord0.to_owned())?;
-      let entry = ProgramDefEntry {
-        code: calcit_code,
-        doc: Arc::from(""), // No doc info in changes, use empty string
-        examples: vec![], // No examples info in changes, use empty vector
-      };
-      file.defs.insert(def.to_owned().into(), entry);
+      let (doc, examples) = match file.defs.get(def.as_str()) {
+        Some(existing) => (existing.doc.clone(), existing.examples.clone()),
+        None => (Arc::from(""), Vec::new()),
+      };
+      file
+        .defs
+        .insert(def.to_owned().into(), ProgramDefEntry { code: calcit_code, doc, examples });
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let calcit_code = code_to_calcit(code, ns, def, coord0.to_owned())?;
let entry = ProgramDefEntry {
code: calcit_code,
doc: Arc::from(""), // No doc info in changes, use empty string
examples: vec![], // No examples info in changes, use empty vector
};
file.defs.insert(def.to_owned().into(), entry);
}
for (def, code) in &info.changed_defs {
let calcit_code = code_to_calcit(code, ns, def, coord0.to_owned())?;
let (doc, examples) = match file.defs.get(def.as_str()) {
Some(existing) => (existing.doc.clone(), existing.examples.clone()),
None => (Arc::from(""), Vec::new()),
};
file.defs.insert(
def.to_owned().into(),
ProgramDefEntry { code: calcit_code, doc, examples },
);
}
🤖 Prompt for AI Agents
In src/program.rs around lines 298-305, the code always reinserts updated defs
with blank doc and examples, discarding existing metadata; compute the map key
first (e.g. let key = def.to_owned().into()), lookup existing entry with
file.defs.get(&key) and reuse its doc and examples when constructing the new
ProgramDefEntry (clone or Arc::clone the existing doc and clone the examples),
falling back to Arc::from("") and vec![] only if no prior entry exists, then
insert using the same key.

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