🐛 fix(vscode): 实参里的闭包、async 块写了查询或路由时不再外面那句、子块各出一张卡

valueCard 交给规则一个 own:拆成子块的那几段不归这一块,sqlx 找查询、axum 找路由时跳过;顺带去掉 rustRows 里 nameRow 没用的参数(页面那边的类型检查报它)
This commit is contained in:
cruldra committed 2026-10-15 21:06:58 +11:00
1 parent 1956879aa1
commit 6ad2a5b27a
4 files changed
+53 -20

No files matched your search

+7 -4
View File
@@ -23,8 +23,8 @@ export const axumRule: LibraryRule = {
const route = attributeRoute(block)
return route ? card(block, route, context) : undefined
}
return valueCard(block, context, (value) => {
const [route] = routesOn(value).filter(item => !handled(value, item.handler))
return valueCard(block, context, (value, own) => {
const [route] = routesOn(value, own).filter(item => !handled(value, item.handler))
return route ? routerCard(value, route, context) : undefined
})
},
@@ -116,7 +116,10 @@ function requestRow(route: Route, params: Inline[][]): PropertyRow {
}
}
function routesOn(node: Node, found: (Route & { handlerNode?: Node })[] = []): (Route & { handlerNode?: Node })[] {
/** 式子里写的各个 `.route(路径, 方法(函数))`,外层在前;拆成子块的那几段(`own` 为假)不看。 */
function routesOn(node: Node, own: (node: Node) => boolean, found: (Route & { handlerNode?: Node })[] = []): (Route & { handlerNode?: Node })[] {
if (!own(node))
return found
if (node.type === 'call_expression') {
const callee = node.childForFieldName('function')
const field = callee?.type === 'field_expression' ? callee.childForFieldName('field')?.text : undefined
@@ -137,7 +140,7 @@ function routesOn(node: Node, found: (Route & { handlerNode?: Node })[] = []): (
}
}
for (const child of named(node))
routesOn(child, found)
routesOn(child, own, found)
return found
}