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

Configure cli file hyperlinks for R package dev tasks #5850

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 0 additions & 6 deletions extensions/positron-r/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,6 @@
"default": [],
"description": "%r.configuration.extraArguments.description%"
},
"positron.r.taskHyperlinks": {
"scope": "window",
"type": "boolean",
"default": false,
"description": "%r.configuration.taskHyperlinks.description%"
},
"positron.r.defaultRepositories": {
"scope": "window",
"type": "string",
Expand Down
1 change: 0 additions & 1 deletion extensions/positron-r/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"r.configuration.pipe.native.description": "Native pipe available in R >= 4.1",
"r.configuration.pipe.magrittr.description": "Pipe operator from the magrittr package, re-exported by many other packages",
"r.configuration.diagnostics.enable.description": "Enable R diagnostics globally",
"r.configuration.taskHyperlinks.description": "Turn on experimental support for hyperlinks in package development tasks",
"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.",
"r.configuration.defaultRepositories.auto.description": "Automatically choose a default repository, or use a repos.conf file if it exists.",
"r.configuration.defaultRepositories.rstudio.description": "Use the RStudio CRAN mirror (cran.rstudio.com)",
Expand Down
22 changes: 4 additions & 18 deletions extensions/positron-r/src/uri-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,13 @@

import * as vscode from 'vscode';

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

export async function registerUriHandler() {
vscode.window.registerUriHandler({ handleUri });
}

// Temporary feature flag to finesse the fact that cli hyperlinks are either all ON or all OFF.
// cli 3.6.3.9001 gained support for configuring the URL format of run/help/vignette hyperlinks.
// But file hyperlinks are not yet configurable and will delegate to operating system.
// If the user still has RStudio as the app associated with .R files, it will open in RStudio.
// Flag will be removed once cli can be configured to emit positron://file/... hyperlinks.
function taskHyperlinksEnabled(): boolean {
const extConfig = vscode.workspace.getConfiguration('positron.r');
const taskHyperlinksEnabled = extConfig.get<boolean>('taskHyperlinks');

return taskHyperlinksEnabled === true;
}

// Example of a URI we expect to handle:
// positron://positron.positron-r/cli?command=x-r-run:testthat::snapshot_review('snap')
//
Expand Down Expand Up @@ -72,21 +59,20 @@ export async function prepCliEnvVars(session?: RSession): Promise<EnvVar> {
return {};
}

const taskHyperlinks = taskHyperlinksEnabled();
const cliPkg = await session.packageVersion('cli', '3.6.3.9001');
const cliPkg = await session.packageVersion('cli', '3.6.3.9002');
const cliSupportsHyperlinks = cliPkg?.compatible ?? false;

if (!taskHyperlinks || !cliSupportsHyperlinks) {
if (!cliSupportsHyperlinks) {
// eslint-disable-next-line @typescript-eslint/naming-convention
return { R_CLI_HYPERLINKS: 'FALSE' };
}

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