v0.21.0
This is a big release, bringing new regal fix
command, several features to the Regal language server, a new linter rule, and many improvements and fixes.
New command: regal fix
The regal fix
command allows you to automatically fix some of the (style) issues reported by the Regal linter. This command is available in the CLI and can be run on a single file or a directory. The following linter rules are supported by the regal fix
command:
More rules will be added in future releases.
The regal fix
command respects the .regal/config.yaml
file, and will only fix issues that aren't ignored by configuration.
New rule: unresolved-import
Category: imports
OPA does not resolve imports until runtime, and when it does, unresolved imports are simply undefined. The unresolved-import rule helps catch these issues early by flagging imports that can't be statically resolved by Regal. Since imports could refer to data documents or rules imported at runtime, this linter rule allows providing a list of of references that should be ignored by the linter.
For more information, see the docs on unresolved-import.
Language Server: Code Actions
Similarly to the regal fix
command, code actions allows fixing some issues reported by Regal but directly from the editor. This release adds code actions to remediate the following linter rules:
- opa-fmt
- use-rego-v1
- use-assignment-operator
- no-whitespace-comment
- Navigate to documentation of any reported linter issue
Language Server: Go to Definition
Ctrl/cmd + clicking a reference in the editor now navigates to the definition of the reference, as Regal now implements the "go to definition" feature of the language server protocol.
Language Server: Formatting
The Regal language server now supports formatting Rego files using the opa fmt
command. This can be triggered either by running the "Format document" command in your editor, or from where a opa-fmt
linter violation is reported in the package.
Language Server: Document Symbols
Symbols — like packages, rules and functions, are now provided by Regal upon requests from an editor. This allows for a quick overview of the structure of a Rego file, and provides "breadcrumbs" to navigate the symbols of an open Rego document.
Language Server: Workspace Symbols
Similarly to document symbols, Regal now reports symbols from the entire workspace, allowing users to search and navigate to any top-level symbol (i.e. package, rule or function) in the workspace.
Language Server: Folding Ranges
Regal now provides folding ranges for Rego files in the workspace, allowing users to fold (i.e. expand or collapse) blocks of code, comments and imports in the editor.
Other improvements
- The language server now searches for the
.regal/config.yaml
file in directories above the workspace if not found before. This allows using a shared configuration file for multiple projects. Thanks @bdjgs for requesting this feature! - Report not just the line but the exact position of use-assignment-operator violations
- The result of a hovering over a built-in function is now cached for faster rendering
Bugs fixed
- Fix bug where whitespace in directory names caused the language server to stop working. Thanks @frittsy for reporting this issue!
Documentation
- Fix wrong category of double-negative rule
Changelog
- de1ff4b: Code action for OPA fmt (#630) (@charlieegan3)
- 0f5b374: lsp: URI decode workspace URIs (#631) (@charlieegan3)
- 1255e7d: Refactor LSP logging (#632) (@charlieegan3)
- 128b5b4: Add quote from Jimmy Ray (#634) (@anderseknert)
- b5b6d56: Open docs code action (#635) (@charlieegan3)
- 5fbf293: Cache result of createHoverContent (#639) (@anderseknert)
- 37d87bf: rules: OPA fmt rule location fix (#633) (@charlieegan3)
- 6904ed9: Add code action for
use-rego-v1
(#640) (@anderseknert) - 8de5461: Implement textDocument/formatting (#641) (@anderseknert)
- 40ed03f: lsp: Accept but ignore cancelled requests (#642) (@charlieegan3)
- fe1dc3a: lsp: Enable formatting functionality (#643) (@charlieegan3)
- c31886e: lsp: Load config from parent dirs (#650) (@charlieegan3)
- ae359bf: Fix wrong category for
double-negative
rule (#652) (@anderseknert) - 8e253b4: Calculate correct column of
=
inuse-assignment-operator
(#655) (@anderseknert) - 63148df: Calculate column index from 1 in
use-assignment-operator
(#656) (@anderseknert) - 8c9b76b: lsp: Increase test buffered channel size (#657) (@charlieegan3)
- dfd9ee2: fixer: Regal fix command (#653) (@charlieegan3)
- 3e0fcd2: Rule:
unresolved-import
(#658) (@anderseknert) - c717dd6: lsp: fix flaky test (#660) (@charlieegan3)
- 5a8c5c1: lsp: refactor types (#662) (@charlieegan3)
- 8ae24da: lsp: Implement code actions for new fixes (#661) (@charlieegan3)
- c803b41: lsp: Support folding ranges (#663) (@anderseknert)
- 2a59305: lsp: handle
textDocument/documentSymbol
(#668) (@anderseknert) - f108c69: lsp: Error handling fixes (#669) (@charlieegan3)
- f546004: lsp: handle
textDocument/definition
requests (#664) (@anderseknert) - af1bdb8: Add LSP section to README (#674) (@anderseknert)
- 24c0b85: lsp: implement
workspace/symbol
(#673) (@anderseknert)