Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.Internal.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Utilities;
Expand All @@ -15,11 +16,14 @@ internal sealed class DiagnosticItemProvider : AttachedCollectionSourceProvider<
[Import(typeof(AnalyzersCommandHandler))]
private IAnalyzersCommandHandler _commandHandler = null;

[Import]
private IDiagnosticAnalyzerService _diagnosticAnalyzerService = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How does this field ever get a value other than null? I'm guessing the [Import] does something magic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is MEF magic.


protected override IAttachedCollectionSource CreateCollectionSource(AnalyzerItem item, string relationshipName)
{
if (relationshipName == KnownRelationships.Contains)
{
return new DiagnosticItemSource(item, _commandHandler);
return new DiagnosticItemSource(item, _commandHandler, (DiagnosticAnalyzerService)_diagnosticAnalyzerService);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this cast is safe, why isn't the type of the field DiagnosticAnalyzerService?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should also consider just adding the GetDiagnosticDescriptors(Analyzer) method to IDiagnosticAnalyzerService interface.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@tmeschter can we just do that as part of this change?

}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Shell;
using Roslyn.Utilities;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplorer
{
Expand All @@ -19,16 +20,18 @@ internal partial class DiagnosticItemSource : IAttachedCollectionSource

private readonly AnalyzerItem _item;
private readonly IAnalyzersCommandHandler _commandHandler;
private readonly DiagnosticAnalyzerService _diagnosticAnalyzerService;
private BulkObservableCollection<DiagnosticItem> _diagnosticItems;
private Workspace _workspace;
private ProjectId _projectId;
private ReportDiagnostic _generalDiagnosticOption;
private ImmutableDictionary<string, ReportDiagnostic> _specificDiagnosticOptions;

public DiagnosticItemSource(AnalyzerItem item, IAnalyzersCommandHandler commandHandler)
public DiagnosticItemSource(AnalyzerItem item, IAnalyzersCommandHandler commandHandler, DiagnosticAnalyzerService diagnosticAnalyzerService)
{
_item = item;
_commandHandler = commandHandler;
_diagnosticAnalyzerService = diagnosticAnalyzerService;
}

public object SourceItem
Expand Down Expand Up @@ -90,7 +93,7 @@ private IEnumerable<DiagnosticItem> GetDiagnosticItems(string language)
// one.

return _item.AnalyzerReference.GetAnalyzers(language)
.SelectMany(a => a.SupportedDiagnostics)
.SelectMany(a => _diagnosticAnalyzerService.GetDiagnosticDescriptors(a))
.GroupBy(d => d.Id)
.OrderBy(g => g.Key, StringComparer.CurrentCulture)
.Select(g =>
Expand Down