From 8a27f8a4f8a4a98188aa7a9cfa25eb96e356b554 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 24 Aug 2022 16:36:43 -0700 Subject: [PATCH] Revert "Simplify handling of local file links" This reverts commit e7974c1f612f8a0f36c8852612c26211bcf156f8. --- .../browser/links/terminalLinkOpeners.ts | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts b/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts index fb54598d415..b087c9d94df 100644 --- a/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts +++ b/src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts @@ -61,31 +61,29 @@ export class TerminalLocalFileLinkOpener implements ITerminalLinkOpener { // Calculate the file name end using the URI if possible, this will help with sanitizing the // link for the match regex. The actual path isn't important in extracting the line and // column from the regex so modifying the link text before the file name is safe. - const fileName = basename(uri.fsPath); + const fileName = basename(uri.path); const index = link.indexOf(fileName); const fileNameEndIndex: number = index !== -1 ? index + fileName.length : link.length; // Sanitize the link text such that the folders and file name do not contain whitespace. - // Prefer the URI's fsPath over the raw `link` text to operate on a consistent format. - // link = uri.fsPath.replace(/\s/g, '_') + link.slice(fileNameEndIndex); + link = link.slice(0, fileNameEndIndex).replace(/\s/g, '_') + link.slice(fileNameEndIndex); // The local link regex only works for non file:// links, check these for a simple // `:line:col` suffix - // if (link.startsWith('file://')) { - // const simpleMatches = link.match(/:(\d+)(:(\d+))?$/); - // if (simpleMatches) { - // if (simpleMatches[1] !== undefined) { - // lineColumnInfo.lineNumber = parseInt(simpleMatches[1]); - // } - // if (simpleMatches[3] !== undefined) { - // lineColumnInfo.columnNumber = parseInt(simpleMatches[3]); - // } - // } - // return lineColumnInfo; - // } + if (link.startsWith('file://')) { + const simpleMatches = link.match(/:(\d+)(:(\d+))?$/); + if (simpleMatches) { + if (simpleMatches[1] !== undefined) { + lineColumnInfo.lineNumber = parseInt(simpleMatches[1]); + } + if (simpleMatches[3] !== undefined) { + lineColumnInfo.columnNumber = parseInt(simpleMatches[3]); + } + } + return lineColumnInfo; + } - const fsLink = uri.fsPath.replace(/\s/g, '_') + link.slice(fileNameEndIndex); - const matches: string[] | null = getLocalLinkRegex(this._os).exec(fsLink); + const matches: string[] | null = getLocalLinkRegex(this._os).exec(link); if (!matches) { return lineColumnInfo; }