@mrclrchtr/supi-lsp 11.0.0 → 11.0.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/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/ignore/README.md +61 -6
- package/node_modules/ignore/index.d.ts +55 -20
- package/node_modules/ignore/index.js +93 -67
- package/node_modules/ignore/legacy.js +109 -85
- package/node_modules/ignore/package.json +1 -1
- package/package.json +3 -3
|
@@ -173,6 +173,29 @@ ig.ignores(path.join('./abc')) // path.join('./abc') -> 'abc'
|
|
|
173
173
|
|
|
174
174
|
In other words, each `Pathname` here should be a relative path to the directory of the gitignore rules.
|
|
175
175
|
|
|
176
|
+
A `.` or `..` component anywhere else in a `Pathname` is outside the
|
|
177
|
+
convention as well, though no error is thrown for it: the check reads how the
|
|
178
|
+
path starts, so that it costs nothing on a hot path. `path.relative()` never
|
|
179
|
+
produces such a component, and one that carries it is not matched the way
|
|
180
|
+
`git` matches it — `git` drops the component from the path first, `ignore`
|
|
181
|
+
matches the path as it was given.
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
// path.relative('/', '/a/./b') -> 'a/b'
|
|
185
|
+
|
|
186
|
+
// Right
|
|
187
|
+
ignore().add('a/b').ignores('a/b') // true
|
|
188
|
+
|
|
189
|
+
// Outside the convention: git matches 'a/b' here and so says true
|
|
190
|
+
ignore().add('a/b').ignores('a/./b') // false
|
|
191
|
+
|
|
192
|
+
// Outside the convention: git matches 'a' here and so says false
|
|
193
|
+
ignore().add('a/.').ignores('a/.') // true
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
A rule that matches an ancestor still agrees, since the component makes no
|
|
197
|
+
difference to it: `add('a').ignores('a/./b')` is `true` either way.
|
|
198
|
+
|
|
176
199
|
Suppose the dir structure is:
|
|
177
200
|
|
|
178
201
|
```
|
|
@@ -265,7 +288,8 @@ Returns `TestResult`
|
|
|
265
288
|
// Since 5.0.0
|
|
266
289
|
interface TestResult {
|
|
267
290
|
ignored: boolean
|
|
268
|
-
// true if the `pathname`
|
|
291
|
+
// true if a negative pattern matched the `pathname` itself, and no parent
|
|
292
|
+
// directory of it is ignored -- see "When both are false" below
|
|
269
293
|
unignored: boolean
|
|
270
294
|
// The `IgnoreRule` which ignores the pathname
|
|
271
295
|
rule?: IgnoreRule
|
|
@@ -283,8 +307,39 @@ interface IgnoreRule {
|
|
|
283
307
|
```
|
|
284
308
|
|
|
285
309
|
- `{ignored: true, unignored: false}`: the `pathname` is ignored
|
|
286
|
-
- `{ignored: false, unignored: true}`: the `pathname`
|
|
287
|
-
- `{ignored: false, unignored: false}`: the `pathname`
|
|
310
|
+
- `{ignored: false, unignored: true}`: a negative pattern matched the `pathname` itself
|
|
311
|
+
- `{ignored: false, unignored: false}`: no rule matched the `pathname` itself, and no parent directory of it is ignored
|
|
312
|
+
|
|
313
|
+
### When both are `false`
|
|
314
|
+
|
|
315
|
+
`{ignored: false, unignored: false}` covers two different situations:
|
|
316
|
+
|
|
317
|
+
- no rule matched the `pathname`, nor any of its parent directories, or
|
|
318
|
+
- no rule matched the `pathname` itself, but one of its parent directories is unignored by a negative pattern: the `pathname` is unignored **indirectly**.
|
|
319
|
+
|
|
320
|
+
`unignored` stays `false` in the second case because only `ignored` passes down from a parent directory. A `pathname` whose parent directory is ignored is ignored as well — git never re-includes a file whose parent directory is excluded — but one whose parent directory is unignored is decided on its own, by the rules that match the `pathname` itself.
|
|
321
|
+
|
|
322
|
+
```js
|
|
323
|
+
const ig2 = ignore().add([
|
|
324
|
+
'foo*',
|
|
325
|
+
'!foobar'
|
|
326
|
+
])
|
|
327
|
+
|
|
328
|
+
// The directory `foobar/` is unignored directly, by `!foobar`
|
|
329
|
+
ig2.test('foobar/') // {ignored: false, unignored: true}
|
|
330
|
+
|
|
331
|
+
// No rule matches `foobar/x.js` itself. It is not ignored only because its
|
|
332
|
+
// parent directory `foobar/` is not, so it is unignored indirectly
|
|
333
|
+
ig2.test('foobar/x.js') // {ignored: false, unignored: false}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
To tell the two situations apart, test the parent directories of the `pathname`, each with a trailing slash: the `pathname` is unignored indirectly if any of them is `unignored`.
|
|
337
|
+
|
|
338
|
+
```js
|
|
339
|
+
['foobar/'].some(dir => ig2.test(dir).unignored) // true
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
`unignored` is meant for packages that implement their own caching mechanism upon `node-ignore`. To simply tell whether a `pathname` is ignored, use `.ignores()` or check `TestResult::ignored`.
|
|
288
343
|
|
|
289
344
|
## .checkIgnore(target: string): TestResult
|
|
290
345
|
|
|
@@ -294,7 +349,7 @@ Debugs gitignore / exclude files, which is equivalent to `git check-ignore -v`.
|
|
|
294
349
|
|
|
295
350
|
- **target** `string` the target to test.
|
|
296
351
|
|
|
297
|
-
Returns `TestResult`
|
|
352
|
+
Returns `TestResult`, the same shape `.test()` returns, so `{ignored: false, unignored: false}` carries the [same two meanings](#when-both-are-false) here.
|
|
298
353
|
|
|
299
354
|
```js
|
|
300
355
|
ig.add({
|
|
@@ -305,10 +360,10 @@ ig.add({
|
|
|
305
360
|
const {
|
|
306
361
|
ignored,
|
|
307
362
|
rule
|
|
308
|
-
} = checkIgnore('foo/')
|
|
363
|
+
} = ig.checkIgnore('foo/')
|
|
309
364
|
|
|
310
365
|
if (ignored) {
|
|
311
|
-
console.log(`.gitignore:${
|
|
366
|
+
console.log(`.gitignore:${rule.mark}:${rule.pattern} foo/`)
|
|
312
367
|
}
|
|
313
368
|
|
|
314
369
|
// .gitignore:60:foo/* foo/
|
|
@@ -1,27 +1,61 @@
|
|
|
1
|
-
type Pathname = string
|
|
2
|
-
|
|
3
|
-
interface IgnoreRule {
|
|
4
|
-
pattern: string
|
|
5
|
-
mark?: string
|
|
6
|
-
negative: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface TestResult {
|
|
10
|
-
ignored: boolean
|
|
11
|
-
unignored: boolean
|
|
12
|
-
rule?: IgnoreRule
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface PatternParams {
|
|
16
|
-
pattern: string
|
|
17
|
-
mark?: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
1
|
/**
|
|
21
2
|
* Creates new ignore manager.
|
|
22
3
|
*/
|
|
23
4
|
declare function ignore(options?: ignore.Options): ignore.Ignore
|
|
24
5
|
declare namespace ignore {
|
|
6
|
+
/**
|
|
7
|
+
* A path relative to the directory the rules belong to, as
|
|
8
|
+
* `path.relative()` returns it.
|
|
9
|
+
*/
|
|
10
|
+
type Pathname = string
|
|
11
|
+
|
|
12
|
+
interface PatternParams {
|
|
13
|
+
pattern: string
|
|
14
|
+
/**
|
|
15
|
+
* Carried through to `IgnoreRule.mark`, for packages that build upon
|
|
16
|
+
* `ignore`.
|
|
17
|
+
*/
|
|
18
|
+
mark?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface IgnoreRule {
|
|
22
|
+
/**
|
|
23
|
+
* The original pattern.
|
|
24
|
+
*/
|
|
25
|
+
pattern: string
|
|
26
|
+
/**
|
|
27
|
+
* Carried through from `PatternParams.mark`.
|
|
28
|
+
*/
|
|
29
|
+
mark?: string
|
|
30
|
+
/**
|
|
31
|
+
* Whether the pattern is a negative one, such as `!foo`.
|
|
32
|
+
*/
|
|
33
|
+
negative: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface TestResult {
|
|
37
|
+
/**
|
|
38
|
+
* Whether the pathname is ignored, by a rule or because a parent
|
|
39
|
+
* directory of it is.
|
|
40
|
+
*/
|
|
41
|
+
ignored: boolean
|
|
42
|
+
/**
|
|
43
|
+
* True if a negative pattern matched the pathname itself, and no parent
|
|
44
|
+
* directory of it is ignored.
|
|
45
|
+
*
|
|
46
|
+
* Only `ignored` passes down from a parent directory, so a pathname that
|
|
47
|
+
* is not ignored only because a parent directory was unignored keeps
|
|
48
|
+
* this false, as does one no rule applies to at all. To tell those two
|
|
49
|
+
* apart, test the parent directories, each with a trailing slash.
|
|
50
|
+
*/
|
|
51
|
+
unignored: boolean
|
|
52
|
+
/**
|
|
53
|
+
* The rule that ignores the pathname. Present exactly when `ignored` is
|
|
54
|
+
* true.
|
|
55
|
+
*/
|
|
56
|
+
rule?: IgnoreRule
|
|
57
|
+
}
|
|
58
|
+
|
|
25
59
|
interface Ignore {
|
|
26
60
|
/**
|
|
27
61
|
* Adds one or several rules to the current manager.
|
|
@@ -54,7 +88,8 @@ declare namespace ignore {
|
|
|
54
88
|
ignores(pathname: Pathname): boolean
|
|
55
89
|
|
|
56
90
|
/**
|
|
57
|
-
*
|
|
91
|
+
* Tests the pathname against the rules. `ignored` and `unignored` can
|
|
92
|
+
* both be false: see `TestResult.unignored` for the two cases.
|
|
58
93
|
* @param {string} pathname a path to check
|
|
59
94
|
* @returns TestResult
|
|
60
95
|
*/
|
|
@@ -49,12 +49,6 @@ const define = (object, key, value) => {
|
|
|
49
49
|
|
|
50
50
|
const RETURN_FALSE = () => false
|
|
51
51
|
|
|
52
|
-
// See fixtures #59
|
|
53
|
-
const cleanRangeBackSlash = slashes => {
|
|
54
|
-
const {length} = slashes
|
|
55
|
-
return slashes.slice(0, length - length % 2)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
52
|
// > The range notation, e.g. [a-zA-Z],
|
|
59
53
|
// > can be used to match one of the characters in a range.
|
|
60
54
|
//
|
|
@@ -194,14 +188,14 @@ const scanBracket = (pattern, start) => {
|
|
|
194
188
|
}
|
|
195
189
|
|
|
196
190
|
if (end > nameStart && pattern[end - 1] === ':') {
|
|
197
|
-
const
|
|
191
|
+
const name = pattern.slice(nameStart, end - 1)
|
|
198
192
|
|
|
199
193
|
// An unknown class name makes the whole pattern match nothing
|
|
200
|
-
if (
|
|
194
|
+
if (!Object.prototype.hasOwnProperty.call(POSIX_CLASSES, name)) {
|
|
201
195
|
return null
|
|
202
196
|
}
|
|
203
197
|
|
|
204
|
-
body +=
|
|
198
|
+
body += POSIX_CLASSES[name]
|
|
205
199
|
prev = EMPTY
|
|
206
200
|
index = end
|
|
207
201
|
} else {
|
|
@@ -245,9 +239,10 @@ const REGEX_RESTORE_PLACEHOLDER = new RegExp(
|
|
|
245
239
|
// That is what keeps it apart from a user-escaped literal `\*`: the unescape
|
|
246
240
|
// steps collapse the escaped one to the exact `\*` a wildcard would leave
|
|
247
241
|
// behind, so by the time `_make` runs the two are otherwise the same string
|
|
248
|
-
// and a literal star gets wrongly rewritten into a wildcard.
|
|
249
|
-
// private-use character
|
|
250
|
-
//
|
|
242
|
+
// and a literal star gets wrongly rewritten into a wildcard. The marker is a
|
|
243
|
+
// private-use character, and `extractBrackets` keeps one that came out of the
|
|
244
|
+
// pattern apart from it, so the only marker `_make` ever turns back into a
|
|
245
|
+
// real wildcard is the one this chain put there itself.
|
|
251
246
|
const TRAILING_WILDCARD = '\uE000'
|
|
252
247
|
|
|
253
248
|
// A trailing "/**" is deferred the same way, because `checkRegex` has to tell
|
|
@@ -255,6 +250,28 @@ const TRAILING_WILDCARD = '\uE000'
|
|
|
255
250
|
// still never matches the folder itself (#21).
|
|
256
251
|
const TRAILING_DOUBLESTAR = '\uE001'
|
|
257
252
|
|
|
253
|
+
// The three characters above mean something to the chain that builds the
|
|
254
|
+
// source rather than to the path, so one that came out of the pattern is
|
|
255
|
+
// held aside like a bracket expression instead of going straight out. Being
|
|
256
|
+
// held is what makes it safe: the restore runs after the step that anchors
|
|
257
|
+
// the source, so the character comes back in the middle of the source and
|
|
258
|
+
// not at its end, which is the one place `_make` and `checkSourceOf` look
|
|
259
|
+
// for a marker. Without it a pattern's own character lands where a pending
|
|
260
|
+
// marker sits, and `_make` turns it into a real trailing wildcard.
|
|
261
|
+
//
|
|
262
|
+
// It is held as a one-member class rather than bare, in both of the branches
|
|
263
|
+
// a reserved character can reach, so that the property can be
|
|
264
|
+
// read off this function alone -- a reserved character never goes out on
|
|
265
|
+
// its own -- rather than depending on where in the chain the restore
|
|
266
|
+
// happens to run. In the expression built here `[x]` matches exactly what
|
|
267
|
+
// `x` matches, none of the three being special to a regular expression or
|
|
268
|
+
// inside a class, so no test can tell the two apart: the class is insurance,
|
|
269
|
+
// and the paragraph above is the reason it is not needed.
|
|
270
|
+
const isReserved = char =>
|
|
271
|
+
char === PLACEHOLDER
|
|
272
|
+
|| char === TRAILING_WILDCARD
|
|
273
|
+
|| char === TRAILING_DOUBLESTAR
|
|
274
|
+
|
|
258
275
|
// Replace every bracket expression with a placeholder the replacers below
|
|
259
276
|
// leave alone, and translate it separately.
|
|
260
277
|
const extractBrackets = pattern => {
|
|
@@ -279,12 +296,19 @@ const extractBrackets = pattern => {
|
|
|
279
296
|
// `\1`, `\/` keep their regular-expression meaning, and would turn a
|
|
280
297
|
// `\?` into `[^\/]`.
|
|
281
298
|
//
|
|
282
|
-
//
|
|
283
|
-
//
|
|
284
|
-
//
|
|
285
|
-
//
|
|
286
|
-
//
|
|
287
|
-
// lone trailing backslash can reach
|
|
299
|
+
// Three escapes are still left for the chain: `\*` (a literal star,
|
|
300
|
+
// told apart from a wildcard by `TRAILING_WILDCARD` and the wildcard
|
|
301
|
+
// replacers), `\[` (a literal bracket, the one `[` the bracket
|
|
302
|
+
// replacer still expects), and `\ ` (a quoted space, which one pass
|
|
303
|
+
// below rewrites in bulk -- holding each one aside instead costs more
|
|
304
|
+
// on a pattern built out of them). A lone trailing backslash can reach
|
|
305
|
+
// here after line-ending cleanup.
|
|
306
|
+
//
|
|
307
|
+
// A quoted backslash is not among them. The chain doubles every
|
|
308
|
+
// backslash, then takes the doubling back out again, and a quoted one
|
|
309
|
+
// standing next to a character the chain also escapes left the two
|
|
310
|
+
// counts sharing a run, so one of the escapes was lost. Held here as
|
|
311
|
+
// the literal it means, it never joins that run.
|
|
288
312
|
const escaped = pattern[index + 1]
|
|
289
313
|
|
|
290
314
|
if (
|
|
@@ -298,22 +322,21 @@ const extractBrackets = pattern => {
|
|
|
298
322
|
escaped === '*'
|
|
299
323
|
|| escaped === '['
|
|
300
324
|
|| escaped === SPACE
|
|
301
|
-
|| escaped === ESCAPE
|
|
302
325
|
) {
|
|
303
326
|
out += pattern.slice(index, index + 2)
|
|
304
327
|
} else {
|
|
305
328
|
out += hold(
|
|
306
329
|
REGEX_LITERAL_SPECIAL.test(escaped)
|
|
307
330
|
? ESCAPE + escaped
|
|
308
|
-
: escaped
|
|
331
|
+
: isReserved(escaped)
|
|
332
|
+
? `[${escaped}]`
|
|
333
|
+
: escaped
|
|
309
334
|
)
|
|
310
335
|
}
|
|
311
336
|
|
|
312
337
|
index += 2
|
|
313
|
-
} else if (char
|
|
314
|
-
|
|
315
|
-
// text can never be mistaken for a placeholder we emitted.
|
|
316
|
-
out += hold(`[${PLACEHOLDER}]`)
|
|
338
|
+
} else if (isReserved(char)) {
|
|
339
|
+
out += hold(`[${char}]`)
|
|
317
340
|
index ++
|
|
318
341
|
} else if (char === '[') {
|
|
319
342
|
const scanned = scanBracket(pattern, index)
|
|
@@ -559,23 +582,23 @@ const REPLACERS = [
|
|
|
559
582
|
// trailing wildcard, held apart from a literal star
|
|
560
583
|
[
|
|
561
584
|
// The step above leaves a trailing `*` alone, so a single `\*` is all that
|
|
562
|
-
// can be left at the end here
|
|
563
|
-
//
|
|
564
|
-
//
|
|
565
|
-
//
|
|
566
|
-
//
|
|
567
|
-
//
|
|
568
|
-
//
|
|
569
|
-
// the
|
|
585
|
+
// can be left at the end here, and what stands in front of it says which
|
|
586
|
+
// kind it is. A wildcard arrives as the escaper wrote it, `\*` with
|
|
587
|
+
// nothing before it; a literal arrives as the user's own escape, which
|
|
588
|
+
// the escaper doubled, and then the star's own -- `\\` and then `\*`.
|
|
589
|
+
// There is no third case: every backslash still reaching the chain is
|
|
590
|
+
// one `\*`, `\[` or `\ ` carries itself, and each is followed by its
|
|
591
|
+
// own character, so a longer run can never form. This runs while the
|
|
592
|
+
// two are still distinct, before the unescape steps below collapse the
|
|
593
|
+
// literal onto the very `\*` a wildcard leaves behind.
|
|
570
594
|
/(^|[^\\])((?:\\\\)*)\\\*$/,
|
|
571
595
|
|
|
572
596
|
(match, p1, p2) =>
|
|
573
|
-
|
|
574
|
-
(p2.length / 2) % 2 === 0
|
|
597
|
+
p2 === EMPTY
|
|
575
598
|
// A real wildcard: carry it to `_make` as the marker, so the unescape
|
|
576
599
|
// steps and the trailing-wildcard rewrite can never mistake it for a
|
|
577
600
|
// literal `\*` (nor the reverse).
|
|
578
|
-
? p1 +
|
|
601
|
+
? p1 + TRAILING_WILDCARD
|
|
579
602
|
// A literal star: leave it exactly as it stands for the unescape steps.
|
|
580
603
|
: match,
|
|
581
604
|
'*'
|
|
@@ -602,12 +625,12 @@ const REPLACERS = [
|
|
|
602
625
|
// been held aside by `extractBrackets`, so the only `[` left in the
|
|
603
626
|
// pattern is an escaped, literal one.
|
|
604
627
|
|
|
605
|
-
//
|
|
606
|
-
|
|
628
|
+
// A backslash could only stand at the end of the range if it quoted the
|
|
629
|
+
// `]`, and `\]` is held aside long before this.
|
|
630
|
+
/\\\[([^\]/]*?)($|\])/g,
|
|
607
631
|
|
|
608
|
-
// '\\[bar]' -> '\\\\[bar
|
|
609
|
-
(match, range,
|
|
610
|
-
`\\[${range}${cleanRangeBackSlash(endEscape)}${close}`,
|
|
632
|
+
// '\\[bar]' -> '\\\\[bar]'
|
|
633
|
+
(match, range, close) => `\\[${range}${close}`,
|
|
611
634
|
'['
|
|
612
635
|
],
|
|
613
636
|
|
|
@@ -678,23 +701,10 @@ const replaceTrailingDoublestar = () => '.+(?=$|\\/$)'
|
|
|
678
701
|
|
|
679
702
|
const WILDCARD = '[^\\/]*'
|
|
680
703
|
|
|
681
|
-
//
|
|
682
|
-
//
|
|
683
|
-
//
|
|
684
|
-
//
|
|
685
|
-
// rather than the length of the path. Every wildcard but the last in such a
|
|
686
|
-
// run can be pinned to stop at the character that follows it, which leaves
|
|
687
|
-
// one way to lay out the input and no rewinding, without changing which
|
|
688
|
-
// paths match: the fixed characters still bound the count, and the last
|
|
689
|
-
// wildcard still absorbs the rest.
|
|
690
|
-
//
|
|
691
|
-
// The source is read one token at a time -- a wildcard, a single-character
|
|
692
|
-
// piece (a literal, an escape, a class), or a parenthesised group or anchor
|
|
693
|
-
// that ends the run -- so only a genuine wildcard is touched.
|
|
694
|
-
|
|
695
|
-
// The fixed pieces between the wildcard at `at` and the next wildcard of the
|
|
696
|
-
// run, joined as they appear in the source. A run never holds two wildcards
|
|
697
|
-
// in a row, so there is always at least one piece.
|
|
704
|
+
// The fixed piece between the wildcard at `at` and the next wildcard of the
|
|
705
|
+
// run: the tokens that separate them, joined as they appear in the source.
|
|
706
|
+
// A run never holds two wildcards in a row, so there is always at least one
|
|
707
|
+
// token.
|
|
698
708
|
const separatorAfter = (run, at) => {
|
|
699
709
|
let separator = EMPTY
|
|
700
710
|
|
|
@@ -705,6 +715,29 @@ const separatorAfter = (run, at) => {
|
|
|
705
715
|
return separator
|
|
706
716
|
}
|
|
707
717
|
|
|
718
|
+
// Where a run of non-slash wildcards is split by fixed pieces --
|
|
719
|
+
// `[^/]*ab[^/]*cd...` -- the engine has many equivalent ways to lay the
|
|
720
|
+
// input across the wildcards, and on input that does not match it works
|
|
721
|
+
// through all of them, so the time grows with the number of wildcards
|
|
722
|
+
// rather than the length of the path. Every wildcard but the last in such a
|
|
723
|
+
// run can be pinned to stop where the piece after it begins, which leaves
|
|
724
|
+
// one way to lay out the input and no rewinding, without changing which
|
|
725
|
+
// paths match: the fixed pieces still bound the count, and the last
|
|
726
|
+
// wildcard still absorbs the rest.
|
|
727
|
+
//
|
|
728
|
+
// A wildcard is pinned to the whole piece, never to the piece's first
|
|
729
|
+
// character. The pin leaves no way back, so a wildcard that stopped at that
|
|
730
|
+
// first character would hand over wherever the character happens to turn
|
|
731
|
+
// up, including the places the rest of the piece cannot follow -- which is
|
|
732
|
+
// how `f*o/*/*` came to miss `foo/b/c`, the first `o` of `foo` not being
|
|
733
|
+
// the one the `o/` after it needs. Every token of a piece matches exactly
|
|
734
|
+
// one character, so the first place the whole piece fits is the leftmost
|
|
735
|
+
// place it can sit, and whatever is left over goes to the wildcards that
|
|
736
|
+
// follow.
|
|
737
|
+
//
|
|
738
|
+
// The source is read one token at a time -- a wildcard, a single-character
|
|
739
|
+
// piece (a literal, an escape, a class), or a parenthesised group or anchor
|
|
740
|
+
// that ends the run -- so only a genuine wildcard is touched.
|
|
708
741
|
const pinWildcards = source => {
|
|
709
742
|
if (source.indexOf(WILDCARD) < 0) {
|
|
710
743
|
return source
|
|
@@ -792,16 +825,9 @@ const pinWildcards = source => {
|
|
|
792
825
|
return
|
|
793
826
|
}
|
|
794
827
|
|
|
795
|
-
//
|
|
796
|
-
//
|
|
797
|
-
//
|
|
798
|
-
// would let the wildcard hand over at a place where the rest of the
|
|
799
|
-
// separator cannot follow, and the pin leaves no way back, so
|
|
800
|
-
// `f*o/*/*` would miss `foo/b/c` -- the first `o` of `foo` is not the
|
|
801
|
-
// one the `o/` after it needs. Every piece matches exactly one
|
|
802
|
-
// character, so pinning to the first place the whole separator fits
|
|
803
|
-
// is the leftmost place it can sit, and the wildcards that follow
|
|
804
|
-
// take up whatever is left.
|
|
828
|
+
// Every wildcard but the last is pinned to the whole piece that
|
|
829
|
+
// follows it, for the reason set out above this function. The last
|
|
830
|
+
// one stays as it is and takes up the rest.
|
|
805
831
|
out += at === lastWildcard
|
|
806
832
|
? WILDCARD
|
|
807
833
|
: `(?:(?!${separatorAfter(run, at)})[^\\/])*`
|
|
@@ -60,12 +60,6 @@ var RETURN_FALSE = function RETURN_FALSE() {
|
|
|
60
60
|
return false;
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
// See fixtures #59
|
|
64
|
-
var cleanRangeBackSlash = function cleanRangeBackSlash(slashes) {
|
|
65
|
-
var length = slashes.length;
|
|
66
|
-
return slashes.slice(0, length - length % 2);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
63
|
// > The range notation, e.g. [a-zA-Z],
|
|
70
64
|
// > can be used to match one of the characters in a range.
|
|
71
65
|
//
|
|
@@ -187,13 +181,13 @@ var scanBracket = function scanBracket(pattern, start) {
|
|
|
187
181
|
return null;
|
|
188
182
|
}
|
|
189
183
|
if (end > nameStart && pattern[end - 1] === ':') {
|
|
190
|
-
var
|
|
184
|
+
var name = pattern.slice(nameStart, end - 1);
|
|
191
185
|
|
|
192
186
|
// An unknown class name makes the whole pattern match nothing
|
|
193
|
-
if (
|
|
187
|
+
if (!Object.prototype.hasOwnProperty.call(POSIX_CLASSES, name)) {
|
|
194
188
|
return null;
|
|
195
189
|
}
|
|
196
|
-
body +=
|
|
190
|
+
body += POSIX_CLASSES[name];
|
|
197
191
|
prev = EMPTY;
|
|
198
192
|
index = end;
|
|
199
193
|
} else {
|
|
@@ -233,9 +227,10 @@ var REGEX_RESTORE_PLACEHOLDER = new RegExp("".concat(PLACEHOLDER, "(\\d+)").conc
|
|
|
233
227
|
// That is what keeps it apart from a user-escaped literal `\*`: the unescape
|
|
234
228
|
// steps collapse the escaped one to the exact `\*` a wildcard would leave
|
|
235
229
|
// behind, so by the time `_make` runs the two are otherwise the same string
|
|
236
|
-
// and a literal star gets wrongly rewritten into a wildcard.
|
|
237
|
-
// private-use character
|
|
238
|
-
//
|
|
230
|
+
// and a literal star gets wrongly rewritten into a wildcard. The marker is a
|
|
231
|
+
// private-use character, and `extractBrackets` keeps one that came out of the
|
|
232
|
+
// pattern apart from it, so the only marker `_make` ever turns back into a
|
|
233
|
+
// real wildcard is the one this chain put there itself.
|
|
239
234
|
var TRAILING_WILDCARD = "\uE000";
|
|
240
235
|
|
|
241
236
|
// A trailing "/**" is deferred the same way, because `checkRegex` has to tell
|
|
@@ -243,6 +238,27 @@ var TRAILING_WILDCARD = "\uE000";
|
|
|
243
238
|
// still never matches the folder itself (#21).
|
|
244
239
|
var TRAILING_DOUBLESTAR = "\uE001";
|
|
245
240
|
|
|
241
|
+
// The three characters above mean something to the chain that builds the
|
|
242
|
+
// source rather than to the path, so one that came out of the pattern is
|
|
243
|
+
// held aside like a bracket expression instead of going straight out. Being
|
|
244
|
+
// held is what makes it safe: the restore runs after the step that anchors
|
|
245
|
+
// the source, so the character comes back in the middle of the source and
|
|
246
|
+
// not at its end, which is the one place `_make` and `checkSourceOf` look
|
|
247
|
+
// for a marker. Without it a pattern's own character lands where a pending
|
|
248
|
+
// marker sits, and `_make` turns it into a real trailing wildcard.
|
|
249
|
+
//
|
|
250
|
+
// It is held as a one-member class rather than bare, in both of the branches
|
|
251
|
+
// a reserved character can reach, so that the property can be
|
|
252
|
+
// read off this function alone -- a reserved character never goes out on
|
|
253
|
+
// its own -- rather than depending on where in the chain the restore
|
|
254
|
+
// happens to run. In the expression built here `[x]` matches exactly what
|
|
255
|
+
// `x` matches, none of the three being special to a regular expression or
|
|
256
|
+
// inside a class, so no test can tell the two apart: the class is insurance,
|
|
257
|
+
// and the paragraph above is the reason it is not needed.
|
|
258
|
+
var isReserved = function isReserved(_char3) {
|
|
259
|
+
return _char3 === PLACEHOLDER || _char3 === TRAILING_WILDCARD || _char3 === TRAILING_DOUBLESTAR;
|
|
260
|
+
};
|
|
261
|
+
|
|
246
262
|
// Replace every bracket expression with a placeholder the replacers below
|
|
247
263
|
// leave alone, and translate it separately.
|
|
248
264
|
var extractBrackets = function extractBrackets(pattern) {
|
|
@@ -254,8 +270,8 @@ var extractBrackets = function extractBrackets(pattern) {
|
|
|
254
270
|
var out = EMPTY;
|
|
255
271
|
var index = 0;
|
|
256
272
|
while (index < length) {
|
|
257
|
-
var
|
|
258
|
-
if (
|
|
273
|
+
var _char4 = pattern[index];
|
|
274
|
+
if (_char4 === ESCAPE) {
|
|
259
275
|
// > Put a backslash ("\") in front of ... a character to make it literal.
|
|
260
276
|
// (gitignore(5) -> fnmatch(3))
|
|
261
277
|
// A backslash quotes the next character, whatever it is, so `\d` is a
|
|
@@ -265,29 +281,34 @@ var extractBrackets = function extractBrackets(pattern) {
|
|
|
265
281
|
// `\1`, `\/` keep their regular-expression meaning, and would turn a
|
|
266
282
|
// `\?` into `[^\/]`.
|
|
267
283
|
//
|
|
268
|
-
//
|
|
269
|
-
//
|
|
270
|
-
//
|
|
271
|
-
//
|
|
272
|
-
//
|
|
273
|
-
// lone trailing backslash can reach
|
|
284
|
+
// Three escapes are still left for the chain: `\*` (a literal star,
|
|
285
|
+
// told apart from a wildcard by `TRAILING_WILDCARD` and the wildcard
|
|
286
|
+
// replacers), `\[` (a literal bracket, the one `[` the bracket
|
|
287
|
+
// replacer still expects), and `\ ` (a quoted space, which one pass
|
|
288
|
+
// below rewrites in bulk -- holding each one aside instead costs more
|
|
289
|
+
// on a pattern built out of them). A lone trailing backslash can reach
|
|
290
|
+
// here after line-ending cleanup.
|
|
291
|
+
//
|
|
292
|
+
// A quoted backslash is not among them. The chain doubles every
|
|
293
|
+
// backslash, then takes the doubling back out again, and a quoted one
|
|
294
|
+
// standing next to a character the chain also escapes left the two
|
|
295
|
+
// counts sharing a run, so one of the escapes was lost. Held here as
|
|
296
|
+
// the literal it means, it never joins that run.
|
|
274
297
|
var escaped = pattern[index + 1];
|
|
275
298
|
if (escaped === UNDEFINED || escaped === SLASH && index + 2 === length) {
|
|
276
299
|
// Git removes a final directory slash before matching. An escape
|
|
277
300
|
// without a character after that removal makes the pattern invalid.
|
|
278
301
|
out += hold(NEVER_MATCH);
|
|
279
|
-
} else if (escaped === '*' || escaped === '[' || escaped === SPACE
|
|
302
|
+
} else if (escaped === '*' || escaped === '[' || escaped === SPACE) {
|
|
280
303
|
out += pattern.slice(index, index + 2);
|
|
281
304
|
} else {
|
|
282
|
-
out += hold(REGEX_LITERAL_SPECIAL.test(escaped) ? ESCAPE + escaped : escaped);
|
|
305
|
+
out += hold(REGEX_LITERAL_SPECIAL.test(escaped) ? ESCAPE + escaped : isReserved(escaped) ? "[".concat(escaped, "]") : escaped);
|
|
283
306
|
}
|
|
284
307
|
index += 2;
|
|
285
|
-
} else if (
|
|
286
|
-
|
|
287
|
-
// text can never be mistaken for a placeholder we emitted.
|
|
288
|
-
out += hold("[".concat(PLACEHOLDER, "]"));
|
|
308
|
+
} else if (isReserved(_char4)) {
|
|
309
|
+
out += hold("[".concat(_char4, "]"));
|
|
289
310
|
index++;
|
|
290
|
-
} else if (
|
|
311
|
+
} else if (_char4 === '[') {
|
|
291
312
|
var scanned = scanBracket(pattern, index);
|
|
292
313
|
if (scanned === null) {
|
|
293
314
|
// git gives up on the whole pattern (`WM_ABORT_ALL`), so whatever
|
|
@@ -299,7 +320,7 @@ var extractBrackets = function extractBrackets(pattern) {
|
|
|
299
320
|
index = scanned.end + 1;
|
|
300
321
|
}
|
|
301
322
|
} else {
|
|
302
|
-
out +=
|
|
323
|
+
out += _char4;
|
|
303
324
|
index++;
|
|
304
325
|
}
|
|
305
326
|
}
|
|
@@ -499,25 +520,23 @@ function (_, p1, p2) {
|
|
|
499
520
|
// trailing wildcard, held apart from a literal star
|
|
500
521
|
[
|
|
501
522
|
// The step above leaves a trailing `*` alone, so a single `\*` is all that
|
|
502
|
-
// can be left at the end here
|
|
503
|
-
//
|
|
504
|
-
//
|
|
505
|
-
//
|
|
506
|
-
//
|
|
507
|
-
//
|
|
508
|
-
//
|
|
509
|
-
// the
|
|
523
|
+
// can be left at the end here, and what stands in front of it says which
|
|
524
|
+
// kind it is. A wildcard arrives as the escaper wrote it, `\*` with
|
|
525
|
+
// nothing before it; a literal arrives as the user's own escape, which
|
|
526
|
+
// the escaper doubled, and then the star's own -- `\\` and then `\*`.
|
|
527
|
+
// There is no third case: every backslash still reaching the chain is
|
|
528
|
+
// one `\*`, `\[` or `\ ` carries itself, and each is followed by its
|
|
529
|
+
// own character, so a longer run can never form. This runs while the
|
|
530
|
+
// two are still distinct, before the unescape steps below collapse the
|
|
531
|
+
// literal onto the very `\*` a wildcard leaves behind.
|
|
510
532
|
/(^|[^\\])((?:\\\\)*)\\\*$/, function (match, p1, p2) {
|
|
511
|
-
return
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
// A literal star: leave it exactly as it stands for the unescape steps.
|
|
519
|
-
: match
|
|
520
|
-
);
|
|
533
|
+
return p2 === EMPTY
|
|
534
|
+
// A real wildcard: carry it to `_make` as the marker, so the unescape
|
|
535
|
+
// steps and the trailing-wildcard rewrite can never mistake it for a
|
|
536
|
+
// literal `\*` (nor the reverse).
|
|
537
|
+
? p1 + TRAILING_WILDCARD
|
|
538
|
+
// A literal star: leave it exactly as it stands for the unescape steps.
|
|
539
|
+
: match;
|
|
521
540
|
}, '*'], [
|
|
522
541
|
// unescape, revert step 3 except for back slash
|
|
523
542
|
// For example, if a user escape a '\\*',
|
|
@@ -533,11 +552,12 @@ function (_, p1, p2) {
|
|
|
533
552
|
// been held aside by `extractBrackets`, so the only `[` left in the
|
|
534
553
|
// pattern is an escaped, literal one.
|
|
535
554
|
|
|
536
|
-
//
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
555
|
+
// A backslash could only stand at the end of the range if it quoted the
|
|
556
|
+
// `]`, and `\]` is held aside long before this.
|
|
557
|
+
/\\\[([^\]/]*?)($|\])/g,
|
|
558
|
+
// '\\[bar]' -> '\\\\[bar]'
|
|
559
|
+
function (match, range, close) {
|
|
560
|
+
return "\\[".concat(range).concat(close);
|
|
541
561
|
}, '['],
|
|
542
562
|
// ending
|
|
543
563
|
[
|
|
@@ -596,30 +616,41 @@ var replaceTrailingDoublestar = function replaceTrailingDoublestar() {
|
|
|
596
616
|
};
|
|
597
617
|
var WILDCARD = '[^\\/]*';
|
|
598
618
|
|
|
599
|
-
//
|
|
600
|
-
//
|
|
619
|
+
// The fixed piece between the wildcard at `at` and the next wildcard of the
|
|
620
|
+
// run: the tokens that separate them, joined as they appear in the source.
|
|
621
|
+
// A run never holds two wildcards in a row, so there is always at least one
|
|
622
|
+
// token.
|
|
623
|
+
var separatorAfter = function separatorAfter(run, at) {
|
|
624
|
+
var separator = EMPTY;
|
|
625
|
+
for (var index = at + 1; index < run.length && !run[index].wildcard; index++) {
|
|
626
|
+
separator += run[index].single;
|
|
627
|
+
}
|
|
628
|
+
return separator;
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
// Where a run of non-slash wildcards is split by fixed pieces --
|
|
632
|
+
// `[^/]*ab[^/]*cd...` -- the engine has many equivalent ways to lay the
|
|
601
633
|
// input across the wildcards, and on input that does not match it works
|
|
602
634
|
// through all of them, so the time grows with the number of wildcards
|
|
603
635
|
// rather than the length of the path. Every wildcard but the last in such a
|
|
604
|
-
// run can be pinned to stop
|
|
636
|
+
// run can be pinned to stop where the piece after it begins, which leaves
|
|
605
637
|
// one way to lay out the input and no rewinding, without changing which
|
|
606
|
-
// paths match: the fixed
|
|
638
|
+
// paths match: the fixed pieces still bound the count, and the last
|
|
607
639
|
// wildcard still absorbs the rest.
|
|
608
640
|
//
|
|
641
|
+
// A wildcard is pinned to the whole piece, never to the piece's first
|
|
642
|
+
// character. The pin leaves no way back, so a wildcard that stopped at that
|
|
643
|
+
// first character would hand over wherever the character happens to turn
|
|
644
|
+
// up, including the places the rest of the piece cannot follow -- which is
|
|
645
|
+
// how `f*o/*/*` came to miss `foo/b/c`, the first `o` of `foo` not being
|
|
646
|
+
// the one the `o/` after it needs. Every token of a piece matches exactly
|
|
647
|
+
// one character, so the first place the whole piece fits is the leftmost
|
|
648
|
+
// place it can sit, and whatever is left over goes to the wildcards that
|
|
649
|
+
// follow.
|
|
650
|
+
//
|
|
609
651
|
// The source is read one token at a time -- a wildcard, a single-character
|
|
610
652
|
// piece (a literal, an escape, a class), or a parenthesised group or anchor
|
|
611
653
|
// that ends the run -- so only a genuine wildcard is touched.
|
|
612
|
-
|
|
613
|
-
// The fixed pieces between the wildcard at `at` and the next wildcard of the
|
|
614
|
-
// run, joined as they appear in the source. A run never holds two wildcards
|
|
615
|
-
// in a row, so there is always at least one piece.
|
|
616
|
-
var separatorAfter = function separatorAfter(run, at) {
|
|
617
|
-
var separator = EMPTY;
|
|
618
|
-
for (var index = at + 1; index < run.length && !run[index].wildcard; index++) {
|
|
619
|
-
separator += run[index].single;
|
|
620
|
-
}
|
|
621
|
-
return separator;
|
|
622
|
-
};
|
|
623
654
|
var pinWildcards = function pinWildcards(source) {
|
|
624
655
|
if (source.indexOf(WILDCARD) < 0) {
|
|
625
656
|
return source;
|
|
@@ -628,13 +659,13 @@ var pinWildcards = function pinWildcards(source) {
|
|
|
628
659
|
var length = source.length;
|
|
629
660
|
var index = 0;
|
|
630
661
|
while (index < length) {
|
|
631
|
-
var
|
|
662
|
+
var _char5 = source[index];
|
|
632
663
|
if (source.startsWith(WILDCARD, index)) {
|
|
633
664
|
tokens.push({
|
|
634
665
|
wildcard: true
|
|
635
666
|
});
|
|
636
667
|
index += WILDCARD.length;
|
|
637
|
-
} else if (
|
|
668
|
+
} else if (_char5 === '[') {
|
|
638
669
|
var end = index + 1;
|
|
639
670
|
if (source[end] === '^') {
|
|
640
671
|
end++;
|
|
@@ -650,12 +681,12 @@ var pinWildcards = function pinWildcards(source) {
|
|
|
650
681
|
single: source.slice(index, end)
|
|
651
682
|
});
|
|
652
683
|
index = end;
|
|
653
|
-
} else if (
|
|
684
|
+
} else if (_char5 === ESCAPE) {
|
|
654
685
|
tokens.push({
|
|
655
686
|
single: source.slice(index, index + 2)
|
|
656
687
|
});
|
|
657
688
|
index += 2;
|
|
658
|
-
} else if (
|
|
689
|
+
} else if (_char5 === '(') {
|
|
659
690
|
var depth = 0;
|
|
660
691
|
var _end = index;
|
|
661
692
|
do {
|
|
@@ -675,14 +706,14 @@ var pinWildcards = function pinWildcards(source) {
|
|
|
675
706
|
boundary: source.slice(index, _end)
|
|
676
707
|
});
|
|
677
708
|
index = _end;
|
|
678
|
-
} else if (
|
|
709
|
+
} else if (_char5 === '^' || _char5 === '$') {
|
|
679
710
|
tokens.push({
|
|
680
|
-
boundary:
|
|
711
|
+
boundary: _char5
|
|
681
712
|
});
|
|
682
713
|
index++;
|
|
683
714
|
} else {
|
|
684
715
|
tokens.push({
|
|
685
|
-
single:
|
|
716
|
+
single: _char5
|
|
686
717
|
});
|
|
687
718
|
index++;
|
|
688
719
|
}
|
|
@@ -702,16 +733,9 @@ var pinWildcards = function pinWildcards(source) {
|
|
|
702
733
|
return;
|
|
703
734
|
}
|
|
704
735
|
|
|
705
|
-
//
|
|
706
|
-
//
|
|
707
|
-
//
|
|
708
|
-
// would let the wildcard hand over at a place where the rest of the
|
|
709
|
-
// separator cannot follow, and the pin leaves no way back, so
|
|
710
|
-
// `f*o/*/*` would miss `foo/b/c` -- the first `o` of `foo` is not the
|
|
711
|
-
// one the `o/` after it needs. Every piece matches exactly one
|
|
712
|
-
// character, so pinning to the first place the whole separator fits
|
|
713
|
-
// is the leftmost place it can sit, and the wildcards that follow
|
|
714
|
-
// take up whatever is left.
|
|
736
|
+
// Every wildcard but the last is pinned to the whole piece that
|
|
737
|
+
// follows it, for the reason set out above this function. The last
|
|
738
|
+
// one stays as it is and takes up the rest.
|
|
715
739
|
out += at === lastWildcard ? WILDCARD : "(?:(?!".concat(separatorAfter(run, at), ")[^\\/])*");
|
|
716
740
|
});
|
|
717
741
|
run = [];
|
|
@@ -890,8 +914,8 @@ var IgnoreRule = /*#__PURE__*/function () {
|
|
|
890
914
|
}]);
|
|
891
915
|
return IgnoreRule;
|
|
892
916
|
}();
|
|
893
|
-
var isLineEnd = function isLineEnd(
|
|
894
|
-
return
|
|
917
|
+
var isLineEnd = function isLineEnd(_char6) {
|
|
918
|
+
return _char6 === '\r' || _char6 === '\n';
|
|
895
919
|
};
|
|
896
920
|
|
|
897
921
|
// Drop a line terminator, which can remain when patterns are passed as an
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-lsp",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.1",
|
|
4
4
|
"description": "Language Server Protocol runtime for SuPi code intelligence",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"vscode-jsonrpc": "^9.0.0",
|
|
38
38
|
"vscode-languageserver-protocol": "^3.18.0",
|
|
39
39
|
"vscode-languageserver-types": "^3.18.0",
|
|
40
|
-
"@mrclrchtr/supi-
|
|
41
|
-
"@mrclrchtr/supi-
|
|
40
|
+
"@mrclrchtr/supi-core": "11.0.1",
|
|
41
|
+
"@mrclrchtr/supi-code-runtime": "11.0.1"
|
|
42
42
|
},
|
|
43
43
|
"bundledDependencies": [
|
|
44
44
|
"@mrclrchtr/supi-code-runtime",
|