-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
variable substitution in tasks.json #43782
Comments
@bobbrow I am not sure I understand you correctly. The two other ways are reading a setting maintained by VS Code |
Other ideas we're considering:
|
Alternatively have you considered to provide a task provider that adds a task programmatically to the system instead of having it in the tasks.json. Then you have the full control over how the command is constructed and there is no need to resolve variables on task execution time. |
We don't know what the task will be or how the requested variable would be used, so I don't think that we can "provide" the tasks. If using the TaskProvider stuff, I would need a callback to resolve the variables the user puts in their tasks. We could then whitelist a variable (e.g. Based on what I see in #33523, it doesn't appear that the TaskProvider API was designed to do variable substitution. Perhaps maybe I can request that VSCode allow extensions to register VariableResolvers. I think that would address the issue sufficiently. VSCode could use its default resolver for variables, but if it doesn't find a match, then it could query a backup resolver registered by the extension. |
The resolveTask hook is meant for something different. It is basically a performance optimization to not load a task provider if a task is customized in the tasks.json. But we could have another hook that is called on What exactly do you want to achieve. Having a |
|
@bobbrow can you provide me with a couple of examples. I am still not fully getting how the various configurations should go together. It sounds a little like half of a task should be specified in task land and the other half somewhere else. |
In the cpptools extension, we have a concept of "configurations" which define compiler settings that we use for IntelliSense. A developer can create multiple configs to change how IntelliSense works on a given subset of code in the workspace. The developer might name these configs to align with how their build system works. For example, CMake's
Since "foo" is the active config, "foo" should be substituted in for They might also have a launch.json following a similar strategy and they want to launch the executable for the code they are currently working on. It would be nice if our extension could register a backup VariableResolver that can handle variables that VSCode is unable to resolve. |
@bobbrow thanks for the example Instead of having a plugable resolver service I would rather pass the task to the extension again to allow either tweaking some of the properties or to fully control the execution. This at the end opens up more use cases. |
Hi. I have the WSL using Ubuntu and want to use gdb installed on WSL through the VSC. The problem is if i want to use relative paths, the VSC is not converting an passing right to gdb inside WSL. My setup:
It says Unexpected GDB output from command "-environment-cd" The ${workspaceFolder} variable is always converting to Win32 type path. This is correct since I'm in Windows. |
If we get this feature, then we could potentially define an extension-specific variable that would do what you are asking. |
I have an additional usage example here, something like what is discussed here. We work under Linux developing the same software for multiple embedded architectures. So we have multiple configuration since there are multiple toolchains. We use multiple CMake configurations and create a build directory for each configuration e.g: ${workspaceFolder}/build/${currentActiveCppConfiguration}. The build command (make, ninja) then has to be issued in this directory and the vscode build task should adjust the path corresponding to the current selected build configuration in vscode. Something like this:
It would really be a big step forward if we could do this. Thanks for working on it |
Sorry for asking again. Is there any update on this? |
No work has started on this. How do you pick your active build configuration? May be you could write an extension that shows a picker and stores the active build configuration in a setting which you can then refer to from ${config:....} |
Another example/question,
Bottom line, I'm trying to avoid asking the user to add anything to the configuration files and I want to completely manage the build process. |
I think you can get what you want with command variable substitution. Your extension would define a command, then you can execute the command as part of your task as described here: https://code.visualstudio.com/docs/editor/variables-reference#_settings-command-variables-and-input-variables. Please comment here if this doesn't solve your use-case. |
I'm sorry, I don't understand how that can help us. The extension cannot define the command because we don't know what "task" the user wants to execute. Or are you saying that a command can return a string that we can feed into the args? (e.g. |
I may have misunderstood then. I was saying that a command can return a string that you can feed into the args. Does that help? |
The C++ extension has some users who would like access to some information that the extension is currently holding private. Based on the tasks documentation the only way I see to export that information in a way that a task could use it is to add a configuration setting to our package.json.
The trouble is that we don't want our users to be able to modify the setting value. Is there a way to make some settings read-only? Or is there perhaps another way that we can expose information for tasks to consume?
The text was updated successfully, but these errors were encountered: