rioj7 / command-variable

Visual Studio Code extension for variable substitution via ${command:commandID}
51 stars 10 forks source link

remember command does not allow variable usage for the key #37

Closed tech-meppem closed 2 years ago

tech-meppem commented 2 years ago

I'm trying to make a simple convenience thing for a web project. Basically, we have it set up to have multiple project roots, for different pages in our web app. I want to make it so when we launch, it just goes to the page based on what workspace files we're currently looking at.

It's simple to get what workspace we're looking at, as we can get it via the variable ${workspaceFolderBasename}, however, mapping that to the webpaths is proving troublesome. I thought I would just be able to make an object map, and use key in extension.commandvariable.remember, but that doesn't resolve variables such as ${workspaceFolderBasename}. It just tries to get the key literally as ${workspaceFolderBasename}. So if I set "store": { "${workspaceFolderBasename}": "path/to/file" }, it gets it, but that's not useful.

Here is a mockup launch.json, to sort of show what I'm trying to do:

{
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "(Served) Launch Chrome against localhost",
      "url": "http://localhost:8080/${input:webPath}",
      "webRoot": "${workspaceFolder:Build}",
      "sourceMaps": true,
      "trace": true,
      "runtimeArgs": [
        "--auto-open-devtools-for-tabs"
      ],
      "preLaunchTask": "npm-serve",
      "internalConsoleOptions": "neverOpen"
    }
  ],
  "inputs": [
    {
      "id": "webPath",
      "type": "command",
      "command": "extension.commandvariable.remember",
      "args": {
        "store": {
          "home-view": "/home.html",
          "about-view": "/about.html",
          "contact-view": "/contact-options.html",
          "help-view": "/path/to/help.html"
        },
        "key": "${workspaceFolderBasename}"
      }
    }
  ]
}

Is there a better way to do this?

rioj7 commented 2 years ago

A nice idea, I will make it possible that key string of remember can have variables.

In the mean time you can use FileAsKey.

Use the search strings like /home-view/

rioj7 commented 2 years ago

@tech-meppem You can try v1.41.0