Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp: Add code lens support for evaluating rules #968

Merged
merged 1 commit into from
Aug 7, 2024
Merged

Conversation

anderseknert
Copy link
Member

@anderseknert anderseknert commented Aug 7, 2024

  • This is currently limited to VS Code clients, but may be extended to other clients too in the furure, if they can support it on their side.

  • Implementation wil recursively look for an input.json file and pick the one closest to the file evaluated, down to the level of the workspace root (if any file is found).

- This is currently limited to VS Code clients, but may be extended
  to other clients too in the furure, if they can support it on their
  side.

- Implementation wil recursively look for an `input.json` file and
  pick the one closest to the file evaluated, down to the level of
  the workspace root (if any file is found).

Signed-off-by: Anders Eknert <[email protected]>
"github.com/styrainc/regal/pkg/builtins"
)

func (l *LanguageServer) Eval(ctx context.Context, query string, input string) (rego.ResultSet, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason that the input is a string rather than an io.Reader/[]byte/any?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, just was the easy choice I guess, but I can look into changing that in the next PR 👍


responseResult := map[string]any{}

err = l.conn.Call(ctx, "regal/showEvalResult", responseParams, &responseResult)
Copy link
Member

Choose a reason for hiding this comment

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

We must use a custom event here as there is client code that will actually show this - rather than being in a generic message/location? Just checking I have that right.

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly! Client side code over here.

// purely by the LSP. Clients that are capable of handling the code lens callback
// should be added here though.
if l.clientIdentifier == clients.IdentifierVSCode {
initializeResult.Capabilities.CodeLensProvider = &types.CodeLensOptions{}
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps to come later, but something we can write to an result.json instead perhaps, but still show the command. (as discussed)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that'll come next!

@anderseknert anderseknert merged commit a318e6c into main Aug 7, 2024
3 checks passed
@anderseknert anderseknert deleted the code-lens branch August 7, 2024 09:36
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.

2 participants