Editors
Grav has editor support for VS Code, Neovim and JetBrains IDEs (CLion, IntelliJ and the rest). All of them use one index and language server written without dependencies, so they offer the same features.
Features
- Highlighting of the whole language: declarations, generics, function types, every import form,
use, namespaces,testblocks, number literals, string interpolation and format specs, raw and multi-line strings, character literals,T?andx!, labels, named arguments, and inline C with the C grammar; casts (x as Array<int>), lambdas and their parameters, enum variants, fields, decorators with named arguments,NaN/Infinity, and built-ins such asreflect,sizeof(int)andlong(x). VS Code, JetBrains and Neovim color the same constructs alike (tests/grammar.shchecks it). - Go to definition, following imports into the standard library, project paths and the
grav.tomldependencies of the open file's project: git packages from the cache at theirgrav.lockcommit, local{ path = ... }ones in their folder. On an import string, it opens the module. - Hover: a declaration's signature, its doc comment (the
//lines above it), and where it lives; for a keyword, type or built-in function, what it means and an example. On a local variable, its type, even where none is written:let xs: Array<int>, afor (row in rows)loop variable (row: Row), acatch (e: IoError)variable, a lambda parameter, acase Some(x):binding. - Inlay hints show the parameter's name before each literal argument (
area(width: 3, height: 4); off withgrav.inlayHints.parameterNames), and the types after each binding that does not write one (let names = new Array<string>()showsnames: Array<string>). The types come from the compiler (grav check --types, run on open and save) and are printed the way they are written in Grav:HashMap<string, any>,fn(int) -> string,long?,int[3]. Before the first check, and for code the compiler cannot check, they are read from the source where it shows them. - Completion of members (from the variable's type, including loop and lambda variables, with a generic class's type bound:
Array<int>.get()is anint, an OrbitUser.where(...)aQuery<User>), static members, namespace members, import paths, keywords and built-ins, plus snippets for common constructs (fn,class,match,test,ifnull, ...). Also:- after
reflect(User).theClassInfomembers (andFieldInfo,MethodInfothrough them:info.fields()[0].); - after
super.the base class's fields, methods and statics; - after
x asthe types the value converts to (numeric casts,"42" as int,d as DecimalthroughDecimal.from, a class'stoFloat(), base classes); - after
@the decorators the project uses; hovering one explains how to read it through reflection. - a class's properties (
get name() -> T/set name(v: T)) as one member each, with its type (and "read-only" without a setter);obj.namehas that type in hovers, inlay hints and further completion, and hoveringgetorsetexplains the accessor. Thepropsnippet writes a pair.
- after
- Methods on built-in values (std/types): after
n.,port.,"text".,maybe.orx., completion lists the std/types methods the value takes (n.toHex()isInteger.toHex(n)), without the value's own parameter and with their doc comments; a class instance also getsObject's for names it lacks (u.toMap()). Hover, signature help and go to definition work on these calls, and the types of their results, of conversion casts (d as Decimal,"42" as int) and of method values (Integer.compare:fn(int, int) -> int) show in hovers and inlay hints. - Signature help inside calls, opening on the overload that takes the arguments written so far.
- Outline and workspace symbols (including the standard library).
- Find references and rename by declaration: a local is renamed only in its function, a field or method only on its class (and where the receiver's type is known to be it), across files and local packages. Names from the standard library and installed packages are not renamed. Highlights mark a name's uses in the file, and Organize Imports sorts the imports (the standard library, then packages, then relative paths) and removes duplicates.
- Diagnostics from
grav check --jsonon open and save. (A compiler older than--typesstill gives diagnostics, without the compiler's types.) - Formatting with
grav fmt.
VS Code
Install the extension from editors/vscode/ (it is packaged as a .vsix):
code --install-extension editors/vscode/grav-lang-1.13.0.vsixCommands (Ctrl+Shift+P, then "Grav"): Run (Ctrl+Alt+R), Build, Run Tests (Ctrl+Alt+T), Check, Format, Show Generated C, Run/Test Project, New Project, Add Package, Install Packages. Settings: grav.compilerPath, grav.checkOnSave, grav.inlayHints.parameterNames.
Neovim
Add editors/nvim to the runtime path. .grav files get highlighting, indentation and the language server automatically (Node.js must be on PATH). Inlay hints are on in Neovim 0.10 and later; set vim.g.grav_inlay_hints = false to turn them off, or toggle them with vim.lsp.inlay_hint.enable(false). See editors/nvim/README.md.
JetBrains IDEs
editors/jetbrains/ builds a plugin that adds the TextMate grammar and starts the language server through the IDE's LSP support (available in the paid IDEs). See editors/jetbrains/README.md.
Other editors
Any editor with LSP support can run the server directly; it speaks LSP over standard input and output:
node editors/lsp/server.jsThe compiler is found through the GRAV_COMPILER environment variable or the compilerPath initialisation option (default: grav). The TextMate grammar in editors/vscode/syntaxes/ works in editors that read TextMate grammars.
Writing documentation comments
Editors show the // comment lines directly above a declaration when you hover over it, or a comment at the end of the declaration's own line:
import "std"
// The price after tax, rounded to cents.
fn withTax(price: float) -> float {
return Math.roundTo(price * 1.16, 2)
}
let retries: int = 3 // how many times to try before giving up
fn main() {
print(retries)
}