command-variable icon indicating copy to clipboard operation
command-variable copied to clipboard

[question/new feature] remember the lable of the last picked item

Open KUGA2 opened this issue 9 months ago • 4 comments

Hi,

I use this extension to select options for the conan install command. We select the build type:

        {
            "id": "buildType",
            "type": "command",
            "command": "extension.commandvariable.pickStringRemember",
            "args": {
                "key": "buildType",
                "description": "What build type to use",
                "options": [
                    {
                        "label": "Use previous value",
                        "description": "${remember:buildType}",
                        "value": "${remember:buildType}"
                    },
                    {
                        "label": "RelWithDebInfo",
                        "description": "Optimized build with debug symbols",
                        "value": "-s:h '&:build_type=RelWithDebInfo' -s:h build_type=Release"
                    },
                    {
                        "label": "Debug",
                        "description": "unoptimized build for debugging",
                        "value": "-s:h '&:build_type=Debug' -s:h build_type=Debug"
                    },
                    {
                        "label": "Release",
                        "description": "Optimized build",
                        "value": "-s:h '&:build_type=Release' -s:h build_type=Release"
                    },
                    {
                        "label": "BullseyeCoverage",
                        "description": "Build with coverage instrumentation",
                        "value": "-s:h '&:build_type=BullseyeCoverage' -s:h build_type=Release"
                    }
                ],
                "rememberTransformed": true
            }
        },

When picking again, the selection shows the value. This is a little bit confusing.

Image

I would like that the text shows "Use previous value RelWithDebInfo". Print the label instead of the value. Is this possible?

KUGA2 avatar Mar 06 '25 13:03 KUGA2

@KUGA2

You can store multiple keys when you pick an item. Just store the picked label string also. And use that as description in the Use previous value item.

{
  "id": "buildType",
  "type": "command",
  "command": "extension.commandvariable.pickStringRemember",
  "args": {
    "key": "buildType",
    "description": "What build type to use",
    "options": [
      {
        "label": "Use previous value",
        "description": "${remember:buildTypeLabel}",
        "value": "${remember:buildType}"
      },
      {
        "label": "RelWithDebInfo",
        "description": "Optimized build with debug symbols",
        "value": {"buildType": "-s:h '&:build_type=RelWithDebInfo' -s:h build_type=Release", "buildTypeLabel": "RelWithDebInfo"}
      },
      {
        "label": "Debug",
        "description": "unoptimized build for debugging",
        "value": {"buildType": "-s:h '&:build_type=Debug' -s:h build_type=Debug", "buildTypeLabel": "Debug"}
      },
      {
        "label": "Release",
        "description": "Optimized build",
        "value": {"buildType": "-s:h '&:build_type=Release' -s:h build_type=Release", "buildTypeLabel": "Release"}
      },
      {
        "label": "BullseyeCoverage",
        "description": "Build with coverage instrumentation",
        "value": {"buildType": "-s:h '&:build_type=BullseyeCoverage' -s:h build_type=Release", "buildTypeLabel": "BullseyeCoverage"}
      }
    ],
    "rememberTransformed": true
  }
},

Maybe you can rewrite the pick with a transform that inserts the variable items of the command from a pickStringRemember that saves multiple keys:

{
  "id": "buildType",
  "type": "command",
  "command": "extension.commandvariable.transform",
  "args": {
    "key": "buildType",
    "text": "-s:h '&:build_type=${pickStringRemember:buildType1}' -s:h build_type=${remember:buildType2}",
    "pickStringRemember": {
      "buildType1": {
        "key": "buildType1",
        "description": "What build type to use",
        "options": [
          {
            "label": "Use previous value",
            "description": "${remember:buildTypeLabel}",
            "value": "${remember:buildType1}"
          },
          {
            "label": "RelWithDebInfo",
            "description": "Optimized build with debug symbols",
            "value": {
              "buildType1": "RelWithDebInfo",
              "buildType2": "Release",
              "builldTypeLabel": "RelWithDebInfo"
            }
          },
          {
            "label": "Debug",
            "description": "unoptimized build for debugging",
            "value": {
              "buildType1": "Debug",
              "buildType2": "Debug",
              "buildTypeLabel": "Debug"
            }
          },
          {
            "label": "Release",
            "description": "Optimized build",
            "value": {
              "buildType1": "Release",
              "buildType2": "Release",
              "buildTypeLabel": "Release"
            }
          },
          {
            "label": "BullseyeCoverage",
            "description": "Build with coverage instrumentation",
            "value": {
              "buildType1": "BullseyeCoverage",
              "buildType2": "Release",
              "buildTypeLabel": "BullseyeCoverage"
            }
          }
        ]
      }
    }
  }
},

Maybe I can add a special variable that has the value of the label of the item.

rioj7 avatar Mar 07 '25 03:03 rioj7

Thank you for the support. I like the second version because it also gets rid of duplicated code :) Will try it asap.

KUGA2 avatar Mar 07 '25 08:03 KUGA2

Version1 works.

Version2 has some typeo (bui-l-ldTypeLabel) but after fixing it doesnt not work. Selection looks correct but the generated command has: -s:h '&:build_type=${remember:buildType1}' -s:h build_type=Release

Using "value": "${pickStringRemember:buildType1}" instead gives -s:h '&:build_type=Unknown' -s:h build_type=Release.

KUGA2 avatar Mar 07 '25 08:03 KUGA2

@KUGA2 I removed 1 line from Version 1 "rememberTransformed": true,. I thought it is not needed here.

    "key": "buildType1",
    "description": "What build type to use",
    "rememberTransformed": true,

rioj7 avatar Mar 07 '25 11:03 rioj7