diff options
Diffstat (limited to 'cli/lsp')
-rw-r--r-- | cli/lsp/cache.rs | 10 | ||||
-rw-r--r-- | cli/lsp/diagnostics.rs | 13 | ||||
-rw-r--r-- | cli/lsp/documents.rs | 32 | ||||
-rw-r--r-- | cli/lsp/language_server.rs | 3 | ||||
-rw-r--r-- | cli/lsp/registries.rs | 3 |
5 files changed, 37 insertions, 24 deletions
diff --git a/cli/lsp/cache.rs b/cli/lsp/cache.rs index df88254ee..9ce47a11b 100644 --- a/cli/lsp/cache.rs +++ b/cli/lsp/cache.rs @@ -69,7 +69,10 @@ impl CacheMetadata { &self, specifier: &ModuleSpecifier, ) -> Option<Arc<HashMap<MetadataKey, String>>> { - if matches!(specifier.scheme(), "file" | "npm" | "node") { + if matches!( + specifier.scheme(), + "file" | "npm" | "node" | "data" | "blob" + ) { return None; } let version = self @@ -85,7 +88,10 @@ impl CacheMetadata { } fn refresh(&self, specifier: &ModuleSpecifier) -> Option<Metadata> { - if matches!(specifier.scheme(), "file" | "npm" | "node") { + if matches!( + specifier.scheme(), + "file" | "npm" | "node" | "data" | "blob" + ) { return None; } let cache_filename = self.cache.get_cache_filename(specifier)?; diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 9acb9cef5..415fe142d 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -721,10 +721,6 @@ pub enum DenoDiagnostic { NoAssertType, /// A remote module was not found in the cache. NoCache(ModuleSpecifier), - /// A blob module was not found in the cache. - NoCacheBlob, - /// A data module was not found in the cache. - NoCacheData(ModuleSpecifier), /// A remote npm package reference was not found in the cache. NoCacheNpm(NpmPackageReqReference, ModuleSpecifier), /// A local module was not found on the local file system. @@ -749,8 +745,6 @@ impl DenoDiagnostic { Self::InvalidAssertType(_) => "invalid-assert-type", Self::NoAssertType => "no-assert-type", Self::NoCache(_) => "no-cache", - Self::NoCacheBlob => "no-cache-blob", - Self::NoCacheData(_) => "no-cache-data", Self::NoCacheNpm(_, _) => "no-cache-npm", Self::NoLocal(_) => "no-local", Self::Redirect { .. } => "redirect", @@ -828,7 +822,7 @@ impl DenoDiagnostic { }), ..Default::default() }, - "no-cache" | "no-cache-data" | "no-cache-npm" => { + "no-cache" | "no-cache-npm" => { let data = diagnostic .data .clone() @@ -920,7 +914,6 @@ impl DenoDiagnostic { "import-map-remap" | "no-cache" | "no-cache-npm" - | "no-cache-data" | "no-assert-type" | "redirect" | "import-node-prefix-missing" @@ -939,8 +932,6 @@ impl DenoDiagnostic { Self::InvalidAssertType(assert_type) => (lsp::DiagnosticSeverity::ERROR, format!("The module is a JSON module and expected an assertion type of \"json\". Instead got \"{assert_type}\"."), None), Self::NoAssertType => (lsp::DiagnosticSeverity::ERROR, "The module is a JSON module and not being imported with an import assertion. Consider adding `assert { type: \"json\" }` to the import statement.".to_string(), None), Self::NoCache(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Uncached or missing remote URL: \"{specifier}\"."), Some(json!({ "specifier": specifier }))), - Self::NoCacheBlob => (lsp::DiagnosticSeverity::ERROR, "Uncached blob URL.".to_string(), None), - Self::NoCacheData(specifier) => (lsp::DiagnosticSeverity::ERROR, "Uncached data URL.".to_string(), Some(json!({ "specifier": specifier }))), Self::NoCacheNpm(pkg_ref, specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Uncached or missing npm package: \"{}\".", pkg_ref.req), Some(json!({ "specifier": specifier }))), Self::NoLocal(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Unable to load a local module: \"{specifier}\".\n Please check the file path."), None), Self::Redirect { from, to} => (lsp::DiagnosticSeverity::INFORMATION, format!("The import of \"{from}\" was redirected to \"{to}\"."), Some(json!({ "specifier": from, "redirect": to }))), @@ -1043,8 +1034,6 @@ fn diagnose_resolution( // about that. let deno_diagnostic = match specifier.scheme() { "file" => DenoDiagnostic::NoLocal(specifier.clone()), - "data" => DenoDiagnostic::NoCacheData(specifier.clone()), - "blob" => DenoDiagnostic::NoCacheBlob, _ => DenoDiagnostic::NoCache(specifier.clone()), }; diagnostics.push(deno_diagnostic); diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 43e192517..f18284db7 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -13,6 +13,7 @@ use crate::cache::CachedUrlMetadata; use crate::cache::FastInsecureHasher; use crate::cache::HttpCache; use crate::file_fetcher::get_source_from_bytes; +use crate::file_fetcher::get_source_from_data_url; use crate::file_fetcher::map_content_type; use crate::file_fetcher::SUPPORTED_SCHEMES; use crate::lsp::logging::lsp_warn; @@ -728,8 +729,12 @@ impl FileSystemDocuments { resolver: &dyn deno_graph::source::Resolver, specifier: &ModuleSpecifier, ) -> Option<Document> { - let fs_version = get_document_path(cache, specifier) - .and_then(|path| calculate_fs_version(&path)); + let fs_version = if specifier.scheme() == "data" { + Some("1".to_string()) + } else { + get_document_path(cache, specifier) + .and_then(|path| calculate_fs_version(&path)) + }; let file_system_doc = self.docs.get(specifier); if file_system_doc.map(|d| d.fs_version().to_string()) != fs_version { // attempt to update the file on the file system @@ -747,10 +752,10 @@ impl FileSystemDocuments { resolver: &dyn deno_graph::source::Resolver, specifier: &ModuleSpecifier, ) -> Option<Document> { - let path = get_document_path(cache, specifier)?; - let fs_version = calculate_fs_version(&path)?; - let bytes = fs::read(path).ok()?; let doc = if specifier.scheme() == "file" { + let path = get_document_path(cache, specifier)?; + let fs_version = calculate_fs_version(&path)?; + let bytes = fs::read(path).ok()?; let maybe_charset = Some(text_encoding::detect_charset(&bytes).to_string()); let content = get_source_from_bytes(bytes, maybe_charset).ok()?; @@ -761,7 +766,19 @@ impl FileSystemDocuments { SourceTextInfo::from_string(content), resolver, ) + } else if specifier.scheme() == "data" { + let (source, _) = get_source_from_data_url(specifier).ok()?; + Document::new( + specifier.clone(), + "1".to_string(), + None, + SourceTextInfo::from_string(source), + resolver, + ) } else { + let path = get_document_path(cache, specifier)?; + let fs_version = calculate_fs_version(&path)?; + let bytes = fs::read(path).ok()?; let cache_filename = cache.get_cache_filename(specifier)?; let specifier_metadata = CachedUrlMetadata::read(&cache_filename).ok()?; let maybe_content_type = specifier_metadata.headers.get("content-type"); @@ -787,7 +804,7 @@ fn get_document_path( specifier: &ModuleSpecifier, ) -> Option<PathBuf> { match specifier.scheme() { - "npm" | "node" => None, + "npm" | "node" | "data" | "blob" => None, "file" => specifier_to_file_path(specifier).ok(), _ => cache.get_cache_filename(specifier), } @@ -970,6 +987,9 @@ impl Documents { if self.open_docs.contains_key(&specifier) { return true; } + if specifier.scheme() == "data" { + return true; + } if let Some(path) = get_document_path(&self.cache, &specifier) { return path.is_file(); } diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 9abdade27..95bdf8724 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -20,7 +20,6 @@ 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; use serde_json::from_value; @@ -1053,7 +1052,7 @@ impl Inner { cache_setting, true, self.http_client.clone(), - BlobStore::default(), + Default::default(), None, ); file_fetcher.set_download_log_level(super::logging::lsp_log_level()); diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs index e4501c903..9454f77f5 100644 --- a/cli/lsp/registries.rs +++ b/cli/lsp/registries.rs @@ -29,7 +29,6 @@ use deno_core::url::Position; use deno_core::url::Url; use deno_core::ModuleSpecifier; use deno_graph::Dependency; -use deno_runtime::deno_web::BlobStore; use deno_runtime::permissions::PermissionsContainer; use log::error; use once_cell::sync::Lazy; @@ -439,7 +438,7 @@ impl ModuleRegistry { CacheSetting::RespectHeaders, true, http_client, - BlobStore::default(), + Default::default(), None, ); file_fetcher.set_download_log_level(super::logging::lsp_log_level()); |