✨ feat(vscode): 代码阅读的 FastAPI 接口多一个筛选属性「请求方法」(GET / POST …);库规则自己报的筛选属性由规则起名(LibraryRule.attributeNames)

This commit is contained in:
cruldra committed 2026-09-27 21:21:48 +08:00
1 parent ec34ace7cf
commit b4e4879570
9 files changed
+107 -11

No files matched your search

+8
View File
@@ -18,6 +18,9 @@ const ICON: KindIconName = 'globe'
/** 认路由对象、参数标记、HTTPException 时看从这几个库导入的名字(HTTPException、status 也可以从 starlette 来)。 */
const NAME_LIBRARIES = ['fastapi', 'starlette']
/** 接口的筛选属性:HTTP 方法,值是大写的 GET、POST……(名字由 attributeNames 给,值照写)。 */
const METHOD_ATTRIBUTE = 'httpMethod'
/** 路由对象上挂接口的方法:`router.get`、`app.post` …… */
const METHODS = new Set(['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'])
/** HTTP 方法的颜色:Swagger UI 的配色,看接口文档的人最熟;白底上照原色看不清,亮色主题取同色相深一些的。 */
@@ -77,6 +80,8 @@ interface Words {
messageSeparator: string
/** 依赖注进哪个参数:「(param)」 */
injectedInto: (param: string) => string
/** 筛选属性 httpMethod 叫什么(值 GET、POST……照写) */
methodAttribute: string
}
const ZH: Words = {
@@ -93,6 +98,7 @@ const ZH: Words = {
listSeparator: '、',
messageSeparator: ';',
injectedInto: param => `(${param})`,
methodAttribute: '请求方法',
}
/** 显示语言 → 用词;翻译插件的显示语言这里没有时用中文。 */
@@ -620,6 +626,7 @@ function routeCard(block: FunctionBlock, route: Route, env: Env): RuleCard {
badge: { label: words.kind, color: COLOR, icon: ICON },
rows,
...(facts.name && { defines: range(facts.name) }),
attributes: { [METHOD_ATTRIBUTE]: route.method },
absorbs: [],
}
}
@@ -641,4 +648,5 @@ export const fastapiRule: LibraryRule = {
}
return undefined
},
attributeNames: displayLanguage => ({ attributes: { [METHOD_ATTRIBUTE]: (WORDS[displayLanguage ?? ''] ?? ZH).methodAttribute }, values: {} }),
}