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

New-MarkdownHelp implementation for v2 #520

Merged
merged 19 commits into from
May 11, 2021

Conversation

adityapatwardhan
Copy link
Member

  • Move the v1 code to sub-folder
  • Create structure for v2
  • Implement New-MarkdownHelp
  • Add xunit tests
  • Add Pester tests
  • Add new build.ps1

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

The use of nullable-reference is a little confusing, and some seem wrong as #nullable enable is not added to all the new files. I suggest to apply #nullable enable to all new files, and that will help you get compiler's help to see if any use of nullable-reference is correct.

@adityapatwardhan
Copy link
Member Author

@daxian-dbw This is ready for re-review. I have removed the StringBuilder pool implementation as it was causing high memory consumption issues. I will include it in separate PR.

@daxian-dbw
Copy link
Member

daxian-dbw commented May 7, 2021

@adityapatwardhan Don't copy the exact ObjectPool implementation from https://docs.microsoft.com/en-us/dotnet/standard/collections/thread-safe/how-to-create-an-object-pool:

  1. you don't need a generic implementation, so no need to have ObjectPool<T> and pass in the object generator.
  2. you should borrow the Create and Return implementation of StringBuilderPooledObjectPolicy, defining capacity of the pool and a new string builder. But most importantly, you need to clear the StringBuilder instance when returning it.

You ran into a memory issue because you didn't clear the StringBuilder instance when returning.

BTW, I don't recommend to use the new() syntax. For a type with default constructor, new() makes it hard to search where the default constructor is called for this type. Take PipelineProcessor in PowerShell as an example, it has a default constructor, so the only way to look for calls to the default constructor is by searching new PipelineProcessor(). Searching all reference to PipelineProcessor type is not helpful in our case because there are too many references to it. If you use new() extensively, it would be impossible to do that search.

It might be fine to use this syntax in a small size code base, but I don't recommend to use it in the PowerShell repo.

@adityapatwardhan
Copy link
Member Author

Thanks for the feedback. Do you think ObjectPool change is needed in this PR or can be brought in later?

@daxian-dbw
Copy link
Member

Since we have been talking about it, and the changes to correct the memory issue is relatively simple, let's maybe get it done in this PR?

@daxian-dbw
Copy link
Member

@adityapatwardhan But not trying to push it. I'm totally fine if you want to do it in a separate PR. So it's up to you 😄

@adityapatwardhan
Copy link
Member Author

adityapatwardhan commented May 7, 2021

@daxian-dbw you convinced me against the usage of new() :)

@daxian-dbw
Copy link
Member

@adityapatwardhan You can absolutely use it when it's appropriate, such as for initializing the file/property members. But just be cautious when using it in other places 😄

@adityapatwardhan
Copy link
Member Author

@daxian-dbw It is ready for review.

@iSazonov
Copy link

.Net team announced End Of Support for Net461. It seems time to move from net461 to net462.

@daxian-dbw
Copy link
Member

I wish we can move directly to netstandard2.0, which implies that we support .NET Framework 4.7.2+ (.NET versions prior to 4.7.2 did NOT ship the netstanardlib.dll and thus doesn't work well with netstandard2.0 applications).

@adityapatwardhan
Copy link
Member Author

adityapatwardhan commented May 11, 2021

I will make that change in a different PR. Needs to be tested in older supported OSes. I can change to 4.6.2 now, since it is a revision update.

@daxian-dbw
Copy link
Member

@adityapatwardhan No need to do that now. The end of support is on April 26, 2022

@adityapatwardhan
Copy link
Member Author

adityapatwardhan commented May 11, 2021

@daxian-dbw Addressed your comments. Keeping it net461 and hoping to move directly to netstandard2.0 in the future.

@adityapatwardhan adityapatwardhan marked this pull request as ready for review May 11, 2021 19:21
/// </summary>
[Cmdlet(VerbsCommon.New, "MarkdownHelp", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2096483")]
[OutputType(typeof(FileInfo[]))]
public sealed class NewMarkdownHelpCommand : PSCmdlet, IModuleAssemblyCleanup
Copy link
Member

Choose a reason for hiding this comment

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

It's recommended to use a separate type for the IModuleAssemblyCleanup logic, with a name that is easy to be recognized for its functionality, like "ModuleCleanUp".

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, makes sense since it is for cleaning up the module, not just a cmdlet.

public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
Copy link
Member

Choose a reason for hiding this comment

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

Do you expect CommandHelpMarkdownWriter to be inherited by another type? If not, then add sealed to the type declaration, and then just move the logic in Dispose(bool disposing) here and remove the GC.SuppressFinalize call. You don't even need the disposedValue field unless you are checking it somewhere else in the code and will throw a ObjectDisposedException.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed.

public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
Copy link
Member

Choose a reason for hiding this comment

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

Same 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.

fixed

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

LGTM

@adityapatwardhan adityapatwardhan self-assigned this May 11, 2021
@adityapatwardhan adityapatwardhan merged commit 016dbac into PowerShell:v2 May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants