Repository navigation
feat(mermaid): flow diagram thể hiện logic + call graph thay vì chuỗi thẳng - #41
Merged
Merged
Conversation
… thẳng `control_flow` trước đây chỉ nối tuần tự mọi node trong chain (`windows(2)`), nên diagram của một hàm không cho biết nhánh if/else, vòng lặp, switch, và call đi đâu — dù `FlowResult.calls` đã có đủ dữ liệu. Thay bằng cách render dùng cả `flow.calls`: - điều kiện (IF_TRUE/IF_FALSE/SWITCH_CASE) → hình thoi, label kèm guard text; - LOOP/LOOP_BACK/RETURN/THROW/... → stadium; - call → hộp chữ nhật có tên callee, `· L<line>`, `· if <condition>`, effect; - call không resolve (ngoài repo) → hộp subroutine + `· ext`; - cạnh suy từ marker: else rẽ từ if, LOOP_BACK vẽ back edge về header, SWITCH_CASE toả từ entry, BRANCH_END hợp nhất nhánh. Cập nhật mô tả tool MCP `codegraph_mermaid` và doc MermaidKind (GraphQL). Thêm 6 unit test cho control_flow.
|
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 |
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (97.98%) 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 #41 +/- ##
==========================================
+ Coverage 77.66% 78.00% +0.33%
==========================================
Files 94 94
Lines 22115 22348 +233
==========================================
+ Hits 17176 17432 +256
+ Misses 4939 4916 -23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
hungpham10
added a commit
that referenced
this pull request
Oct 8, 2026
… thẳng (#41) `control_flow` trước đây chỉ nối tuần tự mọi node trong chain (`windows(2)`), nên diagram của một hàm không cho biết nhánh if/else, vòng lặp, switch, và call đi đâu — dù `FlowResult.calls` đã có đủ dữ liệu. Thay bằng cách render dùng cả `flow.calls`: - điều kiện (IF_TRUE/IF_FALSE/SWITCH_CASE) → hình thoi, label kèm guard text; - LOOP/LOOP_BACK/RETURN/THROW/... → stadium; - call → hộp chữ nhật có tên callee, `· L<line>`, `· if <condition>`, effect; - call không resolve (ngoài repo) → hộp subroutine + `· ext`; - cạnh suy từ marker: else rẽ từ if, LOOP_BACK vẽ back edge về header, SWITCH_CASE toả từ entry, BRANCH_END hợp nhất nhánh. Cập nhật mô tả tool MCP `codegraph_mermaid` và doc MermaidKind (GraphQL). Thêm 6 unit test cho control_flow. Co-authored-by: Hung Pham <hungpham@MacBook-Pro-cua-Hung.local>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vấn đề
Task yêu cầu: tạo Mermaid cho một hàm cụ thể để biết logic hàm làm gì và call đi đâu.
codegraph_mermaid(MCP) /mermaid(GraphQL) đã cókind: FLOW, nhưngcontrol_flowchỉ:flow.chainbằngnodes.windows(2), nên nhánhif/else,switch, vòng lặp đều bị vẽ thành một đường thẳng;FlowResult.calls— không hiện line, condition, effect, callee;· ext).Trong khi đó
flow.callsđã có sẵn mọi thứ cần thiết (position,to_name,to_id,line,condition,effect).Tái hiện (hàm
mermaidtạiquery.rs:167)Trước — chuỗi thẳng, mất hết nhánh và call-site info:
Thay đổi
crates/codegraph-api/src/mermaid.rs— viết lạicontrol_flowdùng cảflow.calls:IF_TRUE/IF_FALSE/SWITCH_CASE) → hình thoi, label kèm guard text lấy từ call record trong nhánh (IF_TRUE: !state.mermaid).LOOP,LOOP_BACK,RETURN,THROW, …) → stadium.tên_callee · L<line> · if <condition> · <effect>.[[...]]+· ext.IF_FALSE(else) rẽ từ chính node điều kiệnif;BRANCH_ENDhợp nhất nhánh (kể cả nhánh false khi không có else);LOOP_BACKvẽ back edge về header loop;SWITCH_CASEtoả từ node entry của switch;Sau:
Ngoài ra cập nhật doc/mô tả:
crates/codegraph-mcp/src/tools.rs: mô tả toolcodegraph_mermaidnêu rõ FLOW thể hiện nhánh + call-site.crates/codegraph-graphql/src/types.rs: docMermaidKindmô tảFLOW/CALLERS/CALLEES/IMPACT.GraphQL
Không đổi schema, chỉ cải thiện nội dung trả về của field sẵn có:
{ mermaid(id: "156", kind: FLOW) } # logic + call đi đâu { mermaid(id: "156", kind: CALLEES, depth: 2) } # hàm gọi ai (graph LR) { mermaid(id: "156", kind: CALLERS, depth: 2) } # ai gọi hàm { mermaid(id: "156", kind: IMPACT, depth: 2) } # bán kính ảnh hưởngServer cần chạy
serve --graphql --mermaid. MCP tương ứngserve --mcp --mermaidvàcodegraph_mermaid {node, kind, depth}.Kiểm thử
control_flow: if/else không nối tuyến tính, loop back edge, switch fan-out, label call (line/condition/effect/ext), guard của điều kiện, root không có cạnh vào.cargo test -p codegraph-api(10 integration + 6 unit) — pass.cargo clippy -p codegraph-api -p codegraph-graphql -p codegraph-mcp --all-targets -- -D warnings— sạch.--mermaidtrên chính repo này (hàmmermaidid 156).