Skip to content
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

Expand targets names while searching for matching build task #3009

Merged

Conversation

piomis
Copy link
Contributor

@piomis piomis commented Feb 7, 2023

This change fixes #2970

@piomis
Copy link
Contributor Author

piomis commented Feb 7, 2023

@elahehrashedi as requested I tried implementing expansion capability while searching for matching task.


let taskTargets: string[];
if (cmakeDriver) {
taskTargets = await expand.expandStrings(task.definition.targets, cmakeDriver.expansionOptions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function findBuildTask is being called from the CMkae Driver, it's better if we pass the expansion options as the input to findBuildTask, instead of fetching the active project and getting the driver instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
FYI - i defined expansionOptions as optional parameter (and code checks if it was passed before calling expandString) - just in case when expansion is not required at all.

@elahehrashedi
Copy link
Contributor

@piomis thank you for your contribution. I tested the branch and it seems to be working. Please apply the changes to simplify the code.

let taskTargets: string[];
if (expansionOptions) {
taskTargets = await expand.expandStrings(task.definition.targets, expansionOptions);
if (task.definition.options?.cwd){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added cwd to be expanded too

@@ -237,12 +250,12 @@ export class CMakeTaskProvider implements vscode.TaskProvider {
} else {
// Search for the matching default task.
const defaultTask: CMakeTask[] = matchingTargetTasks.filter(task => task.isDefault);
if (defaultTask.length === 1) {
if (defaultTask.length >= 1) {
return defaultTask[0];
} else {
// Search for the matching existing task.
const existingTask: CMakeTask[] = matchingTargetTasks.filter(task => !task.isTemplate);
Copy link
Contributor

@elahehrashedi elahehrashedi Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a task.isTemplate in tasks after you fetch tasks using vscode.tasks.fetchTasks. You have to distinguish between the tasks that are fetched from the tasks.json file and the tasks that the task provider provides as a template by setting this value to true/false.

Copy link
Contributor Author

@piomis piomis Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elahehrashedi
Yes. I mentioned this problem already.
#2936 (comment)
#2780 (comment)
But it was like that in your refactor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INstead of using vscode.tasks.fetchTasks we can write our own function to read the tasks in tasks.json to fetch the existing tasks, and use the function provideTasks to get the template tasks.
Here is a sample:

https://github.com/microsoft/vscode-cpptools/blob/a014fe80bdc03b4a9fa3b877866a11d13034f631/Extension/src/LanguageServer/cppBuildTaskProvider.ts#L218

If you need help implementing this let me know and I will modify your branch.

Copy link
Contributor Author

@piomis piomis Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elahehrashedi
I'm not sure if manual parsing of Json is good solution (honestly speaking I am not convinced that ad hoc task creation is good solution either).
First of all this will be very fragile in regards to format of Json.
Like I rised in comments - you have added isTemplate property previously but your code never sets it to true. If you point me what place was intended to have set then I will add it.

By the way I found one comment from maintainers of VS code which suggests not to use ad hock tasks (microsoft/vscode#59337 (comment)) maybe an Original proposal with 'target' retrieval during task execution (instead of having target set by default when task is created). Potentially this could also allownto use 'shell' task type.

By the way I have just discovered that ProblemMatchers stopped working. And this is also related to fact that it is not possible to programicaly define non standard problem matcher in Task constructor.

elahehrashedi
elahehrashedi previously approved these changes Mar 16, 2023
@elahehrashedi
Copy link
Contributor

@bobbrow this can be checked in.

@bobbrow
Copy link
Member

bobbrow commented Mar 16, 2023

@bobbrow this can be checked in.

return matchingTargetTasks[matchingTargetTasks.length];

Should it be length - 1? Arrays are 0-indexed, so I would expect this to be out of bounds.

@bobbrow bobbrow enabled auto-merge (squash) March 16, 2023 21:00
@bobbrow bobbrow merged commit 7d2e207 into microsoft:main Mar 16, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The tasks' targets are not resolved when "cmake.buildTask" is used
3 participants