Skip to content

Commit 1bd80c7

Browse files
authored
DUX-5351 eval: Don't insert empty entries (#460)
The other insertion loop was guarded to not insert empty entries, but this one wasn't. - [ ] Updated the user manual in `docs/`. - [ ] Added integration / regression tests in `tests/`.
1 parent 33f693d commit 1bd80c7

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/ghci/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ impl Ghci {
720720
// We get _all_ file events in this loop, not just Haskell source files, so let's guard
721721
// adding an entry to the `eval_commands` map by making sure we can convert the path to
722722
// a module name.
723+
//
724+
// However!!! We're _modifying_ an existing map here, so if we look at a path and
725+
// _don't_ find any commands, we need to be careful to _remove_ that entry from the map.
726+
//
727+
// Hey maybe this should just be a generic multimap structure, anyone ever think of that?
723728
if self.search_paths.path_to_module(path).is_err() {
724729
if is_haskell_source_file(path) {
725730
// If the path is a Haskell source file (ends with `.hs` or similar), we should
@@ -730,11 +735,16 @@ impl Ghci {
730735
} else {
731736
tracing::debug!(%path, "Could not determine module path, skipping parsing eval commands");
732737
}
738+
self.eval_commands.remove(path);
733739
continue;
734740
}
735741

736742
let commands = Self::parse_eval_commands(path).await?;
737-
self.eval_commands.insert(path.clone(), commands);
743+
if commands.is_empty() {
744+
self.eval_commands.remove(path);
745+
} else {
746+
self.eval_commands.insert(path.clone(), commands);
747+
}
738748
}
739749

740750
Ok(())

tests/eval.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ async fn can_eval_commands() {
5555
.expect("ghciwatch finishes initializing");
5656

5757
// Erase the command.
58+
session.clear_events();
5859
session.fs().replace(module_path, cmd, "").await.unwrap();
5960
session
6061
.wait_until_reload()
@@ -109,6 +110,7 @@ async fn can_load_new_eval_commands_multiline() {
109110
.expect("ghciwatch evals commands");
110111

111112
// Erase the command.
113+
session.clear_events();
112114
session
113115
.fs()
114116
.replace(module_path, eval_cmd, "")

0 commit comments

Comments
 (0)