⚡ perf(vscode): 语言插件按作用域规则认出名字的绑定,找别的文件起的中文名时同一个绑定只问一处、本文件定义的不问
This commit is contained in:
1 parent
12ad047b4d
commit
0070933599
14 files changed
+1159
-36
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import type { NamedKind } from '../blockView'
|
||||
import type { DisplayName, LocalSymbol, RuleContext, SourceDocument } from '../contract'
|
||||
import type { DisplayName, LocalSymbol, NameBinding, RuleContext, SourceDocument } from '../contract'
|
||||
import type { CodeReaderRegistry } from '../registry'
|
||||
import type { TreeSitterRuntime } from '../runtime'
|
||||
import type { ImportedName } from '../symbolLinks'
|
||||
@@ -23,7 +23,8 @@ export interface DocumentSnapshot {
|
||||
|
||||
/**
|
||||
* 发给预览的文档,和这份源码里起了中文名的定义(扩展端接着找用到它们的各处)、语言插件自己认得出的名字(LocalSymbol)、
|
||||
* 各条导入引进来的名字(注释里不带路径的引用按它找导入的定义)、各块自己的名字和种类(调用的定义就在这份文档里时认种类用,见 NamedKind)。
|
||||
* 各条导入引进来的名字(注释里不带路径的引用按它找导入的定义)、各块自己的名字和种类(调用的定义就在这份文档里时认种类用,见 NamedKind)、
|
||||
* 各个名字的绑定(找中文名时同一个绑定问一处,见 NameBinding)。
|
||||
*/
|
||||
export interface DocumentRead {
|
||||
message: DocumentMessage
|
||||
@@ -31,6 +32,7 @@ export interface DocumentRead {
|
||||
symbols: LocalSymbol[]
|
||||
imports: ImportedName[]
|
||||
kinds: NamedKind[]
|
||||
bindings: NameBinding[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,10 +64,10 @@ export async function documentMessage(
|
||||
}
|
||||
const adapter = registry.languageFor(languageId)
|
||||
if (!adapter)
|
||||
return { message: { ...message, error: `代码阅读还不支持「${languageId}」这种语言` }, displayNames: [], symbols: [], imports: [], kinds: [] }
|
||||
return { message: { ...message, error: `代码阅读还不支持「${languageId}」这种语言` }, displayNames: [], symbols: [], imports: [], kinds: [], bindings: [] }
|
||||
try {
|
||||
const rules = registry.rulesFor(languageId)
|
||||
const { blocks, displayNames, symbols, imports, kinds } = await readBlockViews(runtime, adapter, translator, languageId, source, {
|
||||
const { blocks, displayNames, symbols, imports, kinds, bindings } = await readBlockViews(runtime, adapter, translator, languageId, source, {
|
||||
...(document.fileName && { fileName: document.fileName }),
|
||||
rules: { rules, report, lookup },
|
||||
calleeKind,
|
||||
@@ -80,9 +82,9 @@ export async function documentMessage(
|
||||
},
|
||||
})
|
||||
const names = mergeAttributeNames([translator?.attributeNames, ...ruleAttributeNames(rules, translator?.displayLanguage, report)])
|
||||
return { message: { ...message, blocks: markEntryBlocks(blocks, source, document.entryNames ?? []), attributes: fileAttributes(blocks, names) }, displayNames, symbols, imports, kinds }
|
||||
return { message: { ...message, blocks: markEntryBlocks(blocks, source, document.entryNames ?? []), attributes: fileAttributes(blocks, names) }, displayNames, symbols, imports, kinds, bindings }
|
||||
}
|
||||
catch (err) {
|
||||
return { message: { ...message, error: err instanceof Error ? err.message : String(err) }, displayNames: [], symbols: [], imports: [], kinds: [] }
|
||||
return { message: { ...message, error: err instanceof Error ? err.message : String(err) }, displayNames: [], symbols: [], imports: [], kinds: [], bindings: [] }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user