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

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Feb 17, 2022

Followup to #59585


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!

@@ -102,13 +102,7 @@ private partial class AsyncSuggestedActionsSource : SuggestedActionsSource, IAsy
// 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.

@@ -73,72 +71,87 @@ internal partial class CodeFixService : ICodeFixService
_configurationProvidersMap = GetConfigurationProvidersPerLanguageMap(configurationProviders);
}

public async Task<FirstDiagnosticResult> GetMostSevereFixableDiagnosticAsync(
Document document, TextSpan range, CancellationToken cancellationToken)
private Func<string, bool>? GetShouldIncludeDiagnosticPredicate(
Copy link
Member Author

Choose a reason for hiding this comment

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

this helper was extracted so it can be used from two entrypoints.


var spanToDiagnostics = ConvertToMap(allDiagnostics);
Copy link
Member Author

Choose a reason for hiding this comment

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

the start of this is extremely similar to StreamFixesAsync. Both start similarly (though one calls TryGetDaignostics, and one called GetDiagnostics), but how they process hte remainder is different.

// synchronously do the work at the spot.
//
// this design's weakness is that each side don't have enough information to narrow down works to do. it
// will most likely always do more works than needed. sometimes way more than it is needed. (compilation)
Copy link
Member Author

Choose a reason for hiding this comment

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

i'm not sure how valuable some of these comments are. but i'm leaving them in.

Copy link
Member

Choose a reason for hiding this comment

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

I'm more laughing at "this is the first...design" when we've now changed this how many times? 😄

@sharwell
Copy link
Member

Will this make #40672 more difficult?

@CyrusNajmabadi
Copy link
Member Author

Will this make #40672 more difficult?

I don't believe so. This is just unifying code we already have to be cleaner.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review February 17, 2022 20:24
@CyrusNajmabadi
Copy link
Member Author

@jasonmalinowski this is ready for review.

var diagnostic = await errorDiagnosticsTask.ConfigureAwait(false)
?? await otherDiagnosticsTask.ConfigureAwait(false);
var collection = await errorFixTask.ConfigureAwait(false) ??
await otherFixTask.ConfigureAwait(false);
linkedTokenSource.Cancel();
Copy link
Member Author

Choose a reason for hiding this comment

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

imo, this part of the design is unfortunate, though i get why we have it. we basically want to return an error if we have one so that the lightbulb can be red not yello. However, that means that even if we determine that we have some other fix first, we can't quickly update the UI.

/// first. This will also attempt to return a fix for an error first, but will fall back to any fix if that
/// does not succeed.
/// </summary>
Task<FirstFixResult> GetMostSevereFixAsync(Document document, TextSpan range, CodeActionRequestPriority priority, CodeActionOptions options, CancellationToken cancellationToken);
Copy link
Member Author

Choose a reason for hiding this comment

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

outside of addOperationScope (which is used for updating the TWD progress bar for synchronous lightbulbs) this sig now matches the above.

@CyrusNajmabadi
Copy link
Member Author

@jasonmalinowski @mavasani this is ready for review.

Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Some funny looking bits but generally looks good. I'll admit I don't quite have a big picture here, but was able to at least look at this and keep nodding and saying "looks reasonable".


namespace Microsoft.CodeAnalysis.CodeFixes
{
internal readonly struct FirstDiagnosticResult
internal readonly struct FirstFixResult
Copy link
Member

Choose a reason for hiding this comment

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

Rename file to match.

src/Features/Core/Portable/CodeFixes/CodeFixService.cs Outdated Show resolved Hide resolved
.OfType<SuggestedActionPriorityAttribute>()
.ToImmutableArray();
Assert.Equal(attributes.Length, SuggestedActionsSourceProvider.Orderings.Length);
AssertEx.SetEqual(attributes.Select(a => a.Priority), SuggestedActionsSourceProvider.Orderings);
Copy link
Member

Choose a reason for hiding this comment

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

The "SetEqual" here means the orderings can be different -- is that expected here? I would have assumed "orderings" were intended to be ordered here?

Copy link
Member Author

Choose a reason for hiding this comment

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

i have no idea if attributes are ordered when either emitting or reading back from metadata. So this is a setequals as we don't actually care if eitehr is true. All w care about is that the set we exported matches the items in the array in that field.

{
foreach (var diagnostic in diagnostics)
{
var otherMap = diagnostic.Severity == DiagnosticSeverity.Error
Copy link
Member

Choose a reason for hiding this comment

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

Hmm I would have assumed "otherMap" was the "the map that doesn't match the severity", but I guess not? Or is this a typo?

Copy link
Member

Choose a reason for hiding this comment

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

(just call it "map"?)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes. that name was terrible. changed to preferredMap.

src/Features/Core/Portable/CodeFixes/CodeFixService.cs Outdated Show resolved Hide resolved
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner March 1, 2022 21:38
@CyrusNajmabadi CyrusNajmabadi changed the base branch from main to release/dev17.3 March 3, 2022 00:28
@CyrusNajmabadi CyrusNajmabadi merged commit 372547b into dotnet:release/dev17.3 Mar 4, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the firstFix branch March 4, 2022 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants