Skip to main content

Editor support

Visual Studio Code

vscode-opa - the official OPA extension for Visual Studio Code - now supports the Regal language server.

To see Regal linting as you work, install the extension at version 0.13.3 or later and open a workspace with Rego files.

The plugin will automatically find and use Regal config.

Debug Adapter Protocol (DAP)

From v0.17.0 onwards, the OPA extension for Visual Studio Code supports the Regal Debug Adapter.

To start a new debug session use the code action Debug found above a Rego rule or package.

Code Action in VS Code

Breakpoints can be added by clicking in the gutter to the left of the editor. Print statements will be shown in the debug console.

Zed

Zed is a modern open-source code editor with focus on performance and simplicity.

Zed supports Rego via Regal and the zed-rego extension developed by the Styra community. The extension provides syntax highlighting, linting, and most of the other language server features provided by Regal.

Neovim

Neovim supports both the Language Server Protocol and the Debug Adapter Protocol.

Generally, the Regal binary should be installed first. mason.vim users can install the Regal binary with :MasonInstall regal (package definition).

Language Server Protocol (LSP)

There are a number of different plugins available for Neovim which integrate with language servers using the Language Server Protocol.

Below are a number of different plugin options to configure a language server client for Regal in Neovim.

nvim-lspconfig

nvim-lspconfig has native support for the Regal language server. Use the configuration below to configure Regal:

require('lspconfig').regal.setup()

none-ls

none-ls - Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua.

Minimal installation via VimPlug

Plug 'nvim-lua/plenary.nvim'
Plug 'nvimtools/none-ls.nvim'

lua <<EOF
local null_ls = require("null-ls")
null_ls.setup {
sources = { null_ls.builtins.diagnostics.regal }
}
EOF

Using sample rego file test.rego with following content

package test

default allowRbac := true

Example of the diagnostics in as shown in the UI:

regal in none-ls

nvim-cmp

nvim-cmp supports the adding of language servers as a source.

To use Regal with nvim-cmp, it is recommended that you use the nvim-lspconfig source and follow the instructions above to configure nvim-lspconfig.

Other plugins

To see live linting of Rego, your plugin must support textDocument/diagnostic messages.

There are many language server integrations for Neovim, if you'd like to see another one listed, please open an issue or drop us a message in Slack.

Debug Adapter Protocol (DAP)

nvim-dap and nvim-dap-rego

nvim-dap is a DAP client implementation for Neovim. This plugin provides basic functions to control debuggers from Neovim.

nvim-dap-rego provides basic configurations for Regal's DAP interface.

To set up Regal's debugger,

require('dap-rego').setup()

Then you can launch debug sessions by calling :lua require('dap').continue().

Helix

The Helix editor comes with a default config that tries to use regols for Rego files. You can make it use Regal instead via this languages.toml config:

[[language]]
name = "rego"
scope = "source.rego"
roots = [".regal/config.yaml"]
file-types = ["rego"]
indent = { tab-width = 4, unit = "\t" }
comment-token = "#"
language-servers = [ { name = "regal" } ]

[language-server.regal]
command = "regal"
args = ["language-server"]
config = { provideFormatter = true }

See the languages docs for details.