-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix "modules defined in multiple files" bug when modules are renamed #125
Merged
9999years
merged 1 commit into
main
from
rebeccat/dux-1404-module-defined-in-multiple-files-again
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,6 +380,9 @@ impl Ghci { | |
tracing::info!(%command, "Running after-restart command"); | ||
self.stdin.run_command(&mut self.stdout, command).await?; | ||
} | ||
// Once we restart, everything is freshly loaded. We don't need to add or | ||
// reload any other modules. | ||
return Ok(()); | ||
} | ||
|
||
if actions.needs_add_or_reload() { | ||
|
@@ -551,6 +554,11 @@ impl Ghci { | |
/// Optionally returns a compilation result. | ||
#[instrument(skip(self), level = "debug")] | ||
async fn add_module(&mut self, path: &NormalPath) -> miette::Result<Option<CompilationResult>> { | ||
if self.targets.contains_source_path(path.absolute())? { | ||
tracing::debug!(%path, "Skipping `:add`ing already-loaded path"); | ||
return Ok(None); | ||
} | ||
Comment on lines
+557
to
+560
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also sufficient to fix the bug. I'm adding it here in case I make this programming error in the future (calling |
||
|
||
let messages = self | ||
.stdin | ||
.add_module(&mut self.stdout, path.relative()) | ||
|
@@ -662,6 +670,7 @@ impl Display for Mode { | |
/// Actions needed to perform a reload. | ||
/// | ||
/// See [`Ghci::reload`]. | ||
#[derive(Debug)] | ||
struct ReloadActions { | ||
/// Paths to modules which need a full `ghci` restart. | ||
needs_restart: Vec<NormalPath>, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use test_harness::fs; | ||
use test_harness::test; | ||
use test_harness::GhcidNg; | ||
use test_harness::Matcher; | ||
|
||
/// Test that `ghcid-ng` can restart correctly when modules are removed and added (i.e., renamed) | ||
/// at the same time. | ||
#[test] | ||
async fn can_compile_renamed_module() { | ||
let mut session = GhcidNg::new("tests/data/simple") | ||
.await | ||
.expect("ghcid-ng starts"); | ||
session | ||
.wait_until_ready() | ||
.await | ||
.expect("ghcid-ng loads ghci"); | ||
|
||
let module_path = session.path("src/MyModule.hs"); | ||
let new_module_path = session.path("src/MyCoolModule.hs"); | ||
fs::rename(&module_path, &new_module_path).await.unwrap(); | ||
|
||
session | ||
.wait_until_restart() | ||
.await | ||
.expect("ghcid-ng restarts on module move"); | ||
|
||
session | ||
.assert_logged(Matcher::message("Compilation failed").in_span("reload")) | ||
.await | ||
.unwrap(); | ||
|
||
fs::replace(new_module_path, "module MyModule", "module MyCoolModule") | ||
.await | ||
.unwrap(); | ||
|
||
session | ||
.wait_until_reload() | ||
.await | ||
.expect("ghcid-ng reloads on module change"); | ||
|
||
session | ||
.assert_logged(Matcher::message("Compilation succeeded").in_span("reload")) | ||
.await | ||
.unwrap(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual bug fix.