Skip to content

Fix semantic highlighting cancellation during rapid typing#2301

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-semantic-highlighting-issue
Draft

Fix semantic highlighting cancellation during rapid typing#2301
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-semantic-highlighting-issue

Conversation

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

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

    • Remove serial processing from PsesCompletionHandler registration so completion cancellations no longer block the semantic tokens pipeline.
    • Keep completion requests interruptible without coupling them to DidChangeTextDocument sequencing.
  • Cancellation handling

    • Catch TaskCanceledException in completion-item resolve and return the original item instead of letting cancellation escape through the LSP pipeline.
    • Preserve the existing completion response shape when the underlying command lookup is canceled.
  • Regression coverage

    • Add a test for the completion resolve cancellation path to verify the handler returns cleanly under cancellation.
    • Update the test to use CancelAsync() to avoid synchronous cancellation analyzer violations.
try
{
    CommandInfo commandInfo = await CommandHelpers.GetCommandInfoAsync(..., cancellationToken);

    if (commandInfo is not null)
    {
        return request with
        {
            Documentation = await CommandHelpers.GetCommandSynopsisAsync(
                commandInfo, _executionService, cancellationToken)
        };
    }
}
catch (TaskCanceledException)
{
    return request;
}

Copilot AI changed the title [WIP] Fix semantic highlighting breaks when rapidly typing Prevent semantic token pipeline stalls from completion cancellation Jun 10, 2026
Copilot AI requested a review from JustinGrote June 10, 2026 23:05
Copilot AI changed the title Prevent semantic token pipeline stalls from completion cancellation Fix semantic highlighting cancellation during rapid typing Jun 10, 2026
@andyleejordan

Copy link
Copy Markdown
Member

@JustinGrote I added pkgs.dev.azure.com to the agent's firewall's allowlist, try again?

@andyleejordan

Copy link
Copy Markdown
Member

@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?

@JustinGrote

Copy link
Copy Markdown
Collaborator

@andyleejordan could have just been a transitive down situation. Probably best for it to be explicitly called out anyways.

@andyleejordan

Copy link
Copy Markdown
Member

This seems like it's reasonably capturing and handling cancellations of completion requests, ready for review?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 RequestProcessType from PsesCompletionHandler registration so completion cancellations no longer block the semantic tokens pipeline.
  • Wrap the command info and synopsis lookup in CompletionItem resolve with a try/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.

Comment on lines +133 to +137
#if NET5_0_OR_GREATER
await cancellationTokenSource.CancelAsync();
#else
cancellationTokenSource.Cancel();
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't we have a NET_CORE or DESKTOP or something like that already in the codebase? Just be consistent @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to use the repo’s existing CoreCLR compilation symbol for consistency in CompletionResolveHandlesTaskCanceledException (61e5d9e).

@andyleejordan

Copy link
Copy Markdown
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Semantic Highlighting breaks when rapidly typing due to improper cancellation

4 participants