summaryrefslogtreecommitdiff
path: root/cli/lsp/sources.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/sources.rs')
-rw-r--r--cli/lsp/sources.rs47
1 files changed, 47 insertions, 0 deletions
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<HashMap<String, analysis::Dependency>>,
length_utf16: usize,
line_index: LineIndex,
+ maybe_navigation_tree: Option<tsc::NavigationTree>,
maybe_types: Option<analysis::ResolvedDependency>,
maybe_warning: Option<String>,
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<tsc::NavigationTree> {
+ 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<ModuleSpecifier> {
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<tsc::NavigationTree> {
+ 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<PathBuf> {
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)]