Skip to content

Conversation

jennybc
Copy link
Member

@jennybc jennybc commented Oct 10, 2025

(Partially) addresses #8393

RStudio users miss the feature where, if you have one or more files on the clipboard (and I really mean files), and you paste into an R context (an R script or the console), you get a quoted path, with \ converted to /.

In terms of 👍, this issue is ranked fourth among all issues with the os-windows label.

This PR implements this paste magic for R files, but not (yet?) for the R console. I note that it is also not working (yet?) for R chunks of .qmd or .Rmd documents.

file-paste.mp4

I also still want to make the path relative, e.g. the current workspace root or user's home directory, if possible (as RStudio does) now implemented. Ironically I haven't test driven this on macOS, because I'm still limping along on my Windows machine but that will change soon.

I'm looking for:

  • Feedback on the current implementation for editors associated with R
  • High-level guidance on how this should be implemented for the console. I've worked with Claude Code on this and we have had a working implementation for the console. I just thought the design was unsatisfying and I backed out of this. How should an extension contribute to paste behaviour? It feels like we'd need a new extension point or service that can take contributions. This seems like a relevant location:

handler: async accessor => {
const clipboardService = accessor.get(IClipboardService);
const consoleService = accessor.get(IPositronConsoleService);
const text = await clipboardService.readText();
return consoleService.activePositronConsoleInstance?.pasteText(text);
}

Release Notes

New Features

  • N/A

Bug Fixes

  • N/A

QA Notes

Copy link

github-actions bot commented Oct 10, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical

readme  valid tags

@@ -0,0 +1,116 @@
# (Mostly Windows) File Path Auto-Conversion Feature
Copy link
Member Author

Choose a reason for hiding this comment

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

I will presumably remove this file when this feature is done, which may or may not happen in this PR. I.e. might decide to take the win in R documents and handle the console separately.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Typically we don't commit work-in-progress notes files to the repo -- if you want to preserve these, maybe file an issue and link to it from the relevant code?

token: vscode.CancellationToken
): Promise<vscode.DocumentPasteEdit[] | undefined> {

const setting = vscode.workspace.getConfiguration('positron.r').get<boolean>('autoConvertFilePaths');
Copy link
Member Author

Choose a reason for hiding this comment

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

Do we even need a setting to allow people to opt out? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Need? No. But I think it's fine to leave in until we're confident that this won't get in anyone's way!

/**
* File path utilities for data analysis code.
*/
namespace paths {
Copy link
Member Author

Choose a reason for hiding this comment

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

I added this to the positron API to centralize the initial futzing with the clipboard and file URIs, which would be needed to produce usable file paths for any language (e.g. R or Python).

@jennybc jennybc requested a review from jmcphers October 10, 2025 06:37
@jennybc
Copy link
Member Author

jennybc commented Oct 10, 2025

Looks like unit test failures are basically typos on my part. I couldn’t figure out how to run just this specific test file locally 🙈. Can’t correct them rn but should be easy. I've fixed the casing error. But the UNC pat (not) skipping problem looks real. Will get into the debugger and fix.

@jennybc
Copy link
Member Author

jennybc commented Oct 14, 2025

The unit test failures re: UNC paths are due to the fact that CI is running on ubuntu and the isUNC() function returns false unconditionally on non-Windows 🤔 I "fixed" the tests by skipping when the OS is not Windows.

if (!isWindows) {
// UNC is a windows concept
return false;
}

@jennybc jennybc force-pushed the feature/windows-filepath-paste branch 2 times, most recently from 0e76a47 to aaf9362 Compare October 16, 2025 17:57
jmcphers
jmcphers previously approved these changes Oct 20, 2025
Copy link
Collaborator

@jmcphers jmcphers left a comment

Choose a reason for hiding this comment

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

LGTM modulo a few nits. this worked well in my testing!

Is there a good reason we shouldn't also do this for Python? (seems like it'd be almost identical other than the array syntax)

token: vscode.CancellationToken
): Promise<vscode.DocumentPasteEdit[] | undefined> {

const setting = vscode.workspace.getConfiguration('positron.r').get<boolean>('autoConvertFilePaths');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need? No. But I think it's fine to leave in until we're confident that this won't get in anyone's way!

// to get that back.
return [{
insertText,
title: 'Insert file path(s)',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this text be localized?

Copy link
Member Author

Choose a reason for hiding this comment

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

At the moment, I don't think this text is ever surfaced 🫠 At some point, when this PR "did more" but also had a weaker design, this text was surfaced (in a "Paste As" sort of experience). I will rationalize this bit one way or another before I merge.

}

/**
* Extract file paths from clipboard for use in data analysis code.
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO there's no need to specify "for use in data analysis code?" This API is very generic

}

// Err on the side of caution and skip conversion entirely if ANY paths are
// UNC paths
Copy link
Collaborator

Choose a reason for hiding this comment

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

If UNC paths are used it looks like they don't get escaped at all, but are still pasted. Would be nice if this worked but seems like it could be hard!

@@ -0,0 +1,116 @@
# (Mostly Windows) File Path Auto-Conversion Feature
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typically we don't commit work-in-progress notes files to the repo -- if you want to preserve these, maybe file an issue and link to it from the relevant code?

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.

2 participants