✨ feat(vscode): 代码阅读预览里工作区外的库文件也能问 AI,问答记进第一个工作区文件夹,重写注释不对库文件开放
This commit is contained in:
1 parent
cecae0e244
commit
39dfd9b084
24 files changed
+463
-79
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import type { Uri } from 'vscode'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { pathQaLocation, topQaLocation } from './pathPreview'
|
||||
|
||||
const places = vi.hoisted(() => {
|
||||
const folder = { uri: { scheme: 'file', path: '/ws/app', fsPath: '/ws/app', toString: () => 'file:///ws/app' }, name: 'app', index: 0 }
|
||||
/** ⌘ 点进去的标准库源码,不在工作区里 */
|
||||
const library = { scheme: 'file', query: '', path: '/Users/me/.local/lib/python3.12/pathlib.py', fsPath: '/Users/me/.local/lib/python3.12/pathlib.py' }
|
||||
/** locateQa 给它的位置:第一个工作区文件夹,键是 ~/… */
|
||||
const outside = { folder, key: '~/.local/lib/python3.12/pathlib.py', promptPath: library.fsPath, outsideDir: '/Users/me/.local/lib/python3.12' }
|
||||
return { folder, library, outside }
|
||||
})
|
||||
|
||||
vi.mock('vscode', () => ({
|
||||
Uri: {},
|
||||
workspace: {
|
||||
workspaceFolders: [places.folder],
|
||||
getWorkspaceFolder: (uri: { path: string }) => uri.path === '/ws/app' || uri.path.startsWith('/ws/app/') ? places.folder : undefined,
|
||||
},
|
||||
}))
|
||||
vi.mock('../folderStore', () => ({ locateQa: (uri: { path: string }) => uri.path === places.library.path ? places.outside : undefined }))
|
||||
|
||||
describe('顶部问答记在哪', () => {
|
||||
it('工作区外的库文件也能在顶部问:和块下面的问答同一个定位(第一个工作区文件夹 + ~/… 键)', () => {
|
||||
const library = places.library as unknown as Uri
|
||||
expect(pathQaLocation(library)).toEqual(places.outside)
|
||||
expect(topQaLocation(library)).toEqual({ folder: places.folder, key: 'file:///ws/app\n~/.local/lib/python3.12/pathlib.py' })
|
||||
})
|
||||
|
||||
it('工作区根本身也能问:键是空字符串,发给模型也是空的(写成 .)', () => {
|
||||
const root = { scheme: 'file', query: '', path: '/ws/app', fsPath: '/ws/app' } as unknown as Uri
|
||||
expect(pathQaLocation(root)).toEqual({ folder: places.folder, key: '', promptPath: '' })
|
||||
expect(topQaLocation(root)).toEqual({ folder: places.folder, key: 'file:///ws/app\n' })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user