✨ feat(vscode): 代码阅读的 FastAPI 接口多一个筛选属性「请求方法」(GET / POST …);库规则自己报的筛选属性由规则起名(LibraryRule.attributeNames)
This commit is contained in:
1 parent
ec34ace7cf
commit
b4e4879570
9 files changed
+107
-11
No files matched your search
@@ -4,6 +4,7 @@ import { describe, expect, it } from 'vitest'
|
||||
import { createPythonAdapter } from '../languages/python'
|
||||
import { createTypeScriptAdapter } from '../languages/typescript'
|
||||
import { CodeReaderRegistry } from '../registry'
|
||||
import { fastapiRule } from '../rules/fastapi'
|
||||
import { sqlalchemyRule } from '../rules/sqlalchemy'
|
||||
import { runtime, WASM_DIR } from '../testSupport'
|
||||
import { pythonZhTranslator } from '../translators/pythonZh'
|
||||
@@ -82,6 +83,41 @@ describe('预览的 document 消息', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('库规则自己的筛选属性:名字取规则给的(FastAPI 接口的「请求方法」),值照写;规则起名时抛错记下来、照写 id', async () => {
|
||||
const routes = [
|
||||
'from fastapi import APIRouter',
|
||||
'',
|
||||
'router = APIRouter(prefix="/users")',
|
||||
'',
|
||||
'@router.get("/{user_id}")',
|
||||
'def get_user(user_id: int):',
|
||||
' pass',
|
||||
'',
|
||||
'@router.put("/{user_id}")',
|
||||
'def update_user(user_id: int):',
|
||||
' pass',
|
||||
'',
|
||||
'@router.get("")',
|
||||
'def list_users():',
|
||||
' pass',
|
||||
'',
|
||||
].join('\n')
|
||||
const { message } = await documentMessage(doc('python', routes), registryWithPython(fastapiRule), runtime, ignore)
|
||||
expect(message.attributes.find(attribute => attribute.id === 'httpMethod')).toEqual({
|
||||
id: 'httpMethod',
|
||||
name: '请求方法',
|
||||
values: [{ id: 'GET', name: 'GET', count: 2 }, { id: 'PUT', name: 'PUT', count: 1 }],
|
||||
})
|
||||
|
||||
const reports: string[] = []
|
||||
const broken: LibraryRule = { ...fastapiRule, attributeNames: () => {
|
||||
throw new Error('词表坏了')
|
||||
} }
|
||||
const again = await documentMessage(doc('python', routes), registryWithPython(broken), runtime, text => reports.push(text))
|
||||
expect(again.message.attributes.find(attribute => attribute.id === 'httpMethod')?.name).toBe('httpMethod')
|
||||
expect(reports).toEqual(['库规则 fastapi 给筛选属性起名时出错,筛选栏照写 id:词表坏了'])
|
||||
})
|
||||
|
||||
it('库规则抛错:不算解析失败,交给 report 记下,这块照常显示', async () => {
|
||||
const broken: LibraryRule = {
|
||||
id: 'broken',
|
||||
|
||||
Reference in new issue
Block a user