✨ feat(vscode): 有说明的函数、类卡片也能重写注释

重写按钮不再只挂在单独的注释卡片上。只替换说明那几行,上下文用这块代码,不当成文件顶上的说明。
This commit is contained in:
cruldra committed 2026-10-03 03:22:20 +08:00
1 parent b608f6cb87
commit a66e4410e7
5 files changed
+46 -7

No files matched your search

+11
View File
@@ -4,6 +4,7 @@ import type { TreeSitterRuntime } from './runtime'
import { blockAttributes } from './attributes'
import { KIND_ICONS } from './contract'
import { commonIndent, splitLines } from './editText'
import { commentSpan } from './languages/shared'
import { activeRules, claimBlock, importsIn } from './libraryRules'
import { BlockAnchors } from './qa/anchor'
@@ -35,6 +36,9 @@ interface BlockViewBase {
* 同一个 id 只留第一个。webview 按这个画图标,不自己用种类查。
*/
concepts: BlockConcept[]
/** 能重写的那段注释的起止行,0 起。注释块是整块;函数、类等是它的说明。没有说明就没有,不显示重写按钮。 */
commentStartLine?: number
commentEndLine?: number
/** 库规则的卡片才有:筛选栏里这个种类的名字,卡片边框的颜色(RuleCard.badge)。图标在 concepts 里。预览同类块一样默认收起它的子块。 */
badge?: KindBadge
/** 库规则放进父卡片里的子块才有(见 RuleSlot):画在父卡片属性表第 row 行下面,不排在父卡片的子块里。 */
@@ -330,6 +334,11 @@ export function toBlockViews(
}
return concepts
}
function commentLines(block: CodeBlock): { commentStartLine: number, commentEndLine: number } | undefined {
const span = commentSpan(block)
return span && { commentStartLine: span.startLine, commentEndLine: span.endLine }
}
/** 块照它自己的样子(语言插件报的,或库规则认成的属性表块):编辑范围是 span,头部是块自己那部分,子块照常交给各规则看。scope 见 BlockAnchors.place */
function plain(block: CodeBlock, span: SourceSpan, id: string, scope: string): BlockView {
const name = ownName(block)
@@ -343,6 +352,7 @@ export function toBlockViews(
...(name && { defines: { startIndex: name.startIndex, endIndex: name.endIndex } }),
attributes: blockAttributes(block),
concepts: blockConcepts(block),
...commentLines(block),
children: [
...list(block.children, `${id}.`, inner),
...embeddedChildren(block, id, inner, block.children.length),
@@ -378,6 +388,7 @@ export function toBlockViews(
...(defines && { defines: { startIndex: defines.startIndex, endIndex: defines.endIndex } }),
attributes: { ...blockAttributes(block), ...attributes, kind },
concepts: blockConcepts(block, replacement),
...commentLines(block),
badge,
children: list(kept, `${id}.`, inner, 0, slots),
properties: rows,