mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
complete add_category
This commit is contained in:
parent
74331e4b90
commit
a2a79925b3
5 changed files with 95 additions and 7 deletions
|
@ -174,6 +174,12 @@ pub enum ReportText {
|
|||
/// A global tag rendered as code (e.g. a monospace font, or with backticks around it).
|
||||
GlobalTag(Box<str>),
|
||||
|
||||
/// A private tag rendered as code (e.g. a monospace font, or with backticks around it).
|
||||
PrivateTag(Symbol),
|
||||
|
||||
/// A record field name rendered as code (e.g. a monospace font, or with backticks around it).
|
||||
RecordField(Box<str>),
|
||||
|
||||
/// A language keyword like `if`, rendered as code (e.g. a monospace font, or with backticks around it).
|
||||
Keyword(Box<str>),
|
||||
|
||||
|
@ -205,10 +211,18 @@ pub fn em_text(str: &str) -> ReportText {
|
|||
ReportText::EmText(Box::from(str))
|
||||
}
|
||||
|
||||
pub fn private_tag_text(symbol: Symbol) -> ReportText {
|
||||
ReportText::PrivateTag(symbol)
|
||||
}
|
||||
|
||||
pub fn global_tag_text(str: &str) -> ReportText {
|
||||
ReportText::GlobalTag(Box::from(str))
|
||||
}
|
||||
|
||||
pub fn record_field_text(str: &str) -> ReportText {
|
||||
ReportText::RecordField(Box::from(str))
|
||||
}
|
||||
|
||||
pub fn keyword_text(str: &str) -> ReportText {
|
||||
ReportText::Keyword(Box::from(str))
|
||||
}
|
||||
|
@ -323,12 +337,19 @@ impl ReportText {
|
|||
buf.push_str(&string);
|
||||
buf.push('`');
|
||||
}
|
||||
RecordField(string) => {
|
||||
// Since this is CI, the best we can do for code text is backticks.
|
||||
buf.push('`');
|
||||
buf.push('.');
|
||||
buf.push_str(&string);
|
||||
buf.push('`');
|
||||
}
|
||||
Url(url) => {
|
||||
buf.push('<');
|
||||
buf.push_str(&url);
|
||||
buf.push('>');
|
||||
}
|
||||
Value(symbol) => {
|
||||
PrivateTag(symbol) | Value(symbol) => {
|
||||
if symbol.module_id() == env.home {
|
||||
// Render it unqualified if it's in the current module.
|
||||
buf.push_str(symbol.ident_string(env.interns));
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use crate::report::{global_tag_text, keyword_text, plain_text, with_indent, Report, ReportText};
|
||||
use crate::report::{
|
||||
global_tag_text, keyword_text, plain_text, private_tag_text, record_field_text, with_indent,
|
||||
Report, ReportText,
|
||||
};
|
||||
use roc_can::expected::{Expected, PExpected};
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_solve::solve;
|
||||
|
@ -275,13 +278,72 @@ fn lone_type(
|
|||
}
|
||||
|
||||
fn add_category(this_is: ReportText, category: &Category) -> ReportText {
|
||||
use roc_module::ident::TagName;
|
||||
use Category::*;
|
||||
use ReportText::*;
|
||||
|
||||
match category {
|
||||
Lookup(name) => Concat(vec![
|
||||
plain_text("This "),
|
||||
Value(*name),
|
||||
plain_text(" value is a"),
|
||||
]),
|
||||
|
||||
If => Concat(vec![
|
||||
plain_text("This "),
|
||||
keyword_text("if"),
|
||||
plain_text("expression produces"),
|
||||
]),
|
||||
When => Concat(vec![
|
||||
plain_text("This "),
|
||||
keyword_text("when"),
|
||||
plain_text("expression produces"),
|
||||
]),
|
||||
|
||||
List => Concat(vec![this_is, plain_text("a list of type")]),
|
||||
Num => Concat(vec![this_is, plain_text("a number of type")]),
|
||||
Int => Concat(vec![this_is, plain_text("an integer of type")]),
|
||||
Float => Concat(vec![this_is, plain_text("a float of type")]),
|
||||
Str => Concat(vec![this_is, plain_text(" a string of type")]),
|
||||
|
||||
Lambda => Concat(vec![this_is, plain_text("an anonymous function of type")]),
|
||||
|
||||
TagApply(TagName::Global(name)) => Concat(vec![
|
||||
plain_text("This "),
|
||||
global_tag_text(name.as_str()),
|
||||
plain_text(" global tag application produces"),
|
||||
]),
|
||||
TagApply(TagName::Private(name)) => Concat(vec![
|
||||
plain_text("This "),
|
||||
private_tag_text(*name),
|
||||
plain_text(" private tag application produces"),
|
||||
]),
|
||||
|
||||
Record => Concat(vec![this_is, plain_text("a record of type")]),
|
||||
|
||||
Accessor(field) => Concat(vec![
|
||||
plain_text("This "),
|
||||
record_field_text(field.as_str()),
|
||||
plain_text(" value is a"),
|
||||
]),
|
||||
Access(field) => Concat(vec![
|
||||
plain_text("The value at "),
|
||||
record_field_text(field.as_str()),
|
||||
plain_text(" is a"),
|
||||
]),
|
||||
|
||||
CallResult(Some(symbol)) => Concat(vec![
|
||||
plain_text("This "),
|
||||
Value(*symbol),
|
||||
plain_text(" call produces"),
|
||||
]),
|
||||
CallResult(None) => Concat(vec![this_is]),
|
||||
|
||||
Uniqueness => Concat(vec![
|
||||
this_is,
|
||||
plain_text(" an uniqueness attribute of type"),
|
||||
]),
|
||||
Storage => Concat(vec![this_is, plain_text(" a value of type")]),
|
||||
other => todo!("add_category for {:?}", other),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue