@@ -138,6 +138,54 @@ Regal currently provides quick fix code actions for the following linter rules:
138
138
- [ use-assignment-operator] ( https://docs.styra.com/regal/rules/style/use-assignment-operator )
139
139
- [ no-whitespace-comment] ( https://docs.styra.com/regal/rules/style/no-whitespace-comment )
140
140
141
+ ### Code lenses (Evaluation)
142
+
143
+ The code lens feature provides language servers a way to add actionable commands just next to the code that the action
144
+ belongs to. Regal provides code lenses for doing ** evaluation** of any package or rule directly in the editor. This
145
+ allows for an extremely fast feedback loop, where you can see the result of writing of modifying rules directly as you
146
+ work with them, and without having to launch external commands or terminals. In any editor that supports code lenses,
147
+ simply press ` Evaluate ` on top of a package or rule declaration to have it evaluated. The result is displayed on the
148
+ same line.
149
+
150
+ <img
151
+ src={require('./assets/lsp/evalcodelens.png').default}
152
+ alt="Screenshot of evaluation performed via code lens"/>
153
+
154
+ Once evaluation has completed, the result is also pretty-printed in a tooltip when hovering the rule. This is
155
+ particularly useful when the result contains more data than can fit on a single line!
156
+
157
+ Note that when evaluating incrementally defined rules, the result reflects evaluation of the whole ** document** ,
158
+ not a single rule definition. To make this clear, the result will be displayed next to each definition of the
159
+ same rule.
160
+
161
+ In addition to showing the result of evaluation, the "Evaluate" code lens will also display the output of any
162
+ ` print ` calls made in rule bodies. This can be really helpful when trying to figure out _ why_ the rule evaluated
163
+ the way it did, or where rule evaluation failed.
164
+
165
+ <img
166
+ src={require('./assets/lsp/evalcodelensprint.png').default}
167
+ alt="Screenshot of evaluation with print call performed via code lens"/>
168
+
169
+ Policy evaluation often depends on ** input** . This can be provided via an ` input.json ` file which Regal will search
170
+ for first in the same directory as the policy file evaluated. If not found there, Regal will proceed to search each
171
+ parent directory up until the workspace root directory. It is recommended to add ` input.json ` to your ` .gitignore `
172
+ file so that you can work freely with evaluation in any directory without having your input accidentally commited.
173
+
174
+ #### Editor support
175
+
176
+ While the code lens feature is part of the LSP specification, the action that is triggered by a code lens
177
+ isn't necessarily part of the standard. The language server protocol does not provide a native method for requesting
178
+ evaluation, so Regal will handle that on its own, and differently depending on what the client supports.
179
+
180
+ - Currently, only the [ OPA VS Code extension] ( https://github.com/open-policy-agent/vscode-opa ) is capable of handling
181
+ the request to display evaluation results on the same line as the package or rule evaluated.
182
+ - [ Zed] ( https://github.com/StyraInc/zed-rego ) does not support the code lens feature at all at this point in time. As
183
+ soon as it does, Regal will provide them.
184
+ - Displaying the result of evaluation requires customized code in the client. Currently only VS Code has the required
185
+ modifications to handle this, and is thus the only editor to currently support "inline display" of the result.
186
+ For other editors that support the code lens feature, Regal will instead write the result of evaluation to an
187
+ ` output.json ` file.
188
+
141
189
## Unsupported features
142
190
143
191
See the
0 commit comments