@lvce-editor/test-worker 15.10.0 → 16.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.
package/dist/api.d.ts CHANGED
@@ -148,6 +148,19 @@ export interface Diagnostic {
148
148
  readonly type: "error" | "warning";
149
149
  }
150
150
 
151
+ export interface FormattingTextDocument {
152
+ readonly documentId?: number;
153
+ readonly languageId: string;
154
+ readonly text?: string;
155
+ readonly uri?: string;
156
+ }
157
+
158
+ export interface FormattingEdit {
159
+ readonly endOffset: number;
160
+ readonly inserted: string;
161
+ readonly startOffset: number;
162
+ }
163
+
151
164
  export interface FileSystemTmpDirOptions {
152
165
  readonly scheme?: string;
153
166
  }
@@ -183,6 +196,10 @@ export interface LayoutExpectation extends LayoutExpectationObject {
183
196
  readonly groups?: readonly LayoutExpectationObject[];
184
197
  }
185
198
 
199
+ export interface SelectItemOptions {
200
+ readonly waitUntil?: SelectItemWaitUntil;
201
+ }
202
+
186
203
  export interface SelectItem2Options {
187
204
  readonly callbackCommand: string;
188
205
  readonly label: string;
@@ -233,6 +250,8 @@ export type SavedState = {
233
250
  readonly layout?: LayoutState;
234
251
  };
235
252
 
253
+ export type SelectItemWaitUntil = "done" | "quickPick" | "none";
254
+
236
255
  export type SearchInputType = "SearchValue" | "ReplaceValue" | "IncludeValue" | "ExcludeValue";
237
256
 
238
257
  interface Workspace {
@@ -591,6 +610,7 @@ interface Explorer {
591
610
  interface Extension {
592
611
  readonly addNodeExtension: (relativePath: string) => Promise<void>;
593
612
  readonly addWebExtension: (relativePath: string) => Promise<void>;
613
+ readonly executeFormattingProvider: (textDocument: FormattingTextDocument, ...args: readonly unknown[]) => Promise<readonly FormattingEdit[]>;
594
614
  }
595
615
 
596
616
  interface ExtensionDetail {
@@ -862,7 +882,7 @@ interface QuickPick {
862
882
  readonly open: () => Promise<void>;
863
883
  readonly selectCurrentIndex: () => Promise<void>;
864
884
  readonly selectIndex: (index: number) => Promise<void>;
865
- readonly selectItem: (label: string) => Promise<void>;
885
+ readonly selectItem: (label: string, { waitUntil }?: SelectItemOptions) => Promise<void>;
866
886
  readonly selectItem2: ({ callbackCommand, label }: SelectItem2Options) => Promise<void>;
867
887
  readonly setValue: (value: string) => Promise<void>;
868
888
  }
@@ -1091,7 +1091,7 @@ const createMockRpc = ({
1091
1091
  };
1092
1092
 
1093
1093
  const rpcs = Object.create(null);
1094
- const set$7 = (id, rpc) => {
1094
+ const set$8 = (id, rpc) => {
1095
1095
  rpcs[id] = rpc;
1096
1096
  };
1097
1097
  const get$2 = id => {
@@ -1124,7 +1124,7 @@ const create = rpcId => {
1124
1124
  const mockRpc = createMockRpc({
1125
1125
  commandMap
1126
1126
  });
1127
- set$7(rpcId, mockRpc);
1127
+ set$8(rpcId, mockRpc);
1128
1128
  // @ts-ignore
1129
1129
  mockRpc[Symbol.dispose] = () => {
1130
1130
  remove$1(rpcId);
@@ -1133,7 +1133,7 @@ const create = rpcId => {
1133
1133
  return mockRpc;
1134
1134
  },
1135
1135
  set(rpc) {
1136
- set$7(rpcId, rpc);
1136
+ set$8(rpcId, rpc);
1137
1137
  }
1138
1138
  };
1139
1139
  };
@@ -1147,16 +1147,22 @@ const Web = 1;
1147
1147
  const Remote = 3;
1148
1148
 
1149
1149
  const EditorWorker = 99;
1150
+ const ErrorWorker = 3308;
1150
1151
  const ExtensionHostWorker = 44;
1151
1152
  const ExtensionManagementWorker = 9006;
1152
1153
  const OpenerWorker = 4561;
1153
1154
  const RendererWorker = 1;
1154
1155
  const TestWorker = 9001;
1155
1156
 
1157
+ const {
1158
+ invoke: invoke$4,
1159
+ set: set$7
1160
+ } = create(EditorWorker);
1161
+
1156
1162
  const {
1157
1163
  invoke: invoke$3,
1158
1164
  set: set$6
1159
- } = create(EditorWorker);
1165
+ } = create(ErrorWorker);
1160
1166
 
1161
1167
  const {
1162
1168
  set: set$5
@@ -1185,6 +1191,10 @@ const sendMessagePortToOpenerWorker = async (port, rpcId) => {
1185
1191
  const command = 'HandleMessagePort.handleMessagePort';
1186
1192
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToOpenerWorker', port, command, rpcId);
1187
1193
  };
1194
+ const sendMessagePortToErrorWorker = async (port, rpcId) => {
1195
+ const command = 'Errors.handleMessagePort';
1196
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1197
+ };
1188
1198
  const readFile$1 = async uri => {
1189
1199
  return invoke('FileSystem.readFile', uri);
1190
1200
  };
@@ -1200,10 +1210,21 @@ const getPreference = async key => {
1200
1210
  return await invoke('Preferences.get', key);
1201
1211
  };
1202
1212
 
1203
- const send$3 = async port => {
1213
+ const send$4 = async port => {
1204
1214
  await sendMessagePortToEditorWorker(port, TestWorker);
1205
1215
  };
1206
1216
  const initializeEditorWorker = async () => {
1217
+ const rpc = await create$3({
1218
+ commandMap: {},
1219
+ send: send$4
1220
+ });
1221
+ set$7(rpc);
1222
+ };
1223
+
1224
+ const send$3 = async port => {
1225
+ await sendMessagePortToErrorWorker(port, TestWorker);
1226
+ };
1227
+ const initializeErrorWorker = async () => {
1207
1228
  const rpc = await create$3({
1208
1229
  commandMap: {},
1209
1230
  send: send$3
@@ -2806,7 +2827,7 @@ const areSelectionsEqual = (a, b) => {
2806
2827
  };
2807
2828
 
2808
2829
  const getEditorKey = async () => {
2809
- const keys = await invoke$3('Editor.getKeys');
2830
+ const keys = await invoke$4('Editor.getKeys');
2810
2831
  if (keys.length === 0) {
2811
2832
  throw new Error(`no editor found`);
2812
2833
  }
@@ -3072,11 +3093,11 @@ const growSelection = async () => {
3072
3093
  };
3073
3094
  const getSelections = async () => {
3074
3095
  const key = await getEditorKey();
3075
- return invoke$3('Editor.getSelections', key);
3096
+ return invoke$4('Editor.getSelections', key);
3076
3097
  };
3077
3098
  const shouldHaveText = async expectedText => {
3078
3099
  const key = await getEditorKey();
3079
- const text = await invoke$3('Editor.getText', key);
3100
+ const text = await invoke$4('Editor.getText', key);
3080
3101
  if (text !== expectedText) {
3081
3102
  throw new Error(`Expected editor to have text ${expectedText} but was ${text}`);
3082
3103
  }
@@ -3101,7 +3122,7 @@ const areTokensEqual = (actual, expected) => {
3101
3122
  };
3102
3123
  const shouldHaveTokens = async expectedTokens => {
3103
3124
  const key = await getEditorKey();
3104
- const text = await invoke$3('Editor.getTokens', key);
3125
+ const text = await invoke$4('Editor.getTokens', key);
3105
3126
  if (!areTokensEqual(text, expectedTokens)) {
3106
3127
  const stringifiedActual = JSON.stringify(text);
3107
3128
  const stringifiedExpected = JSON.stringify(expectedTokens);
@@ -3110,20 +3131,20 @@ const shouldHaveTokens = async expectedTokens => {
3110
3131
  };
3111
3132
  const shouldHaveSelections = async expectedSelections => {
3112
3133
  const key = await getEditorKey();
3113
- const selections = await invoke$3('Editor.getSelections', key);
3134
+ const selections = await invoke$4('Editor.getSelections', key);
3114
3135
  if (!areSelectionsEqual(selections, expectedSelections)) {
3115
3136
  throw new Error(`Expected editor to have selections ${expectedSelections} but was ${selections}`);
3116
3137
  }
3117
3138
  };
3118
3139
  const undo = async () => {
3119
- await invoke$3('Editor.undo');
3140
+ await invoke$4('Editor.undo');
3120
3141
  };
3121
3142
  const redo = async () => {
3122
- await invoke$3('Editor.redo');
3143
+ await invoke$4('Editor.redo');
3123
3144
  };
3124
3145
  const shouldHaveDiagnostics = async expectedDiagnostics => {
3125
3146
  const key = await getEditorKey();
3126
- const diagnostics = await invoke$3('Editor.getDiagnostics', key);
3147
+ const diagnostics = await invoke$4('Editor.getDiagnostics', key);
3127
3148
  if (!areDiagnosticsEqual(diagnostics, expectedDiagnostics)) {
3128
3149
  const stringifiedActual = JSON.stringify(diagnostics);
3129
3150
  const stringifiedExpected = JSON.stringify(expectedDiagnostics);
@@ -3479,6 +3500,9 @@ const addWebExtension = async relativePath => {
3479
3500
  await invoke$2('Extensions.addWebExtension', absolutePath);
3480
3501
  await invoke('ExtensionMeta.addWebExtension', absolutePath);
3481
3502
  };
3503
+ const executeFormattingProvider = async (textDocument, ...args) => {
3504
+ return invoke$2('Extensions.executeFormattingProvider', textDocument, ...args);
3505
+ };
3482
3506
  const addNodeExtension = async relativePath => {
3483
3507
  // TODO compute absolutePath
3484
3508
  const absolutePath = relativePath;
@@ -3487,7 +3511,8 @@ const addNodeExtension = async relativePath => {
3487
3511
 
3488
3512
  const Extension = {
3489
3513
  addNodeExtension,
3490
- addWebExtension
3514
+ addWebExtension,
3515
+ executeFormattingProvider
3491
3516
  };
3492
3517
 
3493
3518
  const handleClickCategory = async categoryId => {
@@ -4609,8 +4634,21 @@ const focusIndex$2 = async index => {
4609
4634
  const focusPrevious$2 = async () => {
4610
4635
  await invoke('QuickPick.focusPrevious');
4611
4636
  };
4612
- const selectItem = async label => {
4613
- await invoke('QuickPick.selectItem', label);
4637
+ const selectItem = async (label, {
4638
+ waitUntil = 'done'
4639
+ } = {}) => {
4640
+ if (waitUntil === 'done') {
4641
+ await invoke('QuickPick.selectItem', label);
4642
+ return;
4643
+ }
4644
+ const visiblePromise = waitUntil === 'quickPick' ? invoke('QuickPick.waitUntilVisible') : undefined;
4645
+ const promise = Promise.resolve(invoke('QuickPick.selectItem', label));
4646
+ if (waitUntil === 'none') {
4647
+ void promise.catch(() => undefined);
4648
+ return;
4649
+ }
4650
+ void promise.catch(() => undefined);
4651
+ await visiblePromise;
4614
4652
  };
4615
4653
  const selectIndex$3 = async index => {
4616
4654
  await invoke('QuickPick.selectIndex', index);
@@ -5302,9 +5340,18 @@ const printError = error => {
5302
5340
  }
5303
5341
  };
5304
5342
 
5343
+ const prepareError = 'Errors.prepare';
5344
+ const formatPreparedError = preparedError => {
5345
+ const codeFrame = preparedError.codeframe || preparedError.codeFrame;
5346
+ return [preparedError.message, codeFrame, preparedError.stack].filter(Boolean).join('\n');
5347
+ };
5305
5348
  const printTestError = async error => {
5306
- // TODO ask error worker to add codeframe
5307
- printError(error);
5349
+ try {
5350
+ const preparedError = await invoke$3(prepareError, error);
5351
+ console.error(formatPreparedError(preparedError));
5352
+ } catch {
5353
+ printError(error);
5354
+ }
5308
5355
  };
5309
5356
 
5310
5357
  const now = () => {
@@ -5863,7 +5910,7 @@ const initializeRendererWorker = async () => {
5863
5910
  };
5864
5911
 
5865
5912
  const listen = async () => {
5866
- await Promise.all([initializeRendererWorker(), initializeEditorWorker(), initializeOpenerWorker(), initializeExtensionManagementWorker(), initializeExtensionHostWorker()]);
5913
+ await Promise.all([initializeEditorWorker(), initializeErrorWorker(), initializeExtensionHostWorker(), initializeExtensionManagementWorker(), initializeOpenerWorker(), initializeRendererWorker()]);
5867
5914
  };
5868
5915
 
5869
5916
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/test-worker",
3
- "version": "15.10.0",
3
+ "version": "16.0.0",
4
4
  "description": "Test Worker",
5
5
  "repository": {
6
6
  "type": "git",