open-policy-agent / vscode-opa

An extension for VS Code which provides support for OPA and the Rego policy language
https://openpolicyagent.org
Apache License 2.0
112 stars 31 forks source link

Successful check always hides bottom panel in VSCode #102

Closed glimberg closed 5 months ago

glimberg commented 7 months ago

Whenever a check is successful, either on save or otherwise, the plugin closes my bottom panel containing my terminal. Is there a setting to make the plugin NOT hide the panel, or any other way to change this behavior?

glimberg commented 7 months ago

It's possible that it's the formatter doing this, rather than the checker. Whichever one it is, it's incredibly annoying to have to reopen the bottom panel for the terminal after almost every save where format and/or checker successfully runs.

anderseknert commented 7 months ago

That does indeed sound very annoying. I don't see this happening in my editor, even with both check on save and format on save enabled.

.vscode/settings.json

{
    "opa.checkOnSave": true,
    "editor.formatOnSave": true
}

Any other setting you have enabled that could cause this?

glimberg commented 7 months ago

Not that I'm aware of. It's never happened before in any other project I've worked on. I'm just starting messing around with Rego. Installed the plugin am seeing the reported behavior. It doesn't always happen consistently either.

The easiest way I've found to reproduce is to intentionally introduce an error to a file, then save. The bottom pane switches to the 'Output' tab with something along the lines of:

error running opa fmt :: 1 error occurred: stdin:56: rego_parse_error: var cannot be used for rule name

Remove the error, and save again and then the whole bottom panel disappears.

Let's see if embedding a little screen recording works

https://github.com/open-policy-agent/vscode-opa/assets/54439/2c116a8b-8ba2-4c91-99cc-9fa60e88da47

anderseknert commented 7 months ago

Ah, yes, thanks! Getting an error reported and fixing it does the same here. We're pushing a new release early next week which will provide an option to use Regal for linting. This uses a language server which will check/lint continuously, which largely negates the need for check on save. This should be fixed still of course, but perhaps it'll provide a good workaround in the meantime, while also provide more fine-grained reporting on issues than just syntax checks.

@charlieegan3 FYI — it would be good to know if this behavior is the same using the Regal LSP implementation. If so we should look into that I think. If we opened the panel to flag an issue, I think it's fine that we close it when it's fixed... but we shouldn't close it if the panel was open from before.

anderseknert commented 6 months ago

@glimberg did you try the Regal integration yet? That should allow you to disable check on save, as you'll get that for free with the linter. It's not a fix, but it's a pretty good workaround.

glimberg commented 5 months ago

Sorry, I haven't had the occasion to check. This was just something I noticed when editing policies in VSCode while evaluating OPA. We've since moved on to a different solution because we wanted something embeddable into both Go and Rust, rather than requiring another service to run along side everything else.

anderseknert commented 5 months ago

Thanks for coming back to me @glimberg 👍 Regorus would be an interesting option for embedding OPA in Rust :) But back to the topic — I think this issue is largely alleviated by the new Regal integration, as running the equivalence of opa check is done continuously while editing. I'll close this for the time being, but if someone thinks I'm wrong in my conclusion, let me know and I'll reopen.