vtcode_core/tools/registry/
inventory_facade.rs1use std::borrow::Cow;
4use std::path::PathBuf;
5use std::sync::Arc;
6
7use crate::tools::edited_file_monitor::EditedFileMonitor;
8use crate::tools::file_ops::FileOpsTool;
9use crate::tools::grep_file::GrepSearchManager;
10
11use super::{Tool, ToolHandler, ToolRegistry};
12
13impl ToolRegistry {
14 pub fn get_tool(&self, name: &str) -> Option<Arc<dyn Tool>> {
16 if self
18 .optimization_config
19 .tool_registry
20 .use_optimized_registry
21 {
22 {
24 let cache = self.hot_tool_cache.read();
25 if let Some(cached_tool) = cache.peek(name) {
26 return Some(cached_tool.clone());
27 }
28 }
29 }
30
31 let tool = self
33 .inventory
34 .get_registration(name)
35 .and_then(|reg| match reg.handler() {
36 ToolHandler::TraitObject(tool) => Some(tool.clone()),
37 _ => None,
38 });
39
40 if let Some(ref tool_arc) = tool
42 && self
43 .optimization_config
44 .tool_registry
45 .use_optimized_registry
46 {
47 self.hot_tool_cache
48 .write()
49 .put(name.to_string(), tool_arc.clone());
50 }
51
52 tool
53 }
54 pub fn workspace_root(&self) -> &PathBuf {
55 self.inventory.workspace_root()
56 }
57
58 pub fn workspace_root_owned(&self) -> PathBuf {
60 self.inventory.workspace_root().clone()
61 }
62
63 pub(crate) fn workspace_root_str(&self) -> Cow<'_, str> {
65 self.workspace_root().to_string_lossy()
66 }
67
68 pub fn file_ops_tool(&self) -> &FileOpsTool {
69 self.inventory.file_ops_tool()
70 }
71
72 pub fn edited_file_monitor_ref(&self) -> &EditedFileMonitor {
74 self.edited_file_monitor.as_ref()
75 }
76
77 pub fn edited_file_monitor(&self) -> &Arc<EditedFileMonitor> {
79 &self.edited_file_monitor
80 }
81
82 pub fn grep_file_manager(&self) -> Arc<GrepSearchManager> {
83 self.inventory.grep_file_manager()
84 }
85}