summaryrefslogtreecommitdiff
path: root/cli/lsp/cache.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-08-01 20:49:09 -0400
committerGitHub <noreply@github.com>2023-08-02 00:49:09 +0000
commit1cefa831fd74b14121494045a347024502d74e34 (patch)
treecc7791cf674e427fe4165262db416e6c537e99a3 /cli/lsp/cache.rs
parent36ae37604a0ddab4349df6eb6fafb8ae39fd20fc (diff)
feat(unstable): optional `deno_modules` directory (#19977)
Closes #15633
Diffstat (limited to 'cli/lsp/cache.rs')
-rw-r--r--cli/lsp/cache.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/cli/lsp/cache.rs b/cli/lsp/cache.rs
index e14497156..15b909672 100644
--- a/cli/lsp/cache.rs
+++ b/cli/lsp/cache.rs
@@ -8,12 +8,11 @@ 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;
pub fn calculate_fs_version(
- cache: &HttpCache,
+ cache: &Arc<dyn HttpCache>,
specifier: &ModuleSpecifier,
) -> Option<String> {
match specifier.scheme() {
@@ -40,10 +39,13 @@ pub fn calculate_fs_version_at_path(path: &Path) -> Option<String> {
}
fn calculate_fs_version_in_cache(
- cache: &HttpCache,
+ cache: &Arc<dyn HttpCache>,
specifier: &ModuleSpecifier,
) -> Option<String> {
- match cache.get_modified_time(specifier) {
+ let Ok(cache_key) = cache.cache_item_key(specifier) else {
+ return Some("1".to_string());
+ };
+ match cache.read_modified_time(&cache_key) {
Ok(Some(modified)) => {
match modified.duration_since(SystemTime::UNIX_EPOCH) {
Ok(n) => Some(n.as_millis().to_string()),
@@ -80,12 +82,12 @@ struct Metadata {
#[derive(Debug, Clone)]
pub struct CacheMetadata {
- cache: HttpCache,
+ cache: Arc<dyn HttpCache>,
metadata: Arc<Mutex<HashMap<ModuleSpecifier, Metadata>>>,
}
impl CacheMetadata {
- pub fn new(cache: HttpCache) -> Self {
+ pub fn new(cache: Arc<dyn HttpCache>) -> Self {
Self {
cache,
metadata: Default::default(),
@@ -120,8 +122,8 @@ impl CacheMetadata {
) {
return None;
}
- let specifier_metadata =
- self.cache.get(specifier).ok()?.read_metadata().ok()??;
+ let cache_key = self.cache.cache_item_key(specifier).ok()?;
+ let specifier_metadata = self.cache.read_metadata(&cache_key).ok()??;
let values = Arc::new(parse_metadata(&specifier_metadata.headers));
let version = calculate_fs_version_in_cache(&self.cache, specifier);
let mut metadata_map = self.metadata.lock();
@@ -130,8 +132,8 @@ impl CacheMetadata {
Some(metadata)
}
- pub fn set_location(&mut self, location: PathBuf) {
- self.cache = HttpCache::new(location);
+ pub fn set_cache(&mut self, cache: Arc<dyn HttpCache>) {
+ self.cache = cache;
self.metadata.lock().clear();
}
}