✨ feat(vscode): 接口卡片找前端调用时,网址最后一段字面量后面紧贴的 ${...}(messages${qs} 这类)当查询串去掉再对接口

This commit is contained in:
cruldra committed 2026-10-13 13:34:12 +11:00
1 parent 2c490cac2d
commit 7d5432df3b
2 files changed
+49 -5

No files matched your search

+15 -5
View File
@@ -31,7 +31,7 @@ type Method = string | typeof FROM_CALLER
* 不在有名字的函数里时,名字是被调用的 fetch / GET / 包装函数本身。
*/
export interface RequestEntry extends IndexEntry {
/** 写的路径:模板里指向字符串常量的 `${名字}` 换成常量的值,别的 `${...}` 照写,`?`、`#` 后面的去掉 */
/** 写的路径:模板里指向字符串常量的 `${名字}` 换成常量的值,别的 `${...}` 照写;`?`、`#` 后面的,和最后一段末尾紧贴字面量的 `${...}`(查询串)去掉 */
path: string
/** 发请求那个调用的范围,行和列从 0 起 */
at: CallRange
@@ -494,7 +494,8 @@ async function senders(find: IndexFind, resolve: ModuleResolver): Promise<{ call
}
/**
* 网址拼成路径(uri 是网址所在的文件):`${名字}` 取得到常量的值就拼进去,取不到的照写;`?`、`#` 后面的去掉,照写的 `${...}` 里的不算。
* 网址拼成路径(uri 是网址所在的文件):`${名字}` 取得到常量的值就拼进去,取不到的照写;`?`、`#` 后面的去掉,照写的 `${...}` 里的不算;
* 最后一段是字面量文字后面紧贴一个照写的 `${...}`(`messages${qs}`)时,它是拼上去的查询串,也去掉。
* 导入的常量和包装函数一样按 import 来源对到导出它的那处(见 exportOf),它的值里又导入的接着取;对不上、绕回正在取的(循环)取不到。
* 一份查询里同一个常量只取一次;取值时记着正在取的,所以要一处处拼,不能同时拼。
*/
@@ -534,18 +535,27 @@ function pathsOf(find: IndexFind, resolve: ModuleResolver): (uri: string, url: r
return async (uri, url) => {
let path = ''
// 上一个照写的 `${...}` 在 path 里的结尾;末尾照写的 `${...}` 当查询串去掉时从哪截
let written = 0
let query: number | undefined
for (const piece of url) {
const value = typeof piece === 'string' ? piece : await valueOf(uri, piece.constant)
if (value === undefined) {
const segment = path.lastIndexOf('/') + 1
query = segment >= written && segment < path.length ? path.length : undefined
path += typeof piece === 'string' ? piece : piece.written
written = path.length
continue
}
const end = value.search(/[?#]/)
const literal = end >= 0 ? value.slice(0, end) : value
path += literal
if (literal)
query = undefined
if (end >= 0)
return path + value.slice(0, end)
path += value
break
}
return path
return query === undefined ? path : path.slice(0, query)
}
}