⚡ perf(vscode): 代码阅读预览发给页面的块只记相对位置:块在源码里占的地方记成离前一块多远、自己多长,块里名字的下标从块的开头算,页面从文件开头累加回文件里的位置、和扩展端打交道的地方都在一处换算;靠前改了代码,后面内容没变的块发过去一模一样,扩展端自己的块和发给页面的块分成两种类型

This commit is contained in:
cruldra committed 2026-10-13 16:32:18 +11:00
1 parent 3a2815c19c
commit ad5f559e92
43 files changed
+980 -424

No files matched your search

@@ -38,10 +38,10 @@ import { askPrompt, followUpPrompt } from '../qa/prompt'
import { DocumentLookups } from '../ruleLookups'
import { referenceScope, resolveReference } from '../symbolLinks'
import { definitionAction } from './definitionAction'
import { definitionSiteNames, namesOnCard, peekBlock } from './definitionPeek'
import { definitionSiteNames, namesOnCard, pagePeekBlock, peekBlock } from './definitionPeek'
import { definitionKind, findDefinitions, languageDefinitions, pickDefinition, ruleDefinitions } from './definitions'
import { DefinitionSources } from './definitionSources'
import { documentMessage } from './documentMessage'
import { documentMessage, pageDocument } from './documentMessage'
import { documentSymbolNodes } from './documentSymbols'
import { NavigationContext, OCCURRENCES_CONTEXT } from './occurrenceNavigation'
import { occurrencesOf } from './occurrences'
@@ -431,7 +431,7 @@ class Preview {
const reveal = this.pendingReveal
this.pendingReveal = undefined
this.shown = version
this.post({ ...message, names: this.names.known(version), ...(reveal && { reveal }) })
this.post({ ...pageDocument(message), names: this.names.known(version), ...(reveal && { reveal }) })
if (this.sent)
void this.diff.update(this.sent)
// 文档在解析期间又改了的,等下一次发文档再查
@@ -847,8 +847,10 @@ class Preview {
const path = workspace.asRelativePath(uri)
if (uri.toString() === this.document.uri.toString()) {
const { sent } = this
const block = sent?.version === target.version ? peekBlock(sent.blocks, offset, line) : undefined
return block && { path, line, block, names: namesOnCard(block, this.names.known(target.version)) }
if (sent?.version !== target.version)
return undefined
const block = peekBlock(sent.blocks, offset, line)
return block && { path, line, block: pagePeekBlock(block, sent.source), names: namesOnCard(block, this.names.known(target.version)) }
}
const { message, displayNames } = await documentMessage(
{ languageId: target.languageId, version: target.version, getText: () => target.getText(), fileName: target.fileName, entryNames: this.owner.entries.namesOf(uri) },
@@ -858,7 +860,7 @@ class Preview {
() => {},
)
const block = message.error === undefined ? peekBlock(message.blocks, offset, line) : undefined
return block && { path, line, block, names: namesOnCard(block, definitionSiteNames(displayNames)) }
return block && { path, line, block: pagePeekBlock(block, message.source), names: namesOnCard(block, definitionSiteNames(displayNames)) }
}
catch (err) {
logger.add({ level: 'warn', source: 'codeReader', message: `没能读出 ${uri.toString()} 里定义的那块:${err instanceof Error ? err.message : String(err)}` })