✨ 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:
1 parent
335cf9ca9f
commit
582ac4c987
49 files changed
+1730
-757
No files matched your search
@@ -32,7 +32,7 @@ function view(id: string, kind: string, text: string, extra: Partial<BlockView>
|
||||
} as BlockView
|
||||
}
|
||||
|
||||
/** 一张卡片:第 1 行的两个子行各挂一张子卡片,后面还有一个留下的注释块。 */
|
||||
/** 一张卡片:第 1 行的两个子行各挂一张子卡片,后面还有一块留下的语句。 */
|
||||
const CARD: BlockView = {
|
||||
...view('0', 'demo.card', ''),
|
||||
badge: BADGE,
|
||||
@@ -46,13 +46,12 @@ const CARD: BlockView = {
|
||||
children: [
|
||||
view('0.0', 'demo.method', '启动服务', { slot: { row: 1, item: 0 }, badge: { ...BADGE, label: '方法', icon: 'square-function' } }),
|
||||
view('0.1', 'demo.method', '停止服务', { slot: { row: 1, item: 1 }, badge: { ...BADGE, label: '方法', icon: 'square-function' } }),
|
||||
view('0.2', 'comment', '留下的注释'),
|
||||
view('0.2', 'statement', '留下的语句'),
|
||||
],
|
||||
}
|
||||
|
||||
function render(folds: Record<string, boolean>): string {
|
||||
const collapsed = collapsedIds([CARD], folds)
|
||||
const tree: BlockTreeState = {
|
||||
function state(collapsed: ReadonlySet<string>): BlockTreeState {
|
||||
return {
|
||||
edit: {
|
||||
version: 1,
|
||||
editing: new Set(),
|
||||
@@ -72,7 +71,10 @@ function render(folds: Record<string, boolean>): string {
|
||||
onSetFolds: () => {},
|
||||
onOpenRun: () => {},
|
||||
}
|
||||
return renderToStaticMarkup(<BlockLevel blocks={[CARD]} tree={tree} />)
|
||||
}
|
||||
|
||||
function render(folds: Record<string, boolean>): string {
|
||||
return renderToStaticMarkup(<BlockLevel blocks={[CARD]} tree={state(collapsedIds([CARD], folds))} />)
|
||||
}
|
||||
|
||||
describe('挂在卡片子行上的子块', () => {
|
||||
@@ -80,7 +82,7 @@ describe('挂在卡片子行上的子块', () => {
|
||||
const html = render({})
|
||||
expect(html).not.toContain('启动服务')
|
||||
expect(html).not.toContain('停止服务')
|
||||
expect(html).not.toContain('留下的注释')
|
||||
expect(html).not.toContain('留下的语句')
|
||||
expect(html).toContain('<button type="button" class="cr-item-toggle" aria-expanded="false" aria-label="展开start">')
|
||||
})
|
||||
|
||||
@@ -90,7 +92,7 @@ describe('挂在卡片子行上的子块', () => {
|
||||
expect(html).not.toContain('停止服务')
|
||||
expect(html).toContain('data-open="" data-badge="" style="--kind-dark:#61dafb;--kind-light:#0a7ea4"')
|
||||
expect(html).toContain('aria-label="收起"')
|
||||
expect(html).toContain('留下的注释')
|
||||
expect(html).toContain('留下的语句')
|
||||
// 子卡片画在「方法」那一行后面
|
||||
expect(html.indexOf('启动服务')).toBeGreaterThan(html.indexOf('方法</button>'))
|
||||
})
|
||||
@@ -105,3 +107,33 @@ describe('挂在卡片子行上的子块', () => {
|
||||
expect(render({ '0.0': false, '0': false }).match(/data-owner="0"/g)).toHaveLength(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('「注释」一行和「重写注释」按钮', () => {
|
||||
const comment = { label: '注释', value: { markdown: '按名字找' } }
|
||||
const html = (block: BlockView): string => renderToStaticMarkup(<BlockLevel blocks={[block]} tree={state(new Set())} />)
|
||||
/** 「注释」那一行(cr-prop-row)里的 HTML */
|
||||
const commentRowHtml = (markup: string): string => markup.split('cr-prop-row').find(part => part.includes('按名字找')) ?? ''
|
||||
|
||||
it('属性表卡片:「注释」一行照属性表画,按钮画在这一行上,右上角那排不再有', () => {
|
||||
const card = view('1', 'function', '', {
|
||||
properties: [{ label: '名称', value: [{ text: 'find', role: 'function' }] }, comment, { label: '异步', value: [{ text: '否', role: 'storage' }] }],
|
||||
commentRow: 1,
|
||||
commentTarget: { kind: 'replace', startLine: 0, endLine: 0 },
|
||||
})
|
||||
const markup = html(card)
|
||||
expect(commentRowHtml(markup)).toContain('aria-label="按注释规范重写"')
|
||||
expect(markup.match(/aria-label="按注释规范重写"/g)).toHaveLength(1)
|
||||
expect(markup.indexOf('按名字找')).toBeLessThan(markup.indexOf('异步'))
|
||||
})
|
||||
|
||||
it('一行译文的卡片:「注释」一行排在译文下面,按钮同样在这一行上', () => {
|
||||
const markup = html(view('2', 'statement', 'save()', { rows: [comment], commentRow: 0, commentTarget: { kind: 'replace', startLine: 0, endLine: 0 } }))
|
||||
expect(markup.indexOf('save()')).toBeLessThan(markup.indexOf('按名字找'))
|
||||
expect(commentRowHtml(markup)).toContain('aria-label="按注释规范重写"')
|
||||
})
|
||||
|
||||
it('还没有注释的块:按钮在右上角那排,叫「按注释规范写注释」;不能写注释的块没有按钮', () => {
|
||||
expect(html(view('3', 'statement', 'save()', { commentTarget: { kind: 'insert', line: 0 } }))).toMatch(/role="group" aria-label="块操作"><button[^>]*aria-label="按注释规范写注释"/)
|
||||
expect(html(view('4', 'statement', 'save()'))).not.toContain('按注释规范')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user