Closed l-inc closed 1 month ago
@l-inc try v1.65.5
"inputs": [
{
"id": "get-build-cfg",
"type": "command",
"command": "extension.commandvariable.remember",
"args": {
"key": "myprj-build-cfg",
"default": "myprj-default-cfg",
...
}
},
@rioj7, thanks a lot. This was incredibly quick and works as expected.
Is there a similar option for pickStringRemember
? That already has a default
but it means something different.
@gavinltomra, I think, you'd need to specify what exactly you mean with "a similar option". pickStringRemember
is meant to retrieve a value from the user, not from the remember store. In that sense, default
has an equivalent meaning: remember
returns default
if no value can be retrieved from the remember store, whereas pickStringRemember
returns default
if no value can be retrieved from the user.
You had that example in your original question. 😄
But I'm thinking in context of #98 where one of the options in the pick list is "remembered value" but there happens to be no such remembered value. We could just rely on the user to not choose that option, but it might be nice if there was a way to specify a default remembered value other than "I don't remember".
In my testing, pickStringRemember will return the default
if the user presses ESC when prompted, but if they select the "last used" option with a ${remember:x} value with no memory it will return the literal "I don't remember" and not the default
.
I would actually like it to abort if the user presses ESC (which is what happens when no default
is specified) and yet still have a specific value supplied when there's no memory yet.
Ok, I found the syntax, it was just in a different place.
This works (though it's a bit verbose):
"options": {
{ "label": "Last used", "description": "${remember:my_key}", "value": "${remember:my_key}" },
...
},
"key": "my_key",
"rememberTransformed": true,
"remember": {
"my_key": { "key": "my_key", "default": "my-default-value" },
},
@gavinltomra if the user picks Last used
it is an option created by the user, not part of the semantic of the pickStringRemember
command. so the command has to return something other than the default
property.
I see that you have found the way to specify the remember default by using the remember
command as a variable.
I could implement that the ${remember}
variable accepts multiple arguments it would be almost as much verbose as it is now, only the location is a bit closer to the use but than you have to duplicate the ${remember}
variable with arguments because you use it twice and that makes it very verbose.
@gavinltomra, yes, you can create a separate option "Last used". But you can also use addLabelToTop
instead. You can configure it to retrieve a value from the remember store as follows:
"addLabelToTop": "${remember:my-default-option-label}",
"remember": {
"my-default-option-label": {
"key": "my-option-label",
"default": "my-option-value-2-label"
}
},
"options": [
{
"label": "my-option-value-1-label",
"value": {
"my-option-value": "my-option-value-1",
"my-option-label": "my-option-value-1-label"
}
},
{
"label": "my-option-value-2-label",
"value": {
"my-option-value": "my-option-value-2",
"my-option-label": "my-option-value-2-label"
}
},
{
"label": "my-option-value-3-label",
"value": {
"my-option-value": "my-option-value-3",
"my-option-label": "my-option-value-3-label"
}
},
]
This is however even more verbose as you'd have to store the labels for each of the options.
I'd like to be able to set a build configuration independently from running a build command. To achieve that, I create 2 separate "inputs":
This way, I can use
${input:get-build-cfg}
in build tasks without confirming the configuration of the build every time. Now, if the configuration task that invokes${input:sel-build-cfg}
is never executed,${input:get-build-cfg}
returnsI don't remember
. I'm wondering if there's a way to specify the value returned by remember if there's nothing in the storage for the given key yet?As a matter of a workaround, I currently add the following to the args of
get-build-cfg
:But
I don't remember
is not even documented as a default return value of remember. Is there a nicer way to specify a default?