Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -795,8 +795,6 @@ private static async Task TestThirdPartyCodeFixer<TCodefix, TAnalyzer>(string co

using var workspace = EditorTestWorkspace.CreateCSharp(code, composition: EditorTestCompositions.EditorFeaturesWpf.AddParts(typeof(TCodefix)));

var options = CodeActionOptions.DefaultProvider;

var project = workspace.CurrentSolution.Projects.Single();
var analyzer = (DiagnosticAnalyzer)new TAnalyzer();
var diagnosticIds = analyzer.SupportedDiagnostics.SelectAsArray(d => d.Id);
Expand Down Expand Up @@ -824,7 +822,7 @@ private static async Task TestThirdPartyCodeFixer<TCodefix, TAnalyzer>(string co
var enabledDiagnostics = codeCleanupService.GetAllDiagnostics();

var newDoc = await codeCleanupService.CleanupAsync(
document, enabledDiagnostics, CodeAnalysisProgress.None, options, CancellationToken.None);
document, enabledDiagnostics, CodeAnalysisProgress.None, CancellationToken.None);

var actual = await newDoc.GetTextAsync();
Assert.Equal(expected, actual.ToString());
Expand Down Expand Up @@ -926,7 +924,7 @@ private protected static async Task AssertCodeCleanupResult(string expected, str
enabledDiagnostics = VisualStudio.LanguageServices.Implementation.CodeCleanup.AbstractCodeCleanUpFixer.AdjustDiagnosticOptions(enabledDiagnostics, enabledFixIdsFilter);

var newDoc = await codeCleanupService.CleanupAsync(
document, enabledDiagnostics, CodeAnalysisProgress.None, workspace.GlobalOptions.CreateProvider(), CancellationToken.None);
document, enabledDiagnostics, CodeAnalysisProgress.None, CancellationToken.None);

var actual = await newDoc.GetTextAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ public Solution GetFix(
Workspace workspace,
CodeFixProvider fixProvider,
FixAllProvider fixAllProvider,
CodeActionOptionsProvider optionsProvider,
string equivalenceKey,
string waitDialogTitle,
string waitDialogMessage,
IProgress<CodeAnalysisProgress> progress,
CancellationToken cancellationToken)
{
var fixMultipleState = FixAllState.Create(
fixAllProvider, diagnosticsToFix, fixProvider, equivalenceKey, optionsProvider);
fixAllProvider, diagnosticsToFix, fixProvider, equivalenceKey);

return GetFixedSolution(
fixMultipleState, workspace, waitDialogTitle, waitDialogMessage, progress, cancellationToken);
Expand All @@ -54,15 +53,14 @@ public Solution GetFix(
Workspace workspace,
CodeFixProvider fixProvider,
FixAllProvider fixAllProvider,
CodeActionOptionsProvider optionsProvider,
string equivalenceKey,
string waitDialogTitle,
string waitDialogMessage,
IProgress<CodeAnalysisProgress> progress,
CancellationToken cancellationToken)
{
var fixMultipleState = FixAllState.Create(
fixAllProvider, diagnosticsToFix, fixProvider, equivalenceKey, optionsProvider);
fixAllProvider, diagnosticsToFix, fixProvider, equivalenceKey);

return GetFixedSolution(
fixMultipleState, workspace, waitDialogTitle, waitDialogMessage, progress, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,12 @@ private void OnTextViewClosed(object sender, EventArgs e)
if (document == null)
return null;

var fallbackOptions = GlobalOptions.GetCodeActionOptionsProvider();

using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
// Assign over cancellation token so no one accidentally uses the wrong token.
cancellationToken = linkedTokenSource.Token;

// Kick off the work to get errors.
var errorTask = GetFixLevelAsync(document, range, fallbackOptions, cancellationToken);
var errorTask = GetFixLevelAsync(document, range, cancellationToken);

// Make a quick jump back to the UI thread to get the user's selection, then go back to the thread pool..
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);
Expand All @@ -205,7 +203,7 @@ private void OnTextViewClosed(object sender, EventArgs e)

// If we have a selection, kick off the work to get refactorings concurrently with the above work to get errors.
var refactoringTask = selection != null
? TryGetRefactoringSuggestedActionCategoryAsync(document, selection, fallbackOptions, cancellationToken)
? TryGetRefactoringSuggestedActionCategoryAsync(document, selection, cancellationToken)
: SpecializedTasks.Null<string>();

// If we happen to get the result of the error task before the refactoring task,
Expand All @@ -221,7 +219,6 @@ private void OnTextViewClosed(object sender, EventArgs e)
private async Task<string?> GetFixLevelAsync(
TextDocument document,
SnapshotSpan range,
CodeActionOptionsProvider fallbackOptions,
CancellationToken cancellationToken)
{
// Ensure we yield the thread that called into us, allowing it to continue onwards.
Expand Down Expand Up @@ -254,7 +251,7 @@ private void OnTextViewClosed(object sender, EventArgs e)
state.Target.SubjectBuffer.SupportsCodeFixes())
{
var result = await state.Target.Owner._codeFixService.GetMostSevereFixAsync(
document, range.Span.ToTextSpan(), priorityProvider, fallbackOptions, cancellationToken).ConfigureAwait(false);
document, range.Span.ToTextSpan(), priorityProvider, cancellationToken).ConfigureAwait(false);

if (result != null)
{
Expand All @@ -276,7 +273,6 @@ private void OnTextViewClosed(object sender, EventArgs e)
private async Task<string?> TryGetRefactoringSuggestedActionCategoryAsync(
TextDocument document,
TextSpan? selection,
CodeActionOptionsProvider fallbackOptions,
CancellationToken cancellationToken)
{
// Ensure we yield the thread that called into us, allowing it to continue onwards.
Expand All @@ -300,7 +296,7 @@ private void OnTextViewClosed(object sender, EventArgs e)
state.Target.SubjectBuffer.SupportsRefactorings())
{
if (await state.Target.Owner._codeRefactoringService.HasRefactoringsAsync(
document, selection.Value, fallbackOptions, cancellationToken).ConfigureAwait(false))
document, selection.Value, cancellationToken).ConfigureAwait(false))
{
return PredefinedSuggestedActionCategoryNames.Refactoring;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ private async IAsyncEnumerable<SuggestedActionSet> GetCodeFixesAndRefactoringsAs
var workspace = document.Project.Solution.Workspace;
var supportsFeatureService = workspace.Services.GetRequiredService<ITextBufferSupportsFeatureService>();

var options = GlobalOptions.GetCodeActionOptionsProvider();

var fixesTask = GetCodeFixesAsync();
var refactoringsTask = GetRefactoringsAsync();

Expand Down Expand Up @@ -242,7 +240,7 @@ async Task<ImmutableArray<UnifiedSuggestedActionSet>> GetCodeFixesAsync()

return await UnifiedSuggestedActionsSource.GetFilterAndOrderCodeFixesAsync(
workspace, owner._codeFixService, document, range.Span.ToTextSpan(),
priorityProvider, options, cancellationToken).ConfigureAwait(false);
priorityProvider, cancellationToken).ConfigureAwait(false);
}

async Task<ImmutableArray<UnifiedSuggestedActionSet>> GetRefactoringsAsync()
Expand Down Expand Up @@ -273,7 +271,7 @@ async Task<ImmutableArray<UnifiedSuggestedActionSet>> GetRefactoringsAsync()
var filterOutsideSelection = !requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring);

return await UnifiedSuggestedActionsSource.GetFilterAndOrderCodeRefactoringsAsync(
workspace, owner._codeRefactoringService, document, selection.Value, priorityProvider.Priority, options,
workspace, owner._codeRefactoringService, document, selection.Value, priorityProvider.Priority,
filterOutsideSelection, cancellationToken).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected abstract CodeRefactoringProvider CreateCodeRefactoringProvider(
return (actions, actionToInvoke);

var fixAllCodeAction = await GetFixAllFixAsync(actionToInvoke,
refactoring.Provider, refactoring.CodeActionOptionsProvider, document, span, fixAllScope.Value).ConfigureAwait(false);
refactoring.Provider, document, span, fixAllScope.Value).ConfigureAwait(false);
if (fixAllCodeAction == null)
return (ImmutableArray<CodeAction>.Empty, null);

Expand All @@ -71,7 +71,6 @@ protected abstract CodeRefactoringProvider CreateCodeRefactoringProvider(
private static async Task<CodeAction> GetFixAllFixAsync(
CodeAction originalCodeAction,
CodeRefactoringProvider provider,
CodeActionOptionsProvider optionsProvider,
Document document,
TextSpan selectionSpan,
FixAllScope scope)
Expand All @@ -80,7 +79,7 @@ private static async Task<CodeAction> GetFixAllFixAsync(
if (fixAllProvider == null || !fixAllProvider.GetSupportedFixAllScopes().Contains(scope))
return null;

var fixAllState = new FixAllState(fixAllProvider, document, selectionSpan, provider, optionsProvider, scope, originalCodeAction);
var fixAllState = new FixAllState(fixAllProvider, document, selectionSpan, provider, scope, originalCodeAction);
var fixAllContext = new FixAllContext(fixAllState, CodeAnalysisProgress.None, CancellationToken.None);
return await fixAllProvider.GetFixAsync(fixAllContext).ConfigureAwait(false);
}
Expand All @@ -105,13 +104,9 @@ internal async Task<CodeRefactoring> GetCodeRefactoringAsync(

var actions = ArrayBuilder<(CodeAction, TextSpan?)>.GetInstance();

var codeActionOptionsProvider = parameters.globalOptions?.IsEmpty() == false
? CodeActionOptionsStorage.GetCodeActionOptionsProvider(workspace.GlobalOptions)
: CodeActionOptions.DefaultProvider;

var context = new CodeRefactoringContext(document, selectedOrAnnotatedSpan, (a, t) => actions.Add((a, t)), codeActionOptionsProvider, CancellationToken.None);
var context = new CodeRefactoringContext(document, selectedOrAnnotatedSpan, (a, t) => actions.Add((a, t)), CancellationToken.None);
await provider.ComputeRefactoringsAsync(context);
var result = actions.Count > 0 ? new CodeRefactoring(provider, actions.ToImmutable(), FixAllProviderInfo.Create(provider), codeActionOptionsProvider) : null;
var result = actions.Count > 0 ? new CodeRefactoring(provider, actions.ToImmutable(), FixAllProviderInfo.Create(provider)) : null;
actions.Free();
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ protected static Document GetDocumentAndSelectSpan(EditorTestWorkspace workspace
diagnostic.Location.SourceSpan,
ImmutableArray.Create(diagnostic),
(a, d) => fixes.Add(new CodeFix(document.Project, a, d)),
testDriver.FallbackOptions,
CancellationToken.None);

await fixer.RegisterCodeFixesAsync(context);
Expand All @@ -187,7 +186,7 @@ protected static Document GetDocumentAndSelectSpan(EditorTestWorkspace workspace

var fixAllState = GetFixAllState(
fixAllProvider, diagnostics, fixer, testDriver, document,
scope.Value, equivalenceKey, testDriver.FallbackOptions);
scope.Value, equivalenceKey);
var fixAllContext = new FixAllContext(fixAllState, CodeAnalysisProgress.None, CancellationToken.None);
var fixAllFix = await fixAllProvider.GetFixAsync(fixAllContext);

Expand All @@ -203,25 +202,24 @@ private static FixAllState GetFixAllState(
TestDiagnosticAnalyzerDriver testDriver,
Document document,
FixAllScope scope,
string equivalenceKey,
CodeActionOptionsProvider optionsProvider)
string equivalenceKey)
{
Assert.NotEmpty(diagnostics);

if (scope == FixAllScope.Custom)
{
// Bulk fixing diagnostics in selected scope.
var diagnosticsToFix = ImmutableDictionary.CreateRange([KeyValuePairUtil.Create(document, diagnostics.ToImmutableArray())]);
return FixAllState.Create(fixAllProvider, diagnosticsToFix, fixer, equivalenceKey, optionsProvider);
return FixAllState.Create(fixAllProvider, diagnosticsToFix, fixer, equivalenceKey);
}

var diagnostic = diagnostics.First();
var diagnosticIds = ImmutableHashSet.Create(diagnostic.Id);
var fixAllDiagnosticProvider = new FixAllDiagnosticProvider(testDriver, diagnosticIds);

return diagnostic.Location.IsInSource
? new FixAllState(fixAllProvider, diagnostic.Location.SourceSpan, document, document.Project, fixer, scope, equivalenceKey, diagnosticIds, fixAllDiagnosticProvider, optionsProvider)
: new FixAllState(fixAllProvider, diagnosticSpan: null, document: null, document.Project, fixer, scope, equivalenceKey, diagnosticIds, fixAllDiagnosticProvider, optionsProvider);
? new FixAllState(fixAllProvider, diagnostic.Location.SourceSpan, document, document.Project, fixer, scope, equivalenceKey, diagnosticIds, fixAllDiagnosticProvider)
: new FixAllState(fixAllProvider, diagnosticSpan: null, document: null, document.Project, fixer, scope, equivalenceKey, diagnosticIds, fixAllDiagnosticProvider);
}

private protected Task TestActionCountInAllFixesAsync(
Expand Down
Loading