summaryrefslogtreecommitdiff
path: root/cli/lsp/registries.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/registries.rs')
-rw-r--r--cli/lsp/registries.rs38
1 files changed, 21 insertions, 17 deletions
diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs
index a145322b5..a17cd1228 100644
--- a/cli/lsp/registries.rs
+++ b/cli/lsp/registries.rs
@@ -416,6 +416,7 @@ enum VariableItems {
#[derive(Debug, Clone)]
pub struct ModuleRegistry {
origins: HashMap<String, Vec<RegistryConfiguration>>,
+ pub location: PathBuf,
pub file_fetcher: FileFetcher,
http_cache: Arc<GlobalHttpCache>,
}
@@ -424,7 +425,7 @@ impl ModuleRegistry {
pub fn new(location: PathBuf, http_client: Arc<HttpClient>) -> Self {
// the http cache should always be the global one for registry completions
let http_cache = Arc::new(GlobalHttpCache::new(
- location,
+ location.clone(),
crate::cache::RealDenoCacheEnv,
));
let mut file_fetcher = FileFetcher::new(
@@ -439,6 +440,7 @@ impl ModuleRegistry {
Self {
origins: HashMap::new(),
+ location,
file_fetcher,
http_cache,
}
@@ -488,10 +490,12 @@ impl ModuleRegistry {
}
/// Disable a registry, removing its configuration, if any, from memory.
- pub fn disable(&mut self, origin: &str) -> Result<(), AnyError> {
- let origin = base_url(&Url::parse(origin)?);
+ pub fn disable(&mut self, origin: &str) {
+ let Ok(origin_url) = Url::parse(origin) else {
+ return;
+ };
+ let origin = base_url(&origin_url);
self.origins.remove(&origin);
- Ok(())
}
/// Check to see if the given origin has a registry configuration.
@@ -536,13 +540,17 @@ impl ModuleRegistry {
/// Enable a registry by attempting to retrieve its configuration and
/// validating it.
- pub async fn enable(&mut self, origin: &str) -> Result<(), AnyError> {
- let origin_url = Url::parse(origin)?;
+ pub async fn enable(&mut self, origin: &str) {
+ let Ok(origin_url) = Url::parse(origin) else {
+ return;
+ };
let origin = base_url(&origin_url);
#[allow(clippy::map_entry)]
// we can't use entry().or_insert_with() because we can't use async closures
if !self.origins.contains_key(&origin) {
- let specifier = origin_url.join(CONFIG_PATH)?;
+ let Ok(specifier) = origin_url.join(CONFIG_PATH) else {
+ return;
+ };
match self.fetch_config(&specifier).await {
Ok(configs) => {
self.origins.insert(origin, configs);
@@ -557,8 +565,6 @@ impl ModuleRegistry {
}
}
}
-
- Ok(())
}
#[cfg(test)]
@@ -1092,6 +1098,10 @@ impl ModuleRegistry {
.ok()?;
Some(items)
}
+
+ pub fn clear_cache(&self) {
+ self.file_fetcher.clear_memory_files();
+ }
}
#[cfg(test)]
@@ -1256,10 +1266,7 @@ mod tests {
let location = temp_dir.path().join("registries").to_path_buf();
let mut module_registry =
ModuleRegistry::new(location, Arc::new(HttpClient::new(None, None)));
- module_registry
- .enable("http://localhost:4545/")
- .await
- .expect("could not enable");
+ module_registry.enable("http://localhost:4545/").await;
let range = lsp::Range {
start: lsp::Position {
line: 0,
@@ -1317,10 +1324,7 @@ mod tests {
let location = temp_dir.path().join("registries").to_path_buf();
let mut module_registry =
ModuleRegistry::new(location, Arc::new(HttpClient::new(None, None)));
- module_registry
- .enable("http://localhost:4545/")
- .await
- .expect("could not enable");
+ module_registry.enable("http://localhost:4545/").await;
let range = lsp::Range {
start: lsp::Position {
line: 0,