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: Add problemMatching to task #989

Merged
merged 5 commits into from
Feb 13, 2022
Merged
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
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;
}
}