@opensumi/ide-core-common 2.17.9 → 2.18.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.
Files changed (296) hide show
  1. package/lib/application-error.d.ts.map +1 -1
  2. package/lib/application-error.js +6 -0
  3. package/lib/application-error.js.map +1 -1
  4. package/lib/command.d.ts +1 -2
  5. package/lib/command.d.ts.map +1 -1
  6. package/lib/command.js +4 -4
  7. package/lib/command.js.map +1 -1
  8. package/lib/{utils/comparers.d.ts → comparers.d.ts} +1 -1
  9. package/lib/comparers.d.ts.map +1 -0
  10. package/lib/{utils/comparers.js → comparers.js} +5 -5
  11. package/lib/comparers.js.map +1 -0
  12. package/lib/const/application.d.ts +1 -0
  13. package/lib/const/application.d.ts.map +1 -1
  14. package/lib/const/application.js +3 -1
  15. package/lib/const/application.js.map +1 -1
  16. package/lib/const/index.d.ts +1 -1
  17. package/lib/const/index.d.ts.map +1 -1
  18. package/lib/const/index.js +1 -1
  19. package/lib/const/index.js.map +1 -1
  20. package/lib/crypto.d.ts +7 -0
  21. package/lib/{cryptr.d.ts.map → crypto.d.ts.map} +1 -1
  22. package/lib/crypto.js +6 -0
  23. package/lib/crypto.js.map +1 -0
  24. package/lib/electron.d.ts +2 -2
  25. package/lib/electron.d.ts.map +1 -1
  26. package/lib/electron.js.map +1 -1
  27. package/lib/event-bus/event-bus-types.d.ts +3 -4
  28. package/lib/event-bus/event-bus-types.d.ts.map +1 -1
  29. package/lib/event-bus/event-bus.d.ts +3 -3
  30. package/lib/event-bus/event-bus.d.ts.map +1 -1
  31. package/lib/event-bus/event-bus.js +3 -3
  32. package/lib/event-bus/event-bus.js.map +1 -1
  33. package/lib/event-bus/event-decorator.d.ts +1 -1
  34. package/lib/event-bus/event-decorator.d.ts.map +1 -1
  35. package/lib/event-bus/event-decorator.js +2 -2
  36. package/lib/event-bus/event-decorator.js.map +1 -1
  37. package/lib/hash-calculate/hash-calculate.d.ts.map +1 -1
  38. package/lib/hash-calculate/hash-calculate.js +2 -2
  39. package/lib/hash-calculate/hash-calculate.js.map +1 -1
  40. package/lib/index.d.ts +4 -18
  41. package/lib/index.d.ts.map +1 -1
  42. package/lib/index.js +4 -18
  43. package/lib/index.js.map +1 -1
  44. package/lib/keyboard/keyboard-layout-provider.d.ts +1 -1
  45. package/lib/keyboard/keyboard-layout-provider.d.ts.map +1 -1
  46. package/lib/keyboard/keymap.js +4 -4
  47. package/lib/keyboard/keymap.js.map +1 -1
  48. package/lib/localize.d.ts.map +1 -1
  49. package/lib/localize.js +7 -7
  50. package/lib/localize.js.map +1 -1
  51. package/lib/log.d.ts +1 -1
  52. package/lib/log.d.ts.map +1 -1
  53. package/lib/{utils/markdown.d.ts → markdown.d.ts} +1 -1
  54. package/lib/markdown.d.ts.map +1 -0
  55. package/lib/{utils/markdown.js → markdown.js} +0 -0
  56. package/lib/markdown.js.map +1 -0
  57. package/lib/menu.d.ts +1 -1
  58. package/lib/menu.d.ts.map +1 -1
  59. package/lib/menu.js.map +1 -1
  60. package/lib/network.d.ts +2 -1
  61. package/lib/network.d.ts.map +1 -1
  62. package/lib/network.js +19 -18
  63. package/lib/network.js.map +1 -1
  64. package/lib/problem-matcher.d.ts +1 -3
  65. package/lib/problem-matcher.d.ts.map +1 -1
  66. package/lib/problem-matcher.js +5 -6
  67. package/lib/problem-matcher.js.map +1 -1
  68. package/lib/problem-pattern.d.ts +1 -2
  69. package/lib/problem-pattern.d.ts.map +1 -1
  70. package/lib/problem-pattern.js +9 -10
  71. package/lib/problem-pattern.js.map +1 -1
  72. package/lib/reference.d.ts +1 -3
  73. package/lib/reference.d.ts.map +1 -1
  74. package/lib/reference.js +4 -5
  75. package/lib/reference.js.map +1 -1
  76. package/lib/reporter.d.ts +1 -1
  77. package/lib/reporter.d.ts.map +1 -1
  78. package/lib/storage.d.ts +1 -4
  79. package/lib/storage.d.ts.map +1 -1
  80. package/lib/storage.js +11 -11
  81. package/lib/storage.js.map +1 -1
  82. package/lib/task-definition.d.ts +1 -1
  83. package/lib/task-definition.d.ts.map +1 -1
  84. package/lib/task-definition.js +6 -6
  85. package/lib/task-definition.js.map +1 -1
  86. package/lib/types/application.d.ts +4 -4
  87. package/lib/types/application.d.ts.map +1 -1
  88. package/lib/types/authentication.d.ts +1 -2
  89. package/lib/types/authentication.d.ts.map +1 -1
  90. package/lib/types/authentication.js.map +1 -1
  91. package/lib/types/common.d.ts +2 -2
  92. package/lib/types/common.d.ts.map +1 -1
  93. package/lib/types/extension.d.ts +1 -1
  94. package/lib/types/extension.d.ts.map +1 -1
  95. package/lib/types/extension.js.map +1 -1
  96. package/lib/types/file-watch.d.ts +1 -1
  97. package/lib/types/file-watch.d.ts.map +1 -1
  98. package/lib/types/file-watch.js +2 -2
  99. package/lib/types/file-watch.js.map +1 -1
  100. package/lib/types/file.d.ts +1 -1
  101. package/lib/types/file.d.ts.map +1 -1
  102. package/lib/types/index.d.ts +1 -0
  103. package/lib/types/index.d.ts.map +1 -1
  104. package/lib/types/index.js +1 -0
  105. package/lib/types/index.js.map +1 -1
  106. package/lib/types/markdown.d.ts +2 -1
  107. package/lib/types/markdown.d.ts.map +1 -1
  108. package/lib/types/markers/markers-manager.d.ts +2 -2
  109. package/lib/types/markers/markers-manager.d.ts.map +1 -1
  110. package/lib/types/markers/markers-manager.js +25 -23
  111. package/lib/types/markers/markers-manager.js.map +1 -1
  112. package/lib/types/markers/markers.js +2 -2
  113. package/lib/types/markers/markers.js.map +1 -1
  114. package/lib/utils/ipc.d.ts.map +1 -1
  115. package/lib/utils/ipc.js +7 -8
  116. package/lib/utils/ipc.js.map +1 -1
  117. package/package.json +4 -7
  118. package/lib/arrays.d.ts +0 -134
  119. package/lib/arrays.d.ts.map +0 -1
  120. package/lib/arrays.js +0 -545
  121. package/lib/arrays.js.map +0 -1
  122. package/lib/async.d.ts +0 -185
  123. package/lib/async.d.ts.map +0 -1
  124. package/lib/async.js +0 -469
  125. package/lib/async.js.map +0 -1
  126. package/lib/cache.d.ts +0 -12
  127. package/lib/cache.d.ts.map +0 -1
  128. package/lib/cache.js +0 -37
  129. package/lib/cache.js.map +0 -1
  130. package/lib/cancellation.d.ts +0 -23
  131. package/lib/cancellation.d.ts.map +0 -1
  132. package/lib/cancellation.js +0 -120
  133. package/lib/cancellation.js.map +0 -1
  134. package/lib/charCode.d.ts +0 -406
  135. package/lib/charCode.d.ts.map +0 -1
  136. package/lib/charCode.js +0 -8
  137. package/lib/charCode.js.map +0 -1
  138. package/lib/character-classifier.d.ts +0 -25
  139. package/lib/character-classifier.d.ts.map +0 -1
  140. package/lib/character-classifier.js +0 -59
  141. package/lib/character-classifier.js.map +0 -1
  142. package/lib/const/encodings.d.ts +0 -10
  143. package/lib/const/encodings.d.ts.map +0 -1
  144. package/lib/const/encodings.js +0 -244
  145. package/lib/const/encodings.js.map +0 -1
  146. package/lib/cryptr.d.ts +0 -7
  147. package/lib/cryptr.js +0 -6
  148. package/lib/cryptr.js.map +0 -1
  149. package/lib/date.d.ts +0 -2
  150. package/lib/date.d.ts.map +0 -1
  151. package/lib/date.js +0 -22
  152. package/lib/date.js.map +0 -1
  153. package/lib/disposable.d.ts +0 -88
  154. package/lib/disposable.d.ts.map +0 -1
  155. package/lib/disposable.js +0 -316
  156. package/lib/disposable.js.map +0 -1
  157. package/lib/encoding/index.d.ts +0 -34
  158. package/lib/encoding/index.d.ts.map +0 -1
  159. package/lib/encoding/index.js +0 -219
  160. package/lib/encoding/index.js.map +0 -1
  161. package/lib/errors.d.ts +0 -56
  162. package/lib/errors.d.ts.map +0 -1
  163. package/lib/errors.js +0 -148
  164. package/lib/errors.js.map +0 -1
  165. package/lib/event.d.ts +0 -268
  166. package/lib/event.d.ts.map +0 -1
  167. package/lib/event.js +0 -816
  168. package/lib/event.js.map +0 -1
  169. package/lib/filters.d.ts +0 -47
  170. package/lib/filters.d.ts.map +0 -1
  171. package/lib/filters.js +0 -699
  172. package/lib/filters.js.map +0 -1
  173. package/lib/functional.d.ts +0 -4
  174. package/lib/functional.d.ts.map +0 -1
  175. package/lib/functional.js +0 -45
  176. package/lib/functional.js.map +0 -1
  177. package/lib/iterator.d.ts +0 -17
  178. package/lib/iterator.d.ts.map +0 -1
  179. package/lib/iterator.js +0 -24
  180. package/lib/iterator.js.map +0 -1
  181. package/lib/lifecycle.d.ts +0 -17
  182. package/lib/lifecycle.d.ts.map +0 -1
  183. package/lib/lifecycle.js +0 -39
  184. package/lib/lifecycle.js.map +0 -1
  185. package/lib/linked-list.d.ts +0 -18
  186. package/lib/linked-list.d.ts.map +0 -1
  187. package/lib/linked-list.js +0 -138
  188. package/lib/linked-list.js.map +0 -1
  189. package/lib/linkedText.d.ts +0 -13
  190. package/lib/linkedText.d.ts.map +0 -1
  191. package/lib/linkedText.js +0 -50
  192. package/lib/linkedText.js.map +0 -1
  193. package/lib/map.d.ts +0 -124
  194. package/lib/map.d.ts.map +0 -1
  195. package/lib/map.js +0 -819
  196. package/lib/map.js.map +0 -1
  197. package/lib/path.d.ts +0 -92
  198. package/lib/path.d.ts.map +0 -1
  199. package/lib/path.js +0 -1695
  200. package/lib/path.js.map +0 -1
  201. package/lib/platform.d.ts +0 -48
  202. package/lib/platform.d.ts.map +0 -1
  203. package/lib/platform.js +0 -153
  204. package/lib/platform.js.map +0 -1
  205. package/lib/process.d.ts +0 -5
  206. package/lib/process.d.ts.map +0 -1
  207. package/lib/process.js +0 -23
  208. package/lib/process.js.map +0 -1
  209. package/lib/progress.d.ts +0 -56
  210. package/lib/progress.d.ts.map +0 -1
  211. package/lib/progress.js +0 -27
  212. package/lib/progress.js.map +0 -1
  213. package/lib/sequence.d.ts +0 -20
  214. package/lib/sequence.d.ts.map +0 -1
  215. package/lib/sequence.js +0 -17
  216. package/lib/sequence.js.map +0 -1
  217. package/lib/uint.d.ts +0 -32
  218. package/lib/uint.d.ts.map +0 -1
  219. package/lib/uint.js +0 -28
  220. package/lib/uint.js.map +0 -1
  221. package/lib/uri.d.ts +0 -94
  222. package/lib/uri.d.ts.map +0 -1
  223. package/lib/uri.js +0 -231
  224. package/lib/uri.js.map +0 -1
  225. package/lib/utils/ansi.d.ts +0 -5
  226. package/lib/utils/ansi.d.ts.map +0 -1
  227. package/lib/utils/ansi.js +0 -14
  228. package/lib/utils/ansi.js.map +0 -1
  229. package/lib/utils/arrays.d.ts +0 -66
  230. package/lib/utils/arrays.d.ts.map +0 -1
  231. package/lib/utils/arrays.js +0 -260
  232. package/lib/utils/arrays.js.map +0 -1
  233. package/lib/utils/buffer.d.ts +0 -35
  234. package/lib/utils/buffer.d.ts.map +0 -1
  235. package/lib/utils/buffer.js +0 -174
  236. package/lib/utils/buffer.js.map +0 -1
  237. package/lib/utils/comparers.d.ts.map +0 -1
  238. package/lib/utils/comparers.js.map +0 -1
  239. package/lib/utils/decorators.d.ts +0 -11
  240. package/lib/utils/decorators.d.ts.map +0 -1
  241. package/lib/utils/decorators.js +0 -151
  242. package/lib/utils/decorators.js.map +0 -1
  243. package/lib/utils/file-uri.d.ts +0 -15
  244. package/lib/utils/file-uri.d.ts.map +0 -1
  245. package/lib/utils/file-uri.js +0 -46
  246. package/lib/utils/file-uri.js.map +0 -1
  247. package/lib/utils/glob.d.ts +0 -46
  248. package/lib/utils/glob.d.ts.map +0 -1
  249. package/lib/utils/glob.js +0 -556
  250. package/lib/utils/glob.js.map +0 -1
  251. package/lib/utils/hash.d.ts +0 -38
  252. package/lib/utils/hash.d.ts.map +0 -1
  253. package/lib/utils/hash.js +0 -294
  254. package/lib/utils/hash.js.map +0 -1
  255. package/lib/utils/index.d.ts +0 -15
  256. package/lib/utils/index.d.ts.map +0 -1
  257. package/lib/utils/index.js +0 -18
  258. package/lib/utils/index.js.map +0 -1
  259. package/lib/utils/json.d.ts +0 -76
  260. package/lib/utils/json.d.ts.map +0 -1
  261. package/lib/utils/json.js +0 -188
  262. package/lib/utils/json.js.map +0 -1
  263. package/lib/utils/markdown.d.ts.map +0 -1
  264. package/lib/utils/markdown.js.map +0 -1
  265. package/lib/utils/marshalling.d.ts +0 -7
  266. package/lib/utils/marshalling.d.ts.map +0 -1
  267. package/lib/utils/marshalling.js +0 -59
  268. package/lib/utils/marshalling.js.map +0 -1
  269. package/lib/utils/objects.d.ts +0 -6
  270. package/lib/utils/objects.d.ts.map +0 -1
  271. package/lib/utils/objects.js +0 -103
  272. package/lib/utils/objects.js.map +0 -1
  273. package/lib/utils/os.d.ts +0 -49
  274. package/lib/utils/os.d.ts.map +0 -1
  275. package/lib/utils/os.js +0 -98
  276. package/lib/utils/os.js.map +0 -1
  277. package/lib/utils/paths.d.ts +0 -35
  278. package/lib/utils/paths.d.ts.map +0 -1
  279. package/lib/utils/paths.js +0 -313
  280. package/lib/utils/paths.js.map +0 -1
  281. package/lib/utils/promise-util.d.ts +0 -10
  282. package/lib/utils/promise-util.d.ts.map +0 -1
  283. package/lib/utils/promise-util.js +0 -17
  284. package/lib/utils/promise-util.js.map +0 -1
  285. package/lib/utils/strings.d.ts +0 -181
  286. package/lib/utils/strings.d.ts.map +0 -1
  287. package/lib/utils/strings.js +0 -858
  288. package/lib/utils/strings.js.map +0 -1
  289. package/lib/utils/types.d.ts +0 -69
  290. package/lib/utils/types.d.ts.map +0 -1
  291. package/lib/utils/types.js +0 -201
  292. package/lib/utils/types.js.map +0 -1
  293. package/lib/uuid.d.ts +0 -2
  294. package/lib/uuid.d.ts.map +0 -1
  295. package/lib/uuid.js +0 -10
  296. package/lib/uuid.js.map +0 -1
package/lib/filters.js DELETED
@@ -1,699 +0,0 @@
1
- "use strict";
2
- /* ---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
- // Some code copied and modified from https://github.com/microsoft/vscode/blob/1.44.0/src/vs/base/common/filters.ts
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.fuzzyScoreGraceful = exports.fuzzyScoreGracefulAggressive = exports.fuzzyScore = exports.FuzzyScore = exports.isPatternInWord = exports.createMatches = exports.anyScore = exports.matchesFuzzy2 = exports.matchesFuzzy = exports.matchesWords = exports.matchesCamelCase = exports.isUpper = exports.matchesSubString = exports.matchesContiguousSubString = exports.matchesPrefix = exports.matchesStrictPrefix = exports.or = void 0;
9
- const tslib_1 = require("tslib");
10
- const map_1 = require("./map");
11
- const strings = tslib_1.__importStar(require("./utils/strings"));
12
- // Combined filters
13
- /**
14
- * @returns A filter which combines the provided set
15
- * of filters with an or. The *first* filters that
16
- * matches defined the return value of the returned
17
- * filter.
18
- */
19
- function or(...filter) {
20
- return function (word, wordToMatchAgainst) {
21
- for (let i = 0, len = filter.length; i < len; i++) {
22
- const match = filter[i](word, wordToMatchAgainst);
23
- if (match) {
24
- return match;
25
- }
26
- }
27
- return null;
28
- };
29
- }
30
- exports.or = or;
31
- // Prefix
32
- exports.matchesStrictPrefix = _matchesPrefix.bind(undefined, false);
33
- exports.matchesPrefix = _matchesPrefix.bind(undefined, true);
34
- function _matchesPrefix(ignoreCase, word, wordToMatchAgainst) {
35
- if (!wordToMatchAgainst || wordToMatchAgainst.length < word.length) {
36
- return null;
37
- }
38
- let matches;
39
- if (ignoreCase) {
40
- matches = strings.startsWithIgnoreCase(wordToMatchAgainst, word);
41
- }
42
- else {
43
- matches = wordToMatchAgainst.indexOf(word) === 0;
44
- }
45
- if (!matches) {
46
- return null;
47
- }
48
- return word.length > 0 ? [{ start: 0, end: word.length }] : [];
49
- }
50
- // Contiguous Substring
51
- function matchesContiguousSubString(word, wordToMatchAgainst) {
52
- const index = wordToMatchAgainst.toLowerCase().indexOf(word.toLowerCase());
53
- if (index === -1) {
54
- return null;
55
- }
56
- return [{ start: index, end: index + word.length }];
57
- }
58
- exports.matchesContiguousSubString = matchesContiguousSubString;
59
- // Substring
60
- function matchesSubString(word, wordToMatchAgainst) {
61
- return _matchesSubString(word.toLowerCase(), wordToMatchAgainst.toLowerCase(), 0, 0);
62
- }
63
- exports.matchesSubString = matchesSubString;
64
- function _matchesSubString(word, wordToMatchAgainst, i, j) {
65
- if (i === word.length) {
66
- return [];
67
- }
68
- else if (j === wordToMatchAgainst.length) {
69
- return null;
70
- }
71
- else {
72
- if (word[i] === wordToMatchAgainst[j]) {
73
- let result = null;
74
- if ((result = _matchesSubString(word, wordToMatchAgainst, i + 1, j + 1))) {
75
- return join({ start: j, end: j + 1 }, result);
76
- }
77
- return null;
78
- }
79
- return _matchesSubString(word, wordToMatchAgainst, i, j + 1);
80
- }
81
- }
82
- // CamelCase
83
- function isLower(code) {
84
- return 97 /* a */ <= code && code <= 122 /* z */;
85
- }
86
- function isUpper(code) {
87
- return 65 /* A */ <= code && code <= 90 /* Z */;
88
- }
89
- exports.isUpper = isUpper;
90
- function isNumber(code) {
91
- return 48 /* Digit0 */ <= code && code <= 57 /* Digit9 */;
92
- }
93
- function isWhitespace(code) {
94
- return (code === 32 /* Space */ || code === 9 /* Tab */ || code === 10 /* LineFeed */ || code === 13 /* CarriageReturn */);
95
- }
96
- const wordSeparators = new Set();
97
- '`~!@#$%^&*()-=+[{]}\\|;:\'",.<>/?'.split('').forEach((s) => wordSeparators.add(s.charCodeAt(0)));
98
- function isWordSeparator(code) {
99
- return isWhitespace(code) || wordSeparators.has(code);
100
- }
101
- function charactersMatch(codeA, codeB) {
102
- return codeA === codeB || (isWordSeparator(codeA) && isWordSeparator(codeB));
103
- }
104
- function isAlphanumeric(code) {
105
- return isLower(code) || isUpper(code) || isNumber(code);
106
- }
107
- function join(head, tail) {
108
- if (tail.length === 0) {
109
- tail = [head];
110
- }
111
- else if (head.end === tail[0].start) {
112
- tail[0].start = head.start;
113
- }
114
- else {
115
- tail.unshift(head);
116
- }
117
- return tail;
118
- }
119
- function nextAnchor(camelCaseWord, start) {
120
- for (let i = start; i < camelCaseWord.length; i++) {
121
- const c = camelCaseWord.charCodeAt(i);
122
- if (isUpper(c) || isNumber(c) || (i > 0 && !isAlphanumeric(camelCaseWord.charCodeAt(i - 1)))) {
123
- return i;
124
- }
125
- }
126
- return camelCaseWord.length;
127
- }
128
- function _matchesCamelCase(word, camelCaseWord, i, j) {
129
- if (i === word.length) {
130
- return [];
131
- }
132
- else if (j === camelCaseWord.length) {
133
- return null;
134
- }
135
- else if (word[i] !== camelCaseWord[j].toLowerCase()) {
136
- return null;
137
- }
138
- else {
139
- let result = null;
140
- let nextUpperIndex = j + 1;
141
- result = _matchesCamelCase(word, camelCaseWord, i + 1, j + 1);
142
- while (!result && (nextUpperIndex = nextAnchor(camelCaseWord, nextUpperIndex)) < camelCaseWord.length) {
143
- result = _matchesCamelCase(word, camelCaseWord, i + 1, nextUpperIndex);
144
- nextUpperIndex++;
145
- }
146
- return result === null ? null : join({ start: j, end: j + 1 }, result);
147
- }
148
- }
149
- // Heuristic to avoid computing camel case matcher for words that don't
150
- // look like camelCaseWords.
151
- function analyzeCamelCaseWord(word) {
152
- let upper = 0;
153
- let lower = 0;
154
- let alpha = 0;
155
- let numeric = 0;
156
- let code = 0;
157
- for (let i = 0; i < word.length; i++) {
158
- code = word.charCodeAt(i);
159
- if (isUpper(code)) {
160
- upper++;
161
- }
162
- if (isLower(code)) {
163
- lower++;
164
- }
165
- if (isAlphanumeric(code)) {
166
- alpha++;
167
- }
168
- if (isNumber(code)) {
169
- numeric++;
170
- }
171
- }
172
- const upperPercent = upper / word.length;
173
- const lowerPercent = lower / word.length;
174
- const alphaPercent = alpha / word.length;
175
- const numericPercent = numeric / word.length;
176
- return { upperPercent, lowerPercent, alphaPercent, numericPercent };
177
- }
178
- function isUpperCaseWord(analysis) {
179
- const { upperPercent, lowerPercent } = analysis;
180
- return lowerPercent === 0 && upperPercent > 0.6;
181
- }
182
- function isCamelCaseWord(analysis) {
183
- const { upperPercent, lowerPercent, alphaPercent, numericPercent } = analysis;
184
- return lowerPercent > 0.2 && upperPercent < 0.8 && alphaPercent > 0.6 && numericPercent < 0.2;
185
- }
186
- // Heuristic to avoid computing camel case matcher for words that don't
187
- // look like camel case patterns.
188
- function isCamelCasePattern(word) {
189
- let upper = 0;
190
- let lower = 0;
191
- let code = 0;
192
- let whitespace = 0;
193
- for (let i = 0; i < word.length; i++) {
194
- code = word.charCodeAt(i);
195
- if (isUpper(code)) {
196
- upper++;
197
- }
198
- if (isLower(code)) {
199
- lower++;
200
- }
201
- if (isWhitespace(code)) {
202
- whitespace++;
203
- }
204
- }
205
- if ((upper === 0 || lower === 0) && whitespace === 0) {
206
- return word.length <= 30;
207
- }
208
- else {
209
- return upper <= 5;
210
- }
211
- }
212
- function matchesCamelCase(word, camelCaseWord) {
213
- if (!camelCaseWord) {
214
- return null;
215
- }
216
- camelCaseWord = camelCaseWord.trim();
217
- if (camelCaseWord.length === 0) {
218
- return null;
219
- }
220
- if (!isCamelCasePattern(word)) {
221
- return null;
222
- }
223
- if (camelCaseWord.length > 60) {
224
- return null;
225
- }
226
- const analysis = analyzeCamelCaseWord(camelCaseWord);
227
- if (!isCamelCaseWord(analysis)) {
228
- if (!isUpperCaseWord(analysis)) {
229
- return null;
230
- }
231
- camelCaseWord = camelCaseWord.toLowerCase();
232
- }
233
- let result = null;
234
- let i = 0;
235
- word = word.toLowerCase();
236
- while (i < camelCaseWord.length && (result = _matchesCamelCase(word, camelCaseWord, 0, i)) === null) {
237
- i = nextAnchor(camelCaseWord, i + 1);
238
- }
239
- return result;
240
- }
241
- exports.matchesCamelCase = matchesCamelCase;
242
- // Matches beginning of words supporting non-ASCII languages
243
- // If `contiguous` is true then matches word with beginnings of the words in the target. E.g. "pul" will match "Git: Pull"
244
- // Otherwise also matches sub string of the word with beginnings of the words in the target. E.g. "gp" or "g p" will match "Git: Pull"
245
- // Useful in cases where the target is words (e.g. command labels)
246
- function matchesWords(word, target, contiguous = false) {
247
- if (!target || target.length === 0) {
248
- return null;
249
- }
250
- let result = null;
251
- let i = 0;
252
- word = word.toLowerCase();
253
- target = target.toLowerCase();
254
- while (i < target.length && (result = _matchesWords(word, target, 0, i, contiguous)) === null) {
255
- i = nextWord(target, i + 1);
256
- }
257
- return result;
258
- }
259
- exports.matchesWords = matchesWords;
260
- function _matchesWords(word, target, i, j, contiguous) {
261
- if (i === word.length) {
262
- return [];
263
- }
264
- else if (j === target.length) {
265
- return null;
266
- }
267
- else if (!charactersMatch(word.charCodeAt(i), target.charCodeAt(j))) {
268
- return null;
269
- }
270
- else {
271
- let result = null;
272
- let nextWordIndex = j + 1;
273
- result = _matchesWords(word, target, i + 1, j + 1, contiguous);
274
- if (!contiguous) {
275
- while (!result && (nextWordIndex = nextWord(target, nextWordIndex)) < target.length) {
276
- result = _matchesWords(word, target, i + 1, nextWordIndex, contiguous);
277
- nextWordIndex++;
278
- }
279
- }
280
- return result === null ? null : join({ start: j, end: j + 1 }, result);
281
- }
282
- }
283
- function nextWord(word, start) {
284
- for (let i = start; i < word.length; i++) {
285
- if (isWordSeparator(word.charCodeAt(i)) || (i > 0 && isWordSeparator(word.charCodeAt(i - 1)))) {
286
- return i;
287
- }
288
- }
289
- return word.length;
290
- }
291
- // Fuzzy
292
- const fuzzyContiguousFilter = or(exports.matchesPrefix, matchesCamelCase, matchesContiguousSubString);
293
- const fuzzySeparateFilter = or(exports.matchesPrefix, matchesCamelCase, matchesSubString);
294
- const fuzzyRegExpCache = new map_1.LRUCache(10000); // bounded to 10000 elements
295
- function matchesFuzzy(word, wordToMatchAgainst, enableSeparateSubstringMatching = false) {
296
- if (typeof word !== 'string' || typeof wordToMatchAgainst !== 'string') {
297
- return null; // return early for invalid input
298
- }
299
- // Form RegExp for wildcard matches
300
- let regexp = fuzzyRegExpCache.get(word);
301
- if (!regexp) {
302
- regexp = new RegExp(strings.convertSimple2RegExpPattern(word), 'i');
303
- fuzzyRegExpCache.set(word, regexp);
304
- }
305
- // RegExp Filter
306
- const match = regexp.exec(wordToMatchAgainst);
307
- if (match) {
308
- return [{ start: match.index, end: match.index + match[0].length }];
309
- }
310
- // Default Filter
311
- return enableSeparateSubstringMatching
312
- ? fuzzySeparateFilter(word, wordToMatchAgainst)
313
- : fuzzyContiguousFilter(word, wordToMatchAgainst);
314
- }
315
- exports.matchesFuzzy = matchesFuzzy;
316
- /**
317
- * Match pattern againt word in a fuzzy way. As in IntelliSense and faster and more
318
- * powerfull than `matchesFuzzy`
319
- */
320
- function matchesFuzzy2(pattern, word) {
321
- const score = fuzzyScore(pattern, pattern.toLowerCase(), 0, word, word.toLowerCase(), 0, true);
322
- return score ? createMatches(score) : null;
323
- }
324
- exports.matchesFuzzy2 = matchesFuzzy2;
325
- function anyScore(pattern, lowPattern, _patternPos, word, lowWord, _wordPos) {
326
- const result = fuzzyScore(pattern, lowPattern, 0, word, lowWord, 0, true);
327
- if (result) {
328
- return result;
329
- }
330
- let matches = 0;
331
- let score = 0;
332
- let idx = _wordPos;
333
- for (let patternPos = 0; patternPos < lowPattern.length && patternPos < _maxLen; ++patternPos) {
334
- const wordPos = lowWord.indexOf(lowPattern.charAt(patternPos), idx);
335
- if (wordPos >= 0) {
336
- score += 1;
337
- matches += 2 ** wordPos;
338
- idx = wordPos + 1;
339
- }
340
- else if (matches !== 0) {
341
- // once we have started matching things
342
- // we need to match the remaining pattern
343
- // characters
344
- break;
345
- }
346
- }
347
- return [score, matches, _wordPos];
348
- }
349
- exports.anyScore = anyScore;
350
- // #region --- fuzzyScore ---
351
- function createMatches(score) {
352
- if (typeof score === 'undefined') {
353
- return [];
354
- }
355
- const matches = score[1].toString(2);
356
- const wordStart = score[2];
357
- const res = [];
358
- for (let pos = wordStart; pos < _maxLen; pos++) {
359
- if (matches[matches.length - (pos + 1)] === '1') {
360
- const last = res[res.length - 1];
361
- if (last && last.end === pos) {
362
- last.end = pos + 1;
363
- }
364
- else {
365
- res.push({ start: pos, end: pos + 1 });
366
- }
367
- }
368
- }
369
- return res;
370
- }
371
- exports.createMatches = createMatches;
372
- const _maxLen = 128;
373
- function initTable() {
374
- const table = [];
375
- const row = [0];
376
- for (let i = 1; i <= _maxLen; i++) {
377
- row.push(-i);
378
- }
379
- for (let i = 0; i <= _maxLen; i++) {
380
- const thisRow = row.slice(0);
381
- thisRow[0] = -i;
382
- table.push(thisRow);
383
- }
384
- return table;
385
- }
386
- const _table = initTable();
387
- const _scores = initTable();
388
- const _arrows = initTable();
389
- const _debug = false;
390
- function printTable(table, pattern, patternLen, word, wordLen) {
391
- function pad(s, n, pad = ' ') {
392
- while (s.length < n) {
393
- s = pad + s;
394
- }
395
- return s;
396
- }
397
- let ret = ` | |${word
398
- .split('')
399
- .map((c) => pad(c, 3))
400
- .join('|')}\n`;
401
- for (let i = 0; i <= patternLen; i++) {
402
- if (i === 0) {
403
- ret += ' |';
404
- }
405
- else {
406
- ret += `${pattern[i - 1]}|`;
407
- }
408
- ret +=
409
- table[i]
410
- .slice(0, wordLen + 1)
411
- .map((n) => pad(n.toString(), 3))
412
- .join('|') + '\n';
413
- }
414
- return ret;
415
- }
416
- function isSeparatorAtPos(value, index) {
417
- if (index < 0 || index >= value.length) {
418
- return false;
419
- }
420
- const code = value.charCodeAt(index);
421
- switch (code) {
422
- case 95 /* Underline */:
423
- case 45 /* Dash */:
424
- case 46 /* Period */:
425
- case 32 /* Space */:
426
- case 47 /* Slash */:
427
- case 92 /* Backslash */:
428
- case 39 /* SingleQuote */:
429
- case 34 /* DoubleQuote */:
430
- case 58 /* Colon */:
431
- case 36 /* DollarSign */:
432
- return true;
433
- default:
434
- return false;
435
- }
436
- }
437
- function isWhitespaceAtPos(value, index) {
438
- if (index < 0 || index >= value.length) {
439
- return false;
440
- }
441
- const code = value.charCodeAt(index);
442
- switch (code) {
443
- case 32 /* Space */:
444
- case 9 /* Tab */:
445
- return true;
446
- default:
447
- return false;
448
- }
449
- }
450
- function isUpperCaseAtPos(pos, word, wordLow) {
451
- return word[pos] !== wordLow[pos];
452
- }
453
- function isPatternInWord(patternLow, patternPos, patternLen, wordLow, wordPos, wordLen) {
454
- while (patternPos < patternLen && wordPos < wordLen) {
455
- if (patternLow[patternPos] === wordLow[wordPos]) {
456
- patternPos += 1;
457
- }
458
- wordPos += 1;
459
- }
460
- return patternPos === patternLen; // pattern must be exhausted
461
- }
462
- exports.isPatternInWord = isPatternInWord;
463
- var FuzzyScore;
464
- (function (FuzzyScore) {
465
- /**
466
- * No matches and value `-100`
467
- */
468
- FuzzyScore.Default = Object.freeze([-100, 0, 0]);
469
- function isDefault(score) {
470
- return !score || (score[0] === -100 && score[1] === 0 && score[2] === 0);
471
- }
472
- FuzzyScore.isDefault = isDefault;
473
- })(FuzzyScore = exports.FuzzyScore || (exports.FuzzyScore = {}));
474
- function fuzzyScore(pattern, patternLow, patternPos, word, wordLow, wordPos, firstMatchCanBeWeak) {
475
- const patternLen = pattern.length > _maxLen ? _maxLen : pattern.length;
476
- const wordLen = word.length > _maxLen ? _maxLen : word.length;
477
- if (patternPos >= patternLen || wordPos >= wordLen || patternLen > wordLen) {
478
- return undefined;
479
- }
480
- // Run a simple check if the characters of pattern occur
481
- // (in order) at all in word. If that isn't the case we
482
- // stop because no match will be possible
483
- if (!isPatternInWord(patternLow, patternPos, patternLen, wordLow, wordPos, wordLen)) {
484
- return undefined;
485
- }
486
- const patternStartPos = patternPos;
487
- const wordStartPos = wordPos;
488
- // There will be a mach, fill in tables
489
- for (patternPos = patternStartPos + 1; patternPos <= patternLen; patternPos++) {
490
- for (wordPos = 1; wordPos <= wordLen; wordPos++) {
491
- let score = -1;
492
- if (patternLow[patternPos - 1] === wordLow[wordPos - 1]) {
493
- if (wordPos === patternPos - patternStartPos) {
494
- // common prefix: `foobar <-> foobaz`
495
- // ^^^^^
496
- if (pattern[patternPos - 1] === word[wordPos - 1]) {
497
- score = 7;
498
- }
499
- else {
500
- score = 5;
501
- }
502
- }
503
- else if (isUpperCaseAtPos(wordPos - 1, word, wordLow) &&
504
- (wordPos === 1 || !isUpperCaseAtPos(wordPos - 2, word, wordLow))) {
505
- // hitting upper-case: `foo <-> forOthers`
506
- // ^^ ^
507
- if (pattern[patternPos - 1] === word[wordPos - 1]) {
508
- score = 7;
509
- }
510
- else {
511
- score = 5;
512
- }
513
- }
514
- else if (isSeparatorAtPos(wordLow, wordPos - 2) || isWhitespaceAtPos(wordLow, wordPos - 2)) {
515
- // post separator: `foo <-> bar_foo`
516
- // ^^^
517
- score = 5;
518
- }
519
- else {
520
- score = 1;
521
- }
522
- }
523
- _scores[patternPos][wordPos] = score;
524
- const diag = _table[patternPos - 1][wordPos - 1] + (score > 1 ? 1 : score);
525
- const top = _table[patternPos - 1][wordPos] + -1;
526
- const left = _table[patternPos][wordPos - 1] + -1;
527
- if (left >= top) {
528
- // left or diag
529
- if (left > diag) {
530
- _table[patternPos][wordPos] = left;
531
- _arrows[patternPos][wordPos] = 4 /* Left */;
532
- }
533
- else if (left === diag) {
534
- _table[patternPos][wordPos] = left;
535
- _arrows[patternPos][wordPos] = 4 /* Left */ | 2 /* Diag */;
536
- }
537
- else {
538
- _table[patternPos][wordPos] = diag;
539
- _arrows[patternPos][wordPos] = 2 /* Diag */;
540
- }
541
- }
542
- else {
543
- // top or diag
544
- if (top > diag) {
545
- _table[patternPos][wordPos] = top;
546
- _arrows[patternPos][wordPos] = 1 /* Top */;
547
- }
548
- else if (top === diag) {
549
- _table[patternPos][wordPos] = top;
550
- _arrows[patternPos][wordPos] = 1 /* Top */ | 2 /* Diag */;
551
- }
552
- else {
553
- _table[patternPos][wordPos] = diag;
554
- _arrows[patternPos][wordPos] = 2 /* Diag */;
555
- }
556
- }
557
- }
558
- }
559
- if (_debug) {
560
- // eslint-disable-next-line no-console
561
- console.log(printTable(_table, pattern, patternLen, word, wordLen));
562
- // eslint-disable-next-line no-console
563
- console.log(printTable(_arrows, pattern, patternLen, word, wordLen));
564
- // eslint-disable-next-line no-console
565
- console.log(printTable(_scores, pattern, patternLen, word, wordLen));
566
- }
567
- _matchesCount = 0;
568
- _topScore = -100;
569
- _patternStartPos = patternStartPos;
570
- _firstMatchCanBeWeak = firstMatchCanBeWeak;
571
- _findAllMatches2(patternLen, wordLen, patternLen === wordLen ? 1 : 0, 0, false);
572
- if (_matchesCount === 0) {
573
- return undefined;
574
- }
575
- return [_topScore, _topMatch2, wordStartPos];
576
- }
577
- exports.fuzzyScore = fuzzyScore;
578
- let _matchesCount = 0;
579
- let _topMatch2 = 0;
580
- let _topScore = 0;
581
- let _patternStartPos = 0;
582
- let _firstMatchCanBeWeak = false;
583
- function _findAllMatches2(patternPos, wordPos, total, matches, lastMatched) {
584
- if (_matchesCount >= 10 || total < -25) {
585
- // stop when having already 10 results, or
586
- // when a potential alignment as already 5 gaps
587
- return;
588
- }
589
- let simpleMatchCount = 0;
590
- while (patternPos > _patternStartPos && wordPos > 0) {
591
- const score = _scores[patternPos][wordPos];
592
- const arrow = _arrows[patternPos][wordPos];
593
- if (arrow === 4 /* Left */) {
594
- // left -> no match, skip a word character
595
- wordPos -= 1;
596
- if (lastMatched) {
597
- total -= 5; // new gap penalty
598
- }
599
- else if (matches !== 0) {
600
- total -= 1; // gap penalty after first match
601
- }
602
- lastMatched = false;
603
- simpleMatchCount = 0;
604
- }
605
- else if (arrow & 2 /* Diag */) {
606
- if (arrow & 4 /* Left */) {
607
- // left
608
- _findAllMatches2(patternPos, wordPos - 1, matches !== 0 ? total - 1 : total, // gap penalty after first match
609
- matches, lastMatched);
610
- }
611
- // diag
612
- total += score;
613
- patternPos -= 1;
614
- wordPos -= 1;
615
- lastMatched = true;
616
- // match -> set a 1 at the word pos
617
- matches += 2 ** wordPos;
618
- // count simple matches and boost a row of
619
- // simple matches when they yield in a
620
- // strong match.
621
- if (score === 1) {
622
- simpleMatchCount += 1;
623
- if (patternPos === _patternStartPos && !_firstMatchCanBeWeak) {
624
- // when the first match is a weak
625
- // match we discard it
626
- return undefined;
627
- }
628
- }
629
- else {
630
- // boost
631
- total += 1 + simpleMatchCount * (score - 1);
632
- simpleMatchCount = 0;
633
- }
634
- }
635
- else {
636
- return undefined;
637
- }
638
- }
639
- total -= wordPos >= 3 ? 9 : wordPos * 3; // late start penalty
640
- // dynamically keep track of the current top score
641
- // and insert the current best score at head, the rest at tail
642
- _matchesCount += 1;
643
- if (total > _topScore) {
644
- _topScore = total;
645
- _topMatch2 = matches;
646
- }
647
- }
648
- // #endregion
649
- // #region --- graceful ---
650
- function fuzzyScoreGracefulAggressive(pattern, lowPattern, patternPos, word, lowWord, wordPos, firstMatchCanBeWeak) {
651
- return fuzzyScoreWithPermutations(pattern, lowPattern, patternPos, word, lowWord, wordPos, true, firstMatchCanBeWeak);
652
- }
653
- exports.fuzzyScoreGracefulAggressive = fuzzyScoreGracefulAggressive;
654
- function fuzzyScoreGraceful(pattern, lowPattern, patternPos, word, lowWord, wordPos, firstMatchCanBeWeak) {
655
- return fuzzyScoreWithPermutations(pattern, lowPattern, patternPos, word, lowWord, wordPos, false, firstMatchCanBeWeak);
656
- }
657
- exports.fuzzyScoreGraceful = fuzzyScoreGraceful;
658
- function fuzzyScoreWithPermutations(pattern, lowPattern, patternPos, word, lowWord, wordPos, aggressive, firstMatchCanBeWeak) {
659
- let top = fuzzyScore(pattern, lowPattern, patternPos, word, lowWord, wordPos, firstMatchCanBeWeak);
660
- if (top && !aggressive) {
661
- // when using the original pattern yield a result we`
662
- // return it unless we are aggressive and try to find
663
- // a better alignment, e.g. `cno` -> `^co^ns^ole` or `^c^o^nsole`.
664
- return top;
665
- }
666
- if (pattern.length >= 3) {
667
- // When the pattern is long enough then try a few (max 7)
668
- // permutations of the pattern to find a better match. The
669
- // permutations only swap neighbouring characters, e.g
670
- // `cnoso` becomes `conso`, `cnsoo`, `cnoos`.
671
- const tries = Math.min(7, pattern.length - 1);
672
- for (let movingPatternPos = patternPos + 1; movingPatternPos < tries; movingPatternPos++) {
673
- const newPattern = nextTypoPermutation(pattern, movingPatternPos);
674
- if (newPattern) {
675
- const candidate = fuzzyScore(newPattern, newPattern.toLowerCase(), patternPos, word, lowWord, wordPos, firstMatchCanBeWeak);
676
- if (candidate) {
677
- candidate[0] -= 3; // permutation penalty
678
- if (!top || candidate[0] > top[0]) {
679
- top = candidate;
680
- }
681
- }
682
- }
683
- }
684
- }
685
- return top;
686
- }
687
- function nextTypoPermutation(pattern, patternPos) {
688
- if (patternPos + 1 >= pattern.length) {
689
- return undefined;
690
- }
691
- const swap1 = pattern[patternPos];
692
- const swap2 = pattern[patternPos + 1];
693
- if (swap1 === swap2) {
694
- return undefined;
695
- }
696
- return pattern.slice(0, patternPos) + swap2 + swap1 + pattern.slice(patternPos + 2);
697
- }
698
- // #endregion
699
- //# sourceMappingURL=filters.js.map