Skip to content

Fix resolveTask#994

Merged
renkun-ken merged 17 commits intoREditorSupport:masterfrom
renkun-ken:fix-tasks
Feb 16, 2022
Merged

Fix resolveTask#994
renkun-ken merged 17 commits intoREditorSupport:masterfrom
renkun-ken:fix-tasks

Conversation

@renkun-ken
Copy link
Member

What problem did you solve?

Closes #991


import * as vscode from 'vscode';

interface RTaskDefinition extends vscode.TaskDefinition {
Copy link
Contributor

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 :(

Copy link
Member

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.

Copy link
Member Author

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.json for that particular task type, in our case, R.

Previously, our resolveTask does not really resolve the task.

@renkun-ken
Copy link
Member Author

renkun-ken commented Feb 14, 2022

Currently, there is a problem that #964 uses ShellQuotedString in the arguments supplied to ShellExecution. Then clicking the icon on the right of the task label

image

will result in an invalid task definition:

{
	"type": "R",
	"command": "Rscript",
	"args": [
		"-e",
		{
			"value": "devtools::install()",
			"quoting": 2
		}
	],
	"problemMatcher": [],
	"label": "R: Install"
}

I'm wondering if it is necessary to use ShellExecution in the first place? If we use ProcessExecution instead, then there seems to be no quoting issue at all, as implemented at renkun-ken@8384f3a.

@renkun-ken
Copy link
Member Author

I tested using ProcessExecution on Windows, Linux and macOS, and the pre-defined tasks work as expected. And user does not need to take care of argument quoting when they write tasks like this:

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "R",
			"command": "Rscript",
			"args": [
				"-e",
				"readLines('${file}')",
			],
			"cwd": "${workspaceRoot}",
			"env": {
				"ZZZ_TEST": "test1"
			},
			"problemMatcher": [],
			"label": "R: print file"
		}
	]
}

@renkun-ken
Copy link
Member Author

renkun-ken commented Feb 14, 2022

However, in Windows, the file paths are supplied as is. Maybe we could use some form of notation in args so that the file paths could be properly supplied as R string literals.

> Executing task: C:\Program Files\R\R-4.1.2\bin\Rscript.exe -e readLines('c:\Users\ken\Documents\languageserver\.vscode\tasks.json') <

Error: '\U' used without hex digits in character string starting "'$c:\U"
Execution halted
The terminal process "C:\Program Files\R\R-4.1.2\bin\Rscript.exe '-e', 'readLines('c:\Users\ken\Documents\languageserver\.vscode\tasks.json')'" terminated with exit code: 1.

@renkun-ken
Copy link
Member Author

Thanks @gowerc for the nice work done in renkun-ken#3.

@renkun-ken
Copy link
Member Author

renkun-ken commented Feb 16, 2022

Windows user could use raw string (requires R 4.0+) in task code to make use of the path variables:

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "R",
			"code": [
				"readLines(r'{${file}}')"
			],
			"group": "build",
			"problemMatcher": [],
			"label": "R test"
		}
	]
}

@gowerc
Copy link
Contributor

gowerc commented Feb 16, 2022

@renkun-ken

I was wondering if we should document the use of tasks in the readme? Personally I never found the current way vscode exposes them to users to be that intuitive so was thinking we might get more adoption if we had some more docs on it?

@renkun-ken
Copy link
Member Author

renkun-ken commented Feb 16, 2022

Yes, of course. I'll add an entry to Features which points to Tasks in wiki. If you are interested, you could directly edit the wiki page.

@gowerc
Copy link
Contributor

gowerc commented Feb 16, 2022

Makes sense to me, will try and add something

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.

Using "recently used" tasks launches the wrong task

3 participants