use IdentStr

This commit is contained in:
Folkert 2021-08-03 21:14:36 +02:00
parent bd35770e9a
commit ceb5cc66fa
30 changed files with 241 additions and 219 deletions

View file

@ -1,5 +1,5 @@
use roc_collections::all::MutSet;
use roc_module::ident::Lowercase;
use roc_module::ident::{Ident, Lowercase, ModuleName};
use roc_parse::parser::{Col, Row};
use roc_problem::can::PrecedenceProblem::BothNonAssociative;
use roc_problem::can::{BadPattern, FloatErrorKind, IntErrorKind, Problem, RuntimeError};
@ -1002,13 +1002,16 @@ fn to_circular_def_doc<'b>(
fn not_found<'b>(
alloc: &'b RocDocAllocator<'b>,
region: roc_region::all::Region,
name: &str,
name: &Ident,
thing: &'b str,
options: MutSet<Box<str>>,
) -> RocDocBuilder<'b> {
use crate::error::r#type::suggest;
let mut suggestions = suggest::sort(name, options.iter().map(|v| v.as_ref()).collect());
let mut suggestions = suggest::sort(
name.as_inline_str().as_str(),
options.iter().map(|v| v.as_ref()).collect(),
);
suggestions.truncate(4);
let default_no = alloc.concat(vec![
@ -1049,12 +1052,13 @@ fn not_found<'b>(
fn module_not_found<'b>(
alloc: &'b RocDocAllocator<'b>,
region: roc_region::all::Region,
name: &str,
name: &ModuleName,
options: MutSet<Box<str>>,
) -> RocDocBuilder<'b> {
use crate::error::r#type::suggest;
let mut suggestions = suggest::sort(name, options.iter().map(|v| v.as_ref()).collect());
let mut suggestions =
suggest::sort(name.as_str(), options.iter().map(|v| v.as_ref()).collect());
suggestions.truncate(4);
let default_no = alloc.concat(vec![

View file

@ -1,6 +1,6 @@
use roc_can::expected::{Expected, PExpected};
use roc_collections::all::{Index, MutSet, SendMap};
use roc_module::ident::{Lowercase, TagName};
use roc_module::ident::{IdentStr, Lowercase, TagName};
use roc_module::symbol::Symbol;
use roc_solve::solve;
use roc_types::pretty_print::Parens;
@ -1312,6 +1312,12 @@ pub mod suggest {
}
}
impl ToStr for super::IdentStr {
fn to_str(&self) -> &str {
self.as_str()
}
}
impl<A, B> ToStr for (A, B)
where
A: ToStr,
@ -2426,11 +2432,11 @@ fn type_problem_to_pretty<'b>(
}
},
TagTypo(typo, possibilities_tn) => {
let possibilities = possibilities_tn
let possibilities: Vec<IdentStr> = possibilities_tn
.into_iter()
.map(|tag_name| tag_name.as_string(alloc.interns, alloc.home))
.map(|tag_name| tag_name.as_ident_str(alloc.interns, alloc.home))
.collect();
let typo_str = format!("{}", typo.as_string(alloc.interns, alloc.home));
let typo_str = format!("{}", typo.as_ident_str(alloc.interns, alloc.home));
let suggestions = suggest::sort(&typo_str, possibilities);
match suggestions.get(0) {

View file

@ -259,19 +259,19 @@ impl<'a> RocDocAllocator<'a> {
}
pub fn symbol_unqualified(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> {
self.text(format!("{}", symbol.ident_string(self.interns)))
self.text(format!("{}", symbol.ident_str(self.interns)))
.annotate(Annotation::Symbol)
}
pub fn symbol_foreign_qualified(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> {
if symbol.module_id() == self.home || symbol.module_id().is_builtin() {
// Render it unqualified if it's in the current module or a builtin
self.text(format!("{}", symbol.ident_string(self.interns)))
self.text(format!("{}", symbol.ident_str(self.interns)))
.annotate(Annotation::Symbol)
} else {
self.text(format!(
"{}.{}",
symbol.module_string(self.interns),
symbol.ident_string(self.interns),
symbol.ident_str(self.interns),
))
.annotate(Annotation::Symbol)
}
@ -280,7 +280,7 @@ impl<'a> RocDocAllocator<'a> {
self.text(format!(
"{}.{}",
symbol.module_string(self.interns),
symbol.ident_string(self.interns),
symbol.ident_str(self.interns),
))
.annotate(Annotation::Symbol)
}
@ -288,13 +288,13 @@ impl<'a> RocDocAllocator<'a> {
pub fn private_tag_name(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> {
if symbol.module_id() == self.home {
// Render it unqualified if it's in the current module.
self.text(format!("{}", symbol.ident_string(self.interns)))
self.text(format!("{}", symbol.ident_str(self.interns)))
.annotate(Annotation::PrivateTag)
} else {
self.text(format!(
"{}.{}",
symbol.module_string(self.interns),
symbol.ident_string(self.interns),
symbol.ident_str(self.interns),
))
.annotate(Annotation::PrivateTag)
}