✨ feat(vscode): 代码阅读预览问 AI 的回答里代码位置写成链接、点了能跳:提示词要求写 [名字](路径#符号) 或 [文件名:起-止](路径#L起-L止) 并给出仓库根,仓库链接认 #L 行号(注释里同一套),旧回答里整段是「路径:行」的行内代码也当链接,带行号的在预览里展开、闪包住那几行的块,不支持预览的用文本编辑器选中
This commit is contained in:
1 parent
ceeaad91a7
commit
e401e4aec3
22 files changed
+516
-90
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { headLines } from './pathAskContext'
|
||||
import { PATH_ASK_HEAD_LINES, pathAskPrompt } from './pathAskPrompt'
|
||||
import { PATH_ASK_HEAD_LINES, pathAskFollowUp, pathAskPrompt } from './pathAskPrompt'
|
||||
|
||||
const FILE = 'app/[[...section]]/page.tsx'
|
||||
const FOLDER = 'app/[[...section]]'
|
||||
@@ -57,6 +57,26 @@ describe('问路径时发给模型的话', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('问路径时回答里的代码位置', () => {
|
||||
it('在 git 仓库里:要求写成从仓库根算起的链接,带例子;接着问时再说一遍', () => {
|
||||
const subject = { kind: 'folder' as const, path: FOLDER, repoRoot: '/work/shop', children: [] }
|
||||
const prompt = pathAskPrompt(subject, '这里放什么')
|
||||
expect(prompt).toContain('提到代码位置时写成 Markdown 链接,点了能跳过去。路径从仓库根 /work/shop 算起,开头不带 / 或 ./:')
|
||||
expect(prompt).toContain('[文件名:起-止](路径#L起-L止)')
|
||||
expect(prompt).toContain('例如:[OrderService.cancel](backend/app/orders/service.py#OrderService.cancel)')
|
||||
expect(prompt).not.toContain('提到文件时写相对项目根目录的路径')
|
||||
const followUp = pathAskFollowUp(subject, '再说说')
|
||||
expect(followUp).toMatch(/^接着问(还是 app\/\[\[\.\.\.section\]\] 这个文件夹,需要时重新读):再说说\n\n提到代码位置时写成 Markdown 链接/)
|
||||
})
|
||||
|
||||
it('不在 git 仓库里(库源码):写行内代码的绝对路径,不写链接', () => {
|
||||
const library = '/Users/me/.local/share/uv/python/cpython-3.12/lib/python3.12/pathlib.py'
|
||||
const prompt = pathAskPrompt({ kind: 'file', path: library, outside: true, head: { lines: [], truncated: false } }, '?')
|
||||
expect(prompt).toContain('问的代码不在 git 仓库里,提到代码位置时写行内代码:绝对路径加行号')
|
||||
expect(prompt).not.toContain('Markdown 链接')
|
||||
})
|
||||
})
|
||||
|
||||
describe('文件开头截取', () => {
|
||||
it('超过行数上限时只留前 80 行,并标明没贴完', () => {
|
||||
const text = Array.from({ length: 100 }, (_, index) => `L${index}`).join('\n')
|
||||
|
||||
Reference in new issue
Block a user