commands: use last focused Rego editor instead of active editor - #503
Merged
Merged
Conversation
Commands like Evaluate Package read vscode.window.activeTextEditor, which
can be the Output panel or the eval output document. Clicking the Output
panel and running Evaluate Package failed with:
open output:tsandall.opa.OPA & Regal.log: no such file or directory
Track the most recently focused Rego editor and use it when focus has
moved elsewhere. If no Rego file is open, show "Open a .rego file to run
this command." instead of passing an invalid path to opa.
This also stops Test Workspace from running `opa test` with no paths
outside a workspace ("specify at least one file"), and makes input.json
lookup and ${fileDirname} resolution use the Rego editor.
Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
| } | ||
|
|
||
| // Like getRegoEditor, but tells the user to open a Rego file when there is none. | ||
| export function requireRegoEditor(): vscode.TextEditor | undefined { |
Collaborator
There was a problem hiding this comment.
Could this be a param of getRegoEditor?
charlieegan3
approved these changes
Sep 30, 2026
… option Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
| return editor; | ||
| } | ||
|
|
||
| function findRegoEditor(): vscode.TextEditor | undefined { |
Collaborator
There was a problem hiding this comment.
So we have track, get and find Rego editor. I wonder if there is a case here to have the editor wrapped in a custom type or something with these as instance methods too?
find and get sound similar at a glance.
Member
Author
There was a problem hiding this comment.
the names are confusing, I inlined findRegoEditor seeing it was only a helper function for getRegoEditor
Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
sspaink
force-pushed
the
fix/last-rego-editor
branch
from
September 30, 2026 16:55
82101a2 to
709a1c8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Commands like Evaluate Package read vscode.window.activeTextEditor, which can be the Output panel or the eval output document. Clicking the Output panel and running Evaluate Package failed with:
Track the most recently focused Rego editor and use it when focus has moved elsewhere. If no Rego file is open, show "Open a .rego file to run this command." instead of passing an invalid path to opa.
This also stops Test Workspace from running
opa testwith no paths outside a workspace ("specify at least one file"), and makes input.json lookup and ${fileDirname} resolution use the Rego editor.Video showing the current behavior:
Screen.Recording.2026-09-28.at.5.03.25.PM.mov
Video showing the fixed behavior:
Screen.Recording.2026-09-28.at.5.34.36.PM.mov
easter egg is I updated my vscode between videos 😅