Skip to content

Commit adb82ea

Browse files
jkeuhlen9999years
authored andcommitted
[DUX-1511] Add the ability to track warnings through re-compilation
Closes #148
1 parent 02ce561 commit adb82ea

File tree

10 files changed

+1479
-8
lines changed

10 files changed

+1479
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
/result*
33
lcov.info
4+
.direnv/

docs/cli.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Don't reload for `README.md` files:
3737

3838
ghciwatch --reload-glob '!src/**/README.md'
3939

40+
Track warnings across recompilations to prevent them from disappearing:
41+
42+
ghciwatch --track-warnings
43+
4044
## Arguments
4145
<dl>
4246

@@ -88,6 +92,19 @@ Don't interrupt reloads when files change.
8892

8993
Depending on your workflow, `ghciwatch` may feel more responsive with this set.
9094

95+
</dd>
96+
<dt><a id="--track-warnings" href="#--track-warnings"><code>--track-warnings</code></a></dt><dd>
97+
98+
Track warnings across recompilations.
99+
100+
When enabled, warnings will be preserved in memory even when files are recompiled due to dependency changes, helping prevent "ephemeral warnings" from being missed.
101+
102+
This feature addresses the common issue where GHC warnings disappear when files are recompiled due to dependency changes (without the file itself changing). With `--track-warnings`, warnings persist until the file is directly modified or removed.
103+
104+
Tracked warnings are displayed with the same formatting and colors as fresh warnings, and are included in the error file output when using `--error-file`.
105+
106+
Can also be enabled by setting the `GHCIWATCH_TRACK_WARNINGS` environment variable to any value.
107+
91108
</dd>
92109
<dt><a id="--completions" href="#--completions"><code>--completions &lt;COMPLETIONS&gt;</code></a></dt><dd>
93110

src/cli.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ pub struct Opts {
9696
#[arg(long, hide = true)]
9797
pub tui: bool,
9898

99+
/// Track warnings across recompilations.
100+
///
101+
/// When enabled, warnings will be preserved in memory even when files are recompiled
102+
/// due to dependency changes, helping prevent "ephemeral warnings" from being missed.
103+
#[arg(long, env = "GHCIWATCH_TRACK_WARNINGS")]
104+
pub track_warnings: bool,
105+
99106
/// Generate Markdown CLI documentation.
100107
#[cfg(feature = "clap-markdown")]
101108
#[arg(long, hide = true)]

src/ghci/compilation_log.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::ghci::parse::CompilationResult;
22
use crate::ghci::parse::CompilationSummary;
3+
use crate::ghci::parse::CompilingModule;
34
use crate::ghci::parse::GhcDiagnostic;
45
use crate::ghci::parse::GhcMessage;
56
use crate::ghci::parse::Severity;
@@ -9,6 +10,7 @@ use crate::ghci::parse::Severity;
910
pub struct CompilationLog {
1011
pub summary: Option<CompilationSummary>,
1112
pub diagnostics: Vec<GhcDiagnostic>,
13+
pub compiled_modules: Vec<CompilingModule>,
1214
}
1315

1416
impl CompilationLog {
@@ -24,6 +26,7 @@ impl Extend<GhcMessage> for CompilationLog {
2426
match message {
2527
GhcMessage::Compiling(module) => {
2628
tracing::debug!(module = %module.name, path = %module.path, "Compiling");
29+
self.compiled_modules.push(module);
2730
}
2831
GhcMessage::Diagnostic(diagnostic) => {
2932
if let GhcDiagnostic {

src/ghci/error_log.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use camino::Utf8Path;
12
use camino::Utf8PathBuf;
23
use miette::IntoDiagnostic;
34
use tokio::fs::File;
@@ -23,6 +24,11 @@ impl ErrorLog {
2324
Self { path }
2425
}
2526

27+
/// Get the path for this error log writer, if any.
28+
pub fn path(&self) -> Option<&Utf8Path> {
29+
self.path.as_deref()
30+
}
31+
2632
/// Write the error log, if any, with the given compilation summary and diagnostic messages.
2733
#[instrument(skip(self, log), name = "error_log_write", level = "debug")]
2834
pub async fn write(&mut self, log: &CompilationLog) -> miette::Result<()> {

0 commit comments

Comments
 (0)