✨ 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,5 +1,5 @@
|
||||
/**
|
||||
* 顶部问答带给模型的材料:文件是路径加开头若干行,文件夹是路径加这一层的名字。
|
||||
* 顶部问答带给模型的材料:文件是路径加开头若干行,文件夹是路径加这一层的名字,还有它所在的 git 仓库根(回答里的链接从这里算路径)。
|
||||
* 路径见 [QaLocation.promptPath]:工作区里的是相对路径,工作区外的库文件是绝对路径。
|
||||
*/
|
||||
|
||||
@@ -8,13 +8,15 @@ import type { ExcludeSetting } from '../explorer/fileEntries'
|
||||
import type { QaLocation } from '../folderStore'
|
||||
import type { PathAskSubject, PathChild } from './pathAskPrompt'
|
||||
import { FileType, workspace } from 'vscode'
|
||||
import { repoRootOf } from '../editor/repoPath'
|
||||
import { createExcludeMatcher, sortEntries } from '../explorer/fileEntries'
|
||||
import { readFileHead } from './pathAskContext'
|
||||
import { displayRelativePath } from './pathQa'
|
||||
|
||||
export async function describePath(target: { uri: Uri, isDirectory: boolean, at: QaLocation }): Promise<PathAskSubject> {
|
||||
const { uri, isDirectory, at } = target
|
||||
const where = { path: displayRelativePath(at.promptPath), ...(at.outsideDir !== undefined && { outside: true as const }) }
|
||||
const repoRoot = await repoRootOf(uri.fsPath)
|
||||
const where = { path: displayRelativePath(at.promptPath), ...(at.outsideDir !== undefined && { outside: true as const }), ...(repoRoot !== undefined && { repoRoot }) }
|
||||
if (isDirectory)
|
||||
return { kind: 'folder', ...where, children: await folderChildren(uri, at.folder, at.key) }
|
||||
return { kind: 'file', ...where, head: await readFileHead(uri.fsPath) }
|
||||
|
||||
Reference in new issue
Block a user