⚡ perf(vscode): 语言插件按作用域规则认出名字的绑定,找别的文件起的中文名时同一个绑定只问一处、本文件定义的不问

This commit is contained in:
cruldra committed 2026-10-13 14:40:07 +11:00
1 parent 12ad047b4d
commit 0070933599
14 files changed
+1159 -36

No files matched your search

+15
View File
@@ -458,6 +458,16 @@ export interface LocalSymbol {
occurrences: SourceRange[]
}
/**
* 一份源码里一个名字的一个绑定(参数、变量、函数、类、导入的名字……),照这门语言的作用域规则认:各处出现(名字的范围,含定义处)
* 指的是同一个定义,内层同名的参数、推导式变量这类遮住外层的是另一个绑定。local 是这份源码自己定义的(参数、赋值、def、class……),
* 定义一定在这份源码里;导入的、哪儿都没定义的(内置的)不是。
*/
export interface NameBinding {
occurrences: SourceRange[]
local: boolean
}
export interface DeclaratorFacts {
/** 变量名;解构声明是整个模式。 */
name: Node
@@ -760,6 +770,11 @@ export interface LanguageAdapter {
command?: (node: Node) => CommandFacts | undefined
/** 一份源码里自己认得出的名字(见 LocalSymbol);VS Code 有这种语言的定义、高亮提供者时用不上,不填。 */
symbols?: (root: Node, source: string, languageId: string) => LocalSymbol[]
/**
* 一份源码里各个名字的绑定(见 NameBinding):宿主问语言扩展名字的定义时,同一个绑定只问一处,这份源码自己定义的不问。
* 只报认得准的:拿不准的(模式匹配捕获的、跳过不看的声明里的、同一个名字既导入又赋值的……)不报,宿主照旧逐处问。不填就逐处问。
*/
bindings?: (root: Node, source: string, languageId: string) => NameBinding[]
/** 这份源码里嵌着的别的语言的代码(见 EmbeddedCode),块里的(TextBlock.embedded)、属性表里的(HealthFacts.command)都算;没有的语言不填。 */
embedded?: (root: Node, source: string, languageId: string) => EmbeddedCode[]
/** 这门语言的代码被别的语言嵌着、当一串步骤执行时怎么分块(见 StepBlocks);不填就按 toBlocks 分、不算一步失败就停。 */