Skip to content

Conversation

@gabriela-trutan-sonarsource
Copy link
Contributor

@gabriela-trutan-sonarsource gabriela-trutan-sonarsource commented Sep 4, 2025

SLVS-2430

This targets the PR in which DocumentUpdated event was introduced

@gabriela-trutan-sonarsource gabriela-trutan-sonarsource marked this pull request as ready for review September 4, 2025 14:34
Base automatically changed from gt/document-updated to feature/sqvs-roslyn-plugin September 5, 2025 08:18
latestDebounceState = new Debounce(new CancellationTokenSource(), state);
}

var latestState = latestDebounceState;

Choose a reason for hiding this comment

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

This is very unexpected. 1) latestDebounceState should be accessed under lock only 2) it is cached before Task.Delay has completed. To simplify things, I'd suggest removing the T state from the contract make the task into Action without parameters. If we're assuming that the task with the latest state is going to win, we don't need to pass the latest state to it as it already has it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. it is cached before Task.Delay has completed

It has to be cached before. So that the Task.Delay can be cancelled if newer text is being typed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the state from the contract

try
{
await Task.Delay(TimeSpan.FromMilliseconds(debounceMilliseconds), latestState.CancellationTokenSource.Token);
if (!latestState.CancellationTokenSource.Token.IsCancellationRequested)

Choose a reason for hiding this comment

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

This check is redundant. Task delay is going to throw if the token is cancelled. This IF is going to be executed nanoseconds after the task delay completion, so there's no point in checking again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the instructions are in the order of nanoseconds. I would rather leave it

Choose a reason for hiding this comment

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

Not really, the task delay is 1 second so there is definitely a high chance it's going to throw, while there's almost no chance the check below that would fail if it didn't

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 5, 2025

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.

2 participants