feat: 优化上下文项显示和识别逻辑
- 支持显示所有类型的上下文项(文件和代码片段) - 增强路径识别,支持代码片段格式(文件名:行号-行号)
This commit is contained in:
@ -432,15 +432,14 @@ export function getInputAreaScript(): string {
|
|||||||
// 获取上下文项
|
// 获取上下文项
|
||||||
const contextItems = window.getContextItems ? window.getContextItems() : [];
|
const contextItems = window.getContextItems ? window.getContextItems() : [];
|
||||||
|
|
||||||
// 构建显示消息:如果有上下文文件,添加文件路径前缀
|
// 构建显示消息:如果有上下文项,添加路径前缀
|
||||||
let displayText = text;
|
let displayText = text;
|
||||||
if (contextItems.length > 0) {
|
if (contextItems.length > 0) {
|
||||||
const filePaths = contextItems
|
const contextPaths = contextItems
|
||||||
.filter(item => item.type === 'file')
|
|
||||||
.map(item => item.displayPath || item.path)
|
.map(item => item.displayPath || item.path)
|
||||||
.join(' ');
|
.join(' ');
|
||||||
if (filePaths) {
|
if (contextPaths) {
|
||||||
displayText = filePaths + ' ' + text;
|
displayText = contextPaths + ' ' + text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -863,8 +863,8 @@ export function getMessageAreaScript(): string {
|
|||||||
const textParts = [];
|
const textParts = [];
|
||||||
|
|
||||||
parts.forEach(part => {
|
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);
|
filePaths.push(part);
|
||||||
} else {
|
} else {
|
||||||
textParts.push(part);
|
textParts.push(part);
|
||||||
|
|||||||
Reference in New Issue
Block a user