summaryrefslogtreecommitdiff
path: root/cli/lsp/documents.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-02-15 14:49:35 -0500
committerGitHub <noreply@github.com>2024-02-15 14:49:35 -0500
commit4f80d83774ce5402a2b10503529fe422c998b841 (patch)
treed99c2e0bdc13e36727c62800130ebcab3b85dae7 /cli/lsp/documents.rs
parent052b7d8bbdb43eedcdaae1a3094a5f2c70bba279 (diff)
feat(unstable): single checksum per JSR package in the lockfile (#22421)
This changes the lockfile to not store JSR specifiers in the "remote" section. Instead a single JSR integrity is stored per package in the lockfile, which is a hash of the version's `x.x.x_meta.json` file, which contains hashes for every file in the package. The hashes in this file are then compared against when loading. Additionally, when using `{ "vendor": true }` in a deno.json, the files can be modified without causing lockfile errors—the checksum is only checked when copying into the vendor folder and not afterwards (eventually we should add this behaviour for non-jsr specifiers as well). As part of this change, the `vendor` folder creation is not always automatic in the LSP and running an explicit cache command is necessary. The code required to track checksums in the LSP would have been too complex for this PR, so that all goes through deno_graph now. The vendoring is still automatic when running from the CLI.
Diffstat (limited to 'cli/lsp/documents.rs')
-rw-r--r--cli/lsp/documents.rs25
1 files changed, 10 insertions, 15 deletions
diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs
index c58a392d5..125307757 100644
--- a/cli/lsp/documents.rs
+++ b/cli/lsp/documents.rs
@@ -2,6 +2,7 @@
use super::cache::calculate_fs_version;
use super::cache::calculate_fs_version_at_path;
+use super::cache::LSP_DISALLOW_GLOBAL_TO_LOCAL_COPY;
use super::jsr_resolver::JsrResolver;
use super::language_server::StateNpmSnapshot;
use super::text::LineIndex;
@@ -736,12 +737,7 @@ impl RedirectResolver {
) -> Option<ModuleSpecifier> {
if redirect_limit > 0 {
let cache_key = self.cache.cache_item_key(specifier).ok()?;
- let headers = self
- .cache
- .read_metadata(&cache_key)
- .ok()
- .flatten()
- .map(|m| m.headers)?;
+ let headers = self.cache.read_headers(&cache_key).ok().flatten()?;
if let Some(location) = headers.get("location") {
let redirect =
deno_core::resolve_import(location, specifier.as_str()).ok()?;
@@ -822,12 +818,14 @@ impl FileSystemDocuments {
} else {
let fs_version = calculate_fs_version(cache, specifier)?;
let cache_key = cache.cache_item_key(specifier).ok()?;
- let bytes = cache.read_file_bytes(&cache_key).ok()??;
- let specifier_metadata = cache.read_metadata(&cache_key).ok()??;
+ let bytes = cache
+ .read_file_bytes(&cache_key, None, LSP_DISALLOW_GLOBAL_TO_LOCAL_COPY)
+ .ok()??;
+ let specifier_headers = cache.read_headers(&cache_key).ok()??;
let (_, maybe_charset) =
deno_graph::source::resolve_media_type_and_charset_from_headers(
specifier,
- Some(&specifier_metadata.headers),
+ Some(&specifier_headers),
);
let content = deno_graph::source::decode_owned_source(
specifier,
@@ -835,7 +833,7 @@ impl FileSystemDocuments {
maybe_charset,
)
.ok()?;
- let maybe_headers = Some(specifier_metadata.headers);
+ let maybe_headers = Some(specifier_headers);
Document::new(
specifier.clone(),
fs_version,
@@ -1826,8 +1824,7 @@ impl<'a> deno_graph::source::Loader for OpenDocumentsGraphLoader<'a> {
fn load(
&mut self,
specifier: &ModuleSpecifier,
- is_dynamic: bool,
- cache_setting: deno_graph::source::CacheSetting,
+ options: deno_graph::source::LoadOptions,
) -> deno_graph::source::LoadFuture {
let specifier = if self.unstable_sloppy_imports {
self
@@ -1839,9 +1836,7 @@ impl<'a> deno_graph::source::Loader for OpenDocumentsGraphLoader<'a> {
match self.load_from_docs(&specifier) {
Some(fut) => fut,
- None => self
- .inner_loader
- .load(&specifier, is_dynamic, cache_setting),
+ None => self.inner_loader.load(&specifier, options),
}
}