use std::borrow::Cow;
use std::path::PathBuf;
use std::sync::Arc;
use crate::tools::edited_file_monitor::EditedFileMonitor;
use crate::tools::file_ops::FileOpsTool;
use crate::tools::grep_file::GrepSearchManager;
use super::{Tool, ToolHandler, ToolRegistry};
impl ToolRegistry {
pub fn get_tool(&self, name: &str) -> Option<Arc<dyn Tool>> {
if self
.optimization_config
.tool_registry
.use_optimized_registry
{
{
let cache = self.hot_tool_cache.read();
if let Some(cached_tool) = cache.peek(name) {
return Some(cached_tool.clone());
}
}
}
let tool = self
.inventory
.get_registration(name)
.and_then(|reg| match reg.handler() {
ToolHandler::TraitObject(tool) => Some(tool.clone()),
_ => None,
});
if let Some(ref tool_arc) = tool
&& self
.optimization_config
.tool_registry
.use_optimized_registry
{
self.hot_tool_cache
.write()
.put(name.to_string(), tool_arc.clone());
}
tool
}
pub fn workspace_root(&self) -> &PathBuf {
self.inventory.workspace_root()
}
pub fn workspace_root_owned(&self) -> PathBuf {
self.inventory.workspace_root().clone()
}
pub(crate) fn workspace_root_str(&self) -> Cow<'_, str> {
self.workspace_root().to_string_lossy()
}
pub fn file_ops_tool(&self) -> &FileOpsTool {
self.inventory.file_ops_tool()
}
pub fn edited_file_monitor(&self) -> &Arc<EditedFileMonitor> {
&self.edited_file_monitor
}
pub fn grep_file_manager(&self) -> Arc<GrepSearchManager> {
self.inventory.grep_file_manager()
}
}