Skip to content

Commit

Permalink
incremental_reader: operate on strings, not lists of lines
Browse files Browse the repository at this point in the history
  • Loading branch information
9999years committed Sep 11, 2023
1 parent 9b7354a commit 79e7ac2
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 77 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ghcid-ng/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ camino = "1.1.4"
clap = { version = "4.3.2", features = ["derive", "wrap_help", "env"] }
humantime = "2.1.0"
itertools = "0.11.0"
line-span = "0.1.5"
miette = { version = "5.9.0", features = ["fancy"] }
nix = { version = "0.26.2", default_features = false, features = ["process"] }
once_cell = "1.18.0"
Expand Down
1 change: 0 additions & 1 deletion ghcid-ng/src/ghci/parse/module_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl ModuleSet {
/// Determine if a module with the given source path is contained in this module set.
///
/// Returns `Err` if the `path` cannot be canonicalized.
#[allow(dead_code)]
pub fn contains_source_path(&self, path: &Utf8Path) -> miette::Result<bool> {
Ok(self.map.contains(&canonicalize(path)?))
}
Expand Down
25 changes: 12 additions & 13 deletions ghcid-ng/src/ghci/stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use tracing::instrument;
use crate::aho_corasick::AhoCorasickExt;
use crate::incremental_reader::IncrementalReader;
use crate::incremental_reader::WriteBehavior;
use crate::lines::Lines;
use crate::sync_sentinel::SyncSentinel;

use super::parse::ModuleSet;
Expand Down Expand Up @@ -44,11 +43,11 @@ impl GhciStdout {
"GHCJSi, version ",
"Clashi, version ",
]);
let lines = self
let data = self
.reader
.read_until(&bootup_patterns, WriteBehavior::Write, &mut self.buffer)
.await?;
tracing::debug!(?lines, "ghci started, saw version marker");
tracing::debug!(data, "ghci started, saw version marker");

// We know that we'll get _one_ `ghci> ` prompt on startup.
let init_prompt_patterns = AhoCorasick::from_anchored_patterns(["ghci> "]);
Expand All @@ -69,20 +68,20 @@ impl GhciStdout {
prompt_patterns: Option<&AhoCorasick>,
) -> miette::Result<Option<CompilationResult>> {
let prompt_patterns = prompt_patterns.unwrap_or(&self.prompt_patterns);
let lines = self
let data = self
.reader
.read_until(
prompt_patterns,
WriteBehavior::NoFinalLine,
&mut self.buffer,
)
.await?;
tracing::debug!(lines = lines.len(), "Got data from ghci");
tracing::debug!(bytes = data.len(), "Got data from ghci");

let mut result = None;
if self.mode == Mode::Compiling {
result = self
.get_status_from_compile_output(lines)
.get_status_from_compile_output(data.lines().last())
.await
.wrap_err("Failed to get status from compilation output")?;
}
Expand All @@ -104,7 +103,7 @@ impl GhciStdout {
pub async fn sync(&mut self, sentinel: SyncSentinel) -> miette::Result<()> {
// Read until the sync marker...
let sync_pattern = AhoCorasick::from_anchored_patterns([sentinel.to_string()]);
let lines = self
let data = self
.reader
.read_until(&sync_pattern, WriteBehavior::NoFinalLine, &mut self.buffer)
.await?;
Expand All @@ -113,7 +112,7 @@ impl GhciStdout {
.reader
.read_until(&self.prompt_patterns, WriteBehavior::Hide, &mut self.buffer)
.await?;
tracing::debug!(?lines, "Got data from ghci");
tracing::debug!(data, "Synced with ghci");

// Tell the stderr stream to write the error log and then finish.
let (err_sender, err_receiver) = oneshot::channel();
Expand All @@ -133,7 +132,7 @@ impl GhciStdout {
.reader
.read_until(&self.prompt_patterns, WriteBehavior::Hide, &mut self.buffer)
.await?;
ModuleSet::from_lines(&lines.join("\n"))
ModuleSet::from_lines(&lines)
}

#[instrument(skip(self), level = "debug")]
Expand All @@ -148,10 +147,10 @@ impl GhciStdout {
/// compilation status.
async fn get_status_from_compile_output(
&mut self,
mut lines: Lines,
last_line: Option<&str>,
) -> miette::Result<Option<CompilationResult>> {
if let Some(line) = lines.pop() {
if compilation_finished_re().is_match(&line) {
if let Some(line) = last_line {
if compilation_finished_re().is_match(line) {
let result = if line.starts_with("Ok") {
tracing::debug!("Compilation succeeded");
CompilationResult::Ok
Expand All @@ -163,7 +162,7 @@ impl GhciStdout {
let (sender, receiver) = oneshot::channel();
self.stderr_sender
.send(StderrEvent::SetCompilationSummary {
summary: line,
summary: line.to_owned(),
sender,
})
.await
Expand Down
Loading

0 comments on commit 79e7ac2

Please sign in to comment.