From 480894e5c8f9532a4c42477cdf5c058cb8e9e1e3 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 2 Aug 2023 16:57:25 -0400 Subject: feat(unstable/lsp): support navigating to deno_modules folder (#20030) Closes #20015 Closes https://github.com/denoland/vscode_deno/issues/850 (only for deno_modules, but I don't think this will be possible for the global cache) --- cli/lsp/language_server.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'cli/lsp/language_server.rs') diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 4c3ee1013..06fefcaeb 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -88,7 +88,7 @@ use crate::cache::DenoDir; use crate::cache::FastInsecureHasher; use crate::cache::GlobalHttpCache; use crate::cache::HttpCache; -use crate::cache::LocalHttpCache; +use crate::cache::LocalLspHttpCache; use crate::factory::CliFactory; use crate::file_fetcher::FileFetcher; use crate::graph_util; @@ -204,7 +204,7 @@ pub struct Inner { /// An abstraction that handles interactions with TypeScript. pub ts_server: Arc, /// A map of specifiers and URLs used to translate over the LSP. - pub url_map: Arc, + pub url_map: urls::LspUrlMap, } impl LanguageServer { @@ -905,16 +905,18 @@ impl Inner { self.module_registries_location = module_registries_location; // update the cache path let global_cache = Arc::new(GlobalHttpCache::new(dir.deps_folder_path())); - let cache: Arc = - match self.config.maybe_deno_modules_dir_path() { - Some(local_path) => { - Arc::new(LocalHttpCache::new(local_path, global_cache)) - } - None => global_cache, - }; + let maybe_local_cache = + self.config.maybe_deno_modules_dir_path().map(|local_path| { + Arc::new(LocalLspHttpCache::new(local_path, global_cache.clone())) + }); + let cache: Arc = maybe_local_cache + .clone() + .map(|c| c as Arc) + .unwrap_or(global_cache); self.deps_http_cache = cache.clone(); self.documents.set_cache(cache.clone()); self.cache_metadata.set_cache(cache); + self.url_map.set_cache(maybe_local_cache); self.maybe_global_cache_path = new_cache_path; Ok(()) } @@ -2946,6 +2948,7 @@ impl Inner { snapshot: self.snapshot(), config: self.config.snapshot(), lint_options: self.lint_options.clone(), + url_map: self.url_map.clone(), }; if let Err(err) = self.diagnostics_server.update(snapshot) { error!("Cannot update diagnostics: {}", err); -- cgit v1.2.3