vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

cmake.selectActiveFolder command does not work if there are multiple workspace folders with the same name

Open DragosMiloiuNXP opened this issue 1 year ago • 5 comments

Brief Issue Summary

Internally the cmake.selectActiveFolder command can receive the following parameter types:

  • CMakeProject - unfortunately the CMake Tools API only allows me to get a Project, not a CMakeProject instance, so I cannot use the API to distinguish between multiple projects with the same name.
  • the parameter can also be a list of strings, but these are the workspace folder names so it cannot differentiate between multiple folders with the same name.

Additional Information

Cmake Tools version v1.16.32

DragosMiloiuNXP avatar Jan 17 '24 10:01 DragosMiloiuNXP

@DragosMiloiuNXP To help us understand what you'd like to see be improved, could you please detail what you are using this for, how you are currently interacting with that command, and what you'd like to be improved?

We're also happy to take open source contributions if you have a specific idea for a change. Thanks!

gcampbell-msft avatar Jan 19 '24 16:01 gcampbell-msft

@gcampbell-msft, we are trying to execute CMake tasks programmatically. Our environment includes multiple workspace folders, each with their own tasks.json. Internally we are calling vscode.tasks.fetchTasks({type: 'cmake'}) and identify the correct task for our workspace folder by looking at its scope. Although we execute the correct task, CMake Tools calls CMake commands for the “active folder” and not for the workspace folder associated with the task. The only solution we found was to first change the active folder before executing the task. So it would be preferable for us to avoid calling the selectActiveFolder but we did not find a way to make sure the task is executed correctly.

Screenshot of the task execution without selectActiveFolder command. Task is correct, but the folder for which CMake is executed is incorrect. image

Looking in the CMake Tools code, for example in cmakeTaskProvider.ts:

private async runConfigTask(): Promise<any> {
        this.writeEmitter.fire(localize("config.started", "Config task started...") + endOfLine);
        const project: CMakeProject | undefined = this.getActiveProject();

, it seems the project is always the active one.

DragosMiloiuNXP avatar Jan 22 '24 10:01 DragosMiloiuNXP

@DragosMiloiuNXP I think I understand.

So, really, you're asking for two different types of possible fixes.

  1. If you still need to use cmake.selectActiveFolder, then either make it possible for API consumers to access to a CMakeProject to pass to this method, or define some other way to be able to distinguish between folders with the same name.
  2. OR, if you're interested in not using the cmake.selectActiveFolder at all, then make the task execution better at handling

One last question:

To clarify what you mean by this:

"Screenshot of the task execution without selectActiveFolder command. Task is correct, but the folder for which CMake is executed is incorrect."

You're saying that you were able to pick the right task to run, but it's running the task for the wrong folder, right? Does this end up meaning that the task is actually performing something you didn't want it to? For example, configuring a different project/folder then desired?

gcampbell-msft avatar Jan 31 '24 13:01 gcampbell-msft

@gcampbell-msft,

You're saying that you were able to pick the right task to run, but it's running the task for the wrong folder, right?

Yes. It does the correct operation (build or clean) but for the wrong workspace folder (not the one associated with the task).

DragosMiloiuNXP avatar Feb 01 '24 07:02 DragosMiloiuNXP

I'm running into same issue. Currently no additional option in tasks.json to specify which sources we wish to target.

TBRSTM avatar Jul 03 '24 10:07 TBRSTM