⚡ perf(vscode): 代码阅读预览的文档消息里源码和着色只带一份:块不再各带一份连子块在内的整段源码和上色,编辑框按块的编辑范围从整份源码和着色里取,5126 行的消息 4.3MB → 1.9MB

This commit is contained in:
cruldra committed 2026-10-13 15:50:33 +11:00
1 parent 0371712176
commit 2e3602242e
43 files changed
+501 -239

No files matched your search

+5 -4
View File
@@ -2,7 +2,7 @@ import type { BlockView, RuleRun } from './blockView'
import type { CodeBlock, LibraryRule, RuleBlock, RuleLocation, RuleSlot, RuleWorkspace, Segment } from './contract'
import { describe, expect, it } from 'vitest'
import { fileAttributes } from './attributes'
import { toBlockViews } from './blockView'
import { blockCodes, toBlockViews } from './blockView'
import { replaceLines } from './editText'
import { createPythonAdapter } from './languages/python'
import { activeRules, fromLibrary, importsIn, resolveReference } from './libraryRules'
@@ -113,10 +113,10 @@ describe('库规则:认领', () => {
badge: { label: '卡片' },
startLine: 2,
endLine: 8,
code: 'class User(Base):\n __tablename__ = "users"\n # 基本信息\n name = mapped_column(String)\n\n def greet(self) -> str:\n return self.name',
attributes: { kind: 'orm.card', access: 'public' },
properties: [{ label: '名称' }],
})
expect(blockCodes(MODEL)(card)).toBe('class User(Base):\n __tablename__ = "users"\n # 基本信息\n name = mapped_column(String)\n\n def greet(self) -> str:\n return self.name')
expect(card.children.map(child => [child.id, child.kind, child.startLine])).toEqual([['1.0', 'function', 7]])
})
@@ -139,8 +139,9 @@ describe('库规则:认领', () => {
const [, card] = await views(source, [fields])
expect(card.children.map(child => [child.kind, child.startLine, child.endLine])).toEqual([['function', 5, 6]])
expect([card.startLine, card.endLine]).toEqual([2, 8])
expect(replaceLines(source, card.startLine, card.endLine, card.code)).toBe(source)
const edited = replaceLines(source, card.startLine, card.endLine, card.code.replace('greet', 'hello').replace('String', 'Text'))
const code = blockCodes(source)(card)
expect(replaceLines(source, card.startLine, card.endLine, code)).toBe(source)
const edited = replaceLines(source, card.startLine, card.endLine, code.replace('greet', 'hello').replace('String', 'Text'))
expect(edited).toBe(source.replace('greet', 'hello').replace('String', 'Text'))
})