Fix semantic highlighting cancellation during rapid typing#2301
Fix semantic highlighting cancellation during rapid typing#2301Copilot wants to merge 5 commits into
Conversation
|
@JustinGrote I added pkgs.dev.azure.com to the agent's firewall's allowlist, try again? |
|
@JustinGrote huh actually per https://docs.github.com/en/copilot/reference/copilot-allowlist-reference#programming-languages--package-managers-c--net it should have already been allowed so I think something else may be going on? |
|
@andyleejordan could have just been a transitive down situation. Probably best for it to be explicitly called out anyways. |
|
This seems like it's reasonably capturing and handling cancellations of completion requests, ready for review? |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where rapid typing caused semantic highlighting to stop updating in VS Code. The root cause was that the PsesCompletionHandler was registered with serial request processing, which meant DidChangeTextDocument notifications would queue behind completion requests. When those completions were cancelled, it blocked the semantic token delta pipeline.
Changes:
- Remove serial
RequestProcessTypefromPsesCompletionHandlerregistration so completion cancellations no longer block the semantic tokens pipeline. - Wrap the command info and synopsis lookup in
CompletionItemresolve with atry/catch (TaskCanceledException)to gracefully handle cancellation by returning the original request. - Add a regression test that verifies the resolve handler returns cleanly when the cancellation token is already cancelled.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/PowerShellEditorServices/Server/PsesLanguageServer.cs |
Remove serial processing option from PsesCompletionHandler registration and the now-unused OmniSharp.Extensions.JsonRpc import. |
src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs |
Wrap the GetCommandInfoAsync/GetCommandSynopsisAsync calls in a try/catch (TaskCanceledException) block, returning the unmodified request on cancellation. |
test/PowerShellEditorServices.Test/Language/CompletionHandlerTests.cs |
Add CompletionResolveHandlesTaskCanceledException test exercising the cancellation path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if NET5_0_OR_GREATER | ||
| await cancellationTokenSource.CancelAsync(); | ||
| #else | ||
| cancellationTokenSource.Cancel(); | ||
| #endif |
There was a problem hiding this comment.
Don't we have a NET_CORE or DESKTOP or something like that already in the codebase? Just be consistent @copilot
There was a problem hiding this comment.
Updated to use the repo’s existing CoreCLR compilation symbol for consistency in CompletionResolveHandlesTaskCanceledException (61e5d9e).
|
Okay looking at the comment that Copilot removed that explained the original serial behavior...this is an interesting approach. Since the completion creation itself is not really cancellable code, does catching the cancellation exception and then returning the request really work like the weird code seems to imply it will? |
Rapid typing could cancel completion work in a way that left semantic token delta requests without a response, which prevented VS Code from updating semantic highlighting for newly typed text.
Request pipeline
PsesCompletionHandlerregistration so completion cancellations no longer block the semantic tokens pipeline.DidChangeTextDocumentsequencing.Cancellation handling
TaskCanceledExceptionin completion-item resolve and return the original item instead of letting cancellation escape through the LSP pipeline.Regression coverage
CancelAsync()to avoid synchronous cancellation analyzer violations.