✨ feat(vscode): 代码阅读的名字高亮更显眼(当前那处描框、别处画细线),⌘↓ / ⌘↑ 在各处之间跳,跳到折叠处自动展开,筛选栏写第几处

This commit is contained in:
cruldra committed 2026-09-26 23:47:43 +08:00
1 parent c5c5d2b517
commit 49f253b80f
18 files changed
+731 -53

No files matched your search

@@ -1,6 +1,6 @@
import type { LanguageAdapter, Translator } from '../../../src/codeReader/contract'
import type { RevealPlan } from './reveal'
import type { BlockKind, BlockView, Inline, PropertyItem, PropertyRow, Segment } from './types'
import type { BlockKind, BlockView, Inline, Occurrence, PropertyItem, PropertyRow, Segment } from './types'
import { describe, expect, it } from 'vitest'
import { toBlockViews } from '../../../src/codeReader/blockView'
import { createPythonAdapter } from '../../../src/codeReader/languages/python'
@@ -9,7 +9,7 @@ import { sqlalchemyRule } from '../../../src/codeReader/rules/sqlalchemy'
import { WASM_DIR, withBlocks } from '../../../src/codeReader/testSupport'
import { pythonZhTranslator } from '../../../src/codeReader/translators/pythonZh'
import { typescriptZhTranslator } from '../../../src/codeReader/translators/typescriptZh'
import { revealPlan, scrollTopToShow } from './reveal'
import { occurrencePlan, revealPlan, scrollTopToShow } from './reveal'
import { collapsedIds, propertyItemId, propertyRowId } from './viewState'
function name(text: string, offset: number): Segment {
@@ -52,6 +52,44 @@ const BLOCKS: BlockView[] = [
factBlock('2', 'const', 8, [{ label: '名称', value: [name('LIMIT', 130)] }]),
]
describe('用键盘跳到高亮的一处出现:滚到哪块、展开哪些', () => {
const nowhere = (): boolean => false
const at = (start: number, end: number): Occurrence => ({ start, end, kind: 'read' })
it('在嵌套块的译文里:目标是那块,展开它所有的祖先块', () => {
expect(occurrencePlan(BLOCKS, at(102, 108), nowhere)).toEqual({ id: '1.0.0', expand: ['1', '1.0'] })
})
it('在属性行展开的子行里(导入项、参数):连那一行一起展开;在属性行的值里不用展开', () => {
expect(occurrencePlan(BLOCKS, at(34, 40), nowhere)).toEqual({ id: '0', expand: ['0/p1'] })
expect(occurrencePlan(BLOCKS, at(51, 55), nowhere)).toEqual({ id: '1', expand: ['1/p2'] })
expect(occurrencePlan(BLOCKS, at(130, 135), nowhere)).toEqual({ id: '2', expand: [] })
})
it('和段重叠就算(点分模块名的一节、比名字长的段);页面上哪儿都没有时没有', () => {
expect(occurrencePlan(BLOCKS, at(18, 20), nowhere)).toEqual({ id: '0', expand: [] })
expect(occurrencePlan(BLOCKS, at(62, 70), nowhere)).toBeUndefined()
})
it('被筛掉的、正在编辑的、被盖住的块里的不算;只跳过那一块,它下面画出来的子块照常算', () => {
const hidden = new Set(['1.0', '1.0.0'])
expect(occurrencePlan(BLOCKS, at(102, 108), id => hidden.has(id))).toBeUndefined()
expect(occurrencePlan(BLOCKS, at(51, 55), id => id === '1')).toBeUndefined()
expect(occurrencePlan(BLOCKS, at(102, 108), id => id === '1')).toEqual({ id: '1.0.0', expand: ['1', '1.0'] })
})
it('同一处在页面上显示几次:取页面上的第一处;Markdown 里的不算', () => {
const blocks: BlockView[] = [
factBlock('0', 'function', 0, [{ label: '说明', value: { markdown: '见 `get_db`' } }], [
textBlock('0.0', 'return', 1, [word('返回'), name('get_db', 30)]),
]),
factBlock('1', 'class', 2, [{ label: '字段', value: [{ text: '1 个', role: 'hint' }], columns: ['字段'], items: [{ cells: [[name('get_db', 30)]] }] }]),
]
expect(occurrencePlan(blocks, at(30, 36), nowhere)).toEqual({ id: '0.0', expand: ['0'] })
expect(occurrencePlan(blocks, at(30, 36), id => id === '0.0')).toEqual({ id: '1', expand: ['1/p0'] })
})
})
describe('跳到定义:滚到哪块、展开哪些', () => {
it('名字在嵌套块的译文里:目标是那块,展开它所有的祖先块', () => {
expect(revealPlan(BLOCKS, 4, 102)).toEqual({ id: '1.0.0', expand: ['1', '1.0'] })