Skip to content

Commit 739f0c4

Browse files
authored
Merge pull request microsoft#155962 from microsoft/tyriar/fix_link_test
Fix space folder link test
2 parents 8b7a0d8 + ba8b769 commit 739f0c4

File tree

2 files changed

+68
-33
lines changed

2 files changed

+68
-33
lines changed

src/vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ export class TerminalLocalFileLinkOpener implements ITerminalLinkOpener {
5252
*
5353
* @param link Url link which may contain line and column number.
5454
*/
55-
extractLineColumnInfo(link: string, uri?: URI): ILineColumnInfo {
55+
extractLineColumnInfo(link: string, uri: URI): ILineColumnInfo {
5656
const lineColumnInfo: ILineColumnInfo = {
5757
lineNumber: 1,
5858
columnNumber: 1
5959
};
6060

61-
// If a URI was passed in the exact file is known, sanitize the link text such that the
62-
// folders and file name do not contain whitespace. The actual path isn't important in
63-
// extracting the line and column from the regex so this is safe
64-
if (uri) {
65-
const fileName = basename(uri.path);
66-
const index = link.indexOf(fileName);
67-
const endIndex = index + fileName.length;
68-
link = link.slice(0, endIndex).replace(/\s/g, '_') + link.slice(endIndex);
69-
}
61+
// Calculate the file name end using the URI if possible, this will help with sanitizing the
62+
// link for the match regex. The actual path isn't important in extracting the line and
63+
// column from the regex so modifying the link text before the file name is safe.
64+
const fileName = basename(uri.path);
65+
const index = link.indexOf(fileName);
66+
const fileNameEndIndex: number = index !== -1 ? index + fileName.length : link.length;
67+
68+
// Sanitize the link text such that the folders and file name do not contain whitespace.
69+
link = link.slice(0, fileNameEndIndex).replace(/\s/g, '_') + link.slice(fileNameEndIndex);
7070

7171
// The local link regex only works for non file:// links, check these for a simple
7272
// `:line:col` suffix
@@ -259,7 +259,7 @@ export class TerminalSearchLinkOpener implements ITerminalLinkOpener {
259259
const { uri, isDirectory } = result;
260260
const linkToOpen = {
261261
// Use the absolute URI's path here so the optional line/col get detected
262-
text: result.uri.fsPath + (text.match(/:\d+(:\d+)?$/)?.[0] || ''),
262+
text: result.uri.path + (text.match(/:\d+(:\d+)?$/)?.[0] || ''),
263263
uri,
264264
bufferRange: link.bufferRange,
265265
type: link.type

src/vs/workbench/contrib/terminal/test/browser/links/terminalLinkOpeners.test.ts

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,28 +170,6 @@ suite('Workbench - TerminalLinkOpeners', () => {
170170
});
171171
});
172172

173-
test.skip('should extract line and column from links in a workspace containing spaces', async () => {
174-
localFileOpener = instantiationService.createInstance(TerminalLocalFileLinkOpener, OperatingSystem.Linux);
175-
const localFolderOpener = instantiationService.createInstance(TerminalLocalFolderInWorkspaceLinkOpener);
176-
opener = instantiationService.createInstance(TerminalSearchLinkOpener, capabilities, Promise.resolve('/space folder'), localFileOpener, localFolderOpener, OperatingSystem.Linux);
177-
fileService.setFiles([
178-
URI.from({ scheme: Schemas.file, path: '/space folder/foo/bar.txt' })
179-
]);
180-
await opener.open({
181-
text: './foo/bar.txt:10:5',
182-
bufferRange: { start: { x: 1, y: 1 }, end: { x: 8, y: 1 } },
183-
type: TerminalBuiltinLinkType.Search
184-
});
185-
deepStrictEqual(activationResult, {
186-
link: 'file:///space%20folder/foo/bar.txt',
187-
source: 'editor',
188-
selection: {
189-
startColumn: 5,
190-
startLineNumber: 10
191-
},
192-
});
193-
});
194-
195173
suite('macOS/Linux', () => {
196174
setup(() => {
197175
localFileOpener = instantiationService.createInstance(TerminalLocalFileLinkOpener, OperatingSystem.Linux);
@@ -239,6 +217,28 @@ suite('Workbench - TerminalLinkOpeners', () => {
239217
source: 'search'
240218
});
241219
});
220+
221+
test('should extract line and column from links in a workspace containing spaces', async () => {
222+
localFileOpener = instantiationService.createInstance(TerminalLocalFileLinkOpener, OperatingSystem.Linux);
223+
const localFolderOpener = instantiationService.createInstance(TerminalLocalFolderInWorkspaceLinkOpener);
224+
opener = instantiationService.createInstance(TerminalSearchLinkOpener, capabilities, Promise.resolve('/space folder'), localFileOpener, localFolderOpener, OperatingSystem.Linux);
225+
fileService.setFiles([
226+
URI.from({ scheme: Schemas.file, path: '/space folder/foo/bar.txt' })
227+
]);
228+
await opener.open({
229+
text: './foo/bar.txt:10:5',
230+
bufferRange: { start: { x: 1, y: 1 }, end: { x: 8, y: 1 } },
231+
type: TerminalBuiltinLinkType.Search
232+
});
233+
deepStrictEqual(activationResult, {
234+
link: 'file:///space%20folder/foo/bar.txt',
235+
source: 'editor',
236+
selection: {
237+
startColumn: 5,
238+
startLineNumber: 10
239+
},
240+
});
241+
});
242242
});
243243

244244
suite('Windows', () => {
@@ -288,6 +288,41 @@ suite('Workbench - TerminalLinkOpeners', () => {
288288
source: 'search'
289289
});
290290
});
291+
292+
test('should extract line and column from links in a workspace containing spaces', async () => {
293+
localFileOpener = instantiationService.createInstance(TerminalLocalFileLinkOpener, OperatingSystem.Windows);
294+
const localFolderOpener = instantiationService.createInstance(TerminalLocalFolderInWorkspaceLinkOpener);
295+
opener = instantiationService.createInstance(TerminalSearchLinkOpener, capabilities, Promise.resolve('/space folder'), localFileOpener, localFolderOpener, OperatingSystem.Windows);
296+
fileService.setFiles([
297+
URI.from({ scheme: Schemas.file, path: '/space folder/foo/bar.txt' })
298+
]);
299+
await opener.open({
300+
text: './foo/bar.txt:10:5',
301+
bufferRange: { start: { x: 1, y: 1 }, end: { x: 8, y: 1 } },
302+
type: TerminalBuiltinLinkType.Search
303+
});
304+
deepStrictEqual(activationResult, {
305+
link: 'file:///space%20folder/foo/bar.txt',
306+
source: 'editor',
307+
selection: {
308+
startColumn: 5,
309+
startLineNumber: 10
310+
},
311+
});
312+
await opener.open({
313+
text: '.\\foo\\bar.txt:10:5',
314+
bufferRange: { start: { x: 1, y: 1 }, end: { x: 8, y: 1 } },
315+
type: TerminalBuiltinLinkType.Search
316+
});
317+
deepStrictEqual(activationResult, {
318+
link: 'file:///space%20folder/foo/bar.txt',
319+
source: 'editor',
320+
selection: {
321+
startColumn: 5,
322+
startLineNumber: 10
323+
},
324+
});
325+
});
291326
});
292327
});
293328
});

0 commit comments

Comments
 (0)