Skip to content

lsp/eval: Implement selection evaluation - #2104

Merged
anderseknert merged 1 commit into
open-policy-agent:mainfrom
charlieegan3:eval-selection
Oct 1, 2026
Merged

anderseknert merged 1 commit into
open-policy-agent:mainfrom
charlieegan3:eval-selection

Conversation

@charlieegan3

Copy link
Copy Markdown
Contributor

This makes it possible evaluate an editor selection rather than a rule/pkg.

See open-policy-agent/vscode-opa#504 for UI example.

@srenatus

Copy link
Copy Markdown
Contributor

Is this available to over LSP clients as-is? Or do they need special wrapper code like vscode-opa?

@srenatus srenatus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This makes it possible evaluate an editor selection rather than a
 rule/pkg.

Signed-off-by: Charlie Egan <charlie_egan@apple.com>
@charlieegan3

Copy link
Copy Markdown
Contributor Author

Yeah this needs a special wrapper to run evaluation as a custom command.

Comment thread internal/lsp/eval.go
// - 1 = x -> 1, resolved from the right-hand side: "=" can bind either side.
// - [a, b] := [1, 2] -> true, the raw expression value: neither side is a plain
// variable, so there is no single bound value to return.
func finalExpressionValue(body ast.Body, result rego.Result) any {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not know for certain that the result returned here will be an ast.Value (or possibly *ast.Term)?
I hope our eval machinery prevents the default AST -> Go "JSON" values transform, because if it doesn't, it should 😄 If so it would be nice if we made that type assertion in this function and rather had it return a Value (or again, a term pointer if that's what we get back).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into this and consider a follow on.

@anderseknert
anderseknert added this pull request to the merge queue Oct 1, 2026
Merged via the queue into open-policy-agent:main with commit d50b317 Oct 1, 2026
10 of 11 checks passed
@charlieegan3
charlieegan3 deleted the eval-selection branch October 5, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants