Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook brace-matching up to the 'responsive completion' editor option #76746

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

CyrusNajmabadi
Copy link
Member

This way, if brace matching is taking too long, we can responsibly cancel it and unblock typing.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner January 14, 2025 21:00
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 14, 2025
@@ -47,6 +47,10 @@ internal partial class BraceCompletionSessionProvider(
public bool TryCreateSession(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionSession session)
{
_threadingContext.ThrowIfNotOnUIThread();

var isResponsive = textView.Options.GetOptionValue(DefaultOptions.ResponsiveCompletionOptionId);
var responsiveThreshold = isResponsive ? textView.Options.GetOptionValue(DefaultOptions.ResponsiveCompletionThresholdOptionId) : -1;
Copy link
Member Author

Choose a reason for hiding this comment

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

defaults for this are 'true + 250ms'.

// Brace completion is cancellable if the user has the 'responsive completion' option enabled.
var cancellationTokenSource = new CancellationTokenSource();
if (_timeoutThreshold > 0)
cancellationTokenSource.CancelAfter(_timeoutThreshold);
Copy link
Contributor

@ToddGrun ToddGrun Jan 14, 2025

Choose a reason for hiding this comment

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

consider something like to encapsulate the cancellationtokensource usage:

var cancellationToken = GetCancellationToken();
...

CancellationToken GetCancellationToken()
{
    if (_timeoutThreshold <= 0)
        return CancellationToken.None;

    var cancellationTokenSource = new CancellationTokenSource();
    cancellationTokenSource.CancelAfter(_timeoutThreshold);
    return cancellationTokenSource.Token;
}

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants