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/complete.rs | |
| parent | 2e039cb052fcb768027053cbf02ce396f6d7a6be (diff) | |
Autocomplete methods
Diffstat (limited to 'src/ide/complete.rs')
| -rw-r--r-- | src/ide/complete.rs | 15 |
1 files changed, 12 insertions, 3 deletions
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, + }) + } + } } } |
