Skip to content

Commit

Permalink
WIP: Add problemMatching to task (#989)
Browse files Browse the repository at this point in the history
* initial attempt

* removed dummy task

* cleaning up dummy changes

* Use RTaskProvider

* Update code

Co-authored-by: Kun Ren <renkun@outlook.com>
  • Loading branch information
gowerc and renkun-ken authored Feb 13, 2022
1 parent 5f7b9e8 commit 9b525aa
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 22 deletions.
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,27 @@
{
"type": "R"
}
],
"problemMatchers": [
{
"name": "testthat",
"owner": "R",
"severity": "error",
"fileLocation": ["relative", "${workspaceFolder}/tests/testthat"],
"pattern": [
{
"regexp": "^(Failure|Error)\\s\\((.*\\.[Rr]):(\\d+):(\\d+)\\):\\s(.*)",
"file": 2,
"line": 3,
"column": 4,
"message": 5
},
{
"regexp": "^(.*)$",
"message": 1
}
]
}
]
},
"scripts": {
Expand Down
25 changes: 3 additions & 22 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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';


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

// register task provider
const type = 'R';
vscode.tasks.registerTaskProvider(type, {
provideTasks() {
// `vscode.ShellQuoting.Strong` will treat the "value" as pure string and quote them based on the shell used
// this can ensure it works for different shells, e.g., zsh, PowerShell or cmd
return [
new vscode.Task({ type: type }, vscode.TaskScope.Workspace, 'Build', 'R',
new vscode.ShellExecution('Rscript', ['-e', {value: 'devtools::build()', quoting: vscode.ShellQuoting.Strong}])),
new vscode.Task({ type: type }, vscode.TaskScope.Workspace, 'Check', 'R',
new vscode.ShellExecution('Rscript', ['-e', {value: 'devtools::check()', quoting: vscode.ShellQuoting.Strong}])),
new vscode.Task({ type: type }, vscode.TaskScope.Workspace, 'Document', 'R',
new vscode.ShellExecution('Rscript', ['-e', {value: 'devtools::document()', quoting: vscode.ShellQuoting.Strong}])),
new vscode.Task({ type: type }, vscode.TaskScope.Workspace, 'Install', 'R',
new vscode.ShellExecution('Rscript', ['-e', {value: 'devtools::install()', quoting: vscode.ShellQuoting.Strong}])),
new vscode.Task({ type: type }, vscode.TaskScope.Workspace, 'Test', 'R',
new vscode.ShellExecution('Rscript', ['-e', {value: 'devtools::test()', quoting: vscode.ShellQuoting.Strong}]))
];
},
resolveTask(task: vscode.Task) {
return task;
}
});
const taskProvider = new RTaskProvider();
vscode.tasks.registerTaskProvider(taskProvider.type, taskProvider);

// deploy session watcher (if configured by user)
if (enableSessionWatcher) {
Expand Down
107 changes: 107 additions & 0 deletions src/tasks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
'use strict';

import * as vscode from 'vscode';

export class RTaskProvider implements vscode.TaskProvider {
public readonly type = 'R';

// `vscode.ShellQuoting.Strong` will treat the "value" as pure string
// and quote them based on the shell used this can ensure it works for
// different shells, e.g., zsh, PowerShell or cmd
private readonly tasks = [

new vscode.Task(
{ type: this.type },
vscode.TaskScope.Workspace,
'Build',
'R',
new vscode.ShellExecution(
'Rscript',
[
'-e',
{
value: 'devtools::build()',
quoting: vscode.ShellQuoting.Strong
}
]
)
),

new vscode.Task(
{ type: this.type },
vscode.TaskScope.Workspace,
'Check',
'R',
new vscode.ShellExecution(
'Rscript',
[
'-e',
{
value: 'devtools::check()',
quoting: vscode.ShellQuoting.Strong
}
]
)
),

new vscode.Task(
{ type: this.type },
vscode.TaskScope.Workspace,
'Document',
'R',
new vscode.ShellExecution(
'Rscript',
[
'-e',
{
value: 'devtools::document()',
quoting: vscode.ShellQuoting.Strong
}
]
)
),

new vscode.Task(
{ type: this.type },
vscode.TaskScope.Workspace,
'Install',
'R',
new vscode.ShellExecution(
'Rscript',
[
'-e',
{
value: 'devtools::install()',
quoting: vscode.ShellQuoting.Strong
}
]
)
),

new vscode.Task(
{ type: this.type },
vscode.TaskScope.Workspace,
'Test',
'R',
new vscode.ShellExecution(
'Rscript',
[
'-e',
{
value: 'devtools::test()',
quoting: vscode.ShellQuoting.Strong
}
]
),
'$testthat'
)
];

public provideTasks(): vscode.Task[] {
return this.tasks;
}

public resolveTask(task: vscode.Task): vscode.Task {
return task;
}
}

0 comments on commit 9b525aa

Please sign in to comment.