From 5615a26569eb0edbf52b97c67780dd357b6db460 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 29 Feb 2020 02:30:52 -0500 Subject: [PATCH 1/4] Drop obsolete comment --- compiler/src/can/problem.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/src/can/problem.rs b/compiler/src/can/problem.rs index 9c385d097a..09ea30b8c6 100644 --- a/compiler/src/can/problem.rs +++ b/compiler/src/can/problem.rs @@ -9,7 +9,6 @@ use roc_region::all::{Located, Region}; /// Problems that can occur in the course of canonicalization. #[derive(Clone, Debug, PartialEq)] pub enum Problem { - // TODO use Symbol over Ident with these UnusedDef(Symbol, Region), UnusedImport(ModuleId, Region), UnusedArgument(Symbol, Region), From d5163fa4d47709fda30bbfe6bcc5ac3c6b95bad4 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 29 Feb 2020 02:30:57 -0500 Subject: [PATCH 2/4] Add src/reporting.rs --- compiler/src/lib.rs | 1 + compiler/src/reporting.rs | 101 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 compiler/src/reporting.rs diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 408f16090b..9ad683a932 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -29,6 +29,7 @@ pub mod llvm; pub mod load; pub mod mono; pub mod pretty_print_types; +pub mod reporting; pub mod solve; pub mod subs; pub mod types; diff --git a/compiler/src/reporting.rs b/compiler/src/reporting.rs new file mode 100644 index 0000000000..16484f7593 --- /dev/null +++ b/compiler/src/reporting.rs @@ -0,0 +1,101 @@ +use crate::can::problem::Problem; +use crate::module::symbol::{Interns, ModuleId, Symbol}; +use crate::pretty_print_types::content_to_string; +use crate::region::Region; +use crate::subs::{Content, Subs}; +use std::path::PathBuf; + +/// A textual report. +pub struct Report { + pub filename: PathBuf, + pub text: ReportText, +} + +impl Report { + pub fn problem(filename: PathBuf, problem: Problem) -> Self { + let text = ReportText::Plain("TODO convert Problem to ReportText".into()); + + Report { filename, text } + } +} + +#[derive(Debug, Clone)] +pub enum ReportText { + /// A value. Render it qualified unless it was defined in the current module. + Value(Symbol), + + /// A type. Render it using pretty_print_types for now, but maybe + /// do something fancier later. + Type(Content), + + /// Plain text + Plain(Box), + + /// Emphasized text (might be bold, italics, a different color, etc) + EmText(Box), + + /// A region in the original source + Region(Region), + + /// A URL, which should be rendered as a hyperlink. + Url(Box), +} + +impl ReportText { + /// Render to CI console output, where no colors are available. + pub fn render_ci( + self, + buf: &mut String, + subs: &mut Subs, + home: ModuleId, + src_lines: &[&str], + interns: &Interns, + ) { + use ReportText::*; + + match self { + Plain(string) => buf.push_str(&string), + EmText(string) => { + // Since this is CI, the best we can do for emphasis are asterisks. + buf.push('*'); + buf.push_str(&string); + buf.push('*'); + } + Url(url) => { + buf.push('<'); + buf.push_str(&url); + buf.push('>'); + } + Value(symbol) => { + if symbol.module_id() == home { + // Render it unqualified if it's in the current module. + buf.push_str(symbol.ident_string(interns)); + } else { + buf.push_str(symbol.module_string(interns)); + buf.push('.'); + buf.push_str(symbol.ident_string(interns)); + } + } + Type(content) => buf.push_str(content_to_string(content, subs, home, interns).as_str()), + Region(region) => { + panic!( + "TODO convert these source lines and this region into a String: {:?}, {:?}", + src_lines, region + ); + } + } + } + + /// Render to a color terminal using ANSI escape sequences + pub fn render_color_terminal( + &self, + _buf: &mut String, + _subs: &mut Subs, + _home: ModuleId, + _src_lines: &[&str], + _interns: &Interns, + ) { + // TODO do the same stuff as render_ci, but with colors via ANSI terminal escape codes! + // Examples of how to do this are in the source code of https://github.com/rtfeldman/console-print + } +} From a1b8c970392612fbec99de612ebba9d414602e89 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 29 Feb 2020 16:30:25 -0500 Subject: [PATCH 3/4] Added can_problem and Docs --- compiler/src/reporting.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/compiler/src/reporting.rs b/compiler/src/reporting.rs index 16484f7593..1e82ed6937 100644 --- a/compiler/src/reporting.rs +++ b/compiler/src/reporting.rs @@ -12,8 +12,15 @@ pub struct Report { } impl Report { - pub fn problem(filename: PathBuf, problem: Problem) -> Self { - let text = ReportText::Plain("TODO convert Problem to ReportText".into()); + pub fn can_problem(filename: PathBuf, problem: Problem) -> Self { + let text = match problem { + Problem::UnusedDef(symbol, region) => { + panic!("TODO implelment me!"); + } + _ => { + panic!("TODO implement others"); + } + }; Report { filename, text } } @@ -39,6 +46,9 @@ pub enum ReportText { /// A URL, which should be rendered as a hyperlink. Url(Box), + + /// The documentation for this symbol. + Docs(Symbol), } impl ReportText { @@ -83,6 +93,9 @@ impl ReportText { src_lines, region ); } + Docs(_) => { + panic!("TODO implment docs"); + } } } From 6ac60fa5cba3ba91d3c4972cf194bb5ca6dc7ea0 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 Mar 2020 20:51:59 -0500 Subject: [PATCH 4/4] Update reporting to use new crate structure. --- compiler/src/reporting.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/compiler/src/reporting.rs b/compiler/src/reporting.rs index 1e82ed6937..65ad298a05 100644 --- a/compiler/src/reporting.rs +++ b/compiler/src/reporting.rs @@ -1,8 +1,8 @@ use crate::can::problem::Problem; -use crate::module::symbol::{Interns, ModuleId, Symbol}; use crate::pretty_print_types::content_to_string; -use crate::region::Region; use crate::subs::{Content, Subs}; +use roc_module::symbol::{Interns, ModuleId, Symbol}; +use roc_region::all::Region; use std::path::PathBuf; /// A textual report. @@ -12,17 +12,18 @@ pub struct Report { } impl Report { - pub fn can_problem(filename: PathBuf, problem: Problem) -> Self { - let text = match problem { - Problem::UnusedDef(symbol, region) => { - panic!("TODO implelment me!"); - } - _ => { - panic!("TODO implement others"); - } - }; + pub fn can_problem(_filename: PathBuf, _problem: Problem) -> Self { + // let text = match problem { + // Problem::UnusedDef(symbol, region) => { + // panic!("TODO implelment me!"); + // } + // _ => { + // panic!("TODO implement others"); + // } + // }; - Report { filename, text } + // Report { filename, text } + panic!("TODO implement me!"); } }