@lvce-editor/file-search-worker 3.18.0 → 4.0.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.
@@ -448,7 +448,7 @@ const set$2 = (id, fn) => {
448
448
  const get$2 = id => {
449
449
  return callbacks[id];
450
450
  };
451
- const remove$2 = id => {
451
+ const remove = id => {
452
452
  delete callbacks[id];
453
453
  };
454
454
  let id = 0;
@@ -625,7 +625,7 @@ const resolve = (id, response) => {
625
625
  return;
626
626
  }
627
627
  fn(response);
628
- remove$2(id);
628
+ remove(id);
629
629
  };
630
630
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
631
631
  const getErrorType = prettyError => {
@@ -780,7 +780,7 @@ const invokeAndTransfer = (ipc, method, ...params) => {
780
780
  };
781
781
 
782
782
  const commands = Object.create(null);
783
- const register = commandMap => {
783
+ const register$2 = commandMap => {
784
784
  Object.assign(commands, commandMap);
785
785
  };
786
786
  const getCommand = key => {
@@ -847,7 +847,7 @@ const create$4 = async ({
847
847
  commandMap
848
848
  }) => {
849
849
  // TODO create a commandMap per rpc instance
850
- register(commandMap);
850
+ register$2(commandMap);
851
851
  const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
852
852
  handleIpc(ipc);
853
853
  const rpc = createRpc(ipc);
@@ -899,14 +899,14 @@ const warn = (...args) => {
899
899
  console.warn(...args);
900
900
  };
901
901
 
902
- const state$4 = {
902
+ const state$9 = {
903
903
  menuEntries: []
904
904
  };
905
905
  const getAll = () => {
906
- return state$4.menuEntries;
906
+ return state$9.menuEntries;
907
907
  };
908
908
  const add = menuEntries => {
909
- state$4.menuEntries = [...state$4.menuEntries, ...menuEntries];
909
+ state$9.menuEntries = [...state$9.menuEntries, ...menuEntries];
910
910
  };
911
911
 
912
912
  const Hide = 'hide';
@@ -978,7 +978,7 @@ const noWorkspaceSymbolsFound = () => {
978
978
  return i18nString(NoWorkspaceSymbolsFound);
979
979
  };
980
980
 
981
- const name$8 = 'command';
981
+ const name$b = 'command';
982
982
  const getPlaceholder$b = () => {
983
983
  return typeNameofCommandToRun();
984
984
  };
@@ -991,7 +991,7 @@ const helpEntries = () => {
991
991
  const getLabel$5 = () => {
992
992
  return '';
993
993
  };
994
- const getNoResults$a = () => {
994
+ const getNoResults$b = () => {
995
995
  return {
996
996
  label: noMatchingResults()
997
997
  };
@@ -1074,35 +1074,35 @@ const selectPick$b = async item => {
1074
1074
  }
1075
1075
  return selectPickBuiltin(item);
1076
1076
  };
1077
- const getFilterValue$a = value => {
1077
+ const getFilterValue$b = value => {
1078
1078
  return value;
1079
1079
  };
1080
- const getPickFilterValue$6 = pick => {
1080
+ const getPickFilterValue$9 = pick => {
1081
1081
  return pick.label;
1082
1082
  };
1083
- const getPickLabel$5 = pick => {
1083
+ const getPickLabel$8 = pick => {
1084
1084
  return pick.label;
1085
1085
  };
1086
- const getPickIcon$5 = () => {
1086
+ const getPickIcon$8 = () => {
1087
1087
  return '';
1088
1088
  };
1089
1089
 
1090
1090
  const QuickPickEntriesCommand = {
1091
1091
  __proto__: null,
1092
- getFilterValue: getFilterValue$a,
1092
+ getFilterValue: getFilterValue$b,
1093
1093
  getLabel: getLabel$5,
1094
- getNoResults: getNoResults$a,
1095
- getPickFilterValue: getPickFilterValue$6,
1096
- getPickIcon: getPickIcon$5,
1097
- getPickLabel: getPickLabel$5,
1094
+ getNoResults: getNoResults$b,
1095
+ getPickFilterValue: getPickFilterValue$9,
1096
+ getPickIcon: getPickIcon$8,
1097
+ getPickLabel: getPickLabel$8,
1098
1098
  getPicks: getPicks$b,
1099
1099
  getPlaceholder: getPlaceholder$b,
1100
1100
  helpEntries,
1101
- name: name$8,
1101
+ name: name$b,
1102
1102
  selectPick: selectPick$b
1103
1103
  };
1104
1104
 
1105
- const Directory$1 = 3;
1105
+ const Directory = 3;
1106
1106
  const File$2 = 7;
1107
1107
 
1108
1108
  const RE_PROTOCOL = /^([a-z-]+):\/\//;
@@ -1118,1092 +1118,250 @@ const openUri = async uri => {
1118
1118
  await invoke$1(/* Main.openUri */'Main.openUri', /* uri */uri);
1119
1119
  };
1120
1120
 
1121
- const Memfs = 'memfs';
1122
- const Html = 'html';
1123
- const Fetch = 'fetch';
1121
+ const state$8 = Object.create(null);
1122
+ const register$1 = modules => {
1123
+ Object.assign(state$8, modules);
1124
+ };
1125
+ const getModule = protocol => {
1126
+ return state$8[protocol];
1127
+ };
1124
1128
 
1125
- class FileNotFoundError extends Error {
1126
- constructor(uri) {
1127
- super(`File not found: ${uri}`);
1128
- this.code = 'ENOENT';
1129
- }
1130
- }
1129
+ const searchFile$5 = async (path, value, prepare, assetDir) => {
1130
+ const protocol = getProtocol(path);
1131
+ // TODO call different providers depending on protocol
1132
+ const fn = getModule(protocol);
1133
+ const result = await fn(path, value, prepare, assetDir);
1134
+ return result;
1135
+ };
1131
1136
 
1132
- const ApplicationJson = 'application/json';
1133
- const AudioMpeg = 'audio/mpeg';
1134
- const FontTtf = 'font/ttf';
1135
- const ImagePng = 'image/png';
1136
- const ImageSvgXml = 'image/svg+xml';
1137
- const TextCss = 'text/css';
1138
- const TextHtml = 'text/html';
1139
- const TextJavaScript = 'text/javascript';
1140
- const TextPlain = 'text/plain';
1141
- const VideoWebm = 'video/webm';
1142
-
1143
- const getMimeType = fileExtension => {
1144
- switch (fileExtension) {
1145
- case '.html':
1146
- return TextHtml;
1147
- case '.css':
1148
- return TextCss;
1149
- case '.ttf':
1150
- return FontTtf;
1151
- case '.js':
1152
- case '.mjs':
1153
- case '.ts':
1154
- return TextJavaScript;
1155
- case '.svg':
1156
- return ImageSvgXml;
1157
- case '.png':
1158
- return ImagePng;
1159
- case '.json':
1160
- case '.map':
1161
- return ApplicationJson;
1162
- case '.mp3':
1163
- return AudioMpeg;
1164
- case '.webm':
1165
- return VideoWebm;
1166
- case '.txt':
1167
- return TextPlain;
1168
- default:
1169
- return '';
1170
- }
1137
+ // TODO this should be in FileSystem module
1138
+ const pathBaseName = path => {
1139
+ return path.slice(path.lastIndexOf('/') + 1);
1171
1140
  };
1172
1141
 
1173
- const dirname = (pathSeparator, path) => {
1142
+ // TODO this should be in FileSystem module
1143
+ const pathDirName = path => {
1144
+ const pathSeparator = '/';
1174
1145
  const index = path.lastIndexOf(pathSeparator);
1175
- if (index === -1) {
1176
- return path;
1177
- }
1178
- return path.slice(0, index);
1179
- };
1180
- const extname = path => {
1181
- const index = path.lastIndexOf('.');
1182
1146
  if (index === -1) {
1183
1147
  return '';
1184
1148
  }
1185
- return path.slice(index);
1149
+ return path.slice(0, index);
1186
1150
  };
1187
1151
 
1188
- const getContentType = uri => {
1189
- const extension = extname(uri);
1190
- const mime = getMimeType(extension);
1191
- return mime;
1152
+ const searchFile$4 = async (path, value) => {
1153
+ const prepare = true;
1154
+ // @ts-ignore
1155
+ const files = await searchFile$5(/* path */path, /* searchTerm */value, prepare);
1156
+ return files;
1192
1157
  };
1193
-
1194
- const Slash$1 = '/';
1195
-
1196
- const Slash = Slash$1;
1197
-
1198
- // TODO move this to an extension?
1199
-
1200
- const state$3 = {
1201
- files: Object.create(null)
1158
+ const name$a = 'file';
1159
+ const getPlaceholder$a = () => {
1160
+ return '';
1202
1161
  };
1203
- const getDirent = uri => {
1204
- return state$3.files[uri];
1162
+ const getLabel$4 = () => {
1163
+ return files();
1205
1164
  };
1206
- const readFile$1 = uri => {
1207
- const dirent = getDirent(uri);
1208
- if (!dirent) {
1209
- throw new FileNotFoundError(uri);
1210
- }
1211
- if (dirent.type !== File$2) {
1212
- throw new Error('file is a directory');
1213
- }
1214
- return dirent.content;
1165
+
1166
+ // TODO help entries should not be here
1167
+ const getHelpEntries$a = () => {
1168
+ return [{
1169
+ description: goToFile(),
1170
+ category: 'global commands'
1171
+ }];
1215
1172
  };
1216
- const ensureParentDir = uri => {
1217
- const startIndex = 0;
1218
- let endIndex = uri.indexOf(Slash);
1219
- while (endIndex >= 0) {
1220
- const part = uri.slice(startIndex, endIndex + 1);
1221
- state$3.files[part] = {
1222
- type: Directory$1,
1223
- content: ''
1224
- };
1225
- endIndex = uri.indexOf(Slash, endIndex + 1);
1226
- }
1173
+ const getNoResults$a = () => {
1174
+ return {
1175
+ label: noMatchingResults()
1176
+ };
1227
1177
  };
1228
- const writeFile$1 = (uri, content) => {
1229
- const dirent = getDirent(uri);
1230
- if (dirent) {
1231
- dirent.content = content;
1232
- } else {
1233
- ensureParentDir(uri);
1234
- state$3.files[uri] = {
1235
- type: File$2,
1236
- content
1237
- };
1178
+ const getPicks$a = async searchValue => {
1179
+ // TODO cache workspace path
1180
+ const workspace = await invoke$1('Workspace.getPath');
1181
+ if (!workspace) {
1182
+ return [];
1238
1183
  }
1184
+ const files = await searchFile$4(workspace, searchValue);
1185
+ // const picks = files.map(toPick)
1186
+ return files;
1239
1187
  };
1240
- const mkdir$1 = uri => {
1241
- if (!uri.endsWith(Slash)) {
1242
- uri += Slash;
1188
+ const selectPick$a = async pick => {
1189
+ if (typeof pick === 'object') {
1190
+ pick = pick.pick;
1243
1191
  }
1244
- ensureParentDir(uri);
1245
- state$3.files[uri] = {
1246
- type: Directory$1,
1247
- content: ''
1192
+ const workspace = await invoke$1('Workspace.getPath');
1193
+ const absolutePath = `${workspace}/${pick}`;
1194
+ await openUri(absolutePath);
1195
+ return {
1196
+ command: Hide
1248
1197
  };
1249
1198
  };
1250
- const remove$1 = uri => {
1251
- const toDelete = [];
1252
- for (const key of Object.keys(state$3.files)) {
1253
- if (key.startsWith(uri)) {
1254
- toDelete.push(key);
1255
- }
1256
- }
1257
- for (const key of toDelete) {
1258
- delete state$3.files[key];
1259
- }
1199
+ const getFilterValue$a = value => {
1200
+ return value;
1260
1201
  };
1261
- const readDirWithFileTypes$1 = uri => {
1262
- if (!uri.endsWith(Slash)) {
1263
- uri += Slash;
1264
- }
1265
- const dirents = [];
1266
- for (const [key, value] of Object.entries(state$3.files)) {
1267
- if (key.startsWith(uri)) {
1268
- // @ts-ignore
1269
- switch (value.type) {
1270
- case Directory$1:
1271
- if (!key.slice(0, -1).includes(Slash, uri.length) && key !== `${uri}/` && key !== uri) {
1272
- dirents.push({
1273
- // @ts-ignore
1274
- type: value.type,
1275
- name: key.slice(uri.length, -1)
1276
- });
1277
- }
1278
- break;
1279
- case File$2:
1280
- if (!key.includes(Slash, uri.length + 1)) {
1281
- dirents.push({
1282
- // @ts-ignore
1283
- type: value.type,
1284
- name: key.slice(uri.length)
1285
- });
1286
- }
1287
- break;
1288
- }
1289
- }
1202
+ const getPickFilterValue$8 = pick => {
1203
+ if (typeof pick === 'object') {
1204
+ pick = pick.pick;
1290
1205
  }
1291
- return dirents;
1206
+ return pick;
1292
1207
  };
1293
- const getBlob$2 = (uri, type) => {
1294
- const content = readFile$1(uri);
1295
- const contentType = type || getContentType(uri);
1296
- const blob = new Blob([content], {
1297
- type: contentType
1298
- });
1299
- return blob;
1208
+ const getPickLabel$7 = pick => {
1209
+ if (typeof pick === 'object') {
1210
+ pick = pick.pick;
1211
+ }
1212
+ const baseName = pathBaseName(pick);
1213
+ return baseName;
1300
1214
  };
1301
- const getBlobUrl = (uri, type) => {
1302
- const blob = getBlob$2(uri, type);
1303
- const url = URL.createObjectURL(blob);
1304
- return url;
1215
+ const getPickDescription$8 = pick => {
1216
+ if (typeof pick === 'object') {
1217
+ pick = pick.pick;
1218
+ }
1219
+ const dirName = pathDirName(pick);
1220
+ return dirName;
1305
1221
  };
1306
- const chmod$1 = () => {
1307
- throw new Error('[memfs] chmod not implemented');
1222
+ const getPickIcon$7 = () => {
1223
+ return '';
1308
1224
  };
1309
- const getFiles = () => {
1310
- return state$3.files;
1225
+ const getPickFileIcon$2 = pick => {
1226
+ if (typeof pick === 'object') {
1227
+ pick = pick.pick;
1228
+ }
1229
+ if (typeof pick === 'object') {
1230
+ pick = pick.pick;
1231
+ }
1232
+ const baseName = pathBaseName(pick);
1233
+ return {
1234
+ type: File$2,
1235
+ name: baseName
1236
+ };
1311
1237
  };
1312
-
1313
- const searchFile$5 = async () => {
1314
- const files = await getFiles();
1315
- const keys = Object.keys(files);
1316
- return keys;
1238
+ const isPrepared$7 = () => {
1239
+ const workspace = '';
1240
+ // TODO protocol should always be defined. For files it should use file protocol
1241
+ const protocol = getProtocol(workspace);
1242
+ return !protocol;
1317
1243
  };
1318
1244
 
1319
- const SearchFileMemfs = {
1245
+ const QuickPickEntriesFile = {
1320
1246
  __proto__: null,
1321
- searchFile: searchFile$5
1247
+ getFilterValue: getFilterValue$a,
1248
+ getHelpEntries: getHelpEntries$a,
1249
+ getLabel: getLabel$4,
1250
+ getNoResults: getNoResults$a,
1251
+ getPickDescription: getPickDescription$8,
1252
+ getPickFileIcon: getPickFileIcon$2,
1253
+ getPickFilterValue: getPickFilterValue$8,
1254
+ getPickIcon: getPickIcon$7,
1255
+ getPickLabel: getPickLabel$7,
1256
+ getPicks: getPicks$a,
1257
+ getPlaceholder: getPlaceholder$a,
1258
+ isPrepared: isPrepared$7,
1259
+ name: name$a,
1260
+ selectPick: selectPick$a
1322
1261
  };
1323
1262
 
1324
- const assetDir = '';
1325
-
1326
- const fileMapUrl = `${assetDir}/config/fileMap.json`;
1327
-
1328
- const getJson = async url => {
1329
- try {
1330
- const response = await fetch(url);
1331
- if (!response.ok) {
1332
- throw new Error(response.statusText);
1333
- }
1334
- const text = await response.json();
1335
- return text;
1336
- } catch (error) {
1337
- throw new VError(error, `Failed to request json for ${url}`);
1338
- }
1263
+ const execute = async (method, ...params) => {
1264
+ // TODO
1339
1265
  };
1340
1266
 
1341
- const removeLeadingSlash = path => {
1342
- if (path.startsWith('/')) {
1343
- return path.slice(1);
1344
- }
1345
- return path;
1267
+ const name$9 = 'goToLine';
1268
+ const getPlaceholder$9 = () => {
1269
+ return '';
1346
1270
  };
1347
-
1348
- // TODO simplify code
1349
- // 1. don't have playground prefix in fileMap json
1350
- // 2. remove code here that removes the prefix
1351
- const searchFile$4 = async path => {
1352
- const fileList = await getJson(fileMapUrl);
1353
- const result = fileList.map(removeLeadingSlash);
1354
- const prefixLength = path.length - 'file:///'.length;
1355
- const final = [];
1356
- for (const item of result) {
1357
- final.push(item.slice(prefixLength));
1358
- }
1359
- return final;
1271
+ const getHelpEntries$9 = () => {
1272
+ return [];
1273
+ };
1274
+ const getNoResults$9 = () => {
1275
+ return undefined;
1276
+ };
1277
+ const getPicks$9 = async () => {
1278
+ const picks = [{
1279
+ label: '1'
1280
+ }, {
1281
+ label: '2'
1282
+ }, {
1283
+ label: '3'
1284
+ }, {
1285
+ label: '4'
1286
+ }, {
1287
+ label: '5'
1288
+ }, {
1289
+ label: '6'
1290
+ }];
1291
+ return picks;
1292
+ };
1293
+ const selectPick$9 = async item => {
1294
+ const rowIndex = Number.parseInt(item.label);
1295
+ const position = {
1296
+ rowIndex,
1297
+ columnIndex: 5
1298
+ };
1299
+ await execute(/* EditorSetCursor.editorSetCursor */'TODO', /* position */position);
1300
+ // TODO put cursor onto that line
1301
+ return {
1302
+ command: Hide
1303
+ };
1304
+ };
1305
+ const getFilterValue$9 = value => {
1306
+ return value;
1360
1307
  };
1361
1308
 
1362
- const SearchFileFetch = {
1309
+ const QuickPickEntriesGoToLine = {
1363
1310
  __proto__: null,
1364
- searchFile: searchFile$4
1311
+ getFilterValue: getFilterValue$9,
1312
+ getHelpEntries: getHelpEntries$9,
1313
+ getNoResults: getNoResults$9,
1314
+ getPicks: getPicks$9,
1315
+ getPlaceholder: getPlaceholder$9,
1316
+ name: name$9,
1317
+ selectPick: selectPick$9
1365
1318
  };
1366
1319
 
1367
- const Directory = 'directory';
1368
- const File$1 = 'file';
1369
-
1370
- // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
1371
-
1372
- const fromAsync = async asyncIterable => {
1373
- const children = [];
1374
- for await (const value of asyncIterable) {
1375
- children.push(value);
1376
- }
1377
- return children;
1320
+ const name$8 = 'noop';
1321
+ const getPlaceholder$8 = () => {
1322
+ return '';
1378
1323
  };
1379
-
1380
- /**
1381
- * Do not use directly, use FileSystemHtml.getChildHandles
1382
- * instead which prompts for the required permission to
1383
- * retrieve the child handles
1384
- *
1385
- */
1386
-
1387
- const getChildHandles = async handle => {
1388
- // @ts-ignore
1389
- const handles = await fromAsync(handle.values());
1390
- return handles;
1324
+ const getHelpEntries$8 = () => {
1325
+ return [];
1391
1326
  };
1392
-
1393
- const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);
1394
- let idbProxyableTypes;
1395
- let cursorAdvanceMethods;
1396
- // This is a function to prevent it throwing up in node environments.
1397
- function getIdbProxyableTypes() {
1398
- return idbProxyableTypes || (idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction]);
1399
- }
1400
- // This is a function to prevent it throwing up in node environments.
1401
- function getCursorAdvanceMethods() {
1402
- return cursorAdvanceMethods || (cursorAdvanceMethods = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey]);
1403
- }
1404
- const transactionDoneMap = new WeakMap();
1405
- const transformCache = new WeakMap();
1406
- const reverseTransformCache = new WeakMap();
1407
- function promisifyRequest(request) {
1408
- const promise = new Promise((resolve, reject) => {
1409
- const unlisten = () => {
1410
- request.removeEventListener('success', success);
1411
- request.removeEventListener('error', error);
1412
- };
1413
- const success = () => {
1414
- resolve(wrap(request.result));
1415
- unlisten();
1416
- };
1417
- const error = () => {
1418
- reject(request.error);
1419
- unlisten();
1420
- };
1421
- request.addEventListener('success', success);
1422
- request.addEventListener('error', error);
1423
- });
1424
- // This mapping exists in reverseTransformCache but doesn't exist in transformCache. This
1425
- // is because we create many promises from a single IDBRequest.
1426
- reverseTransformCache.set(promise, request);
1427
- return promise;
1428
- }
1429
- function cacheDonePromiseForTransaction(tx) {
1430
- // Early bail if we've already created a done promise for this transaction.
1431
- if (transactionDoneMap.has(tx)) return;
1432
- const done = new Promise((resolve, reject) => {
1433
- const unlisten = () => {
1434
- tx.removeEventListener('complete', complete);
1435
- tx.removeEventListener('error', error);
1436
- tx.removeEventListener('abort', error);
1437
- };
1438
- const complete = () => {
1439
- resolve();
1440
- unlisten();
1441
- };
1442
- const error = () => {
1443
- reject(tx.error || new DOMException('AbortError', 'AbortError'));
1444
- unlisten();
1445
- };
1446
- tx.addEventListener('complete', complete);
1447
- tx.addEventListener('error', error);
1448
- tx.addEventListener('abort', error);
1449
- });
1450
- // Cache it for later retrieval.
1451
- transactionDoneMap.set(tx, done);
1452
- }
1453
- let idbProxyTraps = {
1454
- get(target, prop, receiver) {
1455
- if (target instanceof IDBTransaction) {
1456
- // Special handling for transaction.done.
1457
- if (prop === 'done') return transactionDoneMap.get(target);
1458
- // Make tx.store return the only store in the transaction, or undefined if there are many.
1459
- if (prop === 'store') {
1460
- return receiver.objectStoreNames[1] ? undefined : receiver.objectStore(receiver.objectStoreNames[0]);
1461
- }
1462
- }
1463
- // Else transform whatever we get back.
1464
- return wrap(target[prop]);
1465
- },
1466
- set(target, prop, value) {
1467
- target[prop] = value;
1468
- return true;
1469
- },
1470
- has(target, prop) {
1471
- if (target instanceof IDBTransaction && (prop === 'done' || prop === 'store')) {
1472
- return true;
1473
- }
1474
- return prop in target;
1475
- }
1327
+ const getNoResults$8 = () => {
1328
+ return noResults();
1476
1329
  };
1477
- function replaceTraps(callback) {
1478
- idbProxyTraps = callback(idbProxyTraps);
1479
- }
1480
- function wrapFunction(func) {
1481
- // Due to expected object equality (which is enforced by the caching in `wrap`), we
1482
- // only create one new func per func.
1483
- // Cursor methods are special, as the behaviour is a little more different to standard IDB. In
1484
- // IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
1485
- // cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
1486
- // with real promises, so each advance methods returns a new promise for the cursor object, or
1487
- // undefined if the end of the cursor has been reached.
1488
- if (getCursorAdvanceMethods().includes(func)) {
1489
- return function (...args) {
1490
- // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
1491
- // the original object.
1492
- func.apply(unwrap(this), args);
1493
- return wrap(this.request);
1494
- };
1495
- }
1496
- return function (...args) {
1497
- // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
1498
- // the original object.
1499
- return wrap(func.apply(unwrap(this), args));
1330
+ const getPicks$8 = async value => {
1331
+ return [];
1332
+ };
1333
+ const selectPick$8 = async item => {
1334
+ return {
1335
+ command: Hide
1500
1336
  };
1501
- }
1502
- function transformCachableValue(value) {
1503
- if (typeof value === 'function') return wrapFunction(value);
1504
- // This doesn't return, it just creates a 'done' promise for the transaction,
1505
- // which is later returned for transaction.done (see idbObjectHandler).
1506
- if (value instanceof IDBTransaction) cacheDonePromiseForTransaction(value);
1507
- if (instanceOfAny(value, getIdbProxyableTypes())) return new Proxy(value, idbProxyTraps);
1508
- // Return the same value back if we're not going to transform it.
1337
+ };
1338
+ const getFilterValue$8 = value => {
1509
1339
  return value;
1510
- }
1511
- function wrap(value) {
1512
- // We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
1513
- // IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
1514
- if (value instanceof IDBRequest) return promisifyRequest(value);
1515
- // If we've already transformed this value before, reuse the transformed value.
1516
- // This is faster, but it also provides object equality.
1517
- if (transformCache.has(value)) return transformCache.get(value);
1518
- const newValue = transformCachableValue(value);
1519
- // Not all types are transformed.
1520
- // These may be primitive types, so they can't be WeakMap keys.
1521
- if (newValue !== value) {
1522
- transformCache.set(value, newValue);
1523
- reverseTransformCache.set(newValue, value);
1524
- }
1525
- return newValue;
1526
- }
1527
- const unwrap = value => reverseTransformCache.get(value);
1528
-
1529
- /**
1530
- * Open a database.
1531
- *
1532
- * @param name Name of the database.
1533
- * @param version Schema version.
1534
- * @param callbacks Additional callbacks.
1535
- */
1536
- function openDB(name, version, {
1537
- blocked,
1538
- upgrade,
1539
- blocking,
1540
- terminated
1541
- } = {}) {
1542
- const request = indexedDB.open(name, version);
1543
- const openPromise = wrap(request);
1544
- if (upgrade) {
1545
- request.addEventListener('upgradeneeded', event => {
1546
- upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
1547
- });
1548
- }
1549
- if (blocked) {
1550
- request.addEventListener('blocked', event => blocked(
1551
- // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
1552
- event.oldVersion, event.newVersion, event));
1553
- }
1554
- openPromise.then(db => {
1555
- if (terminated) db.addEventListener('close', () => terminated());
1556
- if (blocking) {
1557
- db.addEventListener('versionchange', event => blocking(event.oldVersion, event.newVersion, event));
1558
- }
1559
- }).catch(() => {});
1560
- return openPromise;
1561
- }
1562
- const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
1563
- const writeMethods = ['put', 'add', 'delete', 'clear'];
1564
- const cachedMethods = new Map();
1565
- function getMethod(target, prop) {
1566
- if (!(target instanceof IDBDatabase && !(prop in target) && typeof prop === 'string')) {
1567
- return;
1568
- }
1569
- if (cachedMethods.get(prop)) return cachedMethods.get(prop);
1570
- const targetFuncName = prop.replace(/FromIndex$/, '');
1571
- const useIndex = prop !== targetFuncName;
1572
- const isWrite = writeMethods.includes(targetFuncName);
1573
- if (
1574
- // Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
1575
- !(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) || !(isWrite || readMethods.includes(targetFuncName))) {
1576
- return;
1577
- }
1578
- const method = async function (storeName, ...args) {
1579
- // isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
1580
- const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
1581
- let target = tx.store;
1582
- if (useIndex) target = target.index(args.shift());
1583
- // Must reject if op rejects.
1584
- // If it's a write operation, must reject if tx.done rejects.
1585
- // Must reject with op rejection first.
1586
- // Must resolve with op value.
1587
- // Must handle both promises (no unhandled rejections)
1588
- return (await Promise.all([target[targetFuncName](...args), isWrite && tx.done]))[0];
1589
- };
1590
- cachedMethods.set(prop, method);
1591
- return method;
1592
- }
1593
- replaceTraps(oldTraps => ({
1594
- ...oldTraps,
1595
- get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
1596
- has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop)
1597
- }));
1598
- const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];
1599
- const methodMap = {};
1600
- const advanceResults = new WeakMap();
1601
- const ittrProxiedCursorToOriginalProxy = new WeakMap();
1602
- const cursorIteratorTraps = {
1603
- get(target, prop) {
1604
- if (!advanceMethodProps.includes(prop)) return target[prop];
1605
- let cachedFunc = methodMap[prop];
1606
- if (!cachedFunc) {
1607
- cachedFunc = methodMap[prop] = function (...args) {
1608
- advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
1609
- };
1610
- }
1611
- return cachedFunc;
1612
- }
1613
- };
1614
- async function* iterate(...args) {
1615
- // tslint:disable-next-line:no-this-assignment
1616
- let cursor = this;
1617
- if (!(cursor instanceof IDBCursor)) {
1618
- cursor = await cursor.openCursor(...args);
1619
- }
1620
- if (!cursor) return;
1621
- cursor = cursor;
1622
- const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
1623
- ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
1624
- // Map this double-proxy back to the original, so other cursor methods work.
1625
- reverseTransformCache.set(proxiedCursor, unwrap(cursor));
1626
- while (cursor) {
1627
- yield proxiedCursor;
1628
- // If one of the advancing methods was not called, call continue().
1629
- cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
1630
- advanceResults.delete(proxiedCursor);
1631
- }
1632
- }
1633
- function isIteratorProp(target, prop) {
1634
- return prop === Symbol.asyncIterator && instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor]) || prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore]);
1635
- }
1636
- replaceTraps(oldTraps => ({
1637
- ...oldTraps,
1638
- get(target, prop, receiver) {
1639
- if (isIteratorProp(target, prop)) return iterate;
1640
- return oldTraps.get(target, prop, receiver);
1641
- },
1642
- has(target, prop) {
1643
- return isIteratorProp(target, prop) || oldTraps.has(target, prop);
1644
- }
1645
- }));
1646
-
1647
- const state$2 = {
1648
- dbVersion: 1};
1340
+ };
1341
+ const getPickFilterValue$7 = pick => {
1342
+ return pick;
1343
+ };
1649
1344
 
1650
- // TODO high memory usage in idb because of transactionDoneMap
1651
-
1652
- const getHandleDb = async () => {
1653
- // @ts-ignore
1654
- const db = await openDB('handle', state$2.dbVersion, {
1655
- async upgrade(db) {
1656
- if (!db.objectStoreNames.contains('file-handles-store')) {
1657
- await db.createObjectStore('file-handles-store', {});
1658
- }
1659
- }
1660
- });
1661
- return db;
1662
- };
1663
- const getHandle$1 = async uri => {
1664
- const handleDb = await getHandleDb();
1665
- const handle = await handleDb.get('file-handles-store', uri);
1666
- return handle;
1667
- };
1668
-
1669
- const getHandle = async uri => {
1670
- try {
1671
- // TODO retrieve handle from state or from indexeddb
1672
- // TODO if not found, throw error
1673
- const handle = await getHandle$1(uri);
1674
- return handle;
1675
- } catch (error) {
1676
- throw new VError(error, 'Failed to get handle');
1677
- }
1678
- };
1679
-
1680
- const getDirectoryHandle = async uri => {
1681
- const handle = await getHandle(uri);
1682
- if (handle) {
1683
- return handle;
1684
- }
1685
- const dirname$1 = dirname('/', uri);
1686
- if (uri === dirname$1) {
1687
- return undefined;
1688
- }
1689
- return getDirectoryHandle(dirname$1);
1690
- };
1691
- const toIgnore = ['.git', 'node_modules', 'dist', 'dist2'];
1692
- const searchFilesRecursively = async (all, parent, handle) => {
1693
- const childHandles = await getChildHandles(handle);
1694
- const promises = [];
1695
- for (const childHandle of childHandles) {
1696
- if (toIgnore.includes(childHandle.name)) {
1697
- continue;
1698
- }
1699
- const absolutePath = parent + '/' + childHandle.name;
1700
- switch (childHandle.kind) {
1701
- case Directory:
1702
- promises.push(searchFilesRecursively(all, absolutePath, childHandle));
1703
- break;
1704
- case File$1:
1705
- all.push(absolutePath);
1706
- break;
1707
- }
1708
- }
1709
- await Promise.all(promises);
1710
- };
1711
- const searchFile$3 = async uri => {
1712
- const path = uri.slice('html://'.length);
1713
- const handle = await getDirectoryHandle(path);
1714
- if (!handle) {
1715
- // @ts-ignore
1716
- throw new VError(`Folder not found ${uri}`);
1717
- }
1718
- const all = [];
1719
- await searchFilesRecursively(all, '', handle);
1720
- return all;
1721
- };
1722
-
1723
- const SearchFileHtml = {
1724
- __proto__: null,
1725
- searchFile: searchFile$3
1726
- };
1727
-
1728
- const emptyMatches = [];
1729
-
1730
- const convertToPick = item => {
1731
- return {
1732
- pick: item,
1733
- matches: emptyMatches
1734
- };
1735
- };
1736
-
1737
- const Diagonal = 1;
1738
- const Left = 2;
1739
-
1740
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1741
-
1742
- const createTable = size => {
1743
- const table = [];
1744
- for (let i = 0; i < size; i++) {
1745
- const row = new Uint8Array(size);
1746
- table.push(row);
1747
- }
1748
- return table;
1749
- };
1750
- const EmptyMatches = [];
1751
- const Dash = '-';
1752
- const Dot = '.';
1753
- const EmptyString = '';
1754
- const Space = ' ';
1755
- const Underline = '_';
1756
- const T = 't';
1757
- const isLowerCase = char => {
1758
- return char === char.toLowerCase();
1759
- };
1760
- const isUpperCase = char => {
1761
- return char === char.toUpperCase();
1762
- };
1763
-
1764
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1765
- const isGap = (columnCharBefore, columnChar) => {
1766
- switch (columnCharBefore) {
1767
- case Dash:
1768
- case Underline:
1769
- case EmptyString:
1770
- case T:
1771
- case Space:
1772
- case Dot:
1773
- return true;
1774
- }
1775
- if (isLowerCase(columnCharBefore) && isUpperCase(columnChar)) {
1776
- return true;
1777
- }
1778
- return false;
1779
- };
1780
-
1781
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1782
- const getScore = (rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, isDiagonalMatch) => {
1783
- if (rowCharLow !== columnCharLow) {
1784
- return -1;
1785
- }
1786
- const isMatch = rowChar === columnChar;
1787
- if (isMatch) {
1788
- if (isDiagonalMatch) {
1789
- return 8;
1790
- }
1791
- if (isGap(columnCharBefore, columnChar)) {
1792
- return 8;
1793
- }
1794
- return 5;
1795
- }
1796
- if (isGap(columnCharBefore, columnChar)) {
1797
- return 8;
1798
- }
1799
- return 5;
1800
- };
1801
-
1802
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1803
-
1804
- const isPatternInWord = (patternLow, patternPos, patternLen, wordLow, wordPos, wordLen) => {
1805
- while (patternPos < patternLen && wordPos < wordLen) {
1806
- if (patternLow[patternPos] === wordLow[wordPos]) {
1807
- patternPos += 1;
1808
- }
1809
- wordPos += 1;
1810
- }
1811
- return patternPos === patternLen; // pattern must be exhausted
1812
- };
1813
-
1814
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1815
- const traceHighlights = (table, arrows, patternLength, wordLength) => {
1816
- let row = patternLength;
1817
- let column = wordLength;
1818
- const matches = [];
1819
- while (row >= 1 && column >= 1) {
1820
- const arrow = arrows[row][column];
1821
- if (arrow === Left) {
1822
- column--;
1823
- } else if (arrow === Diagonal) {
1824
- row--;
1825
- column--;
1826
- const start = column + 1;
1827
- while (row >= 1 && column >= 1) {
1828
- const arrow = arrows[row][column];
1829
- if (arrow === Left) {
1830
- break;
1831
- }
1832
- if (arrow === Diagonal) {
1833
- row--;
1834
- column--;
1835
- }
1836
- }
1837
- const end = column;
1838
- matches.unshift(end, start);
1839
- }
1840
- }
1841
- matches.unshift(table[patternLength][wordLength - 1]);
1842
- return matches;
1843
- };
1844
-
1845
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1846
- const gridSize = 128;
1847
- const table = createTable(gridSize);
1848
- const arrows = createTable(gridSize);
1849
- const fuzzySearch = (pattern, word) => {
1850
- const patternLength = Math.min(pattern.length, gridSize - 1);
1851
- const wordLength = Math.min(word.length, gridSize - 1);
1852
- const patternLower = pattern.toLowerCase();
1853
- const wordLower = word.toLowerCase();
1854
- if (!isPatternInWord(patternLower, 0, patternLength, wordLower, 0, wordLength)) {
1855
- return EmptyMatches;
1856
- }
1857
- let strongMatch = false;
1858
- for (let row = 1; row < patternLength + 1; row++) {
1859
- const rowChar = pattern[row - 1];
1860
- const rowCharLow = patternLower[row - 1];
1861
- for (let column = 1; column < wordLength + 1; column++) {
1862
- const columnChar = word[column - 1];
1863
- const columnCharLow = wordLower[column - 1];
1864
- const columnCharBefore = word[column - 2] || '';
1865
- const isDiagonalMatch = arrows[row - 1][column - 1] === Diagonal;
1866
- const score = getScore(rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, isDiagonalMatch);
1867
- if (row === 1 && score > 5) {
1868
- strongMatch = true;
1869
- }
1870
- let diagonalScore = score + table[row - 1][column - 1];
1871
- if (isDiagonalMatch && score !== -1) {
1872
- diagonalScore += 2;
1873
- }
1874
- const leftScore = table[row][column - 1];
1875
- if (leftScore > diagonalScore) {
1876
- table[row][column] = leftScore;
1877
- arrows[row][column] = Left;
1878
- } else {
1879
- table[row][column] = diagonalScore;
1880
- arrows[row][column] = Diagonal;
1881
- }
1882
- }
1883
- }
1884
- if (!strongMatch) {
1885
- return EmptyMatches;
1886
- }
1887
- const highlights = traceHighlights(table, arrows, patternLength, wordLength);
1888
- return highlights;
1889
- };
1890
-
1891
- const filterQuickPickItem = (pattern, word) => {
1892
- const matches = fuzzySearch(pattern, word);
1893
- return matches;
1894
- };
1895
-
1896
- // TODO this should be in FileSystem module
1897
- const pathBaseName = path => {
1898
- return path.slice(path.lastIndexOf('/') + 1);
1899
- };
1900
-
1901
- // TODO this should be in FileSystem module
1902
- const pathDirName = path => {
1903
- const pathSeparator = '/';
1904
- const index = path.lastIndexOf(pathSeparator);
1905
- if (index === -1) {
1906
- return '';
1907
- }
1908
- return path.slice(0, index);
1909
- };
1910
-
1911
- const filterQuickPickItems = (items, value, provider) => {
1912
- if (!value) {
1913
- return items.map(convertToPick);
1914
- }
1915
- const results = [];
1916
- for (const item of items) {
1917
- let filterValue = '';
1918
- if (provider) {
1919
- filterValue = provider.getPickLabel(item);
1920
- } else {
1921
- filterValue = pathBaseName(item);
1922
- }
1923
- const matches = filterQuickPickItem(value, filterValue);
1924
- if (matches.length > 0) {
1925
- results.push({
1926
- pick: item,
1927
- matches
1928
- });
1929
- }
1930
- }
1931
- return results;
1932
- };
1933
-
1934
- const getFileSearchRipGrepArgs = () => {
1935
- const ripGrepArgs = ['--files', '--sort-files'];
1936
- return ripGrepArgs;
1937
- };
1938
-
1939
- const invoke = (method, ...params) => {
1940
- return invoke$1('SearchProcess.invoke', method, ...params);
1941
- };
1942
-
1943
- const splitLines = lines => {
1944
- if (!lines) {
1945
- return [];
1946
- }
1947
- return lines.split('\n');
1948
- };
1949
-
1950
- // TODO create direct connection from electron to file search worker using message ports
1951
-
1952
- const searchFile$2 = async (path, value, prepare) => {
1953
- const ripGrepArgs = getFileSearchRipGrepArgs();
1954
- const options = {
1955
- ripGrepArgs,
1956
- searchPath: path,
1957
- limit: 9_999_999
1958
- };
1959
- const stdout = await invoke('SearchFile.searchFile', options);
1960
- const lines = splitLines(stdout);
1961
- if (!prepare) {
1962
- return lines;
1963
- }
1964
- const filtered = filterQuickPickItems(lines, value);
1965
- return filtered;
1966
- };
1967
-
1968
- const SearchFileRipGrep = {
1969
- __proto__: null,
1970
- searchFile: searchFile$2
1971
- };
1972
-
1973
- const getModule = protocol => {
1974
- switch (protocol) {
1975
- case Memfs:
1976
- return SearchFileMemfs;
1977
- case Fetch:
1978
- return SearchFileFetch;
1979
- case Html:
1980
- return SearchFileHtml;
1981
- default:
1982
- return SearchFileRipGrep;
1983
- }
1984
- };
1985
-
1986
- const searchFile$1 = async (path, value, prepare, assetDir) => {
1987
- const protocol = getProtocol(path);
1988
- // TODO call different providers depending on protocol
1989
- const module = await getModule(protocol);
1990
- const result = await module.searchFile(path, value, prepare, assetDir);
1991
- return result;
1992
- };
1993
-
1994
- const searchFile = async (path, value) => {
1995
- const prepare = true;
1996
- // @ts-ignore
1997
- const files = await searchFile$1(/* path */path, /* searchTerm */value, prepare);
1998
- return files;
1999
- };
2000
- const name$7 = 'file';
2001
- const getPlaceholder$a = () => {
2002
- return '';
2003
- };
2004
- const getLabel$4 = () => {
2005
- return files();
2006
- };
2007
-
2008
- // TODO help entries should not be here
2009
- const getHelpEntries$9 = () => {
2010
- return [{
2011
- description: goToFile(),
2012
- category: 'global commands'
2013
- }];
2014
- };
2015
- const getNoResults$9 = () => {
2016
- return {
2017
- label: noMatchingResults()
2018
- };
2019
- };
2020
- const getPicks$a = async searchValue => {
2021
- // TODO cache workspace path
2022
- const workspace = await invoke$1('Workspace.getPath');
2023
- if (!workspace) {
2024
- return [];
2025
- }
2026
- const files = await searchFile(workspace, searchValue);
2027
- // const picks = files.map(toPick)
2028
- return files;
2029
- };
2030
- const selectPick$a = async pick => {
2031
- if (typeof pick === 'object') {
2032
- pick = pick.pick;
2033
- }
2034
- const workspace = await invoke$1('Workspace.getPath');
2035
- const absolutePath = `${workspace}/${pick}`;
2036
- await openUri(absolutePath);
2037
- return {
2038
- command: Hide
2039
- };
2040
- };
2041
- const getFilterValue$9 = value => {
2042
- return value;
2043
- };
2044
- const getPickFilterValue$5 = pick => {
2045
- if (typeof pick === 'object') {
2046
- pick = pick.pick;
2047
- }
2048
- return pick;
2049
- };
2050
- const getPickLabel$4 = pick => {
2051
- if (typeof pick === 'object') {
2052
- pick = pick.pick;
2053
- }
2054
- const baseName = pathBaseName(pick);
2055
- return baseName;
2056
- };
2057
- const getPickDescription$4 = pick => {
2058
- if (typeof pick === 'object') {
2059
- pick = pick.pick;
2060
- }
2061
- const dirName = pathDirName(pick);
2062
- return dirName;
2063
- };
2064
- const getPickIcon$4 = () => {
2065
- return '';
2066
- };
2067
- const getPickFileIcon$2 = pick => {
2068
- if (typeof pick === 'object') {
2069
- pick = pick.pick;
2070
- }
2071
- if (typeof pick === 'object') {
2072
- pick = pick.pick;
2073
- }
2074
- const baseName = pathBaseName(pick);
2075
- return {
2076
- type: File$2,
2077
- name: baseName
2078
- };
2079
- };
2080
- const isPrepared$1 = () => {
2081
- const workspace = '';
2082
- // TODO protocol should always be defined. For files it should use file protocol
2083
- const protocol = getProtocol(workspace);
2084
- return !protocol;
2085
- };
2086
-
2087
- const QuickPickEntriesFile = {
2088
- __proto__: null,
2089
- getFilterValue: getFilterValue$9,
2090
- getHelpEntries: getHelpEntries$9,
2091
- getLabel: getLabel$4,
2092
- getNoResults: getNoResults$9,
2093
- getPickDescription: getPickDescription$4,
2094
- getPickFileIcon: getPickFileIcon$2,
2095
- getPickFilterValue: getPickFilterValue$5,
2096
- getPickIcon: getPickIcon$4,
2097
- getPickLabel: getPickLabel$4,
2098
- getPicks: getPicks$a,
2099
- getPlaceholder: getPlaceholder$a,
2100
- isPrepared: isPrepared$1,
2101
- name: name$7,
2102
- selectPick: selectPick$a
2103
- };
2104
-
2105
- const execute = async (method, ...params) => {
2106
- // TODO
2107
- };
2108
-
2109
- const name$6 = 'goToLine';
2110
- const getPlaceholder$9 = () => {
2111
- return '';
2112
- };
2113
- const getHelpEntries$8 = () => {
2114
- return [];
2115
- };
2116
- const getNoResults$8 = () => {
2117
- return undefined;
2118
- };
2119
- const getPicks$9 = async () => {
2120
- const picks = [{
2121
- label: '1'
2122
- }, {
2123
- label: '2'
2124
- }, {
2125
- label: '3'
2126
- }, {
2127
- label: '4'
2128
- }, {
2129
- label: '5'
2130
- }, {
2131
- label: '6'
2132
- }];
2133
- return picks;
2134
- };
2135
- const selectPick$9 = async item => {
2136
- const rowIndex = Number.parseInt(item.label);
2137
- const position = {
2138
- rowIndex,
2139
- columnIndex: 5
2140
- };
2141
- await execute(/* EditorSetCursor.editorSetCursor */'TODO', /* position */position);
2142
- // TODO put cursor onto that line
2143
- return {
2144
- command: Hide
2145
- };
2146
- };
2147
- const getFilterValue$8 = value => {
2148
- return value;
2149
- };
2150
-
2151
- const QuickPickEntriesGoToLine = {
1345
+ const QuickPickNoop = {
2152
1346
  __proto__: null,
2153
1347
  getFilterValue: getFilterValue$8,
2154
1348
  getHelpEntries: getHelpEntries$8,
2155
1349
  getNoResults: getNoResults$8,
2156
- getPicks: getPicks$9,
2157
- getPlaceholder: getPlaceholder$9,
2158
- name: name$6,
2159
- selectPick: selectPick$9
2160
- };
2161
-
2162
- const name$5 = 'noop';
2163
- const getPlaceholder$8 = () => {
2164
- return '';
2165
- };
2166
- const getHelpEntries$7 = () => {
2167
- return [];
2168
- };
2169
- const getNoResults$7 = () => {
2170
- return noResults();
2171
- };
2172
- const getPicks$8 = async value => {
2173
- return [];
2174
- };
2175
- const selectPick$8 = async item => {
2176
- return {
2177
- command: Hide
2178
- };
2179
- };
2180
- const getFilterValue$7 = value => {
2181
- return value;
2182
- };
2183
- const getPickFilterValue$4 = pick => {
2184
- return pick;
2185
- };
2186
-
2187
- const QuickPickNoop = {
2188
- __proto__: null,
2189
- getFilterValue: getFilterValue$7,
2190
- getHelpEntries: getHelpEntries$7,
2191
- getNoResults: getNoResults$7,
2192
- getPickFilterValue: getPickFilterValue$4,
1350
+ getPickFilterValue: getPickFilterValue$7,
2193
1351
  getPicks: getPicks$8,
2194
1352
  getPlaceholder: getPlaceholder$8,
2195
- name: name$5,
1353
+ name: name$8,
2196
1354
  selectPick: selectPick$8
2197
1355
  };
2198
1356
 
2199
- const name$4 = 'symbol';
1357
+ const name$7 = 'symbol';
2200
1358
  const getPlaceholder$7 = () => {
2201
1359
  return '';
2202
1360
  };
2203
- const getHelpEntries$6 = () => {
1361
+ const getHelpEntries$7 = () => {
2204
1362
  return [];
2205
1363
  };
2206
- const getNoResults$6 = () => {
1364
+ const getNoResults$7 = () => {
2207
1365
  return {
2208
1366
  label: noSymbolFound()
2209
1367
  };
@@ -2217,19 +1375,41 @@ const selectPick$7 = async item => {
2217
1375
  command: Hide
2218
1376
  };
2219
1377
  };
2220
- const getFilterValue$6 = value => {
1378
+ const getFilterValue$7 = value => {
1379
+ return value;
1380
+ };
1381
+ const state$7 = {};
1382
+ const getPickDescription$7 = value => {
1383
+ return '';
1384
+ };
1385
+ const isPrepared$6 = () => {
1386
+ return false;
1387
+ };
1388
+ const getPickFilterValue$6 = value => {
1389
+ return value;
1390
+ };
1391
+ const getPickLabel$6 = value => {
2221
1392
  return value;
2222
1393
  };
1394
+ const getPickIcon$6 = value => {
1395
+ return '';
1396
+ };
2223
1397
 
2224
1398
  const QuickPickEntriesSymbol = {
2225
1399
  __proto__: null,
2226
- getFilterValue: getFilterValue$6,
2227
- getHelpEntries: getHelpEntries$6,
2228
- getNoResults: getNoResults$6,
1400
+ getFilterValue: getFilterValue$7,
1401
+ getHelpEntries: getHelpEntries$7,
1402
+ getNoResults: getNoResults$7,
1403
+ getPickDescription: getPickDescription$7,
1404
+ getPickFilterValue: getPickFilterValue$6,
1405
+ getPickIcon: getPickIcon$6,
1406
+ getPickLabel: getPickLabel$6,
2229
1407
  getPicks: getPicks$7,
2230
1408
  getPlaceholder: getPlaceholder$7,
2231
- name: name$4,
2232
- selectPick: selectPick$7
1409
+ isPrepared: isPrepared$6,
1410
+ name: name$7,
1411
+ selectPick: selectPick$7,
1412
+ state: state$7
2233
1413
  };
2234
1414
 
2235
1415
  // TODO probably not needed
@@ -2237,7 +1417,7 @@ const QuickPickEntriesSymbol = {
2237
1417
  const getPlaceholder$6 = () => {
2238
1418
  return typeNameofCommandToRun();
2239
1419
  };
2240
- const getHelpEntries$5 = () => {
1420
+ const getHelpEntries$6 = () => {
2241
1421
  return undefined;
2242
1422
  };
2243
1423
  const getPicks$6 = async () => {
@@ -2252,24 +1432,52 @@ const selectPick$6 = async item => {
2252
1432
  // command: QuickPickReturnValue.Hide,
2253
1433
  // }
2254
1434
  };
2255
- const getFilterValue$5 = value => {
1435
+ const getFilterValue$6 = value => {
1436
+ return value;
1437
+ };
1438
+ const getPickFilterValue$5 = value => {
2256
1439
  return value;
2257
1440
  };
1441
+ const getPickLabel$5 = value => {
1442
+ return value;
1443
+ };
1444
+ const getPickIcon$5 = value => {
1445
+ return '';
1446
+ };
1447
+ const state$6 = {};
1448
+ const getNoResults$6 = () => {
1449
+ return '';
1450
+ };
1451
+ const name$6 = '';
1452
+ const isPrepared$5 = () => {
1453
+ return true;
1454
+ };
1455
+ const getPickDescription$6 = () => {
1456
+ return '';
1457
+ };
2258
1458
 
2259
1459
  const QuickPickEntriesView = {
2260
1460
  __proto__: null,
2261
- getFilterValue: getFilterValue$5,
2262
- getHelpEntries: getHelpEntries$5,
1461
+ getFilterValue: getFilterValue$6,
1462
+ getHelpEntries: getHelpEntries$6,
1463
+ getNoResults: getNoResults$6,
1464
+ getPickDescription: getPickDescription$6,
1465
+ getPickFilterValue: getPickFilterValue$5,
1466
+ getPickIcon: getPickIcon$5,
1467
+ getPickLabel: getPickLabel$5,
2263
1468
  getPicks: getPicks$6,
2264
1469
  getPlaceholder: getPlaceholder$6,
2265
- selectPick: selectPick$6
1470
+ isPrepared: isPrepared$5,
1471
+ name: name$6,
1472
+ selectPick: selectPick$6,
1473
+ state: state$6
2266
1474
  };
2267
1475
 
2268
- const name$3 = 'workspace-symbol';
1476
+ const name$5 = 'workspace-symbol';
2269
1477
  const getPlaceholder$5 = () => {
2270
1478
  return '';
2271
1479
  };
2272
- const getHelpEntries$4 = () => {
1480
+ const getHelpEntries$5 = () => {
2273
1481
  return [];
2274
1482
  };
2275
1483
  const getNoResults$5 = () => {
@@ -2286,23 +1494,23 @@ const selectPick$5 = async item => {
2286
1494
  command: Hide
2287
1495
  };
2288
1496
  };
2289
- const getFilterValue$4 = value => {
1497
+ const getFilterValue$5 = value => {
2290
1498
  return value;
2291
1499
  };
2292
1500
 
2293
1501
  const QuickPickEntriesWorkspaceSymbol = {
2294
1502
  __proto__: null,
2295
- getFilterValue: getFilterValue$4,
2296
- getHelpEntries: getHelpEntries$4,
1503
+ getFilterValue: getFilterValue$5,
1504
+ getHelpEntries: getHelpEntries$5,
2297
1505
  getNoResults: getNoResults$5,
2298
1506
  getPicks: getPicks$5,
2299
1507
  getPlaceholder: getPlaceholder$5,
2300
- name: name$3,
1508
+ name: name$5,
2301
1509
  selectPick: selectPick$5
2302
1510
  };
2303
1511
 
2304
1512
  const Command = '>';
2305
- const Symbol$2 = '@';
1513
+ const Symbol$1 = '@';
2306
1514
  const WorkspaceSymbol$1 = '#';
2307
1515
  const GoToLine = ':';
2308
1516
  const View$1 = 'view ';
@@ -2310,7 +1518,7 @@ const None$2 = '';
2310
1518
 
2311
1519
  // TODO avoid global variable
2312
1520
 
2313
- const state$1 = {
1521
+ const state$5 = {
2314
1522
  // providerId: PROVIDER_NOOP,
2315
1523
  provider: QuickPickNoop,
2316
1524
  prefix: 'string-that-should-never-match-another-string'
@@ -2319,25 +1527,25 @@ const state$1 = {
2319
1527
  /**
2320
1528
  * @type {string}
2321
1529
  */
2322
- const name$2 = 'everything';
1530
+ const name$4 = 'everything';
2323
1531
  const getPlaceholder$4 = () => {
2324
- return state$1.provider.getPlaceholder();
1532
+ return state$5.provider.getPlaceholder();
2325
1533
  };
2326
1534
  const getLabel$3 = () => {
2327
1535
  return '';
2328
1536
  };
2329
- const getHelpEntries$3 = () => {
2330
- return state$1.provider.getHelpEntries();
1537
+ const getHelpEntries$4 = () => {
1538
+ return state$5.provider.getHelpEntries();
2331
1539
  };
2332
1540
  const getNoResults$4 = () => {
2333
- return state$1.provider.getNoResults();
1541
+ return state$5.provider.getNoResults();
2334
1542
  };
2335
1543
  const getPrefix = value => {
2336
1544
  if (value.startsWith(Command)) {
2337
1545
  return Command;
2338
1546
  }
2339
- if (value.startsWith(Symbol$2)) {
2340
- return Symbol$2;
1547
+ if (value.startsWith(Symbol$1)) {
1548
+ return Symbol$1;
2341
1549
  }
2342
1550
  if (value.startsWith(WorkspaceSymbol$1)) {
2343
1551
  return WorkspaceSymbol$1;
@@ -2357,7 +1565,7 @@ const getQuickPickProvider = prefix => {
2357
1565
  switch (prefix) {
2358
1566
  case Command:
2359
1567
  return QuickPickEntriesCommand;
2360
- case Symbol$2:
1568
+ case Symbol$1:
2361
1569
  return QuickPickEntriesSymbol;
2362
1570
  case WorkspaceSymbol$1:
2363
1571
  return QuickPickEntriesWorkspaceSymbol;
@@ -2373,20 +1581,20 @@ const getPicks$4 = async value => {
2373
1581
  const prefix = getPrefix(value);
2374
1582
 
2375
1583
  // TODO race condition
2376
- if (state$1.prefix !== prefix) {
2377
- state$1.prefix = prefix;
1584
+ if (state$5.prefix !== prefix) {
1585
+ state$5.prefix = prefix;
2378
1586
  // @ts-ignore
2379
- state$1.provider = await getQuickPickProvider(prefix);
1587
+ state$5.provider = await getQuickPickProvider(prefix);
2380
1588
  }
2381
1589
  // TODO this line is a bit duplicated with getFilterValue
2382
1590
  const slicedValue = value.slice(prefix.length).trimStart();
2383
- const picks = await state$1.provider.getPicks(slicedValue);
1591
+ const picks = await state$5.provider.getPicks(slicedValue);
2384
1592
  return picks;
2385
1593
  };
2386
1594
  const selectPick$4 = item => {
2387
1595
  const {
2388
1596
  provider
2389
- } = state$1;
1597
+ } = state$5;
2390
1598
  return provider.selectPick(item);
2391
1599
  };
2392
1600
  const openCommandPalette = () => {
@@ -2395,19 +1603,19 @@ const openCommandPalette = () => {
2395
1603
  const openView = () => {
2396
1604
  // show('view ')
2397
1605
  };
2398
- const getFilterValue$3 = value => {
2399
- return value.slice(state$1.prefix.length);
1606
+ const getFilterValue$4 = value => {
1607
+ return value.slice(state$5.prefix.length);
2400
1608
  };
2401
- const getPickFilterValue$3 = pick => {
1609
+ const getPickFilterValue$4 = pick => {
2402
1610
  const {
2403
1611
  provider
2404
- } = state$1;
1612
+ } = state$5;
2405
1613
  return provider.getPickFilterValue(pick);
2406
1614
  };
2407
- const getPickDescription$3 = pick => {
1615
+ const getPickDescription$5 = pick => {
2408
1616
  const {
2409
1617
  provider
2410
- } = state$1;
1618
+ } = state$5;
2411
1619
  // @ts-ignore
2412
1620
  if (provider.getPickDescription) {
2413
1621
  // @ts-ignore
@@ -2415,24 +1623,24 @@ const getPickDescription$3 = pick => {
2415
1623
  }
2416
1624
  return '';
2417
1625
  };
2418
- const getPickLabel$3 = pick => {
1626
+ const getPickLabel$4 = pick => {
2419
1627
  const {
2420
1628
  provider
2421
- } = state$1;
1629
+ } = state$5;
2422
1630
  // @ts-ignore
2423
1631
  return provider.getPickLabel(pick);
2424
1632
  };
2425
- const getPickIcon$3 = pick => {
1633
+ const getPickIcon$4 = pick => {
2426
1634
  const {
2427
1635
  provider
2428
- } = state$1;
1636
+ } = state$5;
2429
1637
  // @ts-ignore
2430
1638
  return provider.getPickIcon(pick);
2431
1639
  };
2432
1640
  const getPickFileIcon$1 = pick => {
2433
1641
  const {
2434
1642
  provider
2435
- } = state$1;
1643
+ } = state$5;
2436
1644
  // @ts-ignore
2437
1645
  if (provider.getPickFileIcon) {
2438
1646
  // @ts-ignore
@@ -2440,10 +1648,10 @@ const getPickFileIcon$1 = pick => {
2440
1648
  }
2441
1649
  return '';
2442
1650
  };
2443
- const isPrepared = () => {
1651
+ const isPrepared$4 = () => {
2444
1652
  const {
2445
1653
  provider
2446
- } = state$1;
1654
+ } = state$5;
2447
1655
  // @ts-ignore
2448
1656
  if (provider.isPrepared) {
2449
1657
  // @ts-ignore
@@ -2454,26 +1662,26 @@ const isPrepared = () => {
2454
1662
 
2455
1663
  const QuickPickEntriesEverything = {
2456
1664
  __proto__: null,
2457
- getFilterValue: getFilterValue$3,
2458
- getHelpEntries: getHelpEntries$3,
1665
+ getFilterValue: getFilterValue$4,
1666
+ getHelpEntries: getHelpEntries$4,
2459
1667
  getLabel: getLabel$3,
2460
1668
  getNoResults: getNoResults$4,
2461
- getPickDescription: getPickDescription$3,
1669
+ getPickDescription: getPickDescription$5,
2462
1670
  getPickFileIcon: getPickFileIcon$1,
2463
- getPickFilterValue: getPickFilterValue$3,
2464
- getPickIcon: getPickIcon$3,
2465
- getPickLabel: getPickLabel$3,
1671
+ getPickFilterValue: getPickFilterValue$4,
1672
+ getPickIcon: getPickIcon$4,
1673
+ getPickLabel: getPickLabel$4,
2466
1674
  getPicks: getPicks$4,
2467
1675
  getPlaceholder: getPlaceholder$4,
2468
- isPrepared,
2469
- name: name$2,
1676
+ isPrepared: isPrepared$4,
1677
+ name: name$4,
2470
1678
  openCommandPalette,
2471
1679
  openView,
2472
1680
  selectPick: selectPick$4,
2473
- state: state$1
1681
+ state: state$5
2474
1682
  };
2475
1683
 
2476
- const Default = 0;
1684
+ const Default$1 = 0;
2477
1685
  const Finished = 2;
2478
1686
 
2479
1687
  const create$3 = () => {
@@ -2565,7 +1773,7 @@ const handleWheel = (state, deltaMode, deltaY) => {
2565
1773
  const create$1 = (uid, uri, listItemHeight, x, y, width, height, platform, args) => {
2566
1774
  const state = {
2567
1775
  uid,
2568
- state: Default,
1776
+ state: Default$1,
2569
1777
  picks: [],
2570
1778
  recentPicks: [],
2571
1779
  recentPickIds: new Map(),
@@ -2598,7 +1806,7 @@ const create$1 = (uid, uri, listItemHeight, x, y, width, height, platform, args)
2598
1806
  const create = (uid, uri, listItemHeight, x, y, width, height, platform, args) => {
2599
1807
  const state = {
2600
1808
  uid,
2601
- state: Default,
1809
+ state: Default$1,
2602
1810
  picks: [],
2603
1811
  recentPicks: [],
2604
1812
  recentPickIds: new Map(),
@@ -2629,80 +1837,195 @@ const create = (uid, uri, listItemHeight, x, y, width, height, platform, args) =
2629
1837
  return state;
2630
1838
  };
2631
1839
 
2632
- const getBlob$1 = async url => {
2633
- try {
2634
- const response = await fetch(url);
2635
- if (!response.ok) {
2636
- throw new Error(response.statusText);
1840
+ const emptyMatches = [];
1841
+
1842
+ const convertToPick = item => {
1843
+ return {
1844
+ pick: item,
1845
+ matches: emptyMatches
1846
+ };
1847
+ };
1848
+
1849
+ const Diagonal = 1;
1850
+ const Left = 2;
1851
+
1852
+ // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1853
+
1854
+ const createTable = size => {
1855
+ const table = [];
1856
+ for (let i = 0; i < size; i++) {
1857
+ const row = new Uint8Array(size);
1858
+ table.push(row);
1859
+ }
1860
+ return table;
1861
+ };
1862
+ const EmptyMatches = [];
1863
+ const Dash = '-';
1864
+ const Dot = '.';
1865
+ const EmptyString = '';
1866
+ const Space = ' ';
1867
+ const Underline = '_';
1868
+ const T = 't';
1869
+ const isLowerCase = char => {
1870
+ return char === char.toLowerCase();
1871
+ };
1872
+ const isUpperCase = char => {
1873
+ return char === char.toUpperCase();
1874
+ };
1875
+
1876
+ // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1877
+ const isGap = (columnCharBefore, columnChar) => {
1878
+ switch (columnCharBefore) {
1879
+ case Dash:
1880
+ case Underline:
1881
+ case EmptyString:
1882
+ case T:
1883
+ case Space:
1884
+ case Dot:
1885
+ return true;
1886
+ }
1887
+ if (isLowerCase(columnCharBefore) && isUpperCase(columnChar)) {
1888
+ return true;
1889
+ }
1890
+ return false;
1891
+ };
1892
+
1893
+ // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1894
+ const getScore = (rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, isDiagonalMatch) => {
1895
+ if (rowCharLow !== columnCharLow) {
1896
+ return -1;
1897
+ }
1898
+ const isMatch = rowChar === columnChar;
1899
+ if (isMatch) {
1900
+ if (isDiagonalMatch) {
1901
+ return 8;
1902
+ }
1903
+ if (isGap(columnCharBefore, columnChar)) {
1904
+ return 8;
1905
+ }
1906
+ return 5;
1907
+ }
1908
+ if (isGap(columnCharBefore, columnChar)) {
1909
+ return 8;
1910
+ }
1911
+ return 5;
1912
+ };
1913
+
1914
+ // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1915
+
1916
+ const isPatternInWord = (patternLow, patternPos, patternLen, wordLow, wordPos, wordLen) => {
1917
+ while (patternPos < patternLen && wordPos < wordLen) {
1918
+ if (patternLow[patternPos] === wordLow[wordPos]) {
1919
+ patternPos += 1;
1920
+ }
1921
+ wordPos += 1;
1922
+ }
1923
+ return patternPos === patternLen; // pattern must be exhausted
1924
+ };
1925
+
1926
+ // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1927
+ const traceHighlights = (table, arrows, patternLength, wordLength) => {
1928
+ let row = patternLength;
1929
+ let column = wordLength;
1930
+ const matches = [];
1931
+ while (row >= 1 && column >= 1) {
1932
+ const arrow = arrows[row][column];
1933
+ if (arrow === Left) {
1934
+ column--;
1935
+ } else if (arrow === Diagonal) {
1936
+ row--;
1937
+ column--;
1938
+ const start = column + 1;
1939
+ while (row >= 1 && column >= 1) {
1940
+ const arrow = arrows[row][column];
1941
+ if (arrow === Left) {
1942
+ break;
1943
+ }
1944
+ if (arrow === Diagonal) {
1945
+ row--;
1946
+ column--;
1947
+ }
1948
+ }
1949
+ const end = column;
1950
+ matches.unshift(end, start);
2637
1951
  }
2638
- const text = await response.blob();
2639
- return text;
2640
- } catch (error) {
2641
- throw new VError(error, `Failed to request blob for ${url}`);
2642
1952
  }
1953
+ matches.unshift(table[patternLength][wordLength - 1]);
1954
+ return matches;
2643
1955
  };
2644
1956
 
2645
- const getText = async url => {
2646
- try {
2647
- const response = await fetch(url);
2648
- if (!response.ok) {
2649
- throw new Error(response.statusText);
2650
- }
2651
- const text = await response.text();
2652
- return text;
2653
- } catch (error) {
2654
- throw new VError(error, `Failed to request text for ${url}`);
1957
+ // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
1958
+ const gridSize = 128;
1959
+ const table = createTable(gridSize);
1960
+ const arrows = createTable(gridSize);
1961
+ const fuzzySearch = (pattern, word) => {
1962
+ const patternLength = Math.min(pattern.length, gridSize - 1);
1963
+ const wordLength = Math.min(word.length, gridSize - 1);
1964
+ const patternLower = pattern.toLowerCase();
1965
+ const wordLower = word.toLowerCase();
1966
+ if (!isPatternInWord(patternLower, 0, patternLength, wordLower, 0, wordLength)) {
1967
+ return EmptyMatches;
2655
1968
  }
2656
- };
2657
-
2658
- // TODO move all of this to an extension
2659
-
2660
- const readFile = async uri => {
2661
- const fetchUri = `${assetDir}${uri}`;
2662
- const text = await getText(fetchUri);
2663
- return text;
2664
- };
2665
- const writeFile = () => {
2666
- throw new Error('not implemented');
2667
- };
2668
- const mkdir = () => {
2669
- throw new Error('not implemented');
2670
- };
2671
- const remove = () => {
2672
- throw new Error('not implemented');
2673
- };
2674
- const readDirWithFileTypes = async uri => {
2675
- const fileList = await getJson(fileMapUrl);
2676
- const dirents = [];
2677
- for (const fileUri of fileList) {
2678
- if (fileUri.startsWith(uri)) {
2679
- const rest = fileUri.slice(uri.length + 1);
2680
- if (rest.includes(Slash)) {
2681
- const name = rest.slice(0, rest.indexOf(Slash));
2682
- if (dirents.some(dirent => dirent.name === name)) {
2683
- continue;
2684
- }
2685
- dirents.push({
2686
- type: Directory$1,
2687
- name
2688
- });
1969
+ let strongMatch = false;
1970
+ for (let row = 1; row < patternLength + 1; row++) {
1971
+ const rowChar = pattern[row - 1];
1972
+ const rowCharLow = patternLower[row - 1];
1973
+ for (let column = 1; column < wordLength + 1; column++) {
1974
+ const columnChar = word[column - 1];
1975
+ const columnCharLow = wordLower[column - 1];
1976
+ const columnCharBefore = word[column - 2] || '';
1977
+ const isDiagonalMatch = arrows[row - 1][column - 1] === Diagonal;
1978
+ const score = getScore(rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, isDiagonalMatch);
1979
+ if (row === 1 && score > 5) {
1980
+ strongMatch = true;
1981
+ }
1982
+ let diagonalScore = score + table[row - 1][column - 1];
1983
+ if (isDiagonalMatch && score !== -1) {
1984
+ diagonalScore += 2;
1985
+ }
1986
+ const leftScore = table[row][column - 1];
1987
+ if (leftScore > diagonalScore) {
1988
+ table[row][column] = leftScore;
1989
+ arrows[row][column] = Left;
2689
1990
  } else {
2690
- dirents.push({
2691
- type: File$2,
2692
- name: rest
2693
- });
1991
+ table[row][column] = diagonalScore;
1992
+ arrows[row][column] = Diagonal;
2694
1993
  }
2695
1994
  }
2696
1995
  }
2697
- return dirents;
1996
+ if (!strongMatch) {
1997
+ return EmptyMatches;
1998
+ }
1999
+ const highlights = traceHighlights(table, arrows, patternLength, wordLength);
2000
+ return highlights;
2698
2001
  };
2699
- const chmod = () => {
2700
- throw new Error('[memfs] chmod not implemented');
2002
+
2003
+ const filterQuickPickItem = (pattern, word) => {
2004
+ const matches = fuzzySearch(pattern, word);
2005
+ return matches;
2701
2006
  };
2702
- const getBlob = async (uri, type) => {
2703
- const fetchUri = `${assetDir}${uri}`;
2704
- const blob = getBlob$1(fetchUri);
2705
- return blob;
2007
+
2008
+ const filterQuickPickItems = (items, value, provider) => {
2009
+ if (!value) {
2010
+ return items.map(convertToPick);
2011
+ }
2012
+ const results = [];
2013
+ for (const item of items) {
2014
+ let filterValue = '';
2015
+ if (provider) {
2016
+ filterValue = provider.getPickLabel(item);
2017
+ } else {
2018
+ filterValue = pathBaseName(item);
2019
+ }
2020
+ const matches = filterQuickPickItem(value, filterValue);
2021
+ if (matches.length > 0) {
2022
+ results.push({
2023
+ pick: item,
2024
+ matches
2025
+ });
2026
+ }
2027
+ }
2028
+ return results;
2706
2029
  };
2707
2030
 
2708
2031
  const focusIndex = async (state, index) => {
@@ -3027,292 +2350,138 @@ const handleBlur = async state => {
3027
2350
  await closeWidget(state.uid);
3028
2351
  return state;
3029
2352
  };
3030
-
3031
- const getPick = (items, index) => {
3032
- array(items);
3033
- number(index);
3034
- // if (index < state.recentPicks.length) {
3035
- // return state.recentPicks[index]
3036
- // }
3037
- // index -= state.recentPicks.length
3038
- if (index < items.length) {
3039
- return items[index].pick;
3040
- }
3041
- console.warn('no pick matching index', index);
3042
- };
3043
-
3044
- const selectIndex = async (state, index, button = /* left */0) => {
3045
- const {
3046
- minLineY,
3047
- provider,
3048
- items
3049
- } = state;
3050
- const actualIndex = index + minLineY;
3051
- const pick = getPick(items, actualIndex);
3052
- const selectPickResult = await provider.selectPick(pick, actualIndex, button);
3053
- object(selectPickResult);
3054
- string(selectPickResult.command);
3055
- const {
3056
- command
3057
- } = selectPickResult;
3058
- switch (command) {
3059
- case Hide:
3060
- await closeWidget(state.uid);
3061
- return state;
3062
- default:
3063
- return state;
3064
- }
3065
-
3066
- // TODO recent picks should be per provider
3067
- // if (!state.recentPickIds.has(pick.id)) {
3068
- // state.recentPicks.unshift(pick)
3069
- // state.recentPickIds.add(pick.id)
3070
- // }
3071
- // if (state.recentPicks.length > RECENT_PICKS_MAX_SIZE) {
3072
- // const last = state.recentPicks.pop()
3073
- // state.recentPickIds.delete(last.id)
3074
- // }
3075
- };
3076
-
3077
- const handleClickAt = (state, x, y) => {
3078
- const {
3079
- top,
3080
- headerHeight,
3081
- itemHeight
3082
- } = state;
3083
- const relativeY = y - top - headerHeight;
3084
- const index = Math.floor(relativeY / itemHeight);
3085
- return selectIndex(state, index);
3086
- };
3087
-
3088
- const getDefaultValue = uri => {
3089
- switch (uri) {
3090
- case 'quickPick://everything':
3091
- return '>';
3092
- default:
3093
- return '';
3094
- }
3095
- };
3096
-
3097
- const getColorThemeNames = async () => {
3098
- return invoke$1(/* Ajax.getJson */'ColorTheme.getColorThemeNames');
3099
- };
3100
-
3101
- const setColorTheme = id => {
3102
- return invoke$1(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
3103
- };
3104
- const getPlaceholder$3 = () => {
3105
- return selectColorTheme();
3106
- };
3107
- const getLabel$2 = () => {
3108
- return selectColorTheme();
3109
- };
3110
- const getPicks$3 = async searchValue => {
3111
- const colorThemeNames = await getColorThemeNames();
3112
- return colorThemeNames;
3113
- };
3114
- const selectPick$3 = async pick => {
3115
- await setColorTheme(/* colorThemeId */pick);
3116
- return {
3117
- command: Hide
3118
- };
3119
- };
3120
- const focusPick = async pick => {
3121
- await setColorTheme(/* colorThemeId */pick);
3122
- };
3123
- const getFilterValue$2 = value => {
3124
- return value;
3125
- };
3126
- const getNoResults$3 = () => {
3127
- return {
3128
- label: noMatchingColorThemesFound()
3129
- };
3130
- };
3131
- const getPickFilterValue$2 = pick => {
3132
- return pick;
3133
- };
3134
- const getPickLabel$2 = pick => {
3135
- return pick;
3136
- };
3137
- const getPickIcon$2 = pick => {
3138
- return '';
3139
- };
3140
-
3141
- const QuickPickEntriesColorTheme = {
3142
- __proto__: null,
3143
- focusPick,
3144
- getFilterValue: getFilterValue$2,
3145
- getLabel: getLabel$2,
3146
- getNoResults: getNoResults$3,
3147
- getPickFilterValue: getPickFilterValue$2,
3148
- getPickIcon: getPickIcon$2,
3149
- getPickLabel: getPickLabel$2,
3150
- getPicks: getPicks$3,
3151
- getPlaceholder: getPlaceholder$3,
3152
- selectPick: selectPick$3,
3153
- setColorTheme
3154
- };
3155
-
3156
- const Tag$1 = 'Tag';
3157
- const Cloud$1 = 'Cloud';
3158
- const SourceControl$1 = 'SourceControl';
3159
- const None$1 = '';
3160
-
3161
- const SourceControl = 1;
3162
- const Cloud = 2;
3163
- const Tag = 3;
3164
-
3165
- const name$1 = 'custom';
3166
- const state = {
3167
- args: []
3168
- };
3169
- const setArgs = args => {
3170
- state.args = args;
3171
- };
3172
- const getPlaceholder$2 = () => {
3173
- return '';
3174
- };
3175
- const getLabel$1 = () => {
3176
- return 'Custom';
3177
- };
3178
-
3179
- // TODO help entries should not be here
3180
- const getHelpEntries$2 = () => {
3181
- return [];
3182
- };
3183
- const getNoResults$2 = () => {
3184
- return {
3185
- label: noMatchingResults()
3186
- };
3187
- };
3188
- const getPicks$2 = async searchValue => {
3189
- const items = state.args[1] || [];
3190
- return items;
3191
- };
3192
- const selectPick$2 = async pick => {
3193
- const {
3194
- args
3195
- } = state;
3196
- const resolve = args[2];
3197
- resolve(pick);
3198
- return {
3199
- command: Hide
3200
- };
3201
- };
3202
- const getFilterValue$1 = value => {
3203
- return value;
3204
- };
3205
- const getPickFilterValue$1 = pick => {
3206
- return pick;
3207
- };
3208
- const getPickLabel$1 = pick => {
3209
- return pick.label;
3210
- };
3211
- const getPickDescription$2 = pick => {
3212
- return pick.description || '';
2353
+
2354
+ const getPick = (items, index) => {
2355
+ array(items);
2356
+ number(index);
2357
+ // if (index < state.recentPicks.length) {
2358
+ // return state.recentPicks[index]
2359
+ // }
2360
+ // index -= state.recentPicks.length
2361
+ if (index < items.length) {
2362
+ return items[index].pick;
2363
+ }
2364
+ console.warn('no pick matching index', index);
3213
2365
  };
3214
- const convertIcon = icon => {
3215
- switch (icon) {
3216
- case SourceControl:
3217
- return SourceControl$1;
3218
- case Cloud:
3219
- return Cloud$1;
3220
- case Tag:
3221
- return Tag$1;
2366
+
2367
+ const selectIndex = async (state, index, button = /* left */0) => {
2368
+ const {
2369
+ minLineY,
2370
+ provider,
2371
+ items
2372
+ } = state;
2373
+ const actualIndex = index + minLineY;
2374
+ const pick = getPick(items, actualIndex);
2375
+ const selectPickResult = await provider.selectPick(pick, actualIndex, button);
2376
+ object(selectPickResult);
2377
+ string(selectPickResult.command);
2378
+ const {
2379
+ command
2380
+ } = selectPickResult;
2381
+ switch (command) {
2382
+ case Hide:
2383
+ await closeWidget(state.uid);
2384
+ return state;
3222
2385
  default:
3223
- return None$1;
2386
+ return state;
3224
2387
  }
3225
- };
3226
- const getPickIcon$1 = pick => {
3227
- return convertIcon(pick.icon);
3228
- };
3229
2388
 
3230
- const QuickPickEntriesCustom = {
3231
- __proto__: null,
3232
- getFilterValue: getFilterValue$1,
3233
- getHelpEntries: getHelpEntries$2,
3234
- getLabel: getLabel$1,
3235
- getNoResults: getNoResults$2,
3236
- getPickDescription: getPickDescription$2,
3237
- getPickFilterValue: getPickFilterValue$1,
3238
- getPickIcon: getPickIcon$1,
3239
- getPickLabel: getPickLabel$1,
3240
- getPicks: getPicks$2,
3241
- getPlaceholder: getPlaceholder$2,
3242
- name: name$1,
3243
- selectPick: selectPick$2,
3244
- setArgs,
3245
- state
2389
+ // TODO recent picks should be per provider
2390
+ // if (!state.recentPickIds.has(pick.id)) {
2391
+ // state.recentPicks.unshift(pick)
2392
+ // state.recentPickIds.add(pick.id)
2393
+ // }
2394
+ // if (state.recentPicks.length > RECENT_PICKS_MAX_SIZE) {
2395
+ // const last = state.recentPicks.pop()
2396
+ // state.recentPickIds.delete(last.id)
2397
+ // }
3246
2398
  };
3247
2399
 
3248
- const name = 'number';
3249
- const getPlaceholder$1 = () => {
3250
- return '';
2400
+ const handleClickAt = (state, x, y) => {
2401
+ const {
2402
+ top,
2403
+ headerHeight,
2404
+ itemHeight
2405
+ } = state;
2406
+ const relativeY = y - top - headerHeight;
2407
+ const index = Math.floor(relativeY / itemHeight);
2408
+ return selectIndex(state, index);
3251
2409
  };
3252
- const getHelpEntries$1 = () => {
3253
- return [];
2410
+
2411
+ const getDefaultValue = uri => {
2412
+ switch (uri) {
2413
+ case 'quickPick://everything':
2414
+ return '>';
2415
+ default:
2416
+ return '';
2417
+ }
3254
2418
  };
3255
- const getNoResults$1 = () => {
3256
- return {
3257
- label: noMatchingResults()
3258
- };
2419
+
2420
+ const state$4 = Object.create(null);
2421
+ const register = modules => {
2422
+ Object.assign(state$4, modules);
3259
2423
  };
3260
- const getPicks$1 = async () => {
3261
- const picks = [{
3262
- label: '1'
3263
- }, {
3264
- label: '2'
3265
- }, {
3266
- label: '3'
3267
- }, {
3268
- label: '4'
3269
- }, {
3270
- label: '5'
3271
- }, {
3272
- label: '6'
3273
- }, {
3274
- label: '7'
3275
- }, {
3276
- label: '8'
3277
- }, {
3278
- label: '9'
3279
- }, {
3280
- label: '10'
3281
- }];
3282
- return picks;
2424
+ const load = moduleId => {
2425
+ const module = state$4[moduleId];
2426
+ if (!module) {
2427
+ throw new Error(`unknown module "${moduleId}"`);
2428
+ }
2429
+ return module;
3283
2430
  };
3284
- const selectPick$1 = async item => {
2431
+
2432
+ const loadContent = async state => {
2433
+ const {
2434
+ uri,
2435
+ args
2436
+ } = state;
2437
+ const value = getDefaultValue(uri);
2438
+ const provider = load(uri);
2439
+ // @ts-ignore
2440
+ if (provider.setArgs) {
2441
+ // @ts-ignore
2442
+ provider.setArgs(args);
2443
+ }
2444
+ const newPicks = await provider.getPicks(value);
2445
+ array(newPicks);
2446
+ // @ts-ignore
2447
+ const filterValue = provider.getFilterValue(value);
2448
+ const items = filterQuickPickItems(newPicks, filterValue, provider);
2449
+ // @ts-ignore
2450
+ provider.getLabel();
2451
+ const minLineY = 0;
2452
+ const maxLineY = Math.min(minLineY + state.maxVisibleItems, newPicks.length);
3285
2453
  return {
3286
- command: Hide
2454
+ ...state,
2455
+ picks: newPicks,
2456
+ items,
2457
+ focusedIndex: 0,
2458
+ state: Finished,
2459
+ minLineY,
2460
+ maxLineY,
2461
+ value,
2462
+ cursorOffset: value.length,
2463
+ provider,
2464
+ inputSource: Script,
2465
+ focused: true
3287
2466
  };
3288
2467
  };
3289
2468
 
3290
- const QuickPickEntriesNumber = {
3291
- __proto__: null,
3292
- getHelpEntries: getHelpEntries$1,
3293
- getNoResults: getNoResults$1,
3294
- getPicks: getPicks$1,
3295
- getPlaceholder: getPlaceholder$1,
3296
- name,
3297
- selectPick: selectPick$1
3298
- };
3299
-
3300
2469
  const getRecentlyOpened = () => {
3301
2470
  return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
3302
2471
  };
3303
2472
  const openWorkspaceFolder = uri => {
3304
2473
  return invoke$1(/* Workspace.setPath */'Workspace.setPath', /* path */uri);
3305
2474
  };
3306
- const getPlaceholder = () => {
2475
+ const getPlaceholder$3 = () => {
3307
2476
  return selectToOpen();
3308
2477
  };
3309
- const getLabel = () => {
2478
+ const getLabel$2 = () => {
3310
2479
  return openRecent();
3311
2480
  };
3312
- const getHelpEntries = () => {
2481
+ const getHelpEntries$3 = () => {
3313
2482
  return [];
3314
2483
  };
3315
- const getNoResults = () => {
2484
+ const getNoResults$3 = () => {
3316
2485
  return {
3317
2486
  label: noRecentlyOpenedFoldersFound()
3318
2487
  };
@@ -3323,32 +2492,32 @@ const getNoResults = () => {
3323
2492
  // This would make the code more module since the code for getting the picks
3324
2493
  // would be more independent of the specific data format of the quickpick provider
3325
2494
 
3326
- const getPicks = async () => {
2495
+ const getPicks$3 = async () => {
3327
2496
  const recentlyOpened = await getRecentlyOpened();
3328
2497
  return recentlyOpened;
3329
2498
  };
3330
2499
 
3331
2500
  // TODO selectPick should be independent of show/hide
3332
- const selectPick = async pick => {
2501
+ const selectPick$3 = async pick => {
3333
2502
  const path = pick;
3334
2503
  await openWorkspaceFolder(path);
3335
2504
  return {
3336
2505
  command: Hide
3337
2506
  };
3338
2507
  };
3339
- const getFilterValue = value => {
2508
+ const getFilterValue$3 = value => {
3340
2509
  return pathBaseName(value);
3341
2510
  };
3342
- const getPickFilterValue = pick => {
2511
+ const getPickFilterValue$3 = pick => {
3343
2512
  return pathBaseName(pick);
3344
2513
  };
3345
- const getPickLabel = pick => {
2514
+ const getPickLabel$3 = pick => {
3346
2515
  return pathBaseName(pick);
3347
2516
  };
3348
- const getPickDescription$1 = pick => {
2517
+ const getPickDescription$4 = pick => {
3349
2518
  return pathDirName(pick);
3350
2519
  };
3351
- const getPickIcon = () => {
2520
+ const getPickIcon$3 = () => {
3352
2521
  return '';
3353
2522
  };
3354
2523
  const getPickFileIcon = pick => {
@@ -3359,100 +2528,46 @@ const getPickFileIcon = pick => {
3359
2528
  pick = pick.pick;
3360
2529
  }
3361
2530
  return {
3362
- type: Directory$1,
2531
+ type: Directory,
3363
2532
  name: pick
3364
2533
  };
3365
2534
  };
2535
+ const state$3 = {};
2536
+ const isPrepared$3 = () => {
2537
+ return false;
2538
+ };
2539
+ const name$3 = '';
3366
2540
 
3367
2541
  const QuickPickEntriesOpenRecent = {
3368
2542
  __proto__: null,
3369
- getFilterValue,
3370
- getHelpEntries,
3371
- getLabel,
3372
- getNoResults,
3373
- getPickDescription: getPickDescription$1,
2543
+ getFilterValue: getFilterValue$3,
2544
+ getHelpEntries: getHelpEntries$3,
2545
+ getLabel: getLabel$2,
2546
+ getNoResults: getNoResults$3,
2547
+ getPickDescription: getPickDescription$4,
3374
2548
  getPickFileIcon,
3375
- getPickFilterValue,
3376
- getPickIcon,
3377
- getPickLabel,
3378
- getPicks,
3379
- getPlaceholder,
3380
- selectPick
2549
+ getPickFilterValue: getPickFilterValue$3,
2550
+ getPickIcon: getPickIcon$3,
2551
+ getPickLabel: getPickLabel$3,
2552
+ getPicks: getPicks$3,
2553
+ getPlaceholder: getPlaceholder$3,
2554
+ isPrepared: isPrepared$3,
2555
+ name: name$3,
2556
+ selectPick: selectPick$3,
2557
+ state: state$3
3381
2558
  };
3382
2559
 
3383
2560
  const CommandPalette = 'quickPick://commandPalette';
3384
2561
  const Commands = 'quickPick://commands';
3385
- const File = 'quickPick://file';
2562
+ const File$1 = 'quickPick://file';
3386
2563
  const EveryThing = 'quickPick://everything';
3387
2564
  const Number$1 = 'quickPick://number';
3388
2565
  const Recent = 'quickPick://recent';
3389
- const ColorTheme = 'quickPick://color-theme';
3390
- const Symbol$1 = 'quickPick://symbol';
3391
- const View = 'quickPick://view';
3392
- const WorkspaceSymbol = 'quickPick://workspace-symbol';
3393
- const Custom = 'quickPick://custom';
3394
-
3395
- const load = moduleId => {
3396
- switch (moduleId) {
3397
- case CommandPalette:
3398
- case Commands:
3399
- case File:
3400
- case EveryThing:
3401
- case WorkspaceSymbol:
3402
- return QuickPickEntriesEverything;
3403
- case Number$1:
3404
- return QuickPickEntriesNumber;
3405
- case Recent:
3406
- return QuickPickEntriesOpenRecent;
3407
- case ColorTheme:
3408
- return QuickPickEntriesColorTheme;
3409
- case Symbol$1:
3410
- return QuickPickEntriesSymbol;
3411
- case View:
3412
- return QuickPickEntriesView;
3413
- case Custom:
3414
- return QuickPickEntriesCustom;
3415
- default:
3416
- throw new Error(`unknown module "${moduleId}"`);
3417
- }
3418
- };
3419
-
3420
- const loadContent = async state => {
3421
- const {
3422
- uri,
3423
- args
3424
- } = state;
3425
- const value = getDefaultValue(uri);
3426
- const provider = await load(uri);
3427
- // @ts-ignore
3428
- if (provider.setArgs) {
3429
- // @ts-ignore
3430
- provider.setArgs(args);
3431
- }
3432
- const newPicks = await provider.getPicks(value);
3433
- array(newPicks);
3434
- // @ts-ignore
3435
- const filterValue = provider.getFilterValue(value);
3436
- const items = filterQuickPickItems(newPicks, filterValue, provider);
3437
- // @ts-ignore
3438
- provider.getLabel();
3439
- const minLineY = 0;
3440
- const maxLineY = Math.min(minLineY + state.maxVisibleItems, newPicks.length);
3441
- return {
3442
- ...state,
3443
- picks: newPicks,
3444
- items,
3445
- focusedIndex: 0,
3446
- state: Finished,
3447
- minLineY,
3448
- maxLineY,
3449
- value,
3450
- cursorOffset: value.length,
3451
- provider,
3452
- inputSource: Script,
3453
- focused: true
3454
- };
3455
- };
2566
+ const ColorTheme = 'quickPick://color-theme';
2567
+ const Symbol = 'quickPick://symbol';
2568
+ const View = 'quickPick://view';
2569
+ const WorkspaceSymbol = 'quickPick://workspace-symbol';
2570
+ const Custom = 'quickPick://custom';
3456
2571
 
3457
2572
  const loadQuickPickEntries = moduleId => {
3458
2573
  switch (moduleId) {
@@ -3491,7 +2606,7 @@ const requestFileIcons = async requests => {
3491
2606
  return Promise.all(promises);
3492
2607
  };
3493
2608
 
3494
- const getPickDescription = (provider, pick) => {
2609
+ const getPickDescription$3 = (provider, pick) => {
3495
2610
  if (provider.getPickDescription) {
3496
2611
  return provider.getPickDescription(pick);
3497
2612
  }
@@ -3508,7 +2623,7 @@ const getVisible = async (provider, items, minLineY, maxLineY, focusedIndex) =>
3508
2623
  const item = items[i];
3509
2624
  const pick = item.pick;
3510
2625
  const label = provider.getPickLabel(pick);
3511
- const description = getPickDescription(provider, pick);
2626
+ const description = getPickDescription$3(provider, pick);
3512
2627
  const icon = provider.getPickIcon(pick);
3513
2628
  const fileIcon = icons[iconIndex++];
3514
2629
  visibleItems.push({
@@ -3584,7 +2699,7 @@ const QuickPickItemActive = 'QuickPickItemActive';
3584
2699
  const QuickPickItemDescription = 'QuickPickItemDescription';
3585
2700
  const QuickPickItemLabel = 'QuickPickItemLabel';
3586
2701
 
3587
- const None = 'none';
2702
+ const None$1 = 'none';
3588
2703
  const Option = 'option';
3589
2704
 
3590
2705
  const Div = 4;
@@ -3597,7 +2712,7 @@ const getFileIconVirtualDom = icon => {
3597
2712
  type: Img,
3598
2713
  className: FileIcon,
3599
2714
  src: icon,
3600
- role: None,
2715
+ role: None$1,
3601
2716
  childCount: 0
3602
2717
  };
3603
2718
  };
@@ -3707,176 +2822,485 @@ const getQuickPickItemsVirtualDom = visibleItems => {
3707
2822
  const dom = visibleItems.flatMap(getQuickPickItemVirtualDom);
3708
2823
  return dom;
3709
2824
  };
3710
-
3711
- const renderItems = newState => {
3712
- const dom = getQuickPickItemsVirtualDom(newState.visibleItems);
3713
- return ['Viewlet.send', newState.uid, /* method */'setItemsDom', dom];
2825
+
2826
+ const renderItems = newState => {
2827
+ const dom = getQuickPickItemsVirtualDom(newState.visibleItems);
2828
+ return ['Viewlet.send', newState.uid, /* method */'setItemsDom', dom];
2829
+ };
2830
+
2831
+ const renderValue = newState => {
2832
+ return ['Viewlet.send', newState.uid, /* method */SetValue, /* value */newState.value];
2833
+ };
2834
+
2835
+ const getRenderer = diffType => {
2836
+ switch (diffType) {
2837
+ case RenderValue:
2838
+ return renderValue;
2839
+ case RenderCursorOffset:
2840
+ return renderCursorOffset;
2841
+ case RenderItems:
2842
+ return renderItems;
2843
+ case RenderFocusedIndex:
2844
+ return renderFocusedIndex;
2845
+ case Height:
2846
+ return renderHeight;
2847
+ case RenderFocus:
2848
+ return renderFocus;
2849
+ default:
2850
+ throw new Error('unknown renderer');
2851
+ }
2852
+ };
2853
+
2854
+ const applyRender = async (oldState, newState, diffResult) => {
2855
+ const commands = [];
2856
+ const viewModel = await createQuickPickViewModel(oldState, newState);
2857
+ for (const item of diffResult) {
2858
+ const fn = getRenderer(item);
2859
+ commands.push(fn(viewModel));
2860
+ }
2861
+ return commands;
2862
+ };
2863
+
2864
+ const diffType$4 = RenderFocus;
2865
+ const isEqual$4 = (oldState, newState) => {
2866
+ return oldState.focused === newState.focused;
2867
+ };
2868
+
2869
+ const diffType$3 = RenderFocusedIndex;
2870
+ const isEqual$3 = (oldState, newState) => {
2871
+ return oldState.focusedIndex === newState.focusedIndex;
2872
+ };
2873
+
2874
+ const diffType$2 = Height;
2875
+ const isEqual$2 = (oldState, newState) => {
2876
+ return oldState.items.length === newState.items.length;
2877
+ };
2878
+
2879
+ const diffType$1 = RenderItems;
2880
+ const isEqual$1 = (oldState, newState) => {
2881
+ return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex;
2882
+ };
2883
+
2884
+ const diffType = RenderValue;
2885
+ const isEqual = (oldState, newState) => {
2886
+ return newState.inputSource === User || oldState.value === newState.value;
2887
+ };
2888
+
2889
+ const modules = [isEqual$2, isEqual$1, isEqual$4, isEqual, isEqual$3];
2890
+ const numbers = [diffType$2, diffType$1, diffType$4, diffType, diffType$3];
2891
+
2892
+ const diff = (oldState, newState) => {
2893
+ const diffResult = [];
2894
+ for (let i = 0; i < modules.length; i++) {
2895
+ const fn = modules[i];
2896
+ if (!fn(oldState, newState)) {
2897
+ diffResult.push(numbers[i]);
2898
+ }
2899
+ }
2900
+ return diffResult;
2901
+ };
2902
+
2903
+ const doRender = async uid => {
2904
+ const {
2905
+ oldState,
2906
+ newState
2907
+ } = get(uid);
2908
+ const diffResult = diff(oldState, newState);
2909
+ return applyRender(oldState, newState, diffResult);
2910
+ };
2911
+
2912
+ const selectCurrentIndex = state => {
2913
+ return selectIndex(state, state.focusedIndex);
2914
+ };
2915
+
2916
+ const findLabelIndex = (items, label) => {
2917
+ for (let i = 0; i < items.length; i++) {
2918
+ if (items[i].pick.label === label) {
2919
+ return i;
2920
+ }
2921
+ }
2922
+ return -1;
2923
+ };
2924
+
2925
+ const selectItem = async (state, label) => {
2926
+ string(label);
2927
+ const index = findLabelIndex(state.items, label);
2928
+ if (index === -1) {
2929
+ return state;
2930
+ }
2931
+ return selectIndex(state, index);
2932
+ };
2933
+
2934
+ const wrapCommand = fn => {
2935
+ const wrapped = async (uid, ...args) => {
2936
+ const {
2937
+ newState
2938
+ } = get(uid);
2939
+ const newerState = await fn(newState, ...args);
2940
+ set(uid, newState, newerState);
2941
+ };
2942
+ return wrapped;
2943
+ };
2944
+
2945
+ const commandMap = {
2946
+ 'QuickPick.addMenuEntries': add,
2947
+ 'QuickPick.create2': create$1,
2948
+ 'QuickPick.focusFirst': wrapCommand(focusFirst),
2949
+ 'QuickPick.focusIndex': wrapCommand(focusIndex),
2950
+ 'QuickPick.focusLast': wrapCommand(focusLast),
2951
+ 'QuickPick.focusNext': wrapCommand(focusNext),
2952
+ 'QuickPick.focusPrevious': wrapCommand(focusPrevious),
2953
+ 'QuickPick.getCommandIds': getCommandIds,
2954
+ 'QuickPick.getKeyBindings': getKeyBindings,
2955
+ 'QuickPick.handleBeforeInput': wrapCommand(handleBeforeInput),
2956
+ 'QuickPick.handleBlur': wrapCommand(handleBlur),
2957
+ 'QuickPick.handleClickAt': wrapCommand(handleClickAt),
2958
+ 'QuickPick.handleInput': wrapCommand(handleInput),
2959
+ 'QuickPick.handleWheel': wrapCommand(handleWheel),
2960
+ 'QuickPick.loadContent': wrapCommand(loadContent),
2961
+ 'QuickPick.loadEntries2': load,
2962
+ 'QuickPick.render': doRender,
2963
+ 'QuickPick.selectCurrentIndex': wrapCommand(selectCurrentIndex),
2964
+ 'QuickPick.selectIndex': wrapCommand(selectIndex),
2965
+ 'QuickPick.selectItem': wrapCommand(selectItem),
2966
+ 'QuickPick.setDeltaY': wrapCommand(setDeltaY),
2967
+ 'QuickPick.setValue': wrapCommand(setValue),
2968
+ // deprecated
2969
+ 'SearchFile.filter': filterQuickPickItems,
2970
+ 'SearchFile.searchFile': searchFile$5,
2971
+ 'QuickPick.create': create,
2972
+ 'QuickPick.loadEntries': loadQuickPickEntries
2973
+ };
2974
+
2975
+ const getColorThemeNames = async () => {
2976
+ return invoke$1(/* Ajax.getJson */'ColorTheme.getColorThemeNames');
2977
+ };
2978
+
2979
+ const setColorTheme = id => {
2980
+ return invoke$1(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
2981
+ };
2982
+ const getPlaceholder$2 = () => {
2983
+ return selectColorTheme();
2984
+ };
2985
+ const getLabel$1 = () => {
2986
+ return selectColorTheme();
2987
+ };
2988
+ const getPicks$2 = async searchValue => {
2989
+ const colorThemeNames = await getColorThemeNames();
2990
+ return colorThemeNames;
2991
+ };
2992
+ const selectPick$2 = async pick => {
2993
+ await setColorTheme(/* colorThemeId */pick);
2994
+ return {
2995
+ command: Hide
2996
+ };
2997
+ };
2998
+ const focusPick = async pick => {
2999
+ await setColorTheme(/* colorThemeId */pick);
3000
+ };
3001
+ const getFilterValue$2 = value => {
3002
+ return value;
3003
+ };
3004
+ const getNoResults$2 = () => {
3005
+ return {
3006
+ label: noMatchingColorThemesFound()
3007
+ };
3008
+ };
3009
+ const getPickFilterValue$2 = pick => {
3010
+ return pick;
3011
+ };
3012
+ const getPickLabel$2 = pick => {
3013
+ return pick;
3014
+ };
3015
+ const getPickIcon$2 = pick => {
3016
+ return '';
3017
+ };
3018
+ const state$2 = {};
3019
+ const getPickDescription$2 = value => {
3020
+ return '';
3021
+ };
3022
+ const isPrepared$2 = () => {
3023
+ return false;
3024
+ };
3025
+ const name$2 = '';
3026
+ const getHelpEntries$2 = () => {
3027
+ return [];
3028
+ };
3029
+
3030
+ const QuickPickEntriesColorTheme = {
3031
+ __proto__: null,
3032
+ focusPick,
3033
+ getFilterValue: getFilterValue$2,
3034
+ getHelpEntries: getHelpEntries$2,
3035
+ getLabel: getLabel$1,
3036
+ getNoResults: getNoResults$2,
3037
+ getPickDescription: getPickDescription$2,
3038
+ getPickFilterValue: getPickFilterValue$2,
3039
+ getPickIcon: getPickIcon$2,
3040
+ getPickLabel: getPickLabel$2,
3041
+ getPicks: getPicks$2,
3042
+ getPlaceholder: getPlaceholder$2,
3043
+ isPrepared: isPrepared$2,
3044
+ name: name$2,
3045
+ selectPick: selectPick$2,
3046
+ setColorTheme,
3047
+ state: state$2
3048
+ };
3049
+
3050
+ const Tag$1 = 'Tag';
3051
+ const Cloud$1 = 'Cloud';
3052
+ const SourceControl$1 = 'SourceControl';
3053
+ const None = '';
3054
+
3055
+ const SourceControl = 1;
3056
+ const Cloud = 2;
3057
+ const Tag = 3;
3058
+
3059
+ const name$1 = 'custom';
3060
+ const state$1 = {
3061
+ args: []
3062
+ };
3063
+ const setArgs = args => {
3064
+ state$1.args = args;
3065
+ };
3066
+ const getPlaceholder$1 = () => {
3067
+ return '';
3068
+ };
3069
+ const getLabel = () => {
3070
+ return 'Custom';
3071
+ };
3072
+
3073
+ // TODO help entries should not be here
3074
+ const getHelpEntries$1 = () => {
3075
+ return [];
3076
+ };
3077
+ const getNoResults$1 = () => {
3078
+ return {
3079
+ label: noMatchingResults()
3080
+ };
3081
+ };
3082
+ const getPicks$1 = async searchValue => {
3083
+ const items = state$1.args[1] || [];
3084
+ return items;
3085
+ };
3086
+ const selectPick$1 = async pick => {
3087
+ const {
3088
+ args
3089
+ } = state$1;
3090
+ const resolve = args[2];
3091
+ resolve(pick);
3092
+ return {
3093
+ command: Hide
3094
+ };
3095
+ };
3096
+ const getFilterValue$1 = value => {
3097
+ return value;
3714
3098
  };
3715
-
3716
- const renderValue = newState => {
3717
- return ['Viewlet.send', newState.uid, /* method */SetValue, /* value */newState.value];
3099
+ const getPickFilterValue$1 = pick => {
3100
+ return pick;
3718
3101
  };
3719
-
3720
- const getRenderer = diffType => {
3721
- switch (diffType) {
3722
- case RenderValue:
3723
- return renderValue;
3724
- case RenderCursorOffset:
3725
- return renderCursorOffset;
3726
- case RenderItems:
3727
- return renderItems;
3728
- case RenderFocusedIndex:
3729
- return renderFocusedIndex;
3730
- case Height:
3731
- return renderHeight;
3732
- case RenderFocus:
3733
- return renderFocus;
3102
+ const getPickLabel$1 = pick => {
3103
+ return pick.label;
3104
+ };
3105
+ const getPickDescription$1 = pick => {
3106
+ return pick.description || '';
3107
+ };
3108
+ const convertIcon = icon => {
3109
+ switch (icon) {
3110
+ case SourceControl:
3111
+ return SourceControl$1;
3112
+ case Cloud:
3113
+ return Cloud$1;
3114
+ case Tag:
3115
+ return Tag$1;
3734
3116
  default:
3735
- throw new Error('unknown renderer');
3117
+ return None;
3736
3118
  }
3737
3119
  };
3738
-
3739
- const applyRender = async (oldState, newState, diffResult) => {
3740
- const commands = [];
3741
- const viewModel = await createQuickPickViewModel(oldState, newState);
3742
- for (const item of diffResult) {
3743
- const fn = getRenderer(item);
3744
- commands.push(fn(viewModel));
3745
- }
3746
- return commands;
3120
+ const getPickIcon$1 = pick => {
3121
+ return convertIcon(pick.icon);
3747
3122
  };
3748
-
3749
- const diffType$4 = RenderFocus;
3750
- const isEqual$4 = (oldState, newState) => {
3751
- return oldState.focused === newState.focused;
3123
+ const isPrepared$1 = () => {
3124
+ return true;
3752
3125
  };
3753
3126
 
3754
- const diffType$3 = RenderFocusedIndex;
3755
- const isEqual$3 = (oldState, newState) => {
3756
- return oldState.focusedIndex === newState.focusedIndex;
3127
+ const QuickPickEntriesCustom = {
3128
+ __proto__: null,
3129
+ getFilterValue: getFilterValue$1,
3130
+ getHelpEntries: getHelpEntries$1,
3131
+ getLabel,
3132
+ getNoResults: getNoResults$1,
3133
+ getPickDescription: getPickDescription$1,
3134
+ getPickFilterValue: getPickFilterValue$1,
3135
+ getPickIcon: getPickIcon$1,
3136
+ getPickLabel: getPickLabel$1,
3137
+ getPicks: getPicks$1,
3138
+ getPlaceholder: getPlaceholder$1,
3139
+ isPrepared: isPrepared$1,
3140
+ name: name$1,
3141
+ selectPick: selectPick$1,
3142
+ setArgs,
3143
+ state: state$1
3757
3144
  };
3758
3145
 
3759
- const diffType$2 = Height;
3760
- const isEqual$2 = (oldState, newState) => {
3761
- return oldState.items.length === newState.items.length;
3146
+ const name = 'number';
3147
+ const getPlaceholder = () => {
3148
+ return '';
3149
+ };
3150
+ const getHelpEntries = () => {
3151
+ return [];
3152
+ };
3153
+ const getNoResults = () => {
3154
+ return {
3155
+ label: noMatchingResults()
3156
+ };
3157
+ };
3158
+ const getPicks = async () => {
3159
+ const picks = [{
3160
+ label: '1'
3161
+ }, {
3162
+ label: '2'
3163
+ }, {
3164
+ label: '3'
3165
+ }, {
3166
+ label: '4'
3167
+ }, {
3168
+ label: '5'
3169
+ }, {
3170
+ label: '6'
3171
+ }, {
3172
+ label: '7'
3173
+ }, {
3174
+ label: '8'
3175
+ }, {
3176
+ label: '9'
3177
+ }, {
3178
+ label: '10'
3179
+ }];
3180
+ return picks;
3181
+ };
3182
+ const selectPick = async item => {
3183
+ return {
3184
+ command: Hide
3185
+ };
3186
+ };
3187
+ const state = {};
3188
+ const getPickFilterValue = value => {
3189
+ return value;
3190
+ };
3191
+ const getFilterValue = value => {
3192
+ return value;
3193
+ };
3194
+ const getPickDescription = value => {
3195
+ return '';
3196
+ };
3197
+ const getPickLabel = value => {
3198
+ return value;
3199
+ };
3200
+ const getPickIcon = value => {
3201
+ return '';
3202
+ };
3203
+ const isPrepared = () => {
3204
+ return false;
3762
3205
  };
3763
3206
 
3764
- const diffType$1 = RenderItems;
3765
- const isEqual$1 = (oldState, newState) => {
3766
- return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex;
3207
+ const QuickPickEntriesNumber = {
3208
+ __proto__: null,
3209
+ getFilterValue,
3210
+ getHelpEntries,
3211
+ getNoResults,
3212
+ getPickDescription,
3213
+ getPickFilterValue,
3214
+ getPickIcon,
3215
+ getPickLabel,
3216
+ getPicks,
3217
+ getPlaceholder,
3218
+ isPrepared,
3219
+ name,
3220
+ selectPick,
3221
+ state
3767
3222
  };
3768
3223
 
3769
- const diffType = RenderValue;
3770
- const isEqual = (oldState, newState) => {
3771
- return newState.inputSource === User || oldState.value === newState.value;
3224
+ const quickPickEntriesModules = {
3225
+ [CommandPalette]: QuickPickEntriesEverything,
3226
+ [Commands]: QuickPickEntriesEverything,
3227
+ [File$1]: QuickPickEntriesEverything,
3228
+ [EveryThing]: QuickPickEntriesEverything,
3229
+ [WorkspaceSymbol]: QuickPickEntriesEverything,
3230
+ [Number$1]: QuickPickEntriesNumber,
3231
+ [Recent]: QuickPickEntriesOpenRecent,
3232
+ [ColorTheme]: QuickPickEntriesColorTheme,
3233
+ [Symbol]: QuickPickEntriesSymbol,
3234
+ [View]: QuickPickEntriesView,
3235
+ [Custom]: QuickPickEntriesCustom
3772
3236
  };
3773
3237
 
3774
- const modules = [isEqual$2, isEqual$1, isEqual$4, isEqual, isEqual$3];
3775
- const numbers = [diffType$2, diffType$1, diffType$4, diffType, diffType$3];
3238
+ const Memfs = 'memfs';
3239
+ const Html = 'html';
3240
+ const Fetch = 'fetch';
3241
+ const File = 'file';
3242
+ const Default = '';
3776
3243
 
3777
- const diff = (oldState, newState) => {
3778
- const diffResult = [];
3779
- for (let i = 0; i < modules.length; i++) {
3780
- const fn = modules[i];
3781
- if (!fn(oldState, newState)) {
3782
- diffResult.push(numbers[i]);
3783
- }
3784
- }
3785
- return diffResult;
3244
+ const searchFile$3 = async uri => {
3245
+ return invoke$1('ExtensionHost.searchFileWithMemory', uri);
3786
3246
  };
3787
3247
 
3788
- const doRender = async uid => {
3789
- const {
3790
- oldState,
3791
- newState
3792
- } = get(uid);
3793
- const diffResult = diff(oldState, newState);
3794
- return applyRender(oldState, newState, diffResult);
3248
+ // TODO simplify code
3249
+ // 1. don't have playground prefix in fileMap json
3250
+ // 2. remove code here that removes the prefix
3251
+ const searchFile$2 = async path => {
3252
+ return invoke$1('ExtensionHost.searchFileWithFetch', path);
3795
3253
  };
3796
3254
 
3797
- const selectCurrentIndex = state => {
3798
- return selectIndex(state, state.focusedIndex);
3255
+ const searchFile$1 = async uri => {
3256
+ return invoke$1('ExtensionHost.searchFileWithHtml', uri);
3799
3257
  };
3800
3258
 
3801
- const findLabelIndex = (items, label) => {
3802
- for (let i = 0; i < items.length; i++) {
3803
- if (items[i].pick.label === label) {
3804
- return i;
3805
- }
3806
- }
3807
- return -1;
3259
+ const getFileSearchRipGrepArgs = () => {
3260
+ const ripGrepArgs = ['--files', '--sort-files'];
3261
+ return ripGrepArgs;
3808
3262
  };
3809
3263
 
3810
- const selectItem = async (state, label) => {
3811
- string(label);
3812
- const index = findLabelIndex(state.items, label);
3813
- if (index === -1) {
3814
- return state;
3264
+ const invoke = (method, ...params) => {
3265
+ return invoke$1('SearchProcess.invoke', method, ...params);
3266
+ };
3267
+
3268
+ const splitLines = lines => {
3269
+ if (!lines) {
3270
+ return [];
3815
3271
  }
3816
- return selectIndex(state, index);
3272
+ return lines.split('\n');
3817
3273
  };
3818
3274
 
3819
- const wrapCommand = fn => {
3820
- const wrapped = async (uid, ...args) => {
3821
- const {
3822
- newState
3823
- } = get(uid);
3824
- const newerState = await fn(newState, ...args);
3825
- set(uid, newState, newerState);
3275
+ // TODO create direct connection from electron to file search worker using message ports
3276
+
3277
+ const searchFile = async (path, value, prepare) => {
3278
+ const ripGrepArgs = getFileSearchRipGrepArgs();
3279
+ const options = {
3280
+ ripGrepArgs,
3281
+ searchPath: path,
3282
+ limit: 9_999_999
3826
3283
  };
3827
- return wrapped;
3284
+ const stdout = await invoke('SearchFile.searchFile', options);
3285
+ const lines = splitLines(stdout);
3286
+ if (!prepare) {
3287
+ return lines;
3288
+ }
3289
+ const filtered = filterQuickPickItems(lines, value);
3290
+ return filtered;
3828
3291
  };
3829
3292
 
3830
- const commandMap = {
3831
- 'QuickPick.addMenuEntries': add,
3832
- 'QuickPick.create2': create$1,
3833
- 'QuickPick.focusFirst': wrapCommand(focusFirst),
3834
- 'QuickPick.focusIndex': wrapCommand(focusIndex),
3835
- 'QuickPick.focusLast': wrapCommand(focusLast),
3836
- 'QuickPick.focusNext': wrapCommand(focusNext),
3837
- 'QuickPick.focusPrevious': wrapCommand(focusPrevious),
3838
- 'QuickPick.getCommandIds': getCommandIds,
3839
- 'QuickPick.getKeyBindings': getKeyBindings,
3840
- 'QuickPick.handleBeforeInput': wrapCommand(handleBeforeInput),
3841
- 'QuickPick.handleBlur': wrapCommand(handleBlur),
3842
- 'QuickPick.handleClickAt': wrapCommand(handleClickAt),
3843
- 'QuickPick.handleInput': wrapCommand(handleInput),
3844
- 'QuickPick.handleWheel': wrapCommand(handleWheel),
3845
- 'QuickPick.loadContent': wrapCommand(loadContent),
3846
- 'QuickPick.loadEntries2': load,
3847
- 'QuickPick.render': doRender,
3848
- 'QuickPick.selectCurrentIndex': wrapCommand(selectCurrentIndex),
3849
- 'QuickPick.selectIndex': wrapCommand(selectIndex),
3850
- 'QuickPick.selectItem': wrapCommand(selectItem),
3851
- 'QuickPick.setDeltaY': wrapCommand(setDeltaY),
3852
- 'QuickPick.setValue': wrapCommand(setValue),
3853
- 'SearchFile.filter': filterQuickPickItems,
3854
- 'SearchFile.searchFile': searchFile$1,
3855
- 'SearchFile.searchFileWithFetch': searchFile$4,
3856
- 'SearchFile.searchFileWithHtml': searchFile$3,
3857
- 'SearchFile.searchFileWithRipGrep': searchFile$2,
3858
- // deprecated
3859
- 'QuickPick.create': create,
3860
- 'QuickPick.loadEntries': loadQuickPickEntries,
3861
- 'FileSystemFetch.chmod': chmod,
3862
- 'FileSystemFetch.getBlob': getBlob,
3863
- 'FileSystemFetch.mkdir': mkdir,
3864
- 'FileSystemFetch.readDirWithFileTypes': readDirWithFileTypes,
3865
- 'FileSystemFetch.readFile': readFile,
3866
- 'FileSystemFetch.remove': remove,
3867
- 'FileSystemFetch.writeFile': writeFile,
3868
- 'FileSystemMemory.chmod': chmod$1,
3869
- 'FileSystemMemory.getBlob': getBlob$2,
3870
- 'FileSystemMemory.getBlobUrl': getBlobUrl,
3871
- 'FileSystemMemory.getFiles': getFiles,
3872
- 'FileSystemMemory.mkdir': mkdir$1,
3873
- 'FileSystemMemory.readDirWithFileTypes': readDirWithFileTypes$1,
3874
- 'FileSystemMemory.readFile': readFile$1,
3875
- 'FileSystemMemory.remove': remove$1,
3876
- 'FileSystemMemory.writeFile': writeFile$1
3293
+ const searchModules = {
3294
+ [Memfs]: searchFile$3,
3295
+ [Fetch]: searchFile$2,
3296
+ [Html]: searchFile$1,
3297
+ [File]: searchFile,
3298
+ [Default]: searchFile
3877
3299
  };
3878
3300
 
3879
3301
  const listen = async () => {
3302
+ register$1(searchModules);
3303
+ register(quickPickEntriesModules);
3880
3304
  const rpc = await WebWorkerRpcClient.create({
3881
3305
  commandMap: commandMap
3882
3306
  });