@lvce-editor/quick-pick-worker 4.1.0 → 4.3.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.
@@ -1088,7 +1088,7 @@ const createMockRpc = ({
1088
1088
  };
1089
1089
 
1090
1090
  const rpcs = Object.create(null);
1091
- const set$5 = (id, rpc) => {
1091
+ const set$6 = (id, rpc) => {
1092
1092
  rpcs[id] = rpc;
1093
1093
  };
1094
1094
  const get$2 = id => {
@@ -1121,7 +1121,7 @@ const create$4 = rpcId => {
1121
1121
  const mockRpc = createMockRpc({
1122
1122
  commandMap
1123
1123
  });
1124
- set$5(rpcId, mockRpc);
1124
+ set$6(rpcId, mockRpc);
1125
1125
  // @ts-ignore
1126
1126
  mockRpc[Symbol.dispose] = () => {
1127
1127
  remove$1(rpcId);
@@ -1130,7 +1130,7 @@ const create$4 = rpcId => {
1130
1130
  return mockRpc;
1131
1131
  },
1132
1132
  set(rpc) {
1133
- set$5(rpcId, rpc);
1133
+ set$6(rpcId, rpc);
1134
1134
  }
1135
1135
  };
1136
1136
  };
@@ -1143,6 +1143,7 @@ const Img = 17;
1143
1143
  const Reference = 100;
1144
1144
 
1145
1145
  const EditorWorker = 99;
1146
+ const ExtensionManagementWorker = 9006;
1146
1147
  const RendererWorker = 1;
1147
1148
 
1148
1149
  const SetDom2 = 'Viewlet.setDom2';
@@ -1151,14 +1152,22 @@ const SetPatches = 'Viewlet.setPatches';
1151
1152
  const FocusQuickPickInput = 20;
1152
1153
 
1153
1154
  const {
1154
- invoke: invoke$3,
1155
- set: set$4
1155
+ invoke: invoke$4,
1156
+ set: set$5
1156
1157
  } = create$4(EditorWorker);
1157
1158
  const getLines = async editorUid => {
1158
- const lines = await invoke$3('Editor.getLines2', editorUid);
1159
+ const lines = await invoke$4('Editor.getLines2', editorUid);
1159
1160
  return lines;
1160
1161
  };
1161
1162
 
1163
+ const {
1164
+ invoke: invoke$3,
1165
+ set: set$4
1166
+ } = create$4(ExtensionManagementWorker);
1167
+ const getLanguages = (platform, assetDir) => {
1168
+ return invoke$3('Extensions.getLanguages', platform, assetDir);
1169
+ };
1170
+
1162
1171
  const {
1163
1172
  invoke: invoke$2,
1164
1173
  set: set$3
@@ -1192,6 +1201,10 @@ const sendMessagePortToFileSearchWorker2 = async (port, rpcId = 0) => {
1192
1201
  const getActiveEditorId = () => {
1193
1202
  return invoke$1('GetActiveEditor.getActiveEditorId');
1194
1203
  };
1204
+ const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
1205
+ const command = 'Extensions.handleMessagePort';
1206
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
1207
+ };
1195
1208
  const openUri$1 = async (uri, focus, options) => {
1196
1209
  await invoke$1('Main.openUri', uri, focus, options);
1197
1210
  };
@@ -1239,6 +1252,7 @@ const Recent$1 = 7;
1239
1252
  const Symbol$3 = 8;
1240
1253
  const View$3 = 9;
1241
1254
  const WorkspaceSymbol$2 = 10;
1255
+ const LanguageMode$1 = 11;
1242
1256
  const EveryThing$1 = 100;
1243
1257
 
1244
1258
  const getCancelResult$1 = args => {
@@ -1290,6 +1304,18 @@ const toCommandId = key => {
1290
1304
  const create$2 = () => {
1291
1305
  const states = Object.create(null);
1292
1306
  const commandMapRef = {};
1307
+ const updateState = (uid, updater) => {
1308
+ const current = states[uid];
1309
+ const updatedState = updater(current.newState);
1310
+ if (updatedState !== current.newState) {
1311
+ states[uid] = {
1312
+ newState: updatedState,
1313
+ oldState: current.oldState,
1314
+ scheduledState: updatedState
1315
+ };
1316
+ }
1317
+ return Promise.resolve(updatedState);
1318
+ };
1293
1319
  return {
1294
1320
  clear() {
1295
1321
  for (const key of Object.keys(states)) {
@@ -1298,13 +1324,13 @@ const create$2 = () => {
1298
1324
  },
1299
1325
  diff(uid, modules, numbers) {
1300
1326
  const {
1301
- newState,
1302
- oldState
1327
+ oldState,
1328
+ scheduledState
1303
1329
  } = states[uid];
1304
1330
  const diffResult = [];
1305
1331
  for (let i = 0; i < modules.length; i++) {
1306
1332
  const fn = modules[i];
1307
- if (!fn(oldState, newState)) {
1333
+ if (!fn(oldState, scheduledState)) {
1308
1334
  diffResult.push(numbers[i]);
1309
1335
  }
1310
1336
  }
@@ -1322,19 +1348,28 @@ const create$2 = () => {
1322
1348
  return ids;
1323
1349
  },
1324
1350
  getKeys() {
1325
- return Object.keys(states).map(key => {
1326
- return Number.parseFloat(key);
1327
- });
1351
+ return Object.keys(states).map(Number);
1328
1352
  },
1329
1353
  registerCommands(commandMap) {
1330
1354
  Object.assign(commandMapRef, commandMap);
1331
1355
  },
1332
- set(uid, oldState, newState) {
1356
+ set(uid, oldState, newState, scheduledState) {
1333
1357
  states[uid] = {
1334
1358
  newState,
1335
- oldState
1359
+ oldState,
1360
+ scheduledState: scheduledState ?? newState
1336
1361
  };
1337
1362
  },
1363
+ wrapAsyncCommand(fn) {
1364
+ const wrapped = async (uid, ...args) => {
1365
+ const context = {
1366
+ getState: () => states[uid].newState,
1367
+ updateState: updater => updateState(uid, updater)
1368
+ };
1369
+ await fn(context, ...args);
1370
+ };
1371
+ return wrapped;
1372
+ },
1338
1373
  wrapCommand(fn) {
1339
1374
  const wrapped = async (uid, ...args) => {
1340
1375
  const {
@@ -1352,7 +1387,8 @@ const create$2 = () => {
1352
1387
  };
1353
1388
  states[uid] = {
1354
1389
  newState: latestNew,
1355
- oldState: latestOld.oldState
1390
+ oldState: latestOld.oldState,
1391
+ scheduledState: latestNew
1356
1392
  };
1357
1393
  };
1358
1394
  return wrapped;
@@ -1389,7 +1425,8 @@ const create$2 = () => {
1389
1425
  };
1390
1426
  states[uid] = {
1391
1427
  newState: latestNew,
1392
- oldState: latestOld.oldState
1428
+ oldState: latestOld.oldState,
1429
+ scheduledState: latestNew
1393
1430
  };
1394
1431
  return {
1395
1432
  error
@@ -1406,6 +1443,7 @@ const {
1406
1443
  getCommandIds,
1407
1444
  registerCommands,
1408
1445
  set: set$1,
1446
+ wrapAsyncCommand,
1409
1447
  wrapCommand
1410
1448
  } = create$2();
1411
1449
 
@@ -2321,7 +2359,7 @@ const getColorThemeNames = async (assetDir, platform) => {
2321
2359
  return invoke$1('ColorTheme.getColorThemeNames', assetDir, platform);
2322
2360
  };
2323
2361
 
2324
- const toProtoVisibleItem$3 = name => {
2362
+ const toProtoVisibleItem$4 = name => {
2325
2363
  const pick = {
2326
2364
  description: '',
2327
2365
  direntType: 0,
@@ -2333,15 +2371,41 @@ const toProtoVisibleItem$3 = name => {
2333
2371
  };
2334
2372
  return pick;
2335
2373
  };
2336
- const getPicks$c = async (searchValue, args, {
2374
+ const getPicks$d = async (searchValue, args, {
2337
2375
  assetDir = '',
2338
2376
  platform = 0
2339
2377
  } = {}) => {
2340
2378
  const colorThemeNames = await getColorThemeNames(assetDir, platform);
2341
- const picks = colorThemeNames.map(toProtoVisibleItem$3);
2379
+ const picks = colorThemeNames.map(toProtoVisibleItem$4);
2342
2380
  return picks;
2343
2381
  };
2344
2382
 
2383
+ const getCommandName = (item, property) => {
2384
+ const value = item[property];
2385
+ return typeof value === 'string' && value ? value : '<unknown>';
2386
+ };
2387
+ const getWarning = (items, property, nameProperty) => {
2388
+ const commandName = getCommandName(items[0], nameProperty);
2389
+ if (items.length === 1) {
2390
+ return `command ${commandName} has missing ${property}`;
2391
+ }
2392
+ const otherCount = items.length - 1;
2393
+ const otherCommands = otherCount === 1 ? 'command' : 'commands';
2394
+ return `command ${commandName} and ${otherCount} other ${otherCommands} have missing ${property}`;
2395
+ };
2396
+ const collectWarnings = items => {
2397
+ const warnings = [];
2398
+ const missingLabels = items.filter(item => !item.label);
2399
+ const missingIds = items.filter(item => !item.id);
2400
+ if (missingLabels.length > 0) {
2401
+ warnings.push(getWarning(missingLabels, 'label', 'id'));
2402
+ }
2403
+ if (missingIds.length > 0) {
2404
+ warnings.push(getWarning(missingIds, 'id', 'label'));
2405
+ }
2406
+ return warnings;
2407
+ };
2408
+
2345
2409
  const handleError = async (error, notify = true, prefix = '') => {
2346
2410
  console.error(error);
2347
2411
  };
@@ -2387,18 +2451,17 @@ const add$1 = menuEntries => {
2387
2451
  state$1.menuEntries = [...state$1.menuEntries, ...menuEntries];
2388
2452
  };
2389
2453
 
2454
+ const changeLanguageModePick = {
2455
+ id: 'QuickPick.changeLanguageMode',
2456
+ label: 'Change Language Mode'
2457
+ };
2458
+
2390
2459
  // TODO combine Ajax with cache (specify strategy: cacheFirst, networkFirst)
2391
2460
  const getBuiltinPicks = async () => {
2392
2461
  const builtinPicks = await getAll();
2393
- return builtinPicks;
2462
+ return [...builtinPicks, changeLanguageModePick];
2394
2463
  };
2395
2464
  const prefixIdWithExt = item => {
2396
- if (!item.label) {
2397
- warn('[QuickPick] item has missing label', item);
2398
- }
2399
- if (!item.id) {
2400
- warn('[QuickPick] item has missing id', item);
2401
- }
2402
2465
  return {
2403
2466
  ...item,
2404
2467
  id: `ext.${item.id}`,
@@ -2416,6 +2479,10 @@ const getExtensionPicks = async (assetDir, platform) => {
2416
2479
  if (!extensionPicks) {
2417
2480
  return [];
2418
2481
  }
2482
+ const warnings = collectWarnings(extensionPicks);
2483
+ for (const warning of warnings) {
2484
+ warn(`[QuickPick] ${warning}`);
2485
+ }
2419
2486
  const mappedPicks = extensionPicks.map(prefixIdWithExt);
2420
2487
  return mappedPicks;
2421
2488
  } catch (error) {
@@ -2423,7 +2490,7 @@ const getExtensionPicks = async (assetDir, platform) => {
2423
2490
  return [];
2424
2491
  }
2425
2492
  };
2426
- const toProtoVisibleItem$2 = item => {
2493
+ const toProtoVisibleItem$3 = item => {
2427
2494
  const pick = {
2428
2495
  // @ts-ignore
2429
2496
  args: item.args,
@@ -2440,7 +2507,7 @@ const toProtoVisibleItem$2 = item => {
2440
2507
  // @ts-ignore
2441
2508
  return pick;
2442
2509
  };
2443
- const getPicks$b = async (value, args, {
2510
+ const getPicks$c = async (value, args, {
2444
2511
  assetDir = '',
2445
2512
  platform = 0
2446
2513
  } = {}) => {
@@ -2448,7 +2515,7 @@ const getPicks$b = async (value, args, {
2448
2515
  const builtinPicks = await getBuiltinPicks();
2449
2516
  const extensionPicks = await getExtensionPicks(assetDir, platform);
2450
2517
  const allPicks = [...builtinPicks, ...extensionPicks];
2451
- const converted = allPicks.map(toProtoVisibleItem$2);
2518
+ const converted = allPicks.map(toProtoVisibleItem$3);
2452
2519
  return converted;
2453
2520
  };
2454
2521
 
@@ -2478,7 +2545,7 @@ const invoke = (method, ...args) => {
2478
2545
  return rpc.invoke(method, ...args);
2479
2546
  };
2480
2547
 
2481
- const toProtoVisibleItem$1 = item => {
2548
+ const toProtoVisibleItem$2 = item => {
2482
2549
  const {
2483
2550
  description = '',
2484
2551
  label,
@@ -2495,11 +2562,11 @@ const toProtoVisibleItem$1 = item => {
2495
2562
  value
2496
2563
  };
2497
2564
  };
2498
- const getPicks$a = async (searchValue, args) => {
2565
+ const getPicks$b = async (searchValue, args) => {
2499
2566
  state.args = args;
2500
2567
  const options = args.at(-1);
2501
2568
  const items = options?.mode === 'quickInput' ? searchValue === '' && options?.customItemsId ? get(options.customItemsId) : await invoke('ExtensionHostQuickPick.renderQuickInput', options.quickInputId, searchValue) : options?.customItemsId ? get(options.customItemsId) : args[1] || [];
2502
- const mapped = items.map(toProtoVisibleItem$1);
2569
+ const mapped = items.map(toProtoVisibleItem$2);
2503
2570
  return mapped;
2504
2571
  };
2505
2572
 
@@ -2552,7 +2619,7 @@ const convertToPick = uri => {
2552
2619
  // e.g. when there are many files, don't need
2553
2620
  // to compute the fileIcon for all files
2554
2621
 
2555
- const getPicks$9 = async searchValue => {
2622
+ const getPicks$a = async searchValue => {
2556
2623
  // TODO cache workspace path
2557
2624
  const workspace = await getWorkspacePath();
2558
2625
  if (!workspace) {
@@ -2716,7 +2783,7 @@ const parseGotoline = value => {
2716
2783
  return wantedLine;
2717
2784
  };
2718
2785
 
2719
- const getPicks$8 = async value => {
2786
+ const getPicks$9 = async value => {
2720
2787
  if (value === GoToLine$1) {
2721
2788
  return getPicksGoToLineBase();
2722
2789
  }
@@ -2746,7 +2813,7 @@ const Percent = '%';
2746
2813
  const AngleBracket = '>';
2747
2814
  const View$1 = 'view';
2748
2815
 
2749
- const getPicks$7 = async () => {
2816
+ const getPicks$8 = async () => {
2750
2817
  return [{
2751
2818
  description: goToFile(),
2752
2819
  direntType: None$2,
@@ -2798,6 +2865,43 @@ const getPicks$7 = async () => {
2798
2865
  }];
2799
2866
  };
2800
2867
 
2868
+ const toProtoVisibleItem$1 = language => {
2869
+ const value = {
2870
+ languageId: language.id,
2871
+ tokenizePath: language.tokenize || ''
2872
+ };
2873
+ return {
2874
+ description: '',
2875
+ direntType: 0,
2876
+ fileIcon: '',
2877
+ icon: '',
2878
+ label: language.id,
2879
+ matches: [],
2880
+ uri: '',
2881
+ value
2882
+ };
2883
+ };
2884
+ const getUniqueLanguages = languages => {
2885
+ const seen = new Set();
2886
+ const uniqueLanguages = [];
2887
+ for (const language of languages) {
2888
+ if (!language || typeof language.id !== 'string' || seen.has(language.id)) {
2889
+ continue;
2890
+ }
2891
+ seen.add(language.id);
2892
+ uniqueLanguages.push(language);
2893
+ }
2894
+ uniqueLanguages.sort((a, b) => a.id.localeCompare(b.id));
2895
+ return uniqueLanguages;
2896
+ };
2897
+ const getPicks$7 = async (_searchValue, _args, {
2898
+ assetDir = '',
2899
+ platform = 0
2900
+ } = {}) => {
2901
+ const languages = await getLanguages(platform, assetDir);
2902
+ return getUniqueLanguages(languages).map(toProtoVisibleItem$1);
2903
+ };
2904
+
2801
2905
  const uniq = array => {
2802
2906
  return [...new Set(array)];
2803
2907
  };
@@ -2859,8 +2963,9 @@ const getPicks$3 = async () => {
2859
2963
 
2860
2964
  const Hide = 'hide';
2861
2965
  const KeepOpen = '';
2966
+ const OpenLanguageMode = 'open-language-mode';
2862
2967
 
2863
- const selectPick$9 = async pick => {
2968
+ const selectPick$a = async pick => {
2864
2969
  const id = pick.label;
2865
2970
  await setColorTheme(id);
2866
2971
  return {
@@ -2880,6 +2985,11 @@ const shouldHide = item => {
2880
2985
  };
2881
2986
 
2882
2987
  const selectPickBuiltin = async item => {
2988
+ if (item.id === 'QuickPick.changeLanguageMode') {
2989
+ return {
2990
+ command: OpenLanguageMode
2991
+ };
2992
+ }
2883
2993
  const args = item.args || [];
2884
2994
  // TODO ids should be all numbers for efficiency -> also directly can call command
2885
2995
  await invoke$1(item.id, ...args);
@@ -2907,7 +3017,7 @@ const selectPickExtension = async item => {
2907
3017
  command: KeepOpen
2908
3018
  };
2909
3019
  };
2910
- const selectPick$8 = async item => {
3020
+ const selectPick$9 = async item => {
2911
3021
  // @ts-ignore
2912
3022
  const {
2913
3023
  id
@@ -2925,7 +3035,7 @@ const getOptions = args => {
2925
3035
  }
2926
3036
  return last;
2927
3037
  };
2928
- const selectPick$7 = async (_pick, value) => {
3038
+ const selectPick$8 = async (_pick, value) => {
2929
3039
  const {
2930
3040
  args
2931
3041
  } = state;
@@ -2952,7 +3062,7 @@ const openUri = async uri => {
2952
3062
  await openUri$1(uri);
2953
3063
  };
2954
3064
 
2955
- const selectPick$6 = async pick => {
3065
+ const selectPick$7 = async pick => {
2956
3066
  const {
2957
3067
  description
2958
3068
  } = pick;
@@ -2990,7 +3100,7 @@ const selectPickGoToColumn = async (item, value) => {
2990
3100
  };
2991
3101
  };
2992
3102
 
2993
- const selectPick$5 = async (item, value) => {
3103
+ const selectPick$6 = async (item, value) => {
2994
3104
  if (value.startsWith(GoToLine$1)) {
2995
3105
  const lineString = value.slice(GoToLine$1.length);
2996
3106
  const wantedLine = Number.parseInt(lineString, 10);
@@ -3006,13 +3116,22 @@ const selectPick$5 = async (item, value) => {
3006
3116
  };
3007
3117
  };
3008
3118
 
3009
- const selectPick$4 = async item => {
3119
+ const selectPick$5 = async item => {
3010
3120
  // Command.execute(/* openView */ 549, /* viewName */ item.label)
3011
3121
  return {
3012
3122
  command: Hide
3013
3123
  };
3014
3124
  };
3015
3125
 
3126
+ const selectPick$4 = async pick => {
3127
+ const editorId = await getActiveEditorId();
3128
+ const value = pick.value;
3129
+ await invoke$1('Viewlet.executeViewletCommand', editorId, 'setLanguageId', value.languageId, value.tokenizePath);
3130
+ return {
3131
+ command: Hide
3132
+ };
3133
+ };
3134
+
3016
3135
  const openWorkspaceFolder = uri => {
3017
3136
  return invoke$1(/* Workspace.setPath */'Workspace.setPath', /* path */uri);
3018
3137
  };
@@ -3047,8 +3166,8 @@ const selectPick = async item => {
3047
3166
  };
3048
3167
  };
3049
3168
 
3050
- const selectPicks = [selectPick$9, selectPick$8, selectPick$7, selectPick$6, selectPickGoToColumn, selectPick$5, selectPick$4, selectPick$3, selectPick$2, selectPick$1, selectPick];
3051
- const getPicks$2 = [getPicks$c, getPicks$b, getPicks$a, getPicks$9, getPicksGoToColumn, getPicks$8, getPicks$7, getPicks$6, getPicks$5, getPicks$4, getPicks$3];
3169
+ const selectPicks = [selectPick$a, selectPick$9, selectPick$8, selectPick$7, selectPickGoToColumn, selectPick$6, selectPick$5, selectPick$3, selectPick$2, selectPick$1, selectPick, selectPick$4];
3170
+ const getPicks$2 = [getPicks$d, getPicks$c, getPicks$b, getPicks$a, getPicksGoToColumn, getPicks$9, getPicks$8, getPicks$6, getPicks$5, getPicks$4, getPicks$3, getPicks$7];
3052
3171
 
3053
3172
  const select = selectPicks;
3054
3173
  const getPick$1 = getPicks$2;
@@ -3096,6 +3215,10 @@ const getQuickPickSubProviderId = (id, prefix) => {
3096
3215
  }
3097
3216
  };
3098
3217
 
3218
+ const requestVersions = new Map();
3219
+ const requestVersionGenerator = {
3220
+ value: 0
3221
+ };
3099
3222
  const isQuickInput = args => {
3100
3223
  const options = args.at(-1);
3101
3224
  return options?.mode === 'quickInput';
@@ -3146,6 +3269,51 @@ const setValue = async (state, newValue) => {
3146
3269
  value: newValue
3147
3270
  };
3148
3271
  };
3272
+ const setValueWithContext = async (context, newValue) => {
3273
+ const state = context.getState();
3274
+ if (state.value === newValue) {
3275
+ return;
3276
+ }
3277
+ const requestVersion = ++requestVersionGenerator.value;
3278
+ requestVersions.set(state.uid, requestVersion);
3279
+ const result = await setValue(state, newValue);
3280
+ await context.updateState(latestState => {
3281
+ if (requestVersions.get(latestState.uid) !== requestVersion) {
3282
+ return latestState;
3283
+ }
3284
+ return {
3285
+ ...latestState,
3286
+ fileIconCache: result.fileIconCache,
3287
+ finalDeltaY: result.finalDeltaY,
3288
+ focusedIndex: result.focusedIndex,
3289
+ icons: result.icons,
3290
+ inputSource: result.inputSource,
3291
+ items: result.items,
3292
+ picks: result.picks,
3293
+ value: result.value
3294
+ };
3295
+ });
3296
+ if (requestVersions.get(state.uid) === requestVersion) {
3297
+ requestVersions.delete(state.uid);
3298
+ }
3299
+ };
3300
+
3301
+ const handleInputWithContext = async (context, newValue, cursorOffset, inputSource = Script) => {
3302
+ const state = context.getState();
3303
+ if (state.value !== newValue) {
3304
+ await setValueWithContext(context, newValue);
3305
+ }
3306
+ await context.updateState(latestState => {
3307
+ if (latestState.value !== newValue) {
3308
+ return latestState;
3309
+ }
3310
+ return {
3311
+ ...latestState,
3312
+ cursorOffset,
3313
+ inputSource
3314
+ };
3315
+ });
3316
+ };
3149
3317
 
3150
3318
  // TODO when user types letters -> no need to query provider again -> just filter existing results
3151
3319
  const handleInput = async (state, newValue, cursorOffset, inputSource = Script) => {
@@ -3223,102 +3391,11 @@ const getPick = (items, index) => {
3223
3391
  return undefined;
3224
3392
  };
3225
3393
 
3226
- const createCustomPick = value => {
3227
- return {
3228
- description: '',
3229
- direntType: 0,
3230
- fileIcon: '',
3231
- icon: '',
3232
- label: value,
3233
- matches: [],
3234
- uri: ''
3235
- };
3236
- };
3237
- const selectIndex = async (state, index, button = /* left */0) => {
3238
- const {
3239
- items,
3240
- minLineY,
3241
- providerId,
3242
- value
3243
- } = state;
3244
- const actualIndex = index + minLineY;
3245
- const prefix = getQuickPickPrefix(value);
3246
- const subId = getQuickPickSubProviderId(providerId, prefix);
3247
- const pick = getPick(items, actualIndex) || (subId === Custom$1 ? createCustomPick(value) : undefined);
3248
- if (!pick) {
3249
- return state;
3250
- }
3251
- const fn = getSelect(subId);
3252
- const selectPickResult = await fn(pick, value);
3253
- object(selectPickResult);
3254
- string(selectPickResult.command);
3255
- const {
3256
- command
3257
- } = selectPickResult;
3258
- switch (command) {
3259
- case Hide:
3260
- await closeWidget(state.uid);
3261
- return state;
3262
- default:
3263
- return state;
3264
- }
3265
-
3266
- // TODO recent picks should be per provider
3267
- // if (!state.recentPickIds.has(pick.id)) {
3268
- // state.recentPicks.unshift(pick)
3269
- // state.recentPickIds.add(pick.id)
3270
- // }
3271
- // if (state.recentPicks.length > RECENT_PICKS_MAX_SIZE) {
3272
- // const last = state.recentPicks.pop()
3273
- // state.recentPickIds.delete(last.id)
3274
- // }
3275
- };
3276
-
3277
- const handleClickAt = (state, x, y) => {
3278
- const {
3279
- headerHeight,
3280
- itemHeight,
3281
- top
3282
- } = state;
3283
- const index = getIndex(top, headerHeight, itemHeight, y);
3284
- return selectIndex(state, index);
3285
- };
3286
-
3287
- const handleFocus = async state => {
3288
- // TODO fix virtual dom diffing so that input isn't destroyed and loses focus when rerendering
3289
- await setFocus(FocusQuickPickInput);
3290
- // await CloseWidget.closeWidget(state.uid)
3291
- return state;
3292
- };
3293
-
3294
- const commandMapRef = {};
3295
-
3296
- const handleMessagePort = async port => {
3297
- const rpc = await create$8({
3298
- commandMap: commandMapRef,
3299
- isMessagePortOpen: true,
3300
- messagePort: port
3301
- });
3302
- set(rpc);
3303
- };
3304
-
3305
- const initialize = async () => {
3306
- // not needed anymore
3307
- };
3308
-
3309
- const getDefaultValue = id => {
3310
- switch (id) {
3311
- case EveryThing$1:
3312
- return Command;
3313
- default:
3314
- return '';
3315
- }
3316
- };
3317
-
3318
3394
  const Commands = 'quickPick://commands';
3319
3395
  const EveryThing = 'quickPick://everything';
3320
3396
  const Recent = 'quickPick://recent';
3321
3397
  const ColorTheme = 'quickPick://color-theme';
3398
+ const LanguageMode = 'quickPick://language-mode';
3322
3399
  const Symbol$1 = 'quickPick://symbol';
3323
3400
  const View = 'quickPick://view';
3324
3401
  const Help = 'quickPick://help';
@@ -3326,6 +3403,18 @@ const WorkspaceSymbol = 'quickPick://workspace-symbol';
3326
3403
  const Custom = 'quickPick://custom';
3327
3404
  const GoToLine = 'quickPick://go-to-line';
3328
3405
 
3406
+ const getDefaultValue = (id, uri = '') => {
3407
+ if (uri === WorkspaceSymbol) {
3408
+ return WorkspaceSymbol$1;
3409
+ }
3410
+ switch (id) {
3411
+ case EveryThing$1:
3412
+ return Command;
3413
+ default:
3414
+ return '';
3415
+ }
3416
+ };
3417
+
3329
3418
  const getQuickPickProviderId = prefix => {
3330
3419
  switch (prefix) {
3331
3420
  case ColorTheme:
@@ -3340,6 +3429,8 @@ const getQuickPickProviderId = prefix => {
3340
3429
  return EveryThing$1;
3341
3430
  case Custom:
3342
3431
  return Custom$1;
3432
+ case LanguageMode:
3433
+ return LanguageMode$1;
3343
3434
  case Recent:
3344
3435
  return Recent$1;
3345
3436
  default:
@@ -3388,7 +3479,7 @@ const parseArgs = (subId, args) => {
3388
3479
  placeholder: last.placeholder ? String(last.placeholder) : ''
3389
3480
  };
3390
3481
  };
3391
- const loadContent = async state => {
3482
+ const getLoadedState = async state => {
3392
3483
  const {
3393
3484
  args,
3394
3485
  assetDir,
@@ -3400,7 +3491,7 @@ const loadContent = async state => {
3400
3491
  uri
3401
3492
  } = state;
3402
3493
  const id = getQuickPickProviderId(uri);
3403
- const value = getDefaultValue(id);
3494
+ const value = getDefaultValue(id, uri);
3404
3495
  const prefix = getQuickPickPrefix(value);
3405
3496
  const subId = getQuickPickSubProviderId(id, prefix);
3406
3497
  const newPicks = await getPicks(subId, value, args, {
@@ -3421,7 +3512,6 @@ const loadContent = async state => {
3421
3512
  const finalDeltaY = getFinalDeltaY(listHeight, itemHeight, items.length);
3422
3513
  const parsedArgs = parseArgs(subId, args);
3423
3514
  const finalValue = parsedArgs.initialValue || value;
3424
- notifyVisible();
3425
3515
  return {
3426
3516
  ...state,
3427
3517
  args,
@@ -3443,6 +3533,125 @@ const loadContent = async state => {
3443
3533
  value: finalValue
3444
3534
  };
3445
3535
  };
3536
+ const loadContent = async state => {
3537
+ const newState = await getLoadedState(state);
3538
+ notifyVisible();
3539
+ return newState;
3540
+ };
3541
+ const loadContentWithContext = async context => {
3542
+ const state = context.getState();
3543
+ const loadedState = await getLoadedState(state);
3544
+ await context.updateState(latestState => ({
3545
+ ...latestState,
3546
+ cursorOffset: loadedState.cursorOffset,
3547
+ fileIconCache: loadedState.fileIconCache,
3548
+ finalDeltaY: loadedState.finalDeltaY,
3549
+ focused: loadedState.focused,
3550
+ focusedIndex: loadedState.focusedIndex,
3551
+ icons: loadedState.icons,
3552
+ initial: loadedState.initial,
3553
+ inputSource: loadedState.inputSource,
3554
+ items: loadedState.items,
3555
+ maxLineY: loadedState.maxLineY,
3556
+ minLineY: loadedState.minLineY,
3557
+ picks: loadedState.picks,
3558
+ placeholder: loadedState.placeholder,
3559
+ providerId: loadedState.providerId,
3560
+ state: loadedState.state,
3561
+ value: loadedState.value
3562
+ }));
3563
+ notifyVisible();
3564
+ };
3565
+
3566
+ const createCustomPick = value => {
3567
+ return {
3568
+ description: '',
3569
+ direntType: 0,
3570
+ fileIcon: '',
3571
+ icon: '',
3572
+ label: value,
3573
+ matches: [],
3574
+ uri: ''
3575
+ };
3576
+ };
3577
+ const selectIndex = async (state, index, button = /* left */0) => {
3578
+ const {
3579
+ items,
3580
+ minLineY,
3581
+ providerId,
3582
+ value
3583
+ } = state;
3584
+ const actualIndex = index + minLineY;
3585
+ const prefix = getQuickPickPrefix(value);
3586
+ const subId = getQuickPickSubProviderId(providerId, prefix);
3587
+ const pick = getPick(items, actualIndex) || (subId === Custom$1 ? createCustomPick(value) : undefined);
3588
+ if (!pick) {
3589
+ return state;
3590
+ }
3591
+ const fn = getSelect(subId);
3592
+ const selectPickResult = await fn(pick, value);
3593
+ object(selectPickResult);
3594
+ string(selectPickResult.command);
3595
+ const {
3596
+ command
3597
+ } = selectPickResult;
3598
+ switch (command) {
3599
+ case Hide:
3600
+ await closeWidget(state.uid);
3601
+ return state;
3602
+ case OpenLanguageMode:
3603
+ return loadContent({
3604
+ ...state,
3605
+ args: [],
3606
+ uri: LanguageMode,
3607
+ value: ''
3608
+ });
3609
+ default:
3610
+ return state;
3611
+ }
3612
+
3613
+ // TODO recent picks should be per provider
3614
+ // if (!state.recentPickIds.has(pick.id)) {
3615
+ // state.recentPicks.unshift(pick)
3616
+ // state.recentPickIds.add(pick.id)
3617
+ // }
3618
+ // if (state.recentPicks.length > RECENT_PICKS_MAX_SIZE) {
3619
+ // const last = state.recentPicks.pop()
3620
+ // state.recentPickIds.delete(last.id)
3621
+ // }
3622
+ };
3623
+
3624
+ const handleClickAt = (state, x, y) => {
3625
+ const {
3626
+ headerHeight,
3627
+ itemHeight,
3628
+ top
3629
+ } = state;
3630
+ const index = getIndex(top, headerHeight, itemHeight, y);
3631
+ return selectIndex(state, index);
3632
+ };
3633
+
3634
+ const handleFocus = async state => {
3635
+ // TODO fix virtual dom diffing so that input isn't destroyed and loses focus when rerendering
3636
+ await setFocus(FocusQuickPickInput);
3637
+ // await CloseWidget.closeWidget(state.uid)
3638
+ return state;
3639
+ };
3640
+
3641
+ const commandMapRef = {};
3642
+
3643
+ const handleMessagePort = async port => {
3644
+ const rpc = await create$8({
3645
+ commandMap: commandMapRef,
3646
+ isMessagePortOpen: true,
3647
+ messagePort: port
3648
+ });
3649
+ set(rpc);
3650
+ };
3651
+
3652
+ const initialize = async () => {
3653
+ // not needed anymore
3654
+ };
3446
3655
 
3447
3656
  const SetCursorOffset = 'setCursorOffset';
3448
3657
  const SetFocusedIndex = 'setFocusedIndex';
@@ -3913,7 +4122,6 @@ const Viewlet = 'Viewlet';
3913
4122
 
3914
4123
  const HandleWheel = 'handleWheel';
3915
4124
  const HandlePointerDown = 'handlePointerDown';
3916
- const HandleBeforeInput = 'handleBeforeInput';
3917
4125
  const HandleBlur = 'handleBlur';
3918
4126
  const HandleFocus = 'handleFocus';
3919
4127
  const HandleInput = 'handleInput';
@@ -3937,7 +4145,6 @@ const getQuickPickInputVirtualDom = (placeholder = '') => {
3937
4145
  className: InputBox,
3938
4146
  inputType: 'text',
3939
4147
  name: QuickPickInput,
3940
- onBeforeInput: HandleBeforeInput,
3941
4148
  onBlur: HandleBlur,
3942
4149
  onFocus: HandleFocus,
3943
4150
  onInput: HandleInput,
@@ -4231,9 +4438,6 @@ const renderEventListeners = () => {
4231
4438
  }, {
4232
4439
  name: HandleBlur,
4233
4440
  params: ['handleBlur']
4234
- }, {
4235
- name: HandleBeforeInput,
4236
- params: ['handleBeforeInput']
4237
4441
  }, {
4238
4442
  name: HandleInput,
4239
4443
  params: ['handleInput', 'event.target.value']
@@ -4341,21 +4545,21 @@ const commandMap = {
4341
4545
  'QuickPick.handleBlur': wrapCommand(handleBlur),
4342
4546
  'QuickPick.handleClickAt': wrapCommand(handleClickAt),
4343
4547
  'QuickPick.handleFocus': wrapCommand(handleFocus),
4344
- 'QuickPick.handleInput': wrapCommand(handleInput),
4548
+ 'QuickPick.handleInput': wrapAsyncCommand(handleInputWithContext),
4345
4549
  'QuickPick.handleMessagePort': handleMessagePort,
4346
4550
  'QuickPick.handleScrollBarPointerDown': wrapCommand(handleScrollBarPointerDown),
4347
4551
  'QuickPick.handleScrollBarPointerMove': wrapCommand(handleScrollBarPointerMove),
4348
4552
  'QuickPick.handleScrollBarPointerUp': wrapCommand(handleScrollBarPointerUp),
4349
4553
  'QuickPick.handleWheel': wrapCommand(handleWheel),
4350
4554
  'QuickPick.initialize': initialize,
4351
- 'QuickPick.loadContent': wrapCommand(loadContent),
4555
+ 'QuickPick.loadContent': wrapAsyncCommand(loadContentWithContext),
4352
4556
  'QuickPick.render2': render2,
4353
4557
  'QuickPick.renderEventListeners': renderEventListeners,
4354
4558
  'QuickPick.selectCurrentIndex': wrapCommand(selectCurrentIndex),
4355
4559
  'QuickPick.selectIndex': wrapCommand(selectIndex),
4356
4560
  'QuickPick.selectItem': wrapCommand(selectItem),
4357
4561
  'QuickPick.setDeltaY': wrapCommand(setDeltaY),
4358
- 'QuickPick.setValue': wrapCommand(setValue),
4562
+ 'QuickPick.setValue': wrapAsyncCommand(setValueWithContext),
4359
4563
  'QuickPick.showQuickInput': showQuickInput,
4360
4564
  'QuickPick.showQuickPick': showQuickPick,
4361
4565
  'QuickPick.waitUntilVisible': waitUntilVisible
@@ -4368,6 +4572,16 @@ const initializeEditorWorker = async () => {
4368
4572
  await sendMessagePortToEditorWorker(port, 0);
4369
4573
  }
4370
4574
  });
4575
+ set$5(rpc);
4576
+ };
4577
+
4578
+ const initializeExtensionManagementWorker = async () => {
4579
+ const rpc = await create$6({
4580
+ commandMap: {},
4581
+ async send(port) {
4582
+ await sendMessagePortToExtensionManagementWorker(port, 0);
4583
+ }
4584
+ });
4371
4585
  set$4(rpc);
4372
4586
  };
4373
4587
 
@@ -4391,7 +4605,7 @@ const initializeRendererWorker = async () => {
4391
4605
  const listen = async () => {
4392
4606
  Object.assign(commandMapRef, commandMap);
4393
4607
  registerCommands(commandMap);
4394
- await Promise.all([initializeRendererWorker(), initializeEditorWorker(), initializeFileSearchWorker()]);
4608
+ await Promise.all([initializeRendererWorker(), initializeEditorWorker(), initializeExtensionManagementWorker(), initializeFileSearchWorker()]);
4395
4609
  };
4396
4610
 
4397
4611
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/quick-pick-worker",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lvce-editor/quick-pick-worker.git"