vtcode_core/tools/registry/
inventory_facade.rs1use std::path::PathBuf;
4use std::sync::Arc;
5
6use crate::tools::edited_file_monitor::EditedFileMonitor;
7use crate::tools::file_ops::FileOpsTool;
8use crate::tools::grep_file::GrepSearchManager;
9
10use super::{Tool, ToolHandler, ToolRegistry};
11
12impl ToolRegistry {
13 pub fn get_tool(&self, name: &str) -> Option<Arc<dyn Tool>> {
15 if self.optimization_config.tool_registry.use_optimized_registry {
17 {
19 let cache = self.hot_tool_cache.read();
20 if let Some(cached_tool) = cache.peek(name) {
21 return Some(cached_tool.clone());
22 }
23 }
24 }
25
26 let tool = self.inventory.get_registration(name).and_then(|reg| match reg.handler() {
28 ToolHandler::TraitObject(tool) => Some(tool.clone()),
29 _ => None,
30 });
31
32 if let Some(ref tool_arc) = tool
34 && self.optimization_config.tool_registry.use_optimized_registry
35 {
36 self.hot_tool_cache.write().put(name.to_string(), tool_arc.clone());
37 }
38
39 tool
40 }
41 pub fn workspace_root(&self) -> &PathBuf {
42 self.inventory.workspace_root()
43 }
44
45 pub fn workspace_root_owned(&self) -> PathBuf {
47 self.inventory.workspace_root().clone()
48 }
49
50 pub fn file_ops_tool(&self) -> &FileOpsTool {
51 self.inventory.file_ops_tool()
52 }
53
54 pub fn edited_file_monitor_ref(&self) -> &EditedFileMonitor {
56 self.edited_file_monitor.as_ref()
57 }
58
59 pub fn edited_file_monitor(&self) -> &Arc<EditedFileMonitor> {
61 &self.edited_file_monitor
62 }
63
64 pub fn grep_file_manager(&self) -> Arc<GrepSearchManager> {
65 self.inventory.grep_file_manager()
66 }
67}