✨ feat(vscode): FastAPI 接口卡片的调用树带上前端调用它的地方

This commit is contained in:
cruldra committed 2026-10-12 12:22:51 +11:00
1 parent d4459e93b3
commit 29cedcb751
30 files changed
+1316 -130

No files matched your search

+13 -1
View File
@@ -8,6 +8,18 @@ export function bundledWasmDir(): string {
return path.join(__dirname, 'tree-sitter')
}
/** 没有语言插件、只给工作区索引解析的语言(接口契约 openapi.json):languageId → 语法包的文件名。 */
const INDEX_GRAMMARS: Record<string, string> = { json: 'tree-sitter-json.wasm' }
/**
* 工作区索引按 languageId 解析时,没有语言插件的语言用哪个语法包;不是这几种语言时没有。
* @param wasmDir 放语法包的目录
*/
export function indexGrammar(wasmDir: string, languageId: string): Pick<LanguageAdapter, 'grammarPath'> | undefined {
const file = INDEX_GRAMMARS[languageId]
return file === undefined ? undefined : { grammarPath: () => path.join(wasmDir, file) }
}
/** 源码下标的行列(行从 0 起,列按 UTF-16,同 web-tree-sitter 解析 JS 字符串时的算法)。 */
function pointAt(source: string, index: number): Point {
const lineStart = source.lastIndexOf('\n', index - 1) + 1
@@ -44,7 +56,7 @@ export class TreeSitterRuntime {
* 返回的语法树占着 wasm 内存,用完必须 `tree.delete()`。给了 ranges 就只解析源码里的这几段(嵌着的代码,见 EmbeddedCode),
* 节点的下标、行列照旧是整份源码的。
*/
async parse(adapter: LanguageAdapter, languageId: string, source: string, ranges?: readonly SourceRange[]): Promise<Tree> {
async parse(adapter: Pick<LanguageAdapter, 'grammarPath'>, languageId: string, source: string, ranges?: readonly SourceRange[]): Promise<Tree> {
const parser = await this.parserFor(adapter.grammarPath(languageId))
const tree = parser.parse(source, null, ranges ? { includedRanges: ranges.map(range => includedRange(source, range)) } : undefined)
if (!tree)