summaryrefslogtreecommitdiff
path: root/cli/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/diagnostics.rs')
-rw-r--r--cli/diagnostics.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/cli/diagnostics.rs b/cli/diagnostics.rs
index 0a674a2c4..f6f68e1d0 100644
--- a/cli/diagnostics.rs
+++ b/cli/diagnostics.rs
@@ -25,13 +25,36 @@ pub trait SourceTextStore {
pub struct SourceTextParsedSourceStore<'a>(pub LazyGraphSourceParser<'a>);
+impl<'a> SourceTextParsedSourceStore<'a> {
+ pub fn get_source_text_from_store(
+ &self,
+ specifier: &ModuleSpecifier,
+ ) -> Option<Cow<'_, SourceTextInfo>> {
+ let parsed_source = self.0.get_or_parse_source(specifier).ok()??;
+ Some(Cow::Owned(parsed_source.text_info().clone()))
+ }
+}
+
impl SourceTextStore for SourceTextParsedSourceStore<'_> {
fn get_source_text<'a>(
&'a self,
specifier: &ModuleSpecifier,
) -> Option<Cow<'a, SourceTextInfo>> {
- let parsed_source = self.0.get_or_parse_source(specifier).ok()??;
- Some(Cow::Owned(parsed_source.text_info().clone()))
+ match self.get_source_text_from_store(specifier) {
+ Some(text_info) => Some(text_info),
+ None => {
+ // todo(#22117): this is extremely hacky and bad because the file
+ // may have changed by the time we get here. Instead of doing this,
+ // we should store the text info in the diagnostics
+ if specifier.scheme() == "file" {
+ let path = specifier.to_file_path().ok()?;
+ let text = std::fs::read_to_string(path).ok()?;
+ Some(Cow::Owned(SourceTextInfo::new(text.into())))
+ } else {
+ None
+ }
+ }
+ }
}
}