summaryrefslogtreecommitdiff
path: root/cli/diagnostics.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-02-06 19:21:26 -0500
committerGitHub <noreply@github.com>2024-02-06 19:21:26 -0500
commite54684864dee1c708325570eaaff2fce0f928387 (patch)
tree02c4b8800cb281b8cd3ccdd4e7f4c974b2a55105 /cli/diagnostics.rs
parent1007358768584856ac63dffaa82fdb00bf726bd9 (diff)
fix(publish): handle diagnostic outside graph (#22310)
Hacky quick fix. The real fix is a lot more work to do (move the `SourceTextInfo` into all the diagnostics in order to make this less error pone). I've already started on it, but it will require a lot of downstream create changes. Closes #22288
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
+ }
+ }
+ }
}
}