Skip to content

feat: cancel a running statement execution - #80

Open
psteinroe wants to merge 1 commit into
feat/render-statement-resultsfrom
feat/cancel-statement-execution
Open

psteinroe wants to merge 1 commit into
feat/render-statement-resultsfrom
feat/cancel-statement-execution

Conversation

@psteinroe

@psteinroe psteinroe commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #79, which adds the results panel. The PR targets its branch, so the diff only shows the cancellation. Please merge #79 first.

A statement executed from the editor could not be stopped from VS Code. The language client only sends $/cancelRequest for a request that was sent with a cancellation token, and the default handling of workspace/executeCommand sends none.

The workspace/executeCommand middleware from #79 now sends pgls.executeStatement itself, with a token, while all other commands go through unchanged. While the request runs:

  • a progress notification "Executing statement" has a Cancel button,
  • the new command Postgres Language Server: Cancel Statement Execution cancels every running execution. It only shows up in the Command Palette while a statement runs (context key postgres-language-server.statementExecutionRunning).

Cancelling cancels the token, so the client sends $/cancelRequest for the request, and the notification changes to "Cancelling…" until the server answers. The answer decides what the results panel shows:

  • RequestCancelled (-32800): "Execution cancelled", with a note that a server that can't cancel statements in the database may still have run it.
  • a result: the result, with a note that the statement finished before it could be cancelled.

Server side, cancellation only takes effect with supabase-community/postgres-language-server#920, which runs the statement off the request thread and calls pg_cancel_backend when the request is cancelled. Servers before that run the statement to completion and then return its result, which the panel shows with the note above. Failed requests are reported as before, through the client's error log and notification.

How I tested it: npm run compile, npm run lint and npm run package pass. I ran the extension in VS Code 1.140 (under Xvfb) with a script in the extension host that runs the "Execute Statement" code action on select pg_sleep(8); and cancels it after about 2 seconds, and checked pg_stat_activity for the statement:

pgls.executeStatement now runs with a progress notification that has a
Cancel button, and a Cancel Statement Execution command is available while
it runs. Both cancel the request, so the language client sends
$/cancelRequest.
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.

1 participant