✨ feat(vscode): 代码阅读预览里跨几行写的列表按项拆开,列表里整项是调用的带着自己的实参表,一层层能往下套
This commit is contained in:
1 parent
7d6e7592c9
commit
2c490cac2d
22 files changed
+848
-314
No files matched your search
@@ -304,33 +304,66 @@ describe('python 属性表信息(facts)', () => {
|
||||
expect(found[10]).not.toHaveProperty('access')
|
||||
})
|
||||
|
||||
it('字典字面量的各项:字符串键、名字键、嵌套字典连它的各项、**展开;空字典是空数组,别的值没有;类属性也有', async () => {
|
||||
it('声明的值照源码给,字面量的各项不在 facts 里(见 LanguageAdapter.collection)', async () => {
|
||||
const found = await facts('EMPTY = {}\nITEMS = [1]\nclass K:\n labels = {"x": 1}')
|
||||
expect(found[1]).toEqual({ access: 'public', declarators: [{ name: 'EMPTY', value: '{}' }] })
|
||||
expect(found[2]).toEqual({ access: 'public', declarators: [{ name: 'ITEMS', value: '[1]' }] })
|
||||
expect(found[4]).toEqual({ access: 'public', declarators: [{ name: 'labels', value: '{"x": 1}' }] })
|
||||
})
|
||||
})
|
||||
|
||||
describe('python 字面量的各项', () => {
|
||||
const collections = (source: string): Promise<unknown[]> => nodeFacts(adapter, 'python', source, node => adapter.collection?.(node))
|
||||
|
||||
it('字典:字符串键、名字键、**展开,注释不算一项;值里的字典另有自己的各项,空字典没有项', async () => {
|
||||
const source = [
|
||||
'_KEYS = {',
|
||||
' "published": "contests:publish",',
|
||||
' key: 1,',
|
||||
' # 注释不算一项',
|
||||
' "nested": {"a": {}, "b": [1]},',
|
||||
' "nested": {"a": {}},',
|
||||
' **other,',
|
||||
'}',
|
||||
'EMPTY = {}',
|
||||
'ITEMS = [1]',
|
||||
'class K:',
|
||||
' labels = {"x": 1}',
|
||||
].join('\n')
|
||||
const found = await facts(source)
|
||||
expect(found[1]).toMatchObject({ access: 'private', declarators: [{ name: '_KEYS', entries: [
|
||||
{ kind: 'pair', key: '"published"', value: '"contests:publish"' },
|
||||
{ kind: 'pair', key: 'key', value: '1' },
|
||||
{ kind: 'pair', key: '"nested"', value: '{"a": {}, "b": [1]}', entries: [
|
||||
{ kind: 'pair', key: '"a"', value: '{}', entries: [] },
|
||||
{ kind: 'pair', key: '"b"', value: '[1]' },
|
||||
expect(await collections(source)).toEqual([
|
||||
{ kind: 'map', entries: [
|
||||
{ kind: 'pair', key: '"published"', value: '"contests:publish"' },
|
||||
{ kind: 'pair', key: 'key', value: '1' },
|
||||
{ kind: 'pair', key: '"nested"', value: '{"a": {}}' },
|
||||
{ kind: 'spread', value: 'other' },
|
||||
] },
|
||||
{ kind: 'spread', value: 'other' },
|
||||
] }] })
|
||||
expect(found[8]).toEqual({ access: 'public', declarators: [{ name: 'EMPTY', value: '{}', entries: [] }] })
|
||||
expect(found[9]).toEqual({ access: 'public', declarators: [{ name: 'ITEMS', value: '[1]' }] })
|
||||
expect(found[11]).toEqual({ access: 'public', declarators: [{ name: 'labels', value: '{"x": 1}', entries: [{ kind: 'pair', key: '"x"', value: '1' }] }] })
|
||||
{ kind: 'map', entries: [{ kind: 'pair', key: '"a"', value: '{}' }] },
|
||||
{ kind: 'map', entries: [] },
|
||||
])
|
||||
})
|
||||
|
||||
it('列表、元组、集合:各项照源码顺序,*x 是展开,注释不算一项;值里的字面量另有自己的各项,空列表没有项', async () => {
|
||||
const source = [
|
||||
'filters = [',
|
||||
' Filter(field="user_id"),',
|
||||
' # 注释不算一项',
|
||||
' *rest,',
|
||||
' (a, b),',
|
||||
' {1},',
|
||||
' [],',
|
||||
']',
|
||||
].join('\n')
|
||||
expect(await collections(source)).toEqual([
|
||||
{ kind: 'sequence', elements: [
|
||||
{ kind: 'item', value: 'Filter(field="user_id")' },
|
||||
{ kind: 'spread', value: 'rest' },
|
||||
{ kind: 'item', value: '(a, b)' },
|
||||
{ kind: 'item', value: '{1}' },
|
||||
{ kind: 'item', value: '[]' },
|
||||
] },
|
||||
{ kind: 'sequence', elements: [{ kind: 'item', value: 'a' }, { kind: 'item', value: 'b' }] },
|
||||
{ kind: 'sequence', elements: [{ kind: 'item', value: '1' }] },
|
||||
{ kind: 'sequence', elements: [] },
|
||||
])
|
||||
})
|
||||
|
||||
it('推导式、括号里的一个式子、调用的实参列表、别的值不是', async () => {
|
||||
expect(await collections('x = [a for a in b]\ny = (a)\nf(a, b)\nz = a, b')).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user