Releases: StyraInc/regal
v0.24.0
This release brings 4 new rules to Regal's linter as well as a number of improvements to the language server.
Rules
New Rule if-object-literal
This rule helps users avoid an error case where an object follows an if
. Typically this represents an incomplete rule.
allow if {}
Read the docs on if-object-literal
.
New Rule pointless-reassignment
Variables in Rego are immutable, so adding a new variable for an existing short variable only adds noise. Read the docs on pointless-reassignment
.
New Rule argument-always-wildcard
Sometimes, particularly after refactoring, a function argument is always a wildcard (_
):
my_func(name, _)
my_func("Alice", _)
This rule catches such cases as they typically offer an opportunity for further refactoring or an error where the argument should be used in one or more cases. Read the docs on argument-always-wildcard
.
New Rule annotation-without-metadata
Rules containing METADATA
annotation syntax without a METADATA
header will not be parsed and represents a likely mistake.
# description: allow allows
allow if {
# ... some conditions
}
Read the docs on annotation-without-metadata
.
New Rule var-shadows-builtin
Variables that share the name of a built-in group or function should be renamed to avoid confusion.
# variable `http` shadows `http.send` built-in function
allow if {
http := startswith(input.url, "http://")
# ...
}
Read the docs on var-shadows-builtin
.
Regal Language Server
Snippet Completions
We have extended the support for completions to add snippets for some
and every
. Both key:value and collection formats are supported.
Screen.Recording.2024-07-16.at.17.31.42.mov
Example Links on Keyword and Built-in Hover
We've been building out a new documentation section called 'Rego By Example'. We have detailed guides here for some of the common keywords and built-in functions. Users can now browse directly to these from their editors by hovering over supported keywords and functions.
Screen.Recording.2024-07-16.at.17.34.05.mov
Supported:
- Keywords
some
andevery
- Function Groups
io.jwt
,regex
,time
, andcontains
- (more coming soon!)
Suggestions for Variables in Local Scope
We've got lots of completions providers now, this new one suggestions previously defined local variables like this:
Project Housekeeping
Start-up Version Check
With much work going into keeping a regular stream of updates, we felt it was important to help users stay up-to-date. In this release we have laid the groundwork for this by having Regal consult the latest releases on GitHub at startup and reporting if the current version is now outdated.
Please see Remote Features for more information and for instructions on how to disable this.
Use OSSF Scorecard
The OpenSSF Scorecard evaluates open source projects against security best practices to identify potential risks and areas for improvement. In this release we have added a workflow to scan the project on a schedule.
New Contributors
Thanks @maruloop for your first contribution to the project in #865 - and for working on this reviewdog integration for our project.
Changelog
- 96246a3: Skip nil check (#819) (@charlieegan3)
- b6588dc: Cache rq binary (#820) (@charlieegan3)
- 90b2bcc: Check Regal version at start-up (#824) (@charlieegan3)
- 53dbce6: Don't call completion providers inside of comments (#831) (@anderseknert)
- 3af7d06: Don't suggest
if
orcontains
following import (#834) (@anderseknert) - e3e12a9: Fix markdown content rendering for Zed editor (#829) (@anderseknert)
- 34fc452: Rule:
if-object-literal
(#835) (@anderseknert) - 5901874: Better support rule head keyword completions (#836) (@charlieegan3)
- b24bde4: lsp: perform no operation when processing events for ignored files (#837) (@charlieegan3)
- fb0250c: Completion suggestions for variables in local scope (#840) (@anderseknert)
- d8dda73: build(deps): bump github.com/spf13/cobra from 1.8.0 to 1.8.1 (#842) (@dependabot[bot])
- 8dd71c8: Add support for ignored files in ls formatting (#845) (@charlieegan3)
- 1edfd88: Completion of locals in more places (#847) (@anderseknert)
- 1191c41: Better
default
suggestions (#848) (@anderseknert) - 7bf1c93: [lsp] Implement rulerefs in rego (#849) (@charlieegan3)
- e9a2ab6: Add more to docs on
prefer-some-in-iteration
(#851) (@anderseknert) - 0536573: Port Import provider to Rego (#853) (@charlieegan3)
- d3dad61: Fix
top-level-iteration
false positive with ref head vars (#854) (@anderseknert) - 39e57db: Clear the store when reloading config (#855) (@charlieegan3)
- 82fd171: More Rego completion providers (#858) (@anderseknert)
- 72f63aa: Precompute refs in file at update (#859) (@charlieegan3)
- 5cb412d: Drop print statement (#860) (@charlieegan3)
- f082b73: Improve performance of rulerefs (#861) (@charlieegan3)
- 0175ee4: Add new blog to README (#862) (@anderseknert)
- ec060ef: Add reviewdog/action-regal to the adopters file (#865) (@maruloop)
- 3b5b83e: docs: update adopters and roadmap (#866) (@anderseknert)
- 2fa61d7: Completions: package name suggested from any path component (#869) (@anderseknert)
- 6cebb1c: Add snippets provider (#870) (@anderseknert)
- 5a61015: Add snippet suggestion for metadata annotation (#871) (@anderseknert)
- 0dad5f0: OPA v0.66.0 (#873) (@anderseknert)
- 300eef2: perf: refactor to avoid excessive
walk
ing (#877) (@anderseknert) - ce8b8ff: Rule:
pointless-reassignment
(#878) (@anderseknert) - 23c3bf5: Docs: add separate page for language server features (#880) (@anderseknert)
- 67de577: Use OSSF scorecard (#884) (@anderseknert)
- 6b6ffc4: [StepSecurity] ci: Harden GitHub Actions (#885) (@step-security-bot)
- a4c96a4: Fix token permissions (#886) (@anderseknert)
- 8110bc5: Rule:
argument-always-wildcard
(#883) (@anderseknert) - 6153d57: Rule:
annotation-without-metadata
(#882) (@anderseknert) - 0ed98f9: build(deps): bump ossf/scorecard-action from 2.3.1 to 2.3.3 (#890) (@dependabot[bot])
- b412ac9: build(deps): bump actions/checkout from 4.1.1 to 4.1.7 (#892) (@dependabot[bot])
- 1e597c8: build(deps): bump github/codeql-action from 3.24.9 to 3.25.11 (#889) (@dependabot[bot])
- 7773c3c: build(deps): bump actions/upload-artifact from 3.pre.node20 to 4.3.3 (#891) (@dependabot[bot])
- b7c7385: Rule:
var-shadows-builtin
(#893) (@anderseknert) - 4ec7018: Fix negative number returned by rulerefs provider issue (#894) (@anderseknert)
- d000d21: Remove used refs completion provider (#896) (@anderseknert)
- bb790c5: Completions:
rulerefs
optimizations (#898) (@anderseknert) - 812ab2b: Fix bug causing
prefer-some-in-iteration
not to be reported (#902) (@anderseknert) - a18e386: Fix some
prefer-snake-case
violations not getting reported (#900) (@anderseknert) - 35d6703: build(deps): bump actions/upload-artifact from 4.3.3 to 4.3.4 (#903) (@dependabot[bot])
- 288d9c3: rule: Fix pointless issue when using with (#907) (@charlieegan3)
- bcfc9b7: Dependabot/go modules/GitHub.com/owenrumney/go sarif/v2 2.3.3 (#909) (@charlieegan3)
- a6e97af: docs: Update language server docs (#910) (@charlieegan3)
- 1efd82c: ls...
v0.23.1
This is a patch release containing a number of fixes. Most of the issues fixed in this release were not directly related to v0.23.0, but we simply don't like the idea of waiting for the next release to address known bugs.
Bugs fixed
- Ignore directives (like
# regal ignore:unresolved-import
) didn't work properly for aggregate rules (i.e. rules that require multiple files to determine if the rule is violated or not). That's now been fixed. Thanks @nejec for bringing this to our attention! - Fix missing rule type in the header of the unresolved-import rule documentation
- An empty
.regal/config.yaml
file would previously have Regal fail with an error. Now it'll simply print a warning and continue with the default configuration - Fix an issue in the language server where completion suggestions would sometimes repeat a word already typed in
- Remove an init call in the language server that would take ~100 milliseconds to process, even for commands that didn't make use of the language server (like
regal lint
) - The
regal lint --format json
would previously output errors as pretty-printed text rather than JSON. That has now been fixed. - The
textDocument/diagnostic
response from the language server is nownull
rather than an empty object. This solves an issue observed with the Neovim client.
Changelog
- 3bcdc33: docs: move code of conduct (#800) (@anderseknert)
- 69f4dcb: docs: set the rule type for unresolved-import (#804) (@charlieegan3)
- 29a9c85: docs: abs link for do.rq (#806) (@charlieegan3)
- e1ed668: Support ignore directives in aggregate rules (#809) (@anderseknert)
- 99f8463: lsp: Use text edit for builtins providers (#814) (@charlieegan3)
- 9091021: Use config.docs.resolve_url consistently (#813) (@anderseknert)
- c2ec08f: lint/fix: roll over empty config (#815) (@charlieegan3)
- 982d13b: lsp/refs: Just in time init for refs util (#816) (@charlieegan3)
- d0def34: cmd/lint: show JSON errors (#817) (@charlieegan3)
v0.23.0
This release adds 3 new linter rules to Regal, greatly improved completion suggestions in the language server, and a number of other improvements and fixes.
New rule: leaked-internal-reference
Category: bugs
Following the recently added style guide recommendation to use underscore prefixes to denote internal rules and functions, this was the first rule to help enforce that convention. The leaked-internal-reference
rule will flag any reference to a rule or function with an underscore prefix that is not defined in the same package:
package policy
import rego.v1
# this will be flagged, as `_allow` is considered internal to the `authz` package
allow if data.authz._allow
For more information, see the docs on leaked-internal-reference.
New rule: internal-entrypoint
Category: bugs
Rules annotated as entrypoints are public by definition and must not be prefixed with an underscore.
Avoid
package policy
import rego.v1
# METADATA
# entrypoint: true
_authorize if {
# some conditions
}
Prefer
package policy
import rego.v1
# METADATA
# entrypoint: true
allow if _authorize
_authorize if {
# some conditions
}
For more information, see the docs on internal-entrypoint.
New rule: ambiguous-scope
Category: idiomatic
The default scope for metadata annotating a rule is the rule
scope, which applies to the individual rule statement only. This default is sensible for a rule defined only once, but is somewhat ambiguous for a rule defined incrementally, like the allow
rule in the examples below. Was the intention really to annotate that single definition, or the rule as whole? Most likely the latter.
If only a single rule in a group of incremental rule definitions is annotated, it should have it's scope
set explicitly to either document
or rule
. If all incremental definitions are annotated, explicit scope: rule
is not required.
Avoid
# METADATA
# description: allow is true if the user is admin, or the requested resource is public
allow if user_is_admin
allow if public_resource
Prefer
# METADATA
# description: allow is true if the user is admin, or the requested resource is public
# scope: document
allow if user_is_admin
allow if public_resource
Or (scope rule
implied, but all incremental definitions annotated)
# METADATA
# description: allow is true if the user is admin
allow if user_is_admin
# METADATA
# description: allow is true if the requested resource is public
allow if public_resource
Or (scope rule
explicit)
# METADATA
# description: allow is true if the user is admin
# scope: rule
allow if user_is_admin
allow if public_resource
For more information, see the docs on ambiguous-scope.
For more information about the scope
metadata attribute, see the OPA docs.
Language server: Greatly improved completion suggestions
Last release introduced a minimal implementation of code completion, which means that the language server supports providing completion suggestions while editing Rego in an editor that supports the Regal languge server, such as VS Code using the OPA VS Code extension.
This release provides greatly improved completion suggestions, including:
- References to packages, rules and functions (both imported and complete references)
- Keywords like
import
,default
,contains
,if
- Completions on
input
attributes based on those previously used - Common rule names like
allow
anddeny
- New package names based on directory structure
- Many more suggestions based on the context of the cursor position
Using completion suggestions now feels like a total game changer for productivity, and we really recommend trying it out!
Other improvements
- Bump OPA version to v0.65.0
- Improve LSP implementation to better handle different clients
- Don't show completion suggestions for internal references outside of their package
- Show different types of icons in completion suggestions based on what's suggested
Docs
- Update README to reflect current LSP features
- Add new documentation page for integrating Regal in build pipelines (thanks @Parsifal-M!)
- Fix typo in messy-rule documentation (thanks @Parsifal-M!)
- Add instructions for installing Regal via asdf (thanks @smorimoto for providing the plugin!)
- Rename development.md -> CONTRIBUTING.md to align with convention
- Add SECURITY.md doc under
docs
directory
Bugs fixed
- Fixed false positive when importing
input
ordata
in ignored-import - Fix possible concurrent read of maps in completion provider
- Filter out ignored files in
regal fix
command (thanks @oren-zohar for reporting the issue!)
Breaking changes
These changes do not affect regular users of Regal, but possibly power users that have built their own custom rules relying on these helpers.
- Remove the
regal.json_pretty
built-in function. Users can now usejson.marshal_with_options
from OPA instead. - Remove the
ast.name
function in favor ofast.ref_to_string
Thank you to all contributors, community members and users! 🎉
If you have any questions, would like to discuss the release, or talk about Regal in general, you'll find us in the Styra Community Slack!
Changelog
- 0de5d4f: Use Go 1.22 (#737) (@anderseknert)
- e21051b: docs: update the readme with the lsp features (#738) (@charlieegan3)
- 153f9a0: Better align with specification based on Zed client testing (#741) (@anderseknert)
- c9d0868: lsp: ensure completion items is not null (#740) (@charlieegan3)
- eb30185: lsp: Identify Zed editor client (#742) (@charlieegan3)
- 87efaf1: fixes typo in messy rule docs (#744) (@Parsifal-M)
- 7b60e7c: Build pipeline docs (Github/Gitlab) (#743) (@Parsifal-M)
- f0875e3: Fix false positive when importing input/data in
ignored-import
(#747) (@anderseknert) - 10aa4b7: lsp: Add package/rule ref completions (#739) (@charlieegan3)
- e10ec82: Don't suggest completions for internal rules or functions (#754) (@anderseknert)
- 372185b: Use completion item kind table for completions icons (#756) (@anderseknert)
- 2275b89: Add completions for default and import keywords (#759) (@anderseknert)
- cf93614: lsp: Return copies of cache maps (#760) (@charlieegan3)
- cf030b4: cmd/fix: Filter files loaded for fixing (#762) (@charlieegan3)
- 285a12d: lsp/completions: Implement better package items (#763) (@charlieegan3)
- 48aa1db: lsp: Provide data ref completions in rules (#769) (@charlieegan3)
- 51bd977: lsp: completions for rule heads (#770) (@charlieegan3)
- 7ea6999: lsp: Show subpackage scope (#772) (@charlieegan3)
- e7a11ae: lsp: Rule head & input doc completion improvements (#773) (@charlieegan3)
- 51dd1f6: lsp: Enable common rule completions (#775) (@charlieegan3)
- 6c91202: OPA v0.65.0 (#777) (@anderseknert)
- 83ae84a: breaking: Remove
regal.json_pretty
built-in function (#785) (@anderseknert) - 2c095e6: Rule:
leaked-internal-reference
(#782) (@anderseknert) - 86c28d7: Rule:
internal-entrypoint
(#784) (@anderseknert) - 96329cf: Add asdf instructions (#786) (@anderseknert)
- d1799ae: Add info on Zed extension (#787) (@anderseknert)
- df57e69: lsp: Show docs for diagnostics in Zed (#789) (@charlieegan3)
- 3886d9d: Rename development.md -> CONTRIBUTING.md (#788) (@anderseknert)
- b4eaad3: Add basic security disclosure doc (#790) (@anderseknert)
- fdda4b5: lsp: implement used refs completions (#794) (@charlieegan3)
- f9e8949: build(deps): bump goreleaser/goreleaser-action from 5 to 6 (#796) (@dependabot[bot])
- 47c6247: Rule:
ambiguous-scope
(#795) (@anderseknert) - fdc479f: Prepare for goreleaser 2.0.0 (#797) (@anderseknert)
- 5f6e238: Refactor: remove
name
function in favor ofref_to_string
(#798) (@anderseknert) - 8...
v0.22.0
This is a release brings 3 new linter rules, as well as some exciting new features, improvements and fixes to both the linter and the language server.
New rule: impossible-not
Category: bugs
The impossible-not
rule will flag when the not
keyword is used to test a partial (multi-value) rule. Even when a set contains no values, it isn't considered "falsey", so using not
in that context is essentially a constant condition. This mistake is particularly common in tests:
package policy
import rego.v1
partial_rule contains item if {
# ...
}
package policy_test
import rego.v1
test_partial_rule if {
# This will now be flagged, as the not-condition is impossible
not partial_rule with input as {
# ...
}
}
Future versions of this rule may detect even more impossible not
conditions.
For more information, see the docs on impossible-not.
New rule: messy-rule
Category: style
Rules that are defined incrementally should be be placed in a sequence, and with no other rule definitions in between. The new messy-rule
linter will help identify such cases, and suggest a re-organization.
Avoid
package policy
allow if something
unrelated_rule if {
# ...
}
allow if something_else
Prefer
package policy
allow if something
allow if something_else
unrelated_rule if {
# ...
}
For more information, see the docs on messy-rule.
New rule: trailing-default-rule
Category: style
The new trailing-default-rule
linter will flag rules with default default
conditions where the default
assignment isn't placed before the other rules. Putting the default
rule first makes it easier to read the policy, knowing there's a default fallback condition for the rules requiring more complex conditions to be met.
Avoid
package policy
import rego.v1
allow if {
# some conditions
}
default allow := false
Prefer
package policy
import rego.v1
default allow := false
allow if {
# some conditions
}
For more information, see the docs on trailing-default-rule.
Language server: Code completion suggestions
The Regal language server now provides a minimal implementation of the code completion feature. This first implementation will help suggest package name based on directory structure, the rego.v1
import and built-in functions at certain locations. This provides a big productivity boost, as users no longer need to jump back to the OPA docs to find the built-in function they need.
More completion suggestions will follow in the next releases, like references to rules and functions. Stay tuned!
Other improvements
- The external-reference rule now detects more cases than previously (thanks @asleire for reporting this issue!)
- The
regal new rule
command now also creates an empty documentation template for the rule - The
regal fix
command now provides documentation for which rules it can fix - The language server will now send a warning back to the client if CRLF line endings are detected in a file (thanks @asleire for the suggestion!)
- The language server will now report parser errors on the whole line instead of just the first character, making them easier to spot
- The language server will now provide links to documentation for any error encountered that has corresponding docs
- Bump OPA version to v0.64.1
Bugs fixed
- Fix issues with loading config file on Windows
- Improve handling of inlay hints in files with parser errors
- Fix bug where
regal lint --profile
would report wrong metrics - Where needed, the language server now properly returns
null
instead of empty object, as per the specification (thanks @sspaink for raising that!) - The language server "find definition" feature now honors ignore directives found in the
.regal/config.yaml
file - Fix false positive in redundant-existence-check rule when the
with
keyword is used (thanks @asleire for reporting this issue!)
Changelog
- a106547: build(deps): bump golangci/golangci-lint-action from 5.0.0 to 5.1.0 (#692) (@dependabot[bot])
- 9a36acb: OPA v0.64.1 (#689) (@anderseknert)
- 32e995f: Use macos-13 for amd64 build (#690) (@anderseknert)
- 92eebc9: build(deps): bump golangci/golangci-lint-action from 5.1.0 to 5.3.0 (#694) (@dependabot[bot])
- 0c96e96: build(deps): bump golangci/golangci-lint-action from 5.3.0 to 6.0.0 (#697) (@dependabot[bot])
- f4eb0f8: Rule:
impossible-not
(#698) (@anderseknert) - f3daf4f: build(deps): bump golangci/golangci-lint-action from 6.0.0 to 6.0.1 (#702) (@dependabot[bot])
- 3abf326: lsp: Fix issue with parse error inlay hints (#701) (@charlieegan3)
- fc92818: lsp: URI to path conversions respect os.Separator (#703) (@charlieegan3)
- 904cb31: lsp: Rename lastValidLine variable (#704) (@charlieegan3)
- 2bda636: lsp: don't add "constant" to the document symbol description (#706) (@anderseknert)
- d826f64: report: Fix profile count aggregation (#707) (@charlieegan3)
- 2023f32: Add a few tasks for VS Code (#710) (@anderseknert)
- e225bda: Singe file
impossible-not
(#713) (@anderseknert) - 3e92381: Rule:
messy-rule
(#714) (@anderseknert) - 0b79d20: Add docs as part of
regal new rule
command (#715) (@anderseknert) - a5aa616: Rule:
trailing-default-rule
(#716) (@anderseknert) - 00ea15e: Send warning to client on CRLF line endings (#717) (@anderseknert)
- e9bc522: build(deps): bump github.com/fatih/color from 1.16.0 to 1.17.0 (#718) (@dependabot[bot])
- 6a17d1d: lsp/completions: Implement a minimal completions provider (#709) (@charlieegan3)
- 05098f2: lsp: Return null when no hover items (@charlieegan3)
- d54f730: Revert "lsp: Return null when no hover items" (@charlieegan3)
- f9065f6: Return
null
instead of empty structs (#721) (@anderseknert) - 85411cf: Some fixes for detecting external refs (#723) (@anderseknert)
- 8bd0650: lsp: parse errors lint whole line (#727) (@charlieegan3)
- e6056e5: docs: add docs for regal fix function (#726) (@charlieegan3)
- 1aa0f50: Various fixes (#730) (@anderseknert)
- 9d7530a: lsp: show correct opa error hint links (#728) (@charlieegan3)
- d1525ce: lsp: find definition should honor ignored files (#732) (@anderseknert)
- 1b0e3fa: Fix false positive in
redundant-existence-check
whenwith
is used (#734) (@anderseknert) - 2ca2df8: Update capabilities.json (#735) (@anderseknert)
- 9d148de: lsp: Fix ast error line index bug (#736) (@charlieegan3)
v0.21.3
No one wants to wait for bugs to get fixed! So we don't. This third patch release following v0.21.0 fixes an issue where deleted or renamed files would still have violations reported by the language server.
Changelog
- e170834: fix: Avoid panic in config finder (#686) (@anderseknert)
- 51c9a94: fix: make sure deleted items aren't added back to the cache (#685) (@anderseknert)
v0.21.2
This is patch release addressing two bugs reported by users.
The first bug fixed is in the new unresolved-import rule, where Regal would mistakenly report a reference to a map-generating rule as unresolved. Thanks @nevumx for making us aware of that issue!
The other bug fixed was a panic that could occur when Regal traverses directories looking for a config file. The cause of this is still not known, but at least we'll now fail gracefully and without a panic. Thanks @scoop96 for reporting the issue!
Changelog
- 0cb54f0: Fix false positive in
unresolved-import
and map rules (#680) (@anderseknert) - e42be60: build(deps): bump golangci/golangci-lint-action from 4.0.0 to 5.0.0 (#683) (@dependabot[bot])
- 0c3043d: Avoid panic when searching for
.regal/config.yaml
(#684) (@anderseknert)
v0.21.1
This patch releases fixes an issue in the language server, which would previously send back an error to the client (i.e. your editor) when a new and empty file was created in the workspace. This would have the server fail to read any document symbols as a result. This has now been fixed to only log the error on the server without sending it back to the client.
Thanks @johanfylling for reporting the issue!
Changelog
- 03c38aa: lsp: More graceful shutdown (#676) (@charlieegan3)
- 55a1294: fix: log but don't send back file read errors in documentSymbol handle (#678) (@anderseknert)
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)
v0.20.1
v0.20.0
This release adds various improvements to the functionality of the language server as well as also including a number of housekeeping updates and fixes.
Language Server: Hover support for built-in function definitions
The language server protocol supports requesting information about the tokens under the cursor. This release implements support for such requests when users are hovering over Rego's built-in functions. Clicking the link in the tooltip heading will take you to the OPA docs for that built-in.
Language Server: Inlay Hints
Inlay Hint requests are also supported from this release. Inlay hints are allow named function arguments to be shown as users edit function calls.
Improvements
- Running the language server with
--verbose
will now show the full request response logs. - File ignore config is now also supported by the language server.
- Unresolved imports are not flagged as part of
prefer-package-imports
Updates
- This release updates OPA to v0.63.0, see the OPA changelog for more detail.
- Go SARIF has also been updated to 2.3.1
Changelog
- 3568183: docs: Add note about nvim-lspconfig (#604) (@charlieegan3)
- 9a670bf: build(deps): bump github.com/owenrumney/go-sarif/v2 from 2.3.0 to 2.3.1 (#606) (@dependabot[bot])
- 45705ca: Don't flag unresolved imports in
prefer-package-imports
(#607) (@anderseknert) - 1f2b72f: docs: use 4 spaces for indentation in
circular-imports
docs (#612) (@anderseknert) - 9200ad1: Publish binaries from build workflow (#610) (@anderseknert)
- 3f0c1bc: OPA v0.63.0 (#614) (@anderseknert)
- b5de824: lsp:
textDocument/hover
implementation (#617) (@anderseknert) - 155d8f5: lsp: Missing built-in data is not a hard error (#619) (@charlieegan3)
- 9081abf: lsp: Support file ignore config (#620) (@charlieegan3)
- 4d7cbe1: lsp: add inlay hint support (#621) (@anderseknert)
- 6df97b3: lsp: Make verbose logging configurable (#623) (@charlieegan3)