Repository navigation
Conversation
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.
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.
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
$/cancelRequestfor a request that was sent with a cancellation token, and the default handling ofworkspace/executeCommandsends none.The
workspace/executeCommandmiddleware from #79 now sendspgls.executeStatementitself, with a token, while all other commands go through unchanged. While the request runs:Cancelbutton,Postgres Language Server: Cancel Statement Executioncancels every running execution. It only shows up in the Command Palette while a statement runs (context keypostgres-language-server.statementExecutionRunning).Cancelling cancels the token, so the client sends
$/cancelRequestfor 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.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_backendwhen 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 lintandnpm run packagepass. 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 onselect pg_sleep(8);and cancels it after about 2 seconds, and checkedpg_stat_activityfor the statement:RequestCancelled36 ms after the cancel, thepg_sleepbackend is gone, and the panel shows "Execution cancelled". The verbose LSP trace shows$/cancelRequestwith the id of theworkspace/executeCommandrequest.Cancelbutton (clicked with xdotool): same, 147 ms after the click.$/cancelRequest, the statement keeps running, and after 8 s the panel shows the result with "The statement finished before it could be cancelled."