summaryrefslogtreecommitdiff
path: root/cli/lsp/documents.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2022-02-02 13:04:26 +1100
committerGitHub <noreply@github.com>2022-02-02 13:04:26 +1100
commit26f5c223df26962f19ccc957d0507facc09c55c5 (patch)
tree2d12e824acefba3e35d8a117693a7b4a7f210cf3 /cli/lsp/documents.rs
parent8176a4d1663529fb8aeebf7734c4994fa1d583f4 (diff)
fix(lsp): properly display x-deno-warning with redirects (#13554)
Fixes: #13472
Diffstat (limited to 'cli/lsp/documents.rs')
-rw-r--r--cli/lsp/documents.rs42
1 files changed, 11 insertions, 31 deletions
diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs
index 19753389d..c9157a86a 100644
--- a/cli/lsp/documents.rs
+++ b/cli/lsp/documents.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+use super::cache::calculate_fs_version;
use super::text::LineIndex;
use super::tsc;
use super::tsc::AssetDocument;
@@ -226,7 +227,6 @@ struct DocumentInner {
maybe_module:
Option<Result<deno_graph::Module, deno_graph::ModuleGraphError>>,
maybe_navigation_tree: Option<Arc<tsc::NavigationTree>>,
- maybe_warning: Option<String>,
specifier: ModuleSpecifier,
text_info: SourceTextInfo,
}
@@ -242,9 +242,6 @@ impl Document {
content: Arc<String>,
maybe_resolver: Option<&dyn deno_graph::source::Resolver>,
) -> Self {
- let maybe_warning = maybe_headers
- .map(|h| h.get("x-deno-warning").cloned())
- .flatten();
let parser = SourceParser::default();
// we only ever do `Document::new` on on disk resources that are supposed to
// be diagnosable, unlike `Document::open`, so it is safe to unconditionally
@@ -272,7 +269,6 @@ impl Document {
maybe_lsp_version: None,
maybe_module,
maybe_navigation_tree: None,
- maybe_warning,
text_info,
specifier,
}))
@@ -314,7 +310,6 @@ impl Document {
maybe_lsp_version: Some(version),
maybe_module,
maybe_navigation_tree: None,
- maybe_warning: None,
text_info: source,
specifier,
}))
@@ -496,10 +491,6 @@ impl Document {
self.0.maybe_navigation_tree.clone()
}
- pub fn maybe_warning(&self) -> Option<String> {
- self.0.maybe_warning.clone()
- }
-
pub fn dependencies(&self) -> Vec<(String, deno_graph::Dependency)> {
self
.0
@@ -692,9 +683,11 @@ impl FileSystemDocuments {
)
} else {
let cache_filename = cache.get_cache_filename(specifier)?;
- let metadata = http_cache::Metadata::read(&cache_filename).ok()?;
- let maybe_content_type = metadata.headers.get("content-type").cloned();
- let maybe_headers = Some(&metadata.headers);
+ let specifier_metadata =
+ http_cache::Metadata::read(&cache_filename).ok()?;
+ let maybe_content_type =
+ specifier_metadata.headers.get("content-type").cloned();
+ let maybe_headers = Some(&specifier_metadata.headers);
let (_, maybe_charset) = map_content_type(specifier, maybe_content_type);
let content = Arc::new(get_source_from_bytes(bytes, maybe_charset).ok()?);
Document::new(
@@ -711,19 +704,6 @@ impl FileSystemDocuments {
}
}
-fn calculate_fs_version(path: &Path) -> Option<String> {
- let metadata = fs::metadata(path).ok()?;
- if let Ok(modified) = metadata.modified() {
- if let Ok(n) = modified.duration_since(SystemTime::UNIX_EPOCH) {
- Some(n.as_millis().to_string())
- } else {
- Some("1".to_string())
- }
- } else {
- Some("1".to_string())
- }
-}
-
fn get_document_path(
cache: &HttpCache,
specifier: &ModuleSpecifier,
@@ -906,8 +886,8 @@ impl Documents {
}
/// Return a document for the specifier.
- pub fn get(&self, specifier: &ModuleSpecifier) -> Option<Document> {
- let specifier = self.specifier_resolver.resolve(specifier)?;
+ pub fn get(&self, original_specifier: &ModuleSpecifier) -> Option<Document> {
+ let specifier = self.specifier_resolver.resolve(original_specifier)?;
if let Some(document) = self.open_docs.get(&specifier) {
Some(document.clone())
} else {
@@ -1013,10 +993,10 @@ 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_location(&mut self, location: &Path) {
// TODO update resolved dependencies?
- self.cache = HttpCache::new(&location);
- self.specifier_resolver = Arc::new(SpecifierResolver::new(&location));
+ self.cache = HttpCache::new(location);
+ self.specifier_resolver = Arc::new(SpecifierResolver::new(location));
self.dirty = true;
}