summaryrefslogtreecommitdiff
path: root/cli/lsp/documents.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/documents.rs')
-rw-r--r--cli/lsp/documents.rs32
1 files changed, 18 insertions, 14 deletions
diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs
index 2d3bed57a..c39c81a41 100644
--- a/cli/lsp/documents.rs
+++ b/cli/lsp/documents.rs
@@ -658,12 +658,12 @@ fn recurse_dependents(
#[derive(Debug)]
struct SpecifierResolver {
- cache: HttpCache,
+ cache: Arc<dyn HttpCache>,
redirects: Mutex<HashMap<ModuleSpecifier, ModuleSpecifier>>,
}
impl SpecifierResolver {
- pub fn new(cache: HttpCache) -> Self {
+ pub fn new(cache: Arc<dyn HttpCache>) -> Self {
Self {
cache,
redirects: Mutex::new(HashMap::new()),
@@ -699,11 +699,12 @@ impl SpecifierResolver {
redirect_limit: usize,
) -> Option<ModuleSpecifier> {
if redirect_limit > 0 {
+ let cache_key = self.cache.cache_item_key(specifier).ok()?;
let headers = self
.cache
- .get(specifier)
+ .read_metadata(&cache_key)
.ok()
- .and_then(|i| i.read_metadata().ok()?)
+ .flatten()
.map(|m| m.headers)?;
if let Some(location) = headers.get("location") {
let redirect =
@@ -727,7 +728,7 @@ struct FileSystemDocuments {
impl FileSystemDocuments {
pub fn get(
&mut self,
- cache: &HttpCache,
+ cache: &Arc<dyn HttpCache>,
resolver: &dyn deno_graph::source::Resolver,
specifier: &ModuleSpecifier,
) -> Option<Document> {
@@ -749,7 +750,7 @@ impl FileSystemDocuments {
/// returning the document.
fn refresh_document(
&mut self,
- cache: &HttpCache,
+ cache: &Arc<dyn HttpCache>,
resolver: &dyn deno_graph::source::Resolver,
specifier: &ModuleSpecifier,
) -> Option<Document> {
@@ -778,9 +779,9 @@ impl FileSystemDocuments {
)
} else {
let fs_version = calculate_fs_version(cache, specifier)?;
- let cache_item = cache.get(specifier).ok()?;
- let bytes = cache_item.read_to_bytes().ok()??;
- let specifier_metadata = cache_item.read_metadata().ok()??;
+ 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 maybe_content_type = specifier_metadata.headers.get("content-type");
let (_, maybe_charset) = map_content_type(specifier, maybe_content_type);
let maybe_headers = Some(specifier_metadata.headers);
@@ -823,7 +824,7 @@ pub enum DocumentsFilter {
#[derive(Debug, Clone)]
pub struct Documents {
/// The DENO_DIR that the documents looks for non-file based modules.
- cache: HttpCache,
+ cache: Arc<dyn HttpCache>,
/// A flag that indicates that stated data is potentially invalid and needs to
/// be recalculated before being considered valid.
dirty: bool,
@@ -853,7 +854,7 @@ pub struct Documents {
}
impl Documents {
- pub fn new(cache: HttpCache) -> Self {
+ pub fn new(cache: Arc<dyn HttpCache>) -> Self {
Self {
cache: cache.clone(),
dirty: true,
@@ -1139,9 +1140,8 @@ impl Documents {
}
/// Update the location of the on disk cache for the document store.
- pub fn set_location(&mut self, location: PathBuf) {
+ pub fn set_cache(&mut self, cache: Arc<dyn HttpCache>) {
// TODO update resolved dependencies?
- let cache = HttpCache::new(location);
self.cache = cache.clone();
self.specifier_resolver = Arc::new(SpecifierResolver::new(cache));
self.dirty = true;
@@ -1177,6 +1177,7 @@ impl Documents {
document_preload_limit: usize,
maybe_import_map: Option<&import_map::ImportMap>,
maybe_jsx_config: Option<&JsxImportSourceConfig>,
+ maybe_deno_modules_dir: Option<bool>,
maybe_package_json_deps: Option<&PackageJsonDeps>,
) -> u64 {
let mut hasher = FastInsecureHasher::default();
@@ -1191,6 +1192,7 @@ impl Documents {
hasher.write_str(&import_map.to_json());
hasher.write_str(import_map.base_url().as_str());
}
+ hasher.write_hashable(maybe_deno_modules_dir);
hasher.write_hashable(maybe_jsx_config);
if let Some(package_json_deps) = &maybe_package_json_deps {
// We need to ensure the hashing is deterministic so explicitly type
@@ -1225,6 +1227,7 @@ impl Documents {
options.document_preload_limit,
options.maybe_import_map.as_deref(),
maybe_jsx_config.as_ref(),
+ options.maybe_config_file.and_then(|c| c.deno_modules_dir()),
maybe_package_json_deps.as_ref(),
);
let deps_provider =
@@ -1840,6 +1843,7 @@ fn sort_and_remove_non_leaf_dirs(mut dirs: Vec<PathBuf>) -> Vec<PathBuf> {
#[cfg(test)]
mod tests {
+ use crate::cache::GlobalHttpCache;
use crate::npm::NpmResolution;
use super::*;
@@ -1850,7 +1854,7 @@ mod tests {
fn setup(temp_dir: &TempDir) -> (Documents, PathRef) {
let location = temp_dir.path().join("deps");
- let cache = HttpCache::new(location.to_path_buf());
+ let cache = Arc::new(GlobalHttpCache::new(location.to_path_buf()));
let documents = Documents::new(cache);
(documents, location)
}