Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the same codepath for computing light-bulb actions to determine if hte lightbulb shoudl appear at all. #59599

Merged
merged 27 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e26c158
Extract method
CyrusNajmabadi Feb 16, 2022
965a6be
Rename
CyrusNajmabadi Feb 16, 2022
0b8bd0f
Simplify the code for getting the first fix to use to drive the light…
CyrusNajmabadi Feb 17, 2022
2af54ee
Merge branch 'asyncFixes' into firstFix
CyrusNajmabadi Feb 17, 2022
aa353fe
Fixup tests
CyrusNajmabadi Feb 17, 2022
d7b9f03
Merge branch 'asyncFixes' into firstFix
CyrusNajmabadi Feb 17, 2022
6667775
REstore
CyrusNajmabadi Feb 17, 2022
a0a88ae
Rename
CyrusNajmabadi Feb 17, 2022
a5d0270
Merge remote-tracking branch 'upstream/main' into firstFix
CyrusNajmabadi Feb 17, 2022
8b5c1ac
Update tests
CyrusNajmabadi Feb 17, 2022
103f92e
Fix test
CyrusNajmabadi Feb 17, 2022
783f777
Delete comment
CyrusNajmabadi Feb 17, 2022
7cce002
Clean up
CyrusNajmabadi Feb 17, 2022
d78637b
Merge remote-tracking branch 'upstream/main' into firstFix
CyrusNajmabadi Feb 17, 2022
290b067
Move check to tests
CyrusNajmabadi Feb 17, 2022
96cd892
Merge remote-tracking branch 'upstream/main' into firstFix
CyrusNajmabadi Feb 18, 2022
3ddb4ef
Merge remote-tracking branch 'upstream/main' into firstFix
CyrusNajmabadi Feb 22, 2022
ea54284
Simplify
CyrusNajmabadi Feb 24, 2022
52cd3a9
simplify
CyrusNajmabadi Feb 24, 2022
3c7c77d
Named param
CyrusNajmabadi Feb 24, 2022
7b23cee
Clean up docs
CyrusNajmabadi Feb 24, 2022
b6d7523
rename
CyrusNajmabadi Feb 24, 2022
a739368
Use multi-add
CyrusNajmabadi Feb 24, 2022
1e14889
rename file
CyrusNajmabadi Feb 24, 2022
61092f3
Merge remote-tracking branch 'upstream/main' into firstFix
CyrusNajmabadi Feb 26, 2022
3e3e3fc
Merge remote-tracking branch 'upstream/main' into firstFix
CyrusNajmabadi Feb 28, 2022
8f4c7f0
Merge remote-tracking branch 'upstream/release/dev17.3' into firstFix
CyrusNajmabadi Mar 1, 2022
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 @@ -102,13 +102,7 @@ private async Task GetSuggestedActionsWorkerAsync(
// Collectors are in priority order. So just walk them from highest to lowest.
Copy link
Member Author

Choose a reason for hiding this comment

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

should be viewed with whitespace off.

foreach (var collector in collectors)
{
var priority = collector.Priority switch
{
VisualStudio.Utilities.DefaultOrderings.Highest => CodeActionRequestPriority.High,
VisualStudio.Utilities.DefaultOrderings.Default => CodeActionRequestPriority.Normal,
VisualStudio.Utilities.DefaultOrderings.Lowest => CodeActionRequestPriority.Lowest,
_ => (CodeActionRequestPriority?)null,
};
var priority = TryGetPriority(collector.Priority);

if (priority != null)
{
Expand Down
48 changes: 32 additions & 16 deletions src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,29 +414,45 @@ await InvokeBelowInputPriorityAsync(() =>
ReferenceCountedDisposable<State> state,
Document document,
SnapshotSpan range,
CodeActionOptions options,
CancellationToken cancellationToken)
{
if (state.Target.Owner._codeFixService != null &&
state.Target.SubjectBuffer.SupportsCodeFixes())
foreach (var order in s_orderings)
{
var result = await state.Target.Owner._codeFixService.GetMostSevereFixableDiagnosticAsync(
document, range.Span.ToTextSpan(), cancellationToken).ConfigureAwait(false);
var priority = TryGetPriority(order);
Contract.ThrowIfNull(priority);

if (result.HasFix)
{
Logger.Log(FunctionId.SuggestedActions_HasSuggestedActionsAsync);
return GetFixCategory(result.Diagnostic.Severity);
}
var result = await GetFixLevelAsync(priority.Value).ConfigureAwait(false);
if (result != null)
return result;
}

return null;

if (result.PartialResult)
async Task<string?> GetFixLevelAsync(CodeActionRequestPriority priority)
{
if (state.Target.Owner._codeFixService != null &&
state.Target.SubjectBuffer.SupportsCodeFixes())
{
// reset solution version number so that we can raise suggested action changed event
Volatile.Write(ref state.Target.LastSolutionVersionReported, InvalidSolutionVersion);
return null;
var result = await state.Target.Owner._codeFixService.GetMostSevereFixAsync(
document, range.Span.ToTextSpan(), priority, options, cancellationToken).ConfigureAwait(false);

if (result.HasFix)
{
Logger.Log(FunctionId.SuggestedActions_HasSuggestedActionsAsync);
return GetFixCategory(result.CodeFixCollection.FirstDiagnostic.Severity);
}

if (!result.UpToDate)
{
// reset solution version number so that we can raise suggested action changed event
Volatile.Write(ref state.Target.LastSolutionVersionReported, InvalidSolutionVersion);
return null;
}
}
}

return null;
return null;
}
}

private async Task<string?> TryGetRefactoringSuggestedActionCategoryAsync(
Expand Down Expand Up @@ -619,7 +635,7 @@ private void OnSuggestedActionsChanged(Workspace currentWorkspace, DocumentId? c
using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
var linkedToken = linkedTokenSource.Token;

var errorTask = Task.Run(() => GetFixLevelAsync(state, document, range, linkedToken), linkedToken);
var errorTask = Task.Run(() => GetFixLevelAsync(state, document, range, options, linkedToken), linkedToken);

var selection = await GetSpanAsync(state, range, linkedToken).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using System.Linq;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tags;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
Expand All @@ -37,6 +37,21 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions
[SuggestedActionPriority(DefaultOrderings.Lowest)]
internal partial class SuggestedActionsSourceProvider : ISuggestedActionsSourceProvider
{
private static readonly ImmutableArray<string> s_orderings = ImmutableArray.Create(
DefaultOrderings.Highest,
DefaultOrderings.Default,
DefaultOrderings.Lowest);

static SuggestedActionsSourceProvider()
{
// Ensure that the list of orderings on this type matches the set we expose in s_orderings
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for adding this!

var attributes = typeof(SuggestedActionsSourceProvider).GetCustomAttributes(inherit: false)
.OfType<SuggestedActionPriorityAttribute>()
.ToImmutableArray();
Contract.ThrowIfFalse(attributes.Length == s_orderings.Length);
Contract.ThrowIfFalse(attributes.Select(a => a.Priority).SetEquals(s_orderings));
}
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved

private static readonly Guid s_CSharpSourceGuid = new Guid("b967fea8-e2c3-4984-87d4-71a38f49e16a");
private static readonly Guid s_visualBasicSourceGuid = new Guid("4de30e93-3e0c-40c2-a4ba-1124da4539f6");
private static readonly Guid s_xamlSourceGuid = new Guid("a0572245-2eab-4c39-9f61-06a6d8c5ddda");
Expand Down Expand Up @@ -100,5 +115,14 @@ public SuggestedActionsSourceProvider(
? new AsyncSuggestedActionsSource(_threadingContext, _globalOptions, this, textView, textBuffer, _suggestedActionCategoryRegistry)
: new SyncSuggestedActionsSource(_threadingContext, _globalOptions, this, textView, textBuffer, _suggestedActionCategoryRegistry);
}

private static CodeActionRequestPriority? TryGetPriority(string priority)
=> priority switch
{
DefaultOrderings.Highest => CodeActionRequestPriority.High,
DefaultOrderings.Default => CodeActionRequestPriority.Normal,
DefaultOrderings.Lowest => CodeActionRequestPriority.Lowest,
_ => (CodeActionRequestPriority?)null,
};
}
}
6 changes: 4 additions & 2 deletions src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public async Task TestGetFirstDiagnosticWithFixAsync()
var reference = new MockAnalyzerReference();
var project = workspace.CurrentSolution.Projects.Single().AddAnalyzerReference(reference);
var document = project.Documents.Single();
var unused = await fixService.GetMostSevereFixableDiagnosticAsync(document, TextSpan.FromBounds(0, 0), cancellationToken: CancellationToken.None);
var unused = await fixService.GetMostSevereFixAsync(
document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, CodeActionOptions.Default, CancellationToken.None);

var fixer1 = (MockFixer)fixers.Single().Value;
var fixer2 = (MockFixer)reference.Fixer!;
Expand Down Expand Up @@ -297,7 +298,8 @@ private static async Task GetFirstDiagnosticWithFixWithExceptionValidationAsync(
errorReportingService.OnError = message => errorReported = true;

GetDocumentAndExtensionManager(tuple.analyzerService, workspace, out var document, out var extensionManager);
var unused = await tuple.codeFixService.GetMostSevereFixableDiagnosticAsync(document, TextSpan.FromBounds(0, 0), cancellationToken: CancellationToken.None);
var unused = await tuple.codeFixService.GetMostSevereFixAsync(
document, TextSpan.FromBounds(0, 0), CodeActionRequestPriority.None, CodeActionOptions.Default, CancellationToken.None);
Assert.True(extensionManager.IsDisabled(codefix));
Assert.False(extensionManager.IsIgnored(codefix));
Assert.True(errorReported);
Expand Down
Loading