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

WIP: Interactive R tasks #1267

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions R/interactiveTask.Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

text <- Sys.getenv("VSCODE_EVAL_CODE")

status <- 1
try({
eval(parse(text = text))
status <- 0
})

quit(save="no", status=status)
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import * as completions from './completions';
import * as rShare from './liveShare';
import * as httpgdViewer from './plotViewer';
import * as languageService from './languageService';
import { RTaskProvider } from './tasks';
import * as tasks from './tasks';


// global objects used in other files
Expand Down Expand Up @@ -214,8 +214,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
await rShare.initLiveShare(context);

// register task provider
const taskProvider = new RTaskProvider();
vscode.tasks.registerTaskProvider(taskProvider.type, taskProvider);
const taskProvider = new tasks.RTaskProvider();
vscode.tasks.registerTaskProvider(tasks.R_TASK_TYPE, taskProvider);

// deploy session watcher (if configured by user)
if (enableSessionWatcher) {
Expand Down
54 changes: 43 additions & 11 deletions src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';
import { getRpath } from './util';
import { extensionContext } from './extension';


const TYPE = 'R';
export const R_TASK_TYPE = 'R';


interface RTaskDefinition extends vscode.TaskDefinition {
type: string,
type: typeof R_TASK_TYPE,
code: string[],
options?: string[],
cwd?: string,
Expand Down Expand Up @@ -37,7 +39,7 @@ const defaultOptions: string[] = ['--no-echo', '--no-restore'];
const rtasks: RTaskInfo[] = [
{
definition: {
type: TYPE,
type: R_TASK_TYPE,
code: ['devtools::test()']
},
name: 'Test',
Expand All @@ -47,7 +49,7 @@ const rtasks: RTaskInfo[] = [

{
definition: {
type: TYPE,
type: R_TASK_TYPE,
code: ['devtools::build()']
},
name: 'Build',
Expand All @@ -57,7 +59,7 @@ const rtasks: RTaskInfo[] = [

{
definition: {
type: TYPE,
type: R_TASK_TYPE,
code: ['devtools::build(binary = TRUE, args = c(\'--preclean\'))']
},
name: 'Build Binary',
Expand All @@ -67,7 +69,7 @@ const rtasks: RTaskInfo[] = [

{
definition: {
type: TYPE,
type: R_TASK_TYPE,
code: ['devtools::check()']
},
name: 'Check',
Expand All @@ -77,7 +79,7 @@ const rtasks: RTaskInfo[] = [

{
definition: {
type: TYPE,
type: R_TASK_TYPE,
code: ['devtools::document()']
},
name: 'Document',
Expand All @@ -87,7 +89,7 @@ const rtasks: RTaskInfo[] = [

{
definition: {
type: TYPE,
type: R_TASK_TYPE,
code: ['devtools::install()']
},
name: 'Install',
Expand All @@ -96,7 +98,7 @@ const rtasks: RTaskInfo[] = [
}
];

function asRTask(rPath: string, folder: vscode.WorkspaceFolder | vscode.TaskScope, info: RTaskInfo): vscode.Task {
function asRTask0(rPath: string, folder: vscode.WorkspaceFolder | vscode.TaskScope, info: RTaskInfo): vscode.Task {
const args = makeRArgs(info.definition.options ?? defaultOptions, info.definition.code);
const rtask: vscode.Task = new vscode.Task(
info.definition,
Expand All @@ -118,9 +120,39 @@ function asRTask(rPath: string, folder: vscode.WorkspaceFolder | vscode.TaskScop
return rtask;
}

export class RTaskProvider implements vscode.TaskProvider {
function asRTask(rPath: string, folder: vscode.WorkspaceFolder | vscode.TaskScope, info: RTaskInfo): vscode.Task {
// const args = makeRArgs(info.definition.options ?? defaultOptions, info.definition.code);
const args = [
'--silent',
'--no-save',
'--no-restore',
];
const rProfile = extensionContext.asAbsolutePath('R/interactiveTask.Rprofile');
const rtask: vscode.Task = new vscode.Task(
info.definition,
folder,
info.name ?? 'Unnamed',
info.definition.type,
new vscode.ProcessExecution(
rPath,
args,
{
cwd: info.definition.cwd,
env: {
...info.definition.env,
R_PROFILE_USER: rProfile,
VSCODE_EVAL_CODE: info.definition.code.join('; ')
}
}
),
info.problemMatchers
);

rtask.group = info.group;
return rtask;
}

public type = TYPE;
export class RTaskProvider implements vscode.TaskProvider {

public async provideTasks(): Promise<vscode.Task[]> {
const folders = vscode.workspace.workspaceFolders;
Expand Down