-
Notifications
You must be signed in to change notification settings - Fork 138
Fix resolveTask #994
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
Merged
Merged
Fix resolveTask #994
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7baa798
Fix resolveTask
renkun-ken 4a509b2
Update task definition
renkun-ken 8384f3a
Use ProcessExecution instead
renkun-ken f2f7636
Merge remote-tracking branch 'fork/fix-tasks2' into fix-tasks
renkun-ken 4d4db4f
Remove comment
renkun-ken 0894101
add in groups
gowerc abbed41
added conditional tasks
gowerc 6591933
added multi-workspace support; allowed r code execution
gowerc 9968560
fixed minor bug
gowerc 94307dd
fixed 'install' being classed as a test
gowerc 287f5cd
renamed variable
gowerc e8c6217
convert to use -e
gowerc 316b6b2
added dynamic terminal + terminal args
gowerc f6315ed
Refine code
renkun-ken b14e301
Merge pull request #3 from gowerc/fix-tasks
renkun-ken 2438b1c
No need to specify options
renkun-ken 9c38acb
Refine description
renkun-ken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,107 +1,146 @@ | ||
| 'use strict'; | ||
|
|
||
| import * as vscode from 'vscode'; | ||
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
| import { getRpath } from './util'; | ||
|
|
||
| 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 = [ | ||
| const TYPE = 'R'; | ||
|
|
||
| new vscode.Task( | ||
| { type: this.type }, | ||
| vscode.TaskScope.Workspace, | ||
| 'Build', | ||
| 'R', | ||
| new vscode.ShellExecution( | ||
| 'Rscript', | ||
| [ | ||
| '-e', | ||
| { | ||
| value: 'devtools::build()', | ||
| quoting: vscode.ShellQuoting.Strong | ||
| } | ||
| ] | ||
| ) | ||
| ), | ||
| interface RTaskDefinition extends vscode.TaskDefinition { | ||
| type: string, | ||
| code: string[], | ||
| options?: string[], | ||
| cwd?: string, | ||
| env?: { [key: string]: string } | ||
| } | ||
|
|
||
| new vscode.Task( | ||
| { type: this.type }, | ||
| vscode.TaskScope.Workspace, | ||
| 'Check', | ||
| 'R', | ||
| new vscode.ShellExecution( | ||
| 'Rscript', | ||
| [ | ||
| '-e', | ||
| { | ||
| value: 'devtools::check()', | ||
| quoting: vscode.ShellQuoting.Strong | ||
| } | ||
| ] | ||
| ) | ||
| ), | ||
| interface RTaskInfo { | ||
| definition: RTaskDefinition, | ||
| problemMatchers?: string | string[], | ||
| name?: string, | ||
| group?: vscode.TaskGroup | ||
| } | ||
|
|
||
| new vscode.Task( | ||
| { type: this.type }, | ||
| vscode.TaskScope.Workspace, | ||
| 'Document', | ||
| 'R', | ||
| new vscode.ShellExecution( | ||
| 'Rscript', | ||
| [ | ||
| '-e', | ||
| { | ||
| value: 'devtools::document()', | ||
| quoting: vscode.ShellQuoting.Strong | ||
| } | ||
| ] | ||
| ) | ||
| ), | ||
| function makeRArgs(options: string[], code: string[]) { | ||
| const codeArgs: string[] = []; | ||
| for (const line of code) { | ||
| codeArgs.push('-e'); | ||
| codeArgs.push(line); | ||
| } | ||
| const args = options.concat(codeArgs); | ||
| return args; | ||
| } | ||
|
|
||
| const defaultOptions: string[] = ['--no-echo', '--no-restore']; | ||
| const rtasks: RTaskInfo[] = [ | ||
| { | ||
| definition: { | ||
| type: TYPE, | ||
| code: ['devtools::test()'] | ||
| }, | ||
| name: 'Test', | ||
| group: vscode.TaskGroup.Test, | ||
| problemMatchers: '$testthat' | ||
| }, | ||
|
|
||
| { | ||
| definition: { | ||
| type: TYPE, | ||
| code: ['devtools::build()'] | ||
| }, | ||
| name: 'Build', | ||
| group: vscode.TaskGroup.Build, | ||
| problemMatchers: [] | ||
| }, | ||
|
|
||
| { | ||
| definition: { | ||
| type: TYPE, | ||
| code: ['devtools::check()'] | ||
| }, | ||
| name: 'Check', | ||
| group: vscode.TaskGroup.Test, | ||
| problemMatchers: [] | ||
| }, | ||
|
|
||
| { | ||
| definition: { | ||
| type: TYPE, | ||
| code: ['devtools::document()'] | ||
| }, | ||
| name: 'Document', | ||
| group: vscode.TaskGroup.Build, | ||
| problemMatchers: [] | ||
| }, | ||
|
|
||
| { | ||
| definition: { | ||
| type: TYPE, | ||
| code: ['devtools::install()'] | ||
| }, | ||
| name: 'Install', | ||
| group: vscode.TaskGroup.Build, | ||
| problemMatchers: [] | ||
| } | ||
| ]; | ||
|
|
||
| new vscode.Task( | ||
| { type: this.type }, | ||
| vscode.TaskScope.Workspace, | ||
| 'Install', | ||
| 'R', | ||
| new vscode.ShellExecution( | ||
| 'Rscript', | ||
| [ | ||
| '-e', | ||
| { | ||
| value: 'devtools::install()', | ||
| quoting: vscode.ShellQuoting.Strong | ||
| } | ||
| ] | ||
| ) | ||
| function asRTask(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, | ||
| folder, | ||
| info.name, | ||
| info.definition.type, | ||
| new vscode.ProcessExecution( | ||
| rPath, | ||
| args, | ||
| { | ||
| cwd: info.definition.cwd, | ||
| env: info.definition.env | ||
| } | ||
| ), | ||
| info.problemMatchers | ||
| ); | ||
|
|
||
| rtask.group = info.group; | ||
| return rtask; | ||
| } | ||
|
|
||
| new vscode.Task( | ||
| { type: this.type }, | ||
| vscode.TaskScope.Workspace, | ||
| 'Test', | ||
| 'R', | ||
| new vscode.ShellExecution( | ||
| 'Rscript', | ||
| [ | ||
| '-e', | ||
| { | ||
| value: 'devtools::test()', | ||
| quoting: vscode.ShellQuoting.Strong | ||
| } | ||
| ] | ||
| ), | ||
| '$testthat' | ||
| ) | ||
| ]; | ||
| export class RTaskProvider implements vscode.TaskProvider { | ||
|
|
||
| public type = TYPE; | ||
|
|
||
| public provideTasks(): vscode.Task[] { | ||
| return this.tasks; | ||
| public async provideTasks(): Promise<vscode.Task[]> { | ||
| const folders = vscode.workspace.workspaceFolders; | ||
|
|
||
| if (!folders) { | ||
| return []; | ||
| } | ||
|
|
||
| const tasks: vscode.Task[] = []; | ||
| const rPath = await getRpath(false); | ||
|
|
||
| for (const folder of folders) { | ||
| const isRPackage = fs.existsSync(path.join(folder.uri.fsPath, 'DESCRIPTION')); | ||
| if (isRPackage) { | ||
| for (const rtask of rtasks) { | ||
| const task = asRTask(rPath, folder, rtask); | ||
| tasks.push(task); | ||
| } | ||
| } | ||
| } | ||
| return tasks; | ||
| } | ||
|
|
||
| public resolveTask(task: vscode.Task): vscode.Task { | ||
| return task; | ||
| public async resolveTask(task: vscode.Task): Promise<vscode.Task> { | ||
| const taskInfo: RTaskInfo = { | ||
| definition: <RTaskDefinition>task.definition, | ||
| group: task.group, | ||
| name: task.name | ||
| }; | ||
| const rPath = await getRpath(false); | ||
| return asRTask(rPath, vscode.TaskScope.Workspace, taskInfo); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More for my own knowledge sorry but what is
vscode.TaskDefinition. I can't seem to find any details about what this interface actually is in the api documentation :(There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just my personal opinion/experience: Last time I tried (~1 year ago), the task api was quite confusing to work with and not really flexible. I tried implementing the typical build/test tasks with the possibility to supply optional arguments to e.g.
devtools::install(), but this was not supported by the task API. Instead, the extension had to explicitly register all possible combinations of arguments, which is not feasible. Apparently, the idea is to scan a list of tasks specified elsewhere, e.g. package.json, and parse them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TaskDefinition is basically the schema of tasks user could specify in
tasks.jsonfor that particular task type, in our case,R.Previously, our
resolveTaskdoes not really resolve the task.