-
Notifications
You must be signed in to change notification settings - Fork 92
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
(Start to) handle cli hyperlinks in the terminal used for pkg dev tasks #5231
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
abc76af
(Start to) handle cli hyperlinks in the terminal used for pkg dev tasks
jennybc 09a3ad1
Move URI handling into its own file
jennybc 6c9d1e0
Remove chattiness that was useful in dev
jennybc e8b9fdb
Handle the env vars more crisply
jennybc 2694a20
Temporarily emit all supported hyperlinks
jennybc d78dff0
Remove temporary command/task to tickle help and vignette links
jennybc 40f3e9e
Put this comma back, the way I found it
jennybc ee4b359
Update "publisher" in mentions of the extension
jennybc 01ab77a
Put behind a feature flag
jennybc 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
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 }); | ||
} | ||
|
||
// Example of a URI we expect to handle: | ||
// positron://positron.positron-r/cli?command=x-r-run:testthat::snapshot_review('snap') | ||
// | ||
// How the example URI breaks down: | ||
// { | ||
// "scheme": "positron", | ||
// "authority": "positron.positron-r", | ||
// "path": "/cli", | ||
// "query": "command=x-r-run:testthat::snapshot_review('zzz')", | ||
// "fragment": "", | ||
// "fsPath": "/cli" | ||
// } | ||
function handleUri(uri: vscode.Uri): void { | ||
if (uri.path !== '/cli') { | ||
return; | ||
} | ||
|
||
// Turns this query string | ||
// "command=x-r-run:testthat::snapshot_review('zzz')" | ||
// into this object | ||
// { "command": "x-r-run:testthat::snapshot_review('zzz')" } | ||
const query = new URLSearchParams(uri.query); | ||
const command = query.get('command'); | ||
if (!command) { | ||
return; | ||
} | ||
|
||
const commandRegex = /^(x-r-(help|run|vignette)):(.+)$/; | ||
if (!commandRegex.test(command)) { | ||
return; | ||
} | ||
|
||
const session = RSessionManager.instance.getConsoleSession(); | ||
if (!session) { | ||
return; | ||
} | ||
|
||
session.openResource(command); | ||
vscode.commands.executeCommand('workbench.panel.positronConsole.focus'); | ||
} | ||
|
||
export async function prepCliEnvVars(session?: RSession): Promise<EnvVar> { | ||
session = session || RSessionManager.instance.getConsoleSession(); | ||
if (!session) { | ||
return {}; | ||
} | ||
|
||
// cli 3.6.3.9001 gained support for configuring the URL format for hyperlinks. | ||
const cliPkg = await session.packageVersion('cli', '3.6.3.9001'); | ||
const cliSupportsHyperlinks = cliPkg?.compatible ?? false; | ||
|
||
if (!cliSupportsHyperlinks) { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
return { R_CLI_HYPERLINKS: 'FALSE' }; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's where we exit early, without activating hyperlinks in the integrated terminal, in the absence of bleeding edge cli. |
||
|
||
return { | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
R_CLI_HYPERLINKS: 'TRUE', | ||
// 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. | ||
// 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}', | ||
R_CLI_HYPERLINK_HELP: 'TRUE', | ||
R_CLI_HYPERLINK_HELP_URL_FORMAT: 'positron://positron.positron-r/cli?command=x-r-help:{topic}', | ||
R_CLI_HYPERLINK_VIGNETTE: 'TRUE', | ||
R_CLI_HYPERLINK_VIGNETTE_URL_FORMAT: 'positron://positron.positron-r/cli?command=x-r-vignette:{vignette}' | ||
/* eslint-enable @typescript-eslint/naming-convention */ | ||
}; | ||
} |
This file contains 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 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
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.
I suspect this should be the case for all extensions we (Positron) have introduced. Harder to say what should happen to VS Code built-in extensions that we modify, but worth thinking about.
The relevance to this PR is that the
publisher
affects the form of URI that the associated extention (positron-r, in this case) is allowed to handle. The general form is:which means that positron-r can handle URIs that begin like so:
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.
From #5268, we're going to use "positron" as publisher here.