✨ feat(vscode): 代码阅读加枚举卡片,Python enum 库规则和 TypeScript enum 画成同一张表
This commit is contained in:
1 parent
2251e67ef8
commit
de355661f0
24 files changed
+858
-83
No files matched your search
@@ -6,7 +6,7 @@ import { toBlockViews } from './blockView'
|
||||
import { replaceLines } from './editText'
|
||||
import { createPythonAdapter } from './languages/python'
|
||||
import { activeRules, fromLibrary, importsIn, resolveReference } from './libraryRules'
|
||||
import { WASM_DIR, withBlocks } from './testSupport'
|
||||
import { propertyLines, WASM_DIR, withBlocks } from './testSupport'
|
||||
import { pythonZhTranslator } from './translators/pythonZh'
|
||||
|
||||
const py = createPythonAdapter(WASM_DIR)
|
||||
@@ -177,6 +177,27 @@ describe('库规则:认领', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('认成契约里现成的属性表块:种类、属性表、筛选属性照语言插件报的这种块,编辑范围是整个类;并进来的不是子块时照常显示', async () => {
|
||||
const asEnum = (absorbs: (block: CodeBlock) => CodeBlock[]): LibraryRule => ({
|
||||
...cardRule('lib'),
|
||||
claim: block => block.kind === 'class' && block.facts.name
|
||||
? { as: { kind: 'enum', facts: { name: block.facts.name, access: block.facts.access, decorators: [], bases: [], members: [] } }, absorbs: absorbs(block) }
|
||||
: undefined,
|
||||
})
|
||||
const [, recognized] = await views(MODEL, [asEnum(block => block.children.slice(0, 1))])
|
||||
expect(recognized).toMatchObject({ kind: 'enum', startLine: 2, endLine: 8, attributes: { kind: 'enum', access: 'public' } })
|
||||
expect(recognized.badge).toBeUndefined()
|
||||
expect(propertyLines('properties' in recognized ? recognized.properties : [])).toEqual(['名称: User', '访问级别: 公共', '成员: 无'])
|
||||
expect(recognized.children.map(child => child.kind)).toEqual(['comment', 'variable', 'function'])
|
||||
|
||||
const reports: string[] = []
|
||||
const stranger: CodeBlock[] = []
|
||||
await withBlocks(py, 'python', 'x = 1', blocks => stranger.push(...blocks))
|
||||
const [, shown] = await views(MODEL, [asEnum(() => stranger)], reports)
|
||||
expect(shown.kind).toBe('class')
|
||||
expect(reports).toEqual(['库规则 lib 给第 3 行的 class 块的替身不合约定,这块照常显示:要并进来的块不是这块的子块'])
|
||||
})
|
||||
|
||||
it('筛选:规则的种类和别的种类一样计数,名字取规则给的标签', async () => {
|
||||
const list = await views(MODEL, [cardRule('orm')])
|
||||
expect(fileAttributes(list, pythonZhTranslator.attributeNames).find(attribute => attribute.id === 'kind')?.values).toEqual([
|
||||
|
||||
Reference in new issue
Block a user