Skip to content

commands: use last focused Rego editor instead of active editor - #503

Merged
anderseknert merged 3 commits into
mainfrom
fix/last-rego-editor
Oct 1, 2026
Merged

anderseknert merged 3 commits into
mainfrom
fix/last-rego-editor

Conversation

@sspaink

@sspaink sspaink commented Sep 28, 2026

Copy link
Copy Markdown
Member

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.

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 😅

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>
Comment thread src/rego-editor.ts Outdated
}

// Like getRegoEditor, but tells the user to open a Rego file when there is none.
export function requireRegoEditor(): vscode.TextEditor | undefined {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could this be a param of getRegoEditor?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sure thing, updated

… option

Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
Comment thread src/rego-editor.ts Outdated
return editor;
}

function findRegoEditor(): vscode.TextEditor | undefined {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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
sspaink force-pushed the fix/last-rego-editor branch from 82101a2 to 709a1c8 Compare September 30, 2026 16:55
@anderseknert
anderseknert added this pull request to the merge queue Oct 1, 2026
Merged via the queue into main with commit ad94552 Oct 1, 2026
3 checks passed
@anderseknert
anderseknert deleted the fix/last-rego-editor branch October 1, 2026 13:19
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