✨ feat(vscode): 代码阅读卡片横排多个概念图标

This commit is contained in:
cruldra committed 2026-10-03 03:11:47 +08:00
1 parent 11fcbef225
commit 394cd2fc1c
19 files changed
+328 -99

No files matched your search

+43 -1
View File
@@ -1,5 +1,5 @@
import type { BlockView } from './blockView'
import type { LanguageAdapter, Translator } from './contract'
import type { LanguageAdapter, LibraryRule, Translator } from './contract'
import { describe, expect, it } from 'vitest'
import { readBlockViews, readDefinitionKind, toBlockViews } from './blockView'
import { replaceLines } from './editText'
@@ -333,6 +333,48 @@ describe('blockView', () => {
})
})
it('概念列表:语言的种类在前,语言另认的接着,规则的种类和另认的在后;同一个 id 只留第一个', async () => {
const language: LanguageAdapter = {
...py,
concepts: block => block.kind === 'class'
? [
{ id: 'class', label: '重复的类', icon: 'zap' },
{ id: 'python.abstract', label: '抽象', icon: 'braces' },
]
: [],
}
const rule: LibraryRule = {
id: 'demo',
label: '演示',
languageIds: ['python'],
libraries: [],
claim: block => block.kind === 'class'
? {
kind: 'demo.thing',
badge: { label: '东西', color: { dark: '#111111', light: '#222222' }, icon: 'package' },
rows: [],
absorbs: [],
concepts: [
{ id: 'class', label: '又一个类', icon: 'lock' },
{ id: 'demo.thing', label: '重复的东西', icon: 'tag', color: { dark: '#333333', light: '#444444' } },
{ id: 'demo.extra', label: '额外', icon: 'lock', color: { dark: '#555555', light: '#666666' } },
],
}
: undefined,
}
const source = 'class Box:\n pass\n'
const [view] = await withBlocks(language, 'python', source, blocks =>
toBlockViews(blocks, { source, language, markers: [] }, pythonZhTranslator, { rules: [rule], report: () => {} }))
expect(view?.concepts).toEqual([
{ id: 'class', label: '类', icon: 'box' },
{ id: 'python.abstract', label: '抽象', icon: 'braces' },
{ id: 'demo.thing', label: '东西', icon: 'package', color: { dark: '#111111', light: '#222222' } },
{ id: 'demo.extra', label: '额外', icon: 'lock', color: { dark: '#555555', light: '#666666' } },
])
expect(view?.kind).toBe('demo.thing')
expect(view?.attributes.kind).toBe('demo.thing')
})
it('readDefinitionKind:offset 落在哪块自己的名字上就是那块的种类,里层的块优先;不在名字上没有', async () => {
const source = 'class UserService:\n def update_user(self):\n pass\n\nclass NotFound(Exception):\n pass\n\nlimit = 3\n'
const kind = (text: string): Promise<string | undefined> => readDefinitionKind(runtime, py, 'python', source, source.indexOf(text))