From 960d462234df3e039b3c38e062d898ba1b86b149 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Fri, 8 Mar 2024 20:49:12 +0000 Subject: [PATCH 1/2] Hack that fixes file hyperlinks --- .../positronConsole/browser/components/outputRun.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/vs/workbench/contrib/positronConsole/browser/components/outputRun.tsx b/src/vs/workbench/contrib/positronConsole/browser/components/outputRun.tsx index 15340cee371..17d51607e0d 100644 --- a/src/vs/workbench/contrib/positronConsole/browser/components/outputRun.tsx +++ b/src/vs/workbench/contrib/positronConsole/browser/components/outputRun.tsx @@ -4,6 +4,7 @@ import 'vs/css!./outputRun'; import * as React from 'react'; +import * as platform from 'vs/base/common/platform'; import { CSSProperties, MouseEvent } from 'react'; // eslint-disable-line no-duplicate-imports import { localize } from 'vs/nls'; import { ANSIColor, ANSIOutputRun, ANSIStyle } from 'vs/base/common/ansiOutput'; @@ -56,6 +57,11 @@ export const OutputRun = (props: OutputRunProps) => { return url; } + // a hack that, at least, pinpoints the problem / solution + if (platform.isWindows) { + url = url.replace(/\\/g, '/').replace(/file:\/\/(?!\/)/g, 'file:///'); + } + // Get the line parameter. If it's not present, return the URL. const line = props.outputRun.hyperlink.params?.get('line') || undefined; if (!line) { From 1506419607f77e84bd4feef4dfdd898707267ee2 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Tue, 12 Mar 2024 21:14:48 +0000 Subject: [PATCH 2/2] Tighten this up and add comment --- .../positronConsole/browser/components/outputRun.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/positronConsole/browser/components/outputRun.tsx b/src/vs/workbench/contrib/positronConsole/browser/components/outputRun.tsx index 17d51607e0d..450b227be30 100644 --- a/src/vs/workbench/contrib/positronConsole/browser/components/outputRun.tsx +++ b/src/vs/workbench/contrib/positronConsole/browser/components/outputRun.tsx @@ -15,6 +15,7 @@ import { Schemas } from 'vs/base/common/network'; * Constants. */ const numberRegex = /^\d+$/; +const fileURLThatNeedsASlash = /^(file:\/\/)([a-zA-Z]:)/; const fileURLWithLine = /^(file:\/\/\/.+):(\d+)$/; const fileURLWithLineAndColumn = /^(file:\/\/\/.+):(\d+):(\d+)$/; @@ -57,9 +58,15 @@ export const OutputRun = (props: OutputRunProps) => { return url; } - // a hack that, at least, pinpoints the problem / solution + // anticipate file URLs produced by, e.g., some versions of the cli R package + // BEFORE example: + // file://D:\\Users\\jenny\\source\\repos\\glue\\tests\\testthat\\test-glue.R + // AFTER example: + // file:///D:/Users/jenny/source/repos/glue/tests/testthat/test-glue.R if (platform.isWindows) { - url = url.replace(/\\/g, '/').replace(/file:\/\/(?!\/)/g, 'file:///'); + url = url + .replace(/\\/g, '/') + .replace(fileURLThatNeedsASlash, '$1/$2'); } // Get the line parameter. If it's not present, return the URL.