Skip to content

Commit f773698

Browse files
authored
Configure cli file hyperlinks for R package dev tasks (#5850)
Addresses #5409 *Needed to wait for r-lib/cli#744, which is now merged* `@:r-pkg-development` ### QA Notes Pre-requisite: You need to install a very recent version of the cli package. At the time I write this, this means a dev version of cli, although I think we'll get a release out fairly soon. In the meantime, a good way to install is: ```r pak::pak("r-lib/cli") ``` Make sure the cli version is >= 3.6.3.9002: ``` r packageVersion("cli") #> [1] '3.6.3.9002' ``` There won't be any obvious error in the presence of an older cli version, but the new functionality just won't activate. Then you need to run tests on a package with one or more failing tests, in order to be able to click on the filepath when test failure is reported. This should take you directly to the relevant test location. I have made a toy package that could be obtained via [`usethis::create_from_github("jennybc/clilinks")`](https://github.com/jennybc/clilinks). It has a couple of snapshot tests that will always fail 😄 because they attempt to snapshot a random number. But really any package with a failing test will do. * Install dev cli: `pak::pak("r-lib/cli")` * Identify a package with a failing test and open it in Positron, perhaps via: `usethis::create_from_github("jennybc/clilinks")` * Use our gesture for running package tests: Ctrl/Cmd + Shift + T or select *R: Test R Package* from the command palette. * Click on a file hyperlink for a failing test: - Note this requires Ctrl/Cmd click! This is a VS Code convention, not specific to us. - Note that you might have to click twice. This is a bug (or 2 bugs?) for which fixes are making their way through the system (microsoft/vscode#230010). Again, not us. - You might need to grant permission to open the file hyperlink. I think I have long since checked some box always permitting this for local files. This is a VS Code feature. <img width="652" alt="file-hyperlink" src="https://github.com/user-attachments/assets/3c1c7a11-e545-4ae8-8891-991d3e22c032" /> --- Note that this PR removes the feature flag introduced in #5231, since now all hyperlinks work (if the cli version is recent enough). If you configured `positron://settings/positron.r.taskHyperlinks` in the interim, that setting can be removed and, indeed, no longer exists.
1 parent f339e73 commit f773698

File tree

3 files changed

+4
-25
lines changed

3 files changed

+4
-25
lines changed

extensions/positron-r/package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,6 @@
273273
"default": [],
274274
"description": "%r.configuration.extraArguments.description%"
275275
},
276-
"positron.r.taskHyperlinks": {
277-
"scope": "window",
278-
"type": "boolean",
279-
"default": false,
280-
"description": "%r.configuration.taskHyperlinks.description%"
281-
},
282276
"positron.r.defaultRepositories": {
283277
"scope": "window",
284278
"type": "string",

extensions/positron-r/package.nls.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"r.configuration.pipe.native.description": "Native pipe available in R >= 4.1",
6060
"r.configuration.pipe.magrittr.description": "Pipe operator from the magrittr package, re-exported by many other packages",
6161
"r.configuration.diagnostics.enable.description": "Enable R diagnostics globally",
62-
"r.configuration.taskHyperlinks.description": "Turn on experimental support for hyperlinks in package development tasks",
6362
"r.configuration.defaultRepositories.description": "The default repositories to use for R package installation, if no repository is otherwise specified in R startup scripts (restart Positron to apply).\n\nThe default repositories will be set as the `repos` option in R.",
6463
"r.configuration.defaultRepositories.auto.description": "Automatically choose a default repository, or use a repos.conf file if it exists.",
6564
"r.configuration.defaultRepositories.rstudio.description": "Use the RStudio CRAN mirror (cran.rstudio.com)",

extensions/positron-r/src/uri-handler.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,13 @@
55

66
import * as vscode from 'vscode';
77

8-
import { LOGGER } from './extension';
98
import { RSessionManager } from './session-manager';
109
import { EnvVar, RSession } from './session';
1110

1211
export async function registerUriHandler() {
1312
vscode.window.registerUriHandler({ handleUri });
1413
}
1514

16-
// Temporary feature flag to finesse the fact that cli hyperlinks are either all ON or all OFF.
17-
// cli 3.6.3.9001 gained support for configuring the URL format of run/help/vignette hyperlinks.
18-
// But file hyperlinks are not yet configurable and will delegate to operating system.
19-
// If the user still has RStudio as the app associated with .R files, it will open in RStudio.
20-
// Flag will be removed once cli can be configured to emit positron://file/... hyperlinks.
21-
function taskHyperlinksEnabled(): boolean {
22-
const extConfig = vscode.workspace.getConfiguration('positron.r');
23-
const taskHyperlinksEnabled = extConfig.get<boolean>('taskHyperlinks');
24-
25-
return taskHyperlinksEnabled === true;
26-
}
27-
2815
// Example of a URI we expect to handle:
2916
// positron://positron.positron-r/cli?command=x-r-run:testthat::snapshot_review('snap')
3017
//
@@ -72,21 +59,20 @@ export async function prepCliEnvVars(session?: RSession): Promise<EnvVar> {
7259
return {};
7360
}
7461

75-
const taskHyperlinks = taskHyperlinksEnabled();
76-
const cliPkg = await session.packageVersion('cli', '3.6.3.9001');
62+
const cliPkg = await session.packageVersion('cli', '3.6.3.9002');
7763
const cliSupportsHyperlinks = cliPkg?.compatible ?? false;
7864

79-
if (!taskHyperlinks || !cliSupportsHyperlinks) {
65+
if (!cliSupportsHyperlinks) {
8066
// eslint-disable-next-line @typescript-eslint/naming-convention
8167
return { R_CLI_HYPERLINKS: 'FALSE' };
8268
}
8369

8470
return {
8571
/* eslint-disable @typescript-eslint/naming-convention */
8672
R_CLI_HYPERLINKS: 'TRUE',
73+
R_CLI_HYPERLINK_FILE_URL_FORMAT: 'positron://file{path}:{line}:{column}',
8774
// TODO: I'd like to request POSIX compliant hyperlinks in the future, but currently
88-
// cli's tests implicitly assume the default and there are more important changes to
89-
// propose in cli, such as tweaks to file hyperlinks. Leave this alone for now.
75+
// cli's tests implicitly assume the default. Doesn't seem worth the fuss at this time.
9076
// R_CLI_HYPERLINK_MODE: "posix",
9177
R_CLI_HYPERLINK_RUN: 'TRUE',
9278
R_CLI_HYPERLINK_RUN_URL_FORMAT: 'positron://positron.positron-r/cli?command=x-r-run:{code}',

0 commit comments

Comments
 (0)