-
Notifications
You must be signed in to change notification settings - Fork 8k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Get-Help approach to find 'about_*.help.txt' files with correct locale for completions #24194
Conversation
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 helpProvidersis 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,helpFileProviderwould remainnull, potentially causing aNullReferenceExceptioninhelpFileProvider.GetExtendedSearchPaths(). - Consider adding a check like:
if (helpFileProvider == null) { // Handle the case where no HelpFileHelpProvider is found return results; }
- It might be helpful to include null checks for
-
Refactor for Clarity:
- The
forloop iterating throughhelpProviderscan be abstracted into a helper method or LINQ expression for better readability:var helpFileProvider = helpProviders.OfType<HelpFileHelpProvider>().LastOrDefault();
- The
-
Use More Descriptive Variable Names:
helpFileProvideris descriptive, but the variableiin 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.const string fileExtension = ".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:
static async Task<List<CompletionResult>> CompleteHelpTopicsAsync(CompletionContext context)
- 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
Outdated
Show resolved
Hide resolved
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.cs
Show resolved
Hide resolved
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
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs
Outdated
Show resolved
Hide resolved
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
@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" |
|
📣 Hey @MartinGC94, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
PR Summary
Updates the help topic completion code to use the same methods that
Get-Helpuses 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-Helptests presumably already covers all the edge cases that are now fixed by this.PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.- [ ] Issue filed:
(which runs in a different PS Host).