Add accessibility modifier on file creation#51935
Add accessibility modifier on file creation#51935CyrusNajmabadi merged 11 commits intodotnet:mainfrom
Conversation
|
No performance concerns about JTF.Run on this particular path. After this is merged, the method could be refactored to make the containing method asynchronous instead, and use a single JTF.Run in the caller. |
|
Closing and reopening for a new build. |
...Core/CodeFixes/AddAccessibilityModifiers/AbstractAddAccessibilityModifiersCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
| Document document, ImmutableArray<Diagnostic> diagnostics, | ||
| SyntaxEditor editor, CancellationToken cancellationToken) | ||
| // Intended for use by AbstractEditorFactory to add accessibility when creating a new file. | ||
| internal static async Task<SyntaxNode> GetTransformedSyntaxRootAsync(Document document, CancellationToken cancellationToken) |
There was a problem hiding this comment.
this is in a codefix. we shoudl not be calling it from random code. INstead, make a helper somewhere and have both the feature and the editor call into that helper.
There was a problem hiding this comment.
this is in a codefix. we shoudl not be calling it from random code. INstead, make a helper somewhere and have both the feature and the editor call into that helper.
I was following what's done with AbstractFileHeaderCodeFixProvider:
Any good place for it?
| var documentOptions = ThreadHelper.JoinableTaskFactory.Run(() => addedDocument.GetOptionsAsync(cancellationToken)); | ||
|
|
||
| // Add access modifier | ||
| var rootWithAccessModifier = ThreadHelper.JoinableTaskFactory.Run(() => |
There was a problem hiding this comment.
ick. instead of this, can we move this all the way to the entrypoint and have it jsut call a clean async method?
There was a problem hiding this comment.
I'm not sure which entrypoint did you mean?
This is where the things are done currently:
roslyn/src/VisualStudio/Core/Def/Implementation/AbstractEditorFactory.cs
Lines 274 to 285 in a358ab7
Probably not very trivial to make it a clean async method.
|
so FormatDocumentCreatedFromTemplate should do the jtf run, and call into a pure async method FormatDocumentCreatedFromTemplateAsync. |
|
@CyrusNajmabadi Thanks for taking this on! |
| // Organize using directives | ||
| addedDocument = ThreadHelper.JoinableTaskFactory.Run(() => OrganizeUsingsCreatedFromTemplateAsync(addedDocument, cancellationToken)); | ||
| rootToFormat = ThreadHelper.JoinableTaskFactory.Run(() => addedDocument.GetRequiredSyntaxRootAsync(cancellationToken).AsTask()); | ||
| addedDocument = await OrganizeUsingsCreatedFromTemplateAsync(addedDocument, cancellationToken).ConfigureAwait(false); |
There was a problem hiding this comment.
📝 These can all be ConfigureAwait(true) to improve efficiency (the main thread is the caller and available to process continuations without the potential latency of the thread pool)
Fixes #50797
@sharwell Any concerns for the excessive usage of
JoinableTaskFactory.Run?