✨ feat(vscode): 代码阅读的注释挂到它讲的代码块上成「注释」一行,重写注释改用技能一句话加结构化结果

- 普通注释不再单独成卡片:同一层挂到后面最近的块(隔空行也算),后面没有挂到前面那块,整层没代码挂到父块;只有文件开头隔着空行的注释、模块 docstring、//!、@file 单独成「文件开头的说明」
- 各语言(Python、TypeScript、Rust、Shell、Dockerfile)建好树后统一调 attachComments;块的编辑范围连着挂上的注释,差异、跳转、钉住卡片都按它
- 宿主统一给每张卡片(语言卡片、翻译插件的属性表、库规则卡片、一行译文的语句卡片)插「注释」一行,排在名称、说明后面
- TypeScript 的 JSDoc 也能当常量、变量的说明;sqlx、React 不再单独处理前面的注释
- 「重写注释」每块都有:提示只发 /ecc:writing-code-comments 路径:起-止,模型只读、按 --json-schema 交 body,没交结构化正文就失败不写;扩展换掉块前面的注释或在块上面新写一段
This commit is contained in:
cruldra committed 2026-10-08 07:51:21 +08:00
1 parent 335cf9ca9f
commit 582ac4c987
49 files changed
+1730 -757

No files matched your search

+4 -3
View File
@@ -2,7 +2,7 @@ import type { BlockShape, CodeBlock, CommandFacts, CommandWord, DeclaratorFacts,
import type { CommentRules, ListBlocks } from './shared'
import * as path from 'node:path'
import { bashNameReader } from './bashNames'
import { children, compoundShape, leafBlock, leafShape, listBlocks, named } from './shared'
import { attachComments, children, compoundShape, leafBlock, leafShape, listBlocks, named } from './shared'
/** 按习惯当常量用的名字:全大写(可带数字、下划线)。 */
const CONSTANT_NAME = /^[A-Z][A-Z0-9_]*$/
@@ -627,7 +627,7 @@ function bashSteps(root: Node): StepBlocks {
const [only, ...more] = items.filter(item => item.type !== 'comment')
if (only && more.length === 0 && andChain(only))
return { blocks: chainOperands(only).flatMap(stepBlocks), chained: true }
return { blocks: statements(items, -1, true), chained: false }
return { blocks: attachComments(statements(items, -1, true), undefined, false), chained: false }
}
/** bash / sh / zsh 脚本(VS Code 的 languageId 是 shellscript)的语言插件。@param wasmDir 语法包 .wasm 所在目录 */
@@ -636,9 +636,10 @@ export function createBashAdapter(wasmDir: string): LanguageAdapter {
id: 'bash',
languageIds: ['shellscript'],
grammarPath: () => path.join(wasmDir, 'tree-sitter-bash.wasm'),
toBlocks: root => programBlocks(root),
toBlocks: root => attachComments(programBlocks(root)),
steps: root => bashSteps(root),
tokenRole: bashTokenRole,
lineComment: '#',
command: bashCommand,
symbols: root => bashSymbols(root),
displayNames: bashNameReader,