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

pickStringRemember with option labels from configExpression.

Open terryaney opened this issue 2 years ago • 5 comments

I've failed to figure out how to do this.

My settings.json:

{
	"tasks.projectFile": "${workspaceFolder}\\Nexgen.csproj",
}

My inputs (I've tried several variations, but this is what looks most right to me):

{
	"id": "projectFilePath",
	"type": "command",
	"command": "extension.commandvariable.config.expression",
	"args":{
		"configVariable": "tasks.projectFile"
	}
},
{
	"id": "projectFile",
	"type": "command",
	"command": "extension.commandvariable.pickStringRemember",
	"args":{
		"description": "Which project do you want to use?",
		"options": [ 
			{ "label": "${configExpression:projectFilePath}", "value": "${configExpression:projectFilePath}" }
		]
	}
}

I seem to always get 'Unknown' displayed as the pick string option. Is this possible? Thanks in advance.

terryaney avatar Sep 29 '23 20:09 terryaney

@terryaney You have to put the arguments of the ${configExpression:projectFilePath} in the arguments of the parent command, (the extension has no knowledge of where the args object is defined)

{
  "id": "projectFile",
  "type": "command",
  "command": "extension.commandvariable.pickStringRemember",
  "args":{
    "description": "Which project do you want to use?",
    "options": [ 
      { "label": "${configExpression:projectFilePath}", "value": "${configExpression:projectFilePath}" }
    ],
    "configExpression": {
      "projectFilePath": {
        "configVariable": "tasks.projectFile"
      }
    }
  }
}

rioj7 avatar Oct 02 '23 12:10 rioj7

@rioj7 Thanks for the reply and sorry for the delay. I've tested with this setup.

settings.json

{
	"tasks.projectFile": "${workspaceFolder}\\Api\\src\\Camelot.Api.WebService.Proxy.csproj",
	"tasks.contractsProjectFile": "${workspaceFolder}\\Contracts\\src\\Camelot.Api.WebService.Proxy.Contracts.csproj"
}

tasks.json Redacted what I thought was not worth displaying...

{
    "version": "2.0.0",
	"inputs": [
		{
			"id": "projectFileName",
			"type": "command",
			"command": "extension.commandvariable.pickStringRemember",
			"args":{
				"description": "Which project do you want to use?",
				"options": [ 
					{ "label": "Api", "value": "Api\\src\\Camelot.Api.WebService.Proxy.csproj" },
					{ "label": "${configExpression:contractsProjectFile}", "value": "Contracts\\src\\Camelot.Api.WebService.Proxy.Contracts.csproj" }
				],
				"configExpression": {
					"contractsProjectFile": { "configVariable": "tasks.contractsProjectFile" }
				}
			}
		}
	],
    "tasks": [
		{
			"label": "build Api WebService.Proxy",
			"command": "dotnet",
			"type": "process",
			"args": [
				"build", "${workspaceFolder}\\${input:projectFileName}",
				"/property:GenerateFullPaths=true",
				"/consoleloggerparameters:NoSummary"
			],
			"presentation": {
				"clear": true
			},
			"problemMatcher": "$msCompile"
		}
	]
}

And when I initiate the build Api WebService.Proxy task, this is what VS Code displays (note, in reality, I want the config variable substituted into the value but was just rendering it in label to see if I was doing it right, let me know if that is problem):

image

terryaney avatar Nov 15 '23 21:11 terryaney

@terryaney Made a few modifications in v1.59.0

I had no trouble to get the config setting, only the variable ${workspaceFolder} was not substituted.

Certain combinations of variables where resolved. I now apply variable substitution until the text does not change anymore.

To get a look behind the scene and see some debug log statements in the Help > Dev Tools > Console you can set the debug property for the ${configExpression} variable:

	"configExpression": {
		"contractsProjectFile": {
			"configVariable": "tasks.contractsProjectFile",
			"debug": true
		}
	}

Please show these log statements (paths anonymized) if you get the wrong result.

rioj7 avatar Nov 19 '23 13:11 rioj7

Sorry for delay. I'm on 1.61.2 and still doesn't seem to work. Debug console didn't seem to have much info, but maybe helpful to you.

[Extension Host] commandvariable.config.expression: debug logs enabled
console.ts:137 [Extension Host] commandvariable.config.expression: getConfigVariable: from: tasks.contractsProjectFile
console.ts:137 [Extension Host] commandvariable.config.expression: getConfigVariable: after variable substitution: tasks.contractsProjectFile
console.ts:137 [Extension Host] commandvariable.config.expression: debug logs enabled
console.ts:137 [Extension Host] commandvariable.config.expression: getConfigVariable: from: tasks.contractsProjectFile
console.ts:137 [Extension Host] commandvariable.config.expression: getConfigVariable: after variable substitution: tasks.contractsProjectFile

terryaney avatar Feb 13 '24 22:02 terryaney

@terryaney

After the line with getConfigVariable: after variable substitution: tasks.contractsProjectFile

It should show the content of the variable

https://github.com/rioj7/command-variable/blob/f14a11d92f642def1df98f09d12b310ddcca32a8/extension.js#L601-L602

that means content === undefined

Can you try to use a config variable like: xyz.zyx

It could be that tasks has special meaning in later VSC, I'm not using the latest, you can define tasks and launch in Multi Root workspace files.

If still you don't get the debug statements for value and result I will add extra debug statements to find out what the intermediate values are that are calculated after debug msg: after variable substitution

rioj7 avatar Feb 14 '24 21:02 rioj7