- Notifications
You must be signed in to change notification settings - Fork7.7k
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Imran-imtiaz48 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Efficient Use of Generics and Collections:
- The use of
List<CompletionResult>
ensures that the results are stored in a typed and efficient collection, improving performance and type safety. - The use of
ArrayList helpProviders
is straightforward, and the loop efficiently finds the right help provider by iterating in reverse order.
- The use of
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.
- 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 (
Error Prevention:
- The check
fileName.StartsWith("about_", StringComparison.OrdinalIgnoreCase)
prevents case-sensitivity issues, which is good for cross-platform consistency.
- The check
Suggestions for Improvement:
Null Checks:
- It might be helpful to include null checks for
helpFileProvider
. 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;}
- It might be helpful to include null checks for
Refactor for Clarity:
- The
for
loop iterating throughhelpProviders
can be abstracted into a helper method or LINQ expression for better readability:varhelpFileProvider=helpProviders.OfType<HelpFileHelpProvider>().LastOrDefault();
- The
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.
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";
- Instead of relying on the hard-coded string
Potential Optimization with String Manipulation:
- In the line where you use
fileName.Substring(0, fileName.LastIndexOf(".help.txt"))
, you could consider usingPath.GetFileNameWithoutExtension(path)
if you're always targeting the last extension.
- In the line where you use
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)
- 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:
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.
There was a problem hiding this 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
src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Patrick Meinecke <SeeminglyScience@users.noreply.github.com>
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this 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.
src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
iSazonov commentedFeb 27, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@MartinGC94 Please reword the PR header and description. I see the PR is exclusively for "about_" files. |
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. |
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" |
bdf0400
intoPowerShell:masterUh oh!
There was an error while loading.Please reload this page.
microsoft-github-policy-servicebot commentedFeb 27, 2025 • edited by unfurl-linksbot
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by unfurl-linksbot
Uh oh!
There was an error while loading.Please reload this page.
📣 Hey@MartinGC94, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗https://aka.ms/PSRepoFeedback |
Uh oh!
There was an error while loading.Please reload this page.
PR Summary
Updates the help topic completion code to use the same methods that
Get-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 the
Get-Help
tests presumably already covers all the edge cases that are now fixed by this.PR Context
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.- [ ] Issue filed:
(which runs in a different PS Host).