@theia/terminal 1.53.0-next.4 → 1.53.0-next.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/terminal-link-provider.d.ts +1 -1
  3. package/lib/browser/terminal-link-provider.d.ts.map +1 -1
  4. package/lib/browser/terminal-widget-impl.js +4 -4
  5. package/package.json +10 -10
  6. package/src/browser/base/terminal-service.ts +60 -60
  7. package/src/browser/base/terminal-widget.ts +268 -268
  8. package/src/browser/index.ts +17 -17
  9. package/src/browser/search/terminal-search-container.ts +28 -28
  10. package/src/browser/search/terminal-search-widget.tsx +161 -161
  11. package/src/browser/shell-terminal-profile.ts +45 -45
  12. package/src/browser/style/terminal-search.css +99 -99
  13. package/src/browser/style/terminal.css +32 -32
  14. package/src/browser/terminal-contribution.ts +19 -19
  15. package/src/browser/terminal-copy-on-selection-handler.ts +92 -92
  16. package/src/browser/terminal-file-link-provider.ts +289 -289
  17. package/src/browser/terminal-frontend-contribution.ts +1134 -1134
  18. package/src/browser/terminal-frontend-module.ts +138 -138
  19. package/src/browser/terminal-link-helpers.ts +187 -187
  20. package/src/browser/terminal-link-provider.ts +203 -203
  21. package/src/browser/terminal-preferences.ts +428 -428
  22. package/src/browser/terminal-profile-service.ts +180 -180
  23. package/src/browser/terminal-quick-open-service.ts +132 -132
  24. package/src/browser/terminal-theme-service.ts +213 -213
  25. package/src/browser/terminal-url-link-provider.ts +66 -66
  26. package/src/browser/terminal-widget-impl.ts +996 -996
  27. package/src/common/base-terminal-protocol.ts +125 -125
  28. package/src/common/shell-terminal-protocol.ts +103 -103
  29. package/src/common/terminal-common-module.ts +30 -30
  30. package/src/common/terminal-protocol.ts +32 -32
  31. package/src/common/terminal-watcher.ts +69 -69
  32. package/src/node/base-terminal-server.ts +173 -173
  33. package/src/node/buffering-stream.spec.ts +46 -46
  34. package/src/node/buffering-stream.ts +95 -95
  35. package/src/node/index.ts +17 -17
  36. package/src/node/shell-process.ts +102 -102
  37. package/src/node/shell-terminal-server.spec.ts +40 -40
  38. package/src/node/shell-terminal-server.ts +223 -223
  39. package/src/node/terminal-backend-contribution.slow-spec.ts +63 -63
  40. package/src/node/terminal-backend-contribution.ts +60 -60
  41. package/src/node/terminal-backend-module.ts +82 -82
  42. package/src/node/terminal-server.spec.ts +47 -47
  43. package/src/node/terminal-server.ts +52 -52
  44. package/src/node/test/terminal-test-container.ts +39 -39
  45. package/src/package.spec.ts +28 -28
@@ -1,289 +1,289 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { OS, Path, QuickInputService } from '@theia/core';
18
- import { OpenerService } from '@theia/core/lib/browser';
19
- import URI from '@theia/core/lib/common/uri';
20
- import { inject, injectable } from '@theia/core/shared/inversify';
21
- import { Position } from '@theia/editor/lib/browser';
22
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
23
- import { TerminalWidget } from './base/terminal-widget';
24
- import { TerminalLink, TerminalLinkProvider } from './terminal-link-provider';
25
- import { TerminalWidgetImpl } from './terminal-widget-impl';
26
- import { FileSearchService } from '@theia/file-search/lib/common/file-search-service';
27
- import { WorkspaceService } from '@theia/workspace/lib/browser';
28
- @injectable()
29
- export class FileLinkProvider implements TerminalLinkProvider {
30
-
31
- @inject(OpenerService) protected readonly openerService: OpenerService;
32
- @inject(QuickInputService) protected readonly quickInputService: QuickInputService;
33
- @inject(FileService) protected fileService: FileService;
34
- @inject(FileSearchService) protected searchService: FileSearchService;
35
- @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
36
-
37
- async provideLinks(line: string, terminal: TerminalWidget): Promise<TerminalLink[]> {
38
- const links: TerminalLink[] = [];
39
- const regExp = await this.createRegExp();
40
- let regExpResult: RegExpExecArray | null;
41
- while (regExpResult = regExp.exec(line)) {
42
- const match = regExpResult[0];
43
- if (await this.isValidFile(match, terminal)) {
44
- links.push({
45
- startIndex: regExp.lastIndex - match.length,
46
- length: match.length,
47
- handle: () => this.open(match, terminal)
48
- });
49
- }
50
- }
51
- return links;
52
- }
53
-
54
- protected async createRegExp(): Promise<RegExp> {
55
- const baseLocalLinkClause = OS.backend.isWindows ? winLocalLinkClause : unixLocalLinkClause;
56
- return new RegExp(`${baseLocalLinkClause}(${lineAndColumnClause})`, 'g');
57
- }
58
-
59
- protected async isValidFile(match: string, terminal: TerminalWidget): Promise<boolean> {
60
- try {
61
- const toOpen = await this.toURI(match, await this.getCwd(terminal));
62
- if (toOpen) {
63
- // TODO: would be better to ask the opener service, but it returns positively even for unknown files.
64
- return this.isValidFileURI(toOpen);
65
- }
66
- } catch (err) {
67
- console.trace('Error validating ' + match, err);
68
- }
69
- return false;
70
- }
71
-
72
- protected async isValidFileURI(uri: URI): Promise<boolean> {
73
- try {
74
- const stat = await this.fileService.resolve(uri);
75
- return !stat.isDirectory;
76
- } catch { }
77
- return false;
78
- }
79
-
80
- protected async toURI(match: string, cwd: URI): Promise<URI | undefined> {
81
- const path = await this.extractPath(match);
82
- if (!path) {
83
- return;
84
- }
85
- const pathObj = new Path(path);
86
- return pathObj.isAbsolute ? cwd.withPath(path) : cwd.resolve(path);
87
- }
88
-
89
- protected async getCwd(terminal: TerminalWidget): Promise<URI> {
90
- if (terminal instanceof TerminalWidgetImpl) {
91
- return terminal.cwd;
92
- }
93
- return terminal.lastCwd;
94
- }
95
-
96
- protected async extractPath(link: string): Promise<string | undefined> {
97
- const matches: string[] | null = (await this.createRegExp()).exec(link);
98
- if (!matches) {
99
- return undefined;
100
- }
101
- return matches[1];
102
- }
103
-
104
- async open(match: string, terminal: TerminalWidget): Promise<void> {
105
- const toOpen = await this.toURI(match, await this.getCwd(terminal));
106
- if (!toOpen) {
107
- return;
108
- }
109
- const position = await this.extractPosition(match);
110
- return this.openURI(toOpen, position);
111
- }
112
-
113
- async openURI(toOpen: URI, position: Position): Promise<void> {
114
- let options = {};
115
- if (position) {
116
- options = { selection: { start: position } };
117
- }
118
-
119
- try {
120
- const opener = await this.openerService.getOpener(toOpen, options);
121
- opener.open(toOpen, options);
122
- } catch (err) {
123
- console.error('Cannot open link ' + toOpen, err);
124
- }
125
- }
126
-
127
- protected async extractPosition(link: string): Promise<Position> {
128
- const matches: string[] | null = (await this.createRegExp()).exec(link);
129
- const info: Position = { line: 1, character: 1 };
130
-
131
- if (!matches) {
132
- return info;
133
- }
134
-
135
- const lineAndColumnMatchIndex = this.getLineAndColumnMatchIndex();
136
- for (let i = 0; i < lineAndColumnClause.length; i++) {
137
- const lineMatchIndex = lineAndColumnMatchIndex + (lineAndColumnClauseGroupCount * i);
138
- const rowNumber = matches[lineMatchIndex];
139
- if (rowNumber) {
140
- info.line = parseInt(rowNumber, 10) - 1;
141
- const columnNumber = matches[lineMatchIndex + 2];
142
- if (columnNumber) {
143
- info.character = parseInt(columnNumber, 10) - 1;
144
- }
145
- break;
146
- }
147
- }
148
-
149
- return info;
150
- }
151
-
152
- protected getLineAndColumnMatchIndex(): number {
153
- return OS.backend.isWindows ? winLineAndColumnMatchIndex : unixLineAndColumnMatchIndex;
154
- }
155
- }
156
-
157
- @injectable()
158
- export class FileDiffPreLinkProvider extends FileLinkProvider {
159
- override async createRegExp(): Promise<RegExp> {
160
- return /^--- a\/(\S*)/g;
161
- }
162
- }
163
-
164
- @injectable()
165
- export class FileDiffPostLinkProvider extends FileLinkProvider {
166
- override async createRegExp(): Promise<RegExp> {
167
- return /^\+\+\+ b\/(\S*)/g;
168
- }
169
- }
170
-
171
- @injectable()
172
- export class LocalFileLinkProvider extends FileLinkProvider {
173
- override async createRegExp(): Promise<RegExp> {
174
- // match links that might not start with a separator, e.g. 'foo.bar', but don't match single words e.g. 'foo'
175
- const baseLocalUnixLinkClause =
176
- '((' + pathPrefix + '|' +
177
- '(' + excludedPathCharactersClause + '+(' + pathSeparatorClause + '|' + '\\.' + ')' + excludedPathCharactersClause + '+))' +
178
- '(' + pathSeparatorClause + '(' + excludedPathCharactersClause + ')+)*)';
179
-
180
- const baseLocalWindowsLinkClause =
181
- '((' + winPathPrefix + '|' +
182
- '(' + winExcludedPathCharactersClause + '+(' + winPathSeparatorClause + '|' + '\\.' + ')' + winExcludedPathCharactersClause + '+))' +
183
- '(' + winPathSeparatorClause + '(' + winExcludedPathCharactersClause + ')+)*)';
184
-
185
- const baseLocalLinkClause = OS.backend.isWindows ? baseLocalWindowsLinkClause : baseLocalUnixLinkClause;
186
- return new RegExp(`${baseLocalLinkClause}(${lineAndColumnClause})`, 'g');
187
- }
188
-
189
- override async provideLinks(line: string, terminal: TerminalWidget): Promise<TerminalLink[]> {
190
- const links: TerminalLink[] = [];
191
- const regExp = await this.createRegExp();
192
- let regExpResult: RegExpExecArray | null;
193
- while (regExpResult = regExp.exec(line)) {
194
- const match = regExpResult[0];
195
- const searchTerm = await this.extractPath(match);
196
- if (searchTerm) {
197
- links.push({
198
- startIndex: regExp.lastIndex - match.length,
199
- length: match.length,
200
- handle: async () => {
201
- const fileUri = await this.isValidWorkspaceFile(searchTerm, terminal);
202
- if (fileUri) {
203
- const position = await this.extractPosition(match);
204
- this.openURI(fileUri, position);
205
- } else {
206
- this.quickInputService.open(match);
207
- }
208
- }
209
- });
210
- }
211
- }
212
- return links;
213
- }
214
-
215
- protected override getLineAndColumnMatchIndex(): number {
216
- return OS.backend.isWindows ? 14 : 12;
217
- }
218
-
219
- protected async isValidWorkspaceFile(searchTerm: string | undefined, terminal: TerminalWidget): Promise<URI | undefined> {
220
- if (!searchTerm) {
221
- return undefined;
222
- }
223
- const cwd = await this.getCwd(terminal);
224
- // remove any leading ./, ../ etc. as they can't be searched
225
- searchTerm = searchTerm.replace(/^(\.+[\\/])+/, '');
226
- const workspaceRoots = this.workspaceService.tryGetRoots().map(root => root.resource.toString());
227
- // try and find a matching file in the workspace
228
- const files = (await this.searchService.find(searchTerm, {
229
- rootUris: [cwd.toString(), ...workspaceRoots],
230
- fuzzyMatch: true,
231
- limit: 1
232
- }));
233
- // checks if the string ends in a separator + searchTerm
234
- const regex = new RegExp(`[\\\\|\\/]${searchTerm}$`);
235
- if (files.length && regex.test(files[0])) {
236
- const fileUri = new URI(files[0]);
237
- const valid = await this.isValidFileURI(fileUri);
238
- if (valid) {
239
- return fileUri;
240
- }
241
- }
242
- }
243
- }
244
-
245
- // The following regular expressions are taken from:
246
- // https://github.com/microsoft/vscode/blob/b118105bf28d773fbbce683f7230d058be2f89a7/src/vs/workbench/contrib/terminal/browser/links/terminalLocalLinkDetector.ts#L34-L58
247
-
248
- /*---------------------------------------------------------------------------------------------
249
- * Copyright (c) Microsoft Corporation. All rights reserved.
250
- * Licensed under the MIT License. See License.txt in the project root for license information.
251
- *--------------------------------------------------------------------------------------------*/
252
-
253
- const pathPrefix = '(\\.\\.?|\\~)';
254
- const pathSeparatorClause = '\\/';
255
- // '":; are allowed in paths but they are often separators so ignore them
256
- // Also disallow \\ to prevent a catastrophic backtracking case #24795
257
- const excludedPathCharactersClause = '[^\\0\\s!`&*()\\[\\]\'":;\\\\]';
258
- /** A regex that matches paths in the form /foo, ~/foo, ./foo, ../foo, foo/bar */
259
- const unixLocalLinkClause = '((' + pathPrefix + '|(' + excludedPathCharactersClause + ')+)?(' + pathSeparatorClause + '(' + excludedPathCharactersClause + ')+)+)';
260
-
261
- const winDrivePrefix = '(?:\\\\\\\\\\?\\\\)?[a-zA-Z]:';
262
- const winPathPrefix = '(' + winDrivePrefix + '|\\.\\.?|\\~)';
263
- const winPathSeparatorClause = '(\\\\|\\/)';
264
- const winExcludedPathCharactersClause = '[^\\0<>\\?\\|\\/\\s!`&*()\\[\\]\'":;]';
265
- /** A regex that matches paths in the form \\?\c:\foo c:\foo, ~\foo, .\foo, ..\foo, foo\bar */
266
- const winLocalLinkClause = '((' + winPathPrefix + '|(' + winExcludedPathCharactersClause + ')+)?(' + winPathSeparatorClause + '(' + winExcludedPathCharactersClause + ')+)+)';
267
-
268
- /** As xterm reads from DOM, space in that case is non-breaking char ASCII code - 160, replacing space with nonBreakingSpace or space ASCII code - 32. */
269
- const lineAndColumnClause = [
270
- // "(file path)", line 45 [see #40468]
271
- '((\\S*)[\'"], line ((\\d+)( column (\\d+))?))',
272
- // "(file path)",45 [see #78205]
273
- '((\\S*)[\'"],((\\d+)(:(\\d+))?))',
274
- // (file path) on line 8, column 13
275
- '((\\S*) on line ((\\d+)(, column (\\d+))?))',
276
- // (file path):line 8, column 13
277
- '((\\S*):line ((\\d+)(, column (\\d+))?))',
278
- // (file path)(45), (file path) (45), (file path)(45,18), (file path) (45,18), (file path)(45, 18), (file path) (45, 18), also with []
279
- '(([^\\s\\(\\)]*)(\\s?[\\(\\[](\\d+)(,\\s?(\\d+))?)[\\)\\]])',
280
- // (file path):336, (file path):336:9
281
- '(([^:\\s\\(\\)<>\'\"\\[\\]]*)(:(\\d+))?(:(\\d+))?)'
282
- ].join('|').replace(/ /g, `[${'\u00A0'} ]`);
283
-
284
- // Changing any regex may effect this value, hence changes this as well if required.
285
- const winLineAndColumnMatchIndex = 12;
286
- const unixLineAndColumnMatchIndex = 11;
287
-
288
- // Each line and column clause have 6 groups (ie no. of expressions in round brackets)
289
- const lineAndColumnClauseGroupCount = 6;
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { OS, Path, QuickInputService } from '@theia/core';
18
+ import { OpenerService } from '@theia/core/lib/browser';
19
+ import URI from '@theia/core/lib/common/uri';
20
+ import { inject, injectable } from '@theia/core/shared/inversify';
21
+ import { Position } from '@theia/editor/lib/browser';
22
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
23
+ import { TerminalWidget } from './base/terminal-widget';
24
+ import { TerminalLink, TerminalLinkProvider } from './terminal-link-provider';
25
+ import { TerminalWidgetImpl } from './terminal-widget-impl';
26
+ import { FileSearchService } from '@theia/file-search/lib/common/file-search-service';
27
+ import { WorkspaceService } from '@theia/workspace/lib/browser';
28
+ @injectable()
29
+ export class FileLinkProvider implements TerminalLinkProvider {
30
+
31
+ @inject(OpenerService) protected readonly openerService: OpenerService;
32
+ @inject(QuickInputService) protected readonly quickInputService: QuickInputService;
33
+ @inject(FileService) protected fileService: FileService;
34
+ @inject(FileSearchService) protected searchService: FileSearchService;
35
+ @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
36
+
37
+ async provideLinks(line: string, terminal: TerminalWidget): Promise<TerminalLink[]> {
38
+ const links: TerminalLink[] = [];
39
+ const regExp = await this.createRegExp();
40
+ let regExpResult: RegExpExecArray | null;
41
+ while (regExpResult = regExp.exec(line)) {
42
+ const match = regExpResult[0];
43
+ if (await this.isValidFile(match, terminal)) {
44
+ links.push({
45
+ startIndex: regExp.lastIndex - match.length,
46
+ length: match.length,
47
+ handle: () => this.open(match, terminal)
48
+ });
49
+ }
50
+ }
51
+ return links;
52
+ }
53
+
54
+ protected async createRegExp(): Promise<RegExp> {
55
+ const baseLocalLinkClause = OS.backend.isWindows ? winLocalLinkClause : unixLocalLinkClause;
56
+ return new RegExp(`${baseLocalLinkClause}(${lineAndColumnClause})`, 'g');
57
+ }
58
+
59
+ protected async isValidFile(match: string, terminal: TerminalWidget): Promise<boolean> {
60
+ try {
61
+ const toOpen = await this.toURI(match, await this.getCwd(terminal));
62
+ if (toOpen) {
63
+ // TODO: would be better to ask the opener service, but it returns positively even for unknown files.
64
+ return this.isValidFileURI(toOpen);
65
+ }
66
+ } catch (err) {
67
+ console.trace('Error validating ' + match, err);
68
+ }
69
+ return false;
70
+ }
71
+
72
+ protected async isValidFileURI(uri: URI): Promise<boolean> {
73
+ try {
74
+ const stat = await this.fileService.resolve(uri);
75
+ return !stat.isDirectory;
76
+ } catch { }
77
+ return false;
78
+ }
79
+
80
+ protected async toURI(match: string, cwd: URI): Promise<URI | undefined> {
81
+ const path = await this.extractPath(match);
82
+ if (!path) {
83
+ return;
84
+ }
85
+ const pathObj = new Path(path);
86
+ return pathObj.isAbsolute ? cwd.withPath(path) : cwd.resolve(path);
87
+ }
88
+
89
+ protected async getCwd(terminal: TerminalWidget): Promise<URI> {
90
+ if (terminal instanceof TerminalWidgetImpl) {
91
+ return terminal.cwd;
92
+ }
93
+ return terminal.lastCwd;
94
+ }
95
+
96
+ protected async extractPath(link: string): Promise<string | undefined> {
97
+ const matches: string[] | null = (await this.createRegExp()).exec(link);
98
+ if (!matches) {
99
+ return undefined;
100
+ }
101
+ return matches[1];
102
+ }
103
+
104
+ async open(match: string, terminal: TerminalWidget): Promise<void> {
105
+ const toOpen = await this.toURI(match, await this.getCwd(terminal));
106
+ if (!toOpen) {
107
+ return;
108
+ }
109
+ const position = await this.extractPosition(match);
110
+ return this.openURI(toOpen, position);
111
+ }
112
+
113
+ async openURI(toOpen: URI, position: Position): Promise<void> {
114
+ let options = {};
115
+ if (position) {
116
+ options = { selection: { start: position } };
117
+ }
118
+
119
+ try {
120
+ const opener = await this.openerService.getOpener(toOpen, options);
121
+ opener.open(toOpen, options);
122
+ } catch (err) {
123
+ console.error('Cannot open link ' + toOpen, err);
124
+ }
125
+ }
126
+
127
+ protected async extractPosition(link: string): Promise<Position> {
128
+ const matches: string[] | null = (await this.createRegExp()).exec(link);
129
+ const info: Position = { line: 1, character: 1 };
130
+
131
+ if (!matches) {
132
+ return info;
133
+ }
134
+
135
+ const lineAndColumnMatchIndex = this.getLineAndColumnMatchIndex();
136
+ for (let i = 0; i < lineAndColumnClause.length; i++) {
137
+ const lineMatchIndex = lineAndColumnMatchIndex + (lineAndColumnClauseGroupCount * i);
138
+ const rowNumber = matches[lineMatchIndex];
139
+ if (rowNumber) {
140
+ info.line = parseInt(rowNumber, 10) - 1;
141
+ const columnNumber = matches[lineMatchIndex + 2];
142
+ if (columnNumber) {
143
+ info.character = parseInt(columnNumber, 10) - 1;
144
+ }
145
+ break;
146
+ }
147
+ }
148
+
149
+ return info;
150
+ }
151
+
152
+ protected getLineAndColumnMatchIndex(): number {
153
+ return OS.backend.isWindows ? winLineAndColumnMatchIndex : unixLineAndColumnMatchIndex;
154
+ }
155
+ }
156
+
157
+ @injectable()
158
+ export class FileDiffPreLinkProvider extends FileLinkProvider {
159
+ override async createRegExp(): Promise<RegExp> {
160
+ return /^--- a\/(\S*)/g;
161
+ }
162
+ }
163
+
164
+ @injectable()
165
+ export class FileDiffPostLinkProvider extends FileLinkProvider {
166
+ override async createRegExp(): Promise<RegExp> {
167
+ return /^\+\+\+ b\/(\S*)/g;
168
+ }
169
+ }
170
+
171
+ @injectable()
172
+ export class LocalFileLinkProvider extends FileLinkProvider {
173
+ override async createRegExp(): Promise<RegExp> {
174
+ // match links that might not start with a separator, e.g. 'foo.bar', but don't match single words e.g. 'foo'
175
+ const baseLocalUnixLinkClause =
176
+ '((' + pathPrefix + '|' +
177
+ '(' + excludedPathCharactersClause + '+(' + pathSeparatorClause + '|' + '\\.' + ')' + excludedPathCharactersClause + '+))' +
178
+ '(' + pathSeparatorClause + '(' + excludedPathCharactersClause + ')+)*)';
179
+
180
+ const baseLocalWindowsLinkClause =
181
+ '((' + winPathPrefix + '|' +
182
+ '(' + winExcludedPathCharactersClause + '+(' + winPathSeparatorClause + '|' + '\\.' + ')' + winExcludedPathCharactersClause + '+))' +
183
+ '(' + winPathSeparatorClause + '(' + winExcludedPathCharactersClause + ')+)*)';
184
+
185
+ const baseLocalLinkClause = OS.backend.isWindows ? baseLocalWindowsLinkClause : baseLocalUnixLinkClause;
186
+ return new RegExp(`${baseLocalLinkClause}(${lineAndColumnClause})`, 'g');
187
+ }
188
+
189
+ override async provideLinks(line: string, terminal: TerminalWidget): Promise<TerminalLink[]> {
190
+ const links: TerminalLink[] = [];
191
+ const regExp = await this.createRegExp();
192
+ let regExpResult: RegExpExecArray | null;
193
+ while (regExpResult = regExp.exec(line)) {
194
+ const match = regExpResult[0];
195
+ const searchTerm = await this.extractPath(match);
196
+ if (searchTerm) {
197
+ links.push({
198
+ startIndex: regExp.lastIndex - match.length,
199
+ length: match.length,
200
+ handle: async () => {
201
+ const fileUri = await this.isValidWorkspaceFile(searchTerm, terminal);
202
+ if (fileUri) {
203
+ const position = await this.extractPosition(match);
204
+ this.openURI(fileUri, position);
205
+ } else {
206
+ this.quickInputService.open(match);
207
+ }
208
+ }
209
+ });
210
+ }
211
+ }
212
+ return links;
213
+ }
214
+
215
+ protected override getLineAndColumnMatchIndex(): number {
216
+ return OS.backend.isWindows ? 14 : 12;
217
+ }
218
+
219
+ protected async isValidWorkspaceFile(searchTerm: string | undefined, terminal: TerminalWidget): Promise<URI | undefined> {
220
+ if (!searchTerm) {
221
+ return undefined;
222
+ }
223
+ const cwd = await this.getCwd(terminal);
224
+ // remove any leading ./, ../ etc. as they can't be searched
225
+ searchTerm = searchTerm.replace(/^(\.+[\\/])+/, '');
226
+ const workspaceRoots = this.workspaceService.tryGetRoots().map(root => root.resource.toString());
227
+ // try and find a matching file in the workspace
228
+ const files = (await this.searchService.find(searchTerm, {
229
+ rootUris: [cwd.toString(), ...workspaceRoots],
230
+ fuzzyMatch: true,
231
+ limit: 1
232
+ }));
233
+ // checks if the string ends in a separator + searchTerm
234
+ const regex = new RegExp(`[\\\\|\\/]${searchTerm}$`);
235
+ if (files.length && regex.test(files[0])) {
236
+ const fileUri = new URI(files[0]);
237
+ const valid = await this.isValidFileURI(fileUri);
238
+ if (valid) {
239
+ return fileUri;
240
+ }
241
+ }
242
+ }
243
+ }
244
+
245
+ // The following regular expressions are taken from:
246
+ // https://github.com/microsoft/vscode/blob/b118105bf28d773fbbce683f7230d058be2f89a7/src/vs/workbench/contrib/terminal/browser/links/terminalLocalLinkDetector.ts#L34-L58
247
+
248
+ /*---------------------------------------------------------------------------------------------
249
+ * Copyright (c) Microsoft Corporation. All rights reserved.
250
+ * Licensed under the MIT License. See License.txt in the project root for license information.
251
+ *--------------------------------------------------------------------------------------------*/
252
+
253
+ const pathPrefix = '(\\.\\.?|\\~)';
254
+ const pathSeparatorClause = '\\/';
255
+ // '":; are allowed in paths but they are often separators so ignore them
256
+ // Also disallow \\ to prevent a catastrophic backtracking case #24795
257
+ const excludedPathCharactersClause = '[^\\0\\s!`&*()\\[\\]\'":;\\\\]';
258
+ /** A regex that matches paths in the form /foo, ~/foo, ./foo, ../foo, foo/bar */
259
+ const unixLocalLinkClause = '((' + pathPrefix + '|(' + excludedPathCharactersClause + ')+)?(' + pathSeparatorClause + '(' + excludedPathCharactersClause + ')+)+)';
260
+
261
+ const winDrivePrefix = '(?:\\\\\\\\\\?\\\\)?[a-zA-Z]:';
262
+ const winPathPrefix = '(' + winDrivePrefix + '|\\.\\.?|\\~)';
263
+ const winPathSeparatorClause = '(\\\\|\\/)';
264
+ const winExcludedPathCharactersClause = '[^\\0<>\\?\\|\\/\\s!`&*()\\[\\]\'":;]';
265
+ /** A regex that matches paths in the form \\?\c:\foo c:\foo, ~\foo, .\foo, ..\foo, foo\bar */
266
+ const winLocalLinkClause = '((' + winPathPrefix + '|(' + winExcludedPathCharactersClause + ')+)?(' + winPathSeparatorClause + '(' + winExcludedPathCharactersClause + ')+)+)';
267
+
268
+ /** As xterm reads from DOM, space in that case is non-breaking char ASCII code - 160, replacing space with nonBreakingSpace or space ASCII code - 32. */
269
+ const lineAndColumnClause = [
270
+ // "(file path)", line 45 [see #40468]
271
+ '((\\S*)[\'"], line ((\\d+)( column (\\d+))?))',
272
+ // "(file path)",45 [see #78205]
273
+ '((\\S*)[\'"],((\\d+)(:(\\d+))?))',
274
+ // (file path) on line 8, column 13
275
+ '((\\S*) on line ((\\d+)(, column (\\d+))?))',
276
+ // (file path):line 8, column 13
277
+ '((\\S*):line ((\\d+)(, column (\\d+))?))',
278
+ // (file path)(45), (file path) (45), (file path)(45,18), (file path) (45,18), (file path)(45, 18), (file path) (45, 18), also with []
279
+ '(([^\\s\\(\\)]*)(\\s?[\\(\\[](\\d+)(,\\s?(\\d+))?)[\\)\\]])',
280
+ // (file path):336, (file path):336:9
281
+ '(([^:\\s\\(\\)<>\'\"\\[\\]]*)(:(\\d+))?(:(\\d+))?)'
282
+ ].join('|').replace(/ /g, `[${'\u00A0'} ]`);
283
+
284
+ // Changing any regex may effect this value, hence changes this as well if required.
285
+ const winLineAndColumnMatchIndex = 12;
286
+ const unixLineAndColumnMatchIndex = 11;
287
+
288
+ // Each line and column clause have 6 groups (ie no. of expressions in round brackets)
289
+ const lineAndColumnClauseGroupCount = 6;