Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/cliPublic

Configurable file hyperlinks#744

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gaborcsardi merged 14 commits intomainfromconfigurable-file-hyperlinks
Jan 10, 2025
Merged

Conversation

@jennybc
Copy link
Member

@jennybcjennybc commentedDec 17, 2024
edited
Loading

This PR makes it possible for Positron (or any execution context) to inform cli howfile hyperlinks need to be constructed in order to work in Positron's terminals. What I mean by "work" is that file hyperlinks openin this product and don't delegate to the operating system. This is beneficial for Positron's R package development tasks, most especiallydevtools::test(), which will emit links likepath/to/test-foo:10:3 when tests fail. Companion to the already-merged#739. Here's a video of runningdevtools::test() and taking advantage of clickable filepaths and runnable code (for reviewing or accepting snapshots):

Screen.Recording.2024-12-16.at.4.10.39.PM.mov

Note the screen recording is made with a local branch of Positron, which also needs another PR to take advantage of the cli changes.

Package: cli
Title: Helpers for Developing Command Line Interfaces
Version: 3.6.3.9001
Version: 3.6.3.9002
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm going to need to detect this version in Positron. We only want to enable hyperlinks in the relevant terminals if we know they're going work exactly as we want.

ret
}

parse_file_link_params<-function(txt) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This became narrower, i.e. just about parsing.

}else {
list(path=path,params= c(line=num,col="1"))
}
construct_file_link<-function(params) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This turns the parsed filepath into the datastyle_hyperlink() needs.

list(path=path,params= c(line=num,col="1"))
}
construct_file_link<-function(params) {
fmt<- get_config_chr("hyperlink_file_url_format")
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As it stands, only an explicitly configured hyperlink format has any effect.

But you could imagine detecting that we're in, e.g. a Positron or VS Code terminal, and setting this configuration from the cli side. Food for thought. But definitely something that could be added later.

@jennybc
Copy link
MemberAuthor

I took inspiration from other tools, such as ripgrep. Here's how ripgrep can be configured to construct hyperlinks for various environments:

https://github.com/BurntSushi/ripgrep/blob/bf63fe8f258afc09bae6caa48f0ae35eaf115005/crates/printer/src/hyperlink_aliases.rs#L4-L22

/// Aliases to well-known hyperlink schemes.////// These need to be sorted by name.const HYPERLINK_PATTERN_ALIASES: &[(&str, &str)] = &[    #[cfg(not(windows))]    ("default", "file://{host}{path}"),    #[cfg(windows)]    ("default", "file://{path}"),    ("file", "file://{host}{path}"),    // https://github.com/misaki-web/grepp    ("grep+", "grep+://{path}:{line}"),    ("kitty", "file://{host}{path}#{line}"),    // https://macvim.org/docs/gui_mac.txt.html#mvim%3A%2F%2F    ("macvim", "mvim://open?url=file://{path}&line={line}&column={column}"),    ("none", ""),    // https://macromates.com/blog/2007/the-textmate-url-scheme/    ("textmate", "txmt://open?url=file://{path}&line={line}&column={column}"),    // https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls    ("vscode", "vscode://file{path}:{line}:{column}"),    ("vscode-insiders", "vscode-insiders://file{path}:{line}:{column}"),    ("vscodium", "vscodium://file{path}:{line}:{column}"),];

Documentation of thevscode:// URL scheme and, therefore, thepositron:// URL scheme:

https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls

delta is another tool that has a similar configuration point:

https://dandavison.github.io/delta/tips-and-tricks/using-delta-with-vscode.html

https://dandavison.github.io/delta/hyperlinks.html

@jennybc
Copy link
MemberAuthor

jennybc commentedDec 19, 2024
edited
Loading

In actual use this is looking pretty good now. For my own convenience, I want to record how to test drive this even without the necessary changes in Positron.

In a terminal inside VS Code, set up some environment variables and then start R:

export R_CLI_HYPERLINKS=trueexport R_CLI_HYPERLINK_FILE_URL_FORMAT=vscode://file{path}:{line}:{column}R

In that R session, you should be able to create cli file hyperlinks and Ctrl/Cmd+click on them to open in VS Code, e.g.:

cli::cli_text("{.file ~/.gitconfig}")

Likewise, you could achieve the same in a terminal inside a released version of Positron by changing the file hyperlink format:

export R_CLI_HYPERLINKS=trueexport R_CLI_HYPERLINK_FILE_URL_FORMAT=positron://file{path}:{line}:{column}R

I'll be back to soon finalize this and remove the draft status.

@jennybc
Copy link
MemberAuthor

@gaborcsardi This is good to go from where I stand. Not sure why I didn't remove the draft label before the holidays, but oh well!

@jennybcjennybc marked this pull request as ready for reviewJanuary 9, 2025 06:25
@jennybc
Copy link
MemberAuthor

jennybc commentedJan 9, 2025
edited
Loading

Another variation on#744 (comment) is that if you always want cli to emitvscode://file orpositron://file links when R is running in an integrated VS Code or Positron terminal, respectively, is that you can put something like this in your user settings, e.g.:

{"terminal.integrated.env.osx": {"R_CLI_HYPERLINKS":"true","R_CLI_HYPERLINK_FILE_URL_FORMAT":"positron://file{path}:{line}:{column}"    }}

It appears this is what cli has always done with a leading `./`, so just keep doing that until there's reason not to.
@gaborcsardigaborcsardi merged commita3cef9f intomainJan 10, 2025
13 checks passed
@gaborcsardigaborcsardi deleted the configurable-file-hyperlinks branchJanuary 10, 2025 09:22
jennybc added a commit to posit-dev/positron that referenced this pull requestJan 14, 2025
Addresses#5409*Needed to wait forr-lib/cli#744, which is nowmerged*`@:r-pkg-development`### QA NotesPre-requisite: You need to install a very recent version of the clipackage. 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, agood way to install is:```rpak::pak("r-lib/cli")```Make sure the cli version is >= 3.6.3.9002:``` rpackageVersion("cli")#> [1] '3.6.3.9002'```There won't be any obvious error in the presence of an older cliversion, 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 isreported. 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 theyattempt to snapshot a random number. But really any package with afailing 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 orselect *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, notspecific 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 thinkI have long since checked some box always permitting this for localfiles. 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, sincenow all hyperlinks work (if the cli version is recent enough). If youconfigured `positron://settings/positron.r.taskHyperlinks` in theinterim, that setting can be removed and, indeed, no longer exists.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@jennybc@gaborcsardi

[8]ページ先頭

©2009-2025 Movatter.jp