Format Document for KivaDB command files (.kva), and the mistakes KivaDB would report, shown as you type. By FomaDev.
KivaDB is a typed key-value, document and vector database in a single executable; .kva files hold its commands and run with kivadb run file.kva.
Shift+Alt+F (Shift+Option+F on macOS), or right-click → Format Document. To format on every save, add to your settings:
"[kva]": { "editor.formatOnSave": true }
Before:
# Data of the shop
SET parametre:devise "CDF"
set produit:001 {
"nom": "Riz",
"prix": 45000
} TTL 60
GET WHERE produit:*.prix>1000 AND (categorie="riz" OR stock<5) RETURN nom ,prix
create index on produit:( categorie ) USING HASH
After:
# Data of the shop
set parametre:devise "CDF"
set produit:001 {
"nom": "Riz",
"prix": 45000
} ttl 60
get where produit:*.prix > 1000 and (categorie = "riz" or stock < 5) return nom, prix
create index on produit: (categorie) using hash
What changes, and only what cannot change the meaning:
- one space between the words of a command; none before
, and ), none after (; spaces around the comparisons of a where (prix>1000 → prix > 1000);
- the case of KivaDB keywords, set by
kvaFormatter.keywordCase (lower, upper or preserve). Keys, fields and values keep theirs: in SET Index 1, Index is a key, and stays as it is;
- comments lose their indentation, lines their trailing spaces, runs of blank lines become one, and the file ends with one newline.
Strings, backtick keys, JSON documents (even over several lines) and the Lua code of eval '...' are kept exactly as written. Formatting twice gives the same file.
Problems as you type
Underlined where KivaDB would point, and listed in the Problems view:
| You wrote |
Problem |
setx a 1 |
Unknown command setx |
set capitale Kinshasa |
Text values must be quoted: "Kinshasa" |
set 44 1 |
A key cannot be purely numeric |
set get 1 |
get is a reserved keyword: write `get` |
set "nom" 1 |
Keys cannot use quotes |
set note "never closed |
Text never closed |
set doc { without its } |
Document never closed |
The checks only catch these common mistakes and never flag a command KivaDB accepts; the server stays the judge. kvaFormatter.lint: false turns them off.
Settings
| Setting |
Default |
Effect |
kvaFormatter.keywordCase |
lower |
lower, upper or preserve |
kvaFormatter.lint |
true |
Show the problems as you type |
Companion extensions
- KivaDB Language (
fomadev.kiva-kva): colours and snippets.
- KivaDB Runner (
fomadev.kiva-runner): run a file with kivadb run.
- KivaDB Tools (
fomadev.kiva-tools): completion, hovers, live connection.
Development
npm install
npm test # formatting and problems, on sample files
npx vsce package # builds kva-formatter-<version>.vsix
Press F5 in VS Code to try the extension in a new window.
Releasing. Add a ## <version> section to CHANGELOG.md, set the same version in package.json, commit, then:
git tag v1.0.0
git push origin v1.0.0
The Release workflow tests the extension, packages it and publishes a GitHub release with the .vsix and the notes of that version. Publishing on the Marketplace is manual: download the .vsix from the release, then upload it at https://marketplace.visualstudio.com/manage/publishers/fomadev.
License
Fordima Public License (FPL).