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

docs: Add docs for DAP support #1113

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/assets/dap/animation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/dap/breakpoint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/dap/codeaction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/dap/print.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/dap/variables.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions docs/debug-adapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Debug Adapter

In addition to being a language server, Regal can act as a
[Debug Adapter](https://microsoft.github.io/debug-adapter-protocol/).
A Debug Adapter is a program that can communicate with a debugger client,
such as Visual Studio Code's debugger, to provide debugging capabilities
for a language.

<img
src={require('./assets/dap/animation.gif').default}
alt="Animation showing the a debugging session in VS Code"/>
_A debugging session in VS Code_

:::info
In order to use the Debug Adapter, you must be using
[Regal v0.27.0](https://github.com/StyraInc/regal/releases/v0.27.0) or greater,
as well as a compatible client. See [Editor Support](/regal/editor-support) for
more details.
:::

## Getting Started

See the documentation in the Editor Support page for supported clients:

* [Visual Studio Code](/regal/editor-support#visual-studio-code)
* [Neovim](/regal/editor-support#neovim)

## Features

The Regal Debug Adapter currently supports the following features:

### Breakpoints

Breakpoints allow you to continue execution of a policy until a given point.
This can be helpful for:

* Inspection of variables at a given point in time
* Seeing how many times a given block of Rego code is executed, if at all
* Avoiding the need to step through code as it's run line by line

<img
src={require('./assets/dap/breakpoint.png').default}
alt="Screenshot of a breakpoint in VS Code"/>

### Variable Inspection

Either at a breakpoint or while stepping through code, you can inspect the
local variables in scope as well as the contents of the global `input` and
`data` documents.

`input` will be loaded from `input.json` in the workspace if it exists.

<img
src={require('./assets/dap/variables.png').default}
alt="Variables being inspected during execution in VS Code"/>

### Print Statements

Print statements are also supported, these are shown in the debug console:

<img
src={require('./assets/dap/print.png').default}
alt="Print statements shown in the debug output console"/>
17 changes: 17 additions & 0 deletions docs/editor-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ and open a workspace with Rego files.

The plugin will automatically find and use [Regal config](https://docs.styra.com/regal#configuration).

### Debug Adapter Protocol (DAP)

From
[`v0.17.0`](https://github.com/open-policy-agent/vscode-opa/blob/main/CHANGELOG.md#0170)
onwards, the OPA extension for Visual Studio Code supports the
[Regal Debug Adapter](/regal/debug-adapter).

To start a new debug session use the code action `Debug` found above a Rego rule
or package.

<img
src={require('./assets/dap/codeaction.png').default}
alt="Code Action in VS Code"/>

Breakpoints can be added by clicking in the gutter to the left of the editor.
Print statements will be shown in the debug console.

## Zed

[Zed](https://zed.dev) is a modern open-source code editor with focus on performance and simplicity.
Expand Down