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

Add Debug Code Lens #1103

Merged
merged 1 commit into from
Sep 12, 2024
Merged

Add Debug Code Lens #1103

merged 1 commit into from
Sep 12, 2024

Conversation

anderseknert
Copy link
Member

Following the excellent work on debugger support by @johanfylling, this PR introduces a code lens for debugging, which triggers a command that simply returns a launch configuration where the package or rule clicked is set as the entrypoint.

The code lens provider is now also rewritten in Rego.

Copy link
Member

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

looks good to me

@@ -4,6 +4,7 @@
"OPA_EVAL_CAPABILITIES": "${workspacePath}/build/capabilities.json"
},
"opa.roots": [
"${workspaceFolder}/lab",
Copy link
Member

Choose a reason for hiding this comment

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

Is this related to the PR?

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, thanks! Removed. Although it is rather tricky to get it right with the "checkOnSave" feature when you want it outside of the main bundle but not the whole workspace... I'll guess I'll have to do some git magic to make sure this line remains unseen. I've removed it from the change now anyway.

Copy link
Member

@johanfylling johanfylling left a comment

Choose a reason for hiding this comment

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

LGTM 👍 😃

break
}

if len(params.Arguments) != 3 {
Copy link
Member

Choose a reason for hiding this comment

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

I don't see us reading arg 2 anywhere. Looks like it's the line number for regal.eval, which I suppose we don't need for debug. Do we still need to assert its presence?

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, you're right, we don't need to assert this here, but we're using the same outputs for both code lenses... and we'll want to check this to avoid getting out of bounds errors in case there aren't at least 2 args.

_debug_lenses contains {
"range": location.to_range(result.ranged_location_from_text(input["package"]).location),
"command": {
"title": "Debug",
Copy link
Member

Choose a reason for hiding this comment

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

Does vscode support emojis? If it does, we could prefix this with a '🪲' 😄.
There's probably plenty of setups where that would break, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

It does support that, and since we're only targeting VS Code for now, we could do it. Not sure this is intuitive though. Most people will probably think they got some dirt on their monitor 🤣

bugs

Copy link
Member

@johanfylling johanfylling Sep 12, 2024

Choose a reason for hiding this comment

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

I was thinking something like ►Evaluate|🪲Debug

_debug_lenses contains _rule_lens(rule, "regal.debug", "Debug") if {
some rule in ast.rules

# no need to add a debug lens for a rule like `pi := 3.14``
Copy link
Member

Choose a reason for hiding this comment

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

👍

bundle/regal/lsp/codelens/codelens.rego Show resolved Hide resolved
Following the excellent work on debugger support by @johanfylling,
this PR introduces a code lens for debugging, which triggers a
command that simply returns a launch configuration where the package
or rule clicked is set as the entrypoint.

The code lens provider is now also rewritten in Rego.

Signed-off-by: Anders Eknert <anders@styra.com>
@anderseknert anderseknert merged commit 822e42c into main Sep 12, 2024
4 checks passed
@anderseknert anderseknert deleted the debug-lens branch September 12, 2024 08:59
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
Following the excellent work on debugger support by @johanfylling,
this PR introduces a code lens for debugging, which triggers a
command that simply returns a launch configuration where the package
or rule clicked is set as the entrypoint.

The code lens provider is now also rewritten in Rego.

Signed-off-by: Anders Eknert <anders@styra.com>
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