提交 357f8610 编写于 作者: M Manish Vasani

Merge pull request #5782 from mavasani/FixBaseliningCommand

Fix "Suppress Active Issues" for project/solution command to use the diagnostics directly from the diagnostic service, instead of the error list. This has couple of benefits:

1.We don't need to wait for error list to be force updated to start computing the suppressions fix. It can take quite a while for error list to reach to stable state


2.We don't do unneccessary mapping from error list entry to roslyn diagnostic snapshots and also don't need to do any filtering of stale diagnostics.
......@@ -35,10 +35,11 @@ public async Task<Solution> GetFixAllChangedSolutionAsync(FixAllProvider fixAllP
{
// Compute fix all occurrences code fix for the given fix all context.
// Bring up a cancellable wait dialog.
var codeAction = GetFixAllCodeAction(fixAllProvider, fixAllContext, fixAllTitle, waitDialogMessage);
bool userCancelled;
var codeAction = GetFixAllCodeAction(fixAllProvider, fixAllContext, fixAllTitle, waitDialogMessage, out userCancelled);
if (codeAction == null)
{
return null;
return userCancelled ? null : fixAllContext.Solution;
}
fixAllContext.CancellationToken.ThrowIfCancellationRequested();
......@@ -49,7 +50,8 @@ public async Task<IEnumerable<CodeActionOperation>> GetFixAllOperationsAsync(Fix
{
// Compute fix all occurrences code fix for the given fix all context.
// Bring up a cancellable wait dialog.
var codeAction = GetFixAllCodeAction(fixAllProvider, fixAllContext, fixAllTitle, waitDialogMessage);
bool userCancelled;
var codeAction = GetFixAllCodeAction(fixAllProvider, fixAllContext, fixAllTitle, waitDialogMessage, out userCancelled);
if (codeAction == null)
{
return null;
......@@ -58,8 +60,10 @@ public async Task<IEnumerable<CodeActionOperation>> GetFixAllOperationsAsync(Fix
return await GetFixAllOperationsAsync(codeAction, fixAllContext, fixAllTitle, showPreviewChangesDialog).ConfigureAwait(false);
}
private CodeAction GetFixAllCodeAction(FixAllProvider fixAllProvider, FixAllContext fixAllContext, string fixAllTitle, string waitDialogMessage)
private CodeAction GetFixAllCodeAction(FixAllProvider fixAllProvider, FixAllContext fixAllContext, string fixAllTitle, string waitDialogMessage, out bool userCancelled)
{
userCancelled = false;
// Compute fix all occurrences code fix for the given fix all context.
// Bring up a cancellable wait dialog.
CodeAction codeAction = null;
......@@ -92,7 +96,8 @@ private CodeAction GetFixAllCodeAction(FixAllProvider fixAllProvider, FixAllCont
}
});
var cancelled = result == WaitIndicatorResult.Canceled || codeAction == null;
userCancelled = result == WaitIndicatorResult.Canceled;
var cancelled = userCancelled || codeAction == null;
if (cancelled)
{
......
......@@ -208,16 +208,16 @@ private static AbstractTableEntriesSnapshot<DiagnosticData> GetEntriesSnapshot(I
}
/// <summary>
/// Gets <see cref="DiagnosticData"/> objects for error list entries, filtered based on the given parameters.
/// Gets <see cref="DiagnosticData"/> objects for selected error list entries.
/// For remove suppression, the method also returns selected external source diagnostics.
/// </summary>
public async Task<ImmutableArray<DiagnosticData>> GetItemsAsync(bool selectedEntriesOnly, bool isAddSuppression, bool isSuppressionInSource, bool onlyCompilerDiagnostics, CancellationToken cancellationToken)
public async Task<ImmutableArray<DiagnosticData>> GetSelectedItemsAsync(bool isAddSuppression, CancellationToken cancellationToken)
{
var builder = ImmutableArray.CreateBuilder<DiagnosticData>();
Dictionary<string, Project> projectNameToProjectMapOpt = null;
Dictionary<Project, ImmutableDictionary<string, Document>> filePathToDocumentMapOpt = null;
var entries = selectedEntriesOnly ? _tableControl.SelectedEntries : _tableControl.Entries;
foreach (var entryHandle in entries)
foreach (var entryHandle in _tableControl.SelectedEntries)
{
cancellationToken.ThrowIfCancellationRequested();
......@@ -240,7 +240,7 @@ public async Task<ImmutableArray<DiagnosticData>> GetItemsAsync(bool selectedEnt
string errorCode = null, category = null, message = null, filePath = null, projectName = null;
int line = -1; // FxCop only supports line, not column.
var location = Location.None;
DiagnosticDataLocation location = null;
if (entryHandle.TryGetValue(StandardTableColumnDefinitions.ErrorCode, out errorCode) && !string.IsNullOrEmpty(errorCode) &&
entryHandle.TryGetValue(StandardTableColumnDefinitions.ErrorCategory, out category) && !string.IsNullOrEmpty(category) &&
......@@ -294,18 +294,21 @@ public async Task<ImmutableArray<DiagnosticData>> GetItemsAsync(bool selectedEnt
var linePosition = new LinePosition(line, 0);
var linePositionSpan = new LinePositionSpan(start: linePosition, end: linePosition);
var textSpan = (await tree.GetTextAsync(cancellationToken).ConfigureAwait(false)).Lines.GetTextSpan(linePositionSpan);
location = tree.GetLocation(textSpan);
location = new DiagnosticDataLocation(document.Id, textSpan, filePath,
originalStartLine: linePosition.Line, originalStartColumn: linePosition.Character,
originalEndLine: linePosition.Line, originalEndColumn: linePosition.Character);
}
Contract.ThrowIfNull(project);
Contract.ThrowIfFalse((document != null) == location.IsInSource);
Contract.ThrowIfFalse((document != null) == (location != null));
// Create a diagnostic with correct values for fields we care about: id, category, message, isSuppressed, location
// and default values for the rest of the fields (not used by suppression fixer).
var diagnostic = Diagnostic.Create(
diagnosticData = new DiagnosticData(
id: errorCode,
category: category,
message: message,
enuMessageForBingSearch: message,
severity: DiagnosticSeverity.Warning,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
......@@ -313,35 +316,16 @@ public async Task<ImmutableArray<DiagnosticData>> GetItemsAsync(bool selectedEnt
isSuppressed: isSuppressedEntry,
title: message,
location: location,
customTags: SuppressionHelpers.SynthesizedExternalSourceDiagnosticCustomTags);
diagnosticData = document != null ?
DiagnosticData.Create(document, diagnostic) :
DiagnosticData.Create(project, diagnostic);
customTags: SuppressionHelpers.SynthesizedExternalSourceDiagnosticCustomTags,
properties: ImmutableDictionary<string, string>.Empty,
workspace: _workspace,
projectId: project.Id);
}
}
if (IsEntryWithConfigurableSuppressionState(diagnosticData))
{
var isCompilerDiagnostic = SuppressionHelpers.IsCompilerDiagnostic(diagnosticData);
if (onlyCompilerDiagnostics && !isCompilerDiagnostic)
{
continue;
}
if (isAddSuppression)
{
// Compiler diagnostics can only be suppressed in source.
if (!diagnosticData.IsSuppressed &&
(isSuppressionInSource || !isCompilerDiagnostic))
{
builder.Add(diagnosticData);
}
}
else if (diagnosticData.IsSuppressed)
{
builder.Add(diagnosticData);
}
builder.Add(diagnosticData);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册