qpl for VSCode
Editor support for qpl — the Quick Polars Query Language.
Features
Syntax highlighting
.qpl files get highlighting for comments (/), double-quoted strings with
escapes, symbols and symbol vectors (`a`b`c), integer / float / bool /
bool-vector literals, statement keywords (select, by, from, where,
over, order, asc, desc, distinct, limit, drop, update, delete),
builtin keywords (load, sink, cols, lazy, collect) and .qpl.*
builtin functions (.qpl.cfg), aggregates (sum, avg, count, round, ...),
cast types (f64$x), the operator functions ? $ :: ! #, join
operators (lj, ij, rj), the like glob-match operator, the IPC client
(hopen, await, dispatch/async dispatch — ipc feature), assignments,
function literals ({[x,y] ..} — braces and parameter names),
\d / \l / \1 / \port REPL lines, and the virtual i column. Plus line
comments, bracket matching and auto-closing pairs for {}, [], () and ".
Braces and indentation
Braces are matched, auto-closed and surroundable like brackets, but they
indent differently, because qpl's own continuation rule decides where a
function body ends: a line indented by a tab or 4+ spaces continues the
statement above it, so a function's closing } has to stay inside the body
indent. Outdenting it to the opening line's column — what an editor normally
does with } — makes the function unterminated and the script fails to parse.
So the closing brace is never auto-outdented: pressing Enter inside { }
indents the body and leaves } at that indent, and typing } on an indented
line leaves it where it is. The extension also pins editor.tabSize to 4 with
spaces for .qpl files, since a 2-space indent is below what the interpreter
counts as a continuation.
Completion & snippets
- Statement/builtin keywords and REPL commands (
\d, \1, \l, log) at the
start of a line; aggregates (sum, avg, round, rn, rank, ...)
everywhere.
- Cast type names (
f64, int, str, ...) right after $.
- Table names after
from / by / drop / collect / sink / load:
tables assigned or referenced in the open document, plus the configurable
qpl.demoTables (default trades, quotes).
- Variables assigned in the open document (
name: ...).
- Snippets:
sel, selby, upd, del, delcols, join, lazyp, cond,
over, fn, lambda.
Interactive REPL
- Ctrl+Enter (Cmd+Enter on macOS) in a
.qpl file runs the selection,
or the whole file when nothing is selected, in a persistent qpl REPL
terminal. State (tables, variables) carries across runs, like a Python REPL.
- Multi-line / multi-statement input is handed to the interpreter via
\l
(run-script), so its own continuation-folding and comment handling apply.
- Commands (Command Palette): qpl: Start REPL, qpl: Restart REPL,
qpl: Run File or Selection in REPL.
Finding the qpl binary
The extension resolves, in order:
- the
qpl.path setting, if set;
qpl on your PATH;
target/release/qpl or target/debug/qpl in the workspace;
cargo run --quiet --manifest-path <workspace>/Cargo.toml -- when a qpl
Cargo.toml is present (handy while hacking on qpl itself).
Set qpl.loadDemo to start the REPL with the demo trades / quotes tables.
Set qpl.demoTables to change which table names completion offers by default
(alongside whatever it finds in the open document).
Developing
cd tools/vscode
npm install
npm run compile # or: npm run watch
# then press F5 in VSCode to launch an Extension Development Host with the
# ../../examples folder open. `npm: compile` runs automatically before launch.
Packaging
vsce (Visual Studio Code Extensions) turns the folder into a distributable
.vsix:
npm install -g @vscode/vsce # one-time
vsce package # runs `npm run compile`, then writes qpl-<version>.vsix
vsce package reads package.json, runs the vscode:prepublish
script (tsc), bundles every file not excluded by .vscodeignore,
and validates the manifest. Install the result with Extensions view → ··· →
Install from VSIX… or code --install-extension qpl-<version>.vsix — no
Marketplace account needed.
To publish to the Marketplace you need a publisher matching an Azure DevOps
organisation and a Personal Access Token: vsce login <publisher> then
vsce publish.