🐛 fix(vscode): 代码阅读预览跳到还没打开的文件时停在文件顶上不再发生:新开的预览注释里有仓库图片时,问图片才把仓库根加进 webview 能读的目录,改了选项 VS Code 重新加载页面,第二次 ready 发的文档不带要滚到的那处;页面能读的目录(页面资源、问答图片、这一页仓库链接的各个根及其真实位置)改在装页面之前一次定好,之后不再改选项,LinkBase 带上它算得出的根

This commit is contained in:
cruldra committed 2026-10-14 23:30:36 +11:00
1 parent 95fc539c3a
commit ad35898716
3 files changed
+66 -35

No files matched your search

@@ -76,7 +76,7 @@ vi.mock('./repoPath', async importOriginal => ({
repoRootOf: async () => '/workspace',
resolveRepoEntry: async (root: string, rel: string) => {
const fsPath = `${root}/${rel}`
const files = ['/workspace/web/a.ts', '/workspace/web/b.ts', '/workspace/docs/notes.txt', '/ws/web/src/app/(main)/page.tsx', '/srv/app/app/routes.py']
const files = ['/workspace/web/a.ts', '/workspace/web/b.ts', '/workspace/docs/notes.txt', '/workspace/docs/home.png', '/ws/web/src/app/(main)/page.tsx', '/srv/app/app/routes.py']
return files.includes(fsPath) ? { fsPath, isDirectory: false } : undefined
},
}))
@@ -377,6 +377,27 @@ describe('预览对比什么看这个标签页是从哪儿打开的', () => {
})
})
/** 页面眼下能读的本地目录 */
function readableRoots(page: ReturnType<typeof tab>): unknown[] {
return (page.panel.webview.options.localResourceRoots ?? []).map(root => root.fsPath)
}
describe('页面能读哪些本地目录', () => {
it('新开的预览装页面之前就放行仓库根:注释里的图片问到时不再改页面选项,打开时要滚到的那处还在', async () => {
const { provider, document } = opening()
const page = tab()
await provider.open(document.uri as never, { reveal: { line: 1 } }, async () => provider.resolveCustomTextEditor(document as never, page.panel))
expect(readableRoots(page)).toContain('/workspace')
const options = page.panel.webview.options
await page.send({ type: 'ready' })
await page.send({ type: 'checkRepoImages', id: 1, paths: ['docs/home.png'] })
expect(page.panel.webview.options).toBe(options)
expect(page.posted()).toContainEqual(expect.objectContaining({ type: 'document', reveal: { line: 1 } }))
expect(page.posted()).toContainEqual({ type: 'repoImagesChecked', id: 1, images: [{ path: 'docs/home.png', src: 'file:///workspace/docs/home.png' }] })
})
})
describe('标签页切走时页面留着', () => {
it('注册时就让页面在标签页切走后留着', () => {
const { provider } = opening()
@@ -719,7 +740,7 @@ describe('「了解一块代码」对话页上的仓库链接按这个功能找
const { provider, document } = opening()
Object.assign(document, { uri: FEATURE_PAGE, fileName: FEATURE_PAGE.fsPath, languageId: 'plaintext', getText: () => '' })
const page = tab()
provider.resolveCustomTextEditor(document as never, page.panel)
await provider.resolveCustomTextEditor(document as never, page.panel)
await page.send({ type: 'ready' })
page.clear()
return page
@@ -752,6 +773,16 @@ describe('「了解一块代码」对话页上的仓库链接按这个功能找
}
})
it('页面装好之前就放行这个功能找代码用的各个工作区文件夹', async () => {
try {
const page = await featurePage([WEB, SERVER])
expect(readableRoots(page)).toEqual(expect.arrayContaining(['/ws/web', '/srv/app']))
}
finally {
reset()
}
})
it('点链接按同一个算法打开文件;带符号的点了、悬停都在那个文件的文档符号里找', async () => {
try {
const page = await featurePage([WEB, SERVER])