-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for evaluating commands in source files on reload. This looks for line commands starting with `-- $>` or multiline commands delimited by `{- $>` and `<$ -}`. This also removes the `failed_modules` mechanism from `Ghci`, which was populated by extracting filenames from error messages, and replaces it with a `targets` `ModuleSet` populated by `:show targets`. This should be more consistent. Finally, paths will be printed as relative paths when possible.
- Loading branch information
Showing
27 changed files
with
1,508 additions
and
127 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,32 @@ | ||
use clap::builder::StringValueParser; | ||
use clap::builder::TypedValueParser; | ||
use clap::builder::ValueParserFactory; | ||
|
||
use crate::ghci::GhciCommand; | ||
|
||
/// [`clap`] parser for [`GhciCommand`] values. | ||
#[derive(Default, Clone)] | ||
pub struct GhciCommandParser { | ||
inner: StringValueParser, | ||
} | ||
|
||
impl TypedValueParser for GhciCommandParser { | ||
type Value = GhciCommand; | ||
|
||
fn parse_ref( | ||
&self, | ||
cmd: &clap::Command, | ||
arg: Option<&clap::Arg>, | ||
value: &std::ffi::OsStr, | ||
) -> Result<Self::Value, clap::Error> { | ||
self.inner.parse_ref(cmd, arg, value).map(GhciCommand) | ||
} | ||
} | ||
|
||
impl ValueParserFactory for GhciCommand { | ||
type Parser = GhciCommandParser; | ||
|
||
fn value_parser() -> Self::Parser { | ||
Self::Parser::default() | ||
} | ||
} |
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,46 @@ | ||
use std::fmt::Debug; | ||
use std::fmt::Display; | ||
|
||
/// A `ghci` command. | ||
/// | ||
/// This is a string that can be written to a `ghci` session, typically a Haskell expression or | ||
/// `ghci` command starting with `:`. | ||
#[derive(Clone, PartialEq, Eq)] | ||
pub struct GhciCommand(pub String); | ||
|
||
impl GhciCommand { | ||
/// Consume this command, producing the wrapped string. | ||
pub fn into_string(self) -> String { | ||
self.0 | ||
} | ||
} | ||
|
||
impl Debug for GhciCommand { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
Debug::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
impl Display for GhciCommand { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
Display::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
impl From<String> for GhciCommand { | ||
fn from(value: String) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl From<GhciCommand> for String { | ||
fn from(value: GhciCommand) -> Self { | ||
value.into_string() | ||
} | ||
} | ||
|
||
impl AsRef<str> for GhciCommand { | ||
fn as_ref(&self) -> &str { | ||
&self.0 | ||
} | ||
} |
Oops, something went wrong.