Skip to content

Pass cancellation token consistently through lsif generator.#65875

Merged
CyrusNajmabadi merged 10 commits intodotnet:mainfrom
CyrusNajmabadi:lsifCancellation
Dec 12, 2022
Merged

Pass cancellation token consistently through lsif generator.#65875
CyrusNajmabadi merged 10 commits intodotnet:mainfrom
CyrusNajmabadi:lsifCancellation

Conversation

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

Followup to #65858

@ghost ghost added the Area-IDE label Dec 8, 2022
public async Task GenerateForProjectAsync(
Project project,
GeneratorOptions options,
CancellationToken cancellationToken)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So we generally weren't worrying about cancellation at all since we don't have any way to produce a cancellation token from the start -- did you have something in mind where we might have one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup. A totally reasonable pattern is to register to hear about ctrl-c and prompt, or use that for cancellation. I agree this it not a big deal here as we're ok with just killing things. But i like code with good hygiene :)

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review December 10, 2022 20:35
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner December 10, 2022 20:35
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@jasonmalinowski ptal.

Comment thread src/Features/Lsif/Generator/Generator.cs Outdated
Comment thread src/Features/Lsif/Generator/Generator.cs Outdated
if (document is SourceGeneratedDocument)
{
var text = await document.GetTextAsync().ConfigureAwait(false);
var text = await document.GetTextAsync();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💭 I thought GetTextAsync would have accepted a cancellation token

_ => throw new NotImplementedException()
};

var cancellationToken = CancellationToken.None;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❔ Move to parameter?

@@ -81,21 +90,21 @@ private static async Task GenerateAsync(FileInfo? solution, FileInfo? project, F
if (solution != null)
{
await LocateAndRegisterMSBuild(logFile);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❔ Missing cancellation token?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nothing in that method needs CT as fat as i can tell :)

Comment thread src/Features/Lsif/Generator/Program.cs Outdated
Comment thread src/Features/Lsif/Generator/Program.cs Outdated
Assert.Empty(compilation.GetDiagnostics().Where(Function(d) d.Severity = DiagnosticSeverity.Error))

Await lsifGenerator.GenerateForProjectAsync(project, GeneratorOptions.Default)
Await lsifGenerator.GenerateForProjectAsync(project, GeneratorOptions.Default, CancellationToken.None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move to parameter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

for tests, i'm ok with this.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@jasonmalinowski ptal.

Comment on lines +7 to +8
# CA2016: Forward the 'CancellationToken' parameter to methods
dotnet_diagnostic.CA2016.severity = warning
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see this already being set here:

# CA2016: Forward the 'CancellationToken' parameter to methods
dotnet_diagnostic.CA2016.severity = warning

Why didn't that take effect?

Copy link
Copy Markdown
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.

@CyrusNajmabadi Signing off if this is really something you want to take, but I'm not sure the "hygiene" here really feels worth it to me. Since we're not actually using this token anywhere, the code that's now trying to be cancellation safe is still not being exercised or tested in any way, and now this will just mean we get to spend more time maintaining passing the token around.

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

but I'm not sure the "hygiene" here really feels worth it to me.

So basically, i'd prefer all our code follow the same rules. That way it's trivial to move/refactor code around and not have to go "oh... this code was originally in the console, but now it's in library code, so we have to update everything it does". Having disparate islands of rules also just makes things more complicated when working as as you jump around from library to console yo have to take on disparate sets of rules.

Finally, i find reviewing much more complex as these things are literally triggers. e.g. when i see CancellationToken.None i have to expend mental cycles figuring out what that means and why it's ok. When all our code follows the same rules, i just don't have to care.

@CyrusNajmabadi CyrusNajmabadi merged commit e56ba07 into dotnet:main Dec 12, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the lsifCancellation branch December 12, 2022 22:19
@ghost ghost added this to the Next milestone Dec 12, 2022
@Cosifne Cosifne modified the milestones: Next, 17.5 P3 Jan 4, 2023
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