Repository navigation
fix: mermaid graph connectivity + method chain order + closure body attribution - #46
Conversation
…ttribution
1. structural_edges(): thêm rule cho marker→terminator/block-end (RETURN, BRANCH_END,
SWITCH_END) để khắc phục node orphan (nổi rời graph) khi thân nhánh if/loop/switch
chỉ chứa marker.
2. control_flow(): fix_call_edge_order() tính scope call theo stack CALL_ENTER/EXIT,
đảo cạnh cho đúng runtime:
- Nested call: con chạy trước cha (a.b().c() → c → b → a).
- Cross-region (closure body): neo vào call owner (unwrap_or_else) thay vì nối
tuần tự sau receiver (name_store.clone).
- Thoát vùng call sang marker điều khiển: neo vào call cha ngoài cùng.
3. common.rs tag_into_var(): gán into_var vào call NGOÀI CÙNG (produce giá trị)
thay vì call trong cùng — sửa biến gán method chain (self.x = storage.read().load_id()
→ gán cho load_id/map_err, không phải read).
4. mermaid.rs sanitize(): truncate 80 ký tự + '…' suffix; rút gọn label external call
lấy segment cuối (map_err thay vì full chain).
Test: all mermaid/graph/extract/mcp tests pass.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
node_style() shortened external-call labels to the last dot-segment, so the outer call of a chain (whose CallRecord name is the whole chain text) rendered as just "ok" instead of "open_from_config(root).await.ok". Node identity was right; only the label was misleading. Replace the segment-shortening with whitespace collapsing (newline + indent -> single space) so the full chain stays readable, and sanitize() still caps at 80 chars with '…' for extreme cases. Before: c6[["ok · L1100 · ext"]] After: c6[["codegraph_extract::BinaryGraph::open_from_config(root) .await .ok · L1100 · ext"]] Tests: 11 mermaid + 39 extract lib + 104 graph all pass.
2 vấn đề cốt lõi trong flowchart control-flow:
1. RETURN/THROW/BREAK/CONTINUE bị nối vào BRANCH_END/SWITCH_END
Rule marker->marker cũ cho phép moi edge, nen 'if c { return None; }'
ve thanh IF_TRUE -> RETURN -> BRANCH_END -> tail: trong nhu return xong
van chay tiep. Gio terminator KHONG con ra edge nao (no đói la dead-end
đúng nghia), va false-path duoc dieu huong QUA BRANCH_END
(cond -> BRANCH_END -> tail) de node merge khong bi orphan.
Tuong tu cho SWITCH_END: case 'A => return' neo SWITCH_END vao case
vua mo thay vi vao RETURN.
2. Method chain render nguoc thu tu thuc thi
Chain emit PRE-ORDER (call ngoai cung truoc, call trong sau) nen mermaid
ve 'bin_base -> ExtractConfig::load' va 'ok -> open_from_config'. Viết lai
control_flow(): dung cay frame tu cap CALL_ENTER/CALL_EXIT roi phat lai
POST-ORDER (con truoc, cha sau) qua execution_order(). Node + canh tuan tu
tu do da dung runtime ma khong can va canh sau nay.
Thay the fix_call_edge_order() (cach ve cu gay 6 orphan o
new_with_storage) bang cach sap lai node.
Ket qua (0 orphan / 0 unreachable, chi con dead-end la node cuoi):
binary_graph_for : RETURN khong con noi toi BRANCH_END
load -> bin_base, open_from_config -> ok
new_with_storage : x.clone -> make -> unwrap_or_else (closure body giua)
storage.clone -> Search::new -> ... -> Ok (Ok dung cuoi)
main : giu nguyen 0 orphan / 0 unreachable
rebuild : giu nguyen
Test: +4 test moi (15/15 mermaid pass), 104 graph, 39 extract lib.
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (98.33%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #46 +/- ##
==========================================
+ Coverage 78.10% 78.21% +0.11%
==========================================
Files 96 96
Lines 23299 23490 +191
==========================================
+ Hits 18197 18373 +176
- Misses 5102 5117 +15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Fix 3 issues in mermaid flow graph:
1. Graph connectivity
structural_edges() adds rule marker -> terminator/block-end (RETURN, BRANCH_END, SWITCH_END).
Result: binary_graph_for from 1 orphan + 2 unreachable -> 0 orphan / 0 unreachable.
2. Method chain order
fix_call_edge_order() tracks call stack (CALL_ENTER/EXIT) to reverse edges.
3. Closure body attribution
Cross-region edge (same parent call, different child regions):
4. Bonus: into_var + label improvements
All existing tests pass (11 mermaid + 44 extract + 104 graph + 8 mcp).