| 語言 | 副檔名 | 狀態 |
|---|---|---|
| TypeScript / JavaScript | .ts .tsx .js .jsx .mjs | Full support |
| ArkTS(HarmonyOS) | .ets | Full support(@Component/@ComponentV2、build() view tree、ohpm workspace) |
| Python | .py | Full support |
| Go | .go | Full support |
| Rust | .rs | Full support |
| Java | .java | Full support |
| C# | .cs | Full support |
| PHP | .php | Full support |
| Ruby | .rb | Full support |
| C / C++ | .c .h .cpp .hpp .cc | Full support |
| Objective-C | .m .mm .h | Partial(classes/protocols/methods/@property/#import/message sends) |
| Metal / CUDA | .metal / .cu .cuh | Full(走 C++ 路徑;CUDA 含 <<<grid, block>>> launch) |
| Swift | .swift | Full support |
| Kotlin | .kt .kts | Full support |
| Scala | .scala .sc | Full support(Scala 3 enums) |
| Dart | .dart | Full support |
| Svelte / Vue / Astro | .svelte / .vue / .astro | Full(script 抽取 + framework routes) |
| Liquid | .liquid | Full support |
| Pascal / Delphi | .pas .dpr .dpk .lpr | Full(含 DFM/FMX form) |
| Lua / Luau | .lua / .luau | Full(Luau 含 Roblox instance-path require) |
| R | .R .r | Full(S4/R5/R6 classes、library/require) |
| CFML | .cfc .cfm .cfs | Full(tag 與 bare-script 兩種) |
| COBOL | .cbl .cob .cpy | Full(PERFORM/GO TO、CALL 'literal'、COPY、DATA DIVISION) |
| Visual Basic .NET | .vb | Full(Declare P/Invoke、Handles/WithEvents、LINQ) |
| Erlang | .erl .hrl .escript … | Full(multi-clause grouping、-spec、gen_server link) |
| Solidity | .sol | Full(contracts/libraries/events/emit) |
| Terraform / OpenTofu | .tf .tfvars .tofu | Full(resources/modules、module calls、remote-state) |
| Nix | .nix | Full(import/callPackage、NixOS module options) |
影響與 blast-radius 查詢好壞取決於依賴圖,所以覆蓋率是量測的而非宣稱的。「Fair coverage」= 有至少一個已解析跨檔依賴者的符號來源檔佔比(在每個語言的真實基準 repo 上):
| 語言 | 基準 repo | 覆蓋率 |
|---|---|---|
| TypeScript / JavaScript | codegraph 自己 | 95.8% |
| Python | psf/requests | 100% |
| Go | gin-gonic/gin | 96.6% |
| Rust | BurntSushi/ripgrep | 86.7% |
| Java | google/gson | 93.3% |
| C# | jbogard/MediatR | 85.2% |
| PHP | guzzle/guzzle | 100% |
| Ruby | sidekiq/sidekiq | 100% |
| C / C++ | redis / leveldb | 92.2% / 94.8% |
| Swift | Alamofire | 95.3% |
| Kotlin | square/okhttp | 96.2% |
| Scala | gatling/gatling | 91.2% |
| Dart | flutter/packages | 92.4% |
| Lua / Luau | telescope.nvim / Fusion | 84.2% / 92.2% |
| Pascal / Delphi | PascalCoin | 77.4% |
殘餘永遠是「真正的靜態分析前緣」——runtime dynamic dispatch、reflection / DI container、framework convention entry points、vendored 第三方——不是靠偷改分母刷出來的。
CodeGraph 的語言支援策略是「自動偵測、無需設定」——根據副檔名自動決定用哪個 extractor,使用者不需要手動配置。
兩種解析引擎的分工:
# 步驟 1:查看支援的語言
codegraph --help | grep -A 5 "languages"
# Supported: TypeScript, JavaScript, Python, Go, Rust, Java,
# C#, PHP, Ruby, C, C++, Swift, Kotlin, Scala, Dart...
# 步驟 2:初始化一個 monorepo
cd my-monorepo
codegraph init
# 步驟 3:查看各語言的索引統計
codegraph status
# Nodes by Kind:
# function 2,706
# method 1,850
# class 206
# Languages detected:
# typescript 45%
# python 30%
# go 25%
關鍵觀察:CodeGraph 自動偵測專案中使用的語言,不需要手動設定。每個語言都用最適合的 extractor 解析。
| 症狀 | 原因 | 解法 |
|---|---|---|
| 某語言未被索引 | 副檔名不在支援清單 | 用 extensions 對映非標準副檔名 |
| 解析錯誤 | 語法不完整或有錯誤 | 修正語法錯誤後執行 codegraph sync |
| 覆蓋率低 | 大量 runtime dispatch 或 reflection | 這是靜態分析的限制,考慮用 include 補充 |
codegraph status 查看各語言的索引統計extensions 對映非標準副檔名前面的範例是乾淨 monorepo。這裡是務實的風險評估:一個 Swift + Objective-C 混合的 iOS app,你想知道「ObjC 的 Partial support 會讓圖譜漏掉什麼」,以及要不要用 extensions 對映補救非標準副檔名。
# ① 索引後先看語言分佈與覆蓋
codegraph status
# Languages detected:
# swift 62% objc 38%
# ② 量測 ObjC 的實際解析成果
codegraph query "@interface" --kind class --limit 20 # classes 有進圖
codegraph query "@property" --kind property --limit 20 # property 有進圖
codegraph query "message send" --kind calls --limit 20 # message send 是否成邊
# ③ 找出「斷流點」:ObjC caller 的 callers 是否通到 Swift
codegraph callers MyLegacyBridge
# ④ 非標準副檔名對映(如果專案用 .mm 以外的自訂副檔名)
cat > codegraph.json << 'EOF'
{ "extensions": { ".bridge": "objective-c" } }
EOF
codegraph index --force
為什麼走這條路徑:Partial support 不是「壞」,是「範圍明確」——classes/protocols/methods/@property/#import/message sends 有解析,但 ObjC 的動態 runtime 行為(IMP 替換、NSClassFromString)就沒有。先量測、再決定要不要靠橋接(Swift↔ObjC)補流,比憑直覺相信「有支援就是全支援」可靠。
內部架構:雙引擎的真實分工。「30+ 語言」與「20 語言」不是同一個 promise:Rust kernel 原生編譯 20 語言(tree-sitter grammar 編進 binary、逐位元組驗證);其餘語言與 per-file fallback 走可攜 TS 引擎(web-tree-sitter wasm)。兩者產出相同形狀的圖,但效能與驗證深度不同。特殊語言各有專屬處理:ArkTS 的 @Component view tree、Terraform 的 resources/modules、Nix 的 callPackage、Solidity 的 events/emit。
| 症狀 | 可能原因 | 解決方案 |
|---|---|---|
| 某語言完全沒被偵測 | 副檔名不在支援清單 | extensions 對映到受支援語言 id |
| Partial 語言的成員缺漏 | Partial support 的範圍限制 | 查支援清單確認該語言的欄位範圍,調整預期 |
| 覆蓋率 100% 但影響分析仍有缺口 | runtime dispatch / reflection 不在解析範圍 | 接受靜態分析前緣;用 include 或手動補節點 |
| 非標準副檔名被當成錯語言 | extensions 沒設或值打錯 | 檢查對映值 + codegraph index --force |
| 升級後語言統計跳變 | extraction-version 變了 | codegraph status 對照版本,必要時 re-index |
<<<grid, block>>> launch 語法如何被特判成 calls 邊?一個包含 TypeScript(前端)、Python(ML pipeline)、Go(API)、Rust(效能核心)的 monorepo,如何評估 CodeGraph 的語言支援深度:
# ① 初始化整個 monorepo(副檔名自動分派)
cd polyglot-monorepo
codegraph init
# ② 查看各語言的索引統計
codegraph status
# Languages detected:
# typescript 42% (Rust kernel)
# python 28% (Rust kernel)
# go 18% (Rust kernel)
# rust 12% (Rust kernel)
# ③ 量測各語言的覆蓋率
# TypeScript(Rust kernel,95.8%)
codegraph query "Controller" --kind class --limit 20 # 完整支援
# Python(Rust kernel,100%)
codegraph query "def " --kind function --limit 20 # 完整支援
# Go(Rust kernel,96.6%)
codegraph query "Handler" --kind interface --limit 20 # 完整支援
# ④ 找出「斷流點」:跨語言的呼叫路徑
codegraph explore "TypeScript 前端呼叫 Go API 的完整路徑"
# ⑤ 量化 refactor 的 blast radius(跨語言)
codegraph impact UserService --depth 3
# 影響範圍:TS 12 files + Python 3 files + Go 5 files
# ⑥ 用 extensions 對映非標準副檔名(如有)
cat > codegraph.json << 'EOF'
{
"extensions": {
".proto": "go",
".templ": "html"
}
}
EOF
codegraph index --force
關鍵觀察:四個主流語言全部走 Rust kernel(原生編譯效能),覆蓋率 95%+。殘餘是靜態分析的誠實前緣(reflection、DI container)。
| 面向 | 考量 | 實務建議 |
|---|---|---|
| 效能 | Rust kernel vs 可攜引擎的效能差異 | 20 個主流語言走 Rust(原生編譯),其餘走可攜 WASM 引擎。效能差異在大型 repo 上才明顯 |
| 品質 | coverage 100% ≠ 全部解析成功 | 定義是「有至少一個已解析跨檔依賴者的符號來源檔佔比」,不代表 dynamic dispatch 全被解析 |
| 安全 | tree-sitter grammar 的供應鏈安全 | grammar 編進 Rust binary,逐位元組驗證對齊參考引擎——不存在 runtime 下載 grammar 的風險 |
| 面向 | 本文(語言支援) | 相關文 | 差異說明 |
|---|---|---|---|
| 20 語言 | Rust kernel 原生編譯的語言清單 | 架構總覽 | 語言支援講哪些語言,架構總覽講 Rust kernel 的跨界策略 |
| coverage | Fair coverage 的定義與實測數字 | 效能基準 | 語言覆蓋率是「解析品質」,效能基準是「使用效率」 |
| extensions | 非標準副檔名對映 | 設定 | 語言支援講支援哪些語言,設定頁講怎麼對映 |
| 跨檔解析 | import resolver + name matcher | 運作原理 | 語言支援講解析深度,運作原理講 resolution 階段 |
codegraph status 查看各語言的索引統計與分佈
- [ ] 能解釋「Fair coverage」的定義:有至少一個已解析跨檔依賴者的符號來源檔佔比
- [ ] 能用 extensions 對映非標準副檔名到受支援語言
- [ ] 能解釋為什麼 coverage 100% 不代表「全部解析成功」
- [ ] 能評估 Objective-C Partial support 對混合專案的影響範圍