Skip to content

Editors

SurrealQL editor support

SurrealDB publishes extensions that add SurrealQL to VS Code and to the JetBrains IDEs, and a language server that provides diagnostics, completion and hover to any editor that speaks the Language Server Protocol (LSP). To embed a SurrealQL editor in a web page, see SurrealQL in CodeMirror.

Files with the .surql and .surrealql extensions are treated as SurrealQL.

ToolGives youInstall from
VS Code extensionHighlighting, snippets, comment toggling, language server features, a Run code lens and a results panelVS Code Marketplace, Open VSX
JetBrains pluginHighlighting, language server features, a Run code lens and a grammar version pickerJetBrains Marketplace
Language serverDiagnostics, completion, hover, go-to-definition, references, rename, code actions and a headless check commandsurreal install lsp, GitHub releases, npm, crates.io
CodeMirror addonHighlighting, folding, indentation and a version linter for editors in a web pagenpm

The language server reads SurrealQL files and reports what it finds in them. The editor extensions start it for you. It provides:

  • Diagnostics for syntax errors, and for queries that disagree with the schema in your files, such as an unknown field or a field of the wrong type.

  • Completion for field names, record<table> types, built-in functions and statement keywords.

  • Hover with type information, function signatures and the permissions on a table.

  • Go-to-definition and references for tables, fields, functions and parameters.

  • Rename for functions defined in your files, and code actions for missing PERMISSIONS clauses.

  • Signature help, call hierarchy and a document outline of tables, fields, events, indexes and functions.

The server builds its picture of the schema from DEFINE statements in your workspace, from the connected database, or from both. A workspace scan skips files over 2 MB and indexes at most 5,000 .surql files.

With the surreal launcher, install it as the lsp component:

surreal install lsp

The server is also attached to each GitHub release as a binary for macOS (arm64), Linux (amd64 and arm64) and Windows (amd64). Rust projects can depend on the surrealql-language-server crate, and the WebAssembly build for browsers is the @surrealdb/surrealql-language-server npm package.

An editor starts the server over standard input and output, and the server writes nothing else to that channel:

surreal lsp stdio

Point any LSP client at that command for files with the .surql extension. The binary from a GitHub release does the same with surrealql-language-server stdio.

The same analysis runs without an editor, which suits CI jobs, pre-commit hooks and coding agents:

surreal lsp check queries/

Pass a directory or files. To check a file against the schema in another folder, add --workspace schema/. For a file that exists only in memory, use --stdin --stdin-filename <path>. A file that creates a record in a table that has no PERMISSIONS clause gives output like this:

Example output
queries/create.surql:1:8 warning[permission-unknown]: No explicit permission rule found for CREATE on `person`.
0 errors, 1 warning in 1 file

--json prints the diagnostics as one JSON document, each with a stable code such as permission-unknown, and --fail-on warning makes warnings fail the run too. The exit code says what happened:

Exit codeMeaning
0The check completed and nothing reached the --fail-on level, which is error by default.
1The check completed and found diagnostics at or above that level.
2The command was misused, or an input file could not be read.

Editors pass settings under a surrealql key, either as initialisation options or as workspace configuration. A table declared SCHEMALESS accepts fields that are not defined, so by default the server stays quiet about unknown fields and field types on it. The analysis.schemalessDiagnostics setting changes that:

ValueBehaviour
quietReports none of the schema-based diagnostics on a SCHEMALESS table. This is the default.
errorsReports only the two faults SurrealDB itself raises: a value of the wrong type and an unknown type name.
strictChecks a SCHEMALESS table in the same way as a SCHEMAFULL one.
Settings
{ "surrealql": { "analysis": { "schemalessDiagnostics": "errors" } } }

Use analysis.externalParams to list parameters that your application binds at run time, so that the server does not report them as undefined.

Note

The server reads function signatures from a catalogue built for a fixed SurrealDB release, and it does not recognise every type added in SurrealDB 4.0. In version 0.6.4, the i8 and f16 field types are reported as unknown-type errors although SurrealDB 4.0 accepts them. Treat that diagnostic as advice when you target a newer type, and check the statement against your server.

The SurrealQL extension adds SurrealQL to VS Code. Open the Extensions view, search for SurrealQL by SurrealDB, and select Install. From a terminal:

code --install-extension surrealdb.surrealql

Editors based on VS Code that use Open VSX, such as VSCodium, install it from there under the same name.

The extension provides:

  • Highlighting with a TextMate grammar, including SurrealQL inside Markdown code fences and JavaScript or TypeScript template literals.

  • Snippets for common statements.

  • Comment toggling that understands all three line comment markers, --, // and #.

  • Language server features. The extension downloads the server from GitHub on first use and caches it.

  • Run above each top-level statement in a .surql or .surrealql file, which runs that statement against the configured endpoint.

  • A SurrealQL Results panel with the last 50 executed queries, as a table or as JSON.

  • A status bar item showing the connection in use, which opens the settings when selected.

Settings live under the surrealql key:

SettingDefaultDescription
surrealql.lsp.enabletrueTurns the language server on or off.
surrealql.lsp.version"latest"Pins a language server release tag.
surrealql.lsp.binaryPath""Uses a local binary instead of the downloaded one.
surrealql.connection.endpoint"http://localhost:8000"HTTP endpoint that Run sends queries to.
surrealql.connection.namespace""Default namespace.
surrealql.connection.database""Default database.
surrealql.connection.username"root"User name for HTTP basic authentication.
surrealql.connection.passwordPassword for that user.
surrealql.connection.authContext"root"The level the user belongs to: root, namespace, database or record.
surrealql.inference.mode"both"Where the schema comes from: workspace, db or both.

A USE NS or USE DB statement in a file overrides the namespace and database settings for the statements that follow it.

To connect a coding agent in VS Code to SurrealDB, see Visual Studio Code in the agent setup pages.

The SurrealQL plugin works in IntelliJ IDEA, PyCharm, WebStorm, GoLand, RustRover, DataGrip and other IntelliJ-based IDEs from build 243 (2024.3) onwards. Open Settings, select Plugins, search the Marketplace tab for SurrealQL, and install the plugin by SurrealDB.

The plugin provides:

  • Highlighting from the same TextMate grammar as the VS Code extension.

  • Language server features through the LSP4IJ plugin, on which it depends.

  • A file icon for .surql and .surrealql files.

  • A Run code lens and a tool window for results, and a status bar widget that shows the connection.

The plugin downloads the newest published grammar when the IDE starts, and falls back to a copy bundled with the plugin when it is offline. To use an older grammar, for example after a highlighting regression, open Settings, Tools, SurrealQL, choose a version from the Version list and select Apply. The change takes effect without restarting the IDE.

Syntax grammars and editor integrations for Zed, Neovim, Helix and Emacs are in development in the SurrealDB GitHub organisation. They are not yet published as releases, so they are not covered here. Any of these editors can use the language server described above. For connecting a coding agent in Zed, see Zed.

SurrealDB Studio has its own SurrealQL editors, described in SurrealQL editors.

Was this page helpful?

Last updated