rioj7 / command-variable

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

ignore workspaceFolder error #78

Closed dvirtz closed 8 months ago

dvirtz commented 8 months ago

I have several multi-root projects that have one shared folder and one folder which is unique to each project, so

project-1:               project-2:               project-3:
|- folder a              |- folder a              |- folder a
|- folder b.1            |- folder b.2            |- folder b.3

etc. I want to have a task in the shared folder that gets the name of the unique folder so I apply a JavaScript expression that returns the first valid of ${workspaceFolder:b.1}, ${workspaceFolder:b.2}, ${workspaceFolder:b.3}, etc. This works but there's annoying Workspace not found with name notifications popping up.

Can you add an option to ignore those errors or can you think of a better way to achieve this?

rioj7 commented 8 months ago

@dvirtz try v1.61.1 and use

${workspaceFolder:b.1:nomsg}
${workspaceFolder:b.2:nomsg}
${workspaceFolder:b.3:nomsg}

I'm curious about the JavaScript expression that you use? Do you do it in the tasks.json file or in the script that is started by the task?

dvirtz commented 8 months ago

Thanks @rioj7, that works. The input variable I use is

{
  "id": "uniqueFolder",
  "type": "command",
  "command": "extension.commandvariable.config.expression",
  "args": {
    "configVariable": "editor.fontSize",
    "expression": "['${workspaceFolder:b.1:nomsg}', '${workspaceFolder:b.2:nomsg}', '${workspaceFolder:b.3:nomsg}'].find(folder => folder != 'Unknown')",
  }
}

in tasks.json. I hack config.expression for that. I couldn't find a better way to just run some JS expression with variable expansion.

rioj7 commented 8 months ago

@dvirtz Users always find creative application of features.

I will add this to the README as a possible use case of variables.

I will make the configVariable property optional.

rioj7 commented 7 months ago

@dvirtz in v1.61.2 configVariable property is optional