@lvce-editor/file-search-worker 2.3.0 → 3.1.0
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/dist/fileSearchWorkerMain.js +393 -201
- package/package.json +10 -4
|
@@ -1126,6 +1126,394 @@ const getFiles = () => {
|
|
|
1126
1126
|
return state$2.files;
|
|
1127
1127
|
};
|
|
1128
1128
|
|
|
1129
|
+
const emptyMatches = [];
|
|
1130
|
+
|
|
1131
|
+
const convertToPick = item => {
|
|
1132
|
+
return {
|
|
1133
|
+
pick: item,
|
|
1134
|
+
matches: emptyMatches
|
|
1135
|
+
};
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
const Diagonal = 1;
|
|
1139
|
+
const Left = 2;
|
|
1140
|
+
|
|
1141
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1142
|
+
|
|
1143
|
+
const createTable = size => {
|
|
1144
|
+
const table = [];
|
|
1145
|
+
for (let i = 0; i < size; i++) {
|
|
1146
|
+
const row = new Uint8Array(size);
|
|
1147
|
+
table.push(row);
|
|
1148
|
+
}
|
|
1149
|
+
return table;
|
|
1150
|
+
};
|
|
1151
|
+
const EmptyMatches = [];
|
|
1152
|
+
const Dash = '-';
|
|
1153
|
+
const Dot = '.';
|
|
1154
|
+
const EmptyString = '';
|
|
1155
|
+
const Space = ' ';
|
|
1156
|
+
const Underline = '_';
|
|
1157
|
+
const T = 't';
|
|
1158
|
+
const isLowerCase = char => {
|
|
1159
|
+
return char === char.toLowerCase();
|
|
1160
|
+
};
|
|
1161
|
+
const isUpperCase = char => {
|
|
1162
|
+
return char === char.toUpperCase();
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1166
|
+
const isGap = (columnCharBefore, columnChar) => {
|
|
1167
|
+
switch (columnCharBefore) {
|
|
1168
|
+
case Dash:
|
|
1169
|
+
case Underline:
|
|
1170
|
+
case EmptyString:
|
|
1171
|
+
case T:
|
|
1172
|
+
case Space:
|
|
1173
|
+
case Dot:
|
|
1174
|
+
return true;
|
|
1175
|
+
}
|
|
1176
|
+
if (isLowerCase(columnCharBefore) && isUpperCase(columnChar)) {
|
|
1177
|
+
return true;
|
|
1178
|
+
}
|
|
1179
|
+
return false;
|
|
1180
|
+
};
|
|
1181
|
+
|
|
1182
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1183
|
+
const getScore = (rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, isDiagonalMatch) => {
|
|
1184
|
+
if (rowCharLow !== columnCharLow) {
|
|
1185
|
+
return -1;
|
|
1186
|
+
}
|
|
1187
|
+
const isMatch = rowChar === columnChar;
|
|
1188
|
+
if (isMatch) {
|
|
1189
|
+
if (isDiagonalMatch) {
|
|
1190
|
+
return 8;
|
|
1191
|
+
}
|
|
1192
|
+
if (isGap(columnCharBefore, columnChar)) {
|
|
1193
|
+
return 8;
|
|
1194
|
+
}
|
|
1195
|
+
return 5;
|
|
1196
|
+
}
|
|
1197
|
+
if (isGap(columnCharBefore, columnChar)) {
|
|
1198
|
+
return 8;
|
|
1199
|
+
}
|
|
1200
|
+
return 5;
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1203
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1204
|
+
|
|
1205
|
+
const isPatternInWord = (patternLow, patternPos, patternLen, wordLow, wordPos, wordLen) => {
|
|
1206
|
+
while (patternPos < patternLen && wordPos < wordLen) {
|
|
1207
|
+
if (patternLow[patternPos] === wordLow[wordPos]) {
|
|
1208
|
+
patternPos += 1;
|
|
1209
|
+
}
|
|
1210
|
+
wordPos += 1;
|
|
1211
|
+
}
|
|
1212
|
+
return patternPos === patternLen; // pattern must be exhausted
|
|
1213
|
+
};
|
|
1214
|
+
|
|
1215
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1216
|
+
const traceHighlights = (table, arrows, patternLength, wordLength) => {
|
|
1217
|
+
let row = patternLength;
|
|
1218
|
+
let column = wordLength;
|
|
1219
|
+
const matches = [];
|
|
1220
|
+
while (row >= 1 && column >= 1) {
|
|
1221
|
+
const arrow = arrows[row][column];
|
|
1222
|
+
if (arrow === Left) {
|
|
1223
|
+
column--;
|
|
1224
|
+
} else if (arrow === Diagonal) {
|
|
1225
|
+
row--;
|
|
1226
|
+
column--;
|
|
1227
|
+
const start = column + 1;
|
|
1228
|
+
while (row >= 1 && column >= 1) {
|
|
1229
|
+
const arrow = arrows[row][column];
|
|
1230
|
+
if (arrow === Left) {
|
|
1231
|
+
break;
|
|
1232
|
+
}
|
|
1233
|
+
if (arrow === Diagonal) {
|
|
1234
|
+
row--;
|
|
1235
|
+
column--;
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
const end = column;
|
|
1239
|
+
matches.unshift(end, start);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
matches.unshift(table[patternLength][wordLength - 1]);
|
|
1243
|
+
return matches;
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1246
|
+
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1247
|
+
const gridSize = 128;
|
|
1248
|
+
const table = createTable(gridSize);
|
|
1249
|
+
const arrows = createTable(gridSize);
|
|
1250
|
+
const fuzzySearch = (pattern, word) => {
|
|
1251
|
+
const patternLength = Math.min(pattern.length, gridSize - 1);
|
|
1252
|
+
const wordLength = Math.min(word.length, gridSize - 1);
|
|
1253
|
+
const patternLower = pattern.toLowerCase();
|
|
1254
|
+
const wordLower = word.toLowerCase();
|
|
1255
|
+
if (!isPatternInWord(patternLower, 0, patternLength, wordLower, 0, wordLength)) {
|
|
1256
|
+
return EmptyMatches;
|
|
1257
|
+
}
|
|
1258
|
+
let strongMatch = false;
|
|
1259
|
+
for (let row = 1; row < patternLength + 1; row++) {
|
|
1260
|
+
const rowChar = pattern[row - 1];
|
|
1261
|
+
const rowCharLow = patternLower[row - 1];
|
|
1262
|
+
for (let column = 1; column < wordLength + 1; column++) {
|
|
1263
|
+
const columnChar = word[column - 1];
|
|
1264
|
+
const columnCharLow = wordLower[column - 1];
|
|
1265
|
+
const columnCharBefore = word[column - 2] || '';
|
|
1266
|
+
const isDiagonalMatch = arrows[row - 1][column - 1] === Diagonal;
|
|
1267
|
+
const score = getScore(rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, isDiagonalMatch);
|
|
1268
|
+
if (row === 1 && score > 5) {
|
|
1269
|
+
strongMatch = true;
|
|
1270
|
+
}
|
|
1271
|
+
let diagonalScore = score + table[row - 1][column - 1];
|
|
1272
|
+
if (isDiagonalMatch && score !== -1) {
|
|
1273
|
+
diagonalScore += 2;
|
|
1274
|
+
}
|
|
1275
|
+
const leftScore = table[row][column - 1];
|
|
1276
|
+
if (leftScore > diagonalScore) {
|
|
1277
|
+
table[row][column] = leftScore;
|
|
1278
|
+
arrows[row][column] = Left;
|
|
1279
|
+
} else {
|
|
1280
|
+
table[row][column] = diagonalScore;
|
|
1281
|
+
arrows[row][column] = Diagonal;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
if (!strongMatch) {
|
|
1286
|
+
return EmptyMatches;
|
|
1287
|
+
}
|
|
1288
|
+
const highlights = traceHighlights(table, arrows, patternLength, wordLength);
|
|
1289
|
+
return highlights;
|
|
1290
|
+
};
|
|
1291
|
+
|
|
1292
|
+
const filterQuickPickItem = (pattern, word) => {
|
|
1293
|
+
const matches = fuzzySearch(pattern, word);
|
|
1294
|
+
return matches;
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
const getBaseName = path => {
|
|
1298
|
+
return path.slice(path.lastIndexOf('/') + 1);
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
const filterQuickPickItems = (items, value) => {
|
|
1302
|
+
if (!value) {
|
|
1303
|
+
return items.map(convertToPick);
|
|
1304
|
+
}
|
|
1305
|
+
const results = [];
|
|
1306
|
+
for (const item of items) {
|
|
1307
|
+
const baseName = getBaseName(item);
|
|
1308
|
+
const matches = filterQuickPickItem(value, baseName);
|
|
1309
|
+
if (matches.length > 0) {
|
|
1310
|
+
results.push({
|
|
1311
|
+
pick: item,
|
|
1312
|
+
matches
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
return results;
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
const Enter = 3;
|
|
1320
|
+
const Escape = 8;
|
|
1321
|
+
const PageUp = 10;
|
|
1322
|
+
const PageDown = 11;
|
|
1323
|
+
const UpArrow = 14;
|
|
1324
|
+
const DownArrow = 16;
|
|
1325
|
+
|
|
1326
|
+
const FocusQuickPickInput = 20;
|
|
1327
|
+
|
|
1328
|
+
const getKeyBindings = () => {
|
|
1329
|
+
return [{
|
|
1330
|
+
key: Escape,
|
|
1331
|
+
command: 'Viewlet.closeWidget',
|
|
1332
|
+
args: ['QuickPick'],
|
|
1333
|
+
when: FocusQuickPickInput
|
|
1334
|
+
}, {
|
|
1335
|
+
key: UpArrow,
|
|
1336
|
+
command: 'QuickPick.focusPrevious',
|
|
1337
|
+
when: FocusQuickPickInput
|
|
1338
|
+
}, {
|
|
1339
|
+
key: DownArrow,
|
|
1340
|
+
command: 'QuickPick.focusNext',
|
|
1341
|
+
when: FocusQuickPickInput
|
|
1342
|
+
}, {
|
|
1343
|
+
key: PageUp,
|
|
1344
|
+
command: 'QuickPick.focusFirst',
|
|
1345
|
+
when: FocusQuickPickInput
|
|
1346
|
+
}, {
|
|
1347
|
+
key: PageDown,
|
|
1348
|
+
command: 'QuickPick.focusLast',
|
|
1349
|
+
when: FocusQuickPickInput
|
|
1350
|
+
}, {
|
|
1351
|
+
key: Enter,
|
|
1352
|
+
command: 'QuickPick.selectCurrentIndex',
|
|
1353
|
+
when: FocusQuickPickInput
|
|
1354
|
+
}];
|
|
1355
|
+
};
|
|
1356
|
+
|
|
1357
|
+
// TODO support file icons
|
|
1358
|
+
const getFolderIcon = () => {
|
|
1359
|
+
return '';
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1362
|
+
const Hide = 'hide';
|
|
1363
|
+
|
|
1364
|
+
const emptyObject = {};
|
|
1365
|
+
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
1366
|
+
const i18nString = (key, placeholders = emptyObject) => {
|
|
1367
|
+
if (placeholders === emptyObject) {
|
|
1368
|
+
return key;
|
|
1369
|
+
}
|
|
1370
|
+
const replacer = (match, rest) => {
|
|
1371
|
+
return placeholders[rest];
|
|
1372
|
+
};
|
|
1373
|
+
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
/**
|
|
1377
|
+
* @enum {string}
|
|
1378
|
+
*/
|
|
1379
|
+
const UiStrings = {
|
|
1380
|
+
Files: 'Files',
|
|
1381
|
+
GoToFile: 'Go to file',
|
|
1382
|
+
NoMatchingColorThemesFound: 'No matching color themes found',
|
|
1383
|
+
NoMatchingResults: 'No matching results',
|
|
1384
|
+
NoRecentlyOpenedFoldersFound: 'No recently opened folders found',
|
|
1385
|
+
NoResults: 'No Results',
|
|
1386
|
+
NoSymbolFound: 'No symbol found',
|
|
1387
|
+
NoWorkspaceSymbolsFound: 'no workspace symbols found',
|
|
1388
|
+
OpenRecent: 'Open Recent',
|
|
1389
|
+
SelectColorTheme: 'Select Color Theme',
|
|
1390
|
+
SelectToOpen: 'Select to open',
|
|
1391
|
+
ShowAndRunCommands: 'Show And Run Commands',
|
|
1392
|
+
TypeNameOfCommandToRun: 'Type the name of a command to run.',
|
|
1393
|
+
TypeTheNameOfAViewToOpen: 'Type the name of a view, output channel or terminal to open.'
|
|
1394
|
+
};
|
|
1395
|
+
const selectToOpen = () => {
|
|
1396
|
+
return i18nString(UiStrings.SelectToOpen);
|
|
1397
|
+
};
|
|
1398
|
+
const openRecent = () => {
|
|
1399
|
+
return i18nString(UiStrings.OpenRecent);
|
|
1400
|
+
};
|
|
1401
|
+
const noRecentlyOpenedFoldersFound = () => {
|
|
1402
|
+
return i18nString(UiStrings.NoRecentlyOpenedFoldersFound);
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
const state$1 = {
|
|
1406
|
+
rpc: undefined
|
|
1407
|
+
};
|
|
1408
|
+
const invoke$1 = (method, ...params) => {
|
|
1409
|
+
const rpc = state$1.rpc;
|
|
1410
|
+
// @ts-ignore
|
|
1411
|
+
return rpc.invoke(method, ...params);
|
|
1412
|
+
};
|
|
1413
|
+
const setRpc = rpc => {
|
|
1414
|
+
state$1.rpc = rpc;
|
|
1415
|
+
};
|
|
1416
|
+
|
|
1417
|
+
// TODO this should be in FileSystem module
|
|
1418
|
+
const pathBaseName = path => {
|
|
1419
|
+
return path.slice(path.lastIndexOf('/') + 1);
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
// TODO this should be in FileSystem module
|
|
1423
|
+
const pathDirName = path => {
|
|
1424
|
+
const pathSeparator = '/';
|
|
1425
|
+
const index = path.lastIndexOf(pathSeparator);
|
|
1426
|
+
if (index === -1) {
|
|
1427
|
+
return '';
|
|
1428
|
+
}
|
|
1429
|
+
return path.slice(0, index);
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1432
|
+
const getRecentlyOpened = () => {
|
|
1433
|
+
return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
|
|
1434
|
+
};
|
|
1435
|
+
const openWorkspaceFolder = uri => {
|
|
1436
|
+
return invoke$1(/* Workspace.setPath */'Workspace.setPath', /* path */uri);
|
|
1437
|
+
};
|
|
1438
|
+
const getPlaceholder = () => {
|
|
1439
|
+
return selectToOpen();
|
|
1440
|
+
};
|
|
1441
|
+
const getLabel = () => {
|
|
1442
|
+
return openRecent();
|
|
1443
|
+
};
|
|
1444
|
+
const getHelpEntries = () => {
|
|
1445
|
+
return [];
|
|
1446
|
+
};
|
|
1447
|
+
const getNoResults = () => {
|
|
1448
|
+
return {
|
|
1449
|
+
label: noRecentlyOpenedFoldersFound()
|
|
1450
|
+
};
|
|
1451
|
+
};
|
|
1452
|
+
|
|
1453
|
+
// TODO could also change api so that getPicks returns an array of anything
|
|
1454
|
+
// and the transformPick gets the label for each pick
|
|
1455
|
+
// This would make the code more module since the code for getting the picks
|
|
1456
|
+
// would be more independent of the specific data format of the quickpick provider
|
|
1457
|
+
|
|
1458
|
+
const getPicks = async () => {
|
|
1459
|
+
const recentlyOpened = await getRecentlyOpened();
|
|
1460
|
+
return recentlyOpened;
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
// TODO selectPick should be independent of show/hide
|
|
1464
|
+
const selectPick = async pick => {
|
|
1465
|
+
const path = pick;
|
|
1466
|
+
await openWorkspaceFolder(path);
|
|
1467
|
+
return {
|
|
1468
|
+
command: Hide
|
|
1469
|
+
};
|
|
1470
|
+
};
|
|
1471
|
+
const getFilterValue = value => {
|
|
1472
|
+
return pathBaseName(value);
|
|
1473
|
+
};
|
|
1474
|
+
const getPickFilterValue = pick => {
|
|
1475
|
+
return pathBaseName(pick);
|
|
1476
|
+
};
|
|
1477
|
+
const getPickLabel = pick => {
|
|
1478
|
+
return pathBaseName(pick);
|
|
1479
|
+
};
|
|
1480
|
+
const getPickDescription = pick => {
|
|
1481
|
+
return pathDirName(pick);
|
|
1482
|
+
};
|
|
1483
|
+
const getPickIcon = () => {
|
|
1484
|
+
return '';
|
|
1485
|
+
};
|
|
1486
|
+
const getPickFileIcon = () => {
|
|
1487
|
+
return getFolderIcon();
|
|
1488
|
+
};
|
|
1489
|
+
|
|
1490
|
+
const QuickPickEntriesOpenRecent = {
|
|
1491
|
+
__proto__: null,
|
|
1492
|
+
getFilterValue,
|
|
1493
|
+
getHelpEntries,
|
|
1494
|
+
getLabel,
|
|
1495
|
+
getNoResults,
|
|
1496
|
+
getPickDescription,
|
|
1497
|
+
getPickFileIcon,
|
|
1498
|
+
getPickFilterValue,
|
|
1499
|
+
getPickIcon,
|
|
1500
|
+
getPickLabel,
|
|
1501
|
+
getPicks,
|
|
1502
|
+
getPlaceholder,
|
|
1503
|
+
selectPick
|
|
1504
|
+
};
|
|
1505
|
+
|
|
1506
|
+
const Recent = 'quickPick://recent';
|
|
1507
|
+
|
|
1508
|
+
const loadQuickPickEntries = moduleId => {
|
|
1509
|
+
switch (moduleId) {
|
|
1510
|
+
case Recent:
|
|
1511
|
+
return QuickPickEntriesOpenRecent;
|
|
1512
|
+
default:
|
|
1513
|
+
throw new Error(`unknown module "${moduleId}"`);
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
|
|
1129
1517
|
const Memfs = 'memfs';
|
|
1130
1518
|
const Html = 'html';
|
|
1131
1519
|
const Fetch = 'fetch';
|
|
@@ -1455,7 +1843,7 @@ replaceTraps(oldTraps => ({
|
|
|
1455
1843
|
}
|
|
1456
1844
|
}));
|
|
1457
1845
|
|
|
1458
|
-
const state
|
|
1846
|
+
const state = {
|
|
1459
1847
|
databases: Object.create(null),
|
|
1460
1848
|
eventId: 0,
|
|
1461
1849
|
dbVersion: 1,
|
|
@@ -1466,7 +1854,7 @@ const state$1 = {
|
|
|
1466
1854
|
|
|
1467
1855
|
const getHandleDb = async () => {
|
|
1468
1856
|
// @ts-ignore
|
|
1469
|
-
const db = await openDB('handle', state
|
|
1857
|
+
const db = await openDB('handle', state.dbVersion, {
|
|
1470
1858
|
async upgrade(db) {
|
|
1471
1859
|
if (!db.objectStoreNames.contains('file-handles-store')) {
|
|
1472
1860
|
await db.createObjectStore('file-handles-store', {});
|
|
@@ -1540,210 +1928,11 @@ const SearchFileHtml = {
|
|
|
1540
1928
|
searchFile: searchFile$2
|
|
1541
1929
|
};
|
|
1542
1930
|
|
|
1543
|
-
const Diagonal = 1;
|
|
1544
|
-
const Left = 2;
|
|
1545
|
-
|
|
1546
|
-
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1547
|
-
|
|
1548
|
-
const createTable = size => {
|
|
1549
|
-
const table = [];
|
|
1550
|
-
for (let i = 0; i < size; i++) {
|
|
1551
|
-
const row = new Uint8Array(size);
|
|
1552
|
-
table.push(row);
|
|
1553
|
-
}
|
|
1554
|
-
return table;
|
|
1555
|
-
};
|
|
1556
|
-
const EmptyMatches = [];
|
|
1557
|
-
const Dash = '-';
|
|
1558
|
-
const Dot = '.';
|
|
1559
|
-
const EmptyString = '';
|
|
1560
|
-
const Space = ' ';
|
|
1561
|
-
const Underline = '_';
|
|
1562
|
-
const T = 't';
|
|
1563
|
-
const isLowerCase = char => {
|
|
1564
|
-
return char === char.toLowerCase();
|
|
1565
|
-
};
|
|
1566
|
-
const isUpperCase = char => {
|
|
1567
|
-
return char === char.toUpperCase();
|
|
1568
|
-
};
|
|
1569
|
-
|
|
1570
|
-
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1571
|
-
const isGap = (columnCharBefore, columnChar) => {
|
|
1572
|
-
switch (columnCharBefore) {
|
|
1573
|
-
case Dash:
|
|
1574
|
-
case Underline:
|
|
1575
|
-
case EmptyString:
|
|
1576
|
-
case T:
|
|
1577
|
-
case Space:
|
|
1578
|
-
case Dot:
|
|
1579
|
-
return true;
|
|
1580
|
-
}
|
|
1581
|
-
if (isLowerCase(columnCharBefore) && isUpperCase(columnChar)) {
|
|
1582
|
-
return true;
|
|
1583
|
-
}
|
|
1584
|
-
return false;
|
|
1585
|
-
};
|
|
1586
|
-
|
|
1587
|
-
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1588
|
-
const getScore = (rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, isDiagonalMatch) => {
|
|
1589
|
-
if (rowCharLow !== columnCharLow) {
|
|
1590
|
-
return -1;
|
|
1591
|
-
}
|
|
1592
|
-
const isMatch = rowChar === columnChar;
|
|
1593
|
-
if (isMatch) {
|
|
1594
|
-
if (isDiagonalMatch) {
|
|
1595
|
-
return 8;
|
|
1596
|
-
}
|
|
1597
|
-
if (isGap(columnCharBefore, columnChar)) {
|
|
1598
|
-
return 8;
|
|
1599
|
-
}
|
|
1600
|
-
return 5;
|
|
1601
|
-
}
|
|
1602
|
-
if (isGap(columnCharBefore, columnChar)) {
|
|
1603
|
-
return 8;
|
|
1604
|
-
}
|
|
1605
|
-
return 5;
|
|
1606
|
-
};
|
|
1607
|
-
|
|
1608
|
-
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1609
|
-
|
|
1610
|
-
const isPatternInWord = (patternLow, patternPos, patternLen, wordLow, wordPos, wordLen) => {
|
|
1611
|
-
while (patternPos < patternLen && wordPos < wordLen) {
|
|
1612
|
-
if (patternLow[patternPos] === wordLow[wordPos]) {
|
|
1613
|
-
patternPos += 1;
|
|
1614
|
-
}
|
|
1615
|
-
wordPos += 1;
|
|
1616
|
-
}
|
|
1617
|
-
return patternPos === patternLen; // pattern must be exhausted
|
|
1618
|
-
};
|
|
1619
|
-
|
|
1620
|
-
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1621
|
-
const traceHighlights = (table, arrows, patternLength, wordLength) => {
|
|
1622
|
-
let row = patternLength;
|
|
1623
|
-
let column = wordLength;
|
|
1624
|
-
const matches = [];
|
|
1625
|
-
while (row >= 1 && column >= 1) {
|
|
1626
|
-
const arrow = arrows[row][column];
|
|
1627
|
-
if (arrow === Left) {
|
|
1628
|
-
column--;
|
|
1629
|
-
} else if (arrow === Diagonal) {
|
|
1630
|
-
row--;
|
|
1631
|
-
column--;
|
|
1632
|
-
const start = column + 1;
|
|
1633
|
-
while (row >= 1 && column >= 1) {
|
|
1634
|
-
const arrow = arrows[row][column];
|
|
1635
|
-
if (arrow === Left) {
|
|
1636
|
-
break;
|
|
1637
|
-
}
|
|
1638
|
-
if (arrow === Diagonal) {
|
|
1639
|
-
row--;
|
|
1640
|
-
column--;
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
const end = column;
|
|
1644
|
-
matches.unshift(end, start);
|
|
1645
|
-
}
|
|
1646
|
-
}
|
|
1647
|
-
matches.unshift(table[patternLength][wordLength - 1]);
|
|
1648
|
-
return matches;
|
|
1649
|
-
};
|
|
1650
|
-
|
|
1651
|
-
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1652
|
-
const gridSize = 128;
|
|
1653
|
-
const table = createTable(gridSize);
|
|
1654
|
-
const arrows = createTable(gridSize);
|
|
1655
|
-
const fuzzySearch = (pattern, word) => {
|
|
1656
|
-
const patternLength = Math.min(pattern.length, gridSize - 1);
|
|
1657
|
-
const wordLength = Math.min(word.length, gridSize - 1);
|
|
1658
|
-
const patternLower = pattern.toLowerCase();
|
|
1659
|
-
const wordLower = word.toLowerCase();
|
|
1660
|
-
if (!isPatternInWord(patternLower, 0, patternLength, wordLower, 0, wordLength)) {
|
|
1661
|
-
return EmptyMatches;
|
|
1662
|
-
}
|
|
1663
|
-
let strongMatch = false;
|
|
1664
|
-
for (let row = 1; row < patternLength + 1; row++) {
|
|
1665
|
-
const rowChar = pattern[row - 1];
|
|
1666
|
-
const rowCharLow = patternLower[row - 1];
|
|
1667
|
-
for (let column = 1; column < wordLength + 1; column++) {
|
|
1668
|
-
const columnChar = word[column - 1];
|
|
1669
|
-
const columnCharLow = wordLower[column - 1];
|
|
1670
|
-
const columnCharBefore = word[column - 2] || '';
|
|
1671
|
-
const isDiagonalMatch = arrows[row - 1][column - 1] === Diagonal;
|
|
1672
|
-
const score = getScore(rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, isDiagonalMatch);
|
|
1673
|
-
if (row === 1 && score > 5) {
|
|
1674
|
-
strongMatch = true;
|
|
1675
|
-
}
|
|
1676
|
-
let diagonalScore = score + table[row - 1][column - 1];
|
|
1677
|
-
if (isDiagonalMatch && score !== -1) {
|
|
1678
|
-
diagonalScore += 2;
|
|
1679
|
-
}
|
|
1680
|
-
const leftScore = table[row][column - 1];
|
|
1681
|
-
if (leftScore > diagonalScore) {
|
|
1682
|
-
table[row][column] = leftScore;
|
|
1683
|
-
arrows[row][column] = Left;
|
|
1684
|
-
} else {
|
|
1685
|
-
table[row][column] = diagonalScore;
|
|
1686
|
-
arrows[row][column] = Diagonal;
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
if (!strongMatch) {
|
|
1691
|
-
return EmptyMatches;
|
|
1692
|
-
}
|
|
1693
|
-
const highlights = traceHighlights(table, arrows, patternLength, wordLength);
|
|
1694
|
-
return highlights;
|
|
1695
|
-
};
|
|
1696
|
-
|
|
1697
|
-
const filterQuickPickItem = (pattern, word) => {
|
|
1698
|
-
const matches = fuzzySearch(pattern, word);
|
|
1699
|
-
return matches;
|
|
1700
|
-
};
|
|
1701
|
-
|
|
1702
|
-
const getBaseName = path => {
|
|
1703
|
-
return path.slice(path.lastIndexOf('/') + 1);
|
|
1704
|
-
};
|
|
1705
|
-
const emptyMatches = [];
|
|
1706
|
-
const convertToPick = item => {
|
|
1707
|
-
return {
|
|
1708
|
-
pick: item,
|
|
1709
|
-
matches: emptyMatches
|
|
1710
|
-
};
|
|
1711
|
-
};
|
|
1712
|
-
const filterQuickPickItems = (items, value) => {
|
|
1713
|
-
if (!value) {
|
|
1714
|
-
return items.map(convertToPick);
|
|
1715
|
-
}
|
|
1716
|
-
const results = [];
|
|
1717
|
-
for (const item of items) {
|
|
1718
|
-
const baseName = getBaseName(item);
|
|
1719
|
-
const matches = filterQuickPickItem(value, baseName);
|
|
1720
|
-
if (matches.length > 0) {
|
|
1721
|
-
results.push({
|
|
1722
|
-
pick: item,
|
|
1723
|
-
matches
|
|
1724
|
-
});
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
return results;
|
|
1728
|
-
};
|
|
1729
|
-
|
|
1730
1931
|
const getFileSearchRipGrepArgs = () => {
|
|
1731
1932
|
const ripGrepArgs = ['--files', '--sort-files'];
|
|
1732
1933
|
return ripGrepArgs;
|
|
1733
1934
|
};
|
|
1734
1935
|
|
|
1735
|
-
const state = {
|
|
1736
|
-
rpc: undefined
|
|
1737
|
-
};
|
|
1738
|
-
const invoke$1 = (method, ...params) => {
|
|
1739
|
-
const rpc = state.rpc;
|
|
1740
|
-
// @ts-ignore
|
|
1741
|
-
return rpc.invoke(method, ...params);
|
|
1742
|
-
};
|
|
1743
|
-
const setRpc = rpc => {
|
|
1744
|
-
state.rpc = rpc;
|
|
1745
|
-
};
|
|
1746
|
-
|
|
1747
1936
|
const invoke = (method, ...params) => {
|
|
1748
1937
|
return invoke$1('SearchProcess.invoke', method, ...params);
|
|
1749
1938
|
};
|
|
@@ -1815,6 +2004,9 @@ const commandMap = {
|
|
|
1815
2004
|
'FileSystemMemory.readFile': readFile,
|
|
1816
2005
|
'FileSystemMemory.remove': remove,
|
|
1817
2006
|
'FileSystemMemory.writeFile': writeFile,
|
|
2007
|
+
'QuickPick.getKeyBindings': getKeyBindings,
|
|
2008
|
+
'QuickPick.loadEntries': loadQuickPickEntries,
|
|
2009
|
+
'SearchFile.filter': filterQuickPickItems,
|
|
1818
2010
|
'SearchFile.searchFile': searchFile,
|
|
1819
2011
|
'SearchFile.searchFileWithFetch': searchFile$3,
|
|
1820
2012
|
'SearchFile.searchFileWithHtml': searchFile$2,
|
package/package.json
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/file-search-worker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/fileSearchWorkerMain.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"keywords": [
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
"keywords": [
|
|
8
|
+
"text-search"
|
|
9
|
+
],
|
|
10
|
+
"author": "Lvce Editor",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/lvce-editor/file-search-worker.git"
|
|
15
|
+
}
|
|
10
16
|
}
|