Skip to content

Commit

Permalink
Merge pull request #28781 from sharwell/vs-threading-analyzers
Browse files Browse the repository at this point in the history
Migrate to Microsoft.VisualStudio.Threading
  • Loading branch information
sharwell committed Aug 13, 2018
2 parents 161765c + dc15c56 commit bd1e0c6
Show file tree
Hide file tree
Showing 296 changed files with 2,053 additions and 995 deletions.
6 changes: 6 additions & 0 deletions build/Rulesets/Roslyn_BuildRules.ruleset
Expand Up @@ -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>
3 changes: 2 additions & 1 deletion build/Targets/Packages.props
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions build/Targets/Settings.props
Expand Up @@ -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'">
Expand Down
@@ -1,9 +1,11 @@
// 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;
Expand All @@ -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;
Expand Down
@@ -1,13 +1,21 @@
// 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
{
[ExportLanguageService(typeof(IFindUsagesService), LanguageNames.CSharp), Shared]
internal class CSharpFindUsagesService : AbstractFindUsagesService
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CSharpFindUsagesService(IThreadingContext threadingContext)
: base(threadingContext)
{
}
}
}
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
@@ -1,16 +1,19 @@
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
{
[ExportLanguageService(typeof(IGoToSymbolService), LanguageNames.CSharp), Shared]
internal class CSharpGoToSymbolService : AbstractGoToSymbolService
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CSharpGoToSymbolService(IThreadingContext threadingContext)
: base(threadingContext)
{
}
}
}
Expand Up @@ -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>(),
Expand Down Expand Up @@ -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>(),
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
@@ -1,28 +1,29 @@
// 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
{
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);
}
Expand All @@ -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);
}
}
}

0 comments on commit bd1e0c6

Please sign in to comment.