⚡ perf(vscode): 代码阅读预览的文档消息里源码和着色只带一份:块不再各带一份连子块在内的整段源码和上色,编辑框按块的编辑范围从整份源码和着色里取,5126 行的消息 4.3MB → 1.9MB
This commit is contained in:
1 parent
0371712176
commit
2e3602242e
43 files changed
+501
-239
No files matched your search
@@ -57,6 +57,8 @@ export async function documentMessage(
|
||||
version,
|
||||
languageId,
|
||||
blocks: [],
|
||||
source: '',
|
||||
colors: { roles: [], runs: [] },
|
||||
attributes: [],
|
||||
translators: registry.translatorsFor(languageId).map(({ id, label }) => ({ id, label })),
|
||||
translatorId: translator?.id ?? '',
|
||||
@@ -67,7 +69,7 @@ export async function documentMessage(
|
||||
return { message: { ...message, error: `代码阅读还不支持「${languageId}」这种语言` }, displayNames: [], symbols: [], imports: [], kinds: [], bindings: [] }
|
||||
try {
|
||||
const rules = registry.rulesFor(languageId)
|
||||
const { blocks, displayNames, symbols, imports, kinds, bindings } = await readBlockViews(runtime, adapter, translator, languageId, source, {
|
||||
const { blocks, colors, displayNames, symbols, imports, kinds, bindings } = await readBlockViews(runtime, adapter, translator, languageId, source, {
|
||||
...(document.fileName && { fileName: document.fileName }),
|
||||
rules: { rules, report, lookup },
|
||||
calleeKind,
|
||||
@@ -82,7 +84,7 @@ 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, bindings }
|
||||
return { message: { ...message, blocks: markEntryBlocks(blocks, source, document.entryNames ?? []), source, colors, 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: [], bindings: [] }
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import type { ClaudeImage } from '../../cc/spawnClaude'
|
||||
import type { FileAttribute } from '../attributes'
|
||||
import type { BlockView } from '../blockView'
|
||||
import type { BlockView, SourceColors } from '../blockView'
|
||||
import type { ContractMiss } from '../callTree/endpoint'
|
||||
import type { CallTree } from '../callTree/model'
|
||||
import type { OpenedFrom } from '../diff/diffBase'
|
||||
@@ -65,6 +65,9 @@ export interface DocumentMessage {
|
||||
version: number
|
||||
languageId: string
|
||||
blocks: BlockView[]
|
||||
/** 整份源码和它的着色,只这一份:编辑框里一块的源码、着色按它的编辑范围取;解析失败、语言不支持时是空的(没有块) */
|
||||
source: string
|
||||
colors: SourceColors
|
||||
/** 这份文件里出现过的筛选属性和值(带显示名、块数),按筛选栏的先后排,见 fileAttributes */
|
||||
attributes: FileAttribute[]
|
||||
translators: TranslatorOption[]
|
||||
|
||||
@@ -530,7 +530,7 @@ describe('注释里不带路径的引用按它写在哪块的注释里找', () =
|
||||
|
||||
/** 一块有名字的代码:名字在源码里的下标是 at */
|
||||
function declared(anchor: string, at: number, children: BlockView[] = []): BlockView {
|
||||
return { id: anchor, anchor, kind: 'function', startLine: 0, endLine: 0, headerEndLine: 0, code: '', codeTokens: [], defines: { startIndex: at, endIndex: at + 1 }, attributes: { kind: 'function' }, concepts: [], children, translation: [] }
|
||||
return { id: anchor, anchor, kind: 'function', startLine: 0, endLine: 0, headerEndLine: 0, defines: { startIndex: at, endIndex: at + 1 }, attributes: { kind: 'function' }, concepts: [], children, translation: [] }
|
||||
}
|
||||
function symbol(name: string, start: number, end: number, children: SymbolNode[] = []): SymbolNode {
|
||||
return { name, range: { startIndex: start, endIndex: end }, selection: { startIndex: start, endIndex: start + name.length }, children }
|
||||
|
||||
@@ -402,6 +402,8 @@ class Preview {
|
||||
version: this.document.version,
|
||||
languageId: '',
|
||||
blocks: [],
|
||||
source: '',
|
||||
colors: { roles: [], runs: [] },
|
||||
attributes: [],
|
||||
translators: [],
|
||||
translatorId: '',
|
||||
|
||||
Reference in new issue
Block a user