✅ test(vscode): 补功能对话页按代码阅读块找符号的用例
This commit is contained in:
1 parent
cae4dcfa00
commit
d5c627c54a
1 file changed
+24
-5
@@ -7,6 +7,8 @@ import type { CodeColors } from '../theme/codeColors'
|
||||
import type { ExtensionToWebview, WebviewToExtension } from './messages'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { commands, Range, Uri, window, workspace } from 'vscode'
|
||||
import { createPythonAdapter } from '../languages/python'
|
||||
import { runtime, WASM_DIR } from '../testSupport'
|
||||
import { languageDefinitions } from './definitions'
|
||||
import { documentMessage } from './documentMessage'
|
||||
import { documentSymbolNodes } from './documentSymbols'
|
||||
@@ -217,7 +219,7 @@ function themeColors(colors: CodeColors) {
|
||||
}
|
||||
|
||||
/** 对比基准只认用「未提交的更改」文件行上的「打开更改」打开的:这样打开的对比上一次提交,别处打开的不比 */
|
||||
function opening(profiles = { ask: profileSet(''), rewrite: profileSet('') }, colors = themeColors(COLORS), languageFor: (languageId: string) => unknown = () => undefined) {
|
||||
function opening(profiles = { ask: profileSet(''), rewrite: profileSet('') }, colors = themeColors(COLORS), languageFor: (languageId: string) => unknown = () => undefined, runtime: unknown = {}) {
|
||||
const subscribe = () => ({ dispose: () => {} })
|
||||
const diffBase = vi.fn((_uri: unknown, from: OpenedFrom): DiffBase | undefined => from === 'uncommitted' ? HEAD_BASE : undefined)
|
||||
const qa = {
|
||||
@@ -231,7 +233,7 @@ function opening(profiles = { ask: profileSet(''), rewrite: profileSet('') }, co
|
||||
const provider = new PreviewEditorProvider(...[
|
||||
{},
|
||||
{ selectedTranslator: () => undefined, languageFor, onDidChange: subscribe },
|
||||
{},
|
||||
runtime,
|
||||
{ subscribe, current: { excluded: {}, onlyChanges: false } },
|
||||
colors,
|
||||
async () => [],
|
||||
@@ -733,11 +735,12 @@ describe('「了解一块代码」对话页上的仓库链接按这个功能找
|
||||
const WEB = { name: 'web', fsPath: '/ws/web' }
|
||||
const SERVER = { name: 'server', fsPath: '/srv/app' }
|
||||
|
||||
async function featurePage(folders: { name: string, fsPath: string }[]) {
|
||||
/** 功能对话页,链接指到的文件都是 Python,内容是 `source`;`languageFor` 给的语言有代码阅读 */
|
||||
async function featurePage(folders: { name: string, fsPath: string }[], { source = '', languageFor }: { source?: string, languageFor?: (languageId: string) => unknown } = {}) {
|
||||
Object.assign(workspace, { workspaceFolders: folders.map(({ name, fsPath }) => ({ name, uri: { fsPath } })) })
|
||||
vi.mocked(commands.executeCommand).mockClear()
|
||||
vi.mocked(workspace.openTextDocument).mockImplementation((async (uri: { fsPath: string }) => ({ uri, languageId: 'python', lineCount: 20, lineAt: () => ({ text: '' }), positionAt: (offset: number) => ({ line: 0, character: offset }) })) as never)
|
||||
const { provider, document } = opening()
|
||||
vi.mocked(workspace.openTextDocument).mockImplementation((async (uri: { fsPath: string }) => ({ uri, languageId: 'python', lineCount: 20, lineAt: () => ({ text: '' }), getText: () => source, positionAt: (offset: number) => ({ line: 0, character: offset }) })) as never)
|
||||
const { provider, document } = opening(undefined, undefined, languageFor, runtime)
|
||||
Object.assign(document, { uri: FEATURE_PAGE, fileName: FEATURE_PAGE.fsPath, languageId: 'plaintext', getText: () => '' })
|
||||
const page = tab()
|
||||
await provider.resolveCustomTextEditor(document as never, page.panel)
|
||||
@@ -783,6 +786,22 @@ describe('「了解一块代码」对话页上的仓库链接按这个功能找
|
||||
}
|
||||
})
|
||||
|
||||
it('链接指到有代码阅读的语言:按代码阅读解析出的块找符号,语言扩展还没起来、文档符号还是空的时候照样点得开', async () => {
|
||||
try {
|
||||
const python = createPythonAdapter(WASM_DIR)
|
||||
const source = ['class Router:', ' async def create(self):', ' pass', ''].join('\n')
|
||||
const page = await featurePage([WEB, SERVER], { source, languageFor: languageId => languageId === 'python' ? python : undefined })
|
||||
vi.mocked(documentSymbolNodes).mockClear()
|
||||
await page.send({ type: 'openRepoLink', path: 'server/app/routes.py', symbol: 'Router.create' })
|
||||
expect(page.posted()).toEqual([{ type: 'repoLinkOpened', path: 'server/app/routes.py', symbol: 'Router.create' }])
|
||||
expect(commands.executeCommand).toHaveBeenCalledWith('vscode.openWith', expect.objectContaining({ fsPath: '/srv/app/app/routes.py' }), PREVIEW_VIEW_TYPE, expect.anything())
|
||||
expect(documentSymbolNodes).not.toHaveBeenCalled()
|
||||
}
|
||||
finally {
|
||||
reset()
|
||||
}
|
||||
})
|
||||
|
||||
it('点链接按同一个算法打开文件;带符号的点了、悬停都在那个文件的文档符号里找', async () => {
|
||||
try {
|
||||
const page = await featurePage([WEB, SERVER])
|
||||
|
||||
Reference in new issue
Block a user