Skip to content

Add task provider for R extension - #1445

Merged
juliasilge merged 4 commits into
mainfrom
r-pkg-check-task
Oct 3, 2023
Merged

juliasilge merged 4 commits into
mainfrom
r-pkg-check-task

Conversation

@juliasilge

Copy link
Copy Markdown
Member

Addresses #1303

Currently I'm just adding package check as a task, but this will be extensible for other tasks.


export async function setContexts(_context: vscode.ExtensionContext): Promise<void> {
const isRPackage = await detectRPackage();
vscode.commands.executeCommand('setContext', 'isRPackage', isRPackage);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Only one context for now, but we need it in multiple places and we can make more in the future.

packageTask.name,
'R',
new vscode.ShellExecution(packageTask.shellExecution),
[]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is where problem matchers go. It's empty now, but we could do a lot of nice stuff with it.

Comment thread extensions/positron-r/src/tasks.ts Outdated
// For now, there will be only one running R runtime:
const runtimePath = runningRuntimes[0].runtimePath;
const allPackageTasks: PackageTask[] = [
{ 'name': 'Check R package', 'shellExecution': `${runtimePath}/R -e "devtools::check()"` }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can add more package tasks here in this array moving forward.

@juliasilge

Copy link
Copy Markdown
Member Author

This PR registers a task provider for the R extension that only provides one single task for now, but I tried to set it up to not be too hard to add more. I definitely think we'll add testing too.

The existing 'r.packageCheck' command and keybinding now executes this task, rather than using the executeCode() API. You can get to this now two ways through the command palette:

  • directly as the command
  • via "Tasks: Run Tasks" as the task

Is that what we want to do? We could just keep it as a task only (with a keybinding) and remove the command.

@juliasilge
juliasilge marked this pull request as ready for review September 28, 2023 19:15

@jmcphers jmcphers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am somewhat concerned that it is too fragile to presume that R is online and running happily at the exact moment that VS Code invokes the task list method.

Since what we really need is the runtime path, I think it might be better to attach event handlers to the R runtimes as they are registered. The event handler can listen for start events and update a global variable that monitors the last-used runtime. Then your task provider can always register the relevant tasks regardless of what's going on with R at the moment.

Comment thread extensions/positron-r/src/tasks.ts Outdated
export async function getRPackageTasks(): Promise<vscode.Task[]> {
const runningRuntimes = await positron.runtime.getRunningRuntimes('r');
// For now, there will be only one running R runtime:
const runtimePath = runningRuntimes[0].runtimePath;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We need to handle the case where there are zero runtimes available (which is possible if R is crashed and hasn't been restarted, etc.). I

@juliasilge
juliasilge requested a review from jmcphers October 2, 2023 21:07

@jmcphers jmcphers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

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