Add expression and statement keywords to completion list

Fixes #76.
This commit is contained in:
Tad Hardesty 2020-07-03 17:03:47 -07:00
parent ee73b109f3
commit ea6966018e
2 changed files with 38 additions and 2 deletions

View file

@ -433,7 +433,6 @@ pub fn register_builtins(tree: &mut ObjectTree) -> Result<(), DMError> {
proc/md5(T);
proc/min(A,B,C/*,...*/);
proc/missile(Type,Start,End);
proc/new/*Type*/(Args); // special form
proc/newlist(A,B,C/*,...*/);
proc/nonspantext(Haystack,Needles,Start=1);
proc/num2text(N,SigFig=6, Radix); // +1 form, (N,SigFig) (N, Digits, Radix)

View file

@ -11,6 +11,43 @@ use dm::objtree::{TypeRef, TypeVar, TypeProc, ProcValue};
use crate::{Engine, Span, is_constructor_name};
use crate::symbol_search::contains;
static PROC_KEYWORDS: &[&str] = &[
// Implicit variables
"args",
"global",
"src",
"usr",
// Term
"null",
"as",
".",
"..",
"new",
// "list", "input", "locate", "pick" appear in builtin proc list
"call",
// Statement
"return",
"throw",
"while",
"do",
"if",
"else",
"for",
"var",
"set",
"spawn",
"switch",
"try",
"catch",
"continue",
"break",
"goto",
"del",
// "CRASH" appears in builtin proc list
];
fn item_var(ty: TypeRef, name: &str, var: &TypeVar) -> CompletionItem {
let mut detail = ty.pretty_path().to_owned();
if let Some(ref decl) = var.declaration {
@ -344,7 +381,7 @@ impl<'a> Engine<'a> {
// implicit proc vars
if proc_name.is_some() {
for &name in ["args", "global", "src", "usr"].iter() {
for &name in PROC_KEYWORDS.iter() {
if contains(name, query) {
results.push(CompletionItem {
label: name.to_owned(),