#Heptio/ksonnet/vscode
To create completion items for a jsonnet source file, you might have to work with an incomplete or malformed source file. JSL should be able to handle this and still offer completion items.
local a = "a";
- Standard library (std)
- a
- expression items...
The scope for this location would include {std, a}. Because we know we are expecting an expression, we could generate a list of expression keywords.
std
is always in scope because the standard library is automatically importeda
comes from the bind defined in the local on line 1.
To make this work, the completer will need to know where the cursor is. In this case, the cursor is in the body of a local. due to local bind; expr
.
The document produces the following tokens:
- tmp/file11.jsonnet:1:1-6: local = local
- tmp/file11.jsonnet:1:7-8: IDENTIFIER = a
- tmp/file11.jsonnet:1:9-10: OPERATOR = =
- tmp/file11.jsonnet:1:11-14: STRING_DOUBLE = a
- tmp/file11.jsonnet:1:14-15: ";" = ;
- tmp/file11.jsonnet:2:1: end of file =
To parse this,
- Parse token 0. It is a
local
- Using the rules for
local
, the next token is abind
. A bind is aid = expr
orid([params]) = expr
. In this case tokens 1-3 identify the bind. - Token 4 is a
;
, so the following item should be an expression. Since it is blank, we should mark a syntax error at token 4.
The cursor is on line 2, column 1. We'll need to know what the parser expects at this point. Given the rules for a local, the parser is expecting an expression. Given our current scope, what expressions could we generate?
a
: from scopestd
: from scopeassert
: expression keyworderror
: expression keywordif
: expression keywordfunction
: expression keywordlocal
: expression keywordimport
: expression keywordimportstr
: expression keywordsuper
: expression keyword
These are organized in the following order:
- scope
- other