-
Notifications
You must be signed in to change notification settings - Fork 8k
Add single/double quote support for Join-String Argument Completer
#25283
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
Add single/double quote support for Join-String Argument Completer
#25283
Conversation
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
…letionHelpers.cs Co-authored-by: Ilya <darpa@yandex.ru>
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs
Outdated
Show resolved
Hide resolved
| { | ||
| string completionText = QuoteCompletionText(value, quote); | ||
| string toolTip = toolTipMapping?.Invoke(value) ?? value; | ||
| string listItemText = listItemTextMapping?.Invoke(value) ?? value; |
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.
We should do the both mappings in one method. If this requires many changes in other completers it is better to implement this in follow PR.
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.
Agree. I am actually thinking of just changing the type from Func<string, string> to Dictionary<string, (string Tooltip, string ListItemText)>. I am not sure Func is the best type to use here.
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.
It could be Func<string, (string Tooltip, string ListItemText)>. It's not critical right now. We can postpone the decision when we choose how best to extend the interface.
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.
Yep sounds good. Will postpone this. I'd like to just get IsMatch and ListItemTextMapping in interface in next PR.
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.
We should do the both mappings in one method.
+ for flexibility we could consider cascading as for possible values method => static list.
|
Thanks for reviews @iSazonov. Let me know what you think with latest changes 🙂 |
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs
Outdated
Show resolved
Hide resolved
…n-String.cs Co-authored-by: Ilya <darpa@yandex.ru>
|
@ArmaanMcleod Please look test failures. |
Thanks @iSazonov. I think test failures are from wildcard pattern like I fixed this in 09818bb |
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Show resolved
Hide resolved
Sorry, it is my typo. Right wording is "do the normalization only if quote is NOT single quote."
I mean we can add this in follow PR. I don't force you to implement this. Now I'd only move the normalization (two
I considered the case but there can be some tokens and it is not easy combine them back in source string. So I concluded it is better to convert WordToComplete.
As I said I agree with current |
|
@iSazonov I have moved this to a method called |
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
…letionHelpers.cs Co-authored-by: Ilya <darpa@yandex.ru>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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 merge this as-is since the PR is good and too large to keep improving.
@ArmaanMcleod Thanks for your efforts!
The comments are below, which I have compiled for further work. Some of them are optional, some are important.
| IEnumerable<string> possibleCompletionValues, | ||
| Func<string, string> toolTipMapping = null, | ||
| CompletionResultType resultType = CompletionResultType.Text) | ||
| Func<string, string> listItemTextMapping = null, |
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.
Perhaps convert these Func<string, string> to delegate.
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.
Yep agree it should all be consolidated to delegates.
| { | ||
| string completionText = QuoteCompletionText(value, quote); | ||
| string toolTip = toolTipMapping?.Invoke(value) ?? value; | ||
| string listItemText = listItemTextMapping?.Invoke(value) ?? value; |
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.
We should do the both mappings in one method.
+ for flexibility we could consider cascading as for possible values method => static list.
| internal static string NormalizeToExpandableString(string value) | ||
| => value | ||
| .Replace("\r", "`r") | ||
| .Replace("\n", "`n") | ||
| .Replace("\t", "`t") |
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.
The method could be optimized for performance as separate work (low priority).
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.
This one is actually quite difficult to optimize, basic Replace approach outperforms other methods (string builder, regex etc.).
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
| /// </remarks> | ||
| internal static readonly MatchStrategy WildcardPatternMatch = (value, wordToComplete) | ||
| => WildcardPattern | ||
| .Get(wordToComplete + "*", WildcardOptions.IgnoreCase) |
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 always wonder why we don't have GetStar(wordToComplete, WildcardOptions.IgnoreCase). At least internally.
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.
That would be good but the name seems a bit weird. For now its fine to just append * ourselves which is everywhere in this codebase 😄.
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
|
@ArmaanMcleod Please remove my two last commits or add new commit to unlock the PR merging. |
…letionHelpers.cs Co-authored-by: Ilya <darpa@yandex.ru>
…letionHelpers.cs Co-authored-by: Ilya <darpa@yandex.ru>
…letionHelpers.cs Co-authored-by: Ilya <darpa@yandex.ru>
…letionHelpers.cs Co-authored-by: Ilya <darpa@yandex.ru>
|
Thanks @iSazonov. I have added some commits from your suggestions. I think for the rest better to do that in another PR for improvements. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
📣 Hey @@ArmaanMcleod, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
PR Summary
This PR makes sure
JoinItemCompleterusesCompletionHelpers.GetMatchingResultsso completions can work with single/double quotes.There is multiple improvements with this completer which is also included in tests, e.g. completing newlines and supporting more variations/flexibility with single/double quotes. I also split
JoinItemCompleterintoSeparatorArgumentCompleterand FormatStringArgumentCompleter`.I've also made the following changes in preparation to extend
IArgumentCompleterfurther:MatchStrategydelegates which can be implemented and overriden by user potentially. This will allowGetMatchingResultsto be more flexible with how values are matched.added new
listItemTextMappingparameter toGetMatchingResultsso we can customize list item text which is needed forJoinItemCompleter.PR Context
Fixes #24873
This was the last completer I intended to move to
GetMatchingResultssince it requires behaviour which will help influence the interface extension in #25033.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).