✨ feat(vscode): 函数体里 let 的初始值、返回值也出 sqlx 查询和 axum 路由卡片
Rust 库规则共用 valueCard:语句看整句、let 看初始值、返回块看返回的值;认领 let 时第一行「变量」是变量名,也是卡片的定义;sqlx 认 query / query_as / query_scalar 函数连着 .bind 的写法,query_scalar! 不再把 SQL 当返回类型
This commit is contained in:
1 parent
324df3d5bd
commit
95559b160b
4 files changed
+217
-29
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import type { FunctionBlock, Inline, KindBadge, LibraryRule, Node, PropertyItem, PropertyRow, RuleCard, RuleContext, ThemeColor } from '../contract'
|
||||
import { returnNote, throwsRows, writtenParamRows } from './docRows'
|
||||
import { returnValue } from './rustRows'
|
||||
import { returnValue, valueCard } from './rustRows'
|
||||
import { attributeName, docSummary, named, stringContent } from './rustTree'
|
||||
|
||||
/** 和 FastAPI 接口同一个蓝。 */
|
||||
@@ -9,7 +9,7 @@ const BADGE: KindBadge = { label: '接口', color: COLOR, icon: 'globe' }
|
||||
const METHODS = new Set(['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'])
|
||||
|
||||
/**
|
||||
* 处理函数上的 get / post 等路由属性,或 Router 上能看出来的 route。
|
||||
* 处理函数上的 get / post 等路由属性,或语句、变量的初始值、返回值里 Router 上能看出来的 route。
|
||||
* 请求表和 FastAPI 接口一样:方法、路径、路径参数,再加返回。
|
||||
* 文件里导入了 axum 才启用。
|
||||
*/
|
||||
@@ -23,11 +23,10 @@ export const axumRule: LibraryRule = {
|
||||
const route = attributeRoute(block)
|
||||
return route ? card(block, route, context) : undefined
|
||||
}
|
||||
if (block.kind === 'statement') {
|
||||
const [route] = routesOn(block.node).filter(item => !handled(block.node, item.handler))
|
||||
return route ? routerCard(block.node, route, context) : undefined
|
||||
}
|
||||
return undefined
|
||||
return valueCard(block, context, (value) => {
|
||||
const [route] = routesOn(value).filter(item => !handled(value, item.handler))
|
||||
return route ? routerCard(value, route, context) : undefined
|
||||
})
|
||||
},
|
||||
attributeNames: () => ({ attributes: {}, values: { kind: { 'axum.route': '接口' } } }),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user