Skip to content

Commit

Permalink
Use codespan-reporting instead of annotate-snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Mar 15, 2020
1 parent aecc3d4 commit 2051589
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 297 deletions.
2 changes: 1 addition & 1 deletion pikelet-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ default = ["gui"]
gui = ["pikelet-gui"]

[dependencies]
annotate-snippets = "0.6.1"
codespan-reporting = "0.9.0"
pikelet = { path = "../pikelet" }
pikelet-gui = { path = "../pikelet-gui", optional = true }
pretty = "0.9"
Expand Down
24 changes: 16 additions & 8 deletions pikelet-cli/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ fn term_width() -> usize {

/// Run the REPL with the given options.
pub fn run(options: Options) -> Result<(), Box<dyn Error>> {
use annotate_snippets::display_list::DisplayList;
use annotate_snippets::formatter::DisplayListFormatter;
use codespan_reporting::files::SimpleFile;
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
use pikelet::{core, surface};
use rustyline::error::ReadlineError;
use rustyline::{Config, Editor};
Expand All @@ -75,6 +75,9 @@ pub fn run(options: Options) -> Result<(), Box<dyn Error>> {
}

let pretty_alloc = pretty::BoxAllocator;
let writer = StandardStream::stderr(ColorChoice::Always);
let reporting_config = codespan_reporting::term::Config::default();

let globals = core::Globals::default();
let mut state = surface::projections::core::State::new(&globals);

Expand All @@ -87,7 +90,9 @@ pub fn run(options: Options) -> Result<(), Box<dyn Error>> {

// TODO: Parse REPL commands

let surface_term = match surface::Term::from_str(&line) {
let file = SimpleFile::new("<input>", line);

let surface_term = match surface::Term::from_str(file.source()) {
Ok(surface_term) => surface_term,
Err(error) => {
println!("error: {}", error);
Expand All @@ -100,11 +105,14 @@ pub fn run(options: Options) -> Result<(), Box<dyn Error>> {
let messages = state.drain_messages().collect::<Vec<_>>();

if !messages.is_empty() {
for message in &messages {
let snippet = message.to_snippet(&line);
let display_list = DisplayList::from(snippet);
let formatter = DisplayListFormatter::new(true, false);
println!("{}", formatter.format(&display_list));
for diagnostic in messages.iter().map(|message| message.to_diagnostic()) {
codespan_reporting::term::emit(
&mut writer.lock(),
&reporting_config,
&file,
&diagnostic,
)
.unwrap();
}
} else {
let ann_term = core::Term::Ann(
Expand Down
2 changes: 1 addition & 1 deletion pikelet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
annotate-snippets = "0.6.1"
codespan-reporting = "0.9.0"
im = "14.2"
itertools = "0.8"
lalrpop-util = "0.17"
Expand Down
Loading

0 comments on commit 2051589

Please sign in to comment.