🐛 fix(vscode): Rust 连着写的行注释合成一块注释,和别的语言走同一套拆块
This commit is contained in:
1 parent
51da724e68
commit
2f610e9cb8
11 files changed
+233
-121
No files matched your search
@@ -133,14 +133,6 @@ function firstLeaf(node: Node): Node {
|
||||
return first ? firstLeaf(first) : node
|
||||
}
|
||||
|
||||
function commentsWithin(node: Node, span: SourceSpan): Node[] {
|
||||
if (node.endIndex <= span.startIndex || node.startIndex >= span.endIndex)
|
||||
return []
|
||||
if (node.type === 'comment')
|
||||
return [node]
|
||||
return node.children.flatMap(child => child ? commentsWithin(child, span) : [])
|
||||
}
|
||||
|
||||
/** 节点的源码去掉整个落在它里面的记号(中文名记号 `@Comment 当前用户` 不是说明文字)。 */
|
||||
function withoutMarkers(node: Node, markers: readonly SourceRange[]): string {
|
||||
let text = ''
|
||||
@@ -639,10 +631,11 @@ export function createZhTemplateTranslator(table: ZhTable): Translator {
|
||||
return table.commentText(node, withoutMarkers(node, markers))
|
||||
}
|
||||
|
||||
/** 注释块的原文:几条行注释连成的一块是从 block.node 起、开头落在头部里的各个兄弟节点。 */
|
||||
function translateComment(block: TextBlock, document: SourceDocument): Markdown {
|
||||
const { startIndex, endIndex } = block.header
|
||||
const root = block.node.tree.rootNode
|
||||
const nodes = block.node.type === 'comment' ? commentsWithin(root.descendantForIndex(startIndex, endIndex) ?? root, block.header) : [block.node]
|
||||
const nodes: Node[] = []
|
||||
for (let node: Node | null = block.node; node && node.startIndex < block.header.endIndex; node = node.nextSibling)
|
||||
nodes.push(node)
|
||||
return { markdown: docText(nodes.map(node => commentOf(node, document))) }
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user