提交 17339d49 编写于 作者: C CyrusNajmabadi

Remove property from FixAllCodeActio

nContext
上级 eb099bf3
......@@ -288,16 +288,18 @@ public async Task<IEnumerable<CodeFixCollection>> GetFixesAsync(Document documen
var fixAllProviderInfo = extensionManager.PerformFunction(fixer, () => ImmutableInterlocked.GetOrAdd(ref _fixAllProviderMap, fixer, FixAllProviderInfo.Create), defaultValue: null);
FixAllCodeActionContext fixAllContext = null;
IEnumerable<FixAllScope> supportedScopes = null;
if (fixAllProviderInfo != null)
{
var codeFixProvider = (fixer as CodeFixProvider) ?? new WrapperCodeFixProvider((ISuppressionFixProvider)fixer, diagnostics.Select(d => d.Id));
fixAllContext = FixAllCodeActionContext.Create(
document, fixAllProviderInfo, codeFixProvider, diagnostics,
this.GetDocumentDiagnosticsAsync, this.GetProjectDiagnosticsAsync, cancellationToken);
supportedScopes = fixAllProviderInfo.SupportedScopes;
}
result = result ?? new List<CodeFixCollection>();
var codeFix = new CodeFixCollection(fixer, span, fixes, fixAllContext);
var codeFix = new CodeFixCollection(fixer, span, fixes, fixAllContext, supportedScopes);
result.Add(codeFix);
}
......
// 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.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
......@@ -46,6 +47,7 @@ internal class CodeFixSuggestedAction : SuggestedActionWithFlavors, ITelemetryDi
CodeAction action,
int actionCount,
FixAllCodeActionContext fixAllCodeActionContext,
IEnumerable<FixAllScope> supportedScopes,
Workspace workspace,
ITextBuffer subjectBuffer,
ICodeActionEditHandlerService editHandler,
......@@ -63,7 +65,7 @@ internal class CodeFixSuggestedAction : SuggestedActionWithFlavors, ITelemetryDi
}
var fixAllSuggestedActions = ImmutableArray.CreateBuilder<FixAllSuggestedAction>();
foreach (var scope in fixAllCodeActionContext.SupportedScopes)
foreach (var scope in supportedScopes)
{
var fixAllContext = GetContextForScopeAndActionId(fixAllCodeActionContext, scope, action.EquivalenceKey);
var fixAllAction = new FixAllCodeAction(fixAllContext, fixAllCodeActionContext.FixAllProvider, showPreviewChangesDialog: true);
......
......@@ -273,7 +273,9 @@ private List<CodeFixCollection> FilterOnUIThread(List<CodeFixCollection> collect
return collections.Select(c => FilterOnUIThread(c, workspace)).WhereNotNull().ToList();
}
private CodeFixCollection FilterOnUIThread(CodeFixCollection collection, Workspace workspace)
private CodeFixCollection FilterOnUIThread(
CodeFixCollection collection,
Workspace workspace)
{
this.AssertIsForeground();
......@@ -282,7 +284,8 @@ private CodeFixCollection FilterOnUIThread(CodeFixCollection collection, Workspa
? null
: applicableFixes.Count == collection.Fixes.Length
? collection
: new CodeFixCollection(collection.Provider, collection.TextSpan, applicableFixes, collection.FixAllContext);
: new CodeFixCollection(collection.Provider, collection.TextSpan, applicableFixes,
collection.FixAllContext, collection.SupportedScopes);
}
private bool IsApplicable(CodeAction action, Workspace workspace)
......@@ -332,17 +335,22 @@ private IEnumerable<SuggestedActionSet> OrganizeFixes(Workspace workspace, IEnum
/// <summary>
/// Groups fixes by the diagnostic being addressed by each fix.
/// </summary>
private void GroupFixes(Workspace workspace, IEnumerable<CodeFixCollection> fixCollections, IDictionary<CodeFixGroupKey, IList<SuggestedAction>> map, IList<CodeFixGroupKey> order, bool hasSuppressionFixes)
private void GroupFixes(
Workspace workspace,
IEnumerable<CodeFixCollection> fixCollections,
IDictionary<CodeFixGroupKey, IList<SuggestedAction>> map,
IList<CodeFixGroupKey> order,
bool hasSuppressionFixes)
{
foreach (var fixCollection in fixCollections)
{
var fixes = fixCollection.Fixes;
var fixCount = fixes.Length;
Func<CodeAction, SuggestedActionSet> getFixAllSuggestedActionSet = codeAction =>
CodeFixSuggestedAction.GetFixAllSuggestedActionSet(
codeAction, fixCount, fixCollection.FixAllContext, workspace, _subjectBuffer,
_owner._editHandler, _owner._waitIndicator, _owner._listener);
Func<CodeAction, SuggestedActionSet> getFixAllSuggestedActionSet =
codeAction => CodeFixSuggestedAction.GetFixAllSuggestedActionSet(
codeAction, fixCount, fixCollection.FixAllContext, fixCollection.SupportedScopes,
workspace, _subjectBuffer, _owner._editHandler, _owner._waitIndicator, _owner._listener);
foreach (var fix in fixes)
{
......
......@@ -142,7 +142,9 @@ protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out stri
await fixer.RegisterCodeFixesAsync(context);
if (fixes.Any())
{
var codeFix = new CodeFixCollection(fixer, diagnostic.Location.SourceSpan, fixes);
var codeFix = new CodeFixCollection(
fixer, diagnostic.Location.SourceSpan, fixes,
fixAllContext: null, supportedScopes: null);
result.Add(Tuple.Create(diagnostic, codeFix));
}
}
......@@ -161,7 +163,9 @@ protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out stri
foreach (var diagnostic in diagnostics)
{
var diagnosticSpan = diagnostic.Location.IsInSource ? diagnostic.Location.SourceSpan : default(TextSpan);
var codeFix = new CodeFixCollection(fixAllProvider, diagnosticSpan, ImmutableArray.Create(new CodeFix(document.Project, fixAllFix, diagnostic)));
var codeFix = new CodeFixCollection(
fixAllProvider, diagnosticSpan, ImmutableArray.Create(new CodeFix(document.Project, fixAllFix, diagnostic)),
fixAllContext: null, supportedScopes: null);
result.Add(Tuple.Create(diagnostic, codeFix));
}
}
......
......@@ -112,7 +112,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
Dim context = New CodeFixContext(_document, diagnostic, Sub(a, d) fixes.Add(New CodeFix(_document.Project, a, d)), CancellationToken.None)
providerAndFixer.Item2.RegisterCodeFixesAsync(context).Wait()
If fixes.Any() Then
result.Add(Tuple.Create(diagnostic, New CodeFixCollection(fixer, diagnostic.Location.SourceSpan, fixes)))
result.Add(Tuple.Create(diagnostic, New CodeFixCollection(fixer, diagnostic.Location.SourceSpan, fixes,
fixAllContext:=Nothing, supportedScopes:=Nothing)))
End If
Next
......
......@@ -21,18 +21,30 @@ internal class CodeFixCollection
/// Optional fix all context, which is non-null if the given <see cref="Provider"/> supports fix all occurrences code fix.
/// </summary>
public FixAllCodeActionContext FixAllContext { get; }
public IEnumerable<FixAllScope> SupportedScopes { get; }
public CodeFixCollection(object provider, TextSpan span, IEnumerable<CodeFix> fixes, FixAllCodeActionContext fixAllContext = null) :
this(provider, span, fixes.ToImmutableArray(), fixAllContext)
public CodeFixCollection(
object provider,
TextSpan span,
IEnumerable<CodeFix> fixes,
FixAllCodeActionContext fixAllContext,
IEnumerable<FixAllScope> supportedScopes) :
this(provider, span, fixes.ToImmutableArray(), fixAllContext, supportedScopes)
{
}
public CodeFixCollection(object provider, TextSpan span, ImmutableArray<CodeFix> fixes, FixAllCodeActionContext fixAllContext = null)
public CodeFixCollection(
object provider,
TextSpan span,
ImmutableArray<CodeFix> fixes,
FixAllCodeActionContext fixAllContext,
IEnumerable<FixAllScope> supportedScopes)
{
this.Provider = provider;
this.TextSpan = span;
this.Fixes = fixes;
this.FixAllContext = fixAllContext;
this.SupportedScopes = supportedScopes;
}
}
}
......@@ -91,9 +91,11 @@ public FixAllProvider FixAllProvider
get { return _fixAllProviderInfo.FixAllProvider; }
}
#if false
public IEnumerable<FixAllScope> SupportedScopes
{
get { return _fixAllProviderInfo.SupportedScopes; }
}
#endif
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册