✨ feat(vscode): 代码阅读预览里工作区外的库文件也能问 AI,问答记进第一个工作区文件夹,重写注释不对库文件开放

This commit is contained in:
cruldra committed 2026-10-13 21:50:54 +11:00
1 parent cecae0e244
commit 39dfd9b084
24 files changed
+463 -79

No files matched your search

+16 -13
View File
@@ -1,5 +1,5 @@
/**
* 侧栏问一个路径时发给模型的话:写明是文件还是文件夹、相对工作区的路径。
* 侧栏问一个路径时发给模型的话:写明是文件还是文件夹、相对工作区的路径(工作区外的库文件写绝对路径)。
* 文件附上开头若干行;文件夹只列这一层的名字,不把里面的代码贴进去。
*/
@@ -16,17 +16,19 @@ export type PathHead
= | { lines: string[], truncated: boolean }
| { unavailable: string }
export interface PathAskFile {
/** 问的这条路径在哪:工作区里的 [path] 是相对所在工作区文件夹的路径;[outside] 时在工作区外(比如库源码),[path] 是绝对路径 */
interface PathAskWhere {
path: string
outside?: true
}
export interface PathAskFile extends PathAskWhere {
kind: 'file'
/** 相对所在工作区文件夹的路径 */
relativePath: string
head: PathHead
}
export interface PathAskFolder {
export interface PathAskFolder extends PathAskWhere {
kind: 'folder'
/** 相对所在工作区文件夹的路径 */
relativePath: string
/** 这一层的子文件和子文件夹,调用方排好序;列不出来时是原因 */
children: PathChild[] | { unavailable: string }
}
@@ -37,17 +39,18 @@ const LEAD = '我在看项目里的一个路径,想问它。请用中文、大
/** 一次提问的全文。不写进某一块代码的问答记录。 */
export function pathAskPrompt(subject: PathAskSubject, question: string): string {
const where = subject.kind === 'file'
? `这是一个文件,相对路径:${subject.relativePath}`
: `这是一个文件夹,相对路径:${subject.relativePath}`
const noun = subject.kind === 'folder' ? '文件夹' : '文件'
const where = subject.outside
? `这是项目外的一个${noun}(比如依赖库的源码),绝对路径:${subject.path}`
: `这是一个${noun},相对路径:${subject.path}`
const detail = subject.kind === 'file' ? fileHead(subject.head) : folderList(subject.children)
return [LEAD, where, detail, `问题:${question}`].join('\n\n')
}
/** 这条路径已经问过、接着上一次会话问时发的话:只说还是这个文件或文件夹,材料在会话里。 */
export function pathAskFollowUp(relativePath: string, kind: 'file' | 'folder', question: string): string {
/** 这条路径已经问过、接着上一次会话问时发的话:只说还是这个文件或文件夹(`path` 同 [PathAskSubject] 的),材料在会话里。 */
export function pathAskFollowUp(path: string, kind: 'file' | 'folder', question: string): string {
const noun = kind === 'folder' ? '文件夹' : '文件'
return `接着问(还是 ${relativePath} 这个${noun},需要时重新读):${question}`
return `接着问(还是 ${path} 这个${noun},需要时重新读):${question}`
}
function fileHead(head: PathHead): string {