Refingere for VS Code
Language support for .rfn files, from the compiler itself (src/lsp/). Each file is checked
with the project around it - its own folder, and each folder above it that has .rfn files too -
so one open folder can hold several projects. It runs on Bun, like the
compiler - set refingere.bunPath if Bun isn't on your PATH.
- Errors as you type, in every file of the open folder - type errors included.
- Macros that add definitions: what derive and program macros give is known too - the
bundled compiler runs them in the background, again on each save, so a method a
@derive adds
or a function a @programMacro writes isn't reported missing; go to definition on one leads to
the macro.
- Navigation: the outline, go to definition (F12), find all references (Shift+F12,
Shift+Alt+F12) with a count over each definition ("3 references", click it to peek), every
use of the name under the cursor highlighted, and Ctrl+T to jump to any definition in the
folder. It reaches functions, types, locals,
&context values (their injects, rejects and
@requires too), and members through a value's type - c.area(), p.x, Shape.Dot. A
builtin (a type, a method, &stdout, @require, an operator) goes to its line in core.md.
- Rename (F2), everywhere a name is used - adding backticks when the new name needs them,
and spelling out
inject x when its two names part.
- Hover: a definition with its
/// comment, a value's type, and where a context value is
injected. Builtins, keywords and operators show their description from the reference, with a
link to their card on language.refingere.org.
- Completion - of the members of what's before a
. too, and of other folders' global
definitions, their `/folder/name` path written in.
- Hints: a
let's inferred type after its name, and the parameters of the call you're
writing.
- Quick fixes: the
@require a function is missing (Ctrl+.), one at a time or every one in
the file.
- Expanding macros in place: Expand Macro (the context menu, the command palette, or
Ctrl+. on a use) replaces one use with what it gives, one level deep; Expand All Macros in
File does every one in the file. One undo takes it back.
- Tests: every
@test in the Testing view, run one, a file's or a project's at a time - with
the bundled command line's --test-name=.
- Debugging: F5 in a
.rfn file - or a Refingere configuration in launch.json - runs the
program under VS Code's debugger, with breakpoints on lines of Refingere, stepping, the call
stack and the locals. "test": true debugs the @tests instead of the @main, and "args" is
what the program is run with. The program is built to JavaScript with a source map back to your
files and run by VS Code's own JavaScript debugger, so Node has to be installed.
- Formatting (Shift+Alt+F, or on every save with
"[refingere]": { "editor.formatOnSave": true }), which only ever moves whitespace, and checks the result still means the same.
Refingere: Format All Files formats every .rfn file in the open folder.
And syntax highlighting - the grammar's at first, then the compiler's own (semantic tokens, mapped
onto the same colors): keywords, definitions, strings and string macros
(#format"... #{ expr } ..."), embedded languages (#SQL {{{ ... }}} is highlighted as SQL,
likewise #HTML, #CSS, #SVG, #JSON, #YAML, #MARKDOWN and #SHELL), attributes, context values
(&stdout), paths, numbers and operators. Also comment toggling (///, /* */), bracket
matching and auto-closing, and the Refingere logo as the file icon for .rfn files - orange for .test.rfn ones (shown by
any file icon theme that doesn't have its own icon for them, like the default Seti).
Unicode symbols
The symbol operators with a Unicode spelling - != <= >= / as ≠ ≤ ≥ ÷ -
and := as ≔ can be switched over as you go. * is left as it is: × is for the cross product
of vectors (type it with \times).
- As you type: a space typed right after one replaces it (on-type formatting, turned on for
.rfn files; refingere.unicode.replaceAsYouType turns it off).
- Suggestions: each ASCII one gets a faint hint, with a quick fix (Ctrl+.) to replace it
(
refingere.unicode.suggest hides them).
- All at once: Refingere: Use Unicode Symbols replaces every one in the selection, or the
whole file with nothing selected. It's also the
source.useUnicodeSymbols source action, so
"editor.codeActionsOnSave": { "source.useUnicodeSymbols": "explicit" } does it on save.
- Backslash abbreviations:
\ne \le \ge \times \div, the word operators'
\and \or \xor \iff \not, \coloneq for ≔, \lambda for λ, \sqrt for √,
and \^2 / \_i for superscripts and subscripts - pick one from the completion list.
Strings, comments and macro bodies are never touched.
Color themes
Refingere Light and Refingere Dark match the docs site's code blocks: keywords in bold
purple, names in indigo, strings and numbers in teal, on the same gray backgrounds. Pick one with
Preferences: Color Theme (Ctrl+K Ctrl+T). They color other languages too, including the ones
embedded in #SQL {{{ ... }}} and friends. The colors are Tailwind's, as the docs use them -
regenerate after the docs' palette changes with bun editors/vscode/build-themes.ts.
Install
Download refingere.vsix - the whole
extension in one file - and drag it onto VS Code's Extensions view, or install it from the command
line. A newer file installs the same way, replacing the old version:
code --install-extension refingere.vsix
Or build it from the repository:
bun run vscode:package # from the repository root - editors/vscode/refingere-<version>.vsix
code --install-extension editors/vscode/refingere-<version>.vsix
Or, while working on the extension itself, bundle its code and link this folder into VS Code's
extensions folder, then reload the window:
bun editors/vscode/build.ts # dist/extension.js and dist/server.js - again after each change
ln -s "$(pwd)/editors/vscode" ~/.vscode/extensions/refingere
Keeping it in sync
The grammar in syntaxes/ is generated from the docs' Keyword Index
(docs/src/lib/index/keywords.ts) - the same word lists the docs site highlights with. After a
keyword, type or embedded language is added to the docs, regenerate it:
bun editors/vscode/build-grammar.ts
grammar.test.ts fails while the committed grammar is out of date.
The language server
src/extension.ts starts the language server, the repository's src/lsp/server.ts, and connects
VS Code to it. bun run vscode:package bundles both into dist/ first (see build.ts), so the
.vsix needs nothing else installed but Bun.