提交 bcb2c8c7 编写于 作者: T Tom Meschter

Merge pull request #1139 from tmeschter/HardenSolutionExplorer

Catch exceptions from user code
......@@ -70,5 +70,11 @@ internal interface IDiagnosticAnalyzerService
/// </summary>
/// <returns>A mapping from analyzer name to the diagnostics produced by that analyzer</returns>
ImmutableDictionary<string, ImmutableArray<DiagnosticDescriptor>> GetDiagnosticDescriptors(Project projectOpt);
/// <summary>
/// Gets a list of the diagnostics provided by the given <see cref="DiagnosticAnalyzer"/>.
/// </summary>
/// <returns>A list of the diagnostics produced by the given analyzer</returns>
ImmutableArray<DiagnosticDescriptor> GetDiagnosticDescriptors(DiagnosticAnalyzer analyzer);
}
}
// 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;
......@@ -15,11 +16,14 @@ internal sealed class DiagnosticItemProvider : AttachedCollectionSourceProvider<
[Import(typeof(AnalyzersCommandHandler))]
private IAnalyzersCommandHandler _commandHandler = null;
[Import]
private IDiagnosticAnalyzerService _diagnosticAnalyzerService = null;
protected override IAttachedCollectionSource CreateCollectionSource(AnalyzerItem item, string relationshipName)
{
if (relationshipName == KnownRelationships.Contains)
{
return new DiagnosticItemSource(item, _commandHandler);
return new DiagnosticItemSource(item, _commandHandler, _diagnosticAnalyzerService);
}
return null;
......
......@@ -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
{
......@@ -19,16 +20,18 @@ internal partial class DiagnosticItemSource : IAttachedCollectionSource
private readonly AnalyzerItem _item;
private readonly IAnalyzersCommandHandler _commandHandler;
private readonly IDiagnosticAnalyzerService _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, IDiagnosticAnalyzerService diagnosticAnalyzerService)
{
_item = item;
_commandHandler = commandHandler;
_diagnosticAnalyzerService = diagnosticAnalyzerService;
}
public object SourceItem
......@@ -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 =>
......
......@@ -185,6 +185,10 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
Public Function GetProjectDiagnosticsForIdsAsync(solution As Solution, Optional projectId As ProjectId = Nothing, Optional diagnosticIds As ImmutableHashSet(Of String) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ImmutableArray(Of DiagnosticData)) Implements IDiagnosticAnalyzerService.GetProjectDiagnosticsForIdsAsync
Return SpecializedTasks.EmptyImmutableArray(Of DiagnosticData)()
End Function
Public Function GetDiagnosticDescriptors(analyzer As DiagnosticAnalyzer) As ImmutableArray(Of DiagnosticDescriptor) Implements IDiagnosticAnalyzerService.GetDiagnosticDescriptors
Return ImmutableArray(Of DiagnosticDescriptor).Empty
End Function
End Class
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册