✨ feat(vscode): 代码阅读函数块默认折叠,函数说明进属性表「说明」行

This commit is contained in:
cruldra committed 2026-09-25 13:09:53 +08:00
1 parent 62f48fe67c
commit 9b32d4b5a8
17 files changed
+489 -100

No files matched your search

@@ -1,6 +1,7 @@
import type { BlockKind, BlockView, PropertyRow, Segment } from './types'
import { describe, expect, it } from 'vitest'
import { revealPlan, scrollTopToShow } from './reveal'
import { collapsedIds } from './viewState'
function name(text: string, offset: number): Segment {
return { text, role: 'variable', offset }
@@ -63,6 +64,14 @@ describe('跳到定义:滚到哪块、展开哪些', () => {
expect(revealPlan(BLOCKS, 20, 999)).toEqual({ id: '2', expand: [] })
})
it('函数块默认折叠:目标在函数体里时,要展开的块里有这个函数;展开过一次就记住,不再挡着', () => {
const plan = revealPlan(BLOCKS, 4, 102)
const hidden = (folds: Record<string, boolean>): string[] => plan?.expand.filter(id => collapsedIds(BLOCKS, folds).has(id)) ?? []
expect(hidden({})).toEqual(['1'])
expect(hidden({ 1: false })).toEqual([])
expect(hidden({ '1': false, '1.0': true })).toEqual(['1.0'])
})
it('按行找:同一行有几块取外层那块;行在所有块之前取第一块;没有块时没有目标', () => {
const sameLine = [textBlock('0', 'if', 1, [word('如果')], [textBlock('0.0', 'return', 1, [word('返回')])])]
expect(revealPlan(sameLine, 1, 999)).toEqual({ id: '0', expand: [] })