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

Support bazel tasks from tasks.json #346

Merged

Conversation

vogelsgesang
Copy link
Collaborator

@vogelsgesang vogelsgesang commented Feb 27, 2024

User-facing changes

This commit fixes two user-facing bugs:

  • The "Run Task" command provides a list of recently used tasks. This list also contains the build/test tasks started from the "Bazel Build Targets" tree view. However, trying to rerun any of those tasks resulted in an error message.
  • The extension already contributed a taskDefinition for bazel tasks. However, trying to actually define such a task in the tasks.json resulted in the same error message.

In both cases, the user was presented with the error message

There is no task provider registered for tasks of type "bazel"

This commit fixes the issue, such that rerunning tasks from the history and configuring tasks through tasks.json now works properly.

Furthermore, the taskDefinition inside the package.json was improved:

  • It now lists the available command options, such that we have auto-completion within the tasks.json editor.
  • It properly constraints the targets entries to be string-typed.
  • It exposes the options argument which allows to specify additional command line parameters.

Code changes

Fixing the issue mainly required registering a TaskProvider for bazel tasks. The TaskProvider currently does not auto-detect the available tasks, but only implements resolveTask.

The notifications in onTaskProcessEnd had to be refactored: So far, the BazelTaskInfo was attached right during task creation. However, this didn't work for the new resolveTask. resolveTask apparently isn't allowed to change a task's definition. To make notifications work, the BazelTaskInfo is now attached in the onTaskStart callback.

Many of the fields of the BazelTaskInfo were unused. This commit removes commandOptions, processId, exitCode all of which were stored but never read. Doing so, it turned out that the onTaskProcessStart was no longer necessary.

Lastly, the callbacks used for task notifications were moved from extension.ts to bazel_task_info.ts and activation of all task-related functionality was centralized in the activateTaskProvider function

BEGIN_COMMIT_OVERRIDE
feat: Support bazel tasks from tasks.json (#346)
END_COMMIT_OVERRIDE

User-facing changes
-------------------

This commit fixes two user-facing bugs:
* The "Run Task" command provides a list of recently used tasks. This
  list also contains the build/test tasks started from the "Bazel Build
  Targets" tree view. However, trying to rerun any of those tasks
  resulted in an error message.
* The extension already contributed a `taskDefinition` for bazel tasks.
  However, trying to actually define such a task in the `tasks.json`
  resulted in the same error message.

In both cases, the user was presented with the error message

> There is no task provider registered for tasks of type "bazel"

This commit fixes the issue, such that rerunning tasks from the history
and configuring tasks through `tasks.json` now works properly.

Furthermore, the `taskDefinition` inside the `package.json` was improved:
* It now lists the available `command` options, such that we have
  auto-completion within the `tasks.json` editor.
* It properly constraints the `targets` entries to be string-typed.
* It exposes the `options` argument which allows to specify additional
  command line parameters.

Code changes
------------

Fixing the issue mainly required registering a `TaskProvider` for
`bazel` tasks. The `TaskProvider` currently does not auto-detect the
available tasks, but only implements `resolveTask`.

The notifications in `onTaskProcessEnd` had to be refactored: So far,
the `BazelTaskInfo` was attached right during task creation. However,
this didn't work for the new `resolveTask`. `resolveTask` apparently
isn't allowed to change a task's definition. To make notifications work,
the `BazelTaskInfo` is now attached in the `onTaskStart` callback.

Many of the fields of the `BazelTaskInfo` were unused. This commit
removes `commandOptions`, `processId`, `exitCode` all of which were
stored but never read. Doing so, it turned out that the
`onTaskProcessStart` was no longer necessary.

Lastly, the callbacks used for task notifications were moved from
`extension.ts` to `bazel_task_info.ts` and activation of all
task-related functionality was centralized in the `activateTaskProvider`
function
@vogelsgesang vogelsgesang force-pushed the avogelsgesang-bazel-tasks branch from 77c922a to 7397c0c Compare March 1, 2024 01:49
Copy link
Collaborator

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

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

Thanks!

@jfirebaugh jfirebaugh merged commit f2426e4 into bazel-contrib:master Mar 1, 2024
4 checks passed
@vogelsgesang vogelsgesang deleted the avogelsgesang-bazel-tasks branch March 26, 2024 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants