diff options
Diffstat (limited to 'cli/lsp')
-rw-r--r-- | cli/lsp/cache.rs | 3 | ||||
-rw-r--r-- | cli/lsp/completions.rs | 6 | ||||
-rw-r--r-- | cli/lsp/diagnostics.rs | 4 | ||||
-rw-r--r-- | cli/lsp/documents.rs | 27 | ||||
-rw-r--r-- | cli/lsp/language_server.rs | 16 | ||||
-rw-r--r-- | cli/lsp/registries.rs | 30 | ||||
-rw-r--r-- | cli/lsp/tsc.rs | 6 |
7 files changed, 49 insertions, 43 deletions
diff --git a/cli/lsp/cache.rs b/cli/lsp/cache.rs index f047e5fd4..df88254ee 100644 --- a/cli/lsp/cache.rs +++ b/cli/lsp/cache.rs @@ -8,6 +8,7 @@ use deno_core::ModuleSpecifier; use std::collections::HashMap; use std::fs; use std::path::Path; +use std::path::PathBuf; use std::sync::Arc; use std::time::SystemTime; @@ -97,7 +98,7 @@ impl CacheMetadata { Some(metadata) } - pub fn set_location(&mut self, location: &Path) { + pub fn set_location(&mut self, location: PathBuf) { self.cache = HttpCache::new(location); self.metadata.lock().clear(); } diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs index 070e3168a..17a00010b 100644 --- a/cli/lsp/completions.rs +++ b/cli/lsp/completions.rs @@ -519,13 +519,13 @@ mod tests { source_fixtures: &[(&str, &str)], location: &Path, ) -> Documents { - let mut documents = Documents::new(location); + let mut documents = Documents::new(location.to_path_buf()); for (specifier, source, version, language_id) in fixtures { let specifier = resolve_url(specifier).expect("failed to create specifier"); documents.open(specifier, *version, *language_id, (*source).into()); } - let http_cache = HttpCache::new(location); + let http_cache = HttpCache::new(location.to_path_buf()); for (specifier, source) in source_fixtures { let specifier = resolve_url(specifier).expect("failed to create specifier"); @@ -546,7 +546,7 @@ mod tests { sources: &[(&str, &str)], ) -> Documents { let location = temp_dir.path().join("deps"); - mock_documents(documents, sources, &location) + mock_documents(documents, sources, location.as_path()) } #[test] diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 6af6c92b3..9acb9cef5 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -1198,7 +1198,7 @@ mod tests { location: &Path, maybe_import_map: Option<(&str, &str)>, ) -> StateSnapshot { - let mut documents = Documents::new(location); + let mut documents = Documents::new(location.to_path_buf()); for (specifier, source, version, language_id) in fixtures { let specifier = resolve_url(specifier).expect("failed to create specifier"); @@ -1243,7 +1243,7 @@ mod tests { sources: &[(&str, &str, i32, LanguageId)], maybe_import_map: Option<(&str, &str)>, ) -> (StateSnapshot, PathBuf) { - let location = temp_dir.path().join("deps"); + let location = temp_dir.path().join("deps").to_path_buf(); let state_snapshot = mock_state_snapshot(sources, &location, maybe_import_map); (state_snapshot, location) diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index d088e01c0..1282f8a18 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -661,9 +661,9 @@ struct SpecifierResolver { } impl SpecifierResolver { - pub fn new(cache_path: &Path) -> Self { + pub fn new(cache: HttpCache) -> Self { Self { - cache: HttpCache::new(cache_path), + cache, redirects: Mutex::new(HashMap::new()), } } @@ -846,9 +846,10 @@ pub struct Documents { } impl Documents { - pub fn new(location: &Path) -> Self { + pub fn new(location: PathBuf) -> Self { + let cache = HttpCache::new(location); Self { - cache: HttpCache::new(location), + cache: cache.clone(), dirty: true, dependents_map: Default::default(), open_docs: HashMap::default(), @@ -858,7 +859,7 @@ impl Documents { resolver: Default::default(), npm_specifier_reqs: Default::default(), has_injected_types_node_package: false, - specifier_resolver: Arc::new(SpecifierResolver::new(location)), + specifier_resolver: Arc::new(SpecifierResolver::new(cache)), } } @@ -1136,10 +1137,11 @@ impl Documents { } /// Update the location of the on disk cache for the document store. - pub fn set_location(&mut self, location: &Path) { + pub fn set_location(&mut self, location: PathBuf) { // TODO update resolved dependencies? - self.cache = HttpCache::new(location); - self.specifier_resolver = Arc::new(SpecifierResolver::new(location)); + let cache = HttpCache::new(location); + self.cache = cache.clone(); + self.specifier_resolver = Arc::new(SpecifierResolver::new(cache)); self.dirty = true; } @@ -1785,11 +1787,12 @@ mod tests { use super::*; use import_map::ImportMap; use pretty_assertions::assert_eq; + use test_util::PathRef; use test_util::TempDir; - fn setup(temp_dir: &TempDir) -> (Documents, PathBuf) { + fn setup(temp_dir: &TempDir) -> (Documents, PathRef) { let location = temp_dir.path().join("deps"); - let documents = Documents::new(&location); + let documents = Documents::new(location.to_path_buf()); (documents, location) } @@ -1861,8 +1864,8 @@ console.log(b, "hello deno"); let (mut documents, documents_path) = setup(&temp_dir); let file_path = documents_path.join("file.ts"); let file_specifier = ModuleSpecifier::from_file_path(&file_path).unwrap(); - fs::create_dir_all(&documents_path).unwrap(); - fs::write(&file_path, "").unwrap(); + documents_path.create_dir_all(); + file_path.write(""); // open the document documents.open( diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index ecd91f459..cf7179670 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -605,11 +605,13 @@ impl Inner { let dir = DenoDir::new(None).expect("could not access DENO_DIR"); let module_registries_location = dir.registries_folder_path(); let http_client = Arc::new(HttpClient::new(None, None)); - let module_registries = - ModuleRegistry::new(&module_registries_location, http_client.clone()); + let module_registries = ModuleRegistry::new( + module_registries_location.clone(), + http_client.clone(), + ); let location = dir.deps_folder_path(); - let documents = Documents::new(&location); - let deps_http_cache = HttpCache::new(&location); + let documents = Documents::new(location.clone()); + let deps_http_cache = HttpCache::new(location); let cache_metadata = cache::CacheMetadata::new(deps_http_cache.clone()); let performance = Arc::new(Performance::default()); let ts_server = Arc::new(TsServer::new(performance.clone())); @@ -944,14 +946,14 @@ impl Inner { .clone(), )); self.module_registries = ModuleRegistry::new( - &module_registries_location, + module_registries_location.clone(), self.http_client.clone(), ); self.module_registries_location = module_registries_location; // update the cache path let location = dir.deps_folder_path(); - self.documents.set_location(&location); - self.cache_metadata.set_location(&location); + self.documents.set_location(location.clone()); + self.cache_metadata.set_location(location); self.maybe_cache_path = new_cache_path; Ok(()) } diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs index b2f9bee2c..f683fa588 100644 --- a/cli/lsp/registries.rs +++ b/cli/lsp/registries.rs @@ -34,7 +34,7 @@ use deno_runtime::permissions::PermissionsContainer; use log::error; use once_cell::sync::Lazy; use std::collections::HashMap; -use std::path::Path; +use std::path::PathBuf; use std::sync::Arc; use tower_lsp::lsp_types as lsp; @@ -427,12 +427,12 @@ impl Default for ModuleRegistry { let dir = DenoDir::new(None).unwrap(); let location = dir.registries_folder_path(); let http_client = Arc::new(HttpClient::new(None, None)); - Self::new(&location, http_client) + Self::new(location, http_client) } } impl ModuleRegistry { - pub fn new(location: &Path, http_client: Arc<HttpClient>) -> Self { + pub fn new(location: PathBuf, http_client: Arc<HttpClient>) -> Self { let http_cache = HttpCache::new(location); let mut file_fetcher = FileFetcher::new( http_cache, @@ -1247,9 +1247,9 @@ mod tests { async fn test_registry_completions_origin_match() { let _g = test_util::http_server(); let temp_dir = TempDir::new(); - let location = temp_dir.path().join("registries"); + let location = temp_dir.path().join("registries").to_path_buf(); let mut module_registry = - ModuleRegistry::new(&location, Arc::new(HttpClient::new(None, None))); + ModuleRegistry::new(location, Arc::new(HttpClient::new(None, None))); module_registry .enable("http://localhost:4545/") .await @@ -1308,9 +1308,9 @@ mod tests { async fn test_registry_completions() { let _g = test_util::http_server(); let temp_dir = TempDir::new(); - let location = temp_dir.path().join("registries"); + let location = temp_dir.path().join("registries").to_path_buf(); let mut module_registry = - ModuleRegistry::new(&location, Arc::new(HttpClient::new(None, None))); + ModuleRegistry::new(location, Arc::new(HttpClient::new(None, None))); module_registry .enable("http://localhost:4545/") .await @@ -1531,9 +1531,9 @@ mod tests { async fn test_registry_completions_key_first() { let _g = test_util::http_server(); let temp_dir = TempDir::new(); - let location = temp_dir.path().join("registries"); + let location = temp_dir.path().join("registries").to_path_buf(); let mut module_registry = - ModuleRegistry::new(&location, Arc::new(HttpClient::new(None, None))); + ModuleRegistry::new(location, Arc::new(HttpClient::new(None, None))); module_registry .enable_custom("http://localhost:4545/lsp/registries/deno-import-intellisense-key-first.json") .await @@ -1601,9 +1601,9 @@ mod tests { async fn test_registry_completions_complex() { let _g = test_util::http_server(); let temp_dir = TempDir::new(); - let location = temp_dir.path().join("registries"); + let location = temp_dir.path().join("registries").to_path_buf(); let mut module_registry = - ModuleRegistry::new(&location, Arc::new(HttpClient::new(None, None))); + ModuleRegistry::new(location, Arc::new(HttpClient::new(None, None))); module_registry .enable_custom("http://localhost:4545/lsp/registries/deno-import-intellisense-complex.json") .await @@ -1652,9 +1652,9 @@ mod tests { async fn test_check_origin_supported() { let _g = test_util::http_server(); let temp_dir = TempDir::new(); - let location = temp_dir.path().join("registries"); + let location = temp_dir.path().join("registries").to_path_buf(); let module_registry = - ModuleRegistry::new(&location, Arc::new(HttpClient::new(None, None))); + ModuleRegistry::new(location, Arc::new(HttpClient::new(None, None))); let result = module_registry.check_origin("http://localhost:4545").await; assert!(result.is_ok()); } @@ -1663,9 +1663,9 @@ mod tests { async fn test_check_origin_not_supported() { let _g = test_util::http_server(); let temp_dir = TempDir::new(); - let location = temp_dir.path().join("registries"); + let location = temp_dir.path().join("registries").to_path_buf(); let module_registry = - ModuleRegistry::new(&location, Arc::new(HttpClient::new(None, None))); + ModuleRegistry::new(location, Arc::new(HttpClient::new(None, None))); let result = module_registry.check_origin("https://example.com").await; assert!(result.is_err()); let err = result.unwrap_err().to_string(); diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 0e52f8d87..66687789b 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -3903,7 +3903,7 @@ mod tests { fixtures: &[(&str, &str, i32, LanguageId)], location: &Path, ) -> StateSnapshot { - let mut documents = Documents::new(location); + let mut documents = Documents::new(location.to_path_buf()); for (specifier, source, version, language_id) in fixtures { let specifier = resolve_url(specifier).expect("failed to create specifier"); @@ -3926,7 +3926,7 @@ mod tests { config: Value, sources: &[(&str, &str, i32, LanguageId)], ) -> (JsRuntime, Arc<StateSnapshot>, PathBuf) { - let location = temp_dir.path().join("deps"); + let location = temp_dir.path().join("deps").to_path_buf(); let state_snapshot = Arc::new(mock_state_snapshot(sources, &location)); let mut runtime = js_runtime(Default::default()); start(&mut runtime, debug).unwrap(); @@ -4406,7 +4406,7 @@ mod tests { LanguageId::TypeScript, )], ); - let cache = HttpCache::new(&location); + let cache = HttpCache::new(location); let specifier_dep = resolve_url("https://deno.land/x/example/a.ts").unwrap(); cache |