Skip to content

Commit 0bf8be7

Browse files
inline
1 parent e30bbd7 commit 0bf8be7

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

src/VisualStudio/Core/Def/CodeCleanup/AbstractCodeCleanUpFixer.cs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
1616
using Microsoft.CodeAnalysis.Host;
1717
using Microsoft.CodeAnalysis.Options;
18-
using Microsoft.CodeAnalysis.PooledObjects;
1918
using Microsoft.CodeAnalysis.Progress;
2019
using Microsoft.CodeAnalysis.Shared.Extensions;
2120
using Microsoft.CodeAnalysis.Shared.Utilities;
@@ -66,7 +65,15 @@ private async Task<bool> FixHierarchyContentAsync(IVsHierarchyCodeCleanupScope h
6665
{
6766
var hierarchy = hierarchyContent.Hierarchy;
6867
if (hierarchy == null)
69-
return await FixSolutionAsync(_workspace.CurrentSolution, context).ConfigureAwait(true);
68+
{
69+
var solution = _workspace.CurrentSolution;
70+
return await FixAsync(
71+
_workspace,
72+
// Just defer to FixProjectsAsync, passing in all fixable projects in the solution.
73+
(progress, cancellationToken) => FixProjectsAsync(
74+
_globalOptions, solution, solution.Projects.Where(p => p.SupportsCompilation).ToImmutableArray(), context.EnabledFixIds, progress, cancellationToken),
75+
context).ConfigureAwait(false);
76+
}
7077

7178
// Map the hierarchy to a ProjectId. For hierarchies mapping to multitargeted projects, we first try to
7279
// get the project in the most recent active context, but fall back to the first target framework if no
@@ -98,7 +105,12 @@ private async Task<bool> FixHierarchyContentAsync(IVsHierarchyCodeCleanupScope h
98105
if (project == null || !project.SupportsCompilation)
99106
return false;
100107

101-
return await FixProjectAsync(project, context).ConfigureAwait(true);
108+
return await FixAsync(
109+
_workspace,
110+
// Just defer to FixProjectsAsync, passing in this single project to fix.
111+
(progress, cancellationToken) => FixProjectsAsync(
112+
_globalOptions, project.Solution, [project], context.EnabledFixIds, progress, cancellationToken),
113+
context).ConfigureAwait(false);
102114
}
103115
else if (hierarchy.GetCanonicalName(itemId, out var path) == 0)
104116
{
@@ -122,37 +134,21 @@ private async Task<bool> FixHierarchyContentAsync(IVsHierarchyCodeCleanupScope h
122134

123135
var document = solution.GetRequiredDocument(documentId);
124136
var options = _globalOptions.GetCodeActionOptions(document.Project.Services);
125-
return await FixDocumentAsync(document, options, context).ConfigureAwait(true);
137+
138+
return await FixAsync(
139+
_workspace,
140+
async (progress, cancellationToken) =>
141+
{
142+
var newDocument = await FixDocumentAsync(document, context.EnabledFixIds, progress, options, cancellationToken).ConfigureAwait(true);
143+
return newDocument.Project.Solution;
144+
},
145+
context).ConfigureAwait(false);
126146
}
127147
}
128148

129149
return false;
130150
}
131151

132-
private Task<bool> FixSolutionAsync(Solution solution, ICodeCleanUpExecutionContext context)
133-
=> FixAsync(
134-
solution.Workspace,
135-
(progress, cancellationToken) => FixProjectsAsync(
136-
_globalOptions, solution, solution.Projects.Where(p => p.SupportsCompilation).ToImmutableArray(), context.EnabledFixIds, progress, cancellationToken),
137-
context);
138-
139-
private Task<bool> FixProjectAsync(Project project, ICodeCleanUpExecutionContext context)
140-
=> FixAsync(
141-
project.Solution.Workspace,
142-
(progress, cancellationToken) => FixProjectsAsync(
143-
_globalOptions, project.Solution, [project], context.EnabledFixIds, progress, cancellationToken),
144-
context);
145-
146-
private Task<bool> FixDocumentAsync(Document document, CodeActionOptions options, ICodeCleanUpExecutionContext context)
147-
=> FixAsync(
148-
document.Project.Solution.Workspace,
149-
async (progress, cancellationToken) =>
150-
{
151-
var newDocument = await FixDocumentAsync(document, context.EnabledFixIds, progress, options, cancellationToken).ConfigureAwait(true);
152-
return newDocument.Project.Solution;
153-
},
154-
context);
155-
156152
private Task<bool> FixTextBufferAsync(TextBufferCodeCleanUpScope textBufferScope, ICodeCleanUpExecutionContext context)
157153
{
158154
var buffer = textBufferScope.SubjectBuffer;

0 commit comments

Comments
 (0)