summaryrefslogtreecommitdiff
path: root/src/ide
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-01-28 15:35:56 +0100
committerLaurenz <laurmaedje@gmail.com>2023-01-28 15:36:32 +0100
commit4809e685a231a3ade2c78b75685ee859196c38c1 (patch)
treee3141236cca536c31c6ef4a6df6d218c16ba5a94 /src/ide
parent28c554ec2185a15e22f0408ce485ed4afe035e03 (diff)
More capable math calls
Diffstat (limited to 'src/ide')
-rw-r--r--src/ide/analyze.rs4
-rw-r--r--src/ide/complete.rs12
-rw-r--r--src/ide/highlight.rs25
3 files changed, 23 insertions, 18 deletions
diff --git a/src/ide/analyze.rs b/src/ide/analyze.rs
index a1ac5778..c170186f 100644
--- a/src/ide/analyze.rs
+++ b/src/ide/analyze.rs
@@ -7,7 +7,9 @@ use crate::World;
/// Try to determine a set of possible values for an expression.
pub fn analyze(world: &(dyn World + 'static), node: &LinkedNode) -> Vec<Value> {
match node.cast::<ast::Expr>() {
- Some(ast::Expr::Ident(_) | ast::Expr::MathIdent(_)) => {
+ Some(
+ ast::Expr::Ident(_) | ast::Expr::MathIdent(_) | ast::Expr::MethodCall(_),
+ ) => {
if let Some(parent) = node.parent() {
if parent.kind() == SyntaxKind::FieldAccess && node.index() > 0 {
return analyze(world, parent);
diff --git a/src/ide/complete.rs b/src/ide/complete.rs
index 83d0ca9c..83202e30 100644
--- a/src/ide/complete.rs
+++ b/src/ide/complete.rs
@@ -229,7 +229,7 @@ fn complete_math(ctx: &mut CompletionContext) -> bool {
}
// Behind existing atom or identifier: "$a|$" or "$abc|$".
- if matches!(ctx.leaf.kind(), SyntaxKind::MathAtom | SyntaxKind::MathIdent) {
+ if matches!(ctx.leaf.kind(), SyntaxKind::Text | SyntaxKind::MathIdent) {
ctx.from = ctx.leaf.offset();
math_completions(ctx);
return true;
@@ -274,7 +274,7 @@ fn complete_field_accesses(ctx: &mut CompletionContext) -> bool {
// Behind an expression plus dot: "emoji.|".
if_chain! {
if ctx.leaf.kind() == SyntaxKind::Dot
- || (matches!(ctx.leaf.kind(), SyntaxKind::Text | SyntaxKind::MathAtom)
+ || (ctx.leaf.kind() == SyntaxKind::Text
&& ctx.leaf.text() == ".");
if ctx.leaf.range().end == ctx.cursor;
if let Some(prev) = ctx.leaf.prev_sibling();
@@ -326,11 +326,15 @@ fn field_access_completions(ctx: &mut CompletionContext, value: &Value) {
}
}
_ => {
- for &method in methods_on(value.type_name()) {
+ for &(method, args) in methods_on(value.type_name()) {
ctx.completions.push(Completion {
kind: CompletionKind::Func,
label: method.into(),
- apply: Some(format_eco!("{method}(${{}})")),
+ apply: Some(if args {
+ format_eco!("{method}(${{}})")
+ } else {
+ format_eco!("{method}()${{}}")
+ }),
detail: None,
})
}
diff --git a/src/ide/highlight.rs b/src/ide/highlight.rs
index 7f7ad6ee..d8f15f00 100644
--- a/src/ide/highlight.rs
+++ b/src/ide/highlight.rs
@@ -1,4 +1,4 @@
-use crate::syntax::{LinkedNode, SyntaxKind};
+use crate::syntax::{ast, LinkedNode, SyntaxKind};
/// Syntax highlighting categories.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
@@ -115,19 +115,17 @@ pub fn highlight(node: &LinkedNode) -> Option<Category> {
SyntaxKind::Formula => None,
SyntaxKind::Math => None,
- SyntaxKind::MathAtom => None,
SyntaxKind::MathIdent => highlight_ident(node),
SyntaxKind::MathDelimited => None,
SyntaxKind::MathAttach => None,
SyntaxKind::MathFrac => None,
SyntaxKind::MathAlignPoint => Some(Category::MathOperator),
- SyntaxKind::Hashtag if node.before_error() => None,
SyntaxKind::Hashtag => node
- .next_leaf()
- .filter(|node| node.kind() != SyntaxKind::Dollar)
- .as_ref()
- .and_then(highlight),
+ .next_sibling()
+ .filter(|node| node.cast::<ast::Expr>().map_or(false, |e| e.hashtag()))
+ .and_then(|node| node.leftmost_leaf())
+ .and_then(|node| highlight(&node)),
SyntaxKind::LeftBrace => Some(Category::Punctuation),
SyntaxKind::RightBrace => Some(Category::Punctuation),
@@ -248,12 +246,6 @@ pub fn highlight(node: &LinkedNode) -> Option<Category> {
/// Highlight an identifier based on context.
fn highlight_ident(node: &LinkedNode) -> Option<Category> {
match node.parent_kind() {
- Some(
- SyntaxKind::Markup
- | SyntaxKind::Math
- | SyntaxKind::MathFrac
- | SyntaxKind::MathAttach,
- ) => Some(Category::Interpolated),
Some(SyntaxKind::FuncCall) => Some(Category::Function),
Some(SyntaxKind::FieldAccess)
if node.parent().and_then(|p| p.parent_kind())
@@ -287,6 +279,13 @@ fn highlight_ident(node: &LinkedNode) -> Option<Category> {
{
Some(Category::Function)
}
+ Some(
+ SyntaxKind::Markup
+ | SyntaxKind::Math
+ | SyntaxKind::MathFrac
+ | SyntaxKind::MathAttach,
+ ) => Some(Category::Interpolated),
+ _ if node.kind() == SyntaxKind::MathIdent => Some(Category::Interpolated),
_ => None,
}
}