GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Enable tab complete for '-Format' parameter of Get-Date by iSazonov · Pull Request #4835 · PowerShell/PowerShell Conversation
|
|
Should we use another attribute name just for the IntelliSense scenario? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
ValidateSet is a sealed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for thinking about the usability here - I agree we should do something here, just not like this.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// Useful if we need enable IntelliSense (TabComplete) but effectively disable validation | ||
| /// when a parameter can accept not only the listed values but also arbitrary. | ||
| /// Ex.: Get-Date -Format | ||
| /// </summary> |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This doesn't feel right to me - you shouldn't use a Validation attribute if you aren't validating.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This should be reverted.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// Unix format string | ||
| /// </summary> | ||
| [Parameter(ParameterSetName = "net")] | ||
| [ValidateSetAttribute("FileDate", "FileDateUniversal", "FileDateTime", "FileDateTimeUniversal", AllowAll=true)] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using an ArgumentCompleter attribute instead - it's a bit more cumbersome, but if this scenario makes sense (and I think it probably does), we can find some way to make it simpler.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Do you suggest enhance ArgumentCompleter to support [ArgumentCompleter("FileDate", "FileDateUniversal", "FileDateTime", "FileDateTimeUniversal")] ?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Just brainstorming here - but maybe a new attribute ArgumentCompletions that also implements IArgumentCompleter - this probably requires some additional code elsewhere, probably similar to the ValidateSet code for completion.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A new attribute requires a lot of code. It seems easiest to add a new constructor public ArgumentCompleterAttribute(params string[] completeStrings)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Introduce new ArgumentCompleter constructor. Invoke the constructor in NativeCommandArgumentCompletion()
| /// </summary> | ||
| [Parameter(ParameterSetName = "net")] | ||
| [ValidateSetAttribute("FileDate", "FileDateUniversal", "FileDateTime", "FileDateTimeUniversal", AllowAll=true)] | ||
| [ArgumentCompleter("FileDate", "FileDateUniversal", "FileDateTime", "FileDateTimeUniversal")] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is much better, but I think still a little weird, I still think it's worth considering adding a new attribute ArgumentCompletions. It seems like you could take your class StringArrayArgumentCompleter, rename it, make it an attribute, and either duplicate a little bit of logic around ValidateSet or ArgumentCompleter in the tab completion code.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is your only thought that ArgumentCompleter is a strange name and you want to rename it?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't rename ArgumentCompleter even if it is a strange name (which I suppose it is.)
It's a really minor thing, but to me, ArgumentCompleter implies some dynamic code to compute the completions, whereas ArgumentCompletions is static.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I have missed that for a long time - the ability to easily complete a set without limiting the parameter to the completions.
Is it a reasonable compromise that you have to go IArgumentCompleter if you want to provide rich CompletionResults, or should be enable this with ArgumentCompletions too?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done next iteration.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This attribute is used to specify an argument completions for a parameter of a cmdlet or function without force throw unlike ValidateSetAttribute.
91b98ab to
ceb9385
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Just a little cleanup and I think it looks good.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| { | ||
| if (wordToCompletePattern.IsMatch(str)) | ||
| { | ||
| yield return new CompletionResult(str, str, CompletionResultType.Text, str); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should this be CompletionResultType.ParameterValue? I think that's the only place the attribute will have any effect.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I agree.
Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| var argumentCompletionsAttribute = parameter.CompiledAttributes.OfType<ArgumentCompletionsAttribute>().FirstOrDefault(); | ||
| if (argumentCompletionsAttribute != null) | ||
| { | ||
| try |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You are calling internal code which doesn't throw, so the try/catch is unnecessary.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Metadata.ValidateNotNullFailure); | ||
| } | ||
|
|
||
| if (AllowAll == true) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This should be reverted.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// Useful if we need enable IntelliSense (TabComplete) but effectively disable validation | ||
| /// when a parameter can accept not only the listed values but also arbitrary. | ||
| /// Ex.: Get-Date -Format | ||
| /// </summary> |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This should be reverted.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| { | ||
| result.IgnoreCase = s_attrArgToBoolConverter.Target(s_attrArgToBoolConverter, argValue); | ||
| } | ||
| else if (argumentName.Equals("AllowAll", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This should be reverted.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Code changes are approved - but we should get a couple of tests for the new ArgumentCompletions attribute.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Ilya (@iSazonov) Can you please update the PR description? Looks like the design has changed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
411123c to
f86c15a
Compare
f86c15a to
306fdc6
Compare
There was an error while loading. Please reload this page.
|
Ilya (@iSazonov) The tests look good, thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| AfterAll { | ||
| #Remove-Module -ModuleInfo $testModule |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Did you forget to uncomment this?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes 😄 Today tests is passed. I wonder - I don't change a code.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Jason Shirk (@lzybkr) Thanks for great idea! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…n scenarios (PowerShell#4835) - Add 'ArgumentCompletionsAttribute' to support argument completion for parameters that cannot have a ValidateSetAttribute. - Use 'ArgumentCompletionsAttribute' for the '-Format' parameter of 'Get-Date' to enable useful argument compeltions.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.