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

Add accessibility modifier on file creation #51935

Merged
merged 11 commits into from
Jul 30, 2021

Conversation

Youssef1313
Copy link
Member

Fixes #50797

@sharwell Any concerns for the excessive usage of JoinableTaskFactory.Run?

@Youssef1313 Youssef1313 requested a review from a team as a code owner March 17, 2021 15:32
@sharwell
Copy link
Member

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.

@Youssef1313
Copy link
Member Author

Closing and reopening for a new build.

  Retrying 'FindPackagesByIdAsync' for source 'https://pkgs.dev.azure.com/dnceng/9ee6d478-d288-47f7-aacc-f6e6d082ae6d/_packaging/45bacae2-5efb-47c8-91e5-8ec20c22b4f8/nuget/v3/flat2/microsoft.visualstudio.progression.common/index.json'.
  An error occurred while sending the request.
    The remote name could not be resolved: 'pkgs.dev.azure.com'
  Retrying 'FindPackagesByIdAsync' for source 'https://pkgs.dev.azure.com/dnceng/9ee6d478-d288-47f7-aacc-f6e6d082ae6d/_packaging/45bacae2-5efb-47c8-91e5-8ec20c22b4f8/nuget/v3/flat2/microsoft.visualstudio.progression.interfaces/index.json'.
  An error occurred while sending the request.
    The remote name could not be resolved: 'pkgs.dev.azure.com'
  Retrying 'FindPackagesByIdAsync' for source 'https://pkgs.dev.azure.com/dnceng/9ee6d478-d288-47f7-aacc-f6e6d082ae6d/_packaging/d1622942-d16f-48e5-bc83-96f4539e7601/nuget/v3/flat2/microsoft.visualstudio.progression.codeschema/index.json'.
  An error occurred while sending the request.
    The remote name could not be resolved: 'pkgs.dev.azure.com'
  Retrying 'FindPackagesByIdAsync' for source 'https://pkgs.dev.azure.com/dnceng/9ee6d478-d288-47f7-aacc-f6e6d082ae6d/_packaging/45bacae2-5efb-47c8-91e5-8ec20c22b4f8/nuget/v3/flat2/microsoft.visualstudio.progression.codeschema/index.json'.
  An error occurred while sending the request.
    The remote name could not be resolved: 'pkgs.dev.azure.com'

@Youssef1313 Youssef1313 reopened this Mar 17, 2021
@jinujoseph jinujoseph added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Mar 17, 2021
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)
Copy link
Member

Choose a reason for hiding this comment

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

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.

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 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:

internal static async Task<SyntaxNode> GetTransformedSyntaxRootAsync(ISyntaxFacts syntaxFacts, AbstractFileHeaderHelper fileHeaderHelper, SyntaxTrivia newLineTrivia, Document document, CancellationToken cancellationToken)

Any good place for it?

@@ -331,11 +332,20 @@ private void FormatDocumentCreatedFromTemplate(IVsHierarchy hierarchy, uint item
Contract.ThrowIfNull(rootToFormat);
var documentOptions = ThreadHelper.JoinableTaskFactory.Run(() => addedDocument.GetOptionsAsync(cancellationToken));

// Add access modifier
var rootWithAccessModifier = ThreadHelper.JoinableTaskFactory.Run(() =>
Copy link
Member

Choose a reason for hiding this comment

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

ick. instead of this, can we move this all the way to the entrypoint and have it jsut call a clean async method?

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 which entrypoint did you mean?

This is where the things are done currently:

int IVsEditorFactoryNotify.NotifyItemAdded(uint grfEFN, IVsHierarchy pHier, uint itemid, string pszMkDocument)
{
// Is this being added from a template?
if (((__EFNFLAGS)grfEFN & __EFNFLAGS.EFN_ClonedFromTemplate) != 0)
{
var waitIndicator = _componentModel.GetService<IWaitIndicator>();
// TODO(cyrusn): Can this be cancellable?
waitIndicator.Wait(
"Intellisense",
allowCancel: false,
action: c => FormatDocumentCreatedFromTemplate(pHier, itemid, pszMkDocument, c.CancellationToken));
}

Probably not very trivial to make it a clean async method.

@CyrusNajmabadi
Copy link
Member

so FormatDocumentCreatedFromTemplate should do the jtf run, and call into a pure async method FormatDocumentCreatedFromTemplateAsync.

@Youssef1313
Copy link
Member Author

@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);
Copy link
Member

@sharwell sharwell Jul 28, 2021

Choose a reason for hiding this comment

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

📝 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add automatically the public keyword when new class is created.
5 participants