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

Remove ForegroundThreadAffinitizedObject usage #60526

Merged
merged 35 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
44ba15e
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 1, 2022
7391a9c
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 1, 2022
68a1969
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 1, 2022
bc02312
Use existing assert
CyrusNajmabadi Apr 1, 2022
dab3e87
Use correct assert
CyrusNajmabadi Apr 1, 2022
a8e229d
Fix
CyrusNajmabadi Apr 1, 2022
8533183
Fix
CyrusNajmabadi Apr 1, 2022
87bcd02
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 1, 2022
6f1690a
Merge remote-tracking branch 'upstream/main-vs-deps' into removeFTAO
CyrusNajmabadi Apr 2, 2022
add177d
fix
CyrusNajmabadi Apr 2, 2022
c7672ba
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
102795d
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
6daa2bb
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
b6d17e6
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
5ea0910
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
5e689a3
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
66b257d
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
08d1cf6
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
81ff6f7
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
b93ec77
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
bd29c17
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
c95a831
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
cb6aab6
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
c29f412
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
fbe4f0b
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
aa4aa04
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
59e809a
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
75770d7
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
999f56f
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
20fe63b
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
664a2d4
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
1ba8010
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
23b0791
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
8a6dc3e
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
27d9a8d
Remove ForegroundThreadAffinitizedObject usage
CyrusNajmabadi Apr 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.EventHookup
[ContentType(ContentTypeNames.CSharpContentType)]
[Name(PredefinedCommandHandlerNames.EventHookup)]
[Order(Before = PredefinedCommandHandlerNames.AutomaticCompletion)]
internal partial class EventHookupCommandHandler : ForegroundThreadAffinitizedObject
internal partial class EventHookupCommandHandler
{
private readonly IThreadingContext _threadingContext;
private readonly IInlineRenameService _inlineRenameService;
private readonly IAsynchronousOperationListener _asyncListener;
private readonly IGlobalOptionService _globalOptions;
Expand All @@ -57,8 +58,8 @@ public EventHookupCommandHandler(
EventHookupSessionManager eventHookupSessionManager,
IGlobalOptionService globalOptions,
IAsynchronousOperationListenerProvider listenerProvider)
: base(threadingContext)
{
_threadingContext = threadingContext;
_inlineRenameService = inlineRenameService;
_asyncListener = listenerProvider.GetListener(FeatureAttribute.EventHookup);
_globalOptions = globalOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Editor.CSharp.EventHookup
{
Expand All @@ -16,14 +17,14 @@ internal partial class EventHookupCommandHandler :

public bool ExecuteCommand(EscapeKeyCommandArgs args, CommandExecutionContext context)
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
EventHookupSessionManager.CancelAndDismissExistingSessions();
return false;
}

public CommandState GetCommandState(EscapeKeyCommandArgs args)
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);
return CommandState.Unspecified;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal partial class EventHookupCommandHandler : IChainedCommandHandler<TabKey
{
public void ExecuteCommand(TabKeyCommandArgs args, Action nextHandler, CommandExecutionContext context)
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);
if (!_globalOptions.GetOption(InternalFeatureOnOffOptions.EventHookup))
{
nextHandler();
Expand All @@ -55,7 +55,7 @@ public void ExecuteCommand(TabKeyCommandArgs args, Action nextHandler, CommandEx

public CommandState GetCommandState(TabKeyCommandArgs args, Func<CommandState> nextHandler)
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);
if (EventHookupSessionManager.CurrentSession != null)
{
return CommandState.Available;
Expand All @@ -68,7 +68,7 @@ public CommandState GetCommandState(TabKeyCommandArgs args, Func<CommandState> n

private void HandleTabWorker(ITextView textView, ITextBuffer subjectBuffer, Action nextHandler, CancellationToken cancellationToken)
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);

// For test purposes only!
if (EventHookupSessionManager.CurrentSession.TESTSessionHookupMutex != null)
Expand Down Expand Up @@ -107,7 +107,7 @@ private void HandleTabWorker(ITextView textView, ITextBuffer subjectBuffer, Acti

private void GenerateAndAddEventHandler(ITextView textView, ITextBuffer subjectBuffer, string eventHandlerMethodName, Action nextHandler, CancellationToken cancellationToken)
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);

using (Logger.LogBlock(FunctionId.EventHookup_Generate_Handler, cancellationToken))
{
Expand Down Expand Up @@ -151,7 +151,7 @@ private Solution CreateSolutionWithEventHandler(
out int plusEqualTokenEndPosition,
CancellationToken cancellationToken)
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);

// Mark the += token with an annotation so we can find it after formatting
var plusEqualsTokenAnnotation = new SyntaxAnnotation();
Expand Down Expand Up @@ -289,7 +289,7 @@ private static IMethodSymbol GetMethodSymbol(

private void BeginInlineRename(ITextView textView, int plusEqualTokenEndPosition, CancellationToken cancellationToken)
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);

if (_inlineRenameService.ActiveSession == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Editor.CSharp.EventHookup
{
internal partial class EventHookupCommandHandler : IChainedCommandHandler<TypeCharCommandArgs>
{
public void ExecuteCommand(TypeCharCommandArgs args, Action nextHandler, CommandExecutionContext context)
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);
nextHandler();

if (!_globalOptions.GetOption(InternalFeatureOnOffOptions.EventHookup))
Expand Down Expand Up @@ -58,7 +59,7 @@ public void ExecuteCommand(TypeCharCommandArgs args, Action nextHandler, Command

private bool IsTextualPlusEquals(ITextView textView, ITextBuffer subjectBuffer)
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);

var caretPoint = textView.GetCaretPoint(subjectBuffer);
if (!caretPoint.HasValue)
Expand All @@ -72,7 +73,7 @@ private bool IsTextualPlusEquals(ITextView textView, ITextBuffer subjectBuffer)

public CommandState GetCommandState(TypeCharCommandArgs args, Func<CommandState> nextHandler)
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);
return nextHandler();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Adornments;
using Microsoft.VisualStudio.Text.Editor;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Editor.CSharp.EventHookup
{
[Export]
internal sealed partial class EventHookupSessionManager : ForegroundThreadAffinitizedObject
internal sealed partial class EventHookupSessionManager
{
public readonly IThreadingContext ThreadingContext;
Copy link
Member

Choose a reason for hiding this comment

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

Why public?


private readonly IToolTipService _toolTipService;
private IToolTipPresenter _toolTipPresenter;

Expand All @@ -33,14 +36,14 @@ internal sealed partial class EventHookupSessionManager : ForegroundThreadAffini
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public EventHookupSessionManager(IThreadingContext threadingContext, IToolTipService toolTipService)
: base(threadingContext)
{
ThreadingContext = threadingContext;
_toolTipService = toolTipService;
}

internal void EventHookupFoundInSession(EventHookupSession analyzedSession)
{
AssertIsForeground();
Contract.ThrowIfFalse(ThreadingContext.HasMainThread);

var caretPoint = analyzedSession.TextView.GetCaretPoint(analyzedSession.SubjectBuffer);

Expand Down Expand Up @@ -114,7 +117,7 @@ internal void BeginSession(

internal void CancelAndDismissExistingSessions()
{
AssertIsForeground();
Contract.ThrowIfFalse(ThreadingContext.HasMainThread);

if (CurrentSession != null)
{
Expand All @@ -137,7 +140,7 @@ internal void CancelAndDismissExistingSessions()
/// </summary>
private void TextBuffer_Changed(object sender, TextContentChangedEventArgs e)
{
AssertIsForeground();
Contract.ThrowIfFalse(ThreadingContext.HasMainThread);

foreach (var change in e.Changes)
{
Expand All @@ -154,7 +157,7 @@ private void TextBuffer_Changed(object sender, TextContentChangedEventArgs e)
/// </summary>
private void Caret_PositionChanged(object sender, EventArgs e)
{
AssertIsForeground();
Contract.ThrowIfFalse(ThreadingContext.HasMainThread);

if (CurrentSession == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ internal sealed partial class EventHookupSessionManager
/// += is being used to add an event handler to an event. If it is, then we also determine
/// a candidate name for the event handler.
/// </summary>
internal class EventHookupSession : ForegroundThreadAffinitizedObject
internal class EventHookupSession
{
public readonly Task<string> GetEventNameTask;
private readonly IThreadingContext _threadingContext;
private readonly CancellationTokenSource _cancellationTokenSource;
private readonly ITrackingPoint _trackingPoint;
private readonly ITrackingSpan _trackingSpan;
Expand All @@ -55,7 +56,7 @@ public ITrackingPoint TrackingPoint
{
get
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);
return _trackingPoint;
}
}
Expand All @@ -64,7 +65,7 @@ public ITrackingSpan TrackingSpan
{
get
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);
return _trackingSpan;
}
}
Expand All @@ -73,7 +74,7 @@ public ITextView TextView
{
get
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);
return _textView;
}
}
Expand All @@ -82,14 +83,14 @@ public ITextBuffer SubjectBuffer
{
get
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);
return _subjectBuffer;
}
}

public void Cancel()
{
AssertIsForeground();
Contract.ThrowIfFalse(_threadingContext.HasMainThread);
_cancellationTokenSource.Cancel();
}

Expand All @@ -100,9 +101,8 @@ public EventHookupSession(
ITextBuffer subjectBuffer,
IAsynchronousOperationListener asyncListener,
Mutex testSessionHookupMutex)
: base(eventHookupSessionManager.ThreadingContext)
{
AssertIsForeground();
_threadingContext = eventHookupSessionManager.ThreadingContext;
_cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = _cancellationTokenSource.Token;
_textView = textView;
Expand All @@ -129,7 +129,7 @@ public EventHookupSession(
var continuedTask = this.GetEventNameTask.SafeContinueWithFromAsync(
async t =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);

if (t.Result != null)
{
Expand All @@ -153,7 +153,7 @@ public EventHookupSession(

private async Task<string> DetermineIfEventHookupAndGetHandlerNameAsync(Document document, int position, CancellationToken cancellationToken)
{
AssertIsBackground();
Contract.ThrowIfTrue(_threadingContext.HasMainThread);

// For test purposes only!
if (TESTSessionHookupMutex != null)
Expand Down Expand Up @@ -191,7 +191,7 @@ private async Task<string> DetermineIfEventHookupAndGetHandlerNameAsync(Document

private async Task<SyntaxToken?> GetPlusEqualsTokenInsideAddAssignExpressionAsync(Document document, int position, CancellationToken cancellationToken)
{
AssertIsBackground();
Contract.ThrowIfTrue(_threadingContext.HasMainThread);
var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var token = syntaxTree.FindTokenOnLeftOfPosition(position, cancellationToken);

Expand All @@ -210,7 +210,7 @@ private async Task<string> DetermineIfEventHookupAndGetHandlerNameAsync(Document

private IEventSymbol GetEventSymbol(SemanticModel semanticModel, SyntaxToken plusEqualsToken, CancellationToken cancellationToken)
{
AssertIsBackground();
Contract.ThrowIfTrue(_threadingContext.HasMainThread);
if (plusEqualsToken.Parent is not AssignmentExpressionSyntax parentToken)
{
return null;
Expand All @@ -229,7 +229,7 @@ private string GetEventHandlerName(
IEventSymbol eventSymbol, SyntaxToken plusEqualsToken, SemanticModel semanticModel,
ISyntaxFactsService syntaxFactsService, NamingRule namingRule)
{
AssertIsBackground();
Contract.ThrowIfTrue(_threadingContext.HasMainThread);
var objectPart = GetNameObjectPart(eventSymbol, plusEqualsToken, semanticModel, syntaxFactsService);
var basename = namingRule.NamingStyle.CreateName(ImmutableArray.Create(
string.Format("{0}_{1}", objectPart, eventSymbol.Name)));
Expand All @@ -249,7 +249,7 @@ private string GetEventHandlerName(
/// </summary>
private string GetNameObjectPart(IEventSymbol eventSymbol, SyntaxToken plusEqualsToken, SemanticModel semanticModel, ISyntaxFactsService syntaxFactsService)
{
AssertIsBackground();
Contract.ThrowIfTrue(_threadingContext.HasMainThread);
var parentToken = plusEqualsToken.Parent as AssignmentExpressionSyntax;

if (parentToken.Left is MemberAccessExpressionSyntax memberAccessExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected AbstractSemanticOrEmbeddedClassificationViewTaggerProvider(

protected sealed override ITaggerEventSource CreateEventSource(ITextView? textView, ITextBuffer subjectBuffer)
{
AssertIsForeground();
Contract.ThrowIfFalse(this.ThreadingContext.HasMainThread);
Contract.ThrowIfNull(textView);

// Note: we don't listen for OnTextChanged. They'll get reported by the ViewSpan changing and also the
Expand All @@ -78,7 +78,7 @@ protected sealed override ITaggerEventSource CreateEventSource(ITextView? textVi

protected sealed override IEnumerable<SnapshotSpan> GetSpansToTag(ITextView? textView, ITextBuffer subjectBuffer)
{
AssertIsForeground();
Contract.ThrowIfFalse(this.ThreadingContext.HasMainThread);
Contract.ThrowIfNull(textView);

// Find the visible span some 100 lines +/- what's actually in view. This way
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ActiveStatementTaggerProvider(

protected override ITaggerEventSource CreateEventSource(ITextView? textView, ITextBuffer subjectBuffer)
{
AssertIsForeground();
Contract.ThrowIfFalse(this.ThreadingContext.HasMainThread);

return TaggerEventSources.Compose(
new EventSource(subjectBuffer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected override ITaggerEventSource CreateEventSource(ITextView? textView, ITe
{
Contract.ThrowIfNull(textView);
return TaggerEventSources.Compose(
TaggerEventSources.OnViewSpanChanged(ThreadingContext, textView),
TaggerEventSources.OnViewSpanChanged(this.ThreadingContext, textView),
TaggerEventSources.OnWorkspaceChanged(subjectBuffer, _listener),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsGlobalStateOption.DisplayAllOverride),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.EnabledForParameters),
Expand All @@ -85,7 +85,7 @@ protected override ITaggerEventSource CreateEventSource(ITextView? textView, ITe

protected override IEnumerable<SnapshotSpan> GetSpansToTag(ITextView? textView, ITextBuffer subjectBuffer)
{
this.AssertIsForeground();
Contract.ThrowIfFalse(this.ThreadingContext.HasMainThread);
Contract.ThrowIfNull(textView);

// Find the visible span some 100 lines +/- what's actually in view. This way
Expand Down
Loading