🐛 fix(vscode): 写注释时改已有说明,不再在声明上面另插一行

This commit is contained in:
cruldra committed 2026-10-08 09:55:36 +08:00
1 parent 63dfb658e9
commit 7f39345d03
11 files changed
+196 -36

No files matched your search

+8
View File
@@ -14,6 +14,7 @@ export function createRustAdapter(wasmDir: string): LanguageAdapter {
toBlocks: root => attachComments(topBlocks(named(root), -1), aboutModule),
tokenRole: rustTokenRole,
lineComment: '//',
freshDoc,
}
}
@@ -35,6 +36,13 @@ const COMMENTS: CommentRules = {
documents: new Set(['function', 'class', 'trait', 'impl', 'module', 'enum', 'const', 'variable']),
}
/** 能带说明的项还没有说明时,在它紧上面插 `///`。 */
function freshDoc(block: CodeBlock): { line: number, shell: string } | undefined {
if (!(COMMENTS.documents as ReadonlySet<string>).has(block.kind))
return undefined
return { line: block.header.startRow, shell: '/// _' }
}
/** 讲所在模块或 crate 的内部文档注释(`//!`、`/*!`):写在文件开头是文件的说明,写在 `mod` 身体里交给那个模块。 */
function aboutModule(comment: CommentBlock): boolean {
return named(comment.node).some(child => child.type === 'inner_doc_comment_marker')