-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Remove CompletionHelpers escape
parameter from CompletionRequiresQuotes
#25178
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
Remove CompletionHelpers escape
parameter from CompletionRequiresQuotes
#25178
Conversation
@@ -14,7 +14,7 @@ internal static class CompletionHelpers | |||
{ | |||
private static readonly SearchValues<char> s_defaultCharsToCheck = SearchValues.Create("$`"); | |||
|
|||
private static readonly SearchValues<char> s_escapeCharsToCheck = SearchValues.Create("$[]`"); | |||
private static readonly SearchValues<char> s_escapeGlobbingPathCharsToCheck = SearchValues.Create("$[]`"); |
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 wonder why do you name the chars "GlobbingPathChars"?
Interesting, is this used at all?
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.
So currently it is not used, but it is from the CompletionRequiresQuotes method. Most usage I see does not use it and keeps it false
.
Perhaps we just remove it if not used instead of refacoring? Or we just decide to escape all special characters without this extra flag.
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.
Could you please look history of the file, maybe it was used in past?
It would be nice to understand why it is in code.
If it is dead code we should remove it.
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.
@iSazonov So it seemed the original author wanted to be able to have the choice to escape globbed chars. To be honest I am not sure why it was ever flagged, there is no current code relying on it. But also making it the default could be done. Just not sure if it would introduce regression.
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 think for backwards compatibility and less risk of introducing regression, it seems fine to just rename this parameter to something more meaningful like in this PR. Currently escape
on its own does not explain much what it is doing.
But we can also completely remove it and just escape $
and backtick. We can reintroduce it later if it is needed again for [
and ]
. I agree right now it is dead code.
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 use WildcardPattern for filtering.
WildcardPattern uses brackets and backtick as special chars. So I'd expect we escape them for example for file paths but they escaped already so it is in another code path. So It is an open question.
Why should we escape $
? Comment says about variables but variables are processed with another method ContainsCharactersRequiringQuotes
. So it is an open question too.
@MartinGC94 Have you any thoughts?
I do not have a complete understanding of what needs to be escaped and whether this is always a general rule. Or since we are talking about a common method, the question is whether there can be completers for which we need to escape a different set of characters. I'd want to get a feedback from @MartinGC94. |
This reverts commit 1bd9919.
I agree that the current name is bad, though I'd remove "Path" from the new name as this is not exclusive to paths. However, I don't see much value in renaming a parameter that is unused. Why not just rename it when you start using it for the first time? Or remove it if there's no plans to use it? As for the code itself, it is flawed and I question its usefulness even if it was fixed. |
@MartinGC94 Thanks! A comment for the code says about paths and variables. I guess the code was used for file paths and variables many years ago. Later specific code was created for file paths and variables. Looking as CompletionRequiresQuotes is used (14 call sites) I see it is for arguments only. So questions are:
@ArmaanMcleod @MartinGC94 What do you think? |
@iSazonov I personally think if we have old code which is not used and doesn't provide much value, we should remove it and perhaps revisit how it is done.
I think we should check any char which causes problems for escaping single/double quotes. Like I understand the basic examples which need escaping:
I like how @MartinGC94 has done this with bad chars in https://github.com/MartinGC94/UsefulArgumentCompleters/blob/bd94bb0b5fadc92e95ea32f70b22eeb35ab4b0b7/Classes/CompletionHelper.psm1#L21-L46. I am wondering if we can use a similar list for this repo so we can at least reduce all the obvious bad cases which come up. I guess I'm just not sure how to expose all these bad cases.
I guess my understanding is that when you parse input for tokens you can get errors, so it was an easy way to check a string is not valid and requires quotes. It's hard to check if it's the right way or if there were suggested alternatives, a lot of the
|
@ArmaanMcleod Thanks for referencing the module! If it is possible to create a test (I mainly assume that we should scenarios where this can happen) for every checked char I believe we can accept the checks from @MartinGC94 module. The same for Parser checks. It is for follow PRs. As for removing old code, we can continue in the PR. |
This reverts commit e6ae71c.
escape
parameter to escapeGlobbingPathChars
escape
parameter from CompletionRequiresQuotes
@iSazonov Thanks. I have repurposed this PR to just remove the |
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 Do you have any interest in transferring the escaping capabilities of your module here in the form of several PRs? |
My module doesn't really do any escaping. It just adds quotes if needed just like the current code (though obviously I handle a few more special characters in my checks). Any new code for this should ideally also take escaping of globbing characters into account, and it sounds like @ArmaanMcleod is already working on that. |
I was referring to quoting, although escaping may also be necessary.
He's working on separating the shared code, which we can make public. This is very similar to how your module works. |
📣 Hey @ArmaanMcleod, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
PR Summary
Just minor refactor to removed unused
escape
parameter fromCompletionRequiresQuotes
method. Given this parameter was meant to be used for escaping globbing characters[
&]
which is not set totrue
anywhere in the code base, it makes sense to remove it to clean up the code and simplify how this method gets used.PR Context
This code came from Windows PowerShell 1bd9919 as dead and has not been used until now.
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).