mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-23 12:45:04 +00:00
chore: move typst-specific types (#294)
* chore: move typst-specific types * QAQ
This commit is contained in:
parent
d995ded9b2
commit
c182c5fadc
11 changed files with 201 additions and 251 deletions
|
@ -35,6 +35,8 @@ type Guard<T> = dashmap::RwLockWriteGuard<
|
||||||
HashMap<Arc<T>, SharedValue<()>, BuildHasherDefault<FxHasher>>,
|
HashMap<Arc<T>, SharedValue<()>, BuildHasherDefault<FxHasher>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
// https://news.ycombinator.com/item?id=22220342
|
||||||
|
|
||||||
pub struct Interned<T: Internable + ?Sized> {
|
pub struct Interned<T: Internable + ?Sized> {
|
||||||
arc: Arc<T>,
|
arc: Arc<T>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ struct TypeChecker<'a, 'w> {
|
||||||
impl<'a, 'w> TypeChecker<'a, 'w> {
|
impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
fn check(&mut self, root: LinkedNode) -> Ty {
|
fn check(&mut self, root: LinkedNode) -> Ty {
|
||||||
let should_record = matches!(root.kind(), SyntaxKind::FuncCall).then(|| root.span());
|
let should_record = matches!(root.kind(), SyntaxKind::FuncCall).then(|| root.span());
|
||||||
let w = self.check_syntax(root).unwrap_or(Ty::Undef);
|
let w = self.check_syntax(root).unwrap_or(Ty::undef());
|
||||||
|
|
||||||
if let Some(s) = should_record {
|
if let Some(s) = should_record {
|
||||||
self.info.witness_at_least(s, w.clone());
|
self.info.witness_at_least(s, w.clone());
|
||||||
|
@ -324,14 +324,7 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
fn possible_ever_be(&mut self, lhs: &Ty, rhs: &Ty) {
|
fn possible_ever_be(&mut self, lhs: &Ty, rhs: &Ty) {
|
||||||
// todo: instantiataion
|
// todo: instantiataion
|
||||||
match rhs {
|
match rhs {
|
||||||
Ty::Undef
|
Ty::Builtin(..) | Ty::Value(..) | Ty::Boolean(..) => {
|
||||||
| Ty::Content
|
|
||||||
| Ty::None
|
|
||||||
| Ty::FlowNone
|
|
||||||
| Ty::Auto
|
|
||||||
| Ty::Builtin(..)
|
|
||||||
| Ty::Value(..)
|
|
||||||
| Ty::Boolean(..) => {
|
|
||||||
self.constrain(rhs, lhs);
|
self.constrain(rhs, lhs);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -374,18 +367,7 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
let w = self.info.vars.get_mut(&v.def).unwrap();
|
let w = self.info.vars.get_mut(&v.def).unwrap();
|
||||||
w.weaken();
|
w.weaken();
|
||||||
}
|
}
|
||||||
Ty::Clause
|
Ty::Any | Ty::Boolean(_) | Ty::Builtin(_) | Ty::Value(_) => {}
|
||||||
| Ty::Undef
|
|
||||||
| Ty::Content
|
|
||||||
| Ty::Any
|
|
||||||
| Ty::Space
|
|
||||||
| Ty::None
|
|
||||||
| Ty::Infer
|
|
||||||
| Ty::FlowNone
|
|
||||||
| Ty::Auto
|
|
||||||
| Ty::Boolean(_)
|
|
||||||
| Ty::Builtin(_)
|
|
||||||
| Ty::Value(_) => {}
|
|
||||||
Ty::Field(v) => {
|
Ty::Field(v) => {
|
||||||
self.weaken(&v.field);
|
self.weaken(&v.field);
|
||||||
}
|
}
|
||||||
|
@ -496,55 +478,46 @@ impl Joiner {
|
||||||
}
|
}
|
||||||
|
|
||||||
match (child, &self.definite) {
|
match (child, &self.definite) {
|
||||||
(Ty::Clause, _) => {}
|
(Ty::Builtin(BuiltinTy::Space | BuiltinTy::None), _) => {}
|
||||||
(Ty::Undef, _) => {}
|
(Ty::Builtin(BuiltinTy::Clause | BuiltinTy::FlowNone), _) => {}
|
||||||
(Ty::Space, _) => {}
|
|
||||||
(Ty::Any, _) | (_, Ty::Any) => {}
|
(Ty::Any, _) | (_, Ty::Any) => {}
|
||||||
(Ty::Infer, _) => {}
|
|
||||||
(Ty::None, _) => {}
|
|
||||||
// todo: mystery flow none
|
|
||||||
(Ty::FlowNone, _) => {}
|
|
||||||
(Ty::Content, Ty::Content) => {}
|
|
||||||
(Ty::Content, Ty::None) => self.definite = Ty::Content,
|
|
||||||
(Ty::Content, _) => self.definite = Ty::Undef,
|
|
||||||
(Ty::Var(v), _) => self.possibles.push(Ty::Var(v)),
|
(Ty::Var(v), _) => self.possibles.push(Ty::Var(v)),
|
||||||
// todo: check possibles
|
// todo: check possibles
|
||||||
(Ty::Array(e), Ty::None) => self.definite = Ty::Array(e),
|
(Ty::Array(e), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Array(e),
|
||||||
(Ty::Array(..), _) => self.definite = Ty::Undef,
|
(Ty::Array(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Tuple(e), Ty::None) => self.definite = Ty::Tuple(e),
|
(Ty::Tuple(e), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Tuple(e),
|
||||||
(Ty::Tuple(..), _) => self.definite = Ty::Undef,
|
(Ty::Tuple(..), _) => self.definite = Ty::undef(),
|
||||||
// todo: possible some style
|
// todo: mystery flow none
|
||||||
(Ty::Auto, Ty::None) => self.definite = Ty::Auto,
|
// todo: possible some style (auto)
|
||||||
(Ty::Auto, _) => self.definite = Ty::Undef,
|
(Ty::Builtin(b), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Builtin(b),
|
||||||
(Ty::Builtin(b), Ty::None) => self.definite = Ty::Builtin(b),
|
(Ty::Builtin(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Builtin(..), _) => self.definite = Ty::Undef,
|
|
||||||
// todo: value join
|
// todo: value join
|
||||||
(Ty::Value(v), Ty::None) => self.definite = Ty::Value(v),
|
(Ty::Value(v), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Value(v),
|
||||||
(Ty::Value(..), _) => self.definite = Ty::Undef,
|
(Ty::Value(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Func(f), Ty::None) => self.definite = Ty::Func(f),
|
(Ty::Func(f), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Func(f),
|
||||||
(Ty::Func(..), _) => self.definite = Ty::Undef,
|
(Ty::Func(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Dict(w), Ty::None) => self.definite = Ty::Dict(w),
|
(Ty::Dict(w), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Dict(w),
|
||||||
(Ty::Dict(..), _) => self.definite = Ty::Undef,
|
(Ty::Dict(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::With(w), Ty::None) => self.definite = Ty::With(w),
|
(Ty::With(w), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::With(w),
|
||||||
(Ty::With(..), _) => self.definite = Ty::Undef,
|
(Ty::With(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Args(w), Ty::None) => self.definite = Ty::Args(w),
|
(Ty::Args(w), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Args(w),
|
||||||
(Ty::Args(..), _) => self.definite = Ty::Undef,
|
(Ty::Args(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Select(w), Ty::None) => self.definite = Ty::Select(w),
|
(Ty::Select(w), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Select(w),
|
||||||
(Ty::Select(..), _) => self.definite = Ty::Undef,
|
(Ty::Select(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Unary(w), Ty::None) => self.definite = Ty::Unary(w),
|
(Ty::Unary(w), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Unary(w),
|
||||||
(Ty::Unary(..), _) => self.definite = Ty::Undef,
|
(Ty::Unary(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Binary(w), Ty::None) => self.definite = Ty::Binary(w),
|
(Ty::Binary(w), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Binary(w),
|
||||||
(Ty::Binary(..), _) => self.definite = Ty::Undef,
|
(Ty::Binary(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::If(w), Ty::None) => self.definite = Ty::If(w),
|
(Ty::If(w), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::If(w),
|
||||||
(Ty::If(..), _) => self.definite = Ty::Undef,
|
(Ty::If(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Union(w), Ty::None) => self.definite = Ty::Union(w),
|
(Ty::Union(w), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Union(w),
|
||||||
(Ty::Union(..), _) => self.definite = Ty::Undef,
|
(Ty::Union(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Let(w), Ty::None) => self.definite = Ty::Let(w),
|
(Ty::Let(w), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Let(w),
|
||||||
(Ty::Let(..), _) => self.definite = Ty::Undef,
|
(Ty::Let(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Field(w), Ty::None) => self.definite = Ty::Field(w),
|
(Ty::Field(w), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Field(w),
|
||||||
(Ty::Field(..), _) => self.definite = Ty::Undef,
|
(Ty::Field(..), _) => self.definite = Ty::undef(),
|
||||||
(Ty::Boolean(b), Ty::None) => self.definite = Ty::Boolean(b),
|
(Ty::Boolean(b), Ty::Builtin(BuiltinTy::None)) => self.definite = Ty::Boolean(b),
|
||||||
(Ty::Boolean(..), _) => self.definite = Ty::Undef,
|
(Ty::Boolean(..), _) => self.definite = Ty::undef(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -552,7 +525,7 @@ impl Default for Joiner {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
break_or_continue_or_return: false,
|
break_or_continue_or_return: false,
|
||||||
definite: Ty::None,
|
definite: Ty::Builtin(BuiltinTy::None),
|
||||||
possibles: Vec::new(),
|
possibles: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,28 +23,28 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
SyntaxKind::ContentBlock => return self.check_in_mode(root, InterpretMode::Markup),
|
SyntaxKind::ContentBlock => return self.check_in_mode(root, InterpretMode::Markup),
|
||||||
|
|
||||||
// todo: space effect
|
// todo: space effect
|
||||||
SyntaxKind::Space => Ty::Space,
|
SyntaxKind::Space => Ty::Builtin(BuiltinTy::Space),
|
||||||
SyntaxKind::Parbreak => Ty::Space,
|
SyntaxKind::Parbreak => Ty::Builtin(BuiltinTy::Space),
|
||||||
|
|
||||||
SyntaxKind::Text => Ty::Content,
|
SyntaxKind::Text => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::Linebreak => Ty::Content,
|
SyntaxKind::Linebreak => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::Escape => Ty::Content,
|
SyntaxKind::Escape => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::Shorthand => Ty::Content,
|
SyntaxKind::Shorthand => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::SmartQuote => Ty::Content,
|
SyntaxKind::SmartQuote => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::Raw => Ty::Content,
|
SyntaxKind::Raw => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::RawLang => Ty::Content,
|
SyntaxKind::RawLang => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::RawDelim => Ty::Content,
|
SyntaxKind::RawDelim => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::RawTrimmed => Ty::Content,
|
SyntaxKind::RawTrimmed => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::Link => Ty::Content,
|
SyntaxKind::Link => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::Label => Ty::Content,
|
SyntaxKind::Label => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::Ref => Ty::Content,
|
SyntaxKind::Ref => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::RefMarker => Ty::Content,
|
SyntaxKind::RefMarker => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::HeadingMarker => Ty::Content,
|
SyntaxKind::HeadingMarker => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::EnumMarker => Ty::Content,
|
SyntaxKind::EnumMarker => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::ListMarker => Ty::Content,
|
SyntaxKind::ListMarker => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::TermMarker => Ty::Content,
|
SyntaxKind::TermMarker => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::MathAlignPoint => Ty::Content,
|
SyntaxKind::MathAlignPoint => Ty::Builtin(BuiltinTy::Content),
|
||||||
SyntaxKind::MathPrimes => Ty::Content,
|
SyntaxKind::MathPrimes => Ty::Builtin(BuiltinTy::Content),
|
||||||
|
|
||||||
SyntaxKind::Strong => return self.check_children(root),
|
SyntaxKind::Strong => return self.check_children(root),
|
||||||
SyntaxKind::Emph => return self.check_children(root),
|
SyntaxKind::Emph => return self.check_children(root),
|
||||||
|
@ -58,17 +58,17 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
SyntaxKind::MathFrac => return self.check_children(root),
|
SyntaxKind::MathFrac => return self.check_children(root),
|
||||||
SyntaxKind::MathRoot => return self.check_children(root),
|
SyntaxKind::MathRoot => return self.check_children(root),
|
||||||
|
|
||||||
SyntaxKind::LoopBreak => Ty::None,
|
SyntaxKind::LoopBreak => Ty::Builtin(BuiltinTy::None),
|
||||||
SyntaxKind::LoopContinue => Ty::None,
|
SyntaxKind::LoopContinue => Ty::Builtin(BuiltinTy::None),
|
||||||
SyntaxKind::FuncReturn => Ty::None,
|
SyntaxKind::FuncReturn => Ty::Builtin(BuiltinTy::None),
|
||||||
SyntaxKind::Error => Ty::None,
|
SyntaxKind::Error => Ty::Builtin(BuiltinTy::None),
|
||||||
SyntaxKind::Eof => Ty::None,
|
SyntaxKind::Eof => Ty::Builtin(BuiltinTy::None),
|
||||||
|
|
||||||
SyntaxKind::None => Ty::None,
|
SyntaxKind::None => Ty::Builtin(BuiltinTy::None),
|
||||||
SyntaxKind::Auto => Ty::Auto,
|
SyntaxKind::Auto => Ty::Builtin(BuiltinTy::Auto),
|
||||||
SyntaxKind::Break => Ty::FlowNone,
|
SyntaxKind::Break => Ty::Builtin(BuiltinTy::FlowNone),
|
||||||
SyntaxKind::Continue => Ty::FlowNone,
|
SyntaxKind::Continue => Ty::Builtin(BuiltinTy::FlowNone),
|
||||||
SyntaxKind::Return => Ty::FlowNone,
|
SyntaxKind::Return => Ty::Builtin(BuiltinTy::FlowNone),
|
||||||
SyntaxKind::Ident => return self.check_ident(root, InterpretMode::Code),
|
SyntaxKind::Ident => return self.check_ident(root, InterpretMode::Code),
|
||||||
SyntaxKind::MathIdent => return self.check_ident(root, InterpretMode::Math),
|
SyntaxKind::MathIdent => return self.check_ident(root, InterpretMode::Math),
|
||||||
SyntaxKind::Bool
|
SyntaxKind::Bool
|
||||||
|
@ -103,62 +103,62 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
SyntaxKind::DestructAssignment => return self.check_destruct_assign(root),
|
SyntaxKind::DestructAssignment => return self.check_destruct_assign(root),
|
||||||
|
|
||||||
// Rest all are clauses
|
// Rest all are clauses
|
||||||
SyntaxKind::LineComment => Ty::Clause,
|
SyntaxKind::LineComment => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::BlockComment => Ty::Clause,
|
SyntaxKind::BlockComment => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Named => Ty::Clause,
|
SyntaxKind::Named => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Keyed => Ty::Clause,
|
SyntaxKind::Keyed => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Spread => Ty::Clause,
|
SyntaxKind::Spread => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Params => Ty::Clause,
|
SyntaxKind::Params => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::ImportItems => Ty::Clause,
|
SyntaxKind::ImportItems => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::RenamedImportItem => Ty::Clause,
|
SyntaxKind::RenamedImportItem => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Hash => Ty::Clause,
|
SyntaxKind::Hash => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::LeftBrace => Ty::Clause,
|
SyntaxKind::LeftBrace => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::RightBrace => Ty::Clause,
|
SyntaxKind::RightBrace => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::LeftBracket => Ty::Clause,
|
SyntaxKind::LeftBracket => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::RightBracket => Ty::Clause,
|
SyntaxKind::RightBracket => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::LeftParen => Ty::Clause,
|
SyntaxKind::LeftParen => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::RightParen => Ty::Clause,
|
SyntaxKind::RightParen => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Comma => Ty::Clause,
|
SyntaxKind::Comma => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Semicolon => Ty::Clause,
|
SyntaxKind::Semicolon => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Colon => Ty::Clause,
|
SyntaxKind::Colon => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Star => Ty::Clause,
|
SyntaxKind::Star => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Underscore => Ty::Clause,
|
SyntaxKind::Underscore => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Dollar => Ty::Clause,
|
SyntaxKind::Dollar => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Plus => Ty::Clause,
|
SyntaxKind::Plus => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Minus => Ty::Clause,
|
SyntaxKind::Minus => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Slash => Ty::Clause,
|
SyntaxKind::Slash => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Hat => Ty::Clause,
|
SyntaxKind::Hat => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Prime => Ty::Clause,
|
SyntaxKind::Prime => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Dot => Ty::Clause,
|
SyntaxKind::Dot => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Eq => Ty::Clause,
|
SyntaxKind::Eq => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::EqEq => Ty::Clause,
|
SyntaxKind::EqEq => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::ExclEq => Ty::Clause,
|
SyntaxKind::ExclEq => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Lt => Ty::Clause,
|
SyntaxKind::Lt => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::LtEq => Ty::Clause,
|
SyntaxKind::LtEq => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Gt => Ty::Clause,
|
SyntaxKind::Gt => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::GtEq => Ty::Clause,
|
SyntaxKind::GtEq => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::PlusEq => Ty::Clause,
|
SyntaxKind::PlusEq => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::HyphEq => Ty::Clause,
|
SyntaxKind::HyphEq => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::StarEq => Ty::Clause,
|
SyntaxKind::StarEq => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::SlashEq => Ty::Clause,
|
SyntaxKind::SlashEq => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Dots => Ty::Clause,
|
SyntaxKind::Dots => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Arrow => Ty::Clause,
|
SyntaxKind::Arrow => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Root => Ty::Clause,
|
SyntaxKind::Root => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Not => Ty::Clause,
|
SyntaxKind::Not => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::And => Ty::Clause,
|
SyntaxKind::And => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Or => Ty::Clause,
|
SyntaxKind::Or => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Let => Ty::Clause,
|
SyntaxKind::Let => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Set => Ty::Clause,
|
SyntaxKind::Set => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Show => Ty::Clause,
|
SyntaxKind::Show => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Context => Ty::Clause,
|
SyntaxKind::Context => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::If => Ty::Clause,
|
SyntaxKind::If => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Else => Ty::Clause,
|
SyntaxKind::Else => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::For => Ty::Clause,
|
SyntaxKind::For => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::In => Ty::Clause,
|
SyntaxKind::In => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::While => Ty::Clause,
|
SyntaxKind::While => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Import => Ty::Clause,
|
SyntaxKind::Import => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::Include => Ty::Clause,
|
SyntaxKind::Include => Ty::Builtin(BuiltinTy::Clause),
|
||||||
SyntaxKind::As => Ty::Clause,
|
SyntaxKind::As => Ty::Builtin(BuiltinTy::Clause),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
|
|
||||||
for elem in root.children() {
|
for elem in root.children() {
|
||||||
let ty = self.check(elem);
|
let ty = self.check(elem);
|
||||||
if matches!(ty, Ty::Clause | Ty::Space) {
|
if matches!(ty, Ty::Builtin(BuiltinTy::Clause | BuiltinTy::Space)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
elements.push(ty);
|
elements.push(ty);
|
||||||
|
@ -421,7 +421,7 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
let value = let_binding
|
let value = let_binding
|
||||||
.init()
|
.init()
|
||||||
.map(|init| self.check_expr_in(init.span(), root.clone()))
|
.map(|init| self.check_expr_in(init.span(), root.clone()))
|
||||||
.unwrap_or_else(|| Ty::Infer);
|
.unwrap_or_else(|| Ty::Builtin(BuiltinTy::Infer));
|
||||||
|
|
||||||
let v = self.get_var(c.span(), to_ident_ref(&root, c)?)?;
|
let v = self.get_var(c.span(), to_ident_ref(&root, c)?)?;
|
||||||
self.constrain(&value, &v);
|
self.constrain(&value, &v);
|
||||||
|
@ -432,7 +432,7 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
let value = let_binding
|
let value = let_binding
|
||||||
.init()
|
.init()
|
||||||
.map(|init| self.check_expr_in(init.span(), root.clone()))
|
.map(|init| self.check_expr_in(init.span(), root.clone()))
|
||||||
.unwrap_or_else(|| Ty::Infer);
|
.unwrap_or_else(|| Ty::Builtin(BuiltinTy::Infer));
|
||||||
|
|
||||||
self.check_pattern(pattern, value, root.clone());
|
self.check_pattern(pattern, value, root.clone());
|
||||||
}
|
}
|
||||||
|
@ -497,7 +497,7 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
let else_ = conditional
|
let else_ = conditional
|
||||||
.else_body()
|
.else_body()
|
||||||
.map(|else_body| self.check_expr_in(else_body.span(), root.clone()))
|
.map(|else_body| self.check_expr_in(else_body.span(), root.clone()))
|
||||||
.unwrap_or(Ty::None);
|
.unwrap_or(Ty::Builtin(BuiltinTy::None));
|
||||||
|
|
||||||
Some(Ty::If(IfTy::new(cond.into(), then.into(), else_.into())))
|
Some(Ty::If(IfTy::new(cond.into(), then.into(), else_.into())))
|
||||||
}
|
}
|
||||||
|
@ -526,11 +526,11 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
|
|
||||||
// check all import items
|
// check all import items
|
||||||
|
|
||||||
Some(Ty::None)
|
Some(Ty::Builtin(BuiltinTy::None))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_module_include(&mut self, _root: LinkedNode<'_>) -> Option<Ty> {
|
fn check_module_include(&mut self, _root: LinkedNode<'_>) -> Option<Ty> {
|
||||||
Some(Ty::Content)
|
Some(Ty::Builtin(BuiltinTy::Content))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_destructuring(&mut self, _root: LinkedNode<'_>) -> Option<Ty> {
|
fn check_destructuring(&mut self, _root: LinkedNode<'_>) -> Option<Ty> {
|
||||||
|
@ -538,17 +538,17 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_destruct_assign(&mut self, _root: LinkedNode<'_>) -> Option<Ty> {
|
fn check_destruct_assign(&mut self, _root: LinkedNode<'_>) -> Option<Ty> {
|
||||||
Some(Ty::None)
|
Some(Ty::Builtin(BuiltinTy::None))
|
||||||
}
|
}
|
||||||
fn check_expr_in(&mut self, span: Span, root: LinkedNode<'_>) -> Ty {
|
fn check_expr_in(&mut self, span: Span, root: LinkedNode<'_>) -> Ty {
|
||||||
root.find(span)
|
root.find(span)
|
||||||
.map(|node| self.check(node))
|
.map(|node| self.check(node))
|
||||||
.unwrap_or(Ty::Undef)
|
.unwrap_or(Ty::Builtin(BuiltinTy::Undef))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_pattern(&mut self, pattern: ast::Pattern<'_>, value: Ty, root: LinkedNode<'_>) -> Ty {
|
fn check_pattern(&mut self, pattern: ast::Pattern<'_>, value: Ty, root: LinkedNode<'_>) -> Ty {
|
||||||
self.check_pattern_(pattern, value, root)
|
self.check_pattern_(pattern, value, root)
|
||||||
.unwrap_or(Ty::Undef)
|
.unwrap_or(Ty::Builtin(BuiltinTy::Undef))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_pattern_(
|
fn check_pattern_(
|
||||||
|
|
|
@ -160,6 +160,15 @@ impl<'a> Iterator for UnionIter<'a> {
|
||||||
|
|
||||||
#[derive(Clone, Hash, PartialEq, Eq)]
|
#[derive(Clone, Hash, PartialEq, Eq)]
|
||||||
pub(crate) enum BuiltinTy {
|
pub(crate) enum BuiltinTy {
|
||||||
|
Clause,
|
||||||
|
Undef,
|
||||||
|
Content,
|
||||||
|
Space,
|
||||||
|
None,
|
||||||
|
Infer,
|
||||||
|
FlowNone,
|
||||||
|
Auto,
|
||||||
|
|
||||||
Args,
|
Args,
|
||||||
Color,
|
Color,
|
||||||
TextSize,
|
TextSize,
|
||||||
|
@ -185,6 +194,15 @@ pub(crate) enum BuiltinTy {
|
||||||
impl fmt::Debug for BuiltinTy {
|
impl fmt::Debug for BuiltinTy {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
BuiltinTy::Clause => f.write_str("Clause"),
|
||||||
|
BuiltinTy::Undef => f.write_str("Undef"),
|
||||||
|
BuiltinTy::Content => f.write_str("Content"),
|
||||||
|
BuiltinTy::Space => f.write_str("Space"),
|
||||||
|
BuiltinTy::None => f.write_str("None"),
|
||||||
|
BuiltinTy::Infer => f.write_str("Infer"),
|
||||||
|
BuiltinTy::FlowNone => f.write_str("FlowNone"),
|
||||||
|
BuiltinTy::Auto => f.write_str("Auto"),
|
||||||
|
|
||||||
BuiltinTy::Args => write!(f, "Args"),
|
BuiltinTy::Args => write!(f, "Args"),
|
||||||
BuiltinTy::Color => write!(f, "Color"),
|
BuiltinTy::Color => write!(f, "Color"),
|
||||||
BuiltinTy::TextSize => write!(f, "TextSize"),
|
BuiltinTy::TextSize => write!(f, "TextSize"),
|
||||||
|
@ -217,16 +235,16 @@ impl BuiltinTy {
|
||||||
|
|
||||||
pub fn from_builtin(builtin: Type) -> Ty {
|
pub fn from_builtin(builtin: Type) -> Ty {
|
||||||
if builtin == Type::of::<AutoValue>() {
|
if builtin == Type::of::<AutoValue>() {
|
||||||
return Ty::Auto;
|
return Ty::Builtin(BuiltinTy::Auto);
|
||||||
}
|
}
|
||||||
if builtin == Type::of::<NoneValue>() {
|
if builtin == Type::of::<NoneValue>() {
|
||||||
return Ty::None;
|
return Ty::Builtin(BuiltinTy::None);
|
||||||
}
|
}
|
||||||
if builtin == Type::of::<typst::visualize::Color>() {
|
if builtin == Type::of::<typst::visualize::Color>() {
|
||||||
return Color.literally();
|
return Color.literally();
|
||||||
}
|
}
|
||||||
if builtin == Type::of::<bool>() {
|
if builtin == Type::of::<bool>() {
|
||||||
return Ty::None;
|
return Ty::Builtin(BuiltinTy::None);
|
||||||
}
|
}
|
||||||
if builtin == Type::of::<f64>() {
|
if builtin == Type::of::<f64>() {
|
||||||
return Float.literally();
|
return Float.literally();
|
||||||
|
@ -235,7 +253,7 @@ impl BuiltinTy {
|
||||||
return Length.literally();
|
return Length.literally();
|
||||||
}
|
}
|
||||||
if builtin == Type::of::<Content>() {
|
if builtin == Type::of::<Content>() {
|
||||||
return Ty::Content;
|
return Ty::Builtin(BuiltinTy::Content);
|
||||||
}
|
}
|
||||||
|
|
||||||
BuiltinTy::Type(builtin).literally()
|
BuiltinTy::Type(builtin).literally()
|
||||||
|
@ -243,6 +261,15 @@ impl BuiltinTy {
|
||||||
|
|
||||||
pub(crate) fn describe(&self) -> &'static str {
|
pub(crate) fn describe(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
|
BuiltinTy::Clause => "any",
|
||||||
|
BuiltinTy::Undef => "any",
|
||||||
|
BuiltinTy::Content => "content",
|
||||||
|
BuiltinTy::Space => "content",
|
||||||
|
BuiltinTy::None => "none",
|
||||||
|
BuiltinTy::Infer => "any",
|
||||||
|
BuiltinTy::FlowNone => "none",
|
||||||
|
BuiltinTy::Auto => "auto",
|
||||||
|
|
||||||
BuiltinTy::Args => "args",
|
BuiltinTy::Args => "args",
|
||||||
BuiltinTy::Color => "color",
|
BuiltinTy::Color => "color",
|
||||||
BuiltinTy::TextSize => "text.size",
|
BuiltinTy::TextSize => "text.size",
|
||||||
|
@ -406,7 +433,7 @@ pub(super) fn param_mapping(f: &Func, p: &ParamInfo) -> Option<Ty> {
|
||||||
"stroke",
|
"stroke",
|
||||||
) => Some(Ty::Builtin(Stroke)),
|
) => Some(Ty::Builtin(Stroke)),
|
||||||
("page", "margin") => Some(Ty::Builtin(Margin)),
|
("page", "margin") => Some(Ty::Builtin(Margin)),
|
||||||
_ => None,
|
_ => Option::None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,8 +548,9 @@ mod tests {
|
||||||
fn test_map() {
|
fn test_map() {
|
||||||
let u = Ty::Var(TypeVar::new("u".into(), DefId(0)));
|
let u = Ty::Var(TypeVar::new("u".into(), DefId(0)));
|
||||||
let v = Ty::Var(TypeVar::new("v".into(), DefId(1)));
|
let v = Ty::Var(TypeVar::new("v".into(), DefId(1)));
|
||||||
let mapper_fn = Ty::Func(SigTy::new([u], None, None, Some(v.clone())).into());
|
let mapper_fn =
|
||||||
let map_fn = Ty::Func(SigTy::new([mapper_fn], None, None, Some(v)).into());
|
Ty::Func(SigTy::new([u], Option::None, Option::None, Some(v.clone())).into());
|
||||||
|
let map_fn = Ty::Func(SigTy::new([mapper_fn], Option::None, Option::None, Some(v)).into());
|
||||||
let _ = map_fn;
|
let _ = map_fn;
|
||||||
// println!("{map_fn:?}");
|
// println!("{map_fn:?}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -768,15 +768,7 @@ impl IfTy {
|
||||||
|
|
||||||
#[derive(Hash, Clone, PartialEq, Eq)]
|
#[derive(Hash, Clone, PartialEq, Eq)]
|
||||||
pub(crate) enum Ty {
|
pub(crate) enum Ty {
|
||||||
Clause,
|
|
||||||
Undef,
|
|
||||||
Content,
|
|
||||||
Any,
|
Any,
|
||||||
Space,
|
|
||||||
None,
|
|
||||||
Infer,
|
|
||||||
FlowNone,
|
|
||||||
Auto,
|
|
||||||
Boolean(Option<bool>),
|
Boolean(Option<bool>),
|
||||||
Builtin(BuiltinTy),
|
Builtin(BuiltinTy),
|
||||||
Value(Interned<InsTy>),
|
Value(Interned<InsTy>),
|
||||||
|
@ -802,15 +794,7 @@ pub(crate) enum Ty {
|
||||||
impl fmt::Debug for Ty {
|
impl fmt::Debug for Ty {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Ty::Clause => f.write_str("Clause"),
|
|
||||||
Ty::Undef => f.write_str("Undef"),
|
|
||||||
Ty::Content => f.write_str("Content"),
|
|
||||||
Ty::Any => f.write_str("Any"),
|
Ty::Any => f.write_str("Any"),
|
||||||
Ty::Space => f.write_str("Space"),
|
|
||||||
Ty::None => f.write_str("None"),
|
|
||||||
Ty::Infer => f.write_str("Infer"),
|
|
||||||
Ty::FlowNone => f.write_str("FlowNone"),
|
|
||||||
Ty::Auto => f.write_str("Auto"),
|
|
||||||
Ty::Builtin(t) => write!(f, "{t:?}"),
|
Ty::Builtin(t) => write!(f, "{t:?}"),
|
||||||
Ty::Args(a) => write!(f, "&({a:?})"),
|
Ty::Args(a) => write!(f, "&({a:?})"),
|
||||||
Ty::Func(s) => write!(f, "{s:?}"),
|
Ty::Func(s) => write!(f, "{s:?}"),
|
||||||
|
@ -872,6 +856,10 @@ impl Ty {
|
||||||
pub(crate) fn iter_union(e: impl IntoIterator<Item = Ty>) -> Self {
|
pub(crate) fn iter_union(e: impl IntoIterator<Item = Ty>) -> Self {
|
||||||
Ty::Union(Interned::new(e.into_iter().collect()))
|
Ty::Union(Interned::new(e.into_iter().collect()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn undef() -> Self {
|
||||||
|
Ty::Builtin(BuiltinTy::Undef)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_internable!(Ty,);
|
impl_internable!(Ty,);
|
||||||
|
@ -915,7 +903,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ty() {
|
fn test_ty() {
|
||||||
use super::*;
|
use super::*;
|
||||||
let ty = Ty::Clause;
|
let ty = Ty::Builtin(BuiltinTy::Clause);
|
||||||
let ty_ref = TyRef::new(ty.clone());
|
let ty_ref = TyRef::new(ty.clone());
|
||||||
assert_debug_snapshot!(ty_ref, @"Clause");
|
assert_debug_snapshot!(ty_ref, @"Clause");
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,22 +137,15 @@ impl TypeDescriber {
|
||||||
Ty::With(w) => {
|
Ty::With(w) => {
|
||||||
return self.describe(&w.sig);
|
return self.describe(&w.sig);
|
||||||
}
|
}
|
||||||
Ty::Clause => {}
|
Ty::Builtin(BuiltinTy::Content | BuiltinTy::Space) => {
|
||||||
Ty::Undef => {}
|
|
||||||
Ty::Content => {
|
|
||||||
return "content".to_string();
|
return "content".to_string();
|
||||||
}
|
}
|
||||||
// Doesn't provide any information, hence we doesn't describe it intermediately here.
|
// Doesn't provide any information, hence we doesn't describe it intermediately here.
|
||||||
Ty::Any => {}
|
Ty::Any | Ty::Builtin(BuiltinTy::Clause | BuiltinTy::Undef | BuiltinTy::Infer) => {}
|
||||||
Ty::Space => {}
|
Ty::Builtin(BuiltinTy::FlowNone | BuiltinTy::None) => {
|
||||||
Ty::None => {
|
|
||||||
return "none".to_string();
|
return "none".to_string();
|
||||||
}
|
}
|
||||||
Ty::Infer => {}
|
Ty::Builtin(BuiltinTy::Auto) => {
|
||||||
Ty::FlowNone => {
|
|
||||||
return "none".to_string();
|
|
||||||
}
|
|
||||||
Ty::Auto => {
|
|
||||||
return "auto".to_string();
|
return "auto".to_string();
|
||||||
}
|
}
|
||||||
Ty::Boolean(None) => {
|
Ty::Boolean(None) => {
|
||||||
|
|
|
@ -191,15 +191,7 @@ impl Mutator {
|
||||||
Ty::Var(..)
|
Ty::Var(..)
|
||||||
| Ty::Let(..)
|
| Ty::Let(..)
|
||||||
| Ty::Value(..)
|
| Ty::Value(..)
|
||||||
| Ty::Clause
|
|
||||||
| Ty::Undef
|
|
||||||
| Ty::Content
|
|
||||||
| Ty::Any
|
| Ty::Any
|
||||||
| Ty::None
|
|
||||||
| Ty::Infer
|
|
||||||
| Ty::FlowNone
|
|
||||||
| Ty::Space
|
|
||||||
| Ty::Auto
|
|
||||||
| Ty::Boolean(..)
|
| Ty::Boolean(..)
|
||||||
| Ty::Builtin(..) => mutator.mutate(ty, pol),
|
| Ty::Builtin(..) => mutator.mutate(ty, pol),
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,15 +153,7 @@ impl<'a, 'b> TypeSimplifier<'a, 'b> {
|
||||||
self.analyze(&v.field, pol);
|
self.analyze(&v.field, pol);
|
||||||
}
|
}
|
||||||
Ty::Value(_v) => {}
|
Ty::Value(_v) => {}
|
||||||
Ty::Clause => {}
|
|
||||||
Ty::Undef => {}
|
|
||||||
Ty::Content => {}
|
|
||||||
Ty::Any => {}
|
Ty::Any => {}
|
||||||
Ty::None => {}
|
|
||||||
Ty::Infer => {}
|
|
||||||
Ty::FlowNone => {}
|
|
||||||
Ty::Space => {}
|
|
||||||
Ty::Auto => {}
|
|
||||||
Ty::Boolean(_) => {}
|
Ty::Boolean(_) => {}
|
||||||
Ty::Builtin(_) => {}
|
Ty::Builtin(_) => {}
|
||||||
}
|
}
|
||||||
|
@ -237,15 +229,7 @@ impl<'a, 'b> TypeSimplifier<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ty::Value(v) => Ty::Value(v.clone()),
|
Ty::Value(v) => Ty::Value(v.clone()),
|
||||||
Ty::Clause => Ty::Clause,
|
|
||||||
Ty::Undef => Ty::Undef,
|
|
||||||
Ty::Content => Ty::Content,
|
|
||||||
Ty::Any => Ty::Any,
|
Ty::Any => Ty::Any,
|
||||||
Ty::None => Ty::None,
|
|
||||||
Ty::Infer => Ty::Infer,
|
|
||||||
Ty::FlowNone => Ty::FlowNone,
|
|
||||||
Ty::Space => Ty::Space,
|
|
||||||
Ty::Auto => Ty::Auto,
|
|
||||||
Ty::Boolean(b) => Ty::Boolean(*b),
|
Ty::Boolean(b) => Ty::Boolean(*b),
|
||||||
Ty::Builtin(b) => Ty::Builtin(b.clone()),
|
Ty::Builtin(b) => Ty::Builtin(b.clone()),
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,18 +71,7 @@ impl MutateDriver for SubstituteChecker {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ty::Value(..)
|
Ty::Value(..) | Ty::Any | Ty::Boolean(..) | Ty::Builtin(..) => return None,
|
||||||
| Ty::Clause
|
|
||||||
| Ty::Undef
|
|
||||||
| Ty::Content
|
|
||||||
| Ty::Any
|
|
||||||
| Ty::None
|
|
||||||
| Ty::Infer
|
|
||||||
| Ty::FlowNone
|
|
||||||
| Ty::Space
|
|
||||||
| Ty::Auto
|
|
||||||
| Ty::Boolean(..)
|
|
||||||
| Ty::Builtin(..) => return None,
|
|
||||||
_ => return None,
|
_ => return None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -98,7 +87,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ty() {
|
fn test_ty() {
|
||||||
use super::*;
|
use super::*;
|
||||||
let ty = Ty::Clause;
|
let ty = Ty::Builtin(BuiltinTy::Clause);
|
||||||
let ty_ref = TyRef::new(ty.clone());
|
let ty_ref = TyRef::new(ty.clone());
|
||||||
assert_debug_snapshot!(ty_ref, @"Clause");
|
assert_debug_snapshot!(ty_ref, @"Clause");
|
||||||
}
|
}
|
||||||
|
|
|
@ -701,10 +701,6 @@ fn type_completion(
|
||||||
log::info!("type_completion: {:?}", infer_type);
|
log::info!("type_completion: {:?}", infer_type);
|
||||||
|
|
||||||
match infer_type? {
|
match infer_type? {
|
||||||
Ty::Clause => return None,
|
|
||||||
Ty::Undef => return None,
|
|
||||||
Ty::Space => return None,
|
|
||||||
Ty::Content => return None,
|
|
||||||
Ty::Any => return None,
|
Ty::Any => return None,
|
||||||
Ty::Tuple(..) | Ty::Array(..) => {
|
Ty::Tuple(..) | Ty::Array(..) => {
|
||||||
ctx.snippet_completion("()", "(${})", "An array.");
|
ctx.snippet_completion("()", "(${})", "An array.");
|
||||||
|
@ -712,12 +708,6 @@ fn type_completion(
|
||||||
Ty::Dict(..) => {
|
Ty::Dict(..) => {
|
||||||
ctx.snippet_completion("()", "(${})", "A dictionary.");
|
ctx.snippet_completion("()", "(${})", "A dictionary.");
|
||||||
}
|
}
|
||||||
Ty::None => ctx.snippet_completion("none", "none", "Nothing."),
|
|
||||||
Ty::Infer => return None,
|
|
||||||
Ty::FlowNone => return None,
|
|
||||||
Ty::Auto => {
|
|
||||||
ctx.snippet_completion("auto", "auto", "A smart default.");
|
|
||||||
}
|
|
||||||
Ty::Boolean(_b) => {
|
Ty::Boolean(_b) => {
|
||||||
ctx.snippet_completion("false", "false", "No / Disabled.");
|
ctx.snippet_completion("false", "false", "No / Disabled.");
|
||||||
ctx.snippet_completion("true", "true", "Yes / Enabled.");
|
ctx.snippet_completion("true", "true", "Yes / Enabled.");
|
||||||
|
@ -738,6 +728,17 @@ fn type_completion(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ty::Builtin(v) => match v {
|
Ty::Builtin(v) => match v {
|
||||||
|
BuiltinTy::None => ctx.snippet_completion("none", "none", "Nothing."),
|
||||||
|
BuiltinTy::Auto => {
|
||||||
|
ctx.snippet_completion("auto", "auto", "A smart default.");
|
||||||
|
}
|
||||||
|
BuiltinTy::Clause => return None,
|
||||||
|
BuiltinTy::Undef => return None,
|
||||||
|
BuiltinTy::Space => return None,
|
||||||
|
BuiltinTy::Content => return None,
|
||||||
|
BuiltinTy::Infer => return None,
|
||||||
|
BuiltinTy::FlowNone => return None,
|
||||||
|
|
||||||
BuiltinTy::Path(p) => {
|
BuiltinTy::Path(p) => {
|
||||||
let source = ctx.ctx.source_by_id(ctx.root.span().id()?).ok()?;
|
let source = ctx.ctx.source_by_id(ctx.root.span().id()?).ok()?;
|
||||||
|
|
||||||
|
@ -852,16 +853,16 @@ fn type_completion(
|
||||||
ctx.snippet_completion("em", "${1}em", "Em length unit.");
|
ctx.snippet_completion("em", "${1}em", "Em length unit.");
|
||||||
let length_ty = Type::of::<Length>();
|
let length_ty = Type::of::<Length>();
|
||||||
ctx.strict_scope_completions(false, |value| value.ty() == length_ty);
|
ctx.strict_scope_completions(false, |value| value.ty() == length_ty);
|
||||||
type_completion(ctx, Some(&Ty::Auto), docs);
|
type_completion(ctx, Some(&Ty::Builtin(BuiltinTy::Auto)), docs);
|
||||||
}
|
}
|
||||||
BuiltinTy::Float => {
|
BuiltinTy::Float => {
|
||||||
ctx.snippet_completion("exponential notation", "${1}e${0}", "Exponential notation");
|
ctx.snippet_completion("exponential notation", "${1}e${0}", "Exponential notation");
|
||||||
}
|
}
|
||||||
BuiltinTy::Type(ty) => {
|
BuiltinTy::Type(ty) => {
|
||||||
if *ty == Type::of::<NoneValue>() {
|
if *ty == Type::of::<NoneValue>() {
|
||||||
type_completion(ctx, Some(&Ty::None), docs);
|
type_completion(ctx, Some(&Ty::Builtin(BuiltinTy::None)), docs);
|
||||||
} else if *ty == Type::of::<AutoValue>() {
|
} else if *ty == Type::of::<AutoValue>() {
|
||||||
type_completion(ctx, Some(&Ty::Auto), docs);
|
type_completion(ctx, Some(&Ty::Builtin(BuiltinTy::Auto)), docs);
|
||||||
} else if *ty == Type::of::<bool>() {
|
} else if *ty == Type::of::<bool>() {
|
||||||
ctx.snippet_completion("false", "false", "No / Disabled.");
|
ctx.snippet_completion("false", "false", "No / Disabled.");
|
||||||
ctx.snippet_completion("true", "true", "Yes / Enabled.");
|
ctx.snippet_completion("true", "true", "Yes / Enabled.");
|
||||||
|
@ -922,9 +923,9 @@ fn type_completion(
|
||||||
if let Value::Type(ty) = &v.val {
|
if let Value::Type(ty) = &v.val {
|
||||||
type_completion(ctx, Some(&Ty::Builtin(BuiltinTy::Type(*ty))), docs);
|
type_completion(ctx, Some(&Ty::Builtin(BuiltinTy::Type(*ty))), docs);
|
||||||
} else if v.val.ty() == Type::of::<NoneValue>() {
|
} else if v.val.ty() == Type::of::<NoneValue>() {
|
||||||
type_completion(ctx, Some(&Ty::None), docs);
|
type_completion(ctx, Some(&Ty::Builtin(BuiltinTy::None)), docs);
|
||||||
} else if v.val.ty() == Type::of::<AutoValue>() {
|
} else if v.val.ty() == Type::of::<AutoValue>() {
|
||||||
type_completion(ctx, Some(&Ty::Auto), docs);
|
type_completion(ctx, Some(&Ty::Builtin(BuiltinTy::Auto)), docs);
|
||||||
} else {
|
} else {
|
||||||
ctx.value_completion(None, &v.val, true, docs);
|
ctx.value_completion(None, &v.val, true, docs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -385,7 +385,7 @@ fn e2e() {
|
||||||
});
|
});
|
||||||
|
|
||||||
let hash = replay_log(&tinymist_binary, &root.join("vscode"));
|
let hash = replay_log(&tinymist_binary, &root.join("vscode"));
|
||||||
insta::assert_snapshot!(hash, @"siphash128_13:dc2b8fe3fd562e82e0ffb855267dac11");
|
insta::assert_snapshot!(hash, @"siphash128_13:48f876724231ca7cdbadce094856da60");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue