提交 a282bae3 编写于 作者: C Cyrus Najmabadi

Merge branch 'features/embeddedRegex' into regexFeatures

......@@ -159,4 +159,10 @@ collection.
<Rule Id="VSSDK001" Action="Warning" /> <!-- Derive from AsyncPackage -->
<Rule Id="VSSDK003" Action="Warning" /> <!-- Support async tool windows -->
</Rules>
<Rules AnalyzerId="Microsoft.VisualStudio.Threading.Analyzers" RuleNamespace="Microsoft.VisualStudio.Threading.Analyzers">
<Rule Id="VSTHRD002" Action="None" /> <!-- Avoid problematic synchronous waits -->
<Rule Id="VSTHRD103" Action="None" /> <!-- Call async methods when in an async method -->
<Rule Id="VSTHRD110" Action="None" /> <!-- Observe result of async calls -->
<Rule Id="VSTHRD200" Action="None" /> <!-- Use "Async" suffix for async methods -->
</Rules>
</RuleSet>
......@@ -123,7 +123,8 @@
<MicrosoftVisualStudioTextManagerInterop100Version>10.0.30319</MicrosoftVisualStudioTextManagerInterop100Version>
<MicrosoftVisualStudioTextManagerInterop120Version>12.0.30110</MicrosoftVisualStudioTextManagerInterop120Version>
<MicrosoftVisualStudioTextManagerInterop121DesignTimeVersion>12.1.30328</MicrosoftVisualStudioTextManagerInterop121DesignTimeVersion>
<MicrosoftVisualStudioThreadingVersion>15.3.23</MicrosoftVisualStudioThreadingVersion>
<MicrosoftVisualStudioThreadingAnalyzersVersion>15.8.132</MicrosoftVisualStudioThreadingAnalyzersVersion>
<MicrosoftVisualStudioThreadingVersion>15.5.32</MicrosoftVisualStudioThreadingVersion>
<MicrosoftVisualStudioUtilitiesVersion>15.0.26730-alpha</MicrosoftVisualStudioUtilitiesVersion>
<MicrosoftVisualStudioValidationVersion>15.3.23</MicrosoftVisualStudioValidationVersion>
<MicrosoftVisualStudioVsInteractiveWindowVersion>2.0.0-rc3-61304-01</MicrosoftVisualStudioVsInteractiveWindowVersion>
......
......@@ -147,6 +147,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="$(MicrosoftNetCoreAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="Roslyn.Diagnostics.Analyzers" Version="$(RoslynDiagnosticsAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="$(MicrosoftVisualStudioThreadingAnalyzersVersion)" PrivateAssets="all" />
</ItemGroup>
<ImportGroup Label="WindowsImports" Condition="'$(OS)' == 'Windows_NT'">
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Composition;
using System.Threading;
using Microsoft.CodeAnalysis.Editor.CSharp.AutomaticCompletion.Sessions;
using Microsoft.CodeAnalysis.Editor.Implementation.AutomaticCompletion;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
......@@ -20,7 +22,9 @@ internal class CSharpEditorBraceCompletionSessionFactory : AbstractEditorBraceCo
private readonly ISmartIndentationService _smartIndentationService;
[ImportingConstructor]
public CSharpEditorBraceCompletionSessionFactory(ISmartIndentationService smartIndentationService, ITextBufferUndoManagerProvider undoManager)
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CSharpEditorBraceCompletionSessionFactory(IThreadingContext threadingContext, ISmartIndentationService smartIndentationService, ITextBufferUndoManagerProvider undoManager)
: base(threadingContext)
{
_smartIndentationService = smartIndentationService;
_undoManager = undoManager;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Composition;
using Microsoft.CodeAnalysis.Editor.FindUsages;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
namespace Microsoft.CodeAnalysis.Editor.CSharp.FindUsages
......@@ -9,5 +11,11 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.FindUsages
[ExportLanguageService(typeof(IFindUsagesService), LanguageNames.CSharp), Shared]
internal class CSharpFindUsagesService : AbstractFindUsagesService
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CSharpFindUsagesService(IThreadingContext threadingContext)
: base(threadingContext)
{
}
}
}
......@@ -97,9 +97,9 @@ public async Task<IList<TextChange>> GetFormattingChangesAsync(Document document
var span = textSpan ?? new TextSpan(0, root.FullSpan.Length);
var formattingSpan = CommonFormattingHelpers.GetFormattingSpan(root, span);
return Formatter.GetFormattedTextChanges(root,
return await Formatter.GetFormattedTextChangesAsync(root,
SpecializedCollections.SingletonEnumerable(formattingSpan),
document.Project.Solution.Workspace, options, cancellationToken);
document.Project.Solution.Workspace, options, cancellationToken).ConfigureAwait(false);
}
public async Task<IList<TextChange>> GetFormattingChangesOnPasteAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
......@@ -309,7 +309,7 @@ private ISmartTokenFormatter CreateSmartTokenFormatter(OptionSet optionSet, IEnu
var formatter = new SmartTokenFormatter(options, formattingRules, (CompilationUnitSyntax)root);
var changes = formatter.FormatRange(document.Project.Solution.Workspace, tokenRange.Value.Item1, tokenRange.Value.Item2, cancellationToken);
var changes = await formatter.FormatRangeAsync(document.Project.Solution.Workspace, tokenRange.Value.Item1, tokenRange.Value.Item2, cancellationToken).ConfigureAwait(false);
return changes;
}
......
......@@ -40,7 +40,7 @@ internal class SmartTokenFormatter : ISmartTokenFormatter
_root = root;
}
public IList<TextChange> FormatRange(
public Task<IList<TextChange>> FormatRangeAsync(
Workspace workspace, SyntaxToken startToken, SyntaxToken endToken, CancellationToken cancellationToken)
{
Contract.ThrowIfTrue(startToken.Kind() == SyntaxKind.None || startToken.Kind() == SyntaxKind.EndOfFileToken);
......@@ -58,7 +58,7 @@ internal class SmartTokenFormatter : ISmartTokenFormatter
smartTokenformattingRules = (new NoLineChangeFormattingRule()).Concat(_formattingRules);
}
return Formatter.GetFormattedTextChanges(_root, new TextSpan[] { TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End) }, workspace, _optionSet, smartTokenformattingRules, cancellationToken);
return Formatter.GetFormattedTextChangesAsync(_root, new TextSpan[] { TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End) }, workspace, _optionSet, smartTokenformattingRules, cancellationToken);
}
private bool CloseBraceOfTryOrDoBlock(SyntaxToken endToken)
......
using System;
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.GoToDefinition;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
namespace Microsoft.CodeAnalysis.Editor.CSharp.GoToDefinition
......@@ -12,5 +9,11 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.GoToDefinition
[ExportLanguageService(typeof(IGoToSymbolService), LanguageNames.CSharp), Shared]
internal class CSharpGoToSymbolService : AbstractGoToSymbolService
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CSharpGoToSymbolService(IThreadingContext threadingContext)
: base(threadingContext)
{
}
}
}
......@@ -2185,6 +2185,7 @@ public async Task TestCreateWithBufferNotInWorkspace()
var listenerProvider = workspace.ExportProvider.GetExportedValue<IAsynchronousOperationListenerProvider>();
var provider = new SemanticClassificationViewTaggerProvider(
workspace.ExportProvider.GetExportedValue<IThreadingContext>(),
workspace.ExportProvider.GetExportedValue<IForegroundNotificationService>(),
workspace.ExportProvider.GetExportedValue<ISemanticChangeNotificationService>(),
workspace.ExportProvider.GetExportedValue<ClassificationTypeMap>(),
......@@ -2216,6 +2217,7 @@ public async Task TestGetTagsOnBufferTagger()
var listenerProvider = workspace.ExportProvider.GetExportedValue<IAsynchronousOperationListenerProvider>();
var provider = new SemanticClassificationBufferTaggerProvider(
workspace.ExportProvider.GetExportedValue<IThreadingContext>(),
workspace.ExportProvider.GetExportedValue<IForegroundNotificationService>(),
workspace.ExportProvider.GetExportedValue<ISemanticChangeNotificationService>(),
workspace.ExportProvider.GetExportedValue<ClassificationTypeMap>(),
......
......@@ -5,6 +5,7 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Implementation.Classification;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Test.Utilities;
......@@ -35,7 +36,7 @@ public async Task TestTagsChangedForEntireFile()
workspace.GetService<IForegroundNotificationService>(),
AsynchronousOperationListenerProvider.NullListener,
null,
new SyntacticClassificationTaggerProvider(null, null, null));
new SyntacticClassificationTaggerProvider(workspace.ExportProvider.GetExportedValue<IThreadingContext>(), null, null, null));
// Capture the expected value before the await, in case it changes.
var expectedLength = subjectBuffer.CurrentSnapshot.Length;
......
......@@ -7,6 +7,7 @@
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Editor.Implementation.Suggestions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Extensions;
using Microsoft.CodeAnalysis.Text;
......@@ -50,6 +51,7 @@ private async Task GetPreview(TestWorkspace workspace, CodeRefactoringProvider p
var codeActions = new List<CodeAction>();
RefactoringSetup(workspace, provider, codeActions, out var extensionManager, out var textBuffer);
var suggestedAction = new CodeRefactoringSuggestedAction(
workspace.ExportProvider.GetExportedValue<IThreadingContext>(),
workspace.ExportProvider.GetExportedValue<SuggestedActionsSourceProvider>(),
workspace, textBuffer, provider, codeActions.First());
await suggestedAction.GetPreviewAsync(CancellationToken.None);
......@@ -62,6 +64,7 @@ private void DisplayText(TestWorkspace workspace, CodeRefactoringProvider provid
var codeActions = new List<CodeAction>();
RefactoringSetup(workspace, provider, codeActions, out var extensionManager, out var textBuffer);
var suggestedAction = new CodeRefactoringSuggestedAction(
workspace.ExportProvider.GetExportedValue<IThreadingContext>(),
workspace.ExportProvider.GetExportedValue<SuggestedActionsSourceProvider>(),
workspace, textBuffer, provider, codeActions.First());
var text = suggestedAction.DisplayText;
......@@ -74,6 +77,7 @@ private async Task ActionSets(TestWorkspace workspace, CodeRefactoringProvider p
var codeActions = new List<CodeAction>();
RefactoringSetup(workspace, provider, codeActions, out var extensionManager, out var textBuffer);
var suggestedAction = new CodeRefactoringSuggestedAction(
workspace.ExportProvider.GetExportedValue<IThreadingContext>(),
workspace.ExportProvider.GetExportedValue<SuggestedActionsSourceProvider>(),
workspace, textBuffer, provider, codeActions.First());
var actionSets = await suggestedAction.GetActionSetsAsync(CancellationToken.None);
......
......@@ -13,6 +13,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Diagnostics.CSharp;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.ErrorLogger;
......@@ -199,7 +200,9 @@ void Method()
var suppressionProvider = CreateDiagnosticProviderAndFixer(workspace).Item2;
var suppressionProviderFactory = new Lazy<ISuppressionFixProvider, CodeChangeProviderMetadata>(() => suppressionProvider,
new CodeChangeProviderMetadata("SuppressionProvider", languages: new[] { LanguageNames.CSharp }));
var fixService = new CodeFixService(diagnosticService,
var fixService = new CodeFixService(
workspace.ExportProvider.GetExportedValue<IThreadingContext>(),
diagnosticService,
SpecializedCollections.EmptyEnumerable<Lazy<IErrorLoggerService>>(),
SpecializedCollections.EmptyEnumerable<Lazy<CodeFixProvider, CodeChangeProviderMetadata>>(),
SpecializedCollections.SingletonEnumerable(suppressionProviderFactory));
......
......@@ -3508,7 +3508,7 @@ private async Task AutoFormatOnMarkerAsync(string initialMarkup, string expected
return;
}
var changes = formatter.FormatRange(workspace, tokenRange.Value.Item1, tokenRange.Value.Item2, CancellationToken.None);
var changes = await formatter.FormatRangeAsync(workspace, tokenRange.Value.Item1, tokenRange.Value.Item2, CancellationToken.None).ConfigureAwait(false);
var actual = GetFormattedText(buffer, changes);
Assert.Equal(expected, actual);
}
......
......@@ -4,6 +4,7 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Implementation.BraceMatching;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Shared.TestHooks;
......@@ -34,6 +35,7 @@ private IEnumerable<T> Enumerable<T>(params T[] array)
{
var view = new Mock<ITextView>();
var producer = new BraceHighlightingViewTaggerProvider(
workspace.ExportProvider.GetExportedValue<IThreadingContext>(),
workspace.GetService<IBraceMatchingService>(),
workspace.GetService<IForegroundNotificationService>(),
AsynchronousOperationListenerProvider.NullProvider);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.Adornments
{
......@@ -16,13 +14,16 @@ internal abstract class AbstractAdornmentManagerProvider<TTag> :
IWpfTextViewCreationListener
where TTag : GraphicsTag
{
private readonly IThreadingContext _threadingContext;
private readonly IViewTagAggregatorFactoryService _tagAggregatorFactoryService;
private readonly IAsynchronousOperationListener _asyncListener;
protected AbstractAdornmentManagerProvider(
IThreadingContext threadingContext,
IViewTagAggregatorFactoryService tagAggregatorFactoryService,
IAsynchronousOperationListenerProvider listenerProvider)
{
_threadingContext = threadingContext;
_tagAggregatorFactoryService = tagAggregatorFactoryService;
_asyncListener = listenerProvider.GetListener(this.FeatureAttributeName);
}
......@@ -43,7 +44,7 @@ public void TextViewCreated(IWpfTextView textView)
}
// the manager keeps itself alive by listening to text view events.
AdornmentManager<TTag>.Create(textView, _tagAggregatorFactoryService, _asyncListener, AdornmentLayerName);
AdornmentManager<TTag>.Create(_threadingContext, textView, _tagAggregatorFactoryService, _asyncListener, AdornmentLayerName);
}
}
}
......@@ -4,11 +4,13 @@
using System.Linq;
using System.Threading;
using System.Windows.Threading;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Threading;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.Adornments
......@@ -20,6 +22,8 @@ internal class AdornmentManager<T> where T : GraphicsTag
{
private readonly object _invalidatedSpansLock = new object();
private readonly IThreadingContext _threadingContext;
/// <summary>View that created us.</summary>
private readonly IWpfTextView _textView;
......@@ -36,30 +40,35 @@ internal class AdornmentManager<T> where T : GraphicsTag
private List<IMappingSpan> _invalidatedSpans;
public static AdornmentManager<T> Create(
IThreadingContext threadingContext,
IWpfTextView textView,
IViewTagAggregatorFactoryService aggregatorService,
IAsynchronousOperationListener asyncListener,
string adornmentLayerName)
{
Contract.ThrowIfNull(threadingContext);
Contract.ThrowIfNull(textView);
Contract.ThrowIfNull(aggregatorService);
Contract.ThrowIfNull(adornmentLayerName);
Contract.ThrowIfNull(asyncListener);
return new AdornmentManager<T>(textView, aggregatorService, asyncListener, adornmentLayerName);
return new AdornmentManager<T>(threadingContext, textView, aggregatorService, asyncListener, adornmentLayerName);
}
internal AdornmentManager(
IThreadingContext threadingContext,
IWpfTextView textView,
IViewTagAggregatorFactoryService tagAggregatorFactoryService,
IAsynchronousOperationListener asyncListener,
string adornmentLayerName)
{
Contract.ThrowIfNull(threadingContext);
Contract.ThrowIfNull(textView);
Contract.ThrowIfNull(tagAggregatorFactoryService);
Contract.ThrowIfNull(adornmentLayerName);
Contract.ThrowIfNull(asyncListener);
_threadingContext = threadingContext;
_textView = textView;
_adornmentLayer = textView.GetAdornmentLayer(adornmentLayerName);
textView.LayoutChanged += OnLayoutChanged;
......@@ -171,19 +180,14 @@ private void OnTagsChanged(object sender, TagsChangedEventArgs e)
if (needToScheduleUpdate)
{
// schedule an update
var asyncToken = _asyncListener.BeginAsyncOperation(GetType() + ".OnTagsChanged.2");
_textView.VisualElement.Dispatcher.BeginInvoke(
new System.Action(() =>
_threadingContext.JoinableTaskFactory.WithPriority(_textView.VisualElement.Dispatcher, DispatcherPriority.Render).RunAsync(async () =>
{
try
using (_asyncListener.BeginAsyncOperation(GetType() + ".OnTagsChanged.2"))
{
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true);
UpdateInvalidSpans();
}
finally
{
asyncToken.Dispose();
}
}), DispatcherPriority.Render);
});
}
}
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using System.Linq;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
......@@ -26,9 +22,12 @@ internal sealed class CompletionPresenter : ForegroundThreadAffinitizedObject, I
private readonly IGlyphService _glyphService;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CompletionPresenter(
IThreadingContext threadingContext,
ICompletionBroker completionBroker,
IGlyphService glyphService)
: base(threadingContext)
{
_completionBroker = completionBroker;
_glyphService = glyphService;
......@@ -42,13 +41,14 @@ internal sealed class CompletionPresenter : ForegroundThreadAffinitizedObject, I
var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
return new CompletionPresenterSession(
ThreadingContext,
_completionBroker, _glyphService, textView, subjectBuffer);
}
ICompletionSource ICompletionSourceProvider.TryCreateCompletionSource(ITextBuffer textBuffer)
{
AssertIsForeground();
return new CompletionSource();
return new CompletionSource(ThreadingContext);
}
}
}
......@@ -51,10 +51,12 @@ internal sealed class CompletionPresenterSession : ForegroundThreadAffinitizedOb
private IDisposable _logger;
public CompletionPresenterSession(
IThreadingContext threadingContext,
ICompletionBroker completionBroker,
IGlyphService glyphService,
ITextView textView,
ITextBuffer subjectBuffer)
: base(threadingContext)
{
_completionBroker = completionBroker;
this.GlyphService = glyphService;
......
......@@ -9,6 +9,11 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion.P
{
internal sealed class CompletionSource : ForegroundThreadAffinitizedObject, ICompletionSource
{
public CompletionSource(IThreadingContext threadingContext)
: base(threadingContext)
{
}
void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
{
AssertIsForeground();
......
......@@ -7,21 +7,18 @@
using System.Globalization;
using System.Linq;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using VSCompletion = Microsoft.VisualStudio.Language.Intellisense.Completion;
using CompletionItem = Microsoft.CodeAnalysis.Completion.CompletionItem;
using VSCompletion = Microsoft.VisualStudio.Language.Intellisense.Completion;
namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion.Presentation
{
internal class RoslynCompletionSet : CompletionSet2
{
private readonly ITextView _textView;
private readonly ForegroundThreadAffinitizedObject _foregroundThread = new ForegroundThreadAffinitizedObject();
private readonly bool _highlightMatchingPortions;
private readonly bool _showFilters;
......@@ -95,7 +92,7 @@ public override void Recalculate()
ImmutableArray<CompletionItemFilter> completionItemFilters,
string filterText)
{
_foregroundThread.AssertIsForeground();
CompletionPresenterSession.AssertIsForeground();
foreach (var item in completionItems)
{
......@@ -209,7 +206,7 @@ private Document GetDocument()
private CompletionHelper GetCompletionHelper()
{
_foregroundThread.AssertIsForeground();
CompletionPresenterSession.AssertIsForeground();
if (_completionHelper == null)
{
var document = GetDocument();
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
......@@ -14,6 +15,7 @@
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Classification;
......@@ -27,6 +29,7 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion.P
[ContentType(ContentTypeNames.RoslynContentType)]
internal class ToolTipProvider : IUIElementProvider<VSCompletion, ICompletionSession>
{
private readonly IThreadingContext _threadingContext;
private readonly ClassificationTypeMap _typeMap;
private readonly IClassificationFormatMap _formatMap;
......@@ -35,8 +38,10 @@ internal class ToolTipProvider : IUIElementProvider<VSCompletion, ICompletionSes
private readonly TextBlock _defaultTextBlock;
[ImportingConstructor]
public ToolTipProvider(ClassificationTypeMap typeMap, IClassificationFormatMapService classificationFormatMapService)
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public ToolTipProvider(IThreadingContext threadingContext, ClassificationTypeMap typeMap, IClassificationFormatMapService classificationFormatMapService)
{
_threadingContext = threadingContext;
_typeMap = typeMap;
_formatMap = classificationFormatMapService.GetClassificationFormatMap("tooltip");
_defaultTextBlock = new TaggedText(TextTags.Text, "...").ToTextBlock(_formatMap, typeMap);
......@@ -55,13 +60,12 @@ public UIElement GetUIElement(VSCompletion itemToRender, ICompletionSession cont
private class CancellableContentControl : ContentControl
{
private readonly ForegroundThreadAffinitizedObject _foregroundObject = new ForegroundThreadAffinitizedObject();
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
private readonly ToolTipProvider _toolTipProvider;
public CancellableContentControl(ToolTipProvider toolTipProvider, CustomCommitCompletion item)
{
Debug.Assert(_foregroundObject.IsForeground());
Debug.Assert(toolTipProvider._threadingContext.JoinableTaskContext.IsOnMainThread);
_toolTipProvider = toolTipProvider;
// Set our content to be "..." initially.
......@@ -81,7 +85,7 @@ public CancellableContentControl(ToolTipProvider toolTipProvider, CustomCommitCo
private void ProcessDescription(Task<CompletionDescription> obj)
{
Debug.Assert(_foregroundObject.IsForeground());
Debug.Assert(_toolTipProvider._threadingContext.JoinableTaskContext.IsOnMainThread);
// If we were canceled, or didn't run all the way to completion, then don't bother
// updating the UI.
......
......@@ -23,7 +23,8 @@ private class SizeToFitHelper : ForegroundThreadAffinitizedObject
private double _width;
private double _height;
public SizeToFitHelper(IWpfDifferenceViewer diffViewer, double minWidth)
public SizeToFitHelper(IThreadingContext threadingContext, IWpfDifferenceViewer diffViewer, double minWidth)
: base(threadingContext)
{
_calculationStarted = 0;
_diffViewer = diffViewer;
......@@ -138,9 +139,9 @@ private static bool IsNormal(double value)
}
}
public static Task SizeToFitAsync(this IWpfDifferenceViewer diffViewer, double minWidth = 400.0)
public static Task SizeToFitAsync(this IWpfDifferenceViewer diffViewer, IThreadingContext threadingContext, double minWidth = 400.0)
{
var helper = new SizeToFitHelper(diffViewer, minWidth);
var helper = new SizeToFitHelper(threadingContext, diffViewer, minWidth);
return helper.SizeToFitAsync();
}
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.VisualStudio.Text.Editor;
namespace Microsoft.CodeAnalysis.Editor.Shared.Extensions
{
internal static class IWpfTextViewExtensions
{
public static void SizeToFit(this IWpfTextView view)
public static void SizeToFit(this IWpfTextView view, IThreadingContext threadingContext)
{
void firstLayout(object sender, TextViewLayoutChangedEventArgs args)
{
view.VisualElement.Dispatcher.BeginInvoke(new Action(() =>
threadingContext.JoinableTaskFactory.RunAsync(async () =>
{
await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true);
var newHeight = view.LineHeight * view.TextBuffer.CurrentSnapshot.LineCount;
if (IsGreater(newHeight, view.VisualElement.Height))
{
......@@ -24,9 +26,11 @@ void firstLayout(object sender, TextViewLayoutChangedEventArgs args)
{
view.VisualElement.Width = newWidth;
}
}));
});
view.LayoutChanged -= firstLayout;
}
view.LayoutChanged += firstLayout;
bool IsGreater(double value, double other)
......
......@@ -5,6 +5,8 @@
using System.ComponentModel.Composition;
using System.Threading;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
......@@ -18,6 +20,7 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename
[Export(typeof(InlineRenameService))]
internal class InlineRenameService : IInlineRenameService
{
private readonly IThreadingContext _threadingContext;
private readonly IWaitIndicator _waitIndicator;
private readonly ITextBufferAssociatedViewService _textBufferAssociatedViewService;
private readonly IAsynchronousOperationListener _asyncListener;
......@@ -27,13 +30,16 @@ internal class InlineRenameService : IInlineRenameService
private InlineRenameSession _activeRenameSession;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public InlineRenameService(
IThreadingContext threadingContext,
IWaitIndicator waitIndicator,
ITextBufferAssociatedViewService textBufferAssociatedViewService,
ITextBufferFactoryService textBufferFactoryService,
[ImportMany] IEnumerable<IRefactorNotifyService> refactorNotifyServices,
IAsynchronousOperationListenerProvider listenerProvider)
{
_threadingContext = threadingContext;
_waitIndicator = waitIndicator;
_textBufferAssociatedViewService = textBufferAssociatedViewService;
_textBufferFactoryService = textBufferFactoryService;
......@@ -60,6 +66,7 @@ internal class InlineRenameService : IInlineRenameService
var snapshot = document.GetTextAsync(cancellationToken).WaitAndGetResult(cancellationToken).FindCorrespondingEditorTextSnapshot();
ActiveSession = new InlineRenameSession(
_threadingContext,
this,
document.Project.Solution.Workspace,
renameInfo.TriggerSpan.ToSnapshotSpan(snapshot),
......
......@@ -55,6 +55,7 @@ internal class OpenTextBufferManager : ForegroundThreadAffinitizedObject
Workspace workspace,
IEnumerable<Document> documents,
ITextBufferFactoryService textBufferFactoryService)
: base(session.ThreadingContext)
{
_session = session;
_subjectBuffer = subjectBuffer;
......
......@@ -23,6 +23,7 @@
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Threading;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename
......@@ -91,6 +92,7 @@ private set
private readonly IInlineRenameInfo _renameInfo;
public InlineRenameSession(
IThreadingContext threadingContext,
InlineRenameService renameService,
Workspace workspace,
SnapshotSpan triggerSpan,
......@@ -99,7 +101,8 @@ private set
ITextBufferAssociatedViewService textBufferAssociatedViewService,
ITextBufferFactoryService textBufferFactoryService,
IEnumerable<IRefactorNotifyService> refactorNotifyServices,
IAsynchronousOperationListener asyncListener) : base(assertIsForeground: true)
IAsynchronousOperationListener asyncListener)
: base(threadingContext, assertIsForeground: true)
{
// This should always be touching a symbol since we verified that upon invocation
_renameInfo = renameInfo;
......@@ -262,11 +265,15 @@ private void UpdateReferenceLocationsTask(Task<IInlineRenameLocationSet> allRena
var asyncToken = _asyncListener.BeginAsyncOperation("UpdateReferencesTask");
_allRenameLocationsTask = allRenameLocationsTask;
allRenameLocationsTask.SafeContinueWith(
t => RaiseSessionSpansUpdated(t.Result.Locations.ToImmutableArray()),
allRenameLocationsTask.SafeContinueWithFromAsync(
async t =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _cancellationTokenSource.Token);
RaiseSessionSpansUpdated(t.Result.Locations.ToImmutableArray());
},
_cancellationTokenSource.Token,
TaskContinuationOptions.OnlyOnRanToCompletion,
ForegroundTaskScheduler).CompletesAsyncOperation(asyncToken);
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default).CompletesAsyncOperation(asyncToken);
UpdateConflictResolutionTask();
QueueApplyReplacements();
......@@ -448,7 +455,11 @@ internal void ApplyReplacementText(string replacementText, bool propagateEditImm
else
{
// When responding to a text edit, we delay propagating the edit until the first transaction completes.
Dispatcher.CurrentDispatcher.BeginInvoke(propagateEditAction, DispatcherPriority.Send, null);
ThreadingContext.JoinableTaskFactory.WithPriority(Dispatcher.CurrentDispatcher, DispatcherPriority.Send).RunAsync(async () =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true);
propagateEditAction();
});
}
}
......@@ -498,11 +509,15 @@ private void QueueApplyReplacements()
TaskContinuationOptions.OnlyOnRanToCompletion,
TaskScheduler.Default)
.Unwrap()
.SafeContinueWith(
t => ApplyReplacements(t.Result.replacementInfo, t.Result.mergeResult, _conflictResolutionTaskCancellationSource.Token),
.SafeContinueWithFromAsync(
async t =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _conflictResolutionTaskCancellationSource.Token);
ApplyReplacements(t.Result.replacementInfo, t.Result.mergeResult, _conflictResolutionTaskCancellationSource.Token);
},
_conflictResolutionTaskCancellationSource.Token,
TaskContinuationOptions.OnlyOnRanToCompletion,
ForegroundTaskScheduler)
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default)
.CompletesAsyncOperation(asyncToken);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Implementation.Adornments;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
......@@ -31,10 +32,12 @@ internal class LineSeparatorAdornmentManagerProvider :
#pragma warning restore 0169
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public LineSeparatorAdornmentManagerProvider(
IThreadingContext threadingContext,
IViewTagAggregatorFactoryService tagAggregatorFactoryService,
IAsynchronousOperationListenerProvider listenerProvider)
: base(tagAggregatorFactoryService, listenerProvider)
: base(threadingContext, tagAggregatorFactoryService, listenerProvider)
{
}
......
......@@ -7,7 +7,9 @@
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
......@@ -40,11 +42,13 @@ internal partial class LineSeparatorTaggerProvider : AsynchronousTaggerProvider<
private LineSeparatorTag _lineSeparatorTag;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public LineSeparatorTaggerProvider(
IThreadingContext threadingContext,
IEditorFormatMapService editorFormatMapService,
IForegroundNotificationService notificationService,
IAsynchronousOperationListenerProvider listenerProvider)
: base(listenerProvider.GetListener(FeatureAttribute.LineSeparators), notificationService)
: base(threadingContext, listenerProvider.GetListener(FeatureAttribute.LineSeparators), notificationService)
{
_editorFormatMap = editorFormatMapService.GetEditorFormatMap("text");
_editorFormatMap.FormatMappingChanged += OnFormatMappingChanged;
......
......@@ -64,7 +64,7 @@ private class Searcher
}
}
internal async void Search()
internal async Task SearchAsync()
{
try
{
......
......@@ -153,7 +153,7 @@ private void StartSearch(INavigateToCallback callback, string searchValue, IImmu
kinds,
_cancellationTokenSource.Token);
searcher.Search();
_ = searcher.SearchAsync();
}
private static INavigateToSearchService_RemoveInterfaceAboveAndRenameThisAfterInternalsVisibleToUsersUpdate TryGetNavigateToSearchService(Project project)
......
......@@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Preview;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
......@@ -39,7 +40,9 @@ internal class PreviewFactoryService : ForegroundThreadAffinitizedObject, IPrevi
private readonly IWpfDifferenceViewerFactoryService _differenceViewerService;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public PreviewFactoryService(
IThreadingContext threadingContext,
ITextBufferFactoryService textBufferFactoryService,
IContentTypeRegistryService contentTypeRegistryService,
IProjectionBufferFactoryService projectionBufferFactoryService,
......@@ -48,8 +51,9 @@ internal class PreviewFactoryService : ForegroundThreadAffinitizedObject, IPrevi
ITextDifferencingSelectorService differenceSelectorService,
IDifferenceBufferFactoryService differenceBufferService,
IWpfDifferenceViewerFactoryService differenceViewerService)
: base(threadingContext)
{
Contract.ThrowIfTrue(this.ForegroundKind == ForegroundThreadDataKind.Unknown);
Contract.ThrowIfFalse(ThreadingContext.HasMainThread);
_textBufferFactoryService = textBufferFactoryService;
_contentTypeRegistryService = contentTypeRegistryService;
......@@ -197,7 +201,7 @@ public SolutionPreviewResult GetSolutionPreviews(Solution oldSolution, Solution
changeSummary = new SolutionChangeSummary(oldSolution, newSolution, solutionChanges);
}
return new SolutionPreviewResult(previewItems, changeSummary);
return new SolutionPreviewResult(ThreadingContext, previewItems, changeSummary);
}
private bool ProjectReferencesChanged(ProjectChanges projectChanges)
......@@ -621,7 +625,7 @@ private ITextBuffer CreateNewPlainTextBuffer(TextDocument document, Cancellation
AssertIsForeground();
// We use ConfigureAwait(true) to stay on the UI thread.
await diffViewer.SizeToFitAsync().ConfigureAwait(true);
await diffViewer.SizeToFitAsync(ThreadingContext).ConfigureAwait(true);
leftWorkspace?.EnableDiagnostic();
rightWorkspace?.EnableDiagnostic();
......
......@@ -5,10 +5,10 @@
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Projection;
using Microsoft.VisualStudio.Utilities;
namespace Microsoft.CodeAnalysis.Editor.QuickInfo
{
......@@ -16,16 +16,20 @@ namespace Microsoft.CodeAnalysis.Editor.QuickInfo
[QuickInfoConverterMetadata(typeof(ProjectionBufferDeferredContent))]
class ProjectionBufferDeferredContentConverter : IDeferredQuickInfoContentToFrameworkElementConverter
{
private readonly IThreadingContext _threadingContext;
private readonly IProjectionBufferFactoryService _projectionBufferFactoryService;
private readonly IEditorOptionsFactoryService _editorOptionsFactoryService;
private readonly ITextEditorFactoryService _textEditorFactoryService;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public ProjectionBufferDeferredContentConverter(
IThreadingContext threadingContext,
IProjectionBufferFactoryService projectionBufferFactoryService,
IEditorOptionsFactoryService editorOptionsFactoryService,
ITextEditorFactoryService textEditorFactoryService)
{
_threadingContext = threadingContext;
_projectionBufferFactoryService = projectionBufferFactoryService;
_editorOptionsFactoryService = editorOptionsFactoryService;
_textEditorFactoryService = textEditorFactoryService;
......@@ -42,7 +46,7 @@ private IWpfTextView CreateView(ProjectionBufferDeferredContent deferredContent,
var view = _textEditorFactoryService.CreateTextView(
buffer, deferredContent.RoleSet ?? _textEditorFactoryService.NoRoles);
view.SizeToFit();
view.SizeToFit(_threadingContext);
view.Background = Brushes.Transparent;
// Zoom out a bit to shrink the text.
......
......@@ -28,12 +28,13 @@ private class QuickInfoPresenterSession : ForegroundThreadAffinitizedObject, IQu
public event EventHandler<EventArgs> Dismissed;
public QuickInfoPresenterSession(IQuickInfoBroker quickInfoBroker, DeferredContentFrameworkElementFactory elementFactory, ITextView textView, ITextBuffer subjectBuffer)
: this(quickInfoBroker, elementFactory, textView, subjectBuffer, null)
public QuickInfoPresenterSession(IThreadingContext threadingContext, IQuickInfoBroker quickInfoBroker, DeferredContentFrameworkElementFactory elementFactory, ITextView textView, ITextBuffer subjectBuffer)
: this(threadingContext, quickInfoBroker, elementFactory, textView, subjectBuffer, null)
{
}
public QuickInfoPresenterSession(IQuickInfoBroker quickInfoBroker, DeferredContentFrameworkElementFactory elementFactory, ITextView textView, ITextBuffer subjectBuffer, IQuickInfoSession sessionOpt)
public QuickInfoPresenterSession(IThreadingContext threadingContext, IQuickInfoBroker quickInfoBroker, DeferredContentFrameworkElementFactory elementFactory, ITextView textView, ITextBuffer subjectBuffer, IQuickInfoSession sessionOpt)
: base(threadingContext)
{
_quickInfoBroker = quickInfoBroker;
_elementFactory = elementFactory;
......
......@@ -12,6 +12,11 @@ internal partial class QuickInfoPresenter
{
private class QuickInfoSource : ForegroundThreadAffinitizedObject, IQuickInfoSource
{
public QuickInfoSource(IThreadingContext threadingContext)
: base(threadingContext)
{
}
public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
{
AssertIsForeground();
......
......@@ -24,7 +24,8 @@ internal partial class QuickInfoPresenter : ForegroundThreadAffinitizedObject, I
private readonly DeferredContentFrameworkElementFactory _elementFactory;
[ImportingConstructor]
public QuickInfoPresenter(IQuickInfoBroker quickInfoBroker, DeferredContentFrameworkElementFactory elementFactory)
public QuickInfoPresenter(IThreadingContext threadingContext, IQuickInfoBroker quickInfoBroker, DeferredContentFrameworkElementFactory elementFactory)
: base(threadingContext)
{
_quickInfoBroker = quickInfoBroker;
_elementFactory = elementFactory;
......@@ -33,13 +34,13 @@ public QuickInfoPresenter(IQuickInfoBroker quickInfoBroker, DeferredContentFrame
IQuickInfoPresenterSession IIntelliSensePresenter<IQuickInfoPresenterSession, IQuickInfoSession>.CreateSession(ITextView textView, ITextBuffer subjectBuffer, IQuickInfoSession sessionOpt)
{
AssertIsForeground();
return new QuickInfoPresenterSession(_quickInfoBroker, _elementFactory, textView, subjectBuffer, sessionOpt);
return new QuickInfoPresenterSession(ThreadingContext, _quickInfoBroker, _elementFactory, textView, subjectBuffer, sessionOpt);
}
IQuickInfoSource IQuickInfoSourceProvider.TryCreateQuickInfoSource(ITextBuffer textBuffer)
{
AssertIsForeground();
return new QuickInfoSource();
return new QuickInfoSource(ThreadingContext);
}
}
}
......
......@@ -6,6 +6,7 @@
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Internal.Log;
......@@ -42,12 +43,13 @@ internal abstract partial class AbstractStructureTaggerProvider<TRegionTag> :
protected readonly IProjectionBufferFactoryService ProjectionBufferFactoryService;
protected AbstractStructureTaggerProvider(
IThreadingContext threadingContext,
IForegroundNotificationService notificationService,
ITextEditorFactoryService textEditorFactoryService,
IEditorOptionsFactoryService editorOptionsFactoryService,
IProjectionBufferFactoryService projectionBufferFactoryService,
IAsynchronousOperationListenerProvider listenerProvider)
: base(listenerProvider.GetListener(FeatureAttribute.Outlining), notificationService)
: base(threadingContext, listenerProvider.GetListener(FeatureAttribute.Outlining), notificationService)
{
TextEditorFactoryService = textEditorFactoryService;
EditorOptionsFactoryService = editorOptionsFactoryService;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Threading;
......@@ -7,6 +8,7 @@
using Microsoft.CodeAnalysis.Editor.Implementation.Structure;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Adornments;
......@@ -28,9 +30,12 @@ internal class RoslynBlockContextProvider : ForegroundThreadAffinitizedObject, I
private readonly IProjectionBufferFactoryService _projectionBufferFactoryService;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public RoslynBlockContextProvider(
IThreadingContext threadingContext,
ITextEditorFactoryService textEditorFactoryService,
IProjectionBufferFactoryService projectionBufferFactoryService)
: base(threadingContext)
{
_textEditorFactoryService = textEditorFactoryService;
_projectionBufferFactoryService = projectionBufferFactoryService;
......@@ -84,6 +89,7 @@ private class RoslynBlockContext : ForegroundThreadAffinitizedObject, IBlockCont
RoslynBlockContextProvider provider,
IBlockTag blockTag,
ITextView textView)
: base(provider.ThreadingContext)
{
_provider = provider;
BlockTag = blockTag;
......@@ -105,6 +111,7 @@ private object CreateContent()
private IWpfTextView CreateElisionBufferView(ITextBuffer finalBuffer)
{
return BlockTagState.CreateShrunkenTextView(
_provider.ThreadingContext,
_provider._textEditorFactoryService, finalBuffer);
}
......
......@@ -24,6 +24,7 @@ internal struct BlockTagState
private const string Ellipsis = "...";
private const int MaxPreviewText = 1000;
private readonly IThreadingContext _threadingContext;
private readonly ITextEditorFactoryService _textEditorFactoryService;
private readonly IProjectionBufferFactoryService _projectionBufferFactoryService;
private readonly IEditorOptionsFactoryService _editorOptionsFactoryService;
......@@ -38,12 +39,14 @@ internal struct BlockTagState
public readonly BlockSpan BlockSpan;
public BlockTagState(
IThreadingContext threadingContext,
ITextEditorFactoryService textEditorFactoryService,
IProjectionBufferFactoryService projectionBufferFactoryService,
IEditorOptionsFactoryService editorOptionsFactoryService,
ITextSnapshot snapshot,
BlockSpan blockSpan)
{
_threadingContext = threadingContext;
_textEditorFactoryService = textEditorFactoryService;
_projectionBufferFactoryService = projectionBufferFactoryService;
_editorOptionsFactoryService = editorOptionsFactoryService;
......@@ -68,9 +71,10 @@ public object CollapsedHintForm
=> new ViewHostingControl(CreateElisionBufferView, CreateElisionBuffer);
private IWpfTextView CreateElisionBufferView(ITextBuffer finalBuffer)
=> CreateShrunkenTextView(_textEditorFactoryService, finalBuffer);
=> CreateShrunkenTextView(_threadingContext, _textEditorFactoryService, finalBuffer);
internal static IWpfTextView CreateShrunkenTextView(
IThreadingContext threadingContext,
ITextEditorFactoryService textEditorFactoryService,
ITextBuffer finalBuffer)
{
......@@ -79,7 +83,7 @@ private IWpfTextView CreateElisionBufferView(ITextBuffer finalBuffer)
view.Background = Brushes.Transparent;
view.SizeToFit();
view.SizeToFit(threadingContext);
// Zoom out a bit to shrink the text.
view.ZoomLevel *= 0.75;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Editor.Implementation.Structure;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
......@@ -19,6 +20,7 @@ internal class RoslynBlockTag : BlockTag
public override int Level { get; }
public RoslynBlockTag(
IThreadingContext threadingContext,
ITextEditorFactoryService textEditorFactoryService,
IProjectionBufferFactoryService projectionBufferFactoryService,
IEditorOptionsFactoryService editorOptionsFactoryService,
......@@ -36,6 +38,7 @@ internal class RoslynBlockTag : BlockTag
collapsedHintForm: null)
{
_state = new BlockTagState(
threadingContext,
textEditorFactoryService, projectionBufferFactoryService,
editorOptionsFactoryService, snapshot, blockSpan);
Level = parent == null ? 0 : parent.Level + 1;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
......@@ -16,6 +17,7 @@ internal class RoslynOutliningRegionTag : IOutliningRegionTag
private readonly BlockTagState _state;
public RoslynOutliningRegionTag(
IThreadingContext threadingContext,
ITextEditorFactoryService textEditorFactoryService,
IProjectionBufferFactoryService projectionBufferFactoryService,
IEditorOptionsFactoryService editorOptionsFactoryService,
......@@ -23,6 +25,7 @@ internal class RoslynOutliningRegionTag : IOutliningRegionTag
BlockSpan blockSpan)
{
_state = new BlockTagState(
threadingContext,
textEditorFactoryService, projectionBufferFactoryService,
editorOptionsFactoryService, snapshot, blockSpan);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.VisualStudio.Text;
......@@ -31,12 +30,13 @@ internal partial class VisualStudio14StructureTaggerProvider :
{
[ImportingConstructor]
public VisualStudio14StructureTaggerProvider(
IThreadingContext threadingContext,
IForegroundNotificationService notificationService,
ITextEditorFactoryService textEditorFactoryService,
IEditorOptionsFactoryService editorOptionsFactoryService,
IProjectionBufferFactoryService projectionBufferFactoryService,
IAsynchronousOperationListenerProvider listenerProvider)
: base(notificationService, textEditorFactoryService, editorOptionsFactoryService, projectionBufferFactoryService, listenerProvider)
: base(threadingContext, notificationService, textEditorFactoryService, editorOptionsFactoryService, projectionBufferFactoryService, listenerProvider)
{
}
......@@ -50,6 +50,7 @@ internal partial class VisualStudio14StructureTaggerProvider :
}
return new RoslynOutliningRegionTag(
ThreadingContext,
this.TextEditorFactoryService,
this.ProjectionBufferFactoryService,
this.EditorOptionsFactoryService,
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Implementation.Structure;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.VisualStudio.Text;
......@@ -23,13 +24,15 @@ internal partial class VisualStudio15StructureTaggerProvider :
AbstractStructureTaggerProvider<IBlockTag>
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public VisualStudio15StructureTaggerProvider(
IThreadingContext threadingContext,
IForegroundNotificationService notificationService,
ITextEditorFactoryService textEditorFactoryService,
IEditorOptionsFactoryService editorOptionsFactoryService,
IProjectionBufferFactoryService projectionBufferFactoryService,
IAsynchronousOperationListenerProvider listenerProvider)
: base(notificationService, textEditorFactoryService, editorOptionsFactoryService, projectionBufferFactoryService, listenerProvider)
: base(threadingContext, notificationService, textEditorFactoryService, editorOptionsFactoryService, projectionBufferFactoryService, listenerProvider)
{
}
......@@ -37,6 +40,7 @@ internal partial class VisualStudio15StructureTaggerProvider :
IBlockTag parentTag, ITextSnapshot snapshot, BlockSpan region)
{
return new RoslynBlockTag(
ThreadingContext,
this.TextEditorFactoryService,
this.ProjectionBufferFactoryService,
this.EditorOptionsFactoryService,
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.VisualStudio.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions
{
......@@ -19,12 +16,13 @@ internal partial class SuggestedActionWithNestedFlavors
private sealed partial class PreviewChangesSuggestedAction : SuggestedAction
{
private PreviewChangesSuggestedAction(
IThreadingContext threadingContext,
SuggestedActionsSourceProvider sourceProvider,
Workspace workspace,
ITextBuffer subjectBuffer,
object provider,
PreviewChangesCodeAction codeAction)
: base(sourceProvider, workspace, subjectBuffer, provider, codeAction)
: base(threadingContext, sourceProvider, workspace, subjectBuffer, provider, codeAction)
{
}
......@@ -44,6 +42,7 @@ private sealed partial class PreviewChangesSuggestedAction : SuggestedAction
}
return new PreviewChangesSuggestedAction(
suggestedAction.ThreadingContext,
suggestedAction.SourceProvider, suggestedAction.Workspace,
suggestedAction.SubjectBuffer, suggestedAction.Provider,
new PreviewChangesCodeAction(
......
......@@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
......@@ -19,10 +20,11 @@ internal sealed class SuggestedActionWithNestedActions : SuggestedAction
public readonly SuggestedActionSet NestedActionSet;
public SuggestedActionWithNestedActions(
IThreadingContext threadingContext,
SuggestedActionsSourceProvider sourceProvider, Workspace workspace,
ITextBuffer subjectBuffer, object provider,
CodeAction codeAction, SuggestedActionSet nestedActionSet)
: base(sourceProvider, workspace, subjectBuffer, provider, codeAction)
: base(threadingContext, sourceProvider, workspace, subjectBuffer, provider, codeAction)
{
NestedActionSet = nestedActionSet;
}
......
......@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Extensions;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;
......@@ -31,11 +32,12 @@ internal abstract partial class SuggestedActionWithNestedFlavors : SuggestedActi
private ImmutableArray<SuggestedActionSet> _nestedFlavors;
public SuggestedActionWithNestedFlavors(
IThreadingContext threadingContext,
SuggestedActionsSourceProvider sourceProvider,
Workspace workspace, ITextBuffer subjectBuffer,
object provider, CodeAction codeAction,
SuggestedActionSet additionalFlavors = null)
: base(sourceProvider, workspace, subjectBuffer,
: base(threadingContext, sourceProvider, workspace, subjectBuffer,
provider, codeAction)
{
_additionalFlavors = additionalFlavors;
......
......@@ -5,8 +5,7 @@
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
......@@ -20,6 +19,7 @@ internal sealed class CodeFixSuggestedAction : SuggestedActionWithNestedFlavors,
private readonly CodeFix _fix;
public CodeFixSuggestedAction(
IThreadingContext threadingContext,
SuggestedActionsSourceProvider sourceProvider,
Workspace workspace,
ITextBuffer subjectBuffer,
......@@ -27,7 +27,7 @@ internal sealed class CodeFixSuggestedAction : SuggestedActionWithNestedFlavors,
object provider,
CodeAction action,
SuggestedActionSet fixAllFlavors)
: base(sourceProvider, workspace, subjectBuffer,
: base(threadingContext, sourceProvider, workspace, subjectBuffer,
provider, action, fixAllFlavors)
{
_fix = fix;
......
......@@ -2,6 +2,7 @@
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.VisualStudio.Text;
namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions
......@@ -12,12 +13,13 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions
internal sealed class CodeRefactoringSuggestedAction : SuggestedActionWithNestedFlavors
{
public CodeRefactoringSuggestedAction(
IThreadingContext threadingContext,
SuggestedActionsSourceProvider sourceProvider,
Workspace workspace,
ITextBuffer subjectBuffer,
CodeRefactoringProvider provider,
CodeAction codeAction)
: base(sourceProvider, workspace, subjectBuffer, provider, codeAction)
: base(threadingContext, sourceProvider, workspace, subjectBuffer, provider, codeAction)
{
}
}
......
......@@ -6,6 +6,7 @@
using System.Threading;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.VisualStudio.Language.Intellisense;
......@@ -31,13 +32,14 @@ internal sealed partial class FixAllSuggestedAction : SuggestedAction, ITelemetr
private readonly FixAllState _fixAllState;
internal FixAllSuggestedAction(
IThreadingContext threadingContext,
SuggestedActionsSourceProvider sourceProvider,
Workspace workspace,
ITextBuffer subjectBuffer,
FixAllState fixAllState,
Diagnostic originalFixedDiagnostic,
CodeAction originalCodeAction)
: base(sourceProvider, workspace, subjectBuffer,
: base(threadingContext, sourceProvider, workspace, subjectBuffer,
fixAllState.FixAllProvider, new FixAllCodeAction(fixAllState))
{
_fixedDiagnostic = originalFixedDiagnostic;
......
......@@ -35,11 +35,13 @@ internal abstract partial class SuggestedAction : ForegroundThreadAffinitizedObj
private ICodeActionEditHandlerService EditHandler => SourceProvider.EditHandler;
internal SuggestedAction(
IThreadingContext threadingContext,
SuggestedActionsSourceProvider sourceProvider,
Workspace workspace,
ITextBuffer subjectBuffer,
object provider,
CodeAction codeAction)
: base(threadingContext)
{
Contract.ThrowIfNull(provider);
Contract.ThrowIfNull(codeAction);
......
......@@ -49,10 +49,12 @@ private class SuggestedActionsSource : ForegroundThreadAffinitizedObject, ISugge
public event EventHandler<EventArgs> SuggestedActionsChanged;
public SuggestedActionsSource(
IThreadingContext threadingContext,
SuggestedActionsSourceProvider owner,
ITextView textView,
ITextBuffer textBuffer,
ISuggestedActionCategoryRegistryService suggestedActionCategoryRegistry)
: base(threadingContext)
{
_owner = owner;
_textView = textView;
......@@ -445,6 +447,7 @@ private CodeRefactoring FilterOnUIThread(CodeRefactoring refactoring, Workspace
{
var nestedActions = fix.Action.NestedCodeActions.SelectAsArray(
nestedAction => new CodeFixSuggestedAction(
ThreadingContext,
_owner, workspace, _subjectBuffer, fix, fixCollection.Provider,
nestedAction, getFixAllSuggestedActionSet(nestedAction)));
......@@ -453,12 +456,14 @@ private CodeRefactoring FilterOnUIThread(CodeRefactoring refactoring, Workspace
applicableToSpan: fix.PrimaryDiagnostic.Location.SourceSpan.ToSpan());
suggestedAction = new SuggestedActionWithNestedActions(
ThreadingContext,
_owner, workspace, _subjectBuffer,
fixCollection.Provider, fix.Action, set);
}
else
{
suggestedAction = new CodeFixSuggestedAction(
ThreadingContext,
_owner, workspace, _subjectBuffer, fix, fixCollection.Provider,
fix.Action, getFixAllSuggestedActionSet(fix.Action));
}
......@@ -512,6 +517,7 @@ private CodeRefactoring FilterOnUIThread(CodeRefactoring refactoring, Workspace
{
var fixAllStateForScope = fixAllState.WithScopeAndEquivalenceKey(scope, action.EquivalenceKey);
var fixAllSuggestedAction = new FixAllSuggestedAction(
ThreadingContext,
_owner, workspace, _subjectBuffer, fixAllStateForScope,
firstDiagnostic, action);
......@@ -660,18 +666,21 @@ private static SuggestedActionSetPriority GetSuggestedActionSetPriority(CodeActi
{
var nestedActions = action.NestedCodeActions.SelectAsArray(
na => new CodeRefactoringSuggestedAction(
ThreadingContext,
_owner, workspace, _subjectBuffer, refactoring.Provider, na));
var set = new SuggestedActionSet(categoryName: null,
actions: nestedActions, priority: SuggestedActionSetPriority.Medium, applicableToSpan: applicableSpan);
refactoringSuggestedActions.Add(new SuggestedActionWithNestedActions(
ThreadingContext,
_owner, workspace, _subjectBuffer,
refactoring.Provider, action, set));
}
else
{
refactoringSuggestedActions.Add(new CodeRefactoringSuggestedAction(
ThreadingContext,
_owner, workspace, _subjectBuffer, refactoring.Provider, action));
}
}
......
......@@ -8,7 +8,9 @@
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tags;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.VisualStudio.Language.Intellisense;
......@@ -32,6 +34,7 @@ internal partial class SuggestedActionsSourceProvider : ISuggestedActionsSourceP
private const int InvalidSolutionVersion = -1;
private readonly IThreadingContext _threadingContext;
private readonly ICodeRefactoringService _codeRefactoringService;
private readonly IDiagnosticAnalyzerService _diagnosticService;
private readonly ICodeFixService _codeFixService;
......@@ -45,7 +48,9 @@ internal partial class SuggestedActionsSourceProvider : ISuggestedActionsSourceP
public readonly ImmutableArray<Lazy<IImageMonikerService, OrderableMetadata>> ImageMonikerServices;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public SuggestedActionsSourceProvider(
IThreadingContext threadingContext,
ICodeRefactoringService codeRefactoringService,
IDiagnosticAnalyzerService diagnosticService,
ICodeFixService codeFixService,
......@@ -56,6 +61,7 @@ internal partial class SuggestedActionsSourceProvider : ISuggestedActionsSourceP
[ImportMany] IEnumerable<Lazy<IImageMonikerService, OrderableMetadata>> imageMonikerServices,
[ImportMany] IEnumerable<Lazy<ISuggestedActionCallback>> actionCallbacks)
{
_threadingContext = threadingContext;
_codeRefactoringService = codeRefactoringService;
_diagnosticService = diagnosticService;
_codeFixService = codeFixService;
......@@ -73,7 +79,7 @@ public ISuggestedActionsSource CreateSuggestedActionsSource(ITextView textView,
Contract.ThrowIfNull(textView);
Contract.ThrowIfNull(textBuffer);
return new SuggestedActionsSource(this, textView, textBuffer, _suggestedActionCategoryRegistry);
return new SuggestedActionsSource(_threadingContext, this, textView, textBuffer, _suggestedActionCategoryRegistry);
}
}
}
......@@ -35,7 +35,8 @@ internal abstract class AbstractCompletionCommandHandler :
public string DisplayName => EditorFeaturesResources.Code_Completion;
protected AbstractCompletionCommandHandler(IAsyncCompletionService completionService)
protected AbstractCompletionCommandHandler(IThreadingContext threadingContext, IAsyncCompletionService completionService)
: base(threadingContext)
{
_completionService = completionService;
}
......
......@@ -2,6 +2,7 @@
using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Utilities;
using VSCommanding = Microsoft.VisualStudio.Commanding;
......@@ -18,8 +19,8 @@ internal sealed class CompletionCommandHandler : AbstractCompletionCommandHandle
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CompletionCommandHandler(IAsyncCompletionService completionService)
: base(completionService)
public CompletionCommandHandler(IThreadingContext threadingContext, IAsyncCompletionService completionService)
: base(threadingContext, completionService)
{
}
}
......
......@@ -34,24 +34,17 @@ internal partial class QuickInfoCommandHandlerAndSourceProvider :
private readonly IList<Lazy<IQuickInfoProvider, OrderableLanguageMetadata>> _providers;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public QuickInfoCommandHandlerAndSourceProvider(
IThreadingContext threadingContext,
[ImportMany] IEnumerable<Lazy<IIntelliSensePresenter<IQuickInfoPresenterSession, IQuickInfoSession>, OrderableMetadata>> presenters,
[ImportMany] IEnumerable<Lazy<IQuickInfoProvider, OrderableLanguageMetadata>> providers,
IAsynchronousOperationListenerProvider listenerProvider)
: this(ExtensionOrderer.Order(presenters).Select(lazy => lazy.Value).FirstOrDefault(),
providers, listenerProvider)
{
}
// For testing purposes.
public QuickInfoCommandHandlerAndSourceProvider(
IIntelliSensePresenter<IQuickInfoPresenterSession, IQuickInfoSession> presenter,
[ImportMany] IEnumerable<Lazy<IQuickInfoProvider, OrderableLanguageMetadata>> providers,
IAsynchronousOperationListenerProvider listenerProvider)
: base(threadingContext)
{
_providers = ExtensionOrderer.Order(providers);
_listener = listenerProvider.GetListener(FeatureAttribute.QuickInfo);
_presenter = presenter;
_presenter = ExtensionOrderer.Order(presenters).Select(lazy => lazy.Value).FirstOrDefault();
}
private bool TryGetController(EditorCommandArgs args, out Controller controller)
......@@ -75,7 +68,7 @@ private bool TryGetController(EditorCommandArgs args, out Controller controller)
// TODO(cyrusn): If there are no presenters then we should not create a controller.
// Otherwise we'll be affecting the user's typing and they'll have no idea why :)
controller = Controller.GetInstance(args, _presenter, _listener, _providers);
controller = Controller.GetInstance(ThreadingContext, args, _presenter, _listener, _providers);
return true;
}
......
......@@ -40,9 +40,11 @@ internal class SignatureHelpCommandHandler :
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public SignatureHelpCommandHandler(
IThreadingContext threadingContext,
[ImportMany] IEnumerable<Lazy<ISignatureHelpProvider, OrderableLanguageMetadata>> signatureHelpProviders,
[ImportMany] IEnumerable<Lazy<IIntelliSensePresenter<ISignatureHelpPresenterSession, ISignatureHelpSession>, OrderableMetadata>> signatureHelpPresenters,
IAsynchronousOperationListenerProvider listenerProvider)
: base(threadingContext)
{
_signatureHelpProviders = ExtensionOrderer.Order(signatureHelpProviders);
_listener = listenerProvider.GetListener(FeatureAttribute.SignatureHelp);
......@@ -70,6 +72,7 @@ private bool TryGetController(EditorCommandArgs args, out Controller controller)
}
controller = Controller.GetInstance(
ThreadingContext,
args, _signatureHelpPresenter,
_listener, _signatureHelpProviders);
......
......@@ -5,6 +5,7 @@
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.FindUsages;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
......@@ -90,7 +91,7 @@ private bool TryExecuteCommand(int caretPosition, Document document, CommandExec
// a presenter that can accept streamed results.
if (streamingService != null && streamingPresenter != null)
{
StreamingFindReferences(document, caretPosition, streamingService, streamingPresenter);
_ = StreamingFindReferencesAsync(document, caretPosition, streamingService, streamingPresenter);
return true;
}
......@@ -109,14 +110,14 @@ private IStreamingFindUsagesPresenter GetStreamingPresenter()
}
}
private async void StreamingFindReferences(
private async Task StreamingFindReferencesAsync(
Document document, int caretPosition,
IFindUsagesService findUsagesService,
IStreamingFindUsagesPresenter presenter)
{
try
{
using (var token = _asyncListener.BeginAsyncOperation(nameof(StreamingFindReferences)))
using (var token = _asyncListener.BeginAsyncOperation(nameof(StreamingFindReferencesAsync)))
{
// Let the presented know we're starting a search. It will give us back
// the context object that the FAR service will push results into.
......
......@@ -65,7 +65,8 @@ private class FindReferencesProgressAdapter : ForegroundThreadAffinitizedObject,
private readonly SemaphoreSlim _gate = new SemaphoreSlim(initialCount: 1);
public FindReferencesProgressAdapter(Solution solution, IFindUsagesContext context)
public FindReferencesProgressAdapter(IThreadingContext threadingContext, Solution solution, IFindUsagesContext context)
: base(threadingContext)
{
_solution = solution;
_context = context;
......
......@@ -5,6 +5,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.LanguageServices;
......@@ -15,6 +16,13 @@ namespace Microsoft.CodeAnalysis.Editor.FindUsages
{
internal abstract partial class AbstractFindUsagesService : IFindUsagesService
{
private readonly IThreadingContext _threadingContext;
protected AbstractFindUsagesService(IThreadingContext threadingContext)
{
_threadingContext = threadingContext;
}
public async Task FindImplementationsAsync(
Document document, int position, IFindUsagesContext context)
{
......@@ -120,6 +128,7 @@ internal abstract partial class AbstractFindUsagesService : IFindUsagesService
}
await FindSymbolReferencesAsync(
_threadingContext,
context, symbolAndProject?.symbol, symbolAndProject?.project, cancellationToken).ConfigureAwait(false);
}
......@@ -128,11 +137,12 @@ internal abstract partial class AbstractFindUsagesService : IFindUsagesService
/// and want to push all the references to it into the Streaming-Find-References window.
/// </summary>
public static async Task FindSymbolReferencesAsync(
IThreadingContext threadingContext,
IFindUsagesContext context, ISymbol symbol, Project project, CancellationToken cancellationToken)
{
await context.SetSearchTitleAsync(string.Format(EditorFeaturesResources._0_references,
FindUsagesHelpers.GetDisplayName(symbol))).ConfigureAwait(false);
var progressAdapter = new FindReferencesProgressAdapter(project.Solution, context);
var progressAdapter = new FindReferencesProgressAdapter(threadingContext, project.Solution, context);
// Now call into the underlying FAR engine to find reference. The FAR
// engine will push results into the 'progress' instance passed into it.
......
......@@ -3,12 +3,18 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.VisualStudio.Threading;
namespace Microsoft.CodeAnalysis.Editor.GoToDefinition
{
// Ctrl+Click (GoToSymbol)
internal abstract class AbstractGoToSymbolService : ForegroundThreadAffinitizedObject, IGoToSymbolService
{
protected AbstractGoToSymbolService(IThreadingContext threadingContext, bool assertIsForeground = false)
: base(threadingContext, assertIsForeground)
{
}
public async Task GetSymbolsAsync(GoToSymbolContext context)
{
var document = context.Document;
......@@ -29,12 +35,12 @@ public async Task GetSymbolsAsync(GoToSymbolContext context)
// We want ctrl-click GTD to be as close to regular GTD as possible.
// This means we have to query for "third party navigation", from
// XAML, etc. That call has to be done on the UI thread.
var definitions = await Task.Factory.StartNew(() =>
GoToDefinitionHelpers.GetDefinitions(symbol, document.Project, thirdPartyNavigationAllowed: true, cancellationToken: cancellationToken)
.WhereAsArray(d => d.CanNavigateTo(document.Project.Solution.Workspace)),
cancellationToken,
TaskCreationOptions.None,
ForegroundTaskScheduler).ConfigureAwait(false);
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);
var definitions = GoToDefinitionHelpers.GetDefinitions(symbol, document.Project, thirdPartyNavigationAllowed: true, cancellationToken)
.WhereAsArray(d => d.CanNavigateTo(document.Project.Solution.Workspace));
await TaskScheduler.Default;
foreach (var definition in definitions)
{
......
......@@ -4,13 +4,13 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.AutomaticCompletion
{
internal abstract class AbstractEditorBraceCompletionSessionFactory : ForegroundThreadAffinitizedObject, IEditorBraceCompletionSessionFactory
{
protected AbstractEditorBraceCompletionSessionFactory()
protected AbstractEditorBraceCompletionSessionFactory(IThreadingContext threadingContext)
: base(threadingContext)
{
}
......
......@@ -28,8 +28,10 @@ internal partial class BraceCompletionSessionProvider : ForegroundThreadAffiniti
[ImportingConstructor]
public BraceCompletionSessionProvider(
IThreadingContext threadingContext,
ITextBufferUndoManagerProvider undoManager,
IEditorOperationsFactoryService editorOperationsFactoryService)
: base(threadingContext)
{
_undoManager = undoManager;
_editorOperationsFactoryService = editorOperationsFactoryService;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
......@@ -32,10 +31,11 @@ internal class BraceHighlightingViewTaggerProvider : AsynchronousViewTaggerProvi
[ImportingConstructor]
public BraceHighlightingViewTaggerProvider(
IThreadingContext threadingContext,
IBraceMatchingService braceMatcherService,
IForegroundNotificationService notificationService,
IAsynchronousOperationListenerProvider listenerProvider)
: base(listenerProvider.GetListener(FeatureAttribute.BraceHighlighting), notificationService)
: base(threadingContext, listenerProvider.GetListener(FeatureAttribute.BraceHighlighting), notificationService)
{
_braceMatcherService = braceMatcherService;
}
......
......@@ -6,7 +6,6 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
......@@ -32,6 +31,7 @@ private class Tagger : ForegroundThreadAffinitizedObject, IAccurateTagger<IClass
private SnapshotSpan? _cachedTaggedSpan_doNotAccessDirectly;
public Tagger(SemanticClassificationBufferTaggerProvider owner, ITextBuffer subjectBuffer)
: base(owner.ThreadingContext)
{
_owner = owner;
_subjectBuffer = subjectBuffer;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Notification;
......@@ -33,10 +31,12 @@ internal partial class SemanticClassificationBufferTaggerProvider : ForegroundTh
[ImportingConstructor]
public SemanticClassificationBufferTaggerProvider(
IThreadingContext threadingContext,
IForegroundNotificationService notificationService,
ISemanticChangeNotificationService semanticChangeNotificationService,
ClassificationTypeMap typeMap,
IAsynchronousOperationListenerProvider listenerProvider)
: base(threadingContext)
{
_notificationService = notificationService;
_semanticChangeNotificationService = semanticChangeNotificationService;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics;
......@@ -44,11 +43,12 @@ internal partial class SemanticClassificationViewTaggerProvider : AsynchronousVi
[ImportingConstructor]
public SemanticClassificationViewTaggerProvider(
IThreadingContext threadingContext,
IForegroundNotificationService notificationService,
ISemanticChangeNotificationService semanticChangeNotificationService,
ClassificationTypeMap typeMap,
IAsynchronousOperationListenerProvider listenerProvider)
: base(listenerProvider.GetListener(FeatureAttribute.Classification), notificationService)
: base(threadingContext, listenerProvider.GetListener(FeatureAttribute.Classification), notificationService)
{
_semanticChangeNotificationService = semanticChangeNotificationService;
_typeMap = typeMap;
......@@ -65,7 +65,7 @@ protected override ITaggerEventSource CreateEventSource(ITextView textView, ITex
// Note: when the user scrolls, we will try to reclassify as soon as possible. That way
// we appear semantically unclassified for a very short amount of time.
return TaggerEventSources.Compose(
TaggerEventSources.OnViewSpanChanged(textView, textChangeDelay: Delay, scrollChangeDelay: TaggerDelay.NearImmediate),
TaggerEventSources.OnViewSpanChanged(ThreadingContext, textView, textChangeDelay: Delay, scrollChangeDelay: TaggerDelay.NearImmediate),
TaggerEventSources.OnSemanticChanged(subjectBuffer, Delay, _semanticChangeNotificationService),
TaggerEventSources.OnDocumentActiveContextChanged(subjectBuffer, Delay));
}
......
......@@ -79,7 +79,7 @@ internal partial class TagComputer
_typeMap = typeMap;
_taggerProvider = taggerProvider;
_workQueue = new AsynchronousSerialWorkQueue(asyncListener);
_workQueue = new AsynchronousSerialWorkQueue(taggerProvider._threadingContext, asyncListener);
_reportChangeCancellationSource = new CancellationTokenSource();
_lastLineCache = new LastLineCache();
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Runtime.CompilerServices;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
......@@ -21,6 +19,7 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Classification
[TagType(typeof(IClassificationTag))]
internal partial class SyntacticClassificationTaggerProvider : ITaggerProvider
{
private readonly IThreadingContext _threadingContext;
private readonly IForegroundNotificationService _notificationService;
private readonly IAsynchronousOperationListener _listener;
private readonly ClassificationTypeMap _typeMap;
......@@ -29,10 +28,12 @@ internal partial class SyntacticClassificationTaggerProvider : ITaggerProvider
[ImportingConstructor]
public SyntacticClassificationTaggerProvider(
IThreadingContext threadingContext,
IForegroundNotificationService notificationService,
ClassificationTypeMap typeMap,
IAsynchronousOperationListenerProvider listenerProvider)
{
_threadingContext = threadingContext;
_notificationService = notificationService;
_typeMap = typeMap;
_listener = listenerProvider.GetListener(FeatureAttribute.Classification);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using System.Diagnostics;
......@@ -11,6 +10,7 @@
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Undo;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.Extensions;
......@@ -28,10 +28,13 @@ internal class CodeActionEditHandlerService : ForegroundThreadAffinitizedObject,
private readonly ITextBufferAssociatedViewService _associatedViewService;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CodeActionEditHandlerService(
IThreadingContext threadingContext,
IPreviewFactoryService previewService,
IInlineRenameService renameService,
ITextBufferAssociatedViewService associatedViewService)
: base(threadingContext)
{
_previewService = previewService;
_renameService = renameService;
......@@ -71,7 +74,7 @@ internal class CodeActionEditHandlerService : ForegroundThreadAffinitizedObject,
if (op is PreviewOperation previewOp)
{
currentResult = SolutionPreviewResult.Merge(currentResult,
new SolutionPreviewResult(new SolutionPreviewItem(
new SolutionPreviewResult(ThreadingContext, new SolutionPreviewItem(
projectId: null, documentId: null,
lazyPreview: c => previewOp.GetPreviewAsync(c))));
continue;
......@@ -82,7 +85,7 @@ internal class CodeActionEditHandlerService : ForegroundThreadAffinitizedObject,
if (title != null)
{
currentResult = SolutionPreviewResult.Merge(currentResult,
new SolutionPreviewResult(new SolutionPreviewItem(
new SolutionPreviewResult(ThreadingContext, new SolutionPreviewItem(
projectId: null, documentId: null, text: title)));
continue;
}
......
......@@ -18,6 +18,7 @@
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Threading;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CodeFixes
......@@ -49,11 +50,12 @@ internal partial class CodeFixService : ForegroundThreadAffinitizedObject, ICode
[ImportingConstructor]
public CodeFixService(
IThreadingContext threadingContext,
IDiagnosticAnalyzerService service,
[ImportMany]IEnumerable<Lazy<IErrorLoggerService>> loggers,
[ImportMany]IEnumerable<Lazy<CodeFixProvider, CodeChangeProviderMetadata>> fixers,
[ImportMany]IEnumerable<Lazy<ISuppressionFixProvider, CodeChangeProviderMetadata>> suppressionProviders)
: base(assertIsForeground: false)
: base(threadingContext, assertIsForeground: false)
{
_errorLoggers = loggers;
_diagnosticService = service;
......@@ -519,13 +521,11 @@ private async Task<IEnumerable<Diagnostic>> GetProjectDiagnosticsAsync(Project p
// Have to see if this fix is still applicable. Jump to the foreground thread
// to make that check.
var applicable = await Task.Factory.StartNew(() =>
{
this.AssertIsForeground();
return fix.Action.IsApplicable(document.Project.Solution.Workspace);
},
cancellationToken, TaskCreationOptions.None, ForegroundTaskScheduler).ConfigureAwait(false);
this.AssertIsBackground();
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);
var applicable = fix.Action.IsApplicable(document.Project.Solution.Workspace);
await TaskScheduler.Default;
if (applicable)
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Tagging;
......@@ -14,10 +14,11 @@ internal abstract class AbstractDiagnosticsAdornmentTaggerProvider<TTag> :
where TTag : ITag
{
public AbstractDiagnosticsAdornmentTaggerProvider(
IThreadingContext threadingContext,
IDiagnosticService diagnosticService,
IForegroundNotificationService notificationService,
IAsynchronousOperationListenerProvider listenerProvider)
: base(diagnosticService, notificationService, listenerProvider.GetListener(FeatureAttribute.ErrorSquiggles))
: base(threadingContext, diagnosticService, notificationService, listenerProvider.GetListener(FeatureAttribute.ErrorSquiggles))
{
}
......
......@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Shared.Preview;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Shared.Extensions;
......@@ -17,7 +18,6 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics
{
......@@ -49,10 +49,11 @@ internal abstract partial class AbstractDiagnosticsTaggerProvider<TTag> : Asynch
new ConditionalWeakTable<object, ITextSnapshot>();
protected AbstractDiagnosticsTaggerProvider(
IThreadingContext threadingContext,
IDiagnosticService diagnosticService,
IForegroundNotificationService notificationService,
IAsynchronousOperationListener listener)
: base(listener, notificationService)
: base(threadingContext, listener, notificationService)
{
_diagnosticService = diagnosticService;
_diagnosticService.DiagnosticsUpdated += OnDiagnosticsUpdated;
......
......@@ -6,6 +6,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
......@@ -32,13 +33,15 @@ internal partial class DiagnosticsClassificationTaggerProvider : AbstractDiagnos
protected override IEnumerable<Option<bool>> Options => s_tagSourceOptions;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public DiagnosticsClassificationTaggerProvider(
IThreadingContext threadingContext,
IDiagnosticService diagnosticService,
ClassificationTypeMap typeMap,
IForegroundNotificationService notificationService,
IEditorOptionsFactoryService editorOptionsFactoryService,
IAsynchronousOperationListenerProvider listenerProvider)
: base(diagnosticService, notificationService, listenerProvider.GetListener(FeatureAttribute.Classification))
: base(threadingContext, diagnosticService, notificationService, listenerProvider.GetListener(FeatureAttribute.Classification))
{
_typeMap = typeMap;
_classificationTag = new ClassificationTag(_typeMap.GetClassificationType(ClassificationTypeDefinitions.UnnecessaryCode));
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
......@@ -9,6 +8,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Implementation.EditAndContinue;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
......@@ -34,10 +34,11 @@ internal partial class DiagnosticsSquiggleTaggerProvider : AbstractDiagnosticsAd
[ImportingConstructor]
public DiagnosticsSquiggleTaggerProvider(
IThreadingContext threadingContext,
IDiagnosticService diagnosticService,
IForegroundNotificationService notificationService,
IAsynchronousOperationListenerProvider listenerProvider)
: base(diagnosticService, notificationService, listenerProvider)
: base(threadingContext, diagnosticService, notificationService, listenerProvider)
{
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Adornments;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;
......@@ -31,10 +30,11 @@ internal partial class DiagnosticsSuggestionTaggerProvider :
[ImportingConstructor]
public DiagnosticsSuggestionTaggerProvider(
IThreadingContext threadingContext,
IDiagnosticService diagnosticService,
IForegroundNotificationService notificationService,
IAsynchronousOperationListenerProvider listenerProvider)
: base(diagnosticService, notificationService, listenerProvider)
: base(threadingContext, diagnosticService, notificationService, listenerProvider)
{
}
......
......@@ -20,7 +20,8 @@ internal sealed class ActiveStatementTagger : ForegroundThreadAffinitizedObject,
private IActiveStatementTrackingService _trackingServiceOpt;
public ActiveStatementTagger(ITextBuffer buffer)
public ActiveStatementTagger(IThreadingContext threadingContext, ITextBuffer buffer)
: base(threadingContext)
{
// A buffer can switch between workspaces (from misc files workspace to primary workspace, etc.).
// The following code handles such transitions.
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
......@@ -16,12 +17,16 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.EditAndContinue
[TextViewRole(PredefinedTextViewRoles.Editable)] // TODO (tomat): ?
internal sealed class ActiveStatementTaggerProvider : ITaggerProvider
{
private readonly IThreadingContext _threadingContext;
[ImportingConstructor]
public ActiveStatementTaggerProvider()
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public ActiveStatementTaggerProvider(IThreadingContext threadingContext)
{
_threadingContext = threadingContext;
}
public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
=> new ActiveStatementTagger(buffer) as ITagger<T>;
=> new ActiveStatementTagger(_threadingContext, buffer) as ITagger<T>;
}
}
......@@ -139,9 +139,11 @@ public void EndTracking()
}
private void DocumentOpened(object sender, DocumentEventArgs e)
=> DocumentOpenedAsync(e.Document);
{
_ = DocumentOpenedAsync(e.Document);
}
private async void DocumentOpenedAsync(Document document)
private async Task DocumentOpenedAsync(Document document)
{
try
{
......@@ -232,12 +234,12 @@ private async Task TrackActiveSpansAsync()
SetTrackingSpansNoLock(document.Id, null);
// fire and forget:
RefreshTrackingSpansAsync(document, snapshot);
_ = RefreshTrackingSpansAsync(document, snapshot);
}
}
}
private async void RefreshTrackingSpansAsync(Document document, ITextSnapshot snapshot)
private async Task RefreshTrackingSpansAsync(Document document, ITextSnapshot snapshot)
{
try
{
......
......@@ -21,8 +21,8 @@ internal sealed class ReadOnlyDocumentTracker : ForegroundThreadAffinitizedObjec
// invoked on UI thread
private readonly Action<DocumentId, SessionReadOnlyReason, ProjectReadOnlyReason> _onReadOnlyDocumentEditAttempt;
public ReadOnlyDocumentTracker(IEditAndContinueService encService, Action<DocumentId, SessionReadOnlyReason, ProjectReadOnlyReason> onReadOnlyDocumentEditAttempt)
: base(assertIsForeground: true)
public ReadOnlyDocumentTracker(IThreadingContext threadingContext, IEditAndContinueService encService, Action<DocumentId, SessionReadOnlyReason, ProjectReadOnlyReason> onReadOnlyDocumentEditAttempt)
: base(threadingContext, assertIsForeground: true)
{
Debug.Assert(encService.DebuggingSession != null);
......
......@@ -7,12 +7,11 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.ForegroundNotification
{
......@@ -31,13 +30,14 @@ internal class ForegroundNotificationService : ForegroundThreadAffinitizedObject
private int _lastProcessedTimeInMS;
[ImportingConstructor]
public ForegroundNotificationService()
public ForegroundNotificationService(IThreadingContext threadingContext)
: base(threadingContext)
{
_workQueue = new PriorityQueue();
_lastProcessedTimeInMS = Environment.TickCount;
// Only start the background processing task if foreground work is allowed
if (ForegroundKind != ForegroundThreadDataKind.Unknown)
if (threadingContext.HasMainThread)
{
Task.Factory.SafeStartNewFromAsync(ProcessAsync, CancellationToken.None, TaskScheduler.Default);
}
......@@ -64,7 +64,7 @@ public void RegisterNotification(Action action, int delay, IAsyncToken asyncToke
}
// Assert we have some kind of foreground thread
Contract.ThrowIfTrue(CurrentForegroundThreadData.Kind == ForegroundThreadDataKind.Unknown);
Contract.ThrowIfFalse(ThreadingContext.HasMainThread);
var current = Environment.TickCount;
......@@ -82,7 +82,7 @@ public void RegisterNotification(Func<bool> action, int delay, IAsyncToken async
}
// Assert we have some kind of foreground thread
Contract.ThrowIfTrue(CurrentForegroundThreadData.Kind == ForegroundThreadDataKind.Unknown);
Contract.ThrowIfFalse(ThreadingContext.HasMainThread);
var current = Environment.TickCount;
......
......@@ -47,9 +47,11 @@ internal partial class FormatCommandHandler :
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public FormatCommandHandler(
IThreadingContext threadingContext,
ITextUndoHistoryRegistry undoHistoryRegistry,
IEditorOperationsFactoryService editorOperationsFactoryService,
IWaitIndicator waitIndicator)
: base(threadingContext)
{
_undoHistoryRegistry = undoHistoryRegistry;
_editorOperationsFactoryService = editorOperationsFactoryService;
......
......@@ -28,7 +28,8 @@ internal abstract class AbstractController<TSession, TModel, TPresenterSession,
protected bool IsSessionActive => sessionOpt != null;
public AbstractController(ITextView textView, ITextBuffer subjectBuffer, IIntelliSensePresenter<TPresenterSession, TEditorSession> presenter, IAsynchronousOperationListener asyncListener, IDocumentProvider documentProvider, string asyncOperationId)
protected AbstractController(IThreadingContext threadingContext, ITextView textView, ITextBuffer subjectBuffer, IIntelliSensePresenter<TPresenterSession, TEditorSession> presenter, IAsynchronousOperationListener asyncListener, IDocumentProvider documentProvider, string asyncOperationId)
: base(threadingContext)
{
this.TextView = textView;
this.SubjectBuffer = subjectBuffer;
......
......@@ -34,12 +34,14 @@ internal class AsyncCompletionService : ForegroundThreadAffinitizedObject, IAsyn
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public AsyncCompletionService(
IThreadingContext threadingContext,
IEditorOperationsFactoryService editorOperationsFactoryService,
ITextUndoHistoryRegistry undoHistoryRegistry,
IInlineRenameService inlineRenameService,
IAsynchronousOperationListenerProvider listenerProvider,
[ImportMany] IEnumerable<Lazy<IIntelliSensePresenter<ICompletionPresenterSession, ICompletionSession>, OrderableMetadata>> completionPresenters,
[ImportMany] IEnumerable<Lazy<IBraceCompletionSessionProvider, BraceCompletionMetadata>> autoBraceCompletionChars)
: base(threadingContext)
{
_editorOperationsFactoryService = editorOperationsFactoryService;
_undoHistoryRegistry = undoHistoryRegistry;
......@@ -74,6 +76,7 @@ public bool TryGetController(ITextView textView, ITextBuffer subjectBuffer, out
var autobraceCompletionCharSet = GetAllAutoBraceCompletionChars(subjectBuffer.ContentType);
controller = Controller.GetInstance(
ThreadingContext,
textView, subjectBuffer,
_editorOperationsFactoryService, _undoHistoryRegistry, _completionPresenter,
_listener,
......
......@@ -60,6 +60,7 @@ private class ModelComputer : ForegroundThreadAffinitizedObject
CompletionTrigger trigger,
ImmutableHashSet<string> roles,
OptionSet options)
: base(session.ThreadingContext)
{
_session = session;
_completionService = completionService;
......
......@@ -3,6 +3,7 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
......@@ -49,6 +50,7 @@ internal partial class Controller :
private readonly ImmutableHashSet<string> _roles;
public Controller(
IThreadingContext threadingContext,
ITextView textView,
ITextBuffer subjectBuffer,
IEditorOperationsFactoryService editorOperationsFactoryService,
......@@ -58,7 +60,7 @@ internal partial class Controller :
ImmutableHashSet<char> autoBraceCompletionChars,
bool isDebugger,
bool isImmediateWindow)
: base(textView, subjectBuffer, presenter, asyncListener, null, "Completion")
: base(threadingContext, textView, subjectBuffer, presenter, asyncListener, null, "Completion")
{
_editorOperationsFactoryService = editorOperationsFactoryService;
_undoHistoryRegistry = undoHistoryRegistry;
......@@ -69,6 +71,7 @@ internal partial class Controller :
}
internal static Controller GetInstance(
IThreadingContext threadingContext,
ITextView textView,
ITextBuffer subjectBuffer,
IEditorOperationsFactoryService editorOperationsFactoryService,
......@@ -83,6 +86,7 @@ internal partial class Controller :
return textView.GetOrCreatePerSubjectBufferProperty(subjectBuffer, s_controllerPropertyKey,
(v, b) => new Controller(
threadingContext,
textView, subjectBuffer, editorOperationsFactoryService, undoHistoryRegistry,
presenter, asyncListener, autoBraceCompletionChars, isDebugger, isImmediateWindow));
}
......@@ -184,7 +188,7 @@ internal override void OnModelUpdated(Model modelOpt)
_editorOperationsFactoryService.GetEditorOperations(TextView).InsertText("");
}
var computation = new ModelComputation<Model>(this, PrioritizedTaskScheduler.AboveNormalInstance);
var computation = new ModelComputation<Model>(ThreadingContext, this, PrioritizedTaskScheduler.AboveNormalInstance);
this.sessionOpt = new Session(this, computation, Presenter.CreateSession(TextView, SubjectBuffer, null));
......
......@@ -4,6 +4,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
......@@ -73,9 +74,9 @@ private void CommitUniqueCompletionListItemAsynchronously()
// We're kicking off async work. Track this with an async token for test purposes.
var token = ((IController<Model>)this).BeginAsyncOperation(nameof(CommitUniqueCompletionListItemAsynchronously));
var task = currentTask.ContinueWith(t =>
var task = currentTask.ContinueWith(async t =>
{
this.AssertIsForeground();
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true);
if (this.sessionOpt == currentSession &&
this.sessionOpt.Computation.ModelTask == currentTask)
......@@ -83,7 +84,7 @@ private void CommitUniqueCompletionListItemAsynchronously()
// Nothing happened between when we were invoked and now.
CommitIfUnique(t.Result);
}
}, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, ForegroundTaskScheduler);
}, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default).Unwrap();
task.CompletesAsyncOperation(token);
}
......
......@@ -16,6 +16,11 @@ internal interface IDocumentProvider
internal class DocumentProvider : ForegroundThreadAffinitizedObject, IDocumentProvider
{
public DocumentProvider(IThreadingContext threadingContext)
: base(threadingContext)
{
}
public Task<Document> GetDocumentAsync(ITextSnapshot snapshot, CancellationToken cancellationToken)
{
AssertIsBackground();
......
......@@ -50,7 +50,8 @@ private TaskScheduler _taskScheduler
#endregion
public ModelComputation(IController<TModel> controller, TaskScheduler computationTaskScheduler)
public ModelComputation(IThreadingContext threadingContext, IController<TModel> controller, TaskScheduler computationTaskScheduler)
: base(threadingContext)
{
_controller = controller;
__taskScheduler = computationTaskScheduler;
......@@ -143,22 +144,23 @@ public virtual void Stop()
// then we don't need to notify as a later task will do so.
_notifyControllerTask = Task.Factory.ContinueWhenAll(
new[] { _notifyControllerTask, nextTask },
tasks =>
async tasks =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _stopCancellationToken);
if (tasks.All(t => t.Status == TaskStatus.RanToCompletion))
{
this.AssertIsForeground();
if (tasks.All(t => t.Status == TaskStatus.RanToCompletion))
{
_stopCancellationToken.ThrowIfCancellationRequested();
// Check if we're still the last task. If so then we should update the
// controller. Otherwise there's a pending task that should run. We
// don't need to update the controller (and the presenters) until our
// chain is finished.
updateController &= nextTask == _lastTask;
OnModelUpdated(nextTask.Result, updateController);
}
},
_stopCancellationToken, TaskContinuationOptions.None, ForegroundTaskScheduler);
_stopCancellationToken.ThrowIfCancellationRequested();
// Check if we're still the last task. If so then we should update the
// controller. Otherwise there's a pending task that should run. We
// don't need to update the controller (and the presenters) until our
// chain is finished.
updateController &= nextTask == _lastTask;
OnModelUpdated(nextTask.Result, updateController);
}
},
_stopCancellationToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default).Unwrap();
// When we've notified the controller of our result, we consider the async operation
// to be completed.
......
......@@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Internal.Log;
......@@ -28,31 +29,34 @@ internal partial class Controller :
private IList<IQuickInfoProvider> _providers;
public Controller(
IThreadingContext threadingContext,
ITextView textView,
ITextBuffer subjectBuffer,
IIntelliSensePresenter<IQuickInfoPresenterSession, IQuickInfoSession> presenter,
IAsynchronousOperationListener asyncListener,
IDocumentProvider documentProvider,
IList<Lazy<IQuickInfoProvider, OrderableLanguageMetadata>> allProviders)
: base(textView, subjectBuffer, presenter, asyncListener, documentProvider, "QuickInfo")
: base(threadingContext, textView, subjectBuffer, presenter, asyncListener, documentProvider, "QuickInfo")
{
_allProviders = allProviders;
}
// For testing purposes
internal Controller(
IThreadingContext threadingContext,
ITextView textView,
ITextBuffer subjectBuffer,
IIntelliSensePresenter<IQuickInfoPresenterSession, IQuickInfoSession> presenter,
IAsynchronousOperationListener asyncListener,
IDocumentProvider documentProvider,
IList<IQuickInfoProvider> providers)
: base(textView, subjectBuffer, presenter, asyncListener, documentProvider, "QuickInfo")
: base(threadingContext, textView, subjectBuffer, presenter, asyncListener, documentProvider, "QuickInfo")
{
_providers = providers;
}
internal static Controller GetInstance(
IThreadingContext threadingContext,
EditorCommandArgs args,
IIntelliSensePresenter<IQuickInfoPresenterSession, IQuickInfoSession> presenter,
IAsynchronousOperationListener asyncListener,
......@@ -61,10 +65,10 @@ internal partial class Controller :
var textView = args.TextView;
var subjectBuffer = args.SubjectBuffer;
return textView.GetOrCreatePerSubjectBufferProperty(subjectBuffer, s_quickInfoPropertyKey,
(v, b) => new Controller(v, b,
(v, b) => new Controller(threadingContext, v, b,
presenter,
asyncListener,
new DocumentProvider(),
new DocumentProvider(threadingContext),
allProviders));
}
......@@ -102,7 +106,7 @@ internal override void OnModelUpdated(Model modelOpt)
}
var snapshot = this.SubjectBuffer.CurrentSnapshot;
this.sessionOpt = new Session<Controller, Model, IQuickInfoPresenterSession>(this, new ModelComputation<Model>(this, TaskScheduler.Default),
this.sessionOpt = new Session<Controller, Model, IQuickInfoPresenterSession>(this, new ModelComputation<Model>(ThreadingContext, this, TaskScheduler.Default),
this.Presenter.CreateSession(this.TextView, this.SubjectBuffer, augmentSession));
this.sessionOpt.Computation.ChainTaskAndNotifyControllerWhenFinished(
......
......@@ -20,6 +20,7 @@ internal class Session<TController, TModel, TPresenterSession> : ForegroundThrea
public TPresenterSession PresenterSession { get; }
public Session(TController controller, ModelComputation<TModel> computation, TPresenterSession presenterSession)
: base(computation.ThreadingContext)
{
this.Controller = controller;
this.Computation = computation;
......
......@@ -10,7 +10,7 @@ internal partial class Controller
internal partial class Session : Session<Controller, Model, ISignatureHelpPresenterSession>
{
public Session(Controller controller, ISignatureHelpPresenterSession presenterSession)
: base(controller, new ModelComputation<Model>(controller, TaskScheduler.Default), presenterSession)
: base(controller, new ModelComputation<Model>(controller.ThreadingContext, controller, TaskScheduler.Default), presenterSession)
{
this.PresenterSession.ItemSelected += OnPresenterSessionItemSelected;
}
......
......@@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.SignatureHelp;
......@@ -32,31 +33,34 @@ internal partial class Controller :
public string DisplayName => EditorFeaturesResources.Signature_Help;
public Controller(
IThreadingContext threadingContext,
ITextView textView,
ITextBuffer subjectBuffer,
IIntelliSensePresenter<ISignatureHelpPresenterSession, ISignatureHelpSession> presenter,
IAsynchronousOperationListener asyncListener,
IDocumentProvider documentProvider,
IList<Lazy<ISignatureHelpProvider, OrderableLanguageMetadata>> allProviders)
: base(textView, subjectBuffer, presenter, asyncListener, documentProvider, "SignatureHelp")
: base(threadingContext, textView, subjectBuffer, presenter, asyncListener, documentProvider, "SignatureHelp")
{
_allProviders = allProviders;
}
// For testing purposes.
internal Controller(
IThreadingContext threadingContext,
ITextView textView,
ITextBuffer subjectBuffer,
IIntelliSensePresenter<ISignatureHelpPresenterSession, ISignatureHelpSession> presenter,
IAsynchronousOperationListener asyncListener,
IDocumentProvider documentProvider,
IList<ISignatureHelpProvider> providers)
: base(textView, subjectBuffer, presenter, asyncListener, documentProvider, "SignatureHelp")
: base(threadingContext, textView, subjectBuffer, presenter, asyncListener, documentProvider, "SignatureHelp")
{
_providers = providers.ToImmutableArray();
}
internal static Controller GetInstance(
IThreadingContext threadingContext,
EditorCommandArgs args,
IIntelliSensePresenter<ISignatureHelpPresenterSession, ISignatureHelpSession> presenter,
IAsynchronousOperationListener asyncListener,
......@@ -65,10 +69,10 @@ internal partial class Controller :
var textView = args.TextView;
var subjectBuffer = args.SubjectBuffer;
return textView.GetOrCreatePerSubjectBufferProperty(subjectBuffer, s_controllerPropertyKey,
(v, b) => new Controller(v, b,
(v, b) => new Controller(threadingContext, v, b,
presenter,
asyncListener,
new DocumentProvider(),
new DocumentProvider(threadingContext),
allProviders));
}
......
......@@ -36,9 +36,11 @@ private class SignatureHelpPresenterSession : ForegroundThreadAffinitizedObject,
public bool EditorSessionIsActive => _editorSessionOpt?.IsDismissed == false;
public SignatureHelpPresenterSession(
IThreadingContext threadingContext,
ISignatureHelpBroker sigHelpBroker,
ITextView textView,
ITextBuffer subjectBuffer)
: base(threadingContext)
{
_sigHelpBroker = sigHelpBroker;
_textView = textView;
......
......@@ -10,6 +10,11 @@ internal partial class SignatureHelpPresenter
{
private class SignatureHelpSource : ForegroundThreadAffinitizedObject, ISignatureHelpSource
{
public SignatureHelpSource(IThreadingContext threadingContext)
: base(threadingContext)
{
}
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures)
{
AssertIsForeground();
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
......@@ -20,7 +22,9 @@ internal partial class SignatureHelpPresenter : ForegroundThreadAffinitizedObjec
private readonly ISignatureHelpBroker _sigHelpBroker;
[ImportingConstructor]
public SignatureHelpPresenter(ISignatureHelpBroker sigHelpBroker)
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public SignatureHelpPresenter(IThreadingContext threadingContext, ISignatureHelpBroker sigHelpBroker)
: base(threadingContext)
{
_sigHelpBroker = sigHelpBroker;
}
......@@ -28,13 +32,13 @@ public SignatureHelpPresenter(ISignatureHelpBroker sigHelpBroker)
ISignatureHelpPresenterSession IIntelliSensePresenter<ISignatureHelpPresenterSession, ISignatureHelpSession>.CreateSession(ITextView textView, ITextBuffer subjectBuffer, ISignatureHelpSession sessionOpt)
{
AssertIsForeground();
return new SignatureHelpPresenterSession(_sigHelpBroker, textView, subjectBuffer);
return new SignatureHelpPresenterSession(ThreadingContext, _sigHelpBroker, textView, subjectBuffer);
}
ISignatureHelpSource ISignatureHelpSourceProvider.TryCreateSignatureHelpSource(ITextBuffer textBuffer)
{
AssertIsForeground();
return new SignatureHelpSource();
return new SignatureHelpSource(ThreadingContext);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
......@@ -36,10 +36,11 @@ internal class HighlighterViewTaggerProvider : AsynchronousViewTaggerProvider<Ke
[ImportingConstructor]
public HighlighterViewTaggerProvider(
IThreadingContext threadingContext,
IHighlightingService highlightingService,
IForegroundNotificationService notificationService,
IAsynchronousOperationListenerProvider listenerProvider)
: base(listenerProvider.GetListener(FeatureAttribute.KeywordHighlighting), notificationService)
: base(threadingContext, listenerProvider.GetListener(FeatureAttribute.KeywordHighlighting), notificationService)
{
_highlightingService = highlightingService;
}
......
......@@ -44,10 +44,12 @@ internal partial class NavigationBarController : ForegroundThreadAffinitizedObje
private Workspace _workspace;
public NavigationBarController(
IThreadingContext threadingContext,
INavigationBarPresenter presenter,
ITextBuffer subjectBuffer,
IWaitIndicator waitIndicator,
IAsynchronousOperationListener asyncListener)
: base(threadingContext)
{
_presenter = presenter;
_subjectBuffer = subjectBuffer;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Text;
......@@ -12,14 +13,18 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.NavigationBar
[Export(typeof(INavigationBarControllerFactoryService))]
internal class NavigationBarControllerFactoryService : INavigationBarControllerFactoryService
{
private readonly IThreadingContext _threadingContext;
private readonly IWaitIndicator _waitIndicator;
private readonly IAsynchronousOperationListener _asyncListener;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public NavigationBarControllerFactoryService(
IThreadingContext threadingContext,
IWaitIndicator waitIndicator,
IAsynchronousOperationListenerProvider listenerProvider)
{
_threadingContext = threadingContext;
_waitIndicator = waitIndicator;
_asyncListener = listenerProvider.GetListener(FeatureAttribute.NavigationBar);
}
......@@ -27,6 +32,7 @@ internal class NavigationBarControllerFactoryService : INavigationBarControllerF
public INavigationBarController CreateController(INavigationBarPresenter presenter, ITextBuffer textBuffer)
{
return new NavigationBarController(
_threadingContext,
presenter,
textBuffer,
_waitIndicator,
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
......@@ -142,11 +141,15 @@ private void StartSelectedItemUpdateTask(int delay, bool updateUIWhenDone)
if (updateUIWhenDone)
{
asyncToken = _asyncListener.BeginAsyncOperation(GetType().Name + ".StartSelectedItemUpdateTask.UpdateUI");
_selectedItemInfoTask.SafeContinueWith(
t => PushSelectedItemsToPresenter(t.Result),
_selectedItemInfoTask.SafeContinueWithFromAsync(
async t =>
{
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);
PushSelectedItemsToPresenter(t.Result);
},
cancellationToken,
TaskContinuationOptions.OnlyOnRanToCompletion,
ForegroundTaskScheduler).CompletesAsyncOperation(asyncToken);
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default).CompletesAsyncOperation(asyncToken);
}
}
......
......@@ -28,7 +28,7 @@ public override void Initialize(AnalysisContext context)
private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
{
var diagnostics = RenameTrackingTaggerProvider.GetDiagnosticsAsync(context.Tree, DiagnosticDescriptor, context.CancellationToken).WaitAndGetResult(context.CancellationToken);
var diagnostics = RenameTrackingTaggerProvider.GetDiagnosticsAsync(context.Tree, DiagnosticDescriptor, context.CancellationToken).WaitAndGetResult_CanCallOnBackground(context.CancellationToken);
foreach (var diagnostic in diagnostics)
{
......
......@@ -36,6 +36,7 @@ private class RenameTrackingCommitter : ForegroundThreadAffinitizedObject
IEnumerable<IRefactorNotifyService> refactorNotifyServices,
ITextUndoHistoryRegistry undoHistoryRegistry,
string displayText)
: base(stateMachine.ThreadingContext)
{
_stateMachine = stateMachine;
_snapshotSpan = snapshotSpan;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册