diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-01-27 16:09:35 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-01-27 16:09:35 +0100 |
| commit | a96141a3ea9d1b11ef4cdc924216d8979689e6f0 (patch) | |
| tree | 0192bdd4e63f3fb3c9172faae35bf8b08c8c957d /src/ide | |
| parent | 2e039cb052fcb768027053cbf02ce396f6d7a6be (diff) | |
Autocomplete methods
Diffstat (limited to 'src/ide')
| -rw-r--r-- | src/ide/analyze.rs | 2 | ||||
| -rw-r--r-- | src/ide/complete.rs | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/ide/analyze.rs b/src/ide/analyze.rs index d8925cfc..a1ac5778 100644 --- a/src/ide/analyze.rs +++ b/src/ide/analyze.rs @@ -22,6 +22,8 @@ pub fn analyze(world: &(dyn World + 'static), node: &LinkedNode) -> Vec<Value> { return tracer.finish(); } + Some(ast::Expr::Str(s)) => return vec![Value::Str(s.get().into())], + Some(ast::Expr::FieldAccess(access)) => { if let Some(child) = node.children().next() { return analyze(world, &child) diff --git a/src/ide/complete.rs b/src/ide/complete.rs index f4b9be5e..9302b552 100644 --- a/src/ide/complete.rs +++ b/src/ide/complete.rs @@ -3,7 +3,7 @@ use std::collections::{BTreeSet, HashSet}; use if_chain::if_chain; use super::{analyze, plain_docs_sentence, summarize_font_family}; -use crate::model::{CastInfo, Scope, Value}; +use crate::model::{methods_on, CastInfo, Scope, Value}; use crate::syntax::{ast, LinkedNode, Source, SyntaxKind, SyntaxNode}; use crate::util::{format_eco, EcoString}; use crate::World; @@ -271,7 +271,7 @@ fn math_completions(ctx: &mut CompletionContext) { /// Complete field accesses. fn complete_field_accesses(ctx: &mut CompletionContext) -> bool { - // Behind an identifier plus dot: "emoji.|". + // Behind an expression plus dot: "emoji.|". if_chain! { if ctx.leaf.kind() == SyntaxKind::Dot || (matches!(ctx.leaf.kind(), SyntaxKind::Text | SyntaxKind::MathAtom) @@ -325,7 +325,16 @@ fn field_access_completions(ctx: &mut CompletionContext, value: &Value) { ctx.value_completion(Some(name.clone()), value, None); } } - _ => {} + _ => { + for &method in methods_on(value.type_name()) { + ctx.completions.push(Completion { + kind: CompletionKind::Func, + label: method.into(), + apply: Some(format_eco!("{method}(${{}})")), + detail: None, + }) + } + } } } |
