diff options
Diffstat (limited to 'cli/lsp')
| -rw-r--r-- | cli/lsp/language_server.rs | 33 | ||||
| -rw-r--r-- | cli/lsp/registries.rs | 32 |
2 files changed, 34 insertions, 31 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index d49a2559c..83657a8ef 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -12,6 +12,8 @@ use deno_core::ModuleSpecifier; use deno_runtime::deno_node; use deno_runtime::deno_node::NodeResolver; use deno_runtime::deno_node::PackageJson; +use deno_runtime::deno_tls::rustls::RootCertStore; +use deno_runtime::deno_tls::RootCertStoreProvider; use deno_runtime::deno_web::BlobStore; use import_map::ImportMap; use log::error; @@ -93,6 +95,14 @@ use crate::util::path::specifier_to_file_path; use crate::util::progress_bar::ProgressBar; use crate::util::progress_bar::ProgressBarStyle; +struct LspRootCertStoreProvider(RootCertStore); + +impl RootCertStoreProvider for LspRootCertStoreProvider { + fn get_or_try_init(&self) -> Result<&RootCertStore, AnyError> { + Ok(&self.0) + } +} + #[derive(Debug, Clone)] pub struct LanguageServer(Arc<tokio::sync::RwLock<Inner>>); @@ -124,7 +134,7 @@ pub struct Inner { /// The collection of documents that the server is currently handling, either /// on disk or "open" within the client. pub documents: Documents, - http_client: HttpClient, + http_client: Arc<HttpClient>, /// Handles module registries, which allow discovery of modules module_registries: ModuleRegistry, /// The path to the module registries cache @@ -420,7 +430,7 @@ impl LanguageServer { fn create_lsp_structs( dir: &DenoDir, - http_client: HttpClient, + http_client: Arc<HttpClient>, ) -> ( Arc<CliNpmRegistryApi>, Arc<NpmCache>, @@ -469,10 +479,9 @@ impl Inner { let dir = DenoDir::new(maybe_custom_root).expect("could not access DENO_DIR"); let module_registries_location = dir.registries_folder_path(); - let http_client = HttpClient::new(None, None).unwrap(); + let http_client = Arc::new(HttpClient::new(None, None)); let module_registries = - ModuleRegistry::new(&module_registries_location, http_client.clone()) - .unwrap(); + ModuleRegistry::new(&module_registries_location, http_client.clone()); let location = dir.deps_folder_path(); let documents = Documents::new(&location, client.kind()); let deps_http_cache = HttpCache::new(&location); @@ -775,20 +784,22 @@ impl Inner { .root_uri .as_ref() .and_then(|uri| specifier_to_file_path(uri).ok()); - let root_cert_store = Some(get_root_cert_store( + let root_cert_store = get_root_cert_store( maybe_root_path, workspace_settings.certificate_stores, workspace_settings.tls_certificate.map(CaData::File), - )?); + )?; + let root_cert_store_provider = + Arc::new(LspRootCertStoreProvider(root_cert_store)); let module_registries_location = dir.registries_folder_path(); - self.http_client = HttpClient::new( - root_cert_store, + self.http_client = Arc::new(HttpClient::new( + Some(root_cert_store_provider), workspace_settings.unsafely_ignore_certificate_errors, - )?; + )); self.module_registries = ModuleRegistry::new( &module_registries_location, self.http_client.clone(), - )?; + ); self.module_registries_location = module_registries_location; ( self.npm_api, diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs index f46aba44f..b2f9bee2c 100644 --- a/cli/lsp/registries.rs +++ b/cli/lsp/registries.rs @@ -35,6 +35,7 @@ use log::error; use once_cell::sync::Lazy; use std::collections::HashMap; use std::path::Path; +use std::sync::Arc; use tower_lsp::lsp_types as lsp; const CONFIG_PATH: &str = "/.well-known/deno-import-intellisense.json"; @@ -425,16 +426,13 @@ impl Default for ModuleRegistry { // custom root. let dir = DenoDir::new(None).unwrap(); let location = dir.registries_folder_path(); - let http_client = HttpClient::new(None, None).unwrap(); - Self::new(&location, http_client).unwrap() + let http_client = Arc::new(HttpClient::new(None, None)); + Self::new(&location, http_client) } } impl ModuleRegistry { - pub fn new( - location: &Path, - http_client: HttpClient, - ) -> Result<Self, AnyError> { + pub fn new(location: &Path, http_client: Arc<HttpClient>) -> Self { let http_cache = HttpCache::new(location); let mut file_fetcher = FileFetcher::new( http_cache, @@ -446,10 +444,10 @@ impl ModuleRegistry { ); file_fetcher.set_download_log_level(super::logging::lsp_log_level()); - Ok(Self { + Self { origins: HashMap::new(), file_fetcher, - }) + } } fn complete_literal( @@ -1251,8 +1249,7 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = - ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) - .unwrap(); + ModuleRegistry::new(&location, Arc::new(HttpClient::new(None, None))); module_registry .enable("http://localhost:4545/") .await @@ -1313,8 +1310,7 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = - ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) - .unwrap(); + ModuleRegistry::new(&location, Arc::new(HttpClient::new(None, None))); module_registry .enable("http://localhost:4545/") .await @@ -1537,8 +1533,7 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = - ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) - .unwrap(); + 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 @@ -1608,8 +1603,7 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = - ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) - .unwrap(); + ModuleRegistry::new(&location, Arc::new(HttpClient::new(None, None))); module_registry .enable_custom("http://localhost:4545/lsp/registries/deno-import-intellisense-complex.json") .await @@ -1660,8 +1654,7 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let module_registry = - ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) - .unwrap(); + ModuleRegistry::new(&location, Arc::new(HttpClient::new(None, None))); let result = module_registry.check_origin("http://localhost:4545").await; assert!(result.is_ok()); } @@ -1672,8 +1665,7 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let module_registry = - ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) - .unwrap(); + 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(); |
