feat: 优化上下文项显示和识别逻辑

- 支持显示所有类型的上下文项(文件和代码片段)
   - 增强路径识别,支持代码片段格式(文件名:行号-行号)
This commit is contained in:
Roe-xin
2026-03-06 15:40:59 +08:00
parent 45934baf0a
commit f24bd38ec7
2 changed files with 6 additions and 7 deletions

View File

@ -432,15 +432,14 @@ export function getInputAreaScript(): string {
// 获取上下文项
const contextItems = window.getContextItems ? window.getContextItems() : [];
// 构建显示消息:如果有上下文文件,添加文件路径前缀
// 构建显示消息:如果有上下文,添加路径前缀
let displayText = text;
if (contextItems.length > 0) {
const filePaths = contextItems
.filter(item => item.type === 'file')
const contextPaths = contextItems
.map(item => item.displayPath || item.path)
.join(' ');
if (filePaths) {
displayText = filePaths + ' ' + text;
if (contextPaths) {
displayText = contextPaths + ' ' + text;
}
}

View File

@ -863,8 +863,8 @@ export function getMessageAreaScript(): string {
const textParts = [];
parts.forEach(part => {
// 判断是否为文件路径:包含路径分隔符文件扩展名
if (part.includes('/') || part.includes('\\\\') || /\\.[a-zA-Z0-9]+$/.test(part)) {
// 判断是否为文件路径或代码片段:包含路径分隔符文件扩展名或代码片段格式(文件名:行号-行号)
if (part.includes('/') || part.includes('\\\\') || /\\.[a-zA-Z0-9]+$/.test(part) || /:[0-9]+-[0-9]+$/.test(part)) {
filePaths.push(part);
} else {
textParts.push(part);