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
Expand Up @@ -95,12 +95,6 @@ Task<ImmutableArray<DiagnosticDescriptor>> GetDiagnosticDescriptorsAsync(
Task<ImmutableDictionary<ImmutableArray<string>, ImmutableArray<DiagnosticDescriptor>>> GetLanguageKeyedDiagnosticDescriptorsAsync(
Copy link
Member Author

Choose a reason for hiding this comment

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

View with whitespacce off.

Solution solution, ProjectId projectId, AnalyzerReference analyzerReference, CancellationToken cancellationToken);

/// <summary>
/// Given a list of errors ids (like CS1234), attempts to find an associated descriptor for each id.
/// </summary>
Task<ImmutableDictionary<string, DiagnosticDescriptor>> TryGetDiagnosticDescriptorsAsync(
Solution solution, ImmutableArray<string> diagnosticIds, CancellationToken cancellationToken);

/// <inheritdoc cref="HostDiagnosticAnalyzers.GetDiagnosticDescriptorsPerReference(DiagnosticAnalyzerInfoCache)"/>
Task<ImmutableDictionary<string, ImmutableArray<DiagnosticDescriptor>>> GetDiagnosticDescriptorsPerReferenceAsync(
Solution solution, CancellationToken cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,35 +203,6 @@ ImmutableArray<DiagnosticDescriptor> GetDiagnosticDescriptors(ImmutableArray<Dia
=> analyzers.SelectManyAsArray(this._analyzerInfoCache.GetDiagnosticDescriptors);
}

public async Task<ImmutableDictionary<string, DiagnosticDescriptor>> TryGetDiagnosticDescriptorsAsync(
Solution solution, ImmutableArray<string> diagnosticIds, CancellationToken cancellationToken)
{
var client = await RemoteHostClient.TryGetClientAsync(solution.Services, cancellationToken).ConfigureAwait(false);
if (client is not null)
{
var map = await client.TryInvokeAsync<IRemoteDiagnosticAnalyzerService, ImmutableDictionary<string, DiagnosticDescriptorData>>(
solution,
(service, solution, cancellationToken) => service.TryGetDiagnosticDescriptorsAsync(solution, diagnosticIds, cancellationToken),
cancellationToken).ConfigureAwait(false);

if (!map.HasValue)
return ImmutableDictionary<string, DiagnosticDescriptor>.Empty;

return map.Value.ToImmutableDictionary(
kvp => kvp.Key,
kvp => kvp.Value.ToDiagnosticDescriptor());
}

var builder = ImmutableDictionary.CreateBuilder<string, DiagnosticDescriptor>();
foreach (var diagnosticId in diagnosticIds)
{
if (this._analyzerInfoCache.TryGetDescriptorForDiagnosticId(diagnosticId, out var descriptor))
builder[diagnosticId] = descriptor;
}

return builder.ToImmutable();
}

public async Task<ImmutableDictionary<string, ImmutableArray<DiagnosticDescriptor>>> GetDiagnosticDescriptorsPerReferenceAsync(Solution solution, CancellationToken cancellationToken)
{
var client = await RemoteHostClient.TryGetClientAsync(solution.Services, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
Expand All @@ -16,14 +15,12 @@
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Threading;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Microsoft.VisualStudio.LanguageServices.Implementation.Venus;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Threading;
using Roslyn.Utilities;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.TaskList;
Expand Down Expand Up @@ -121,16 +118,13 @@ private async Task AddNewErrorsAsync(

var solution = project.Solution;
var errorIds = allErrors.Select(e => e.iErrorID).Distinct().Select(GetErrorId).ToImmutableArray();
var diagnosticService = solution.Services.GetRequiredService<IDiagnosticAnalyzerService>();
var errorIdToDescriptor = await diagnosticService.TryGetDiagnosticDescriptorsAsync(
solution, errorIds, cancellationToken).ConfigureAwait(false);

foreach (var error in allErrors)
{
if (error.bstrFileName != null)
{
var diagnostic = await TryCreateDocumentDiagnosticItemAsync(
project, error, errorIdToDescriptor, cancellationToken).ConfigureAwait(false);
project, error, cancellationToken).ConfigureAwait(false);
if (diagnostic != null)
{
allDiagnostics.Add(diagnostic);
Expand All @@ -146,7 +140,6 @@ private async Task AddNewErrorsAsync(
GetDiagnosticSeverity(error),
_language,
new FileLinePositionSpan(project.FilePath ?? "", span: default),
errorIdToDescriptor,
cancellationToken).ConfigureAwait(false));
}

Expand Down Expand Up @@ -189,7 +182,6 @@ public int GetErrors(out IVsEnumExternalErrors? pErrors)
private async Task<DiagnosticData?> TryCreateDocumentDiagnosticItemAsync(
Project project,
ExternalError error,
ImmutableDictionary<string, DiagnosticDescriptor> errorIdToDescriptor,
CancellationToken cancellationToken)
{
var documentId = TryGetDocumentId(error.bstrFileName);
Expand Down Expand Up @@ -240,7 +232,6 @@ public int GetErrors(out IVsEnumExternalErrors? pErrors)
new FileLinePositionSpan(error.bstrFileName,
new LinePosition(line, column),
new LinePosition(line, column)),
errorIdToDescriptor,
cancellationToken).ConfigureAwait(false);
}

Expand Down Expand Up @@ -319,10 +310,6 @@ async Task ReportErrorAsync(CancellationToken cancellationToken)
if (project is null)
return;

var diagnosticService = solution.Services.GetRequiredService<IDiagnosticAnalyzerService>();
var errorIdToDescriptor = await diagnosticService.TryGetDiagnosticDescriptorsAsync(
solution, [bstrErrorId], cancellationToken).ConfigureAwait(false);

var diagnostic = await GetDiagnosticDataAsync(
project,
documentId,
Expand All @@ -334,7 +321,6 @@ async Task ReportErrorAsync(CancellationToken cancellationToken)
bstrFileName,
new LinePosition(iStartLine, iStartColumn),
new LinePosition(iEndLine, iEndColumn)),
errorIdToDescriptor,
cancellationToken).ConfigureAwait(false);

DiagnosticProvider.AddNewErrors(_projectId, _projectHierarchyGuid, [diagnostic]);
Expand All @@ -349,54 +335,25 @@ private static async Task<DiagnosticData> GetDiagnosticDataAsync(
DiagnosticSeverity severity,
string language,
FileLinePositionSpan unmappedSpan,
ImmutableDictionary<string, DiagnosticDescriptor> errorIdToDescriptor,
CancellationToken cancellationToken)
{
string title, description, category;
string? helpLink;
DiagnosticSeverity defaultSeverity;
bool isEnabledByDefault;
ImmutableArray<string> customTags;

if (errorIdToDescriptor.TryGetValue(errorId, out var descriptor))
{
title = descriptor.Title.ToString(CultureInfo.CurrentUICulture);
description = descriptor.Description.ToString(CultureInfo.CurrentUICulture);
category = descriptor.Category;
defaultSeverity = descriptor.DefaultSeverity;
isEnabledByDefault = descriptor.IsEnabledByDefault;
customTags = descriptor.CustomTags.AsImmutableOrEmpty();
helpLink = descriptor.HelpLinkUri;
}
else
{
title = message;
description = message;
category = WellKnownDiagnosticTags.Build;
defaultSeverity = severity;
isEnabledByDefault = true;
customTags = IsCompilerDiagnostic(errorId) ? CompilerDiagnosticCustomTags : CustomTags;
helpLink = null;
}

var diagnostic = new DiagnosticData(
id: errorId,
category: category,
category: WellKnownDiagnosticTags.Build,
message: message,
title: title,
description: description,
title: (string?)message,
description: (string?)message,
severity: severity,
defaultSeverity: defaultSeverity,
isEnabledByDefault: isEnabledByDefault,
defaultSeverity: severity,
isEnabledByDefault: true,
warningLevel: (severity == DiagnosticSeverity.Error) ? 0 : 1,
customTags: customTags,
customTags: IsCompilerDiagnostic(errorId) ? CompilerDiagnosticCustomTags : CustomTags,
properties: DiagnosticData.PropertiesForBuildDiagnostic,
projectId: project.Id,
location: new DiagnosticDataLocation(
unmappedSpan,
documentId),
language: language,
helpLink: helpLink);
language: language);

if (documentId != null &&
project.GetDocument(documentId) is Document document &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ ValueTask<ImmutableArray<DiagnosticDescriptorData>> GetDiagnosticDescriptorsAsyn
ValueTask<ImmutableDictionary<ImmutableArray<string>, ImmutableArray<DiagnosticDescriptorData>>> GetLanguageKeyedDiagnosticDescriptorsAsync(
Checksum solutionChecksum, ProjectId projectId, string analyzerReferenceFullPath, CancellationToken cancellationToken);

ValueTask<ImmutableDictionary<string, DiagnosticDescriptorData>> TryGetDiagnosticDescriptorsAsync(
Checksum solutionChecksum, ImmutableArray<string> diagnosticIds, CancellationToken cancellationToken);

ValueTask<ImmutableDictionary<string, ImmutableArray<DiagnosticDescriptorData>>> GetDiagnosticDescriptorsPerReferenceAsync(
Checksum solutionChecksum, CancellationToken cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,6 @@ public ValueTask<ImmutableDictionary<ImmutableArray<string>, ImmutableArray<Diag
cancellationToken);
}

public ValueTask<ImmutableDictionary<string, DiagnosticDescriptorData>> TryGetDiagnosticDescriptorsAsync(
Checksum solutionChecksum,
ImmutableArray<string> diagnosticIds,
CancellationToken cancellationToken)
{
return RunWithSolutionAsync(
solutionChecksum,
async solution =>
{
var service = solution.Services.GetRequiredService<IDiagnosticAnalyzerService>();
var map = await service.TryGetDiagnosticDescriptorsAsync(solution, diagnosticIds, cancellationToken).ConfigureAwait(false);
return map.ToImmutableDictionary(
kvp => kvp.Key,
kvp => DiagnosticDescriptorData.Create(kvp.Value));
},
cancellationToken);
}

public ValueTask<ImmutableDictionary<string, ImmutableArray<DiagnosticDescriptorData>>> GetDiagnosticDescriptorsPerReferenceAsync(
Checksum solutionChecksum,
CancellationToken cancellationToken)
Expand Down
Loading