-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add search file & content tool #4396
Conversation
Walkthrough本次变更主要更新了 MCP 服务器相关的接口与调用方式,对原有的 Changes
Sequence Diagram(s)sequenceDiagram
participant C as 客户端
participant S as MCPServerImpl
participant R as 工具调用注册表
participant H as 工具处理器
C->>S: callTool(toolName, toolCallId, argString)
S->>R: 转换请求,传递包含 toolCallId 的选项
R->>H: 执行 handler(argString, options)
H-->>R: 返回处理结果
R-->>S: 返回处理后的结果
S-->>C: 返回最终结果
Possibly related PRs
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
yarn install v1.22.22 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
💤 Files with no reviewable changes (4)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (8)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🔭 Outside diff range comments (1)
packages/ai-native/__test__/node/mcp-server.test.ts (1)
83-88
: 🛠️ Refactor suggestion测试用例需要完善
测试期望中缺少对 toolCallId 参数的验证。建议更新测试断言以确保该参数被正确传递。
expect(mockClient.callTool).toHaveBeenCalledWith({ name: toolName, arguments: { key: 'value' }, + toolCallId: 'toolCallId', });
🧹 Nitpick comments (10)
packages/ai-native/src/browser/mcp/tools/grepSearch.ts (1)
52-52
: 请完善 TODO 注释
此处提及需要“语义化搜索”的更多说明,但尚未完成。建议尽早补充具体描述,以便后续维护人员了解此功能的优劣势与适用场景。packages/ai-native/src/browser/mcp/mcp-server.feature.registry.ts (1)
65-67
: 建议增加类型安全性当前从
args
中提取toolCallId
的方式可能不够类型安全。建议定义一个接口来约束args
的类型。- const toolCallId = args.toolCallId; + interface ToolArgs { + toolCallId: string; + [key: string]: any; + } + const { toolCallId, ...restArgs } = args as ToolArgs;packages/ai-native/src/browser/model/msg-history-manager.ts (2)
11-11
: 建议添加类型定义和文档注释为了提高代码的可维护性和可读性,建议:
- 为
messageAdditionalMap
定义具体的类型接口- 为事件发射器添加 JSDoc 文档说明其用途
+interface MessageAdditional { + [key: string]: any; +} -private messageAdditionalMap: Map<string, Record<string, any>> = new Map(); +private messageAdditionalMap: Map<string, MessageAdditional> = new Map(); +/** 当消息附加数据发生变化时触发 */ private readonly _onMessageAdditionalChange = new Emitter<MessageAdditional>();Also applies to: 16-17
79-91
: 建议优化错误处理和返回值类型建议增加以下改进:
- 为不存在的消息 ID 添加错误日志
- 明确
getMessageAdditional
的返回值类型+import { ILogger } from '@opensumi/ide-core-common'; +@Autowired(ILogger) +private readonly logger: ILogger; public setMessageAdditional(id: string, additional: MessageAdditional) { if (!this.messageMap.has(id)) { + this.logger.warn(`Attempted to set additional data for non-existent message: ${id}`); return; } // ... rest of the code } -public getMessageAdditional(id: string): Record<string, any> { +public getMessageAdditional(id: string): MessageAdditional { return this.messageAdditionalMap.get(id) || {}; }packages/ai-native/src/browser/mcp/tools/components/SearchResult.tsx (1)
52-64
: 优化性能
parsedFiles
的依赖项不完整,可能导致不必要的重计算。const parsedFiles = useMemo( () => files.map((file) => { const uri = URI.parse(file); const iconClass = labelService.getIcon(uri); return { iconClass, name: uri.path.base, path: path.relative(workspaceRoot.codeUri.fsPath, uri.path.dir.toString()), }; }), - [files], + [files, labelService, workspaceRoot], );packages/ai-native/src/browser/mcp/tools/fileSearch.ts (2)
21-21
: 建议将魔法数字提取为配置项
MAX_RESULTS = 10
建议移至配置文件中,使其更容易维护和调整。-const MAX_RESULTS = 10; +import { FILE_SEARCH_CONFIG } from '../config'; +const { MAX_RESULTS } = FILE_SEARCH_CONFIG;Also applies to: 72-75
64-66
: 建议将排除模式配置化目前硬编码的排除模式
['**/node_modules/**']
建议移至配置文件,并考虑支持用户自定义配置。- excludePatterns: ['**/node_modules/**'], + excludePatterns: config.getExcludePatterns(),packages/ai-native/src/common/tool-invocation-registry.ts (1)
100-107
: 简化 registerTool 方法的条件逻辑当前实现中,无论条件如何,都执行相同的
set
操作。建议简化代码以提高可读性。建议应用以下更改:
registerTool(tool: ToolRequest): void { - if (this.tools.has(tool.id)) { - // TODO: 使用适当的日志机制 - this.tools.set(tool.id, tool); - } else { - this.tools.set(tool.id, tool); - } + // TODO: 如果需要,在工具已存在时添加日志 + this.tools.set(tool.id, tool); }packages/core-common/src/types/ai-native/index.ts (1)
433-434
: 建议优化 additional 属性的类型定义当前
additional
属性使用Record<string, any>
类型过于宽松,可能导致类型安全问题。建议:
- 定义具体的接口来描述工具调用结果的结构
- 使用联合类型来限制可能的值类型
示例改进:
- additional?: Record<string, any>; + additional?: { + toolCallResults?: { + toolCallId: string; + name: string; + result: string | number | boolean | null; + }[]; + };packages/ai-native/src/browser/mcp/tools/components/index.module.less (1)
100-118
: .fileItem 样式与交互反馈建议改进
.fileItem 的样式定义清晰,设置了适当的内边距、字体及布局,并通过 overflow 属性处理了文本溢出。不过,在悬停状态(hover)下,背景色保持与父级背景相同,可能会导致交互反馈不够明显。
建议修改 &:hover 部分的背景色,例如使用 less 的 lighten 函数稍微调整颜色以增强视觉反馈:- &:hover { - background-color: var(--design-block-background); - } + &:hover { + background-color: lighten(var(--design-block-background), 10%); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (27)
packages/ai-native/__test__/node/mcp-server.test.ts
(2 hunks)packages/ai-native/src/browser/components/ChatToolRender.tsx
(2 hunks)packages/ai-native/src/browser/index.ts
(2 hunks)packages/ai-native/src/browser/mcp/mcp-server.feature.registry.ts
(1 hunks)packages/ai-native/src/browser/mcp/tools/components/SearchResult.tsx
(1 hunks)packages/ai-native/src/browser/mcp/tools/components/index.module.less
(1 hunks)packages/ai-native/src/browser/mcp/tools/fileSearch.ts
(1 hunks)packages/ai-native/src/browser/mcp/tools/findFilesByNameSubstring.ts
(0 hunks)packages/ai-native/src/browser/mcp/tools/getCurrentFilePath.ts
(0 hunks)packages/ai-native/src/browser/mcp/tools/getFileTextByPath.ts
(0 hunks)packages/ai-native/src/browser/mcp/tools/getOpenEditorFileText.ts
(0 hunks)packages/ai-native/src/browser/mcp/tools/getSelectedText.ts
(0 hunks)packages/ai-native/src/browser/mcp/tools/grepSearch.ts
(1 hunks)packages/ai-native/src/browser/mcp/tools/listDir.ts
(1 hunks)packages/ai-native/src/browser/mcp/tools/readFile.ts
(1 hunks)packages/ai-native/src/browser/mcp/tools/replaceOpenEditorFile.ts
(0 hunks)packages/ai-native/src/browser/mcp/tools/replaceOpenEditorFileByDiffPreviewer.ts
(0 hunks)packages/ai-native/src/browser/model/msg-history-manager.ts
(2 hunks)packages/ai-native/src/common/mcp-server-manager.ts
(1 hunks)packages/ai-native/src/common/tool-invocation-registry.ts
(2 hunks)packages/ai-native/src/node/base-language-model.ts
(2 hunks)packages/ai-native/src/node/mcp-server-manager-impl.ts
(3 hunks)packages/ai-native/src/node/mcp-server.ts
(3 hunks)packages/ai-native/src/node/mcp/sumi-mcp-server.ts
(2 hunks)packages/core-common/src/types/ai-native/index.ts
(1 hunks)packages/search/src/browser/search.service.ts
(1 hunks)packages/search/src/common/content-search.ts
(1 hunks)
💤 Files with no reviewable changes (7)
- packages/ai-native/src/browser/mcp/tools/getOpenEditorFileText.ts
- packages/ai-native/src/browser/mcp/tools/replaceOpenEditorFile.ts
- packages/ai-native/src/browser/mcp/tools/getSelectedText.ts
- packages/ai-native/src/browser/mcp/tools/getCurrentFilePath.ts
- packages/ai-native/src/browser/mcp/tools/findFilesByNameSubstring.ts
- packages/ai-native/src/browser/mcp/tools/getFileTextByPath.ts
- packages/ai-native/src/browser/mcp/tools/replaceOpenEditorFileByDiffPreviewer.ts
🧰 Additional context used
🪛 GitHub Check: unittest (ubuntu-latest, 18.x, node)
packages/ai-native/src/browser/mcp/tools/components/SearchResult.tsx
[failure] 3-3:
Cannot find module '@opensumi/ide-ai-native/lib/common' or its corresponding type declarations.
packages/ai-native/src/browser/mcp/tools/grepSearch.ts
[failure] 4-4:
Cannot find module '@opensumi/ide-ai-native/lib/common' or its corresponding type declarations.
packages/ai-native/src/browser/mcp/tools/fileSearch.ts
[failure] 4-4:
Cannot find module '@opensumi/ide-ai-native/lib/common' or its corresponding type declarations.
🪛 Biome (1.9.4)
packages/ai-native/src/browser/mcp/tools/grepSearch.ts
[error] 103-103: Avoid the use of spread (...
) syntax on accumulators.
Spread syntax should be avoided on accumulators (like those in .reduce
) because it causes a time complexity of O(n^2)
.
Consider methods such as .splice or .push instead.
(lint/performance/noAccumulatingSpread)
⏰ Context from checks skipped due to timeout of 90000ms (7)
- GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
- GitHub Check: build (ubuntu-latest, 20.x)
- GitHub Check: build (macos-latest, 20.x)
- GitHub Check: unittest (macos-latest, 18.x, jsdom)
- GitHub Check: unittest (macos-latest, 18.x, node)
- GitHub Check: build-windows
- GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (25)
packages/ai-native/src/browser/mcp/tools/grepSearch.ts (2)
4-4
: 无法找到对应模块或类型声明
可能是路径错误或缺少类型声明文件,导致无法解析@opensumi/ide-ai-native/lib/common
。建议检查依赖包和tsconfig
中的路径配置,确保导入路径或类型声明可用。🧰 Tools
🪛 GitHub Check: unittest (ubuntu-latest, 18.x, node)
[failure] 4-4:
Cannot find module '@opensumi/ide-ai-native/lib/common' or its corresponding type declarations.
42-45
: 工具注册逻辑看起来可行
此处将搜索工具注册到 MCP 平台,并指定了前端呈现组件,整体实现较为规范,暂未发现明显问题。packages/ai-native/src/common/mcp-server-manager.ts (1)
4-9
: 新增toolCallId
参数需要确认全局引用
callTool
方法签名新增了toolCallId
。为确保功能正常,请确认所有调用点都已传入相应的参数,并对其进行测试以避免潜在的运行时错误。packages/ai-native/src/browser/mcp/tools/listDir.ts (1)
17-17
: 将explanation
字段改为可选
此变更提升了灵活性,允许在不需要说明的情况下也可使用此工具,避免不必要的字段校验错误。整体实现无异常,值得肯定。packages/ai-native/src/browser/mcp/tools/readFile.ts (1)
16-19
: 代码变更合理将
explanation
字段设置为可选是一个合理的改进,这样可以在不需要解释的情况下简化工具的使用。packages/ai-native/src/node/mcp-server.ts (2)
11-11
: 接口更新符合预期!接口方法签名的更新正确地包含了新的 toolCallId 参数,这有助于工具调用的追踪和管理。
90-107
: 实现更新完整且一致!callTool 方法的实现正确地处理了新增的 toolCallId 参数,并将其包含在传递给客户端的参数对象中。
packages/ai-native/src/browser/components/ChatToolRender.tsx (1)
57-95
: 组件渲染逻辑优化!使用三元运算符重构了渲染逻辑,使代码更加简洁清晰。同时正确地传递了 toolCallId 到 ToolComponent。
packages/ai-native/src/common/tool-invocation-registry.ts (2)
6-13
: 代码结构清晰且类型安全!使用 zod 进行参数验证的实现非常合理,特别是通过
lazy
实现的递归定义可以很好地处理嵌套结构。
17-24
: 接口设计合理且保持了向后兼容性!
handler
方法签名的更新很好地支持了工具执行选项,同时通过可选参数保持了与现有代码的兼容性。packages/ai-native/src/node/mcp-server-manager-impl.ts (2)
47-58
: 方法签名更新合理且实现正确!
callTool
方法的更新很好地支持了工具调用 ID 的传递,实现逻辑清晰。
81-91
: 错误处理完善,参数传递正确!
handler
实现很好地处理了新增的 options 参数,同时保持了原有的错误处理逻辑。packages/ai-native/src/node/base-language-model.ts (1)
69-70
: 参数传递实现正确且符合功能需求!
execute
函数的更新正确地将 options 参数传递给了 handler,实现符合预期。packages/ai-native/src/node/mcp/sumi-mcp-server.ts (1)
159-178
: 参数处理和错误处理都很完善!
callTool
方法的实现正确地处理了 toolCallId 参数,并保持了良好的 JSON 解析错误处理。packages/ai-native/src/browser/index.ts (2)
61-61
: 导入语句的顺序符合规范!新增的
FileSearchTool
和GrepSearchTool
的导入语句按字母顺序正确放置。Also applies to: 64-64
100-101
: 工具注册顺序合理!新增的搜索工具
FileSearchTool
和GrepSearchTool
被正确地添加到 MCP Server Contributions 区域,并保持了与其他工具一致的注册方式。packages/search/src/common/content-search.ts (1)
151-151
: 文档注释更新准确!
lineText
属性的注释从rangeLineText
更新为renderLineText
,与实际代码实现保持一致。这个更新提高了文档的准确性。packages/search/src/browser/search.service.ts (2)
235-239
: 搜索参数扩展设计合理!
doSearch
方法通过扩展state
参数类型来支持更灵活的搜索配置,同时保持了向后兼容性。这种设计方式值得肯定。
241-241
: 参数处理逻辑完善!新增参数的处理逻辑考虑周全:
maxResults
有合理的默认值 2000include
和exclude
在未提供时会回退到实例变量Also applies to: 247-248
packages/ai-native/src/browser/mcp/tools/components/index.module.less (6)
69-74
: .container 样式定义清晰
.container 类为容器提供了明确的边框、圆角和溢出隐藏效果,有助于组件的视觉分组和框架整洁。目前的实现符合设计预期。
76-86
: .header 样式设置得当
.header 类通过合理的内边距、背景色、边框底部和对齐方式,构建了一个易于点击且与整体风格一致的头部区域。
88-94
: .fileList 样式完善
.fileList 定义了无内外边距、无列表样式的块级展示,并设置了背景色,保证了文件列表展示的整洁性。
96-98
: .fileList.collapsed 状态实现
通过将 display 设置为 none,实现了列表的折叠效果,方案简单明了,符合需求。
120-124
: .fileIcon 样式检查
.fileIcon 类适当地设置了图标的颜色和尺寸,有助于与文本内容形成区分,提升整体视觉效果。
126-132
: .filePath 样式实现良好
.filePath 类利用 flex 布局及自动边距,实现了文本的对齐和自适应分配空间,样式清晰且实用。
packages/ai-native/src/browser/mcp/tools/components/SearchResult.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (1)
packages/ai-native/src/browser/mcp/tools/grepSearch.ts (1)
97-103
: 🛠️ Refactor suggestion优化搜索结果处理性能
在
.reduce()
中使用扩展运算符会导致 O(n²) 的时间复杂度。建议使用push
方法来提高性能。-.reduce((acc, r) => { - if (acc.find((a) => a.line === r.line)) { - return acc; - } - return [...acc, r]; -}, [] as ContentSearchResult[]) +.reduce((acc, r) => { + if (!acc.some((a) => a.line === r.line)) { + acc.push(r); + } + return acc; +}, [] as ContentSearchResult[])🧰 Tools
🪛 Biome (1.9.4)
[error] 103-103: Avoid the use of spread (
...
) syntax on accumulators.Spread syntax should be avoided on accumulators (like those in
.reduce
) because it causes a time complexity ofO(n^2)
.
Consider methods such as .splice or .push instead.(lint/performance/noAccumulatingSpread)
🧹 Nitpick comments (4)
packages/ai-native/src/browser/mcp/tools/components/SearchResult.tsx (2)
12-17
: 建议改进类型安全性
args
参数使用any
类型会降低类型安全性,建议定义具体的接口类型。interface SearchResultProps { - args: any; + args: { + query: string; + explanation?: string; + }; toolCallId: string; messageId: string; toolName: string; }
19-25
: 建议重构以减少代码重复
FileSearchToolComponent
和GrepSearchToolComponent
结构完全相同,可以合并为一个组件。-export const FileSearchToolComponent: React.FC<SearchResultProps> = ({ args, toolCallId, messageId }) => ( - <SearchResult args={args} toolCallId={toolCallId} messageId={messageId} toolName='fileSearch' /> -); - -export const GrepSearchToolComponent: React.FC<SearchResultProps> = ({ args, toolCallId, messageId }) => ( - <SearchResult args={args} toolCallId={toolCallId} messageId={messageId} toolName='grepSearch' /> -); +export const SearchToolComponent = (toolName: 'fileSearch' | 'grepSearch') => + React.memo<Omit<SearchResultProps, 'toolName'>>(({ args, toolCallId, messageId }) => ( + <SearchResult args={args} toolCallId={toolCallId} messageId={messageId} toolName={toolName} /> + )); + +export const FileSearchToolComponent = SearchToolComponent('fileSearch'); +export const GrepSearchToolComponent = SearchToolComponent('grepSearch');packages/ai-native/src/browser/mcp/tools/fileSearch.ts (1)
64-66
: 建议改进配置管理当前的忽略配置是硬编码的,建议将其移至配置文件中以提高灵活性。
- // TODO: 忽略配置 - excludePatterns: ['**/node_modules/**'], + excludePatterns: this.getExcludePatterns(),建议添加以下方法:
private getExcludePatterns(): string[] { return this.configService.getValue('search.exclude') || ['**/node_modules/**']; }packages/ai-native/src/browser/mcp/tools/grepSearch.ts (1)
52-53
: 需要更新工具描述TODO 注释表明需要在支持语义化搜索后更新描述。建议创建一个任务来跟踪这个改进。
是否需要我帮助创建一个任务来跟踪语义化搜索的实现和文档更新?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/ai-native/src/browser/mcp/tools/components/SearchResult.tsx
(1 hunks)packages/ai-native/src/browser/mcp/tools/fileSearch.ts
(1 hunks)packages/ai-native/src/browser/mcp/tools/grepSearch.ts
(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ai-native/src/browser/mcp/tools/grepSearch.ts
[error] 103-103: Avoid the use of spread (...
) syntax on accumulators.
Spread syntax should be avoided on accumulators (like those in .reduce
) because it causes a time complexity of O(n^2)
.
Consider methods such as .splice or .push instead.
(lint/performance/noAccumulatingSpread)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: build (ubuntu-latest, 20.x)
- GitHub Check: build (macos-latest, 20.x)
- GitHub Check: build-windows
- GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
- GitHub Check: unittest (ubuntu-latest, 18.x, node)
- GitHub Check: unittest (macos-latest, 18.x, jsdom)
- GitHub Check: ubuntu-latest, Node.js 20.x
- GitHub Check: unittest (macos-latest, 18.x, node)
🔇 Additional comments (2)
packages/ai-native/src/browser/mcp/tools/components/SearchResult.tsx (2)
38-45
: 优化 useEffect 清理逻辑当前的 useEffect 清理可能存在内存泄漏风险。建议在组件卸载时确保所有订阅都被正确清理。
47-50
: 添加错误处理文件打开操作缺少错误处理机制。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (6)
packages/ai-native/__test__/common/mcp-server-manager.test.ts (1)
88-89
: 建议改进测试用例的实现方式当前测试用例存在以下可以改进的地方:
- 'call-x' 是硬编码的值,建议将其定义为有意义的常量或变量
- 缺少对错误情况的测试,比如当 toolCallId 为空或无效时的处理
- 测试用例的名称可以更具体地反映新增的 toolCallId 参数
建议按照以下方式重构测试代码:
+ const TEST_TOOL_CALL_ID = 'test-call-123'; + - it('should call tool on server', async () => { + it('should call tool on server with valid tool call ID', async () => { const toolName = 'test-tool'; const argString = '{"key": "value"}'; - await mockManager.callTool('test-server', toolName, 'call-x', argString); - expect(mockManager.callTool).toHaveBeenCalledWith('test-server', toolName, 'call-x', argString); + await mockManager.callTool('test-server', toolName, TEST_TOOL_CALL_ID, argString); + expect(mockManager.callTool).toHaveBeenCalledWith('test-server', toolName, TEST_TOOL_CALL_ID, argString); }); + + it('should reject invalid tool call ID', async () => { + const toolName = 'test-tool'; + const argString = '{"key": "value"}'; + await expect( + mockManager.callTool('test-server', toolName, '', argString) + ).rejects.toThrow('Invalid tool call ID'); + });packages/ai-native/src/browser/mcp/tools/components/SearchResult.tsx (2)
12-17
: 改进类型定义和组件结构建议进行以下改进:
- 将
args
的类型从any
改为具体的接口类型- 考虑合并两个工具组件,通过属性区分不同工具类型
interface SearchResultProps { - args: any; + args: { + query: string; + [key: string]: unknown; + }; toolCallId: string; messageId: string; toolName: string; }
81-81
: 改进文件路径处理逻辑建议使用更安全的路径处理方式:
- 验证工作区根路径是否存在
- 使用
path.join
替代字符串拼接- onClick={() => handleFileClick(URI.file(path.join(workspaceRoot.codeUri.fsPath, file.path, file.name)))} + onClick={() => { + if (!workspaceRoot?.codeUri?.fsPath) { + return; + } + const filePath = path.join(workspaceRoot.codeUri.fsPath, file.path, file.name); + handleFileClick(URI.file(filePath)); + }}packages/ai-native/src/browser/mcp/tools/fileSearch.ts (2)
64-70
: 优化搜索配置的灵活性当前的搜索配置存在以下问题:
- 硬编码的排除模式
**/node_modules/**
- 未完成的忽略配置 TODO
建议:
- 从工作区配置或用户设置中读取排除模式
- 完成忽略配置的实现
需要我帮助实现配置读取和忽略规则的逻辑吗?
62-70
: 添加错误处理和进度反馈建议添加以下功能:
- 搜索操作的错误处理
- 搜索进度的反馈机制
const searchResults = await this.fileSearchService.find(searchPattern, { rootUris: [new URI(workspaceRoots[0].uri).codeUri.fsPath], excludePatterns: ['**/node_modules/**'], limit: 100, useGitIgnore: true, noIgnoreParent: true, fuzzyMatch: true, + onProgress: (progress) => { + logger.appendLine(`搜索进度: ${progress}%`); + }, }).catch(error => { + logger.appendLine(`搜索失败: ${error.message}`); + throw error; });packages/ai-native/src/browser/mcp/tools/grepSearch.ts (1)
52-53
: 完善语义化搜索的描述TODO 注释提到需要描述语义化搜索的优劣势。
需要我帮助编写关于语义化搜索功能的详细描述吗?我可以提供:
- 与正则搜索的对比
- 使用场景建议
- 性能考虑因素
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (5)
packages/ai-native/__test__/common/mcp-server-manager.test.ts
(1 hunks)packages/ai-native/package.json
(1 hunks)packages/ai-native/src/browser/mcp/tools/components/SearchResult.tsx
(1 hunks)packages/ai-native/src/browser/mcp/tools/fileSearch.ts
(1 hunks)packages/ai-native/src/browser/mcp/tools/grepSearch.ts
(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ai-native/src/browser/mcp/tools/grepSearch.ts
[error] 103-103: Avoid the use of spread (...
) syntax on accumulators.
Spread syntax should be avoided on accumulators (like those in .reduce
) because it causes a time complexity of O(n^2)
.
Consider methods such as .splice or .push instead.
(lint/performance/noAccumulatingSpread)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
- GitHub Check: unittest (ubuntu-latest, 18.x, node)
- GitHub Check: unittest (macos-latest, 18.x, jsdom)
- GitHub Check: build (ubuntu-latest, 20.x)
- GitHub Check: unittest (macos-latest, 18.x, node)
- GitHub Check: build (macos-latest, 20.x)
- GitHub Check: build-windows
- GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (5)
packages/ai-native/src/browser/mcp/tools/components/SearchResult.tsx (2)
38-45
: 优化 useEffect 依赖项和清理逻辑
47-50
: 添加文件操作的错误处理packages/ai-native/src/browser/mcp/tools/grepSearch.ts (2)
97-103
: 避免在 .reduce() 中使用扩展运算符🧰 Tools
🪛 Biome (1.9.4)
[error] 103-103: Avoid the use of spread (
...
) syntax on accumulators.Spread syntax should be avoided on accumulators (like those in
.reduce
) because it causes a time complexity ofO(n^2)
.
Consider methods such as .splice or .push instead.(lint/performance/noAccumulatingSpread)
87-91
: 添加搜索超时处理packages/ai-native/package.json (1)
41-41
: 依赖添加正确新增的
@opensumi/ide-search
依赖与新的搜索功能相符。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4396 +/- ##
==========================================
- Coverage 53.73% 53.58% -0.16%
==========================================
Files 1655 1651 -4
Lines 101889 101806 -83
Branches 22028 22027 -1
==========================================
- Hits 54751 54552 -199
- Misses 39203 39308 +105
- Partials 7935 7946 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Types
Background or solution
feat: add search file & content tool
Changelog
feat: add search file & content tool
Summary by CodeRabbit
新功能
样式
优化