diff options
Diffstat (limited to 'src/ide')
| -rw-r--r-- | src/ide/complete.rs | 30 | ||||
| -rw-r--r-- | src/ide/highlight.rs | 47 | ||||
| -rw-r--r-- | src/ide/tooltip.rs | 16 |
3 files changed, 46 insertions, 47 deletions
diff --git a/src/ide/complete.rs b/src/ide/complete.rs index bbc4115a..9e13fc8d 100644 --- a/src/ide/complete.rs +++ b/src/ide/complete.rs @@ -138,7 +138,7 @@ fn complete_params(ctx: &mut CompletionContext) -> bool { (SyntaxKind::Colon, _) => prev.prev_leaf(), _ => None, }; - if let SyntaxKind::Ident(param) = before_colon.kind(); + if let Some(param) = before_colon.cast::<ast::Ident>(); then { ctx.from = match ctx.leaf.kind() { SyntaxKind::Colon | SyntaxKind::Space { .. } => ctx.cursor, @@ -160,11 +160,11 @@ fn complete_params(ctx: &mut CompletionContext) -> bool { deciding.kind(), SyntaxKind::LeftParen | SyntaxKind::Comma - | SyntaxKind::Ident(_) + | SyntaxKind::Ident ); then { ctx.from = match deciding.kind() { - SyntaxKind::Ident(_) => deciding.offset(), + SyntaxKind::Ident => deciding.offset(), _ => ctx.cursor, }; @@ -192,9 +192,9 @@ fn complete_symbols(ctx: &mut CompletionContext) -> bool { // Behind half-completed symbol: "$arrow:|$". if_chain! { - if matches!(ctx.leaf.kind(), SyntaxKind::Atom(s) if s == ":"); + if matches!(ctx.leaf.kind(), SyntaxKind::Atom if ctx.leaf.text() == ":"); if let Some(prev) = ctx.leaf.prev_leaf(); - if matches!(prev.kind(), SyntaxKind::Ident(_)); + if matches!(prev.kind(), SyntaxKind::Ident); then { ctx.from = prev.offset(); ctx.symbol_completions(false); @@ -205,7 +205,7 @@ fn complete_symbols(ctx: &mut CompletionContext) -> bool { // Start of a symbol: ":|". // Checking for a text node ensures that "\:" isn't completed. if ctx.before.ends_with(':') - && matches!(ctx.leaf.kind(), SyntaxKind::Text(_) | SyntaxKind::Atom(_)) + && matches!(ctx.leaf.kind(), SyntaxKind::Text | SyntaxKind::Atom) { ctx.from = ctx.cursor; ctx.symbol_completions(needs_colon); @@ -213,7 +213,7 @@ fn complete_symbols(ctx: &mut CompletionContext) -> bool { } // An existing symbol: ":arrow:". - if matches!(ctx.leaf.kind(), SyntaxKind::Symbol(_)) { + if matches!(ctx.leaf.kind(), SyntaxKind::Symbol) { // We want to complete behind the colon, therefore plus 1. let has_colon = ctx.after.starts_with(':'); ctx.from = ctx.leaf.offset() + (has_colon as usize); @@ -225,12 +225,12 @@ fn complete_symbols(ctx: &mut CompletionContext) -> bool { if_chain! { if matches!( ctx.leaf.kind(), - SyntaxKind::Text(_) | SyntaxKind::Atom(_) | SyntaxKind::Ident(_) + SyntaxKind::Text | SyntaxKind::Atom | SyntaxKind::Ident ); if let Some(prev) = ctx.leaf.prev_leaf(); - if matches!(prev.kind(), SyntaxKind::Symbol(_)) || matches!( + if matches!(prev.kind(), SyntaxKind::Symbol) || matches!( prev.kind(), - SyntaxKind::Text(s) | SyntaxKind::Atom(s) if s == ":" + SyntaxKind::Text | SyntaxKind::Atom if prev.text() == ":" ); then { // We want to complete behind the colon, therefore plus 1. @@ -252,14 +252,14 @@ fn complete_markup(ctx: &mut CompletionContext) -> bool { // Start of an interpolated identifier: "#|". // Checking for a text node ensures that "\#" isn't completed. - if ctx.before.ends_with('#') && matches!(ctx.leaf.kind(), SyntaxKind::Text(_)) { + if ctx.before.ends_with('#') && matches!(ctx.leaf.kind(), SyntaxKind::Text) { ctx.from = ctx.cursor; ctx.expr_completions(true); return true; } // An existing identifier: "#pa|". - if matches!(ctx.leaf.kind(), SyntaxKind::Ident(_)) { + if matches!(ctx.leaf.kind(), SyntaxKind::Ident) { // We want to complete behind the hashtag, therefore plus 1. ctx.from = ctx.leaf.offset() + 1; ctx.expr_completions(true); @@ -298,14 +298,14 @@ fn complete_math(ctx: &mut CompletionContext) -> bool { } // Start of an interpolated identifier: "#|". - if matches!(ctx.leaf.kind(), SyntaxKind::Atom(s) if s == "#") { + if matches!(ctx.leaf.kind(), SyntaxKind::Atom if ctx.leaf.text() == "#") { ctx.from = ctx.cursor; ctx.expr_completions(true); return true; } // Behind existing atom or identifier: "$a|$" or "$abc|$". - if matches!(ctx.leaf.kind(), SyntaxKind::Atom(_) | SyntaxKind::Ident(_)) { + if matches!(ctx.leaf.kind(), SyntaxKind::Atom | SyntaxKind::Ident) { ctx.from = ctx.leaf.offset(); ctx.math_completions(); return true; @@ -331,7 +331,7 @@ fn complete_code(ctx: &mut CompletionContext) -> bool { } // An existing identifier: "{ pa| }". - if matches!(ctx.leaf.kind(), SyntaxKind::Ident(_)) { + if matches!(ctx.leaf.kind(), SyntaxKind::Ident) { ctx.from = ctx.leaf.offset(); ctx.expr_completions(false); return true; diff --git a/src/ide/highlight.rs b/src/ide/highlight.rs index 321bf9a6..cc502537 100644 --- a/src/ide/highlight.rs +++ b/src/ide/highlight.rs @@ -119,7 +119,6 @@ pub fn highlight(node: &LinkedNode) -> Option<Category> { _ => Category::Operator, }), SyntaxKind::Hat => Some(Category::MathOperator), - SyntaxKind::Amp => Some(Category::MathOperator), SyntaxKind::Dot => Some(Category::Punctuation), SyntaxKind::Eq => match node.parent_kind() { Some(SyntaxKind::Heading) => None, @@ -159,38 +158,38 @@ pub fn highlight(node: &LinkedNode) -> Option<Category> { SyntaxKind::As => Some(Category::Keyword), SyntaxKind::Markup { .. } - if node.parent_kind() == Some(&SyntaxKind::TermItem) + if node.parent_kind() == Some(SyntaxKind::TermItem) && node.next_sibling().as_ref().map(|v| v.kind()) - == Some(&SyntaxKind::Colon) => + == Some(SyntaxKind::Colon) => { Some(Category::ListTerm) } SyntaxKind::Markup { .. } => None, - SyntaxKind::Text(_) => None, + SyntaxKind::Text => None, SyntaxKind::Linebreak => Some(Category::Escape), - SyntaxKind::Escape(_) => Some(Category::Escape), - SyntaxKind::Shorthand(_) => Some(Category::Escape), - SyntaxKind::Symbol(_) => Some(Category::Escape), + SyntaxKind::Escape => Some(Category::Escape), + SyntaxKind::Shorthand => Some(Category::Escape), + SyntaxKind::Symbol => Some(Category::Escape), SyntaxKind::SmartQuote { .. } => None, SyntaxKind::Strong => Some(Category::Strong), SyntaxKind::Emph => Some(Category::Emph), - SyntaxKind::Raw(_) => Some(Category::Raw), - SyntaxKind::Link(_) => Some(Category::Link), - SyntaxKind::Label(_) => Some(Category::Label), - SyntaxKind::Ref(_) => Some(Category::Ref), + SyntaxKind::Raw { .. } => Some(Category::Raw), + SyntaxKind::Link => Some(Category::Link), + SyntaxKind::Label => Some(Category::Label), + SyntaxKind::Ref => Some(Category::Ref), SyntaxKind::Heading => Some(Category::Heading), SyntaxKind::ListItem => None, SyntaxKind::EnumItem => None, - SyntaxKind::EnumNumbering(_) => Some(Category::ListMarker), + SyntaxKind::EnumNumbering => Some(Category::ListMarker), SyntaxKind::TermItem => None, SyntaxKind::Math => None, - SyntaxKind::Atom(_) => None, + SyntaxKind::Atom => None, SyntaxKind::Script => None, SyntaxKind::Frac => None, - SyntaxKind::AlignPoint => None, + SyntaxKind::AlignPoint => Some(Category::MathOperator), - SyntaxKind::Ident(_) => match node.parent_kind() { + SyntaxKind::Ident => match node.parent_kind() { Some( SyntaxKind::Markup { .. } | SyntaxKind::Math @@ -202,9 +201,9 @@ pub fn highlight(node: &LinkedNode) -> Option<Category> { if node .parent() .and_then(|p| p.parent()) - .filter(|gp| gp.kind() == &SyntaxKind::Parenthesized) + .filter(|gp| gp.kind() == SyntaxKind::Parenthesized) .and_then(|gp| gp.parent()) - .map_or(false, |ggp| ggp.kind() == &SyntaxKind::FuncCall) + .map_or(false, |ggp| ggp.kind() == SyntaxKind::FuncCall) && node.next_sibling().is_none() => { Some(Category::Function) @@ -218,17 +217,17 @@ pub fn highlight(node: &LinkedNode) -> Option<Category> { Some(SyntaxKind::SetRule) => Some(Category::Function), Some(SyntaxKind::ShowRule) if node.prev_sibling().as_ref().map(|v| v.kind()) - == Some(&SyntaxKind::Show) => + == Some(SyntaxKind::Show) => { Some(Category::Function) } _ => None, }, - SyntaxKind::Bool(_) => Some(Category::Keyword), - SyntaxKind::Int(_) => Some(Category::Number), - SyntaxKind::Float(_) => Some(Category::Number), - SyntaxKind::Numeric(_, _) => Some(Category::Number), - SyntaxKind::Str(_) => Some(Category::String), + SyntaxKind::Bool => Some(Category::Keyword), + SyntaxKind::Int => Some(Category::Number), + SyntaxKind::Float => Some(Category::Number), + SyntaxKind::Numeric => Some(Category::Number), + SyntaxKind::Str => Some(Category::String), SyntaxKind::CodeBlock => None, SyntaxKind::ContentBlock => None, SyntaxKind::Parenthesized => None, @@ -259,7 +258,7 @@ pub fn highlight(node: &LinkedNode) -> Option<Category> { SyntaxKind::LoopContinue => None, SyntaxKind::FuncReturn => None, - SyntaxKind::Error(_, _) => Some(Category::Error), + SyntaxKind::Error => Some(Category::Error), } } diff --git a/src/ide/tooltip.rs b/src/ide/tooltip.rs index 62cb11c1..8c734bbb 100644 --- a/src/ide/tooltip.rs +++ b/src/ide/tooltip.rs @@ -18,12 +18,12 @@ pub fn tooltip(world: &dyn World, source: &Source, cursor: usize) -> Option<Stri /// Tooltip for a function or set rule name. fn function_tooltip(world: &dyn World, leaf: &LinkedNode) -> Option<String> { if_chain! { - if let SyntaxKind::Ident(ident) = leaf.kind(); + if let Some(ident) = leaf.cast::<ast::Ident>(); if matches!( leaf.parent_kind(), Some(SyntaxKind::FuncCall | SyntaxKind::SetRule), ); - if let Some(Value::Func(func)) = world.library().scope.get(ident); + if let Some(Value::Func(func)) = world.library().scope.get(&ident); if let Some(info) = func.info(); then { return Some(plain_docs_sentence(&info.docs)); @@ -60,8 +60,8 @@ fn named_param_tooltip(world: &dyn World, leaf: &LinkedNode) -> Option<String> { // Hovering over the parameter name. if_chain! { if leaf.index() == 0; - if let SyntaxKind::Ident(ident) = leaf.kind(); - if let Some(param) = info.param(ident); + if let Some(ident) = leaf.cast::<ast::Ident>(); + if let Some(param) = info.param(&ident); then { return Some(plain_docs_sentence(param.docs)); } @@ -69,9 +69,9 @@ fn named_param_tooltip(world: &dyn World, leaf: &LinkedNode) -> Option<String> { // Hovering over a string parameter value. if_chain! { - if let SyntaxKind::Str(string) = leaf.kind(); + if let Some(string) = leaf.cast::<ast::Str>(); if let Some(param) = info.param(&named.name()); - if let Some(docs) = find_string_doc(¶m.cast, string); + if let Some(docs) = find_string_doc(¶m.cast, &string.get()); then { return Some(docs.into()); } @@ -95,8 +95,8 @@ fn find_string_doc(info: &CastInfo, string: &str) -> Option<&'static str> { fn font_family_tooltip(world: &dyn World, leaf: &LinkedNode) -> Option<String> { if_chain! { // Ensure that we are on top of a string. - if let SyntaxKind::Str(string) = leaf.kind(); - let lower = string.to_lowercase(); + if let Some(string) = leaf.cast::<ast::Str>(); + let lower = string.get().to_lowercase(); // Ensure that we are in the arguments to the text function. if let Some(parent) = leaf.parent(); |
