✨ feat(vscode): 代码阅读把推导式换成按读的顺序重排的遍历小框
This commit is contained in:
1 parent
677fb7da1f
commit
6416cdf714
16 files changed
+641
-91
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import type { Segment } from './types'
|
||||
import type { Inline, Segment } from './types'
|
||||
|
||||
/** 取 segments 拼起来的文字里 [from, to) 这一段,每个字保留原来的词性。 */
|
||||
export function sliceSegments(segments: Segment[], from: number, to: number): Segment[] {
|
||||
@@ -37,3 +37,13 @@ export function recolor(tokens: Segment[], code: string, text: string): Segment[
|
||||
...sliceSegments(tokens, code.length - tail, code.length),
|
||||
]
|
||||
}
|
||||
|
||||
/** 着色的词拼成的文字(给折叠按钮的说明用);框写成框头加框里的文字。 */
|
||||
export function inlineText(pieces: Inline[]): string {
|
||||
return pieces.map(piece => 'role' in piece ? piece.text : `${piece.label} ${inlineText(piece.segments)}`).join('')
|
||||
}
|
||||
|
||||
/** 文字里有没有 offset 处的那个名字,框里的也算。 */
|
||||
export function showsOffset(pieces: Inline[], offset: number): boolean {
|
||||
return pieces.some(piece => 'role' in piece ? piece.offset === offset : showsOffset(piece.segments, offset))
|
||||
}
|
||||
Reference in new issue
Block a user