From e8be116ab6d06bed764ad9b6cb253d8de36ae73d Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Sat, 5 Jun 2021 07:31:44 +1000 Subject: fix(lsp): refactor, fix issues and add benchmark for code lens (#10841) --- cli/lsp/sources.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'cli/lsp/sources.rs') diff --git a/cli/lsp/sources.rs b/cli/lsp/sources.rs index c5586a440..74e1a6a60 100644 --- a/cli/lsp/sources.rs +++ b/cli/lsp/sources.rs @@ -2,6 +2,7 @@ use super::analysis; use super::text::LineIndex; +use super::tsc; use crate::file_fetcher::get_source_from_bytes; use crate::file_fetcher::map_content_type; @@ -15,6 +16,7 @@ use crate::program_state::ProgramState; use crate::specifier_handler::FetchHandler; use crate::text_encoding; +use deno_core::error::anyhow; use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::ModuleSpecifier; @@ -26,6 +28,7 @@ use std::path::PathBuf; use std::sync::Arc; use std::sync::Mutex; use std::time::SystemTime; +use tsc::NavigationTree; pub async fn cache( specifier: &ModuleSpecifier, @@ -104,6 +107,7 @@ struct Metadata { dependencies: Option>, length_utf16: usize, line_index: LineIndex, + maybe_navigation_tree: Option, maybe_types: Option, maybe_warning: Option, media_type: MediaType, @@ -139,6 +143,7 @@ impl Metadata { dependencies, length_utf16: source.encode_utf16().count(), line_index, + maybe_navigation_tree: None, maybe_types, maybe_warning, media_type: media_type.to_owned(), @@ -197,6 +202,13 @@ impl Sources { self.0.lock().unwrap().get_media_type(specifier) } + pub fn get_navigation_tree( + &self, + specifier: &ModuleSpecifier, + ) -> Option { + self.0.lock().unwrap().get_navigation_tree(specifier) + } + pub fn get_script_version( &self, specifier: &ModuleSpecifier, @@ -223,6 +235,18 @@ impl Sources { pub fn specifiers(&self) -> Vec { self.0.lock().unwrap().metadata.keys().cloned().collect() } + + pub fn set_navigation_tree( + &self, + specifier: &ModuleSpecifier, + navigation_tree: tsc::NavigationTree, + ) -> Result<(), AnyError> { + self + .0 + .lock() + .unwrap() + .set_navigation_tree(specifier, navigation_tree) + } } impl Inner { @@ -343,6 +367,16 @@ impl Inner { Some(metadata) } + fn get_navigation_tree( + &mut self, + specifier: &ModuleSpecifier, + ) -> Option { + let specifier = + resolve_specifier(specifier, &mut self.redirects, &self.http_cache)?; + let metadata = self.get_metadata(&specifier)?; + metadata.maybe_navigation_tree + } + fn get_path(&mut self, specifier: &ModuleSpecifier) -> Option { if specifier.scheme() == "file" { specifier.to_file_path().ok() @@ -461,6 +495,19 @@ impl Inner { } } } + + fn set_navigation_tree( + &mut self, + specifier: &ModuleSpecifier, + navigation_tree: NavigationTree, + ) -> Result<(), AnyError> { + let mut metadata = self + .metadata + .get_mut(specifier) + .ok_or_else(|| anyhow!("Specifier not found {}"))?; + metadata.maybe_navigation_tree = Some(navigation_tree); + Ok(()) + } } #[cfg(test)] -- cgit v1.2.3