Skip to content

Conversation

@ArmaanMcleod
Copy link
Contributor

@ArmaanMcleod ArmaanMcleod commented Jan 22, 2025

PR Summary

The below argument completers don't have support for quotes:

  • VerbArgumentCompleter
  • StrictModeVersionArgumentCompleter
  • ScopeArgumentCompleter

This PR creates a static method GetMatchingResults which wraps the quote handling using CompletionCompleters.HandleDoubleAndSingleQuote and reuses this method across all these argument completers so quotes are handled in the same way. Happy to change this method name, I could not figure out a nicer name :D.

I also refactored VerbArgumentCompleter for Get-Verb/Get-Command to separate the actual cmdlet filtering and the completion methods, so it can also use this shared method like the other completers. Previously the cmdlet filtering and completion code were quite coupled but it makes more sense to separate these two since they both have different requirements, and it simplifies the code.

There are also more tests added to ensure single/double quotes are being handled correctly.

I've also ensured the PropertyTypeArgumentCompleter is using the same method which was already handling quotes in #21117.

PR Context

Fixes #24838

PR Checklist

@iSazonov

This comment was marked as outdated.

@azure-pipelines

This comment was marked as outdated.

@ArmaanMcleod ArmaanMcleod changed the title Refactor ArgumentCompleters to use single method for quoted & unqoted completions Refactor Argument Completers to use single method for quoted & unqoted completions Jan 23, 2025
@iSazonov
Copy link
Collaborator

@MartinGC94 Could you please review?

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jan 23, 2025
@ArmaanMcleod
Copy link
Contributor Author

ArmaanMcleod commented Jan 23, 2025

I think the remaining mystery is with Array parameter completion.

if you do Get-Verb -Verb "A it will complete to Get-Verb -Verb "Add". Single array strings work fine.

But if you have an array and you surround quotes on the next item it does not tab complete correctly e.g. Get-Verb -Verb "Add", "C completes using file paths Get-Verb -Verb "Add", ".\CHANGELOG\". I suspect it is going back to file path completion.

@MartinGC94 @iSazonov Wondering if you would know why this might be happening?

@iSazonov
Copy link
Collaborator

I suspect it is going back to file path completion.

Yes, I suggest postpone this to follow PR.

@ArmaanMcleod ArmaanMcleod requested a review from iSazonov January 23, 2025 15:03
@iSazonov

This comment was marked as outdated.

@azure-pipelines

This comment was marked as outdated.

@ArmaanMcleod ArmaanMcleod changed the title Refactor Argument Completers to use single method for quoted & unqoted completions Refactor Verb, StrictModeVersion, Scope & PropertyType Argument Completers to use single method for quoted & unquoted completions Jan 23, 2025
@ArmaanMcleod ArmaanMcleod changed the title Refactor Verb, StrictModeVersion, Scope & PropertyType Argument Completers to use single method for quoted & unquoted completions Fix Verb, StrictModeVersion, Scope & PropertyType Argument Completers to use single method for quoted & unquoted completions Jan 24, 2025
@ArmaanMcleod ArmaanMcleod force-pushed the completer-fix-and-refactoring branch from df404c8 to 593ccf5 Compare January 24, 2025 05:49
@iSazonov

This comment was marked as outdated.

@iSazonov

This comment was marked as outdated.

@azure-pipelines

This comment was marked as outdated.

Copy link
Contributor

@MartinGC94 MartinGC94 left a comment

Choose a reason for hiding this comment

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

Looks fine just a few suggestions. I didn't bother to look at the tests and verbs completion though.

@ArmaanMcleod ArmaanMcleod force-pushed the completer-fix-and-refactoring branch from 53fd566 to a297ab8 Compare January 26, 2025 14:07
@ArmaanMcleod ArmaanMcleod force-pushed the completer-fix-and-refactoring branch from 00ebd15 to a246416 Compare January 27, 2025 00:16
Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

@ArmaanMcleod Now the PR contains too many unrelated changes (style, bug fixes, enhancements). Our guideline requires not mixing. I'd prefer to split the PR: first with bug fix, then style/refactoring with minimal changes in GetMatchingResults() for minimal completers, then enhancement GetMatchingResults().
Also we could update s_charactersRequiringQuotes with SearchValues.Create() in a PR.

@ArmaanMcleod
Copy link
Contributor Author

@ArmaanMcleod Now the PR contains too many unrelated changes (style, bug fixes, enhancements). Our guideline requires not mixing. I'd prefer to split the PR: first with bug fix, then style/refactoring with minimal changes in GetMatchingResults() for minimal completers, then enhancement GetMatchingResults(). Also we could update s_charactersRequiringQuotes with SearchValues.Create() in a PR.

It's a valid concern, as per your feedback I have reverted the changes.

I will create follow up PRs to address these separately:

  • Quote escaping for special characters
  • Bug fix with Completion Result type, I will need to see if this can be changed for the completers
  • Issue with quote completion with arrays

@MartinGC94 Thank you again for your review, I will address these in a separate PR so this one is easy to review and get merged in. I would also like to get these tested as well which will be easier in a separate PR

With that said, @iSazonov are you ok with current changes as they stand to get this merged in?

@iSazonov

This comment was marked as outdated.

@azure-pipelines

This comment was marked as outdated.

@ArmaanMcleod ArmaanMcleod changed the title Fix Verb, StrictModeVersion, Scope & PropertyType Argument Completers to use single method for quoted & unquoted completions Fix Verb, StrictModeVersion, Scope & PropertyType Argument Completers to use single method for completions Jan 29, 2025
@ArmaanMcleod
Copy link
Contributor Author

@iSazonov Was there anything else you wanted me to address? I'd like to use this code to address #24873 as well.

Let me know if there are concerns or we need MSFT team to approve these changes as well 🙂. I don't have anything else to add since there is no regression being introduced with these changes.

@iSazonov iSazonov self-assigned this Feb 1, 2025
@iSazonov

This comment was marked as outdated.

@azure-pipelines

This comment was marked as duplicate.

@iSazonov iSazonov changed the title Fix Verb, StrictModeVersion, Scope & PropertyType Argument Completers to use single method for completions Add quote handling in Verb, StrictModeVersion, Scope & PropertyType Argument Completers with single helper method Feb 1, 2025
@iSazonov iSazonov merged commit 459fc8d into PowerShell:master Feb 1, 2025
44 of 46 checks passed
@MatejKafka
Copy link
Contributor

MatejKafka commented Feb 8, 2025

Is there any specific reason for not making the new method public? Afaik, there's still no built-in way to correctly handle quoting in third-party completers, and this should mostly solve that problem, right?

Nevertheless, big 👍 for creating the method in the first place, having to handle quoting separately for each completer is really annoying. :)

@ArmaanMcleod
Copy link
Contributor Author

ArmaanMcleod commented Feb 9, 2025

Is there any specific reason for not making the new method public? Afaik, there's still no built-in way to correctly handle quoting in third-party completers, and this should mostly solve that problem, right?

Nevertheless, big 👍 for creating the method in the first place, having to handle quoting separately for each completer is really annoying. :)

@MatejKafka I guess for now it should probably remain internal until it is finalised. I do agree it makes things a lot easier for managing quoting.

There were some concerns around escaping which should probably be addressed before making this public. I also think the method argument itself probably needs to be tweaked for public use. Not sure how I feel making users use Func<string, string> toolTipMapping or IEnumerable 😄. Could probably make a public overload which makes these easier to pass in and use more powershell friendly types.

Happy for you to raise an issue and we can discuss way forward.

@iSazonov @MartinGC94 thoughts?

@iSazonov
Copy link
Collaborator

iSazonov commented Feb 9, 2025

Happy for you to raise an issue and we can discuss way forward.

Right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verb, StrictModeVersion and Scope Argument completers don't handle single/double quotes for parameter text completion

4 participants