Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use Get-Help approach to find 'about_*.help.txt' files with correct locale for completions#24194

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

MartinGC94
Copy link
Contributor

@MartinGC94MartinGC94 commentedAug 22, 2024
edited
Loading

PR Summary

Updates the help topic completion code to use the same methods thatGet-Help uses when finding the topics. This will make it more accurate when handling different locales and also makes it search modules forabout_ topics.
I haven't added any tests as theGet-Help tests presumably already covers all the edge cases that are now fixed by this.

PR Context

PR Checklist

@microsoft-github-policy-servicemicrosoft-github-policy-servicebot added the Review - NeededThe PR is being reviewed labelAug 29, 2024
Copy link

@Imran-imtiaz48Imran-imtiaz48 left a comment

Choose a reason for hiding this comment

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

  1. Efficient Use of Generics and Collections:

    • The use ofList<CompletionResult> ensures that the results are stored in a typed and efficient collection, improving performance and type safety.
    • The use ofArrayList helpProviders is straightforward, and the loop efficiently finds the right help provider by iterating in reverse order.
  2. Clear Purpose:

    • The function's intent to autocomplete help topics is clear. It retrieves the relevant help topics by searching for help files based on the user's input (context.WordToComplete).
    • The logic for filtering filenames that start with"about_" indicates a good understanding of the help topic conventions.
  3. Error Prevention:

    • The checkfileName.StartsWith("about_", StringComparison.OrdinalIgnoreCase) prevents case-sensitivity issues, which is good for cross-platform consistency.

Suggestions for Improvement:

  1. Null Checks:

    • It might be helpful to include null checks forhelpFileProvider. If no provider is found in the loop,helpFileProvider would remainnull, potentially causing aNullReferenceException inhelpFileProvider.GetExtendedSearchPaths().
    • Consider adding a check like:
      if(helpFileProvider==null){// Handle the case where no HelpFileHelpProvider is foundreturnresults;}
  2. Refactor for Clarity:

    • Thefor loop iterating throughhelpProviders can be abstracted into a helper method or LINQ expression for better readability:
      varhelpFileProvider=helpProviders.OfType<HelpFileHelpProvider>().LastOrDefault();
  3. Use More Descriptive Variable Names:

    • helpFileProvider is descriptive, but the variablei in the loop could be replaced with something more meaningful, likeproviderIndex. However, this might be less relevant if you switch to LINQ as suggested above.
  4. File Searching:

    • Instead of relying on the hard-coded string".help.txt", you might want to store that as a constant or parameterize it to enhance maintainability.
      conststringfileExtension=".help.txt";
  5. Potential Optimization with String Manipulation:

    • In the line where you usefileName.Substring(0, fileName.LastIndexOf(".help.txt")), you could consider usingPath.GetFileNameWithoutExtension(path) if you're always targeting the last extension.
  6. Asynchronous Operations:

    • Depending on the usage context, if this file search might involve I/O-bound operations that could block the main thread, consider making this method asynchronous:
      staticasyncTask<List<CompletionResult>>CompleteHelpTopicsAsync(CompletionContextcontext)
  7. Logging and Error Handling:

    • Currently, there are no logging or exception-handling mechanisms in place. Adding error handling for file operations and logging unexpected behaviors would help with debugging and robustness.

Final Thoughts:

The method is well-structured and efficient for its intended use. With a few improvements around null checks, readability, and potential optimizations, it can become more robust and maintainable.

Copy link
Collaborator

@SeeminglyScienceSeeminglyScience left a comment

Choose a reason for hiding this comment

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

Thanks Martin! Looks great, one question/potential change

MartinGC94and others added2 commitsDecember 12, 2024 09:32
Co-authored-by: Patrick Meinecke <SeeminglyScience@users.noreply.github.com>
@iSazonov

This comment was marked as outdated.

@microsoft-github-policy-servicemicrosoft-github-policy-servicebot removed the Review - NeededThe PR is being reviewed labelFeb 26, 2025
@azure-pipelinesAzure Pipelines

This comment was marked as outdated.

@iSazonoviSazonov added Review - NeededThe PR is being reviewed CL-GeneralIndicates that a PR should be marked as a general cmdlet change in the Change Log labelsFeb 26, 2025
Copy link
Collaborator

@iSazonoviSazonov left a comment

Choose a reason for hiding this comment

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

I found tests in TabCompletion.Test.ps1 so it is ok for tests.

@iSazonoviSazonov self-assigned thisFeb 26, 2025
@microsoft-github-policy-servicemicrosoft-github-policy-servicebot removed the Review - NeededThe PR is being reviewed labelFeb 26, 2025
@iSazonov

This comment was marked as outdated.

@azure-pipelinesAzure Pipelines

This comment was marked as outdated.

@iSazonov

This comment was marked as outdated.

@azure-pipelinesAzure Pipelines

This comment was marked as outdated.

@iSazonov
Copy link
Collaborator

iSazonov commentedFeb 27, 2025
edited
Loading

@MartinGC94 Please reword the PR header and description. I see the PR is exclusively for "about_" files.

@MartinGC94
Copy link
ContributorAuthor

I don't see what's wrong with the current title and description. It matches exactly what this PR does: It replaces the custom logic to find help topics in the completion code with the logic that the help system uses.

@iSazonov
Copy link
Collaborator

The header says nothing about "about_" files. And it follows from the description that the locale search has been fixed, and the rest is an addition. Maybe something like "Use Get-Help approach to find 'about_*.help.txt' files with correct locale"

@MartinGC94MartinGC94 changed the titleUse help system code to complete help topicsUse Get-Help approach to find 'about_*.help.txt' files with correct locale for completionsFeb 27, 2025
@iSazonoviSazonov merged commitbdf0400 intoPowerShell:masterFeb 27, 2025
39 of 41 checks passed
@microsoft-github-policy-serviceMicrosoft GitHub Policy Service
Copy link
Contributor

microsoft-github-policy-servicebot commentedFeb 27, 2025
edited by unfurl-linksbot
Loading

📣 Hey@MartinGC94, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗https://aka.ms/PSRepoFeedback

@MartinGC94MartinGC94 deleted the UpdateHelpTopicCompletion branchFebruary 28, 2025 10:40
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@SeeminglyScienceSeeminglyScienceSeeminglyScience left review comments

@Imran-imtiaz48Imran-imtiaz48Imran-imtiaz48 left review comments

@iSazonoviSazonoviSazonov approved these changes

Assignees

@iSazonoviSazonov

Labels
CL-GeneralIndicates that a PR should be marked as a general cmdlet change in the Change Log
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@MartinGC94@iSazonov@SeeminglyScience@Imran-imtiaz48

[8]ページ先頭

©2009-2025 Movatter.jp