-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50243 from CyrusNajmabadi/workingProgress
Add a working internal progress system for codeactions
- Loading branch information
Showing
2 changed files
with
82 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
60 changes: 60 additions & 0 deletions
60
...Features/Core.Wpf/Suggestions/SuggestedActions/UIThreadOperationContextProgressTracker.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.CodeAnalysis.Shared.Utilities; | ||
using Microsoft.VisualStudio.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions | ||
{ | ||
internal class UIThreadOperationContextProgressTracker : IProgressTracker | ||
{ | ||
private readonly IUIThreadOperationScope _scope; | ||
|
||
private readonly object _gate = new(); | ||
|
||
public UIThreadOperationContextProgressTracker(IUIThreadOperationScope scope) | ||
=> _scope = scope; | ||
|
||
public string? Description { get => _scope.Description; set => _scope.Description = value; } | ||
|
||
public int CompletedItems { get; private set; } | ||
|
||
public int TotalItems { get; private set; } | ||
|
||
public void AddItems(int count) | ||
{ | ||
ProgressInfo progressInfo; | ||
lock (_gate) | ||
{ | ||
TotalItems += count; | ||
progressInfo = new ProgressInfo(CompletedItems, TotalItems); | ||
} | ||
|
||
_scope.Progress.Report(progressInfo); | ||
} | ||
|
||
public void ItemCompleted() | ||
{ | ||
ProgressInfo progressInfo; | ||
lock (_gate) | ||
{ | ||
CompletedItems++; | ||
progressInfo = new ProgressInfo(CompletedItems, TotalItems); | ||
} | ||
|
||
_scope.Progress.Report(progressInfo); | ||
} | ||
|
||
public void Clear() | ||
{ | ||
lock (_gate) | ||
{ | ||
CompletedItems = 0; | ||
TotalItems = 0; | ||
} | ||
|
||
_scope.Progress.Report(new ProgressInfo()); | ||
} | ||
} | ||
} |