Skip to content

Add accessibility modifier on file creation#51935

Merged
CyrusNajmabadi merged 11 commits intodotnet:mainfrom
Youssef1313:cleanup-file-creation
Jul 30, 2021
Merged

Add accessibility modifier on file creation#51935
CyrusNajmabadi merged 11 commits intodotnet:mainfrom
Youssef1313:cleanup-file-creation

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
@ghost ghost added the Area-IDE label Mar 17, 2021
@sharwell
Copy link
Contributor

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
Contributor

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?

var documentOptions = ThreadHelper.JoinableTaskFactory.Run(() => addedDocument.GetOptionsAsync(cancellationToken));

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

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
Contributor

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

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge July 28, 2021 17:44
@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
Contributor

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

@CyrusNajmabadi CyrusNajmabadi merged commit 011b722 into dotnet:main Jul 30, 2021
@ghost ghost added this to the Next milestone Jul 30, 2021
@Youssef1313 Youssef1313 deleted the cleanup-file-creation branch July 30, 2021 08:34
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