gnata-sqlite
Reference

Editor & LSP API

API reference for the CodeMirror 6 npm package, WASM exports, and native LSP server

Editor & LSP API

Two delivery modes from the same Go codebase:

  • Browser — TinyGo WASM module (380 KB / 145 KB gzipped)
  • Server — Native Go LSP server (stdio JSON-RPC)

CodeMirror API

jsonata(): LanguageSupport

Syntax highlighting only. No WASM required.

import { jsonata } from "@gnata-sqlite/codemirror"
// extensions: [basicSetup, jsonata()]

Provides: syntax highlighting, bracket matching, auto-close, code folding.

jsonataFull(config?): LanguageSupport

Full support: highlighting + diagnostics + autocomplete + hover.

import { jsonataFull, initWasm } from "@gnata-sqlite/codemirror"

await initWasm("/gnata-lsp.wasm", "/lsp-wasm_exec.js")

new EditorView({
  extensions: [basicSetup, jsonataFull({ schema: '...' })],
  parent: document.getElementById("editor")!,
})
OptionTypeDescription
schemastringJSON schema for field autocompletion

initWasm(wasmUrl, execUrl): Promise<void>

Load the TinyGo WASM module. Call once before creating editors.

jsonataLint(): Extension

Standalone linter extension. Use with jsonata() for manual composition.

jsonataCompletion(config?): CompletionSource

Standalone autocompletion source.


Schema format

{
  "fields": {
    "Account": {
      "type": "object",
      "fields": {
        "Name": { "type": "string" },
        "Order": {
          "type": "array",
          "fields": {
            "OrderID": { "type": "string" },
            "Product": { "type": "object" },
            "Price": { "type": "number" }
          }
        }
      }
    }
  }
}

Flat rows:

{ "fields": { "id": { "type": "number" }, "name": { "type": "string" } } }

Autocomplete contexts

ContextSuggestions
After $Built-in function names (70+)
After .Schema fields at resolved path depth
Start of expressionTop-level schema fields + functions + keywords
After operatorsFields + functions + keywords

WASM exports (low-level)

FunctionSignatureReturns
_gnataDiagnostics(src)string → stringJSON array of {from, to, message}
_gnataCompletions(src, pos, schema)string, number, string → stringJSON array of completion items
_gnataHover(src, pos, schema)string, number, string → string|nullJSON {from, to, text} or null

Build tags

FilePurposeBuild constraint
main_wasm.gosyscall/js entry point//go:build js && wasm
main_lsp.gostdio JSON-RPC server//go:build !js
diagnostics.goParse errors → diagnosticsshared
completions.goContext-aware autocompleteshared
hover.goFunction documentationshared
funcinfo.goBuilt-in function catalogshared
schema.goSchema parsershared
marshal.goReflect-free AST serializershared

On this page