编程语言接入_add-lang
以下为本文档的中文说明Add Lang 是一个专门用于为 CodeGraph 代码分析系统添加新编程语言支持的端到端自动化工具。它的工作流程完整覆盖了从语法接入到质量验证的全过程首先将 tree-sitter 语法接入 CodeGraph 的提取管道然后编写相应的测试用例最后通过基准测试评估提取质量和检索价值。使用场景非常明确每当需要为 CodeGraph 增加新的语言支持时触发典型目标语言包括 Lua、Elixir、Zig、OCaml 等。用户可以通过运行 /add-lang 命令来启动整个过程。该技能的核心特点在于高度自动化和质量导向。整个流程完全自主运行自动选择测试仓库、运行基准测试、更新文档并生成报告但严格遵守不提交、不推送、不发布的原则所有变更留待用户审阅。设计原则强调数据驱动的验证必须证明新语言支持在提取真实符号方面优于不使用 CodeGraph 的基准线确保每次添加都有明确的价值提升。对于维护代码分析工具的团队来说这显著降低了语言扩展的技术门槛使非专业人员也能为系统添加新的语言支持。该技能的价值不仅体现在直接的功能实现上还在于它与现有技术生态系统的良好兼容性和集成能力。无论是作为独立工具使用还是嵌入到更大的工作流中它都能发Add a language to CodeGraphWire a new tree-sitter language into codegraph’s extraction pipeline, prove itextracts real symbols on popular repos, and prove it beats no-codegraph for anagent. Runsfully autonomously— pick repos, benchmark, update docs, thenreport.Never commit, push, publish, or tag(house rule); leave all changesfor the user to review.The argument is the language token used throughout theLanguageunion, e.g.lua,elixir,zig. If none was given, ask which language. Use the lowercasesingle-token form everywhere (csharp, notc#).PrerequisitesRun from the codegraph repo root.node,git,gh, and a logged-inclaudeCLI (the benchmark spawns realclaude -pruns).The benchmark uses the local dev build — Step 8 builds links it on PATH.WorkflowCopy this checklist and work through it in order:- [ ] 1. Resolve language; bail early if already supported (just benchmark) - [ ] 2. Find a grammar health-check it (ABI / heap corruption) - [ ] 3. Discover the grammars AST node types (dump-ast.mjs) - [ ] 4. Wire the language (4 files; sometimes a 5th core touch) - [ ] 5. Build verify-extraction loop until PASS - [ ] 6. Add extraction tests; make them green - [ ] 7. Auto-pick 3 popular repos by size tier; add to corpus.json - [ ] 8. Benchmark all 3: extraction with/without A/B - [ ] 9. Update README CHANGELOG - [ ] 10. Report; do NOT commitStep 1 — Resolve short-circuitCheck whether the language is already wired: look for the token in theLANGUAGESconst (src/types.ts) and theEXTRACTORSmap(src/extraction/languages/index.ts). If it is already supported (e.g.typescript,rust),skip Steps 2–6and go straight to benchmarking(Steps 7–8) to validate/measure it — note in the report that no code changed.Step 2 — Find a grammar, then health-check itlsnode_modules/tree-sitter-wasms/out/|grep-ilang# csharp - c_sharpPresent→ likely off-the-shelf;grammars.tsresolves it fromtree-sitter-wasmsautomatically. (Many languages: elixir, zig, ocaml,solidity, toml, yaml, …)Absent→ vendor a.wasmintosrc/extraction/wasm/(likepascal/scala/lua) and add the token to the vendored branch in Step 4.Always health-check before writing an extractor — apresentgrammar canstill be unusable:nodescripts/add-lang/check-grammar.mjslangpath/to/valid-sample.extIt prints the grammar’s ABI version and parses a valid sample many times in amulti-grammar runtime. If itFAILs(ERROR trees on valid code — an old ABIcorrupting the shared WASM heap, which silently drops nested calls/imports onevery file after the first; e.g. the tree-sitter-wasmsLuagrammar is ABI 13and fails), do NOT use that wasm.Vendor a newer (ABI 14/15) build instead:npmpack tree-sitter-grammars/tree-sitter-lang# often ships a prebuilt *.wasm# or build one: npx tree-sitter build --wasm (needs Docker/emscripten)cpthe.wasm src/extraction/wasm/tree-sitter-lang.wasmthen add the token to the vendored branch in Step 4 and re-run check-grammar onthe vendored path until it PASSes.If you cannot obtain a healthy wasm, STOPand tell the user.Step 3 — Discover AST node typesGet a representative source file (write a small sample covering functions,classes/structs, imports, enums; orcurla raw file from a known repo), then:nodescripts/add-lang/dump-ast.mjslangpath/to/sample.ext# vendored grammar: pass the wasm path instead of the tokennodescripts/add-lang/dump-ast.mjs src/extraction/wasm/tree-sitter-lang.wasm sample.extThe frequency table field names (name:,parameters:,body:,return_type:) tell you what to map. Open the existing extractor closest to thelanguage’s paradigm as a model:rust.ts/scala.ts(functional, traits),java.ts/csharp.ts(OO),python.ts/ruby.ts(scripting),go.ts(top-level methods receivers).Step 4 — Wire the language (4 files)These are exact, fragile wiring — match the existing style precisely:src/types.ts— TWO edits:addlang,to theLANGUAGESconst (beforeunknown);add**/*.ext,toDEFAULT_CONFIG.include.Don’t skip this— it’sthe file-scan allowlist; without the glob,codegraph initfinds0fileseven though detection/extraction are wired.src/extraction/grammars.ts— three maps:WASM_GRAMMAR_FILES:lang: tree-sitter-lang.wasm,EXTENSION_MAP: each file extension →lang(e.g..lua: lua,)getLanguageDisplayName:lang: Display Name,vendored only: addlangto the(lang pascal || lang scala || …)wasm-path branch.src/extraction/languages/lang.ts— new file exportingexport const langExtractor: LanguageExtractor { … }. Map the node typesfrom Step 3. Required fields:functionTypes,classTypes,methodTypes,interfaceTypes,structTypes,enumTypes,typeAliasTypes,importTypes,callTypes,variableTypes,nameField,bodyField,paramsField. Add hooks as the grammar needs them (getSignature,getVisibility,isExported,extractImport,visitNode,getReceiverType,interfaceKind,enumMemberTypes, etc. — seesrc/extraction/tree-sitter-types.ts).src/extraction/languages/index.ts—import { langExtractor } from ./lang;and addlang: langExtractor,toEXTRACTORS.Sometimes a 5th, core touch insrc/extraction/tree-sitter.ts— variableextraction has per-language branches inextractVariable(the generic fallbackonly finds directidentifier/variable_declaratorchildren). If the grammarnests declared names (e.g. Lua’svariable_declaration → variable_list), add a} else if (this.language lang)branch there, mirroring the existingts/python/go ones. Import forms that aren’t a distinct node (Lua/Rubyrequireis acall) are handled in the extractor’svisitNodehook instead.Step 5 — Build verify loopnpmrun build# tsc copy-assets (copies any vendored *.wasm into dist/)Index a small sample repo and check extraction:(cdsample-repocodegraph init-i)nodescripts/add-lang/verify-extraction.mjssample-repolangverify-extraction.mjsfails (exit 1) if the language isn’t detected or onlyfile/importnodes were produced — the classic symptom of wrong node-typenames. On FAIL or a thin WARN: re-rundump-ast.mjson a richer file, fix themappings inlang.ts,npm run build, re-index, re-verify.Repeat untilPASS.Step 6 — TestsAdd to__tests__/extraction.test.ts, modeled on theRust Extractionblock:adetectLanguageassertion indescribe(Language Detection)adescribe(Lang Extraction)block asserting functions/classes/importsare extracted from an inline source string.npx vitest run __tests__/extraction.test.tsGreen before continuing.Step 7 — Auto-pick 3 repos corpusPickwithout asking. Find candidates, then curate 3 that are genuinelylang-dominant, one per size tier:gh search repos--languagelang--sortstars--limit40\\--jsonfullName,stargazerCount,descriptionTiers (matchcorpus.json):Small~150 files ·Medium~150–1500 ·Large~1500. Skip repos that are taggedlangbut mostly anotherlanguage. Write one cross-file architecturequestionper repo (the kind thatneeds tracing across files). Add aLanguageblock to.claude/skills/agent-eval/corpus.json(fields:name,repo,size,files,question) so/agent-evalcan reuse them.Step 8 — Benchmark all 3 (extraction A/B)Make the dev build the codegraph on PATHonce, then loop:npmrun build./scripts/local-install.sh scripts/add-lang/bench.shlangnameurlquestionheadless# ×3bench.shclones (shared/tmp/codegraph-corpus), wipes indexes, runsverify-extraction.mjs, then the with/without retrieval A/B viascripts/agent-eval/run-all.sh(skips the paid A/B if extraction is broken).Read eachparse-run.mjssummary printed byrun-all.sh: tool calls, fileReads, Grep/Bash, codegraph-tool calls, duration, andcost— for both thewithandwithoutarms. After the loop, restore the dev link if needed:./scripts/local-install.sh.Step 9 — Docs CHANGELOGREADME.md: addLangto the “19 Languages” feature bullet, and add arow to theSupported Languagestable:| Lang | \\.ext\| Full support (classes, methods, …) |.CHANGELOG.md: add an## [Unreleased]section at the top (above thelatest version) with### Added→ a user-perspective bullet, e.g.“CodeGraph now indexes (.ext) — functions, classes, imports, andcall edges.”If## [Unreleased]already exists, append under it. (It’sfolded into the next versioned block at release time.)Step 10 — Report (do NOT commit)Summarize for review:Files changed: the 4 wiring edits new extractor tests README CHANGELOG corpus.json ( any vendored.wasm).Extractionper repo: files / nodes / edges /verify-extractionresult.A/Bper repo:withvswithout(tool calls, file Reads, cost) and aone-line verdict — did codegraph reduce effort, and did both arms reach acorrect answer?Gaps / follow-ups(node types not yet mapped, resolution edges missing,framework routes, etc.).Hand the changes to the user.Do notrungit commit/pushor publish —releases go through the GitHub Actions Release workflow.NotesThe A/B spawns realpaidclaude -pruns (opus,--max-budget-usd),2 arms × 3 repos. The corpus dir/tmp/codegraph-corpusis shared with/agent-eval, so clones are reused across runs.Any new*.wasmmust live insrc/extraction/wasm/—copy-assets(run bynpm run build) ships it; otherwise it won’t be indist/.An index must be served by thesamebinary that built it. Step 8 builds links the dev build first, so this holds.If a grammar can’t be obtained, or extraction can’t reach PASS,STOP andreport— don’t ship a half-wired language.

相关新闻

5分钟彻底解决C盘爆红问题:Windows Cleaner系统清理完全指南

5分钟彻底解决C盘爆红问题:Windows Cleaner系统清理完全指南

5分钟彻底解决C盘爆红问题:Windows Cleaner系统清理完全指南 【免费下载链接】WindowsCleaner Windows Cleaner——专治C盘爆红及各种不服! 项目地址: https://gitcode.com/gh_mirrors/wi/WindowsCleaner 你是否经常被C盘爆红警告困扰&#xff1f…

2026/9/26 21:12:05 阅读更多 →
非洲草原动物识别数据集与YOLOv5模型实践

非洲草原动物识别数据集与YOLOv5模型实践

1. 项目背景与核心价值这个非洲草原动物识别数据集和模型项目,解决了野生动物保护领域的一个关键痛点——高效准确的动物种群监测。传统的人工巡查方式不仅成本高昂,在广袤的非洲草原上实施也极为困难。我们团队历时18个月,采集了超过15万张高…

2026/9/24 17:52:17 阅读更多 →
AI智能体平台横评:五大平台对比 + 企业办公场景选型指南(含技术支持、客户服务、知识管理路径)

AI智能体平台横评:五大平台对比 + 企业办公场景选型指南(含技术支持、客户服务、知识管理路径)

这篇不写"大而全"的盘点,只回答一个问题:企业办公场景里的三大高频需求——技术支持、客户服务、知识管理,到底该用哪个智能体平台落地? 我按场景路径拆开对比,五家平台覆盖国外巨头到国产方案。本人因项目交…

2026/10/4 19:37:51 阅读更多 →

最新新闻

基于LSTM的五类动作识别源码包:从视频特征提取到可视化全流程

基于LSTM的五类动作识别源码包:从视频特征提取到可视化全流程

简介:这份资源面向深度学习入门者、课程设计与毕业设计学生,以及需要快速验证行为识别方案的技术人员,提供一套可直接运行的五类动作识别项目源码。项目覆盖jump、walk、pickup、salute、wave五种日常动作,并实现LSTM、TA-LSTM、S…

2026/10/13 1:59:18 阅读更多 →
Ventoy 多合一启动盘实战:一次部署,镜像即拷即用

Ventoy 多合一启动盘实战:一次部署,镜像即拷即用

简介:Ventoy 是一款开源的可启动 U 盘制作工具,面向系统运维、装机测试与多系统启动盘需求的技术人员。它解决的核心痛点是无需反复格式化磁盘,只需将 ISO/WIM/IMG/VHD(x)/EFI 等镜像文件复制到 U 盘即可启动,并支持一次放入多个镜…

2026/10/13 1:59:18 阅读更多 →
Win10下用VS2017与CMake编译OpenCV 4.5.1并集成contrib模块的完整指南

Win10下用VS2017与CMake编译OpenCV 4.5.1并集成contrib模块的完整指南

简介:一份专为Windows平台计算机视觉开发者准备的OpenCV 4.5.1contrib重新编译成果,基于win10、VS2017与CMake构建,解决在官方发行版中无法直接使用SIFT、SURF等contrib模块功能的痛点。包体为RAR压缩包,共992个文件、约47.65MB&a…

2026/10/13 1:59:18 阅读更多 →
STM32CubeIDE集成RT-Thread实战:从裸机到多任务调度

STM32CubeIDE集成RT-Thread实战:从裸机到多任务调度

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/13 1:59:18 阅读更多 →
Visual Studio 2010 Shell(Isolate):轻量级遗产系统调试环境搭建指南

Visual Studio 2010 Shell(Isolate):轻量级遗产系统调试环境搭建指南

简介:Microsoft Visual Studio 2010 Shell (Isolate) 是面向Windows平台C、C#、VB.NET等开发者的一套轻量级、可定制IDE运行环境,专为无需完整VS安装但需调试器、编辑器及扩展框架的场景设计,适用于旧系统维护、第三方工具集成或精简开发环境…

2026/10/13 1:59:18 阅读更多 →
JavaScript公式编辑器实战:从LaTeX渲染到存储回显全解析

JavaScript公式编辑器实战:从LaTeX渲染到存储回显全解析

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/13 1:58:18 阅读更多 →

日新闻

物联网系统集成避坑指南:从选型到验收的关键要点

物联网系统集成避坑指南:从选型到验收的关键要点

做了这么多年物联网系统集成的项目,我最大的感受是,大部分坑不是出在技术前沿,而是出在一些看起来很平常的地方。设备选了便宜的、协议没问清楚、现场没摸透、验收标准写得含糊——这些细枝末节,最后都会变成延期、超支和扯皮的大…

2026/10/13 0:00:57 阅读更多 →
ESP32舵机控制全攻略:从PWM原理到高级玩法与常见故障排查

ESP32舵机控制全攻略:从PWM原理到高级玩法与常见故障排查

如果你玩ESP32有一阵子了,很难不碰到舵机控制这道坎。做智能小车要转方向,做机械臂要抬关节,做云台要偏航俯仰,背后都是同一个东西在干活:舵机。而我见过太多人卡在“代码能编译、舵机就是不听话”这个阶段&#xff0c…

2026/10/13 0:00:57 阅读更多 →
CAN总线原理与STM32实战:抗干扰、仲裁、错误处理全解析

CAN总线原理与STM32实战:抗干扰、仲裁、错误处理全解析

1. 为什么CAN总线至今仍是工业现场的“硬通货”?——从汽车底盘到智能温室的真实需求你有没有拆过一辆老款燃油车的中控台?或者调试过某高校实验室里那台跑着Modbus协议却频频丢帧的PLC控制柜?又或者,在某个农业物联网项目里&…

2026/10/13 0:00:57 阅读更多 →

周新闻

流感时间序列预测实战:ARIMA/LSTM全流程拆解与避坑指南

流感时间序列预测实战:ARIMA/LSTM全流程拆解与避坑指南

简介:基于 ARIMA、LSTM、Transformer 等模型的流感时间序列预测 Python 源码,面向计算机相关专业课程设计与期末大作业学生,以及项目实战学习者。内容覆盖预处理、平稳性检验、定阶、残差分析、多模型对比预测的完整时序建模流程,…

2026/10/12 0:16:30 阅读更多 →
影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别

影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别

影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别 做影刀RPA自动化,十个新手有八个栽在"往输入框里填东西"这件事上:要么填不进去,要么填了一半,要么直接把原来内容追加在后面。这背后的根因&…

2026/10/12 0:16:38 阅读更多 →
影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容

影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容

影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容 1. 认识影刀:什么场景该用RPA采小说数据 起点中文网的页面结构相对稳定——分类榜单、书籍详情、章节内容三块独立页面,跳转链路清晰。这种场景非常适合影刀自动化&#x…

2026/10/13 1:58:08 阅读更多 →

月新闻

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/12 21:05:09 阅读更多 →
Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/12 14:48:49 阅读更多 →
黑夜航拍船只数据集训练YOLOV5模型全流程解析

黑夜航拍船只数据集训练YOLOV5模型全流程解析

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/12 18:11:17 阅读更多 →