@codingame/monaco-vscode-search-result-default-extension 1.81.8-next.1

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.
package/extension.js ADDED
@@ -0,0 +1,806 @@
1
+ /******/ (() => { // webpackBootstrap
2
+ /******/ "use strict";
3
+ /******/ var __webpack_modules__ = ([
4
+ /* 0 */,
5
+ /* 1 */
6
+ /***/ ((module) => {
7
+
8
+ module.exports = require("vscode");
9
+
10
+ /***/ }),
11
+ /* 2 */
12
+ /***/ ((module) => {
13
+
14
+ // 'path' module extracted from Node.js v8.11.1 (only the posix part)
15
+ // transplited with Babel
16
+
17
+ // Copyright Joyent, Inc. and other Node contributors.
18
+ //
19
+ // Permission is hereby granted, free of charge, to any person obtaining a
20
+ // copy of this software and associated documentation files (the
21
+ // "Software"), to deal in the Software without restriction, including
22
+ // without limitation the rights to use, copy, modify, merge, publish,
23
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
24
+ // persons to whom the Software is furnished to do so, subject to the
25
+ // following conditions:
26
+ //
27
+ // The above copyright notice and this permission notice shall be included
28
+ // in all copies or substantial portions of the Software.
29
+ //
30
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
31
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
33
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
35
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
36
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
37
+
38
+
39
+
40
+ function assertPath(path) {
41
+ if (typeof path !== 'string') {
42
+ throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
43
+ }
44
+ }
45
+
46
+ // Resolves . and .. elements in a path with directory names
47
+ function normalizeStringPosix(path, allowAboveRoot) {
48
+ var res = '';
49
+ var lastSegmentLength = 0;
50
+ var lastSlash = -1;
51
+ var dots = 0;
52
+ var code;
53
+ for (var i = 0; i <= path.length; ++i) {
54
+ if (i < path.length)
55
+ code = path.charCodeAt(i);
56
+ else if (code === 47 /*/*/)
57
+ break;
58
+ else
59
+ code = 47 /*/*/;
60
+ if (code === 47 /*/*/) {
61
+ if (lastSlash === i - 1 || dots === 1) {
62
+ // NOOP
63
+ } else if (lastSlash !== i - 1 && dots === 2) {
64
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
65
+ if (res.length > 2) {
66
+ var lastSlashIndex = res.lastIndexOf('/');
67
+ if (lastSlashIndex !== res.length - 1) {
68
+ if (lastSlashIndex === -1) {
69
+ res = '';
70
+ lastSegmentLength = 0;
71
+ } else {
72
+ res = res.slice(0, lastSlashIndex);
73
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
74
+ }
75
+ lastSlash = i;
76
+ dots = 0;
77
+ continue;
78
+ }
79
+ } else if (res.length === 2 || res.length === 1) {
80
+ res = '';
81
+ lastSegmentLength = 0;
82
+ lastSlash = i;
83
+ dots = 0;
84
+ continue;
85
+ }
86
+ }
87
+ if (allowAboveRoot) {
88
+ if (res.length > 0)
89
+ res += '/..';
90
+ else
91
+ res = '..';
92
+ lastSegmentLength = 2;
93
+ }
94
+ } else {
95
+ if (res.length > 0)
96
+ res += '/' + path.slice(lastSlash + 1, i);
97
+ else
98
+ res = path.slice(lastSlash + 1, i);
99
+ lastSegmentLength = i - lastSlash - 1;
100
+ }
101
+ lastSlash = i;
102
+ dots = 0;
103
+ } else if (code === 46 /*.*/ && dots !== -1) {
104
+ ++dots;
105
+ } else {
106
+ dots = -1;
107
+ }
108
+ }
109
+ return res;
110
+ }
111
+
112
+ function _format(sep, pathObject) {
113
+ var dir = pathObject.dir || pathObject.root;
114
+ var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
115
+ if (!dir) {
116
+ return base;
117
+ }
118
+ if (dir === pathObject.root) {
119
+ return dir + base;
120
+ }
121
+ return dir + sep + base;
122
+ }
123
+
124
+ var posix = {
125
+ // path.resolve([from ...], to)
126
+ resolve: function resolve() {
127
+ var resolvedPath = '';
128
+ var resolvedAbsolute = false;
129
+ var cwd;
130
+
131
+ for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
132
+ var path;
133
+ if (i >= 0)
134
+ path = arguments[i];
135
+ else {
136
+ if (cwd === undefined)
137
+ cwd = process.cwd();
138
+ path = cwd;
139
+ }
140
+
141
+ assertPath(path);
142
+
143
+ // Skip empty entries
144
+ if (path.length === 0) {
145
+ continue;
146
+ }
147
+
148
+ resolvedPath = path + '/' + resolvedPath;
149
+ resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
150
+ }
151
+
152
+ // At this point the path should be resolved to a full absolute path, but
153
+ // handle relative paths to be safe (might happen when process.cwd() fails)
154
+
155
+ // Normalize the path
156
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
157
+
158
+ if (resolvedAbsolute) {
159
+ if (resolvedPath.length > 0)
160
+ return '/' + resolvedPath;
161
+ else
162
+ return '/';
163
+ } else if (resolvedPath.length > 0) {
164
+ return resolvedPath;
165
+ } else {
166
+ return '.';
167
+ }
168
+ },
169
+
170
+ normalize: function normalize(path) {
171
+ assertPath(path);
172
+
173
+ if (path.length === 0) return '.';
174
+
175
+ var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
176
+ var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
177
+
178
+ // Normalize the path
179
+ path = normalizeStringPosix(path, !isAbsolute);
180
+
181
+ if (path.length === 0 && !isAbsolute) path = '.';
182
+ if (path.length > 0 && trailingSeparator) path += '/';
183
+
184
+ if (isAbsolute) return '/' + path;
185
+ return path;
186
+ },
187
+
188
+ isAbsolute: function isAbsolute(path) {
189
+ assertPath(path);
190
+ return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
191
+ },
192
+
193
+ join: function join() {
194
+ if (arguments.length === 0)
195
+ return '.';
196
+ var joined;
197
+ for (var i = 0; i < arguments.length; ++i) {
198
+ var arg = arguments[i];
199
+ assertPath(arg);
200
+ if (arg.length > 0) {
201
+ if (joined === undefined)
202
+ joined = arg;
203
+ else
204
+ joined += '/' + arg;
205
+ }
206
+ }
207
+ if (joined === undefined)
208
+ return '.';
209
+ return posix.normalize(joined);
210
+ },
211
+
212
+ relative: function relative(from, to) {
213
+ assertPath(from);
214
+ assertPath(to);
215
+
216
+ if (from === to) return '';
217
+
218
+ from = posix.resolve(from);
219
+ to = posix.resolve(to);
220
+
221
+ if (from === to) return '';
222
+
223
+ // Trim any leading backslashes
224
+ var fromStart = 1;
225
+ for (; fromStart < from.length; ++fromStart) {
226
+ if (from.charCodeAt(fromStart) !== 47 /*/*/)
227
+ break;
228
+ }
229
+ var fromEnd = from.length;
230
+ var fromLen = fromEnd - fromStart;
231
+
232
+ // Trim any leading backslashes
233
+ var toStart = 1;
234
+ for (; toStart < to.length; ++toStart) {
235
+ if (to.charCodeAt(toStart) !== 47 /*/*/)
236
+ break;
237
+ }
238
+ var toEnd = to.length;
239
+ var toLen = toEnd - toStart;
240
+
241
+ // Compare paths to find the longest common path from root
242
+ var length = fromLen < toLen ? fromLen : toLen;
243
+ var lastCommonSep = -1;
244
+ var i = 0;
245
+ for (; i <= length; ++i) {
246
+ if (i === length) {
247
+ if (toLen > length) {
248
+ if (to.charCodeAt(toStart + i) === 47 /*/*/) {
249
+ // We get here if `from` is the exact base path for `to`.
250
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
251
+ return to.slice(toStart + i + 1);
252
+ } else if (i === 0) {
253
+ // We get here if `from` is the root
254
+ // For example: from='/'; to='/foo'
255
+ return to.slice(toStart + i);
256
+ }
257
+ } else if (fromLen > length) {
258
+ if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
259
+ // We get here if `to` is the exact base path for `from`.
260
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
261
+ lastCommonSep = i;
262
+ } else if (i === 0) {
263
+ // We get here if `to` is the root.
264
+ // For example: from='/foo'; to='/'
265
+ lastCommonSep = 0;
266
+ }
267
+ }
268
+ break;
269
+ }
270
+ var fromCode = from.charCodeAt(fromStart + i);
271
+ var toCode = to.charCodeAt(toStart + i);
272
+ if (fromCode !== toCode)
273
+ break;
274
+ else if (fromCode === 47 /*/*/)
275
+ lastCommonSep = i;
276
+ }
277
+
278
+ var out = '';
279
+ // Generate the relative path based on the path difference between `to`
280
+ // and `from`
281
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
282
+ if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
283
+ if (out.length === 0)
284
+ out += '..';
285
+ else
286
+ out += '/..';
287
+ }
288
+ }
289
+
290
+ // Lastly, append the rest of the destination (`to`) path that comes after
291
+ // the common path parts
292
+ if (out.length > 0)
293
+ return out + to.slice(toStart + lastCommonSep);
294
+ else {
295
+ toStart += lastCommonSep;
296
+ if (to.charCodeAt(toStart) === 47 /*/*/)
297
+ ++toStart;
298
+ return to.slice(toStart);
299
+ }
300
+ },
301
+
302
+ _makeLong: function _makeLong(path) {
303
+ return path;
304
+ },
305
+
306
+ dirname: function dirname(path) {
307
+ assertPath(path);
308
+ if (path.length === 0) return '.';
309
+ var code = path.charCodeAt(0);
310
+ var hasRoot = code === 47 /*/*/;
311
+ var end = -1;
312
+ var matchedSlash = true;
313
+ for (var i = path.length - 1; i >= 1; --i) {
314
+ code = path.charCodeAt(i);
315
+ if (code === 47 /*/*/) {
316
+ if (!matchedSlash) {
317
+ end = i;
318
+ break;
319
+ }
320
+ } else {
321
+ // We saw the first non-path separator
322
+ matchedSlash = false;
323
+ }
324
+ }
325
+
326
+ if (end === -1) return hasRoot ? '/' : '.';
327
+ if (hasRoot && end === 1) return '//';
328
+ return path.slice(0, end);
329
+ },
330
+
331
+ basename: function basename(path, ext) {
332
+ if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
333
+ assertPath(path);
334
+
335
+ var start = 0;
336
+ var end = -1;
337
+ var matchedSlash = true;
338
+ var i;
339
+
340
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
341
+ if (ext.length === path.length && ext === path) return '';
342
+ var extIdx = ext.length - 1;
343
+ var firstNonSlashEnd = -1;
344
+ for (i = path.length - 1; i >= 0; --i) {
345
+ var code = path.charCodeAt(i);
346
+ if (code === 47 /*/*/) {
347
+ // If we reached a path separator that was not part of a set of path
348
+ // separators at the end of the string, stop now
349
+ if (!matchedSlash) {
350
+ start = i + 1;
351
+ break;
352
+ }
353
+ } else {
354
+ if (firstNonSlashEnd === -1) {
355
+ // We saw the first non-path separator, remember this index in case
356
+ // we need it if the extension ends up not matching
357
+ matchedSlash = false;
358
+ firstNonSlashEnd = i + 1;
359
+ }
360
+ if (extIdx >= 0) {
361
+ // Try to match the explicit extension
362
+ if (code === ext.charCodeAt(extIdx)) {
363
+ if (--extIdx === -1) {
364
+ // We matched the extension, so mark this as the end of our path
365
+ // component
366
+ end = i;
367
+ }
368
+ } else {
369
+ // Extension does not match, so our result is the entire path
370
+ // component
371
+ extIdx = -1;
372
+ end = firstNonSlashEnd;
373
+ }
374
+ }
375
+ }
376
+ }
377
+
378
+ if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
379
+ return path.slice(start, end);
380
+ } else {
381
+ for (i = path.length - 1; i >= 0; --i) {
382
+ if (path.charCodeAt(i) === 47 /*/*/) {
383
+ // If we reached a path separator that was not part of a set of path
384
+ // separators at the end of the string, stop now
385
+ if (!matchedSlash) {
386
+ start = i + 1;
387
+ break;
388
+ }
389
+ } else if (end === -1) {
390
+ // We saw the first non-path separator, mark this as the end of our
391
+ // path component
392
+ matchedSlash = false;
393
+ end = i + 1;
394
+ }
395
+ }
396
+
397
+ if (end === -1) return '';
398
+ return path.slice(start, end);
399
+ }
400
+ },
401
+
402
+ extname: function extname(path) {
403
+ assertPath(path);
404
+ var startDot = -1;
405
+ var startPart = 0;
406
+ var end = -1;
407
+ var matchedSlash = true;
408
+ // Track the state of characters (if any) we see before our first dot and
409
+ // after any path separator we find
410
+ var preDotState = 0;
411
+ for (var i = path.length - 1; i >= 0; --i) {
412
+ var code = path.charCodeAt(i);
413
+ if (code === 47 /*/*/) {
414
+ // If we reached a path separator that was not part of a set of path
415
+ // separators at the end of the string, stop now
416
+ if (!matchedSlash) {
417
+ startPart = i + 1;
418
+ break;
419
+ }
420
+ continue;
421
+ }
422
+ if (end === -1) {
423
+ // We saw the first non-path separator, mark this as the end of our
424
+ // extension
425
+ matchedSlash = false;
426
+ end = i + 1;
427
+ }
428
+ if (code === 46 /*.*/) {
429
+ // If this is our first dot, mark it as the start of our extension
430
+ if (startDot === -1)
431
+ startDot = i;
432
+ else if (preDotState !== 1)
433
+ preDotState = 1;
434
+ } else if (startDot !== -1) {
435
+ // We saw a non-dot and non-path separator before our dot, so we should
436
+ // have a good chance at having a non-empty extension
437
+ preDotState = -1;
438
+ }
439
+ }
440
+
441
+ if (startDot === -1 || end === -1 ||
442
+ // We saw a non-dot character immediately before the dot
443
+ preDotState === 0 ||
444
+ // The (right-most) trimmed path component is exactly '..'
445
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
446
+ return '';
447
+ }
448
+ return path.slice(startDot, end);
449
+ },
450
+
451
+ format: function format(pathObject) {
452
+ if (pathObject === null || typeof pathObject !== 'object') {
453
+ throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
454
+ }
455
+ return _format('/', pathObject);
456
+ },
457
+
458
+ parse: function parse(path) {
459
+ assertPath(path);
460
+
461
+ var ret = { root: '', dir: '', base: '', ext: '', name: '' };
462
+ if (path.length === 0) return ret;
463
+ var code = path.charCodeAt(0);
464
+ var isAbsolute = code === 47 /*/*/;
465
+ var start;
466
+ if (isAbsolute) {
467
+ ret.root = '/';
468
+ start = 1;
469
+ } else {
470
+ start = 0;
471
+ }
472
+ var startDot = -1;
473
+ var startPart = 0;
474
+ var end = -1;
475
+ var matchedSlash = true;
476
+ var i = path.length - 1;
477
+
478
+ // Track the state of characters (if any) we see before our first dot and
479
+ // after any path separator we find
480
+ var preDotState = 0;
481
+
482
+ // Get non-dir info
483
+ for (; i >= start; --i) {
484
+ code = path.charCodeAt(i);
485
+ if (code === 47 /*/*/) {
486
+ // If we reached a path separator that was not part of a set of path
487
+ // separators at the end of the string, stop now
488
+ if (!matchedSlash) {
489
+ startPart = i + 1;
490
+ break;
491
+ }
492
+ continue;
493
+ }
494
+ if (end === -1) {
495
+ // We saw the first non-path separator, mark this as the end of our
496
+ // extension
497
+ matchedSlash = false;
498
+ end = i + 1;
499
+ }
500
+ if (code === 46 /*.*/) {
501
+ // If this is our first dot, mark it as the start of our extension
502
+ if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
503
+ } else if (startDot !== -1) {
504
+ // We saw a non-dot and non-path separator before our dot, so we should
505
+ // have a good chance at having a non-empty extension
506
+ preDotState = -1;
507
+ }
508
+ }
509
+
510
+ if (startDot === -1 || end === -1 ||
511
+ // We saw a non-dot character immediately before the dot
512
+ preDotState === 0 ||
513
+ // The (right-most) trimmed path component is exactly '..'
514
+ preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
515
+ if (end !== -1) {
516
+ if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
517
+ }
518
+ } else {
519
+ if (startPart === 0 && isAbsolute) {
520
+ ret.name = path.slice(1, startDot);
521
+ ret.base = path.slice(1, end);
522
+ } else {
523
+ ret.name = path.slice(startPart, startDot);
524
+ ret.base = path.slice(startPart, end);
525
+ }
526
+ ret.ext = path.slice(startDot, end);
527
+ }
528
+
529
+ if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
530
+
531
+ return ret;
532
+ },
533
+
534
+ sep: '/',
535
+ delimiter: ':',
536
+ win32: null,
537
+ posix: null
538
+ };
539
+
540
+ posix.posix = posix;
541
+
542
+ module.exports = posix;
543
+
544
+
545
+ /***/ })
546
+ /******/ ]);
547
+ /************************************************************************/
548
+ /******/ // The module cache
549
+ /******/ var __webpack_module_cache__ = {};
550
+ /******/
551
+ /******/ // The require function
552
+ /******/ function __webpack_require__(moduleId) {
553
+ /******/ // Check if module is in cache
554
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
555
+ /******/ if (cachedModule !== undefined) {
556
+ /******/ return cachedModule.exports;
557
+ /******/ }
558
+ /******/ // Create a new module (and put it into the cache)
559
+ /******/ var module = __webpack_module_cache__[moduleId] = {
560
+ /******/ // no module.id needed
561
+ /******/ // no module.loaded needed
562
+ /******/ exports: {}
563
+ /******/ };
564
+ /******/
565
+ /******/ // Execute the module function
566
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
567
+ /******/
568
+ /******/ // Return the exports of the module
569
+ /******/ return module.exports;
570
+ /******/ }
571
+ /******/
572
+ /************************************************************************/
573
+ var __webpack_exports__ = {};
574
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
575
+ (() => {
576
+ var exports = __webpack_exports__;
577
+
578
+ /*---------------------------------------------------------------------------------------------
579
+ * Copyright (c) Microsoft Corporation. All rights reserved.
580
+ * Licensed under the MIT License. See License.txt in the project root for license information.
581
+ *--------------------------------------------------------------------------------------------*/
582
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
583
+ exports.activate = void 0;
584
+ const vscode = __webpack_require__(1);
585
+ const pathUtils = __webpack_require__(2);
586
+ const FILE_LINE_REGEX = /^(\S.*):$/;
587
+ const RESULT_LINE_REGEX = /^(\s+)(\d+)(: | )(\s*)(.*)$/;
588
+ const ELISION_REGEX = /⟪ ([0-9]+) characters skipped ⟫/g;
589
+ const SEARCH_RESULT_SELECTOR = { language: 'search-result', exclusive: true };
590
+ const DIRECTIVES = ['# Query:', '# Flags:', '# Including:', '# Excluding:', '# ContextLines:'];
591
+ const FLAGS = ['RegExp', 'CaseSensitive', 'IgnoreExcludeSettings', 'WordMatch'];
592
+ let cachedLastParse;
593
+ let documentChangeListener;
594
+ function activate(context) {
595
+ const contextLineDecorations = vscode.window.createTextEditorDecorationType({ opacity: '0.7' });
596
+ const matchLineDecorations = vscode.window.createTextEditorDecorationType({ fontWeight: 'bold' });
597
+ const decorate = (editor) => {
598
+ const parsed = parseSearchResults(editor.document).filter(isResultLine);
599
+ const contextRanges = parsed.filter(line => line.isContext).map(line => line.prefixRange);
600
+ const matchRanges = parsed.filter(line => !line.isContext).map(line => line.prefixRange);
601
+ editor.setDecorations(contextLineDecorations, contextRanges);
602
+ editor.setDecorations(matchLineDecorations, matchRanges);
603
+ };
604
+ if (vscode.window.activeTextEditor && vscode.window.activeTextEditor.document.languageId === 'search-result') {
605
+ decorate(vscode.window.activeTextEditor);
606
+ }
607
+ context.subscriptions.push(vscode.languages.registerDocumentSymbolProvider(SEARCH_RESULT_SELECTOR, {
608
+ provideDocumentSymbols(document, token) {
609
+ const results = parseSearchResults(document, token)
610
+ .filter(isFileLine)
611
+ .map(line => new vscode.DocumentSymbol(line.path, '', vscode.SymbolKind.File, line.allLocations.map(({ originSelectionRange }) => originSelectionRange).reduce((p, c) => p.union(c), line.location.originSelectionRange), line.location.originSelectionRange));
612
+ return results;
613
+ }
614
+ }), vscode.languages.registerCompletionItemProvider(SEARCH_RESULT_SELECTOR, {
615
+ provideCompletionItems(document, position) {
616
+ const line = document.lineAt(position.line);
617
+ if (position.line > 3) {
618
+ return [];
619
+ }
620
+ if (position.character === 0 || (position.character === 1 && line.text === '#')) {
621
+ const header = Array.from({ length: DIRECTIVES.length }).map((_, i) => document.lineAt(i).text);
622
+ return DIRECTIVES
623
+ .filter(suggestion => header.every(line => line.indexOf(suggestion) === -1))
624
+ .map(flag => ({ label: flag, insertText: (flag.slice(position.character)) + ' ' }));
625
+ }
626
+ if (line.text.indexOf('# Flags:') === -1) {
627
+ return [];
628
+ }
629
+ return FLAGS
630
+ .filter(flag => line.text.indexOf(flag) === -1)
631
+ .map(flag => ({ label: flag, insertText: flag + ' ' }));
632
+ }
633
+ }, '#'), vscode.languages.registerDefinitionProvider(SEARCH_RESULT_SELECTOR, {
634
+ provideDefinition(document, position, token) {
635
+ const lineResult = parseSearchResults(document, token)[position.line];
636
+ if (!lineResult) {
637
+ return [];
638
+ }
639
+ if (lineResult.type === 'file') {
640
+ return lineResult.allLocations.map(l => ({ ...l, originSelectionRange: lineResult.location.originSelectionRange }));
641
+ }
642
+ const location = lineResult.locations.find(l => l.originSelectionRange.contains(position));
643
+ if (!location) {
644
+ return [];
645
+ }
646
+ const targetPos = new vscode.Position(location.targetSelectionRange.start.line, location.targetSelectionRange.start.character + (position.character - location.originSelectionRange.start.character));
647
+ return [{
648
+ ...location,
649
+ targetSelectionRange: new vscode.Range(targetPos, targetPos),
650
+ }];
651
+ }
652
+ }), vscode.languages.registerDocumentLinkProvider(SEARCH_RESULT_SELECTOR, {
653
+ async provideDocumentLinks(document, token) {
654
+ return parseSearchResults(document, token)
655
+ .filter(isFileLine)
656
+ .map(({ location }) => ({ range: location.originSelectionRange, target: location.targetUri }));
657
+ }
658
+ }), vscode.window.onDidChangeActiveTextEditor(editor => {
659
+ if (editor?.document.languageId === 'search-result') {
660
+ // Clear the parse whenever we open a new editor.
661
+ // Conservative because things like the URI might remain constant even if the contents change, and re-parsing even large files is relatively fast.
662
+ cachedLastParse = undefined;
663
+ documentChangeListener?.dispose();
664
+ documentChangeListener = vscode.workspace.onDidChangeTextDocument(doc => {
665
+ if (doc.document.uri === editor.document.uri) {
666
+ decorate(editor);
667
+ }
668
+ });
669
+ decorate(editor);
670
+ }
671
+ }), { dispose() { cachedLastParse = undefined; documentChangeListener?.dispose(); } });
672
+ }
673
+ exports.activate = activate;
674
+ function relativePathToUri(path, resultsUri) {
675
+ const userDataPrefix = '(Settings) ';
676
+ if (path.startsWith(userDataPrefix)) {
677
+ return vscode.Uri.file(path.slice(userDataPrefix.length)).with({ scheme: 'vscode-userdata' });
678
+ }
679
+ if (pathUtils.isAbsolute(path)) {
680
+ if (/^[\\\/]Untitled-\d*$/.test(path)) {
681
+ return vscode.Uri.file(path.slice(1)).with({ scheme: 'untitled', path: path.slice(1) });
682
+ }
683
+ return vscode.Uri.file(path);
684
+ }
685
+ if (path.indexOf('~/') === 0) {
686
+ const homePath = {}.HOME || {}.HOMEPATH || '';
687
+ return vscode.Uri.file(pathUtils.join(homePath, path.slice(2)));
688
+ }
689
+ const uriFromFolderWithPath = (folder, path) => vscode.Uri.joinPath(folder.uri, path);
690
+ if (vscode.workspace.workspaceFolders) {
691
+ const multiRootFormattedPath = /^(.*) • (.*)$/.exec(path);
692
+ if (multiRootFormattedPath) {
693
+ const [, workspaceName, workspacePath] = multiRootFormattedPath;
694
+ const folder = vscode.workspace.workspaceFolders.filter(wf => wf.name === workspaceName)[0];
695
+ if (folder) {
696
+ return uriFromFolderWithPath(folder, workspacePath);
697
+ }
698
+ }
699
+ else if (vscode.workspace.workspaceFolders.length === 1) {
700
+ return uriFromFolderWithPath(vscode.workspace.workspaceFolders[0], path);
701
+ }
702
+ else if (resultsUri.scheme !== 'untitled') {
703
+ // We're in a multi-root workspace, but the path is not multi-root formatted
704
+ // Possibly a saved search from a single root session. Try checking if the search result document's URI is in a current workspace folder.
705
+ const prefixMatch = vscode.workspace.workspaceFolders.filter(wf => resultsUri.toString().startsWith(wf.uri.toString()))[0];
706
+ if (prefixMatch) {
707
+ return uriFromFolderWithPath(prefixMatch, path);
708
+ }
709
+ }
710
+ }
711
+ console.error(`Unable to resolve path ${path}`);
712
+ return undefined;
713
+ }
714
+ const isFileLine = (line) => line.type === 'file';
715
+ const isResultLine = (line) => line.type === 'result';
716
+ function parseSearchResults(document, token) {
717
+ if (cachedLastParse && cachedLastParse.uri === document.uri && cachedLastParse.version === document.version) {
718
+ return cachedLastParse.parse;
719
+ }
720
+ const lines = document.getText().split(/\r?\n/);
721
+ const links = [];
722
+ let currentTarget = undefined;
723
+ let currentTargetLocations = undefined;
724
+ for (let i = 0; i < lines.length; i++) {
725
+ // TODO: This is probably always false, given we're pegging the thread...
726
+ if (token?.isCancellationRequested) {
727
+ return [];
728
+ }
729
+ const line = lines[i];
730
+ const fileLine = FILE_LINE_REGEX.exec(line);
731
+ if (fileLine) {
732
+ const [, path] = fileLine;
733
+ currentTarget = relativePathToUri(path, document.uri);
734
+ if (!currentTarget) {
735
+ continue;
736
+ }
737
+ currentTargetLocations = [];
738
+ const location = {
739
+ targetRange: new vscode.Range(0, 0, 0, 1),
740
+ targetUri: currentTarget,
741
+ originSelectionRange: new vscode.Range(i, 0, i, line.length),
742
+ };
743
+ links[i] = { type: 'file', location, allLocations: currentTargetLocations, path };
744
+ }
745
+ if (!currentTarget) {
746
+ continue;
747
+ }
748
+ const resultLine = RESULT_LINE_REGEX.exec(line);
749
+ if (resultLine) {
750
+ const [, indentation, _lineNumber, separator] = resultLine;
751
+ const lineNumber = +_lineNumber - 1;
752
+ const metadataOffset = (indentation + _lineNumber + separator).length;
753
+ const targetRange = new vscode.Range(Math.max(lineNumber - 3, 0), 0, lineNumber + 3, line.length);
754
+ const locations = [];
755
+ let lastEnd = metadataOffset;
756
+ let offset = 0;
757
+ ELISION_REGEX.lastIndex = metadataOffset;
758
+ for (let match; (match = ELISION_REGEX.exec(line));) {
759
+ locations.push({
760
+ targetRange,
761
+ targetSelectionRange: new vscode.Range(lineNumber, offset, lineNumber, offset),
762
+ targetUri: currentTarget,
763
+ originSelectionRange: new vscode.Range(i, lastEnd, i, ELISION_REGEX.lastIndex - match[0].length),
764
+ });
765
+ offset += (ELISION_REGEX.lastIndex - lastEnd - match[0].length) + Number(match[1]);
766
+ lastEnd = ELISION_REGEX.lastIndex;
767
+ }
768
+ if (lastEnd < line.length) {
769
+ locations.push({
770
+ targetRange,
771
+ targetSelectionRange: new vscode.Range(lineNumber, offset, lineNumber, offset),
772
+ targetUri: currentTarget,
773
+ originSelectionRange: new vscode.Range(i, lastEnd, i, line.length),
774
+ });
775
+ }
776
+ // only show result lines in file-level peek
777
+ if (separator.includes(':')) {
778
+ currentTargetLocations?.push(...locations);
779
+ }
780
+ // Allow line number, indentation, etc to take you to definition as well.
781
+ const convenienceLocation = {
782
+ targetRange,
783
+ targetSelectionRange: new vscode.Range(lineNumber, 0, lineNumber, 1),
784
+ targetUri: currentTarget,
785
+ originSelectionRange: new vscode.Range(i, 0, i, metadataOffset - 1),
786
+ };
787
+ locations.push(convenienceLocation);
788
+ links[i] = { type: 'result', locations, isContext: separator === ' ', prefixRange: new vscode.Range(i, 0, i, metadataOffset) };
789
+ }
790
+ }
791
+ cachedLastParse = {
792
+ version: document.version,
793
+ parse: links,
794
+ uri: document.uri
795
+ };
796
+ return links;
797
+ }
798
+
799
+ })();
800
+
801
+ var __webpack_export_target__ = exports;
802
+ for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
803
+ if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
804
+ /******/ })()
805
+ ;
806
+ //# sourceMappingURL=extension.js.map