@lvce-editor/file-search-worker 7.5.0 → 8.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/README.md +12 -3
- package/dist/fileSearchWorkerMain.js +883 -3741
- package/package.json +6 -6
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
const EditorWorker = 99;
|
|
2
|
-
const RendererWorker = 1;
|
|
3
|
-
|
|
4
1
|
const normalizeLine = line => {
|
|
5
2
|
if (line.startsWith('Error: ')) {
|
|
6
3
|
return line.slice('Error: '.length);
|
|
@@ -57,3951 +54,1091 @@ class VError extends Error {
|
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
super(message);
|
|
63
|
-
this.name = 'AssertionError';
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const Object$1 = 1;
|
|
67
|
-
const Number$1 = 2;
|
|
68
|
-
const Array$1 = 3;
|
|
69
|
-
const String$1 = 4;
|
|
70
|
-
const Boolean$1 = 5;
|
|
71
|
-
const Function = 6;
|
|
72
|
-
const Null = 7;
|
|
73
|
-
const Unknown = 8;
|
|
74
|
-
const getType = value => {
|
|
75
|
-
switch (typeof value) {
|
|
76
|
-
case 'number':
|
|
77
|
-
return Number$1;
|
|
78
|
-
case 'function':
|
|
79
|
-
return Function;
|
|
80
|
-
case 'string':
|
|
81
|
-
return String$1;
|
|
82
|
-
case 'object':
|
|
83
|
-
if (value === null) {
|
|
84
|
-
return Null;
|
|
85
|
-
}
|
|
86
|
-
if (Array.isArray(value)) {
|
|
87
|
-
return Array$1;
|
|
88
|
-
}
|
|
89
|
-
return Object$1;
|
|
90
|
-
case 'boolean':
|
|
91
|
-
return Boolean$1;
|
|
92
|
-
default:
|
|
93
|
-
return Unknown;
|
|
94
|
-
}
|
|
57
|
+
const isMessagePort = value => {
|
|
58
|
+
return value && value instanceof MessagePort;
|
|
95
59
|
};
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
if (type !== Object$1) {
|
|
99
|
-
throw new AssertionError('expected value to be of type object');
|
|
100
|
-
}
|
|
60
|
+
const isMessagePortMain = value => {
|
|
61
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
101
62
|
};
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
if (type !== Number$1) {
|
|
105
|
-
throw new AssertionError('expected value to be of type number');
|
|
106
|
-
}
|
|
63
|
+
const isOffscreenCanvas = value => {
|
|
64
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
107
65
|
};
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
if (type !== Array$1) {
|
|
111
|
-
throw new AssertionError('expected value to be of type array');
|
|
112
|
-
}
|
|
66
|
+
const isInstanceOf = (value, constructorName) => {
|
|
67
|
+
return value?.constructor?.name === constructorName;
|
|
113
68
|
};
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
if (type !== String$1) {
|
|
117
|
-
throw new AssertionError('expected value to be of type string');
|
|
118
|
-
}
|
|
69
|
+
const isSocket = value => {
|
|
70
|
+
return isInstanceOf(value, 'Socket');
|
|
119
71
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
72
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
73
|
+
const isTransferrable = value => {
|
|
74
|
+
for (const fn of transferrables) {
|
|
75
|
+
if (fn(value)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
125
78
|
}
|
|
126
|
-
|
|
127
|
-
const commands = Object.create(null);
|
|
128
|
-
const register$1 = commandMap => {
|
|
129
|
-
Object.assign(commands, commandMap);
|
|
130
|
-
};
|
|
131
|
-
const getCommand = key => {
|
|
132
|
-
return commands[key];
|
|
79
|
+
return false;
|
|
133
80
|
};
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
throw new CommandNotFoundError(command);
|
|
81
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
82
|
+
if (!value) {
|
|
83
|
+
return;
|
|
138
84
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const invoke = (method, ...params) => {
|
|
147
|
-
invocations.push([method, ...params]);
|
|
148
|
-
const command = commandMap[method];
|
|
149
|
-
if (!command) {
|
|
150
|
-
throw new Error(`command ${method} not found`);
|
|
85
|
+
if (isTransferrable(value)) {
|
|
86
|
+
transferrables.push(value);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
for (const item of value) {
|
|
91
|
+
walkValue(item, transferrables, isTransferrable);
|
|
151
92
|
}
|
|
152
|
-
return
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (typeof value === 'object') {
|
|
96
|
+
for (const property of Object.values(value)) {
|
|
97
|
+
walkValue(property, transferrables, isTransferrable);
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const getTransferrables = value => {
|
|
103
|
+
const transferrables = [];
|
|
104
|
+
walkValue(value, transferrables, isTransferrable);
|
|
105
|
+
return transferrables;
|
|
106
|
+
};
|
|
107
|
+
const attachEvents = that => {
|
|
108
|
+
const handleMessage = (...args) => {
|
|
109
|
+
const data = that.getData(...args);
|
|
110
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
111
|
+
data
|
|
112
|
+
}));
|
|
153
113
|
};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
invokeAndTransfer: invoke
|
|
114
|
+
that.onMessage(handleMessage);
|
|
115
|
+
const handleClose = event => {
|
|
116
|
+
that.dispatchEvent(new Event('close'));
|
|
158
117
|
};
|
|
159
|
-
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const rpcs = Object.create(null);
|
|
163
|
-
const set$3 = (id, rpc) => {
|
|
164
|
-
rpcs[id] = rpc;
|
|
118
|
+
that.onClose(handleClose);
|
|
165
119
|
};
|
|
166
|
-
|
|
167
|
-
|
|
120
|
+
class Ipc extends EventTarget {
|
|
121
|
+
constructor(rawIpc) {
|
|
122
|
+
super();
|
|
123
|
+
this._rawIpc = rawIpc;
|
|
124
|
+
attachEvents(this);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
128
|
+
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
129
|
+
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
130
|
+
const NewLine$1 = '\n';
|
|
131
|
+
const joinLines$1 = lines => {
|
|
132
|
+
return lines.join(NewLine$1);
|
|
168
133
|
};
|
|
169
|
-
const
|
|
170
|
-
|
|
134
|
+
const RE_AT = /^\s+at/;
|
|
135
|
+
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
136
|
+
const isNormalStackLine = line => {
|
|
137
|
+
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
171
138
|
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return rpc.invoke(method, ...params);
|
|
185
|
-
},
|
|
186
|
-
// @ts-ignore
|
|
187
|
-
invokeAndTransfer(method, ...params) {
|
|
188
|
-
const rpc = get$2(rpcId);
|
|
189
|
-
// @ts-ignore
|
|
190
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
191
|
-
},
|
|
192
|
-
registerMockRpc(commandMap) {
|
|
193
|
-
const mockRpc = createMockRpc({
|
|
194
|
-
commandMap
|
|
195
|
-
});
|
|
196
|
-
set$3(rpcId, mockRpc);
|
|
197
|
-
// @ts-ignore
|
|
198
|
-
mockRpc[Symbol.dispose] = () => {
|
|
199
|
-
remove$1(rpcId);
|
|
200
|
-
};
|
|
201
|
-
// @ts-ignore
|
|
202
|
-
return mockRpc;
|
|
203
|
-
},
|
|
204
|
-
set(rpc) {
|
|
205
|
-
set$3(rpcId, rpc);
|
|
139
|
+
const getDetails = lines => {
|
|
140
|
+
const index = lines.findIndex(isNormalStackLine);
|
|
141
|
+
if (index === -1) {
|
|
142
|
+
return {
|
|
143
|
+
actualMessage: joinLines$1(lines),
|
|
144
|
+
rest: []
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
let lastIndex = index - 1;
|
|
148
|
+
while (++lastIndex < lines.length) {
|
|
149
|
+
if (!isNormalStackLine(lines[lastIndex])) {
|
|
150
|
+
break;
|
|
206
151
|
}
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
actualMessage: lines[index - 1],
|
|
155
|
+
rest: lines.slice(index, lastIndex)
|
|
207
156
|
};
|
|
208
157
|
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
invoke: invoke$2,
|
|
212
|
-
set: set$2
|
|
213
|
-
} = create$b(EditorWorker);
|
|
214
|
-
const getLines = async editorUid => {
|
|
215
|
-
const lines = await invoke$2('Editor.getLines2', editorUid);
|
|
216
|
-
return lines;
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const {
|
|
220
|
-
invoke: invoke$1,
|
|
221
|
-
invokeAndTransfer,
|
|
222
|
-
set: set$1
|
|
223
|
-
} = create$b(RendererWorker);
|
|
224
|
-
const sendMessagePortToEditorWorker = async (port, rpcId) => {
|
|
225
|
-
const command = 'HandleMessagePort.handleMessagePort';
|
|
226
|
-
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
|
|
227
|
-
};
|
|
228
|
-
const setFocus = key => {
|
|
229
|
-
return invoke$1('Focus.setFocus', key);
|
|
230
|
-
};
|
|
231
|
-
const getFileIcon = async options => {
|
|
232
|
-
return invoke$1('IconTheme.getFileIcon', options);
|
|
158
|
+
const splitLines$2 = lines => {
|
|
159
|
+
return lines.split(NewLine$1);
|
|
233
160
|
};
|
|
234
|
-
const
|
|
235
|
-
|
|
161
|
+
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
162
|
+
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
163
|
+
const isMessageCodeBlockStartIndex = line => {
|
|
164
|
+
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
236
165
|
};
|
|
237
|
-
const
|
|
238
|
-
return
|
|
166
|
+
const isMessageCodeBlockEndIndex = line => {
|
|
167
|
+
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
239
168
|
};
|
|
240
|
-
const
|
|
241
|
-
|
|
169
|
+
const getMessageCodeBlock = stderr => {
|
|
170
|
+
const lines = splitLines$2(stderr);
|
|
171
|
+
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
172
|
+
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
173
|
+
const relevantLines = lines.slice(startIndex, endIndex);
|
|
174
|
+
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
175
|
+
return relevantMessage;
|
|
242
176
|
};
|
|
243
|
-
const
|
|
244
|
-
|
|
177
|
+
const isModuleNotFoundMessage = line => {
|
|
178
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
245
179
|
};
|
|
246
|
-
const
|
|
247
|
-
|
|
180
|
+
const getModuleNotFoundError = stderr => {
|
|
181
|
+
const lines = splitLines$2(stderr);
|
|
182
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
183
|
+
const message = lines[messageIndex];
|
|
184
|
+
return {
|
|
185
|
+
code: ERR_MODULE_NOT_FOUND,
|
|
186
|
+
message
|
|
187
|
+
};
|
|
248
188
|
};
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
189
|
+
const isModuleNotFoundError = stderr => {
|
|
190
|
+
if (!stderr) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
253
194
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
195
|
+
const isModulesSyntaxError = stderr => {
|
|
196
|
+
if (!stderr) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
258
200
|
};
|
|
259
|
-
|
|
260
|
-
const
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
const minimumSliderSize = 20;
|
|
264
|
-
|
|
265
|
-
const Default$1 = 0;
|
|
266
|
-
const Finished = 2;
|
|
267
|
-
|
|
268
|
-
const toCommandId = key => {
|
|
269
|
-
const dotIndex = key.indexOf('.');
|
|
270
|
-
return key.slice(dotIndex + 1);
|
|
201
|
+
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
202
|
+
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
203
|
+
const isUnhelpfulNativeModuleError = stderr => {
|
|
204
|
+
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
271
205
|
};
|
|
272
|
-
const
|
|
273
|
-
const
|
|
274
|
-
const commandMapRef = {};
|
|
206
|
+
const getNativeModuleErrorMessage = stderr => {
|
|
207
|
+
const message = getMessageCodeBlock(stderr);
|
|
275
208
|
return {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
},
|
|
279
|
-
set(uid, oldState, newState) {
|
|
280
|
-
states[uid] = {
|
|
281
|
-
oldState,
|
|
282
|
-
newState
|
|
283
|
-
};
|
|
284
|
-
},
|
|
285
|
-
dispose(uid) {
|
|
286
|
-
delete states[uid];
|
|
287
|
-
},
|
|
288
|
-
getKeys() {
|
|
289
|
-
return Object.keys(states).map(key => {
|
|
290
|
-
return Number.parseInt(key);
|
|
291
|
-
});
|
|
292
|
-
},
|
|
293
|
-
clear() {
|
|
294
|
-
for (const key of Object.keys(states)) {
|
|
295
|
-
delete states[key];
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
wrapCommand(fn) {
|
|
299
|
-
const wrapped = async (uid, ...args) => {
|
|
300
|
-
const {
|
|
301
|
-
oldState,
|
|
302
|
-
newState
|
|
303
|
-
} = states[uid];
|
|
304
|
-
const newerState = await fn(newState, ...args);
|
|
305
|
-
if (oldState === newerState || newState === newerState) {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
const latest = states[uid];
|
|
309
|
-
states[uid] = {
|
|
310
|
-
oldState: latest.oldState,
|
|
311
|
-
newState: newerState
|
|
312
|
-
};
|
|
313
|
-
};
|
|
314
|
-
return wrapped;
|
|
315
|
-
},
|
|
316
|
-
wrapGetter(fn) {
|
|
317
|
-
const wrapped = (uid, ...args) => {
|
|
318
|
-
const {
|
|
319
|
-
newState
|
|
320
|
-
} = states[uid];
|
|
321
|
-
return fn(newState, ...args);
|
|
322
|
-
};
|
|
323
|
-
return wrapped;
|
|
324
|
-
},
|
|
325
|
-
diff(uid, modules, numbers) {
|
|
326
|
-
const {
|
|
327
|
-
oldState,
|
|
328
|
-
newState
|
|
329
|
-
} = states[uid];
|
|
330
|
-
const diffResult = [];
|
|
331
|
-
for (let i = 0; i < modules.length; i++) {
|
|
332
|
-
const fn = modules[i];
|
|
333
|
-
if (!fn(oldState, newState)) {
|
|
334
|
-
diffResult.push(numbers[i]);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
return diffResult;
|
|
338
|
-
},
|
|
339
|
-
getCommandIds() {
|
|
340
|
-
const keys = Object.keys(commandMapRef);
|
|
341
|
-
const ids = keys.map(toCommandId);
|
|
342
|
-
return ids;
|
|
343
|
-
},
|
|
344
|
-
registerCommands(commandMap) {
|
|
345
|
-
Object.assign(commandMapRef, commandMap);
|
|
346
|
-
}
|
|
209
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
210
|
+
message: `Incompatible native node module: ${message}`
|
|
347
211
|
};
|
|
348
212
|
};
|
|
349
|
-
|
|
350
|
-
const {
|
|
351
|
-
dispose: dispose$1,
|
|
352
|
-
get: get$1,
|
|
353
|
-
getCommandIds,
|
|
354
|
-
registerCommands,
|
|
355
|
-
set,
|
|
356
|
-
wrapCommand
|
|
357
|
-
} = create$a();
|
|
358
|
-
|
|
359
|
-
const create$9 = ({
|
|
360
|
-
headerHeight = 0,
|
|
361
|
-
itemHeight,
|
|
362
|
-
minimumSliderSize = 20
|
|
363
|
-
}) => {
|
|
213
|
+
const getModuleSyntaxError = () => {
|
|
364
214
|
return {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
focusedIndex: -1,
|
|
368
|
-
headerHeight,
|
|
369
|
-
itemHeight,
|
|
370
|
-
items: [],
|
|
371
|
-
maxLineY: 0,
|
|
372
|
-
minimumSliderSize,
|
|
373
|
-
minLineY: 0,
|
|
374
|
-
scrollBarActive: false,
|
|
375
|
-
scrollBarHeight: 0,
|
|
376
|
-
touchDifference: 0,
|
|
377
|
-
touchOffsetY: 0,
|
|
378
|
-
touchTimeStamp: 0
|
|
215
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
216
|
+
message: `ES Modules are not supported in electron`
|
|
379
217
|
};
|
|
380
218
|
};
|
|
381
|
-
const
|
|
382
|
-
if (
|
|
383
|
-
return
|
|
219
|
+
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
220
|
+
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
221
|
+
return getNativeModuleErrorMessage(stderr);
|
|
384
222
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
223
|
+
if (isModulesSyntaxError(stderr)) {
|
|
224
|
+
return getModuleSyntaxError();
|
|
225
|
+
}
|
|
226
|
+
if (isModuleNotFoundError(stderr)) {
|
|
227
|
+
return getModuleNotFoundError(stderr);
|
|
228
|
+
}
|
|
229
|
+
const lines = splitLines$2(stderr);
|
|
390
230
|
const {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
items
|
|
395
|
-
} = state;
|
|
396
|
-
const listHeight = getListHeight$1(height, headerHeight);
|
|
397
|
-
const itemsLength = items.length;
|
|
398
|
-
const finalDeltaY = itemsLength * itemHeight - listHeight;
|
|
399
|
-
if (deltaY < 0) {
|
|
400
|
-
deltaY = 0;
|
|
401
|
-
} else if (deltaY > finalDeltaY) {
|
|
402
|
-
deltaY = Math.max(finalDeltaY, 0);
|
|
403
|
-
}
|
|
404
|
-
if (state.deltaY === deltaY) {
|
|
405
|
-
return state;
|
|
406
|
-
}
|
|
407
|
-
const minLineY = Math.round(deltaY / itemHeight);
|
|
408
|
-
const maxLineY = minLineY + Math.round(listHeight / itemHeight);
|
|
409
|
-
number(minLineY);
|
|
410
|
-
number(maxLineY);
|
|
231
|
+
actualMessage,
|
|
232
|
+
rest
|
|
233
|
+
} = getDetails(lines);
|
|
411
234
|
return {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
minLineY
|
|
416
|
-
};
|
|
417
|
-
};
|
|
418
|
-
const handleWheel = (state, deltaMode, deltaY) => {
|
|
419
|
-
object(state);
|
|
420
|
-
number(deltaMode);
|
|
421
|
-
number(deltaY);
|
|
422
|
-
return setDeltaY(state, state.deltaY + deltaY);
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
const create$8 = (uid, uri, listItemHeight, x, y, width, height, platform, args, workspaceUri, assetDir) => {
|
|
426
|
-
const state = {
|
|
427
|
-
allowEmptyResult: false,
|
|
428
|
-
cursorOffset: 0,
|
|
429
|
-
height: 300,
|
|
430
|
-
icons: [],
|
|
431
|
-
maxVisibleItems: 12,
|
|
432
|
-
picks: [],
|
|
433
|
-
recentPickIds: Object.create(null),
|
|
434
|
-
recentPicks: [],
|
|
435
|
-
state: Default$1,
|
|
436
|
-
top: 50,
|
|
437
|
-
uid,
|
|
438
|
-
uri,
|
|
439
|
-
versionId: 0,
|
|
440
|
-
warned: [],
|
|
441
|
-
width: 600,
|
|
442
|
-
workspaceUri,
|
|
443
|
-
...create$9({
|
|
444
|
-
headerHeight: 38,
|
|
445
|
-
itemHeight: listItemHeight,
|
|
446
|
-
minimumSliderSize: minimumSliderSize
|
|
447
|
-
}),
|
|
448
|
-
args,
|
|
449
|
-
assetDir,
|
|
450
|
-
fileIconCache: Object.create(null),
|
|
451
|
-
focused: false,
|
|
452
|
-
inputSource: User,
|
|
453
|
-
placeholder: '',
|
|
454
|
-
platform,
|
|
455
|
-
value: ''
|
|
235
|
+
code: '',
|
|
236
|
+
message: actualMessage,
|
|
237
|
+
stack: rest
|
|
456
238
|
};
|
|
457
|
-
set(uid, state, state);
|
|
458
239
|
};
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
const diffType$2 = Height;
|
|
479
|
-
const isEqual$2 = (oldState, newState) => {
|
|
480
|
-
return oldState.items.length === newState.items.length;
|
|
481
|
-
};
|
|
482
|
-
|
|
483
|
-
const diffType$1 = RenderItems;
|
|
484
|
-
const isEqual$1 = (oldState, newState) => {
|
|
485
|
-
return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex;
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
const diffType = RenderValue;
|
|
489
|
-
const isEqual = (oldState, newState) => {
|
|
490
|
-
return newState.inputSource === User || oldState.value === newState.value;
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
const modules = [isEqual$2, isEqual$1, isEqual, isEqual$3, isEqual$4];
|
|
494
|
-
const numbers = [diffType$2, diffType$1, diffType, diffType$3, diffType$4];
|
|
495
|
-
|
|
496
|
-
const diff = (oldState, newState) => {
|
|
497
|
-
const diffResult = [];
|
|
498
|
-
for (let i = 0; i < modules.length; i++) {
|
|
499
|
-
const fn = modules[i];
|
|
500
|
-
if (!fn(oldState, newState)) {
|
|
501
|
-
diffResult.push(numbers[i]);
|
|
240
|
+
class IpcError extends VError {
|
|
241
|
+
// @ts-ignore
|
|
242
|
+
constructor(betterMessage, stdout = '', stderr = '') {
|
|
243
|
+
if (stdout || stderr) {
|
|
244
|
+
// @ts-ignore
|
|
245
|
+
const {
|
|
246
|
+
code,
|
|
247
|
+
message,
|
|
248
|
+
stack
|
|
249
|
+
} = getHelpfulChildProcessError(stdout, stderr);
|
|
250
|
+
const cause = new Error(message);
|
|
251
|
+
// @ts-ignore
|
|
252
|
+
cause.code = code;
|
|
253
|
+
cause.stack = stack;
|
|
254
|
+
super(cause, betterMessage);
|
|
255
|
+
} else {
|
|
256
|
+
super(betterMessage);
|
|
502
257
|
}
|
|
258
|
+
// @ts-ignore
|
|
259
|
+
this.name = 'IpcError';
|
|
260
|
+
// @ts-ignore
|
|
261
|
+
this.stdout = stdout;
|
|
262
|
+
// @ts-ignore
|
|
263
|
+
this.stderr = stderr;
|
|
503
264
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
const {
|
|
509
|
-
newState,
|
|
510
|
-
oldState
|
|
511
|
-
} = get$1(uid);
|
|
512
|
-
return diff(oldState, newState);
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
const dispose = uid => {
|
|
516
|
-
dispose$1(uid);
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
const setColorTheme = id => {
|
|
520
|
-
return invoke$1(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
|
|
521
|
-
};
|
|
522
|
-
|
|
523
|
-
const focusPick$1 = async pick => {
|
|
524
|
-
const {
|
|
525
|
-
label
|
|
526
|
-
} = pick;
|
|
527
|
-
await setColorTheme(label);
|
|
265
|
+
}
|
|
266
|
+
const readyMessage = 'ready';
|
|
267
|
+
const getData$2 = event => {
|
|
268
|
+
return event.data;
|
|
528
269
|
};
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
const File$2 = 3;
|
|
534
|
-
const GoToColumn$1 = 4;
|
|
535
|
-
const GoToLine$2 = 5;
|
|
536
|
-
const Help$2 = 6;
|
|
537
|
-
const Recent$1 = 7;
|
|
538
|
-
const Symbol$3 = 8;
|
|
539
|
-
const View$3 = 9;
|
|
540
|
-
const WorkspaceSymbol$2 = 10;
|
|
541
|
-
const EveryThing$1 = 100;
|
|
542
|
-
|
|
543
|
-
const noop$1 = async () => {};
|
|
544
|
-
const getFn$2 = id => {
|
|
545
|
-
switch (id) {
|
|
546
|
-
case ColorTheme$1:
|
|
547
|
-
return focusPick$1;
|
|
548
|
-
default:
|
|
549
|
-
return noop$1;
|
|
270
|
+
const listen$7 = () => {
|
|
271
|
+
// @ts-ignore
|
|
272
|
+
if (typeof WorkerGlobalScope === 'undefined') {
|
|
273
|
+
throw new TypeError('module is not in web worker scope');
|
|
550
274
|
}
|
|
275
|
+
return globalThis;
|
|
551
276
|
};
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
return fn(pick);
|
|
555
|
-
};
|
|
556
|
-
|
|
557
|
-
const getIconsCached = (paths, fileIconCache) => {
|
|
558
|
-
return paths.map(path => fileIconCache[path]);
|
|
277
|
+
const signal$8 = global => {
|
|
278
|
+
global.postMessage(readyMessage);
|
|
559
279
|
};
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
for (const dirent of dirents) {
|
|
564
|
-
if (!dirent.path) {
|
|
565
|
-
continue;
|
|
566
|
-
}
|
|
567
|
-
if (!(dirent.path in fileIconCache)) {
|
|
568
|
-
missingRequests.push({
|
|
569
|
-
name: dirent.name,
|
|
570
|
-
path: dirent.path,
|
|
571
|
-
type: dirent.type
|
|
572
|
-
});
|
|
573
|
-
}
|
|
280
|
+
class IpcChildWithModuleWorker extends Ipc {
|
|
281
|
+
getData(event) {
|
|
282
|
+
return getData$2(event);
|
|
574
283
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
const None$2 = 0;
|
|
579
|
-
const Directory = 3;
|
|
580
|
-
const File$1 = 7;
|
|
581
|
-
|
|
582
|
-
const requestFileIcon = async request => {
|
|
583
|
-
if (!request.name) {
|
|
584
|
-
return '';
|
|
585
|
-
}
|
|
586
|
-
return request.type === File$1 ? getFileIcon({
|
|
587
|
-
name: request.name
|
|
588
|
-
}) : getFolderIcon({
|
|
589
|
-
name: request.name
|
|
590
|
-
});
|
|
591
|
-
};
|
|
592
|
-
const requestFileIcons = async requests => {
|
|
593
|
-
const promises = requests.map(requestFileIcon);
|
|
594
|
-
return Promise.all(promises);
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
const updateIconCache = (iconCache, missingRequests, newIcons) => {
|
|
598
|
-
if (missingRequests.length === 0) {
|
|
599
|
-
return iconCache;
|
|
284
|
+
send(message) {
|
|
285
|
+
// @ts-ignore
|
|
286
|
+
this._rawIpc.postMessage(message);
|
|
600
287
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
const request = missingRequests[i];
|
|
606
|
-
const icon = newIcons[i];
|
|
607
|
-
newFileIconCache[request.path] = icon;
|
|
288
|
+
sendAndTransfer(message) {
|
|
289
|
+
const transfer = getTransferrables(message);
|
|
290
|
+
// @ts-ignore
|
|
291
|
+
this._rawIpc.postMessage(message, transfer);
|
|
608
292
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
const getPath = dirent => {
|
|
613
|
-
return dirent.path;
|
|
614
|
-
};
|
|
615
|
-
const toDirent = pick => {
|
|
616
|
-
const dirent = {
|
|
617
|
-
name: pick.label,
|
|
618
|
-
path: pick.uri,
|
|
619
|
-
type: pick.direntType
|
|
620
|
-
};
|
|
621
|
-
return dirent;
|
|
622
|
-
};
|
|
623
|
-
const getQuickPickFileIcons = async (items, fileIconCache) => {
|
|
624
|
-
const dirents = items.map(toDirent);
|
|
625
|
-
const missingRequests = getMissingIconRequests(dirents, fileIconCache);
|
|
626
|
-
const newIcons = await requestFileIcons(missingRequests);
|
|
627
|
-
const newFileIconCache = updateIconCache(fileIconCache, missingRequests, newIcons);
|
|
628
|
-
const paths = dirents.map(getPath);
|
|
629
|
-
const icons = getIconsCached(paths, newFileIconCache);
|
|
630
|
-
return {
|
|
631
|
-
icons,
|
|
632
|
-
newFileIconCache
|
|
633
|
-
};
|
|
634
|
-
};
|
|
635
|
-
|
|
636
|
-
const focusIndex = async (state, index) => {
|
|
637
|
-
const {
|
|
638
|
-
fileIconCache,
|
|
639
|
-
items,
|
|
640
|
-
maxLineY,
|
|
641
|
-
maxVisibleItems,
|
|
642
|
-
minLineY,
|
|
643
|
-
providerId
|
|
644
|
-
} = state;
|
|
645
|
-
await focusPick(providerId, items[index]);
|
|
646
|
-
if (index < minLineY + 1) {
|
|
647
|
-
const minLineY = index;
|
|
648
|
-
const maxLineY = Math.min(index + maxVisibleItems, items.length - 1);
|
|
649
|
-
const sliced = items.slice(minLineY, maxLineY);
|
|
650
|
-
const {
|
|
651
|
-
icons,
|
|
652
|
-
newFileIconCache
|
|
653
|
-
} = await getQuickPickFileIcons(sliced, fileIconCache);
|
|
654
|
-
|
|
655
|
-
// TODO need to scroll up
|
|
656
|
-
return {
|
|
657
|
-
...state,
|
|
658
|
-
fileIconCache: newFileIconCache,
|
|
659
|
-
focusedIndex: index,
|
|
660
|
-
icons,
|
|
661
|
-
maxLineY,
|
|
662
|
-
minLineY
|
|
663
|
-
};
|
|
293
|
+
dispose() {
|
|
294
|
+
// ignore
|
|
664
295
|
}
|
|
665
|
-
|
|
666
|
-
//
|
|
667
|
-
const maxLineY = index + 1;
|
|
668
|
-
const minLineY = Math.max(maxLineY - maxVisibleItems, 0);
|
|
669
|
-
const sliced = items.slice(minLineY, maxLineY);
|
|
670
|
-
const {
|
|
671
|
-
icons,
|
|
672
|
-
newFileIconCache
|
|
673
|
-
} = await getQuickPickFileIcons(sliced, fileIconCache);
|
|
674
|
-
return {
|
|
675
|
-
...state,
|
|
676
|
-
fileIconCache: newFileIconCache,
|
|
677
|
-
focusedIndex: index,
|
|
678
|
-
icons,
|
|
679
|
-
maxLineY,
|
|
680
|
-
minLineY
|
|
681
|
-
};
|
|
296
|
+
onClose(callback) {
|
|
297
|
+
// ignore
|
|
682
298
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
return
|
|
689
|
-
...state,
|
|
690
|
-
fileIconCache: newFileIconCache,
|
|
691
|
-
focusedIndex: index,
|
|
692
|
-
icons
|
|
693
|
-
};
|
|
694
|
-
};
|
|
695
|
-
|
|
696
|
-
const first = () => {
|
|
697
|
-
return 0;
|
|
698
|
-
};
|
|
699
|
-
const last = items => {
|
|
700
|
-
return items.length - 1;
|
|
701
|
-
};
|
|
702
|
-
const next = (items, index) => {
|
|
703
|
-
return (index + 1) % items.length;
|
|
704
|
-
};
|
|
705
|
-
const previous = (items, index) => {
|
|
706
|
-
return index === 0 ? items.length - 1 : index - 1;
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
const focusFirst = state => {
|
|
710
|
-
return focusIndex(state, first());
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
const focusLast = state => {
|
|
714
|
-
const {
|
|
715
|
-
items
|
|
716
|
-
} = state;
|
|
717
|
-
return focusIndex(state, last(items));
|
|
718
|
-
};
|
|
719
|
-
|
|
720
|
-
const focusNext = state => {
|
|
721
|
-
const {
|
|
722
|
-
focusedIndex,
|
|
723
|
-
items
|
|
724
|
-
} = state;
|
|
725
|
-
const nextIndex = next(items, focusedIndex);
|
|
726
|
-
return focusIndex(state, nextIndex);
|
|
299
|
+
onMessage(callback) {
|
|
300
|
+
this._rawIpc.addEventListener('message', callback);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const wrap$f = global => {
|
|
304
|
+
return new IpcChildWithModuleWorker(global);
|
|
727
305
|
};
|
|
728
|
-
|
|
729
|
-
const focusPrevious = state => {
|
|
306
|
+
const waitForFirstMessage = async port => {
|
|
730
307
|
const {
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
} =
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
};
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
const Span = 8;
|
|
741
|
-
const Text = 12;
|
|
742
|
-
const Img = 17;
|
|
743
|
-
|
|
744
|
-
const SetDom2 = 'Viewlet.setDom2';
|
|
745
|
-
const SetPatches = 'Viewlet.setPatches';
|
|
746
|
-
|
|
747
|
-
const FocusQuickPickInput = 20;
|
|
748
|
-
|
|
749
|
-
const Enter = 3;
|
|
750
|
-
const Escape = 8;
|
|
751
|
-
const PageUp = 10;
|
|
752
|
-
const PageDown = 11;
|
|
753
|
-
const UpArrow = 14;
|
|
754
|
-
const DownArrow = 16;
|
|
755
|
-
|
|
756
|
-
const getKeyBindings = () => {
|
|
757
|
-
return [{
|
|
758
|
-
args: ['QuickPick'],
|
|
759
|
-
command: 'Viewlet.closeWidget',
|
|
760
|
-
key: Escape,
|
|
761
|
-
when: FocusQuickPickInput
|
|
762
|
-
}, {
|
|
763
|
-
command: 'QuickPick.focusPrevious',
|
|
764
|
-
key: UpArrow,
|
|
765
|
-
when: FocusQuickPickInput
|
|
766
|
-
}, {
|
|
767
|
-
command: 'QuickPick.focusNext',
|
|
768
|
-
key: DownArrow,
|
|
769
|
-
when: FocusQuickPickInput
|
|
770
|
-
}, {
|
|
771
|
-
command: 'QuickPick.focusFirst',
|
|
772
|
-
key: PageUp,
|
|
773
|
-
when: FocusQuickPickInput
|
|
774
|
-
}, {
|
|
775
|
-
command: 'QuickPick.focusLast',
|
|
776
|
-
key: PageDown,
|
|
777
|
-
when: FocusQuickPickInput
|
|
778
|
-
}, {
|
|
779
|
-
command: 'QuickPick.selectCurrentIndex',
|
|
780
|
-
key: Enter,
|
|
781
|
-
when: FocusQuickPickInput
|
|
782
|
-
}];
|
|
308
|
+
promise,
|
|
309
|
+
resolve
|
|
310
|
+
} = Promise.withResolvers();
|
|
311
|
+
port.addEventListener('message', resolve, {
|
|
312
|
+
once: true
|
|
313
|
+
});
|
|
314
|
+
const event = await promise;
|
|
315
|
+
// @ts-ignore
|
|
316
|
+
return event.data;
|
|
783
317
|
};
|
|
784
|
-
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
cursorOffset: before.length,
|
|
792
|
-
newValue
|
|
793
|
-
};
|
|
318
|
+
const listen$6 = async () => {
|
|
319
|
+
const parentIpcRaw = listen$7();
|
|
320
|
+
signal$8(parentIpcRaw);
|
|
321
|
+
const parentIpc = wrap$f(parentIpcRaw);
|
|
322
|
+
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
323
|
+
if (firstMessage.method !== 'initialize') {
|
|
324
|
+
throw new IpcError('unexpected first message');
|
|
794
325
|
}
|
|
795
|
-
const
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
};
|
|
802
|
-
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
if (selectionStart === selectionEnd) {
|
|
806
|
-
const after = value.slice(selectionEnd + 1);
|
|
807
|
-
const newValue = before + after;
|
|
808
|
-
return {
|
|
809
|
-
cursorOffset: selectionStart,
|
|
810
|
-
newValue
|
|
811
|
-
};
|
|
326
|
+
const type = firstMessage.params[0];
|
|
327
|
+
if (type === 'message-port') {
|
|
328
|
+
parentIpc.send({
|
|
329
|
+
id: firstMessage.id,
|
|
330
|
+
jsonrpc: '2.0',
|
|
331
|
+
result: null
|
|
332
|
+
});
|
|
333
|
+
parentIpc.dispose();
|
|
334
|
+
const port = firstMessage.params[1];
|
|
335
|
+
return port;
|
|
812
336
|
}
|
|
813
|
-
|
|
814
|
-
const newValue = before + after;
|
|
815
|
-
return {
|
|
816
|
-
cursorOffset: selectionStart,
|
|
817
|
-
newValue
|
|
818
|
-
};
|
|
819
|
-
};
|
|
820
|
-
|
|
821
|
-
const RE_ALPHA_NUMERIC = /[a-z\d]/i;
|
|
822
|
-
const isAlphaNumeric = character => {
|
|
823
|
-
return RE_ALPHA_NUMERIC.test(character);
|
|
337
|
+
return globalThis;
|
|
824
338
|
};
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
if (selectionStart === selectionEnd) {
|
|
829
|
-
let startIndex = Math.max(selectionStart - 1, 0);
|
|
830
|
-
while (startIndex > 0 && isAlphaNumeric(value[startIndex])) {
|
|
831
|
-
startIndex--;
|
|
832
|
-
}
|
|
833
|
-
const before = value.slice(0, startIndex);
|
|
834
|
-
const newValue = before + after;
|
|
835
|
-
return {
|
|
836
|
-
cursorOffset: before.length,
|
|
837
|
-
newValue
|
|
838
|
-
};
|
|
339
|
+
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
340
|
+
getData(event) {
|
|
341
|
+
return getData$2(event);
|
|
839
342
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
if (selectionStart === selectionEnd) {
|
|
851
|
-
let startIndex = Math.min(selectionStart + 1, value.length - 1);
|
|
852
|
-
while (startIndex < value.length && isAlphaNumeric(value[startIndex])) {
|
|
853
|
-
startIndex++;
|
|
343
|
+
send(message) {
|
|
344
|
+
this._rawIpc.postMessage(message);
|
|
345
|
+
}
|
|
346
|
+
sendAndTransfer(message) {
|
|
347
|
+
const transfer = getTransferrables(message);
|
|
348
|
+
this._rawIpc.postMessage(message, transfer);
|
|
349
|
+
}
|
|
350
|
+
dispose() {
|
|
351
|
+
if (this._rawIpc.close) {
|
|
352
|
+
this._rawIpc.close();
|
|
854
353
|
}
|
|
855
|
-
const after = value.slice(startIndex);
|
|
856
|
-
const newValue = before + after;
|
|
857
|
-
return {
|
|
858
|
-
cursorOffset: before.length,
|
|
859
|
-
newValue
|
|
860
|
-
};
|
|
861
354
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
return {
|
|
865
|
-
cursorOffset: selectionStart,
|
|
866
|
-
newValue
|
|
867
|
-
};
|
|
868
|
-
};
|
|
869
|
-
|
|
870
|
-
const getNewValueInsertText = (value, selectionStart, selectionEnd, data) => {
|
|
871
|
-
if (selectionStart === value.length) {
|
|
872
|
-
const newValue = value + data;
|
|
873
|
-
return {
|
|
874
|
-
cursorOffset: newValue.length,
|
|
875
|
-
newValue
|
|
876
|
-
};
|
|
355
|
+
onClose(callback) {
|
|
356
|
+
// ignore
|
|
877
357
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
return {
|
|
882
|
-
cursorOffset: selectionStart + data.length,
|
|
883
|
-
newValue
|
|
884
|
-
};
|
|
885
|
-
};
|
|
886
|
-
|
|
887
|
-
const getNewValueInsertCompositionText = (value, selectionStart, selectionEnd, data) => {
|
|
888
|
-
return getNewValueInsertText(value, selectionStart, selectionEnd, data);
|
|
889
|
-
};
|
|
890
|
-
|
|
891
|
-
const getNewValueInsertLineBreak = (value, selectionStart, selectionEnd, data) => {
|
|
892
|
-
return {
|
|
893
|
-
cursorOffset: selectionEnd,
|
|
894
|
-
newValue: value
|
|
895
|
-
};
|
|
896
|
-
};
|
|
897
|
-
|
|
898
|
-
const InsertText = 'insertText';
|
|
899
|
-
const DeleteContentBackward = 'deleteContentBackward';
|
|
900
|
-
const DeleteContentForward = 'deleteContentForward';
|
|
901
|
-
const DeleteWordForward = 'deleteWordForward';
|
|
902
|
-
const DeleteWordBackward = 'deleteWordBackward';
|
|
903
|
-
const InsertLineBreak = 'insertLineBreak';
|
|
904
|
-
const InsertCompositionText = 'insertCompositionText';
|
|
905
|
-
const InsertFromPaste = 'insertFromPaste';
|
|
906
|
-
|
|
907
|
-
const getNewValueFunction = inputType => {
|
|
908
|
-
switch (inputType) {
|
|
909
|
-
case DeleteContentBackward:
|
|
910
|
-
return getNewValueDeleteContentBackward;
|
|
911
|
-
case DeleteContentForward:
|
|
912
|
-
return getNewValueDeleteContentForward;
|
|
913
|
-
case DeleteWordBackward:
|
|
914
|
-
return getNewValueDeleteWordBackward;
|
|
915
|
-
case DeleteWordForward:
|
|
916
|
-
return getNewValueDeleteWordForward;
|
|
917
|
-
case InsertCompositionText:
|
|
918
|
-
return getNewValueInsertCompositionText;
|
|
919
|
-
case InsertFromPaste:
|
|
920
|
-
case InsertText:
|
|
921
|
-
return getNewValueInsertText;
|
|
922
|
-
case InsertLineBreak:
|
|
923
|
-
return getNewValueInsertLineBreak;
|
|
924
|
-
default:
|
|
925
|
-
throw new Error(`unsupported input type ${inputType}`);
|
|
358
|
+
onMessage(callback) {
|
|
359
|
+
this._rawIpc.addEventListener('message', callback);
|
|
360
|
+
this._rawIpc.start();
|
|
926
361
|
}
|
|
362
|
+
}
|
|
363
|
+
const wrap$e = port => {
|
|
364
|
+
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
927
365
|
};
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
};
|
|
933
|
-
|
|
934
|
-
const Diagonal = 1;
|
|
935
|
-
const Left = 2;
|
|
936
|
-
|
|
937
|
-
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
938
|
-
|
|
939
|
-
const createTable = size => {
|
|
940
|
-
const table = [];
|
|
941
|
-
for (let i = 0; i < size; i++) {
|
|
942
|
-
const row = new Uint8Array(size);
|
|
943
|
-
table.push(row);
|
|
944
|
-
}
|
|
945
|
-
return table;
|
|
946
|
-
};
|
|
947
|
-
const EmptyMatches = [];
|
|
948
|
-
const Dash = '-';
|
|
949
|
-
const Dot = '.';
|
|
950
|
-
const EmptyString = '';
|
|
951
|
-
const Space = ' ';
|
|
952
|
-
const Underline = '_';
|
|
953
|
-
const T = 't';
|
|
954
|
-
const isLowerCase = char => {
|
|
955
|
-
return char === char.toLowerCase();
|
|
956
|
-
};
|
|
957
|
-
const isUpperCase = char => {
|
|
958
|
-
return char === char.toUpperCase();
|
|
366
|
+
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
367
|
+
__proto__: null,
|
|
368
|
+
listen: listen$6,
|
|
369
|
+
wrap: wrap$e
|
|
959
370
|
};
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
case Underline:
|
|
966
|
-
case EmptyString:
|
|
967
|
-
case T:
|
|
968
|
-
case Space:
|
|
969
|
-
case Dot:
|
|
970
|
-
return true;
|
|
971
|
-
}
|
|
972
|
-
if (isLowerCase(columnCharBefore) && isUpperCase(columnChar)) {
|
|
973
|
-
return true;
|
|
371
|
+
const addListener = (emitter, type, callback) => {
|
|
372
|
+
if ('addEventListener' in emitter) {
|
|
373
|
+
emitter.addEventListener(type, callback);
|
|
374
|
+
} else {
|
|
375
|
+
emitter.on(type, callback);
|
|
974
376
|
}
|
|
975
|
-
return false;
|
|
976
377
|
};
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
}
|
|
983
|
-
const isMatch = rowChar === columnChar;
|
|
984
|
-
if (isMatch) {
|
|
985
|
-
if (isDiagonalMatch) {
|
|
986
|
-
return 8;
|
|
987
|
-
}
|
|
988
|
-
if (isGap(columnCharBefore, columnChar)) {
|
|
989
|
-
return 8;
|
|
990
|
-
}
|
|
991
|
-
return 5;
|
|
992
|
-
}
|
|
993
|
-
if (isGap(columnCharBefore, columnChar)) {
|
|
994
|
-
return 8;
|
|
995
|
-
}
|
|
996
|
-
return 5;
|
|
997
|
-
};
|
|
998
|
-
|
|
999
|
-
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1000
|
-
|
|
1001
|
-
const isPatternInWord = (patternLow, patternPos, patternLen, wordLow, wordPos, wordLen) => {
|
|
1002
|
-
while (patternPos < patternLen && wordPos < wordLen) {
|
|
1003
|
-
if (patternLow[patternPos] === wordLow[wordPos]) {
|
|
1004
|
-
patternPos += 1;
|
|
1005
|
-
}
|
|
1006
|
-
wordPos += 1;
|
|
1007
|
-
}
|
|
1008
|
-
return patternPos === patternLen; // pattern must be exhausted
|
|
1009
|
-
};
|
|
1010
|
-
|
|
1011
|
-
// based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
|
|
1012
|
-
const traceHighlights = (table, arrows, patternLength, wordLength) => {
|
|
1013
|
-
let row = patternLength;
|
|
1014
|
-
let column = wordLength;
|
|
1015
|
-
const matches = [];
|
|
1016
|
-
while (row >= 1 && column >= 1) {
|
|
1017
|
-
const arrow = arrows[row][column];
|
|
1018
|
-
if (arrow === Left) {
|
|
1019
|
-
column--;
|
|
1020
|
-
} else if (arrow === Diagonal) {
|
|
1021
|
-
row--;
|
|
1022
|
-
column--;
|
|
1023
|
-
const start = column + 1;
|
|
1024
|
-
while (row >= 1 && column >= 1) {
|
|
1025
|
-
const arrow = arrows[row][column];
|
|
1026
|
-
if (arrow === Left) {
|
|
1027
|
-
break;
|
|
1028
|
-
}
|
|
1029
|
-
if (arrow === Diagonal) {
|
|
1030
|
-
row--;
|
|
1031
|
-
column--;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
const end = column;
|
|
1035
|
-
matches.unshift(end, start);
|
|
1036
|
-
}
|
|
378
|
+
const removeListener = (emitter, type, callback) => {
|
|
379
|
+
if ('removeEventListener' in emitter) {
|
|
380
|
+
emitter.removeEventListener(type, callback);
|
|
381
|
+
} else {
|
|
382
|
+
emitter.off(type, callback);
|
|
1037
383
|
}
|
|
1038
|
-
matches.unshift(table[patternLength][wordLength - 1]);
|
|
1039
|
-
return matches;
|
|
1040
384
|
};
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
const
|
|
1047
|
-
const
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
const wordLower = word.toLowerCase();
|
|
1051
|
-
if (!isPatternInWord(patternLower, 0, patternLength, wordLower, 0, wordLength)) {
|
|
1052
|
-
return EmptyMatches;
|
|
1053
|
-
}
|
|
1054
|
-
let strongMatch = false;
|
|
1055
|
-
for (let row = 1; row < patternLength + 1; row++) {
|
|
1056
|
-
const rowChar = pattern[row - 1];
|
|
1057
|
-
const rowCharLow = patternLower[row - 1];
|
|
1058
|
-
for (let column = 1; column < wordLength + 1; column++) {
|
|
1059
|
-
const columnChar = word[column - 1];
|
|
1060
|
-
const columnCharLow = wordLower[column - 1];
|
|
1061
|
-
const columnCharBefore = word[column - 2] || '';
|
|
1062
|
-
const isDiagonalMatch = arrows[row - 1][column - 1] === Diagonal;
|
|
1063
|
-
const score = getScore(rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, isDiagonalMatch);
|
|
1064
|
-
if (row === 1 && score > 5) {
|
|
1065
|
-
strongMatch = true;
|
|
1066
|
-
}
|
|
1067
|
-
let diagonalScore = score + table[row - 1][column - 1];
|
|
1068
|
-
if (isDiagonalMatch && score !== -1) {
|
|
1069
|
-
diagonalScore += 2;
|
|
1070
|
-
}
|
|
1071
|
-
const leftScore = table[row][column - 1];
|
|
1072
|
-
if (leftScore > diagonalScore) {
|
|
1073
|
-
table[row][column] = leftScore;
|
|
1074
|
-
arrows[row][column] = Left;
|
|
1075
|
-
} else {
|
|
1076
|
-
table[row][column] = diagonalScore;
|
|
1077
|
-
arrows[row][column] = Diagonal;
|
|
1078
|
-
}
|
|
385
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
386
|
+
const {
|
|
387
|
+
promise,
|
|
388
|
+
resolve
|
|
389
|
+
} = Promise.withResolvers();
|
|
390
|
+
const listenerMap = Object.create(null);
|
|
391
|
+
const cleanup = value => {
|
|
392
|
+
for (const event of Object.keys(eventMap)) {
|
|
393
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
1079
394
|
}
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
const filterQuickPickItem = (pattern, word) => {
|
|
1089
|
-
const matches = fuzzySearch(pattern, word);
|
|
1090
|
-
return matches;
|
|
1091
|
-
};
|
|
1092
|
-
|
|
1093
|
-
const filterQuickPickItems = (items, value) => {
|
|
1094
|
-
if (!value) {
|
|
1095
|
-
return items;
|
|
1096
|
-
}
|
|
1097
|
-
const results = [];
|
|
1098
|
-
for (const item of items) {
|
|
1099
|
-
const filterValue = item.label;
|
|
1100
|
-
const matches = filterQuickPickItem(value, filterValue);
|
|
1101
|
-
if (matches.length > 0) {
|
|
1102
|
-
results.push({
|
|
1103
|
-
...item,
|
|
1104
|
-
matches
|
|
395
|
+
resolve(value);
|
|
396
|
+
};
|
|
397
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
398
|
+
const listener = event => {
|
|
399
|
+
cleanup({
|
|
400
|
+
event,
|
|
401
|
+
type
|
|
1105
402
|
});
|
|
1106
|
-
}
|
|
403
|
+
};
|
|
404
|
+
addListener(eventEmitter, event, listener);
|
|
405
|
+
listenerMap[event] = listener;
|
|
1107
406
|
}
|
|
1108
|
-
return
|
|
407
|
+
return promise;
|
|
1109
408
|
};
|
|
1110
|
-
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
const Help$1 = '?';
|
|
1118
|
-
const GoToColumn = '::';
|
|
1119
|
-
|
|
1120
|
-
const getQuickPickPrefix = value => {
|
|
1121
|
-
if (value.startsWith(Command)) {
|
|
1122
|
-
return Command;
|
|
1123
|
-
}
|
|
1124
|
-
if (value.startsWith(Symbol$2)) {
|
|
1125
|
-
return Symbol$2;
|
|
1126
|
-
}
|
|
1127
|
-
if (value.startsWith(WorkspaceSymbol$1)) {
|
|
1128
|
-
return WorkspaceSymbol$1;
|
|
409
|
+
const Message$1 = 3;
|
|
410
|
+
const create$5$1 = async ({
|
|
411
|
+
isMessagePortOpen,
|
|
412
|
+
messagePort
|
|
413
|
+
}) => {
|
|
414
|
+
if (!isMessagePort(messagePort)) {
|
|
415
|
+
throw new IpcError('port must be of type MessagePort');
|
|
1129
416
|
}
|
|
1130
|
-
if (
|
|
1131
|
-
return
|
|
417
|
+
if (isMessagePortOpen) {
|
|
418
|
+
return messagePort;
|
|
1132
419
|
}
|
|
1133
|
-
|
|
1134
|
-
|
|
420
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
421
|
+
message: Message$1
|
|
422
|
+
});
|
|
423
|
+
messagePort.start();
|
|
424
|
+
const {
|
|
425
|
+
event,
|
|
426
|
+
type
|
|
427
|
+
} = await eventPromise;
|
|
428
|
+
if (type !== Message$1) {
|
|
429
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
1135
430
|
}
|
|
1136
|
-
if (
|
|
1137
|
-
|
|
431
|
+
if (event.data !== readyMessage) {
|
|
432
|
+
throw new IpcError('unexpected first message');
|
|
1138
433
|
}
|
|
1139
|
-
return
|
|
1140
|
-
};
|
|
1141
|
-
|
|
1142
|
-
const noop = value => {
|
|
1143
|
-
return value;
|
|
1144
|
-
};
|
|
1145
|
-
const getFilterValueEverything = value => {
|
|
1146
|
-
const prefix = getQuickPickPrefix(value);
|
|
1147
|
-
const prefixLength = prefix.length;
|
|
1148
|
-
return value.slice(prefixLength).trim();
|
|
1149
|
-
};
|
|
1150
|
-
const getValueGoToColumn = value => {
|
|
1151
|
-
return '';
|
|
434
|
+
return messagePort;
|
|
1152
435
|
};
|
|
1153
|
-
const
|
|
1154
|
-
|
|
436
|
+
const signal$1 = messagePort => {
|
|
437
|
+
messagePort.start();
|
|
1155
438
|
};
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
case GoToColumn$1:
|
|
1161
|
-
return getValueGoToColumn;
|
|
1162
|
-
case GoToLine$2:
|
|
1163
|
-
return getValueGoToLine;
|
|
1164
|
-
default:
|
|
1165
|
-
return noop;
|
|
439
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
440
|
+
getData = getData$2;
|
|
441
|
+
send(message) {
|
|
442
|
+
this._rawIpc.postMessage(message);
|
|
1166
443
|
}
|
|
1167
|
-
|
|
1168
|
-
const
|
|
1169
|
-
|
|
1170
|
-
|
|
444
|
+
sendAndTransfer(message) {
|
|
445
|
+
const transfer = getTransferrables(message);
|
|
446
|
+
this._rawIpc.postMessage(message, transfer);
|
|
447
|
+
}
|
|
448
|
+
dispose() {
|
|
449
|
+
this._rawIpc.close();
|
|
1171
450
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
451
|
+
onMessage(callback) {
|
|
452
|
+
this._rawIpc.addEventListener('message', callback);
|
|
1174
453
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
454
|
+
onClose(callback) {}
|
|
455
|
+
}
|
|
456
|
+
const wrap$5 = messagePort => {
|
|
457
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
1178
458
|
};
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
459
|
+
const IpcParentWithMessagePort$1 = {
|
|
460
|
+
__proto__: null,
|
|
461
|
+
create: create$5$1,
|
|
462
|
+
signal: signal$1,
|
|
463
|
+
wrap: wrap$5
|
|
1184
464
|
};
|
|
1185
465
|
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
if (itemsLength === 0) {
|
|
1191
|
-
return itemHeight;
|
|
466
|
+
class CommandNotFoundError extends Error {
|
|
467
|
+
constructor(command) {
|
|
468
|
+
super(`Command not found ${command}`);
|
|
469
|
+
this.name = 'CommandNotFoundError';
|
|
1192
470
|
}
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
const getColorThemeNames = async (assetDir, platform) => {
|
|
1198
|
-
return invoke$1('ColorTheme.getColorThemeNames', assetDir, platform);
|
|
471
|
+
}
|
|
472
|
+
const commands = Object.create(null);
|
|
473
|
+
const register$1 = commandMap => {
|
|
474
|
+
Object.assign(commands, commandMap);
|
|
1199
475
|
};
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
const pick = {
|
|
1203
|
-
description: '',
|
|
1204
|
-
direntType: 0,
|
|
1205
|
-
fileIcon: '',
|
|
1206
|
-
icon: '',
|
|
1207
|
-
label: name,
|
|
1208
|
-
matches: [],
|
|
1209
|
-
uri: ''
|
|
1210
|
-
};
|
|
1211
|
-
return pick;
|
|
476
|
+
const getCommand = key => {
|
|
477
|
+
return commands[key];
|
|
1212
478
|
};
|
|
1213
|
-
const
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
return picks;
|
|
479
|
+
const execute = (command, ...args) => {
|
|
480
|
+
const fn = getCommand(command);
|
|
481
|
+
if (!fn) {
|
|
482
|
+
throw new CommandNotFoundError(command);
|
|
483
|
+
}
|
|
484
|
+
return fn(...args);
|
|
1220
485
|
};
|
|
1221
486
|
|
|
1222
|
-
const
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
const {
|
|
1227
|
-
code
|
|
1228
|
-
} = error;
|
|
1229
|
-
const {
|
|
1230
|
-
message
|
|
1231
|
-
} = error;
|
|
1232
|
-
const {
|
|
1233
|
-
stack
|
|
1234
|
-
} = error;
|
|
1235
|
-
const {
|
|
1236
|
-
name
|
|
1237
|
-
} = error;
|
|
1238
|
-
const errorInfo = {
|
|
1239
|
-
code,
|
|
1240
|
-
message,
|
|
1241
|
-
name,
|
|
1242
|
-
stack
|
|
1243
|
-
};
|
|
1244
|
-
await showErrorDialog$1(errorInfo);
|
|
1245
|
-
};
|
|
1246
|
-
const warn$1 = (...args) => {
|
|
1247
|
-
console.warn(...args);
|
|
487
|
+
const Two$1 = '2.0';
|
|
488
|
+
const callbacks = Object.create(null);
|
|
489
|
+
const get$1 = id => {
|
|
490
|
+
return callbacks[id];
|
|
1248
491
|
};
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
menuEntries: []
|
|
492
|
+
const remove$1 = id => {
|
|
493
|
+
delete callbacks[id];
|
|
1252
494
|
};
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
return entries || [];
|
|
1258
|
-
} catch {
|
|
1259
|
-
// ignore
|
|
495
|
+
class JsonRpcError extends Error {
|
|
496
|
+
constructor(message) {
|
|
497
|
+
super(message);
|
|
498
|
+
this.name = 'JsonRpcError';
|
|
1260
499
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
500
|
+
}
|
|
501
|
+
const NewLine = '\n';
|
|
502
|
+
const DomException = 'DOMException';
|
|
503
|
+
const ReferenceError$1 = 'ReferenceError';
|
|
504
|
+
const SyntaxError$1 = 'SyntaxError';
|
|
505
|
+
const TypeError$1 = 'TypeError';
|
|
506
|
+
const getErrorConstructor = (message, type) => {
|
|
507
|
+
if (type) {
|
|
508
|
+
switch (type) {
|
|
509
|
+
case DomException:
|
|
510
|
+
return DOMException;
|
|
511
|
+
case ReferenceError$1:
|
|
512
|
+
return ReferenceError;
|
|
513
|
+
case SyntaxError$1:
|
|
514
|
+
return SyntaxError;
|
|
515
|
+
case TypeError$1:
|
|
516
|
+
return TypeError;
|
|
517
|
+
default:
|
|
518
|
+
return Error;
|
|
519
|
+
}
|
|
1275
520
|
}
|
|
1276
|
-
if (
|
|
1277
|
-
|
|
521
|
+
if (message.startsWith('TypeError: ')) {
|
|
522
|
+
return TypeError;
|
|
1278
523
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
524
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
525
|
+
return SyntaxError;
|
|
526
|
+
}
|
|
527
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
528
|
+
return ReferenceError;
|
|
529
|
+
}
|
|
530
|
+
return Error;
|
|
1284
531
|
};
|
|
1285
|
-
const
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
return [];
|
|
532
|
+
const constructError = (message, type, name) => {
|
|
533
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
534
|
+
if (ErrorConstructor === DOMException && name) {
|
|
535
|
+
return new ErrorConstructor(message, name);
|
|
536
|
+
}
|
|
537
|
+
if (ErrorConstructor === Error) {
|
|
538
|
+
const error = new Error(message);
|
|
539
|
+
if (name && name !== 'VError') {
|
|
540
|
+
error.name = name;
|
|
1295
541
|
}
|
|
1296
|
-
|
|
1297
|
-
return mappedPicks;
|
|
1298
|
-
} catch (error) {
|
|
1299
|
-
console.error(`Failed to get extension picks: ${error}`);
|
|
1300
|
-
return [];
|
|
542
|
+
return error;
|
|
1301
543
|
}
|
|
544
|
+
return new ErrorConstructor(message);
|
|
1302
545
|
};
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1305
|
-
// @ts-ignore
|
|
1306
|
-
args: item.args,
|
|
1307
|
-
description: '',
|
|
1308
|
-
direntType: 0,
|
|
1309
|
-
fileIcon: '',
|
|
1310
|
-
icon: '',
|
|
1311
|
-
// @ts-ignore
|
|
1312
|
-
id: item.id,
|
|
1313
|
-
label: item.label,
|
|
1314
|
-
matches: [],
|
|
1315
|
-
uri: ''
|
|
1316
|
-
};
|
|
1317
|
-
// @ts-ignore
|
|
1318
|
-
return pick;
|
|
1319
|
-
};
|
|
1320
|
-
const getPicks$b = async (value, args, {
|
|
1321
|
-
assetDir = '',
|
|
1322
|
-
platform = 0
|
|
1323
|
-
} = {}) => {
|
|
1324
|
-
// TODO get picks in parallel
|
|
1325
|
-
const builtinPicks = await getBuiltinPicks();
|
|
1326
|
-
const extensionPicks = await getExtensionPicks(assetDir, platform);
|
|
1327
|
-
const allPicks = [...builtinPicks, ...extensionPicks];
|
|
1328
|
-
const converted = allPicks.map(toProtoVisibleItem$2);
|
|
1329
|
-
return converted;
|
|
1330
|
-
};
|
|
1331
|
-
|
|
1332
|
-
const toProtoVisibleItem$1 = item => {
|
|
1333
|
-
const {
|
|
1334
|
-
label
|
|
1335
|
-
} = item;
|
|
1336
|
-
return {
|
|
1337
|
-
description: '',
|
|
1338
|
-
direntType: 0,
|
|
1339
|
-
fileIcon: '',
|
|
1340
|
-
icon: '',
|
|
1341
|
-
label,
|
|
1342
|
-
matches: [],
|
|
1343
|
-
uri: ''
|
|
1344
|
-
};
|
|
1345
|
-
};
|
|
1346
|
-
const getPicks$a = async (searchValue, args) => {
|
|
1347
|
-
const items = args[1] || [];
|
|
1348
|
-
const mapped = items.map(toProtoVisibleItem$1);
|
|
1349
|
-
return mapped;
|
|
1350
|
-
};
|
|
1351
|
-
|
|
1352
|
-
const emptyMatches = [];
|
|
1353
|
-
|
|
1354
|
-
const getWorkspacePath = async () => {
|
|
1355
|
-
return invoke$1('Workspace.getPath');
|
|
546
|
+
const joinLines = lines => {
|
|
547
|
+
return lines.join(NewLine);
|
|
1356
548
|
};
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
const getProtocol = uri => {
|
|
1360
|
-
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
1361
|
-
if (protocolMatch) {
|
|
1362
|
-
return protocolMatch[1];
|
|
1363
|
-
}
|
|
1364
|
-
return '';
|
|
549
|
+
const splitLines$1 = lines => {
|
|
550
|
+
return lines.split(NewLine);
|
|
1365
551
|
};
|
|
1366
|
-
|
|
1367
|
-
const
|
|
1368
|
-
const
|
|
1369
|
-
|
|
552
|
+
const getCurrentStack = () => {
|
|
553
|
+
const stackLinesToSkip = 3;
|
|
554
|
+
const currentStack = joinLines(splitLines$1(new Error().stack || '').slice(stackLinesToSkip));
|
|
555
|
+
return currentStack;
|
|
1370
556
|
};
|
|
1371
|
-
const
|
|
1372
|
-
return
|
|
557
|
+
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
558
|
+
return string.indexOf(NewLine, startIndex);
|
|
1373
559
|
};
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
const fn = getFn(protocol);
|
|
1379
|
-
if (!fn) {
|
|
1380
|
-
throw new Error(`No search handler registered for protocol: ${protocol}`);
|
|
560
|
+
const getParentStack = error => {
|
|
561
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
562
|
+
if (parentStack.startsWith(' at')) {
|
|
563
|
+
parentStack = error.message + NewLine + parentStack;
|
|
1381
564
|
}
|
|
1382
|
-
|
|
1383
|
-
return result;
|
|
1384
|
-
};
|
|
1385
|
-
|
|
1386
|
-
// TODO this should be in FileSystem module
|
|
1387
|
-
const pathBaseName = path => {
|
|
1388
|
-
return path.slice(path.lastIndexOf('/') + 1);
|
|
565
|
+
return parentStack;
|
|
1389
566
|
};
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
const
|
|
1393
|
-
const
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
567
|
+
const MethodNotFound = -32601;
|
|
568
|
+
const Custom = -32001;
|
|
569
|
+
const restoreJsonRpcError = error => {
|
|
570
|
+
const currentStack = getCurrentStack();
|
|
571
|
+
if (error && error instanceof Error) {
|
|
572
|
+
if (typeof error.stack === 'string') {
|
|
573
|
+
error.stack = error.stack + NewLine + currentStack;
|
|
574
|
+
}
|
|
575
|
+
return error;
|
|
1397
576
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
const files = await searchFile$5(/* path */path, /* searchTerm */value, prepare, '');
|
|
1404
|
-
return files;
|
|
1405
|
-
};
|
|
1406
|
-
const convertToPick = uri => {
|
|
1407
|
-
const baseName = pathBaseName(uri);
|
|
1408
|
-
const dirName = pathDirName(uri);
|
|
1409
|
-
return {
|
|
1410
|
-
description: dirName,
|
|
1411
|
-
direntType: File$1,
|
|
1412
|
-
fileIcon: '',
|
|
1413
|
-
icon: '',
|
|
1414
|
-
label: baseName,
|
|
1415
|
-
matches: emptyMatches,
|
|
1416
|
-
uri
|
|
1417
|
-
};
|
|
1418
|
-
};
|
|
1419
|
-
|
|
1420
|
-
// TODO handle files differently
|
|
1421
|
-
// e.g. when there are many files, don't need
|
|
1422
|
-
// to compute the fileIcon for all files
|
|
1423
|
-
|
|
1424
|
-
const getPicks$9 = async searchValue => {
|
|
1425
|
-
// TODO cache workspace path
|
|
1426
|
-
const workspace = await getWorkspacePath();
|
|
1427
|
-
if (!workspace) {
|
|
1428
|
-
return [];
|
|
577
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
578
|
+
const restoredError = new JsonRpcError(error.message);
|
|
579
|
+
const parentStack = getParentStack(error);
|
|
580
|
+
restoredError.stack = parentStack + NewLine + currentStack;
|
|
581
|
+
return restoredError;
|
|
1429
582
|
}
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
matches: [],
|
|
1451
|
-
uri: ''
|
|
1452
|
-
}];
|
|
1453
|
-
};
|
|
1454
|
-
|
|
1455
|
-
const getPosition = (text, wantedColumn) => {
|
|
1456
|
-
let row = 0;
|
|
1457
|
-
let column = 0;
|
|
1458
|
-
for (let i = 0; i < wantedColumn; i++) {
|
|
1459
|
-
if (text[i] === '\n') {
|
|
1460
|
-
row++;
|
|
1461
|
-
column = 0;
|
|
583
|
+
if (error && error.message) {
|
|
584
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
585
|
+
if (error.data) {
|
|
586
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
587
|
+
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
588
|
+
} else if (error.data.stack) {
|
|
589
|
+
restoredError.stack = error.data.stack;
|
|
590
|
+
}
|
|
591
|
+
if (error.data.codeFrame) {
|
|
592
|
+
// @ts-ignore
|
|
593
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
594
|
+
}
|
|
595
|
+
if (error.data.code) {
|
|
596
|
+
// @ts-ignore
|
|
597
|
+
restoredError.code = error.data.code;
|
|
598
|
+
}
|
|
599
|
+
if (error.data.type) {
|
|
600
|
+
// @ts-ignore
|
|
601
|
+
restoredError.name = error.data.type;
|
|
602
|
+
}
|
|
1462
603
|
} else {
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
if (placeholders === emptyObject) {
|
|
1476
|
-
return key;
|
|
1477
|
-
}
|
|
1478
|
-
const replacer = (match, rest) => {
|
|
1479
|
-
return placeholders[rest];
|
|
1480
|
-
};
|
|
1481
|
-
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
1482
|
-
};
|
|
1483
|
-
|
|
1484
|
-
const GoToFile = 'Go to file';
|
|
1485
|
-
const GoToLineColumn = 'Go to Line / Column';
|
|
1486
|
-
const GoToSymbolInEditor = 'Go to Symbol in Editor';
|
|
1487
|
-
const NoResults = 'No Results';
|
|
1488
|
-
const OpenView = 'Open View';
|
|
1489
|
-
const QuickOpen = 'Quick open';
|
|
1490
|
-
const SearchForText = 'Search for text';
|
|
1491
|
-
const ShowAndRunCommands = 'Show And Run Commands';
|
|
1492
|
-
const TypeNameOfCommandToRun = 'Type the name of a command to run.';
|
|
1493
|
-
const PressEnterToGoToLine = `Press 'Enter' to go to line {PH1} column {PH2}`;
|
|
1494
|
-
|
|
1495
|
-
const pressEnterToGoToLine = (row, column) => {
|
|
1496
|
-
return i18nString(PressEnterToGoToLine, {
|
|
1497
|
-
PH1: row,
|
|
1498
|
-
PH2: column
|
|
1499
|
-
});
|
|
1500
|
-
};
|
|
1501
|
-
const typeNameofCommandToRun = () => {
|
|
1502
|
-
return i18nString(TypeNameOfCommandToRun);
|
|
1503
|
-
};
|
|
1504
|
-
const showAndRunCommands = () => {
|
|
1505
|
-
return i18nString(ShowAndRunCommands);
|
|
1506
|
-
};
|
|
1507
|
-
const goToFile = () => {
|
|
1508
|
-
return i18nString(GoToFile);
|
|
1509
|
-
};
|
|
1510
|
-
const noResults = () => {
|
|
1511
|
-
return i18nString(NoResults);
|
|
1512
|
-
};
|
|
1513
|
-
const quickOpen = () => {
|
|
1514
|
-
return i18nString(QuickOpen);
|
|
1515
|
-
};
|
|
1516
|
-
const goToLineColumn = () => {
|
|
1517
|
-
return i18nString(GoToLineColumn);
|
|
1518
|
-
};
|
|
1519
|
-
const goToSymbolInEditor = () => {
|
|
1520
|
-
return i18nString(GoToSymbolInEditor);
|
|
1521
|
-
};
|
|
1522
|
-
const searchForText = () => {
|
|
1523
|
-
return i18nString(SearchForText);
|
|
1524
|
-
};
|
|
1525
|
-
const openView = () => {
|
|
1526
|
-
return i18nString(OpenView);
|
|
1527
|
-
};
|
|
1528
|
-
|
|
1529
|
-
const getPicksGoToColumn = async value => {
|
|
1530
|
-
if (value === GoToColumn) {
|
|
1531
|
-
return getPicksGoToColumnBase();
|
|
1532
|
-
}
|
|
1533
|
-
if (value.startsWith(GoToColumn)) {
|
|
1534
|
-
const columnString = value.slice(GoToColumn.length);
|
|
1535
|
-
const wantedColumn = Number.parseInt(columnString, 10);
|
|
1536
|
-
if (Number.isNaN(wantedColumn)) {
|
|
1537
|
-
return getPicksGoToColumnBase();
|
|
1538
|
-
}
|
|
1539
|
-
const text = await getText();
|
|
1540
|
-
const position = getPosition(text, wantedColumn);
|
|
1541
|
-
return [{
|
|
1542
|
-
description: '',
|
|
1543
|
-
direntType: 0,
|
|
1544
|
-
fileIcon: '',
|
|
1545
|
-
icon: '',
|
|
1546
|
-
label: pressEnterToGoToLine(position.row, position.column),
|
|
1547
|
-
matches: [],
|
|
1548
|
-
uri: ''
|
|
1549
|
-
}];
|
|
1550
|
-
}
|
|
1551
|
-
return [];
|
|
1552
|
-
};
|
|
1553
|
-
|
|
1554
|
-
const splitLines$2 = lines => {
|
|
1555
|
-
if (!lines) {
|
|
1556
|
-
return [];
|
|
1557
|
-
}
|
|
1558
|
-
return lines.split('\n');
|
|
1559
|
-
};
|
|
1560
|
-
|
|
1561
|
-
const getPicksGoToLineBase = async () => {
|
|
1562
|
-
const text = await getText();
|
|
1563
|
-
const lines = splitLines$2(text);
|
|
1564
|
-
const lineCount = lines.length;
|
|
1565
|
-
return [{
|
|
1566
|
-
description: '',
|
|
1567
|
-
direntType: 0,
|
|
1568
|
-
fileIcon: '',
|
|
1569
|
-
icon: '',
|
|
1570
|
-
label: `Type a line number to go to (from 1 to ${lineCount})`,
|
|
1571
|
-
matches: [],
|
|
1572
|
-
uri: ''
|
|
1573
|
-
}];
|
|
1574
|
-
};
|
|
1575
|
-
|
|
1576
|
-
const parseGotoline = value => {
|
|
1577
|
-
const lineString = value.slice(GoToLine$1.length);
|
|
1578
|
-
const wantedLine = Number.parseInt(lineString, 10);
|
|
1579
|
-
if (Number.isNaN(wantedLine)) {
|
|
1580
|
-
return -1;
|
|
1581
|
-
}
|
|
1582
|
-
return wantedLine;
|
|
1583
|
-
};
|
|
1584
|
-
|
|
1585
|
-
const getPicks$8 = async value => {
|
|
1586
|
-
if (value === GoToLine$1) {
|
|
1587
|
-
return getPicksGoToLineBase();
|
|
1588
|
-
}
|
|
1589
|
-
if (value.startsWith(GoToLine$1)) {
|
|
1590
|
-
const wantedLine = parseGotoline(value);
|
|
1591
|
-
if (wantedLine === -1) {
|
|
1592
|
-
return getPicksGoToLineBase();
|
|
604
|
+
if (error.stack) {
|
|
605
|
+
const lowerStack = restoredError.stack || '';
|
|
606
|
+
// @ts-ignore
|
|
607
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
608
|
+
const parentStack = getParentStack(error);
|
|
609
|
+
// @ts-ignore
|
|
610
|
+
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
611
|
+
}
|
|
612
|
+
if (error.codeFrame) {
|
|
613
|
+
// @ts-ignore
|
|
614
|
+
restoredError.codeFrame = error.codeFrame;
|
|
615
|
+
}
|
|
1593
616
|
}
|
|
1594
|
-
|
|
1595
|
-
const columnIndex = 0;
|
|
1596
|
-
return [{
|
|
1597
|
-
description: '',
|
|
1598
|
-
direntType: 0,
|
|
1599
|
-
fileIcon: '',
|
|
1600
|
-
icon: '',
|
|
1601
|
-
label: pressEnterToGoToLine(rowIndex, columnIndex),
|
|
1602
|
-
matches: [],
|
|
1603
|
-
uri: ''
|
|
1604
|
-
}];
|
|
1605
|
-
}
|
|
1606
|
-
return [];
|
|
1607
|
-
};
|
|
1608
|
-
|
|
1609
|
-
const DotDotDot = '...';
|
|
1610
|
-
const Colon = ':';
|
|
1611
|
-
const Percent = '%';
|
|
1612
|
-
const AngleBracket = '>';
|
|
1613
|
-
const View$1 = 'view';
|
|
1614
|
-
|
|
1615
|
-
const getPicks$7 = async () => {
|
|
1616
|
-
return [{
|
|
1617
|
-
description: goToFile(),
|
|
1618
|
-
direntType: None$2,
|
|
1619
|
-
fileIcon: '',
|
|
1620
|
-
icon: '',
|
|
1621
|
-
label: DotDotDot,
|
|
1622
|
-
matches: [],
|
|
1623
|
-
uri: ''
|
|
1624
|
-
}, {
|
|
1625
|
-
description: goToLineColumn(),
|
|
1626
|
-
direntType: None$2,
|
|
1627
|
-
fileIcon: '',
|
|
1628
|
-
icon: '',
|
|
1629
|
-
label: ':',
|
|
1630
|
-
matches: [],
|
|
1631
|
-
uri: ''
|
|
1632
|
-
}, {
|
|
1633
|
-
description: goToSymbolInEditor(),
|
|
1634
|
-
direntType: None$2,
|
|
1635
|
-
fileIcon: '',
|
|
1636
|
-
icon: '',
|
|
1637
|
-
label: Colon,
|
|
1638
|
-
matches: [],
|
|
1639
|
-
uri: ''
|
|
1640
|
-
}, {
|
|
1641
|
-
description: searchForText(),
|
|
1642
|
-
direntType: None$2,
|
|
1643
|
-
fileIcon: '',
|
|
1644
|
-
icon: '',
|
|
1645
|
-
label: Percent,
|
|
1646
|
-
matches: [],
|
|
1647
|
-
uri: ''
|
|
1648
|
-
}, {
|
|
1649
|
-
description: showAndRunCommands(),
|
|
1650
|
-
direntType: None$2,
|
|
1651
|
-
fileIcon: '',
|
|
1652
|
-
icon: '',
|
|
1653
|
-
label: AngleBracket,
|
|
1654
|
-
matches: [],
|
|
1655
|
-
uri: ''
|
|
1656
|
-
}, {
|
|
1657
|
-
description: openView(),
|
|
1658
|
-
direntType: None$2,
|
|
1659
|
-
fileIcon: '',
|
|
1660
|
-
icon: '',
|
|
1661
|
-
label: View$1,
|
|
1662
|
-
matches: [],
|
|
1663
|
-
uri: ''
|
|
1664
|
-
}];
|
|
1665
|
-
};
|
|
1666
|
-
|
|
1667
|
-
const getRecentlyOpened = () => {
|
|
1668
|
-
return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
|
|
1669
|
-
};
|
|
1670
|
-
|
|
1671
|
-
const getLabel = uri => {
|
|
1672
|
-
if (uri.startsWith('file://')) {
|
|
1673
|
-
return uri.slice('file://'.length);
|
|
1674
|
-
}
|
|
1675
|
-
return uri;
|
|
1676
|
-
};
|
|
1677
|
-
const toProtoVisibleItem = uri => {
|
|
1678
|
-
return {
|
|
1679
|
-
description: '',
|
|
1680
|
-
direntType: Directory,
|
|
1681
|
-
fileIcon: '',
|
|
1682
|
-
icon: '',
|
|
1683
|
-
label: getLabel(uri),
|
|
1684
|
-
matches: [],
|
|
1685
|
-
uri
|
|
1686
|
-
};
|
|
1687
|
-
};
|
|
1688
|
-
const getPicks$6 = async () => {
|
|
1689
|
-
const recentlyOpened = await getRecentlyOpened();
|
|
1690
|
-
const picks = recentlyOpened.map(toProtoVisibleItem);
|
|
1691
|
-
return picks;
|
|
1692
|
-
};
|
|
1693
|
-
|
|
1694
|
-
const getPicks$5 = async () => {
|
|
1695
|
-
const picks = [];
|
|
1696
|
-
return picks;
|
|
1697
|
-
};
|
|
1698
|
-
|
|
1699
|
-
const getPicks$4 = async () => {
|
|
1700
|
-
return [];
|
|
1701
|
-
};
|
|
1702
|
-
|
|
1703
|
-
const getPicks$3 = async () => {
|
|
1704
|
-
const picks = [];
|
|
1705
|
-
return picks;
|
|
1706
|
-
};
|
|
1707
|
-
|
|
1708
|
-
const Hide = 'hide';
|
|
1709
|
-
const KeepOpen = '';
|
|
1710
|
-
|
|
1711
|
-
const selectPick$9 = async pick => {
|
|
1712
|
-
const id = pick.label;
|
|
1713
|
-
await setColorTheme(id);
|
|
1714
|
-
return {
|
|
1715
|
-
command: Hide
|
|
1716
|
-
};
|
|
1717
|
-
};
|
|
1718
|
-
|
|
1719
|
-
const hideIds = ['AutoUpdater.checkForUpdates'];
|
|
1720
|
-
const shouldHide = item => {
|
|
1721
|
-
if (hideIds.includes(item.id)) {
|
|
1722
|
-
return false;
|
|
1723
|
-
}
|
|
1724
|
-
if (item.id === 'Viewlet.openWidget' && item.args?.[0] === 'QuickPick') {
|
|
1725
|
-
return false;
|
|
1726
|
-
}
|
|
1727
|
-
return true;
|
|
1728
|
-
};
|
|
1729
|
-
|
|
1730
|
-
const selectPickBuiltin = async item => {
|
|
1731
|
-
const args = item.args || [];
|
|
1732
|
-
// TODO ids should be all numbers for efficiency -> also directly can call command
|
|
1733
|
-
await invoke$1(item.id, ...args);
|
|
1734
|
-
if (shouldHide(item)) {
|
|
1735
|
-
return {
|
|
1736
|
-
command: Hide
|
|
1737
|
-
};
|
|
1738
|
-
}
|
|
1739
|
-
return {
|
|
1740
|
-
command: KeepOpen
|
|
1741
|
-
};
|
|
1742
|
-
};
|
|
1743
|
-
const selectPickExtension = async item => {
|
|
1744
|
-
const id = item.id.slice(4); // TODO lots of string allocation with 'ext.' find a better way to separate builtin commands from extension commands
|
|
1745
|
-
try {
|
|
1746
|
-
await invoke$1('ExtensionHost.executeCommand', id);
|
|
1747
|
-
} catch (error) {
|
|
1748
|
-
await handleError(error, false);
|
|
1749
|
-
await showErrorDialog(error);
|
|
1750
|
-
}
|
|
1751
|
-
return {
|
|
1752
|
-
command: Hide
|
|
1753
|
-
};
|
|
1754
|
-
};
|
|
1755
|
-
const selectPick$8 = async item => {
|
|
1756
|
-
// @ts-ignore
|
|
1757
|
-
const {
|
|
1758
|
-
id
|
|
1759
|
-
} = item;
|
|
1760
|
-
if (id.startsWith('ext.')) {
|
|
1761
|
-
return selectPickExtension(item);
|
|
1762
|
-
}
|
|
1763
|
-
return selectPickBuiltin(item);
|
|
1764
|
-
};
|
|
1765
|
-
|
|
1766
|
-
const state = {
|
|
1767
|
-
args: []
|
|
1768
|
-
};
|
|
1769
|
-
|
|
1770
|
-
const selectPick$7 = async pick => {
|
|
1771
|
-
const {
|
|
1772
|
-
args
|
|
1773
|
-
} = state;
|
|
1774
|
-
const resolveId = args[2];
|
|
1775
|
-
await invoke$1(`QuickPick.executeCallback`, resolveId, pick);
|
|
1776
|
-
return {
|
|
1777
|
-
command: Hide
|
|
1778
|
-
};
|
|
1779
|
-
};
|
|
1780
|
-
|
|
1781
|
-
const openUri = async uri => {
|
|
1782
|
-
await openUri$1(uri);
|
|
1783
|
-
};
|
|
1784
|
-
|
|
1785
|
-
const selectPick$6 = async pick => {
|
|
1786
|
-
const {
|
|
1787
|
-
description
|
|
1788
|
-
} = pick;
|
|
1789
|
-
const fileName = pick.label;
|
|
1790
|
-
const workspace = await getWorkspacePath();
|
|
1791
|
-
const absolutePath = `${workspace}/${description}/${fileName}`;
|
|
1792
|
-
await openUri(absolutePath);
|
|
1793
|
-
return {
|
|
1794
|
-
command: Hide
|
|
1795
|
-
};
|
|
1796
|
-
};
|
|
1797
|
-
|
|
1798
|
-
const setCursor = async (rowIndex, columnIndex) => {
|
|
1799
|
-
await invoke$1('Editor.cursorSet', rowIndex, columnIndex);
|
|
1800
|
-
};
|
|
1801
|
-
|
|
1802
|
-
const goToPositionAndFocus = async (rowIndex, columnIndex) => {
|
|
1803
|
-
await setCursor(rowIndex, columnIndex);
|
|
1804
|
-
await invoke$1('Editor.handleFocus');
|
|
1805
|
-
};
|
|
1806
|
-
|
|
1807
|
-
const selectPickGoToColumn = async (item, value) => {
|
|
1808
|
-
if (value.startsWith(GoToColumn)) {
|
|
1809
|
-
const columnString = value.slice(2);
|
|
1810
|
-
const wantedColumn = Number.parseInt(columnString, 10);
|
|
1811
|
-
const text = await getText();
|
|
1812
|
-
const position = getPosition(text, wantedColumn);
|
|
1813
|
-
await goToPositionAndFocus(position.row, position.column);
|
|
1814
|
-
return {
|
|
1815
|
-
command: Hide
|
|
1816
|
-
};
|
|
1817
|
-
}
|
|
1818
|
-
return {
|
|
1819
|
-
command: Hide
|
|
1820
|
-
};
|
|
1821
|
-
};
|
|
1822
|
-
|
|
1823
|
-
const selectPick$5 = async (item, value) => {
|
|
1824
|
-
if (value.startsWith(GoToLine$1)) {
|
|
1825
|
-
const lineString = value.slice(GoToLine$1.length);
|
|
1826
|
-
const wantedLine = Number.parseInt(lineString, 10);
|
|
1827
|
-
const rowIndex = wantedLine - 1;
|
|
1828
|
-
const columnIndex = 0;
|
|
1829
|
-
await goToPositionAndFocus(rowIndex, columnIndex);
|
|
1830
|
-
return {
|
|
1831
|
-
command: Hide
|
|
1832
|
-
};
|
|
617
|
+
return restoredError;
|
|
1833
618
|
}
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
};
|
|
1837
|
-
};
|
|
1838
|
-
|
|
1839
|
-
const selectPick$4 = async item => {
|
|
1840
|
-
// Command.execute(/* openView */ 549, /* viewName */ item.label)
|
|
1841
|
-
return {
|
|
1842
|
-
command: Hide
|
|
1843
|
-
};
|
|
1844
|
-
};
|
|
1845
|
-
|
|
1846
|
-
const openWorkspaceFolder = uri => {
|
|
1847
|
-
return invoke$1(/* Workspace.setPath */'Workspace.setPath', /* path */uri);
|
|
1848
|
-
};
|
|
1849
|
-
|
|
1850
|
-
// TODO selectPick should be independent of show/hide
|
|
1851
|
-
const selectPick$3 = async pick => {
|
|
1852
|
-
const {
|
|
1853
|
-
uri
|
|
1854
|
-
} = pick;
|
|
1855
|
-
await openWorkspaceFolder(uri);
|
|
1856
|
-
return {
|
|
1857
|
-
command: Hide
|
|
1858
|
-
};
|
|
1859
|
-
};
|
|
1860
|
-
|
|
1861
|
-
const selectPick$2 = async item => {
|
|
1862
|
-
return {
|
|
1863
|
-
command: Hide
|
|
1864
|
-
};
|
|
1865
|
-
};
|
|
1866
|
-
|
|
1867
|
-
const selectPick$1 = async item => {
|
|
1868
|
-
// Command.execute(/* openView */ 549, /* viewName */ item.label)
|
|
1869
|
-
return {
|
|
1870
|
-
command: Hide
|
|
1871
|
-
};
|
|
1872
|
-
};
|
|
1873
|
-
|
|
1874
|
-
const selectPick = async item => {
|
|
1875
|
-
return {
|
|
1876
|
-
command: Hide
|
|
1877
|
-
};
|
|
1878
|
-
};
|
|
1879
|
-
|
|
1880
|
-
const selectPicks = [selectPick$9, selectPick$8, selectPick$7, selectPick$6, selectPickGoToColumn, selectPick$5, selectPick$4, selectPick$3, selectPick$2, selectPick$1, selectPick];
|
|
1881
|
-
const getPicks$2 = [getPicks$c, getPicks$b, getPicks$a, getPicks$9, getPicksGoToColumn, getPicks$8, getPicks$7, getPicks$6, getPicks$5, getPicks$4, getPicks$3];
|
|
1882
|
-
|
|
1883
|
-
const select = selectPicks;
|
|
1884
|
-
const getPick$1 = getPicks$2;
|
|
1885
|
-
const getPicks$1 = id => {
|
|
1886
|
-
const fn = getPick$1[id];
|
|
1887
|
-
return fn;
|
|
1888
|
-
};
|
|
1889
|
-
const getSelect = id => {
|
|
1890
|
-
const fn = select[id];
|
|
1891
|
-
return fn;
|
|
1892
|
-
};
|
|
1893
|
-
|
|
1894
|
-
const getPicks = (id, searchValue, args, {
|
|
1895
|
-
assetDir,
|
|
1896
|
-
platform
|
|
1897
|
-
}) => {
|
|
1898
|
-
const fn = getPicks$1(id);
|
|
1899
|
-
return fn(searchValue, args, {
|
|
1900
|
-
assetDir,
|
|
1901
|
-
platform
|
|
1902
|
-
});
|
|
1903
|
-
};
|
|
1904
|
-
|
|
1905
|
-
const getQuickPickSubProviderId = (id, prefix) => {
|
|
1906
|
-
if (id !== EveryThing$1) {
|
|
1907
|
-
return id;
|
|
1908
|
-
}
|
|
1909
|
-
switch (prefix) {
|
|
1910
|
-
case Command:
|
|
1911
|
-
return Commands$1;
|
|
1912
|
-
case GoToColumn:
|
|
1913
|
-
return GoToColumn$1;
|
|
1914
|
-
case GoToLine$1:
|
|
1915
|
-
return GoToLine$2;
|
|
1916
|
-
case Help$1:
|
|
1917
|
-
return Help$2;
|
|
1918
|
-
case Symbol$2:
|
|
1919
|
-
return Symbol$3;
|
|
1920
|
-
case View$2:
|
|
1921
|
-
return View$3;
|
|
1922
|
-
case WorkspaceSymbol$1:
|
|
1923
|
-
return WorkspaceSymbol$2;
|
|
1924
|
-
default:
|
|
1925
|
-
return File$2;
|
|
619
|
+
if (typeof error === 'string') {
|
|
620
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
1926
621
|
}
|
|
622
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
1927
623
|
};
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
const
|
|
1931
|
-
|
|
1932
|
-
args,
|
|
1933
|
-
assetDir,
|
|
1934
|
-
fileIconCache,
|
|
1935
|
-
height,
|
|
1936
|
-
itemHeight,
|
|
1937
|
-
maxLineY,
|
|
1938
|
-
minLineY,
|
|
1939
|
-
platform,
|
|
1940
|
-
providerId,
|
|
1941
|
-
value
|
|
1942
|
-
} = state;
|
|
1943
|
-
if (value === newValue) {
|
|
1944
|
-
return state;
|
|
1945
|
-
}
|
|
1946
|
-
const prefix = getQuickPickPrefix(newValue);
|
|
1947
|
-
const subId = getQuickPickSubProviderId(providerId, prefix);
|
|
1948
|
-
const newPicks = await getPicks(subId, newValue, args, {
|
|
1949
|
-
assetDir,
|
|
1950
|
-
platform
|
|
1951
|
-
});
|
|
1952
|
-
const filterValue = getFilterValue(providerId, subId, newValue);
|
|
1953
|
-
const items = filterQuickPickItems(newPicks, filterValue);
|
|
1954
|
-
const focusedIndex = items.length === 0 ? -1 : 0;
|
|
1955
|
-
const sliced = items.slice(minLineY, maxLineY);
|
|
1956
|
-
const {
|
|
1957
|
-
icons,
|
|
1958
|
-
newFileIconCache
|
|
1959
|
-
} = await getQuickPickFileIcons(sliced, fileIconCache);
|
|
1960
|
-
const listHeight = getListHeight(items.length, itemHeight, height);
|
|
1961
|
-
const finalDeltaY = getFinalDeltaY(listHeight, itemHeight, items.length);
|
|
1962
|
-
return {
|
|
1963
|
-
...state,
|
|
1964
|
-
fileIconCache: newFileIconCache,
|
|
1965
|
-
finalDeltaY,
|
|
1966
|
-
focusedIndex,
|
|
1967
|
-
icons,
|
|
1968
|
-
inputSource: Script,
|
|
1969
|
-
items,
|
|
1970
|
-
picks: newPicks,
|
|
1971
|
-
value: newValue
|
|
1972
|
-
};
|
|
1973
|
-
};
|
|
1974
|
-
|
|
1975
|
-
// TODO when user types letters -> no need to query provider again -> just filter existing results
|
|
1976
|
-
const handleInput = async (state, newValue, cursorOffset, inputSource = Script) => {
|
|
1977
|
-
if (state.value === newValue) {
|
|
1978
|
-
return {
|
|
1979
|
-
...state,
|
|
1980
|
-
cursorOffset,
|
|
1981
|
-
inputSource
|
|
1982
|
-
};
|
|
624
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
625
|
+
if ('error' in responseMessage) {
|
|
626
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
627
|
+
throw restoredError;
|
|
1983
628
|
}
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
...newState,
|
|
1987
|
-
cursorOffset,
|
|
1988
|
-
inputSource
|
|
1989
|
-
};
|
|
1990
|
-
};
|
|
1991
|
-
|
|
1992
|
-
const handleBeforeInput = (state, inputType, data, selectionStart, selectionEnd) => {
|
|
1993
|
-
string(inputType);
|
|
1994
|
-
number(selectionStart);
|
|
1995
|
-
number(selectionEnd);
|
|
1996
|
-
const {
|
|
1997
|
-
value
|
|
1998
|
-
} = state;
|
|
1999
|
-
const {
|
|
2000
|
-
cursorOffset,
|
|
2001
|
-
newValue
|
|
2002
|
-
} = getNewValue(value, inputType, data, selectionStart, selectionEnd);
|
|
2003
|
-
return handleInput(state, newValue, cursorOffset, User);
|
|
2004
|
-
};
|
|
2005
|
-
|
|
2006
|
-
const handleBlur = async state => {
|
|
2007
|
-
// TODO fix virtual dom diffing so that input isn't destroyed and loses focus when rerendering
|
|
2008
|
-
// await CloseWidget.closeWidget(state.uid)
|
|
2009
|
-
return state;
|
|
2010
|
-
};
|
|
2011
|
-
|
|
2012
|
-
const getIndex = (top, headerHeight, itemHeight, y) => {
|
|
2013
|
-
const relativeY = y - top - headerHeight;
|
|
2014
|
-
const index = Math.floor(relativeY / itemHeight);
|
|
2015
|
-
return index;
|
|
2016
|
-
};
|
|
2017
|
-
|
|
2018
|
-
const getPick = (items, index) => {
|
|
2019
|
-
array(items);
|
|
2020
|
-
number(index);
|
|
2021
|
-
// if (index < state.recentPicks.length) {
|
|
2022
|
-
// return state.recentPicks[index]
|
|
2023
|
-
// }
|
|
2024
|
-
// index -= state.recentPicks.length
|
|
2025
|
-
if (index < items.length) {
|
|
2026
|
-
return items[index];
|
|
2027
|
-
}
|
|
2028
|
-
console.warn('no pick matching index', index);
|
|
2029
|
-
return undefined;
|
|
2030
|
-
};
|
|
2031
|
-
|
|
2032
|
-
const selectIndex = async (state, index, button = /* left */0) => {
|
|
2033
|
-
const {
|
|
2034
|
-
items,
|
|
2035
|
-
minLineY,
|
|
2036
|
-
providerId,
|
|
2037
|
-
value
|
|
2038
|
-
} = state;
|
|
2039
|
-
const actualIndex = index + minLineY;
|
|
2040
|
-
const pick = getPick(items, actualIndex);
|
|
2041
|
-
if (!pick) {
|
|
2042
|
-
return state;
|
|
2043
|
-
}
|
|
2044
|
-
const prefix = getQuickPickPrefix(value);
|
|
2045
|
-
const subId = getQuickPickSubProviderId(providerId, prefix);
|
|
2046
|
-
const fn = getSelect(subId);
|
|
2047
|
-
const selectPickResult = await fn(pick, value);
|
|
2048
|
-
object(selectPickResult);
|
|
2049
|
-
string(selectPickResult.command);
|
|
2050
|
-
const {
|
|
2051
|
-
command
|
|
2052
|
-
} = selectPickResult;
|
|
2053
|
-
switch (command) {
|
|
2054
|
-
case Hide:
|
|
2055
|
-
await closeWidget(state.uid);
|
|
2056
|
-
return state;
|
|
2057
|
-
default:
|
|
2058
|
-
return state;
|
|
629
|
+
if ('result' in responseMessage) {
|
|
630
|
+
return responseMessage.result;
|
|
2059
631
|
}
|
|
2060
|
-
|
|
2061
|
-
// TODO recent picks should be per provider
|
|
2062
|
-
// if (!state.recentPickIds.has(pick.id)) {
|
|
2063
|
-
// state.recentPicks.unshift(pick)
|
|
2064
|
-
// state.recentPickIds.add(pick.id)
|
|
2065
|
-
// }
|
|
2066
|
-
// if (state.recentPicks.length > RECENT_PICKS_MAX_SIZE) {
|
|
2067
|
-
// const last = state.recentPicks.pop()
|
|
2068
|
-
// state.recentPickIds.delete(last.id)
|
|
2069
|
-
// }
|
|
2070
|
-
};
|
|
2071
|
-
|
|
2072
|
-
const handleClickAt = (state, x, y) => {
|
|
2073
|
-
const {
|
|
2074
|
-
headerHeight,
|
|
2075
|
-
itemHeight,
|
|
2076
|
-
top
|
|
2077
|
-
} = state;
|
|
2078
|
-
const index = getIndex(top, headerHeight, itemHeight, y);
|
|
2079
|
-
return selectIndex(state, index);
|
|
2080
|
-
};
|
|
2081
|
-
|
|
2082
|
-
const handleFocus = async state => {
|
|
2083
|
-
// TODO fix virtual dom diffing so that input isn't destroyed and loses focus when rerendering
|
|
2084
|
-
await setFocus(FocusQuickPickInput);
|
|
2085
|
-
// await CloseWidget.closeWidget(state.uid)
|
|
2086
|
-
return state;
|
|
2087
|
-
};
|
|
2088
|
-
|
|
2089
|
-
const isMessagePort = value => {
|
|
2090
|
-
return value && value instanceof MessagePort;
|
|
2091
|
-
};
|
|
2092
|
-
const isMessagePortMain = value => {
|
|
2093
|
-
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
2094
|
-
};
|
|
2095
|
-
const isOffscreenCanvas = value => {
|
|
2096
|
-
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
2097
|
-
};
|
|
2098
|
-
const isInstanceOf = (value, constructorName) => {
|
|
2099
|
-
return value?.constructor?.name === constructorName;
|
|
632
|
+
throw new JsonRpcError('unexpected response message');
|
|
2100
633
|
};
|
|
2101
|
-
const
|
|
2102
|
-
|
|
634
|
+
const warn = (...args) => {
|
|
635
|
+
console.warn(...args);
|
|
2103
636
|
};
|
|
2104
|
-
const
|
|
2105
|
-
const
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
}
|
|
2111
|
-
return false;
|
|
2112
|
-
};
|
|
2113
|
-
const walkValue = (value, transferrables, isTransferrable) => {
|
|
2114
|
-
if (!value) {
|
|
2115
|
-
return;
|
|
2116
|
-
}
|
|
2117
|
-
if (isTransferrable(value)) {
|
|
2118
|
-
transferrables.push(value);
|
|
2119
|
-
return;
|
|
2120
|
-
}
|
|
2121
|
-
if (Array.isArray(value)) {
|
|
2122
|
-
for (const item of value) {
|
|
2123
|
-
walkValue(item, transferrables, isTransferrable);
|
|
2124
|
-
}
|
|
2125
|
-
return;
|
|
2126
|
-
}
|
|
2127
|
-
if (typeof value === 'object') {
|
|
2128
|
-
for (const property of Object.values(value)) {
|
|
2129
|
-
walkValue(property, transferrables, isTransferrable);
|
|
2130
|
-
}
|
|
2131
|
-
return;
|
|
2132
|
-
}
|
|
2133
|
-
};
|
|
2134
|
-
const getTransferrables = value => {
|
|
2135
|
-
const transferrables = [];
|
|
2136
|
-
walkValue(value, transferrables, isTransferrable);
|
|
2137
|
-
return transferrables;
|
|
2138
|
-
};
|
|
2139
|
-
const attachEvents = that => {
|
|
2140
|
-
const handleMessage = (...args) => {
|
|
2141
|
-
const data = that.getData(...args);
|
|
2142
|
-
that.dispatchEvent(new MessageEvent('message', {
|
|
2143
|
-
data
|
|
2144
|
-
}));
|
|
2145
|
-
};
|
|
2146
|
-
that.onMessage(handleMessage);
|
|
2147
|
-
const handleClose = event => {
|
|
2148
|
-
that.dispatchEvent(new Event('close'));
|
|
2149
|
-
};
|
|
2150
|
-
that.onClose(handleClose);
|
|
2151
|
-
};
|
|
2152
|
-
class Ipc extends EventTarget {
|
|
2153
|
-
constructor(rawIpc) {
|
|
2154
|
-
super();
|
|
2155
|
-
this._rawIpc = rawIpc;
|
|
2156
|
-
attachEvents(this);
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
2160
|
-
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
2161
|
-
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
2162
|
-
const NewLine$1 = '\n';
|
|
2163
|
-
const joinLines$1 = lines => {
|
|
2164
|
-
return lines.join(NewLine$1);
|
|
2165
|
-
};
|
|
2166
|
-
const RE_AT = /^\s+at/;
|
|
2167
|
-
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
2168
|
-
const isNormalStackLine = line => {
|
|
2169
|
-
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
2170
|
-
};
|
|
2171
|
-
const getDetails = lines => {
|
|
2172
|
-
const index = lines.findIndex(isNormalStackLine);
|
|
2173
|
-
if (index === -1) {
|
|
2174
|
-
return {
|
|
2175
|
-
actualMessage: joinLines$1(lines),
|
|
2176
|
-
rest: []
|
|
2177
|
-
};
|
|
2178
|
-
}
|
|
2179
|
-
let lastIndex = index - 1;
|
|
2180
|
-
while (++lastIndex < lines.length) {
|
|
2181
|
-
if (!isNormalStackLine(lines[lastIndex])) {
|
|
2182
|
-
break;
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
return {
|
|
2186
|
-
actualMessage: lines[index - 1],
|
|
2187
|
-
rest: lines.slice(index, lastIndex)
|
|
2188
|
-
};
|
|
2189
|
-
};
|
|
2190
|
-
const splitLines$1 = lines => {
|
|
2191
|
-
return lines.split(NewLine$1);
|
|
2192
|
-
};
|
|
2193
|
-
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
2194
|
-
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
2195
|
-
const isMessageCodeBlockStartIndex = line => {
|
|
2196
|
-
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
2197
|
-
};
|
|
2198
|
-
const isMessageCodeBlockEndIndex = line => {
|
|
2199
|
-
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
2200
|
-
};
|
|
2201
|
-
const getMessageCodeBlock = stderr => {
|
|
2202
|
-
const lines = splitLines$1(stderr);
|
|
2203
|
-
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
2204
|
-
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
2205
|
-
const relevantLines = lines.slice(startIndex, endIndex);
|
|
2206
|
-
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
2207
|
-
return relevantMessage;
|
|
2208
|
-
};
|
|
2209
|
-
const isModuleNotFoundMessage = line => {
|
|
2210
|
-
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
2211
|
-
};
|
|
2212
|
-
const getModuleNotFoundError = stderr => {
|
|
2213
|
-
const lines = splitLines$1(stderr);
|
|
2214
|
-
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
2215
|
-
const message = lines[messageIndex];
|
|
2216
|
-
return {
|
|
2217
|
-
code: ERR_MODULE_NOT_FOUND,
|
|
2218
|
-
message
|
|
2219
|
-
};
|
|
2220
|
-
};
|
|
2221
|
-
const isModuleNotFoundError = stderr => {
|
|
2222
|
-
if (!stderr) {
|
|
2223
|
-
return false;
|
|
2224
|
-
}
|
|
2225
|
-
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
2226
|
-
};
|
|
2227
|
-
const isModulesSyntaxError = stderr => {
|
|
2228
|
-
if (!stderr) {
|
|
2229
|
-
return false;
|
|
2230
|
-
}
|
|
2231
|
-
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
2232
|
-
};
|
|
2233
|
-
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
2234
|
-
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
2235
|
-
const isUnhelpfulNativeModuleError = stderr => {
|
|
2236
|
-
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
2237
|
-
};
|
|
2238
|
-
const getNativeModuleErrorMessage = stderr => {
|
|
2239
|
-
const message = getMessageCodeBlock(stderr);
|
|
2240
|
-
return {
|
|
2241
|
-
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
2242
|
-
message: `Incompatible native node module: ${message}`
|
|
2243
|
-
};
|
|
2244
|
-
};
|
|
2245
|
-
const getModuleSyntaxError = () => {
|
|
2246
|
-
return {
|
|
2247
|
-
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
2248
|
-
message: `ES Modules are not supported in electron`
|
|
2249
|
-
};
|
|
2250
|
-
};
|
|
2251
|
-
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
2252
|
-
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
2253
|
-
return getNativeModuleErrorMessage(stderr);
|
|
2254
|
-
}
|
|
2255
|
-
if (isModulesSyntaxError(stderr)) {
|
|
2256
|
-
return getModuleSyntaxError();
|
|
2257
|
-
}
|
|
2258
|
-
if (isModuleNotFoundError(stderr)) {
|
|
2259
|
-
return getModuleNotFoundError(stderr);
|
|
2260
|
-
}
|
|
2261
|
-
const lines = splitLines$1(stderr);
|
|
2262
|
-
const {
|
|
2263
|
-
actualMessage,
|
|
2264
|
-
rest
|
|
2265
|
-
} = getDetails(lines);
|
|
2266
|
-
return {
|
|
2267
|
-
code: '',
|
|
2268
|
-
message: actualMessage,
|
|
2269
|
-
stack: rest
|
|
2270
|
-
};
|
|
2271
|
-
};
|
|
2272
|
-
class IpcError extends VError {
|
|
2273
|
-
// @ts-ignore
|
|
2274
|
-
constructor(betterMessage, stdout = '', stderr = '') {
|
|
2275
|
-
if (stdout || stderr) {
|
|
2276
|
-
// @ts-ignore
|
|
2277
|
-
const {
|
|
2278
|
-
code,
|
|
2279
|
-
message,
|
|
2280
|
-
stack
|
|
2281
|
-
} = getHelpfulChildProcessError(stdout, stderr);
|
|
2282
|
-
const cause = new Error(message);
|
|
2283
|
-
// @ts-ignore
|
|
2284
|
-
cause.code = code;
|
|
2285
|
-
cause.stack = stack;
|
|
2286
|
-
super(cause, betterMessage);
|
|
2287
|
-
} else {
|
|
2288
|
-
super(betterMessage);
|
|
2289
|
-
}
|
|
2290
|
-
// @ts-ignore
|
|
2291
|
-
this.name = 'IpcError';
|
|
2292
|
-
// @ts-ignore
|
|
2293
|
-
this.stdout = stdout;
|
|
2294
|
-
// @ts-ignore
|
|
2295
|
-
this.stderr = stderr;
|
|
2296
|
-
}
|
|
2297
|
-
}
|
|
2298
|
-
const readyMessage = 'ready';
|
|
2299
|
-
const getData$2 = event => {
|
|
2300
|
-
return event.data;
|
|
2301
|
-
};
|
|
2302
|
-
const listen$7 = () => {
|
|
2303
|
-
// @ts-ignore
|
|
2304
|
-
if (typeof WorkerGlobalScope === 'undefined') {
|
|
2305
|
-
throw new TypeError('module is not in web worker scope');
|
|
2306
|
-
}
|
|
2307
|
-
return globalThis;
|
|
2308
|
-
};
|
|
2309
|
-
const signal$8 = global => {
|
|
2310
|
-
global.postMessage(readyMessage);
|
|
2311
|
-
};
|
|
2312
|
-
class IpcChildWithModuleWorker extends Ipc {
|
|
2313
|
-
getData(event) {
|
|
2314
|
-
return getData$2(event);
|
|
2315
|
-
}
|
|
2316
|
-
send(message) {
|
|
2317
|
-
// @ts-ignore
|
|
2318
|
-
this._rawIpc.postMessage(message);
|
|
2319
|
-
}
|
|
2320
|
-
sendAndTransfer(message) {
|
|
2321
|
-
const transfer = getTransferrables(message);
|
|
2322
|
-
// @ts-ignore
|
|
2323
|
-
this._rawIpc.postMessage(message, transfer);
|
|
2324
|
-
}
|
|
2325
|
-
dispose() {
|
|
2326
|
-
// ignore
|
|
2327
|
-
}
|
|
2328
|
-
onClose(callback) {
|
|
2329
|
-
// ignore
|
|
2330
|
-
}
|
|
2331
|
-
onMessage(callback) {
|
|
2332
|
-
this._rawIpc.addEventListener('message', callback);
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
const wrap$f = global => {
|
|
2336
|
-
return new IpcChildWithModuleWorker(global);
|
|
2337
|
-
};
|
|
2338
|
-
const waitForFirstMessage = async port => {
|
|
2339
|
-
const {
|
|
2340
|
-
promise,
|
|
2341
|
-
resolve
|
|
2342
|
-
} = Promise.withResolvers();
|
|
2343
|
-
port.addEventListener('message', resolve, {
|
|
2344
|
-
once: true
|
|
2345
|
-
});
|
|
2346
|
-
const event = await promise;
|
|
2347
|
-
// @ts-ignore
|
|
2348
|
-
return event.data;
|
|
2349
|
-
};
|
|
2350
|
-
const listen$6 = async () => {
|
|
2351
|
-
const parentIpcRaw = listen$7();
|
|
2352
|
-
signal$8(parentIpcRaw);
|
|
2353
|
-
const parentIpc = wrap$f(parentIpcRaw);
|
|
2354
|
-
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
2355
|
-
if (firstMessage.method !== 'initialize') {
|
|
2356
|
-
throw new IpcError('unexpected first message');
|
|
2357
|
-
}
|
|
2358
|
-
const type = firstMessage.params[0];
|
|
2359
|
-
if (type === 'message-port') {
|
|
2360
|
-
parentIpc.send({
|
|
2361
|
-
id: firstMessage.id,
|
|
2362
|
-
jsonrpc: '2.0',
|
|
2363
|
-
result: null
|
|
2364
|
-
});
|
|
2365
|
-
parentIpc.dispose();
|
|
2366
|
-
const port = firstMessage.params[1];
|
|
2367
|
-
return port;
|
|
2368
|
-
}
|
|
2369
|
-
return globalThis;
|
|
2370
|
-
};
|
|
2371
|
-
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
2372
|
-
getData(event) {
|
|
2373
|
-
return getData$2(event);
|
|
2374
|
-
}
|
|
2375
|
-
send(message) {
|
|
2376
|
-
this._rawIpc.postMessage(message);
|
|
2377
|
-
}
|
|
2378
|
-
sendAndTransfer(message) {
|
|
2379
|
-
const transfer = getTransferrables(message);
|
|
2380
|
-
this._rawIpc.postMessage(message, transfer);
|
|
2381
|
-
}
|
|
2382
|
-
dispose() {
|
|
2383
|
-
if (this._rawIpc.close) {
|
|
2384
|
-
this._rawIpc.close();
|
|
2385
|
-
}
|
|
2386
|
-
}
|
|
2387
|
-
onClose(callback) {
|
|
2388
|
-
// ignore
|
|
2389
|
-
}
|
|
2390
|
-
onMessage(callback) {
|
|
2391
|
-
this._rawIpc.addEventListener('message', callback);
|
|
2392
|
-
this._rawIpc.start();
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
const wrap$e = port => {
|
|
2396
|
-
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
2397
|
-
};
|
|
2398
|
-
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
2399
|
-
__proto__: null,
|
|
2400
|
-
listen: listen$6,
|
|
2401
|
-
wrap: wrap$e
|
|
2402
|
-
};
|
|
2403
|
-
const addListener = (emitter, type, callback) => {
|
|
2404
|
-
if ('addEventListener' in emitter) {
|
|
2405
|
-
emitter.addEventListener(type, callback);
|
|
2406
|
-
} else {
|
|
2407
|
-
emitter.on(type, callback);
|
|
2408
|
-
}
|
|
2409
|
-
};
|
|
2410
|
-
const removeListener = (emitter, type, callback) => {
|
|
2411
|
-
if ('removeEventListener' in emitter) {
|
|
2412
|
-
emitter.removeEventListener(type, callback);
|
|
2413
|
-
} else {
|
|
2414
|
-
emitter.off(type, callback);
|
|
2415
|
-
}
|
|
2416
|
-
};
|
|
2417
|
-
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
2418
|
-
const {
|
|
2419
|
-
promise,
|
|
2420
|
-
resolve
|
|
2421
|
-
} = Promise.withResolvers();
|
|
2422
|
-
const listenerMap = Object.create(null);
|
|
2423
|
-
const cleanup = value => {
|
|
2424
|
-
for (const event of Object.keys(eventMap)) {
|
|
2425
|
-
removeListener(eventEmitter, event, listenerMap[event]);
|
|
2426
|
-
}
|
|
2427
|
-
resolve(value);
|
|
2428
|
-
};
|
|
2429
|
-
for (const [event, type] of Object.entries(eventMap)) {
|
|
2430
|
-
const listener = event => {
|
|
2431
|
-
cleanup({
|
|
2432
|
-
event,
|
|
2433
|
-
type
|
|
2434
|
-
});
|
|
2435
|
-
};
|
|
2436
|
-
addListener(eventEmitter, event, listener);
|
|
2437
|
-
listenerMap[event] = listener;
|
|
2438
|
-
}
|
|
2439
|
-
return promise;
|
|
2440
|
-
};
|
|
2441
|
-
const Message$1 = 3;
|
|
2442
|
-
const create$5$1 = async ({
|
|
2443
|
-
isMessagePortOpen,
|
|
2444
|
-
messagePort
|
|
2445
|
-
}) => {
|
|
2446
|
-
if (!isMessagePort(messagePort)) {
|
|
2447
|
-
throw new IpcError('port must be of type MessagePort');
|
|
2448
|
-
}
|
|
2449
|
-
if (isMessagePortOpen) {
|
|
2450
|
-
return messagePort;
|
|
2451
|
-
}
|
|
2452
|
-
const eventPromise = getFirstEvent(messagePort, {
|
|
2453
|
-
message: Message$1
|
|
2454
|
-
});
|
|
2455
|
-
messagePort.start();
|
|
2456
|
-
const {
|
|
2457
|
-
event,
|
|
2458
|
-
type
|
|
2459
|
-
} = await eventPromise;
|
|
2460
|
-
if (type !== Message$1) {
|
|
2461
|
-
throw new IpcError('Failed to wait for ipc message');
|
|
2462
|
-
}
|
|
2463
|
-
if (event.data !== readyMessage) {
|
|
2464
|
-
throw new IpcError('unexpected first message');
|
|
2465
|
-
}
|
|
2466
|
-
return messagePort;
|
|
2467
|
-
};
|
|
2468
|
-
const signal$1 = messagePort => {
|
|
2469
|
-
messagePort.start();
|
|
2470
|
-
};
|
|
2471
|
-
class IpcParentWithMessagePort extends Ipc {
|
|
2472
|
-
getData = getData$2;
|
|
2473
|
-
send(message) {
|
|
2474
|
-
this._rawIpc.postMessage(message);
|
|
2475
|
-
}
|
|
2476
|
-
sendAndTransfer(message) {
|
|
2477
|
-
const transfer = getTransferrables(message);
|
|
2478
|
-
this._rawIpc.postMessage(message, transfer);
|
|
2479
|
-
}
|
|
2480
|
-
dispose() {
|
|
2481
|
-
this._rawIpc.close();
|
|
2482
|
-
}
|
|
2483
|
-
onMessage(callback) {
|
|
2484
|
-
this._rawIpc.addEventListener('message', callback);
|
|
2485
|
-
}
|
|
2486
|
-
onClose(callback) {}
|
|
2487
|
-
}
|
|
2488
|
-
const wrap$5 = messagePort => {
|
|
2489
|
-
return new IpcParentWithMessagePort(messagePort);
|
|
2490
|
-
};
|
|
2491
|
-
const IpcParentWithMessagePort$1 = {
|
|
2492
|
-
__proto__: null,
|
|
2493
|
-
create: create$5$1,
|
|
2494
|
-
signal: signal$1,
|
|
2495
|
-
wrap: wrap$5
|
|
2496
|
-
};
|
|
2497
|
-
|
|
2498
|
-
const Two$1 = '2.0';
|
|
2499
|
-
const callbacks$1 = Object.create(null);
|
|
2500
|
-
const get = id => {
|
|
2501
|
-
return callbacks$1[id];
|
|
2502
|
-
};
|
|
2503
|
-
const remove = id => {
|
|
2504
|
-
delete callbacks$1[id];
|
|
2505
|
-
};
|
|
2506
|
-
class JsonRpcError extends Error {
|
|
2507
|
-
constructor(message) {
|
|
2508
|
-
super(message);
|
|
2509
|
-
this.name = 'JsonRpcError';
|
|
2510
|
-
}
|
|
2511
|
-
}
|
|
2512
|
-
const NewLine = '\n';
|
|
2513
|
-
const DomException = 'DOMException';
|
|
2514
|
-
const ReferenceError$1 = 'ReferenceError';
|
|
2515
|
-
const SyntaxError$1 = 'SyntaxError';
|
|
2516
|
-
const TypeError$1 = 'TypeError';
|
|
2517
|
-
const getErrorConstructor = (message, type) => {
|
|
2518
|
-
if (type) {
|
|
2519
|
-
switch (type) {
|
|
2520
|
-
case DomException:
|
|
2521
|
-
return DOMException;
|
|
2522
|
-
case ReferenceError$1:
|
|
2523
|
-
return ReferenceError;
|
|
2524
|
-
case SyntaxError$1:
|
|
2525
|
-
return SyntaxError;
|
|
2526
|
-
case TypeError$1:
|
|
2527
|
-
return TypeError;
|
|
2528
|
-
default:
|
|
2529
|
-
return Error;
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
if (message.startsWith('TypeError: ')) {
|
|
2533
|
-
return TypeError;
|
|
2534
|
-
}
|
|
2535
|
-
if (message.startsWith('SyntaxError: ')) {
|
|
2536
|
-
return SyntaxError;
|
|
2537
|
-
}
|
|
2538
|
-
if (message.startsWith('ReferenceError: ')) {
|
|
2539
|
-
return ReferenceError;
|
|
2540
|
-
}
|
|
2541
|
-
return Error;
|
|
2542
|
-
};
|
|
2543
|
-
const constructError = (message, type, name) => {
|
|
2544
|
-
const ErrorConstructor = getErrorConstructor(message, type);
|
|
2545
|
-
if (ErrorConstructor === DOMException && name) {
|
|
2546
|
-
return new ErrorConstructor(message, name);
|
|
2547
|
-
}
|
|
2548
|
-
if (ErrorConstructor === Error) {
|
|
2549
|
-
const error = new Error(message);
|
|
2550
|
-
if (name && name !== 'VError') {
|
|
2551
|
-
error.name = name;
|
|
2552
|
-
}
|
|
2553
|
-
return error;
|
|
2554
|
-
}
|
|
2555
|
-
return new ErrorConstructor(message);
|
|
2556
|
-
};
|
|
2557
|
-
const joinLines = lines => {
|
|
2558
|
-
return lines.join(NewLine);
|
|
2559
|
-
};
|
|
2560
|
-
const splitLines = lines => {
|
|
2561
|
-
return lines.split(NewLine);
|
|
2562
|
-
};
|
|
2563
|
-
const getCurrentStack = () => {
|
|
2564
|
-
const stackLinesToSkip = 3;
|
|
2565
|
-
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
2566
|
-
return currentStack;
|
|
2567
|
-
};
|
|
2568
|
-
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
2569
|
-
return string.indexOf(NewLine, startIndex);
|
|
2570
|
-
};
|
|
2571
|
-
const getParentStack = error => {
|
|
2572
|
-
let parentStack = error.stack || error.data || error.message || '';
|
|
2573
|
-
if (parentStack.startsWith(' at')) {
|
|
2574
|
-
parentStack = error.message + NewLine + parentStack;
|
|
2575
|
-
}
|
|
2576
|
-
return parentStack;
|
|
2577
|
-
};
|
|
2578
|
-
const MethodNotFound = -32601;
|
|
2579
|
-
const Custom$1 = -32001;
|
|
2580
|
-
const restoreJsonRpcError = error => {
|
|
2581
|
-
const currentStack = getCurrentStack();
|
|
2582
|
-
if (error && error instanceof Error) {
|
|
2583
|
-
if (typeof error.stack === 'string') {
|
|
2584
|
-
error.stack = error.stack + NewLine + currentStack;
|
|
2585
|
-
}
|
|
2586
|
-
return error;
|
|
2587
|
-
}
|
|
2588
|
-
if (error && error.code && error.code === MethodNotFound) {
|
|
2589
|
-
const restoredError = new JsonRpcError(error.message);
|
|
2590
|
-
const parentStack = getParentStack(error);
|
|
2591
|
-
restoredError.stack = parentStack + NewLine + currentStack;
|
|
2592
|
-
return restoredError;
|
|
2593
|
-
}
|
|
2594
|
-
if (error && error.message) {
|
|
2595
|
-
const restoredError = constructError(error.message, error.type, error.name);
|
|
2596
|
-
if (error.data) {
|
|
2597
|
-
if (error.data.stack && error.data.type && error.message) {
|
|
2598
|
-
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
2599
|
-
} else if (error.data.stack) {
|
|
2600
|
-
restoredError.stack = error.data.stack;
|
|
2601
|
-
}
|
|
2602
|
-
if (error.data.codeFrame) {
|
|
2603
|
-
// @ts-ignore
|
|
2604
|
-
restoredError.codeFrame = error.data.codeFrame;
|
|
2605
|
-
}
|
|
2606
|
-
if (error.data.code) {
|
|
2607
|
-
// @ts-ignore
|
|
2608
|
-
restoredError.code = error.data.code;
|
|
2609
|
-
}
|
|
2610
|
-
if (error.data.type) {
|
|
2611
|
-
// @ts-ignore
|
|
2612
|
-
restoredError.name = error.data.type;
|
|
2613
|
-
}
|
|
2614
|
-
} else {
|
|
2615
|
-
if (error.stack) {
|
|
2616
|
-
const lowerStack = restoredError.stack || '';
|
|
2617
|
-
// @ts-ignore
|
|
2618
|
-
const indexNewLine = getNewLineIndex(lowerStack);
|
|
2619
|
-
const parentStack = getParentStack(error);
|
|
2620
|
-
// @ts-ignore
|
|
2621
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
2622
|
-
}
|
|
2623
|
-
if (error.codeFrame) {
|
|
2624
|
-
// @ts-ignore
|
|
2625
|
-
restoredError.codeFrame = error.codeFrame;
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
return restoredError;
|
|
2629
|
-
}
|
|
2630
|
-
if (typeof error === 'string') {
|
|
2631
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
2632
|
-
}
|
|
2633
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
2634
|
-
};
|
|
2635
|
-
const unwrapJsonRpcResult = responseMessage => {
|
|
2636
|
-
if ('error' in responseMessage) {
|
|
2637
|
-
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
2638
|
-
throw restoredError;
|
|
2639
|
-
}
|
|
2640
|
-
if ('result' in responseMessage) {
|
|
2641
|
-
return responseMessage.result;
|
|
2642
|
-
}
|
|
2643
|
-
throw new JsonRpcError('unexpected response message');
|
|
2644
|
-
};
|
|
2645
|
-
const warn = (...args) => {
|
|
2646
|
-
console.warn(...args);
|
|
2647
|
-
};
|
|
2648
|
-
const resolve = (id, response) => {
|
|
2649
|
-
const fn = get(id);
|
|
2650
|
-
if (!fn) {
|
|
2651
|
-
console.log(response);
|
|
2652
|
-
warn(`callback ${id} may already be disposed`);
|
|
2653
|
-
return;
|
|
2654
|
-
}
|
|
2655
|
-
fn(response);
|
|
2656
|
-
remove(id);
|
|
2657
|
-
};
|
|
2658
|
-
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
2659
|
-
const getErrorType = prettyError => {
|
|
2660
|
-
if (prettyError && prettyError.type) {
|
|
2661
|
-
return prettyError.type;
|
|
2662
|
-
}
|
|
2663
|
-
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
2664
|
-
return prettyError.constructor.name;
|
|
2665
|
-
}
|
|
2666
|
-
return undefined;
|
|
2667
|
-
};
|
|
2668
|
-
const isAlreadyStack = line => {
|
|
2669
|
-
return line.trim().startsWith('at ');
|
|
2670
|
-
};
|
|
2671
|
-
const getStack = prettyError => {
|
|
2672
|
-
const stackString = prettyError.stack || '';
|
|
2673
|
-
const newLineIndex = stackString.indexOf('\n');
|
|
2674
|
-
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
2675
|
-
return stackString.slice(newLineIndex + 1);
|
|
2676
|
-
}
|
|
2677
|
-
return stackString;
|
|
2678
|
-
};
|
|
2679
|
-
const getErrorProperty = (error, prettyError) => {
|
|
2680
|
-
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
2681
|
-
return {
|
|
2682
|
-
code: MethodNotFound,
|
|
2683
|
-
data: error.stack,
|
|
2684
|
-
message: error.message
|
|
2685
|
-
};
|
|
2686
|
-
}
|
|
2687
|
-
return {
|
|
2688
|
-
code: Custom$1,
|
|
2689
|
-
data: {
|
|
2690
|
-
code: prettyError.code,
|
|
2691
|
-
codeFrame: prettyError.codeFrame,
|
|
2692
|
-
name: prettyError.name,
|
|
2693
|
-
stack: getStack(prettyError),
|
|
2694
|
-
type: getErrorType(prettyError)
|
|
2695
|
-
},
|
|
2696
|
-
message: prettyError.message
|
|
2697
|
-
};
|
|
2698
|
-
};
|
|
2699
|
-
const create$1$1 = (id, error) => {
|
|
2700
|
-
return {
|
|
2701
|
-
error,
|
|
2702
|
-
id,
|
|
2703
|
-
jsonrpc: Two$1
|
|
2704
|
-
};
|
|
2705
|
-
};
|
|
2706
|
-
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
2707
|
-
const prettyError = preparePrettyError(error);
|
|
2708
|
-
logError(error, prettyError);
|
|
2709
|
-
const errorProperty = getErrorProperty(error, prettyError);
|
|
2710
|
-
return create$1$1(id, errorProperty);
|
|
2711
|
-
};
|
|
2712
|
-
const create$7 = (message, result) => {
|
|
2713
|
-
return {
|
|
2714
|
-
id: message.id,
|
|
2715
|
-
jsonrpc: Two$1,
|
|
2716
|
-
result: result ?? null
|
|
2717
|
-
};
|
|
2718
|
-
};
|
|
2719
|
-
const getSuccessResponse = (message, result) => {
|
|
2720
|
-
const resultProperty = result ?? null;
|
|
2721
|
-
return create$7(message, resultProperty);
|
|
2722
|
-
};
|
|
2723
|
-
const getErrorResponseSimple = (id, error) => {
|
|
2724
|
-
return {
|
|
2725
|
-
error: {
|
|
2726
|
-
code: Custom$1,
|
|
2727
|
-
data: error,
|
|
2728
|
-
// @ts-ignore
|
|
2729
|
-
message: error.message
|
|
2730
|
-
},
|
|
2731
|
-
id,
|
|
2732
|
-
jsonrpc: Two$1
|
|
2733
|
-
};
|
|
2734
|
-
};
|
|
2735
|
-
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
2736
|
-
try {
|
|
2737
|
-
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
2738
|
-
return getSuccessResponse(message, result);
|
|
2739
|
-
} catch (error) {
|
|
2740
|
-
if (ipc.canUseSimpleErrorResponse) {
|
|
2741
|
-
return getErrorResponseSimple(message.id, error);
|
|
2742
|
-
}
|
|
2743
|
-
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
2744
|
-
}
|
|
2745
|
-
};
|
|
2746
|
-
const defaultPreparePrettyError = error => {
|
|
2747
|
-
return error;
|
|
2748
|
-
};
|
|
2749
|
-
const defaultLogError = () => {
|
|
2750
|
-
// ignore
|
|
2751
|
-
};
|
|
2752
|
-
const defaultRequiresSocket = () => {
|
|
2753
|
-
return false;
|
|
2754
|
-
};
|
|
2755
|
-
const defaultResolve = resolve;
|
|
2756
|
-
|
|
2757
|
-
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
2758
|
-
const normalizeParams = args => {
|
|
2759
|
-
if (args.length === 1) {
|
|
2760
|
-
const options = args[0];
|
|
2761
|
-
return {
|
|
2762
|
-
execute: options.execute,
|
|
2763
|
-
ipc: options.ipc,
|
|
2764
|
-
logError: options.logError || defaultLogError,
|
|
2765
|
-
message: options.message,
|
|
2766
|
-
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
2767
|
-
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
2768
|
-
resolve: options.resolve || defaultResolve
|
|
2769
|
-
};
|
|
2770
|
-
}
|
|
2771
|
-
return {
|
|
2772
|
-
execute: args[2],
|
|
2773
|
-
ipc: args[0],
|
|
2774
|
-
logError: args[5],
|
|
2775
|
-
message: args[1],
|
|
2776
|
-
preparePrettyError: args[4],
|
|
2777
|
-
requiresSocket: args[6],
|
|
2778
|
-
resolve: args[3]
|
|
2779
|
-
};
|
|
2780
|
-
};
|
|
2781
|
-
const handleJsonRpcMessage = async (...args) => {
|
|
2782
|
-
const options = normalizeParams(args);
|
|
2783
|
-
const {
|
|
2784
|
-
execute,
|
|
2785
|
-
ipc,
|
|
2786
|
-
logError,
|
|
2787
|
-
message,
|
|
2788
|
-
preparePrettyError,
|
|
2789
|
-
requiresSocket,
|
|
2790
|
-
resolve
|
|
2791
|
-
} = options;
|
|
2792
|
-
if ('id' in message) {
|
|
2793
|
-
if ('method' in message) {
|
|
2794
|
-
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
2795
|
-
try {
|
|
2796
|
-
ipc.send(response);
|
|
2797
|
-
} catch (error) {
|
|
2798
|
-
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
2799
|
-
ipc.send(errorResponse);
|
|
2800
|
-
}
|
|
2801
|
-
return;
|
|
2802
|
-
}
|
|
2803
|
-
resolve(message.id, message);
|
|
2804
|
-
return;
|
|
2805
|
-
}
|
|
2806
|
-
if ('method' in message) {
|
|
2807
|
-
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
2808
|
-
return;
|
|
2809
|
-
}
|
|
2810
|
-
throw new JsonRpcError('unexpected message');
|
|
2811
|
-
};
|
|
2812
|
-
|
|
2813
|
-
const Two = '2.0';
|
|
2814
|
-
|
|
2815
|
-
const create$6 = (method, params) => {
|
|
2816
|
-
return {
|
|
2817
|
-
jsonrpc: Two,
|
|
2818
|
-
method,
|
|
2819
|
-
params
|
|
2820
|
-
};
|
|
2821
|
-
};
|
|
2822
|
-
|
|
2823
|
-
const create$5 = (id, method, params) => {
|
|
2824
|
-
const message = {
|
|
2825
|
-
id,
|
|
2826
|
-
jsonrpc: Two,
|
|
2827
|
-
method,
|
|
2828
|
-
params
|
|
2829
|
-
};
|
|
2830
|
-
return message;
|
|
2831
|
-
};
|
|
2832
|
-
|
|
2833
|
-
let id = 0;
|
|
2834
|
-
const create$4 = () => {
|
|
2835
|
-
return ++id;
|
|
2836
|
-
};
|
|
2837
|
-
|
|
2838
|
-
const registerPromise = map => {
|
|
2839
|
-
const id = create$4();
|
|
2840
|
-
const {
|
|
2841
|
-
promise,
|
|
2842
|
-
resolve
|
|
2843
|
-
} = Promise.withResolvers();
|
|
2844
|
-
map[id] = resolve;
|
|
2845
|
-
return {
|
|
2846
|
-
id,
|
|
2847
|
-
promise
|
|
2848
|
-
};
|
|
2849
|
-
};
|
|
2850
|
-
|
|
2851
|
-
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
2852
|
-
const {
|
|
2853
|
-
id,
|
|
2854
|
-
promise
|
|
2855
|
-
} = registerPromise(callbacks);
|
|
2856
|
-
const message = create$5(id, method, params);
|
|
2857
|
-
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
2858
|
-
ipc.sendAndTransfer(message);
|
|
2859
|
-
} else {
|
|
2860
|
-
ipc.send(message);
|
|
2861
|
-
}
|
|
2862
|
-
const responseMessage = await promise;
|
|
2863
|
-
return unwrapJsonRpcResult(responseMessage);
|
|
2864
|
-
};
|
|
2865
|
-
const createRpc = ipc => {
|
|
2866
|
-
const callbacks = Object.create(null);
|
|
2867
|
-
ipc._resolve = (id, response) => {
|
|
2868
|
-
const fn = callbacks[id];
|
|
2869
|
-
if (!fn) {
|
|
2870
|
-
console.warn(`callback ${id} may already be disposed`);
|
|
2871
|
-
return;
|
|
2872
|
-
}
|
|
2873
|
-
fn(response);
|
|
2874
|
-
delete callbacks[id];
|
|
2875
|
-
};
|
|
2876
|
-
const rpc = {
|
|
2877
|
-
async dispose() {
|
|
2878
|
-
await ipc?.dispose();
|
|
2879
|
-
},
|
|
2880
|
-
invoke(method, ...params) {
|
|
2881
|
-
return invokeHelper(callbacks, ipc, method, params, false);
|
|
2882
|
-
},
|
|
2883
|
-
invokeAndTransfer(method, ...params) {
|
|
2884
|
-
return invokeHelper(callbacks, ipc, method, params, true);
|
|
2885
|
-
},
|
|
2886
|
-
// @ts-ignore
|
|
2887
|
-
ipc,
|
|
2888
|
-
/**
|
|
2889
|
-
* @deprecated
|
|
2890
|
-
*/
|
|
2891
|
-
send(method, ...params) {
|
|
2892
|
-
const message = create$6(method, params);
|
|
2893
|
-
ipc.send(message);
|
|
2894
|
-
}
|
|
2895
|
-
};
|
|
2896
|
-
return rpc;
|
|
2897
|
-
};
|
|
2898
|
-
|
|
2899
|
-
const requiresSocket = () => {
|
|
2900
|
-
return false;
|
|
2901
|
-
};
|
|
2902
|
-
const preparePrettyError = error => {
|
|
2903
|
-
return error;
|
|
2904
|
-
};
|
|
2905
|
-
const logError = () => {
|
|
2906
|
-
// handled by renderer worker
|
|
2907
|
-
};
|
|
2908
|
-
const handleMessage = event => {
|
|
2909
|
-
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
2910
|
-
const actualExecute = event?.target?.execute || execute;
|
|
2911
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
2912
|
-
};
|
|
2913
|
-
|
|
2914
|
-
const handleIpc = ipc => {
|
|
2915
|
-
if ('addEventListener' in ipc) {
|
|
2916
|
-
ipc.addEventListener('message', handleMessage);
|
|
2917
|
-
} else if ('on' in ipc) {
|
|
2918
|
-
// deprecated
|
|
2919
|
-
ipc.on('message', handleMessage);
|
|
2920
|
-
}
|
|
2921
|
-
};
|
|
2922
|
-
|
|
2923
|
-
const listen$1 = async (module, options) => {
|
|
2924
|
-
const rawIpc = await module.listen(options);
|
|
2925
|
-
if (module.signal) {
|
|
2926
|
-
module.signal(rawIpc);
|
|
2927
|
-
}
|
|
2928
|
-
const ipc = module.wrap(rawIpc);
|
|
2929
|
-
return ipc;
|
|
2930
|
-
};
|
|
2931
|
-
|
|
2932
|
-
const create$3 = async ({
|
|
2933
|
-
commandMap,
|
|
2934
|
-
isMessagePortOpen = true,
|
|
2935
|
-
messagePort
|
|
2936
|
-
}) => {
|
|
2937
|
-
// TODO create a commandMap per rpc instance
|
|
2938
|
-
register$1(commandMap);
|
|
2939
|
-
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
2940
|
-
isMessagePortOpen,
|
|
2941
|
-
messagePort
|
|
2942
|
-
});
|
|
2943
|
-
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
2944
|
-
handleIpc(ipc);
|
|
2945
|
-
const rpc = createRpc(ipc);
|
|
2946
|
-
messagePort.start();
|
|
2947
|
-
return rpc;
|
|
2948
|
-
};
|
|
2949
|
-
|
|
2950
|
-
const create$2 = async ({
|
|
2951
|
-
commandMap,
|
|
2952
|
-
isMessagePortOpen,
|
|
2953
|
-
send
|
|
2954
|
-
}) => {
|
|
2955
|
-
const {
|
|
2956
|
-
port1,
|
|
2957
|
-
port2
|
|
2958
|
-
} = new MessageChannel();
|
|
2959
|
-
await send(port1);
|
|
2960
|
-
return create$3({
|
|
2961
|
-
commandMap,
|
|
2962
|
-
isMessagePortOpen,
|
|
2963
|
-
messagePort: port2
|
|
2964
|
-
});
|
|
2965
|
-
};
|
|
2966
|
-
|
|
2967
|
-
const createSharedLazyRpc = factory => {
|
|
2968
|
-
let rpcPromise;
|
|
2969
|
-
const getOrCreate = () => {
|
|
2970
|
-
if (!rpcPromise) {
|
|
2971
|
-
rpcPromise = factory();
|
|
2972
|
-
}
|
|
2973
|
-
return rpcPromise;
|
|
2974
|
-
};
|
|
2975
|
-
return {
|
|
2976
|
-
async dispose() {
|
|
2977
|
-
const rpc = await getOrCreate();
|
|
2978
|
-
await rpc.dispose();
|
|
2979
|
-
},
|
|
2980
|
-
async invoke(method, ...params) {
|
|
2981
|
-
const rpc = await getOrCreate();
|
|
2982
|
-
return rpc.invoke(method, ...params);
|
|
2983
|
-
},
|
|
2984
|
-
async invokeAndTransfer(method, ...params) {
|
|
2985
|
-
const rpc = await getOrCreate();
|
|
2986
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
2987
|
-
},
|
|
2988
|
-
async send(method, ...params) {
|
|
2989
|
-
const rpc = await getOrCreate();
|
|
2990
|
-
rpc.send(method, ...params);
|
|
2991
|
-
}
|
|
2992
|
-
};
|
|
2993
|
-
};
|
|
2994
|
-
|
|
2995
|
-
const create$1 = async ({
|
|
2996
|
-
commandMap,
|
|
2997
|
-
isMessagePortOpen,
|
|
2998
|
-
send
|
|
2999
|
-
}) => {
|
|
3000
|
-
return createSharedLazyRpc(() => {
|
|
3001
|
-
return create$2({
|
|
3002
|
-
commandMap,
|
|
3003
|
-
isMessagePortOpen,
|
|
3004
|
-
send
|
|
3005
|
-
});
|
|
3006
|
-
});
|
|
3007
|
-
};
|
|
3008
|
-
|
|
3009
|
-
const create = async ({
|
|
3010
|
-
commandMap
|
|
3011
|
-
}) => {
|
|
3012
|
-
// TODO create a commandMap per rpc instance
|
|
3013
|
-
register$1(commandMap);
|
|
3014
|
-
const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
|
|
3015
|
-
handleIpc(ipc);
|
|
3016
|
-
const rpc = createRpc(ipc);
|
|
3017
|
-
return rpc;
|
|
3018
|
-
};
|
|
3019
|
-
|
|
3020
|
-
const commandMapRef = {};
|
|
3021
|
-
|
|
3022
|
-
const handleMessagePort = async port => {
|
|
3023
|
-
await create$3({
|
|
3024
|
-
commandMap: commandMapRef,
|
|
3025
|
-
isMessagePortOpen: true,
|
|
3026
|
-
messagePort: port
|
|
3027
|
-
});
|
|
3028
|
-
};
|
|
3029
|
-
|
|
3030
|
-
const initialize = async () => {
|
|
3031
|
-
// not needed anymore
|
|
3032
|
-
};
|
|
3033
|
-
|
|
3034
|
-
const getDefaultValue = id => {
|
|
3035
|
-
switch (id) {
|
|
3036
|
-
case EveryThing$1:
|
|
3037
|
-
return Command;
|
|
3038
|
-
default:
|
|
3039
|
-
return '';
|
|
637
|
+
const resolve = (id, response) => {
|
|
638
|
+
const fn = get$1(id);
|
|
639
|
+
if (!fn) {
|
|
640
|
+
console.log(response);
|
|
641
|
+
warn(`callback ${id} may already be disposed`);
|
|
642
|
+
return;
|
|
3040
643
|
}
|
|
644
|
+
fn(response);
|
|
645
|
+
remove$1(id);
|
|
3041
646
|
};
|
|
3042
|
-
|
|
3043
|
-
const
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
const Help = 'quickPick://help';
|
|
3050
|
-
const WorkspaceSymbol = 'quickPick://workspace-symbol';
|
|
3051
|
-
const Custom = 'quickPick://custom';
|
|
3052
|
-
const GoToLine = 'quickPick://go-to-line';
|
|
3053
|
-
|
|
3054
|
-
const getQuickPickProviderId = prefix => {
|
|
3055
|
-
switch (prefix) {
|
|
3056
|
-
case ColorTheme:
|
|
3057
|
-
return ColorTheme$1;
|
|
3058
|
-
case Commands:
|
|
3059
|
-
case EveryThing:
|
|
3060
|
-
case GoToLine:
|
|
3061
|
-
case Help:
|
|
3062
|
-
case Symbol$1:
|
|
3063
|
-
case View:
|
|
3064
|
-
case WorkspaceSymbol:
|
|
3065
|
-
return EveryThing$1;
|
|
3066
|
-
case Custom:
|
|
3067
|
-
return Custom$2;
|
|
3068
|
-
case Recent:
|
|
3069
|
-
return Recent$1;
|
|
3070
|
-
default:
|
|
3071
|
-
return File$2;
|
|
647
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
648
|
+
const getErrorType = prettyError => {
|
|
649
|
+
if (prettyError && prettyError.type) {
|
|
650
|
+
return prettyError.type;
|
|
651
|
+
}
|
|
652
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
653
|
+
return prettyError.constructor.name;
|
|
3072
654
|
}
|
|
655
|
+
return undefined;
|
|
3073
656
|
};
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
657
|
+
const isAlreadyStack = line => {
|
|
658
|
+
return line.trim().startsWith('at ');
|
|
659
|
+
};
|
|
660
|
+
const getStack = prettyError => {
|
|
661
|
+
const stackString = prettyError.stack || '';
|
|
662
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
663
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
664
|
+
return stackString.slice(newLineIndex + 1);
|
|
3081
665
|
}
|
|
3082
|
-
|
|
3083
|
-
|
|
666
|
+
return stackString;
|
|
667
|
+
};
|
|
668
|
+
const getErrorProperty = (error, prettyError) => {
|
|
669
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
3084
670
|
return {
|
|
3085
|
-
|
|
3086
|
-
|
|
671
|
+
code: MethodNotFound,
|
|
672
|
+
data: error.stack,
|
|
673
|
+
message: error.message
|
|
3087
674
|
};
|
|
3088
675
|
}
|
|
3089
676
|
return {
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
677
|
+
code: Custom,
|
|
678
|
+
data: {
|
|
679
|
+
code: prettyError.code,
|
|
680
|
+
codeFrame: prettyError.codeFrame,
|
|
681
|
+
name: prettyError.name,
|
|
682
|
+
stack: getStack(prettyError),
|
|
683
|
+
type: getErrorType(prettyError)
|
|
684
|
+
},
|
|
685
|
+
message: prettyError.message
|
|
3094
686
|
};
|
|
3095
687
|
};
|
|
3096
|
-
const
|
|
3097
|
-
const {
|
|
3098
|
-
args,
|
|
3099
|
-
assetDir,
|
|
3100
|
-
fileIconCache,
|
|
3101
|
-
height,
|
|
3102
|
-
itemHeight,
|
|
3103
|
-
maxVisibleItems,
|
|
3104
|
-
platform,
|
|
3105
|
-
uri
|
|
3106
|
-
} = state;
|
|
3107
|
-
const id = getQuickPickProviderId(uri);
|
|
3108
|
-
const value = getDefaultValue(id);
|
|
3109
|
-
const prefix = getQuickPickPrefix(value);
|
|
3110
|
-
const subId = getQuickPickSubProviderId(id, prefix);
|
|
3111
|
-
const newPicks = await getPicks(subId, value, args, {
|
|
3112
|
-
assetDir,
|
|
3113
|
-
platform
|
|
3114
|
-
});
|
|
3115
|
-
array(newPicks);
|
|
3116
|
-
const filterValue = getFilterValue(id, subId, value);
|
|
3117
|
-
const items = filterQuickPickItems(newPicks, filterValue);
|
|
3118
|
-
const minLineY = 0;
|
|
3119
|
-
const maxLineY = Math.min(minLineY + maxVisibleItems, newPicks.length);
|
|
3120
|
-
const sliced = newPicks.slice(minLineY, maxLineY);
|
|
3121
|
-
const {
|
|
3122
|
-
icons,
|
|
3123
|
-
newFileIconCache
|
|
3124
|
-
} = await getQuickPickFileIcons(sliced, fileIconCache);
|
|
3125
|
-
const listHeight = getListHeight(items.length, itemHeight, height);
|
|
3126
|
-
const finalDeltaY = getFinalDeltaY(listHeight, itemHeight, items.length);
|
|
3127
|
-
const parsedArgs = parseArgs(subId, args);
|
|
3128
|
-
const finalValue = parsedArgs.initialValue || value;
|
|
688
|
+
const create$1$1 = (id, error) => {
|
|
3129
689
|
return {
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
fileIconCache: newFileIconCache,
|
|
3134
|
-
finalDeltaY,
|
|
3135
|
-
focused: true,
|
|
3136
|
-
focusedIndex: 0,
|
|
3137
|
-
icons,
|
|
3138
|
-
inputSource: Script,
|
|
3139
|
-
items,
|
|
3140
|
-
maxLineY,
|
|
3141
|
-
minLineY,
|
|
3142
|
-
picks: newPicks,
|
|
3143
|
-
placeholder: '',
|
|
3144
|
-
providerId: id,
|
|
3145
|
-
state: Finished,
|
|
3146
|
-
value: finalValue
|
|
690
|
+
error,
|
|
691
|
+
id,
|
|
692
|
+
jsonrpc: Two$1
|
|
3147
693
|
};
|
|
3148
694
|
};
|
|
3149
|
-
|
|
3150
|
-
const
|
|
3151
|
-
|
|
3152
|
-
const
|
|
3153
|
-
|
|
3154
|
-
fn();
|
|
695
|
+
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
696
|
+
const prettyError = preparePrettyError(error);
|
|
697
|
+
logError(error, prettyError);
|
|
698
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
699
|
+
return create$1$1(id, errorProperty);
|
|
3155
700
|
};
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
fileIcon: icons[index]
|
|
3163
|
-
};
|
|
3164
|
-
});
|
|
3165
|
-
return protoVisibleItems;
|
|
701
|
+
const create$8 = (message, result) => {
|
|
702
|
+
return {
|
|
703
|
+
id: message.id,
|
|
704
|
+
jsonrpc: Two$1,
|
|
705
|
+
result: result ?? null
|
|
706
|
+
};
|
|
3166
707
|
};
|
|
3167
|
-
|
|
3168
|
-
const
|
|
3169
|
-
|
|
3170
|
-
return 0;
|
|
3171
|
-
}
|
|
3172
|
-
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
708
|
+
const getSuccessResponse = (message, result) => {
|
|
709
|
+
const resultProperty = result ?? null;
|
|
710
|
+
return create$8(message, resultProperty);
|
|
3173
711
|
};
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
712
|
+
const getErrorResponseSimple = (id, error) => {
|
|
713
|
+
return {
|
|
714
|
+
error: {
|
|
715
|
+
code: Custom,
|
|
716
|
+
data: error,
|
|
717
|
+
// @ts-ignore
|
|
718
|
+
message: error.message
|
|
719
|
+
},
|
|
720
|
+
id,
|
|
721
|
+
jsonrpc: Two$1
|
|
722
|
+
};
|
|
723
|
+
};
|
|
724
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
725
|
+
try {
|
|
726
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
727
|
+
return getSuccessResponse(message, result);
|
|
728
|
+
} catch (error) {
|
|
729
|
+
if (ipc.canUseSimpleErrorResponse) {
|
|
730
|
+
return getErrorResponseSimple(message.id, error);
|
|
3192
731
|
}
|
|
3193
|
-
|
|
3194
|
-
sections.push({
|
|
3195
|
-
highlighted: true,
|
|
3196
|
-
text: highlightText
|
|
3197
|
-
});
|
|
3198
|
-
position = highlightEnd;
|
|
3199
|
-
}
|
|
3200
|
-
if (position < label.length) {
|
|
3201
|
-
const afterText = label.slice(position);
|
|
3202
|
-
sections.push({
|
|
3203
|
-
highlighted: false,
|
|
3204
|
-
text: afterText
|
|
3205
|
-
});
|
|
732
|
+
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
3206
733
|
}
|
|
3207
|
-
return sections;
|
|
3208
734
|
};
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
const visibleItems = protoVisibleItems.map((visibleItem, i) => {
|
|
3212
|
-
const highlights = visibleItem.matches.slice(1);
|
|
3213
|
-
const sections = getHighlightSections(highlights, visibleItem.label);
|
|
3214
|
-
return {
|
|
3215
|
-
...visibleItem,
|
|
3216
|
-
highlights: sections,
|
|
3217
|
-
isActive: i === focusedIndex,
|
|
3218
|
-
posInSet: minLineY + i + 1,
|
|
3219
|
-
setSize
|
|
3220
|
-
};
|
|
3221
|
-
});
|
|
3222
|
-
return visibleItems;
|
|
735
|
+
const defaultPreparePrettyError = error => {
|
|
736
|
+
return error;
|
|
3223
737
|
};
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
|
|
3227
|
-
return scrollBarOffset;
|
|
738
|
+
const defaultLogError = () => {
|
|
739
|
+
// ignore
|
|
3228
740
|
};
|
|
3229
|
-
const
|
|
741
|
+
const defaultRequiresSocket = () => {
|
|
742
|
+
return false;
|
|
743
|
+
};
|
|
744
|
+
const defaultResolve = resolve;
|
|
3230
745
|
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
minLineY,
|
|
3246
|
-
uid,
|
|
3247
|
-
value
|
|
3248
|
-
} = newState;
|
|
3249
|
-
const protoVisibleItems = getVisible$1(items, minLineY, maxLineY, icons);
|
|
3250
|
-
const visibleItems = getVisible(items.length, protoVisibleItems, minLineY, focusedIndex);
|
|
3251
|
-
const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
|
|
3252
|
-
const newFocusedIndex = focusedIndex - minLineY;
|
|
3253
|
-
const itemCount = items.length;
|
|
3254
|
-
const listHeight = getListHeight(itemCount, itemHeight, height);
|
|
3255
|
-
const contentHeight = itemCount * itemHeight;
|
|
3256
|
-
const scrollBarHeight = getScrollBarSize(listHeight, contentHeight, minimumSliderSize);
|
|
3257
|
-
const scrollBarY = getScrollBarY(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
|
|
3258
|
-
const roundedScrollBarY = Math.round(scrollBarY);
|
|
746
|
+
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
747
|
+
const normalizeParams = args => {
|
|
748
|
+
if (args.length === 1) {
|
|
749
|
+
const options = args[0];
|
|
750
|
+
return {
|
|
751
|
+
execute: options.execute,
|
|
752
|
+
ipc: options.ipc,
|
|
753
|
+
logError: options.logError || defaultLogError,
|
|
754
|
+
message: options.message,
|
|
755
|
+
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
756
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
757
|
+
resolve: options.resolve || defaultResolve
|
|
758
|
+
};
|
|
759
|
+
}
|
|
3259
760
|
return {
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
uid,
|
|
3268
|
-
value,
|
|
3269
|
-
visibleItems
|
|
761
|
+
execute: args[2],
|
|
762
|
+
ipc: args[0],
|
|
763
|
+
logError: args[5],
|
|
764
|
+
message: args[1],
|
|
765
|
+
preparePrettyError: args[4],
|
|
766
|
+
requiresSocket: args[6],
|
|
767
|
+
resolve: args[3]
|
|
3270
768
|
};
|
|
3271
769
|
};
|
|
3272
|
-
|
|
3273
|
-
const
|
|
3274
|
-
const SetFocusedIndex = 'setFocusedIndex';
|
|
3275
|
-
const SetItemsHeight = 'setItemsHeight';
|
|
3276
|
-
|
|
3277
|
-
const renderCursorOffset = newState => {
|
|
3278
|
-
return ['Viewlet.send', newState.uid, /* method */SetCursorOffset, /* cursorOffset */newState.cursorOffset];
|
|
3279
|
-
};
|
|
3280
|
-
|
|
3281
|
-
const QuickPickInput = 'QuickPickInput';
|
|
3282
|
-
|
|
3283
|
-
const renderFocus = newState => {
|
|
3284
|
-
return ['Viewlet.focusElementByName', QuickPickInput];
|
|
3285
|
-
};
|
|
3286
|
-
|
|
3287
|
-
const renderFocusedIndex = newState => {
|
|
3288
|
-
return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */newState.oldFocusedIndex, /* newFocusedIndex */newState.newFocusedIndex];
|
|
3289
|
-
};
|
|
3290
|
-
|
|
3291
|
-
const renderHeight = newState => {
|
|
770
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
771
|
+
const options = normalizeParams(args);
|
|
3292
772
|
const {
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
773
|
+
execute,
|
|
774
|
+
ipc,
|
|
775
|
+
logError,
|
|
776
|
+
message,
|
|
777
|
+
preparePrettyError,
|
|
778
|
+
requiresSocket,
|
|
779
|
+
resolve
|
|
780
|
+
} = options;
|
|
781
|
+
if ('id' in message) {
|
|
782
|
+
if ('method' in message) {
|
|
783
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
784
|
+
try {
|
|
785
|
+
ipc.send(response);
|
|
786
|
+
} catch (error) {
|
|
787
|
+
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
788
|
+
ipc.send(errorResponse);
|
|
789
|
+
}
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
resolve(message.id, message);
|
|
793
|
+
return;
|
|
3298
794
|
}
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
795
|
+
if ('method' in message) {
|
|
796
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
throw new JsonRpcError('unexpected message');
|
|
3304
800
|
};
|
|
3305
801
|
|
|
3306
|
-
const
|
|
3307
|
-
return `${value}px`;
|
|
3308
|
-
};
|
|
3309
|
-
const position = (x, y) => {
|
|
3310
|
-
return `${x}px ${y}px`;
|
|
3311
|
-
};
|
|
802
|
+
const Two = '2.0';
|
|
3312
803
|
|
|
3313
|
-
const
|
|
804
|
+
const create$7 = (method, params) => {
|
|
3314
805
|
return {
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
806
|
+
jsonrpc: Two,
|
|
807
|
+
method,
|
|
808
|
+
params
|
|
3318
809
|
};
|
|
3319
810
|
};
|
|
3320
811
|
|
|
3321
|
-
const
|
|
3322
|
-
const
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
const NavigateSibling = 10;
|
|
3330
|
-
|
|
3331
|
-
const isKey = key => {
|
|
3332
|
-
return key !== 'type' && key !== 'childCount';
|
|
812
|
+
const create$6 = (id, method, params) => {
|
|
813
|
+
const message = {
|
|
814
|
+
id,
|
|
815
|
+
jsonrpc: Two,
|
|
816
|
+
method,
|
|
817
|
+
params
|
|
818
|
+
};
|
|
819
|
+
return message;
|
|
3333
820
|
};
|
|
3334
821
|
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
return
|
|
822
|
+
let id = 0;
|
|
823
|
+
const create$5 = () => {
|
|
824
|
+
return ++id;
|
|
3338
825
|
};
|
|
3339
826
|
|
|
3340
|
-
const
|
|
3341
|
-
const
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
nodesConsumed
|
|
3348
|
-
} = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
|
|
3349
|
-
result.push({
|
|
3350
|
-
node,
|
|
3351
|
-
children
|
|
3352
|
-
});
|
|
3353
|
-
i += 1 + nodesConsumed;
|
|
3354
|
-
}
|
|
3355
|
-
return result;
|
|
3356
|
-
};
|
|
3357
|
-
const getChildrenWithCount = (nodes, startIndex, childCount) => {
|
|
3358
|
-
if (childCount === 0) {
|
|
3359
|
-
return {
|
|
3360
|
-
children: [],
|
|
3361
|
-
nodesConsumed: 0
|
|
3362
|
-
};
|
|
3363
|
-
}
|
|
3364
|
-
const children = [];
|
|
3365
|
-
let i = startIndex;
|
|
3366
|
-
let remaining = childCount;
|
|
3367
|
-
let totalConsumed = 0;
|
|
3368
|
-
while (remaining > 0 && i < nodes.length) {
|
|
3369
|
-
const node = nodes[i];
|
|
3370
|
-
const nodeChildCount = node.childCount || 0;
|
|
3371
|
-
const {
|
|
3372
|
-
children: nodeChildren,
|
|
3373
|
-
nodesConsumed
|
|
3374
|
-
} = getChildrenWithCount(nodes, i + 1, nodeChildCount);
|
|
3375
|
-
children.push({
|
|
3376
|
-
node,
|
|
3377
|
-
children: nodeChildren
|
|
3378
|
-
});
|
|
3379
|
-
const nodeSize = 1 + nodesConsumed;
|
|
3380
|
-
i += nodeSize;
|
|
3381
|
-
totalConsumed += nodeSize;
|
|
3382
|
-
remaining--;
|
|
3383
|
-
}
|
|
827
|
+
const registerPromise = map => {
|
|
828
|
+
const id = create$5();
|
|
829
|
+
const {
|
|
830
|
+
promise,
|
|
831
|
+
resolve
|
|
832
|
+
} = Promise.withResolvers();
|
|
833
|
+
map[id] = resolve;
|
|
3384
834
|
return {
|
|
3385
|
-
|
|
3386
|
-
|
|
835
|
+
id,
|
|
836
|
+
promise
|
|
3387
837
|
};
|
|
3388
838
|
};
|
|
3389
839
|
|
|
3390
|
-
const
|
|
3391
|
-
const
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
patches.push({
|
|
3401
|
-
type: SetText,
|
|
3402
|
-
value: newNode.text
|
|
3403
|
-
});
|
|
3404
|
-
}
|
|
3405
|
-
return patches;
|
|
3406
|
-
}
|
|
3407
|
-
// Compare attributes
|
|
3408
|
-
const oldKeys = getKeys(oldNode);
|
|
3409
|
-
const newKeys = getKeys(newNode);
|
|
3410
|
-
// Check for attribute changes
|
|
3411
|
-
for (const key of newKeys) {
|
|
3412
|
-
if (oldNode[key] !== newNode[key]) {
|
|
3413
|
-
patches.push({
|
|
3414
|
-
type: SetAttribute,
|
|
3415
|
-
key,
|
|
3416
|
-
value: newNode[key]
|
|
3417
|
-
});
|
|
3418
|
-
}
|
|
3419
|
-
}
|
|
3420
|
-
// Check for removed attributes
|
|
3421
|
-
for (const key of oldKeys) {
|
|
3422
|
-
if (!(key in newNode)) {
|
|
3423
|
-
patches.push({
|
|
3424
|
-
type: RemoveAttribute,
|
|
3425
|
-
key
|
|
3426
|
-
});
|
|
3427
|
-
}
|
|
3428
|
-
}
|
|
3429
|
-
return patches;
|
|
3430
|
-
};
|
|
3431
|
-
|
|
3432
|
-
const treeToArray = node => {
|
|
3433
|
-
const result = [node.node];
|
|
3434
|
-
for (const child of node.children) {
|
|
3435
|
-
result.push(...treeToArray(child));
|
|
3436
|
-
}
|
|
3437
|
-
return result;
|
|
3438
|
-
};
|
|
3439
|
-
|
|
3440
|
-
const diffChildren = (oldChildren, newChildren, patches) => {
|
|
3441
|
-
const maxLength = Math.max(oldChildren.length, newChildren.length);
|
|
3442
|
-
// Track where we are: -1 means at parent, >= 0 means at child index
|
|
3443
|
-
let currentChildIndex = -1;
|
|
3444
|
-
// Collect indices of children to remove (we'll add these patches at the end in reverse order)
|
|
3445
|
-
const indicesToRemove = [];
|
|
3446
|
-
for (let i = 0; i < maxLength; i++) {
|
|
3447
|
-
const oldNode = oldChildren[i];
|
|
3448
|
-
const newNode = newChildren[i];
|
|
3449
|
-
if (!oldNode && !newNode) {
|
|
3450
|
-
continue;
|
|
3451
|
-
}
|
|
3452
|
-
if (!oldNode) {
|
|
3453
|
-
// Add new node - we should be at the parent
|
|
3454
|
-
if (currentChildIndex >= 0) {
|
|
3455
|
-
// Navigate back to parent
|
|
3456
|
-
patches.push({
|
|
3457
|
-
type: NavigateParent
|
|
3458
|
-
});
|
|
3459
|
-
currentChildIndex = -1;
|
|
3460
|
-
}
|
|
3461
|
-
// Flatten the entire subtree so renderInternal can handle it
|
|
3462
|
-
const flatNodes = treeToArray(newNode);
|
|
3463
|
-
patches.push({
|
|
3464
|
-
type: Add,
|
|
3465
|
-
nodes: flatNodes
|
|
3466
|
-
});
|
|
3467
|
-
} else if (newNode) {
|
|
3468
|
-
// Compare nodes to see if we need any patches
|
|
3469
|
-
const nodePatches = compareNodes(oldNode.node, newNode.node);
|
|
3470
|
-
// If nodePatches is null, the node types are incompatible - need to replace
|
|
3471
|
-
if (nodePatches === null) {
|
|
3472
|
-
// Navigate to this child
|
|
3473
|
-
if (currentChildIndex === -1) {
|
|
3474
|
-
patches.push({
|
|
3475
|
-
type: NavigateChild,
|
|
3476
|
-
index: i
|
|
3477
|
-
});
|
|
3478
|
-
currentChildIndex = i;
|
|
3479
|
-
} else if (currentChildIndex !== i) {
|
|
3480
|
-
patches.push({
|
|
3481
|
-
type: NavigateSibling,
|
|
3482
|
-
index: i
|
|
3483
|
-
});
|
|
3484
|
-
currentChildIndex = i;
|
|
3485
|
-
}
|
|
3486
|
-
// Replace the entire subtree
|
|
3487
|
-
const flatNodes = treeToArray(newNode);
|
|
3488
|
-
patches.push({
|
|
3489
|
-
type: Replace,
|
|
3490
|
-
nodes: flatNodes
|
|
3491
|
-
});
|
|
3492
|
-
// After replace, we're at the new element (same position)
|
|
3493
|
-
continue;
|
|
3494
|
-
}
|
|
3495
|
-
// Check if we need to recurse into children
|
|
3496
|
-
const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
|
|
3497
|
-
// Only navigate to this element if we need to do something
|
|
3498
|
-
if (nodePatches.length > 0 || hasChildrenToCompare) {
|
|
3499
|
-
// Navigate to this child if not already there
|
|
3500
|
-
if (currentChildIndex === -1) {
|
|
3501
|
-
patches.push({
|
|
3502
|
-
type: NavigateChild,
|
|
3503
|
-
index: i
|
|
3504
|
-
});
|
|
3505
|
-
currentChildIndex = i;
|
|
3506
|
-
} else if (currentChildIndex !== i) {
|
|
3507
|
-
patches.push({
|
|
3508
|
-
type: NavigateSibling,
|
|
3509
|
-
index: i
|
|
3510
|
-
});
|
|
3511
|
-
currentChildIndex = i;
|
|
3512
|
-
}
|
|
3513
|
-
// Apply node patches (these apply to the current element, not children)
|
|
3514
|
-
if (nodePatches.length > 0) {
|
|
3515
|
-
patches.push(...nodePatches);
|
|
3516
|
-
}
|
|
3517
|
-
// Compare children recursively
|
|
3518
|
-
if (hasChildrenToCompare) {
|
|
3519
|
-
diffChildren(oldNode.children, newNode.children, patches);
|
|
3520
|
-
}
|
|
3521
|
-
}
|
|
3522
|
-
} else {
|
|
3523
|
-
// Remove old node - collect the index for later removal
|
|
3524
|
-
indicesToRemove.push(i);
|
|
3525
|
-
}
|
|
3526
|
-
}
|
|
3527
|
-
// Navigate back to parent if we ended at a child
|
|
3528
|
-
if (currentChildIndex >= 0) {
|
|
3529
|
-
patches.push({
|
|
3530
|
-
type: NavigateParent
|
|
3531
|
-
});
|
|
3532
|
-
currentChildIndex = -1;
|
|
3533
|
-
}
|
|
3534
|
-
// Add remove patches in reverse order (highest index first)
|
|
3535
|
-
// This ensures indices remain valid as we remove
|
|
3536
|
-
for (let j = indicesToRemove.length - 1; j >= 0; j--) {
|
|
3537
|
-
patches.push({
|
|
3538
|
-
type: RemoveChild,
|
|
3539
|
-
index: indicesToRemove[j]
|
|
3540
|
-
});
|
|
840
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
841
|
+
const {
|
|
842
|
+
id,
|
|
843
|
+
promise
|
|
844
|
+
} = registerPromise(callbacks);
|
|
845
|
+
const message = create$6(id, method, params);
|
|
846
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
847
|
+
ipc.sendAndTransfer(message);
|
|
848
|
+
} else {
|
|
849
|
+
ipc.send(message);
|
|
3541
850
|
}
|
|
851
|
+
const responseMessage = await promise;
|
|
852
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
3542
853
|
};
|
|
3543
|
-
const
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
// Compare root nodes
|
|
3550
|
-
const nodePatches = compareNodes(oldNode.node, newNode.node);
|
|
3551
|
-
// If nodePatches is null, the root node types are incompatible - need to replace
|
|
3552
|
-
if (nodePatches === null) {
|
|
3553
|
-
const flatNodes = treeToArray(newNode);
|
|
3554
|
-
patches.push({
|
|
3555
|
-
type: Replace,
|
|
3556
|
-
nodes: flatNodes
|
|
3557
|
-
});
|
|
854
|
+
const createRpc = ipc => {
|
|
855
|
+
const callbacks = Object.create(null);
|
|
856
|
+
ipc._resolve = (id, response) => {
|
|
857
|
+
const fn = callbacks[id];
|
|
858
|
+
if (!fn) {
|
|
859
|
+
console.warn(`callback ${id} may already be disposed`);
|
|
3558
860
|
return;
|
|
3559
861
|
}
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
}
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
862
|
+
fn(response);
|
|
863
|
+
delete callbacks[id];
|
|
864
|
+
};
|
|
865
|
+
const rpc = {
|
|
866
|
+
async dispose() {
|
|
867
|
+
await ipc?.dispose();
|
|
868
|
+
},
|
|
869
|
+
invoke(method, ...params) {
|
|
870
|
+
return invokeHelper(callbacks, ipc, method, params, false);
|
|
871
|
+
},
|
|
872
|
+
invokeAndTransfer(method, ...params) {
|
|
873
|
+
return invokeHelper(callbacks, ipc, method, params, true);
|
|
874
|
+
},
|
|
875
|
+
// @ts-ignore
|
|
876
|
+
ipc,
|
|
877
|
+
/**
|
|
878
|
+
* @deprecated
|
|
879
|
+
*/
|
|
880
|
+
send(method, ...params) {
|
|
881
|
+
const message = create$7(method, params);
|
|
882
|
+
ipc.send(message);
|
|
3581
883
|
}
|
|
3582
|
-
}
|
|
3583
|
-
// Return patches up to and including the last non-navigation patch
|
|
3584
|
-
return lastNonNavigationIndex === -1 ? [] : patches.slice(0, lastNonNavigationIndex + 1);
|
|
3585
|
-
};
|
|
3586
|
-
|
|
3587
|
-
const diffTree = (oldNodes, newNodes) => {
|
|
3588
|
-
// Step 1: Convert flat arrays to tree structures
|
|
3589
|
-
const oldTree = arrayToTree(oldNodes);
|
|
3590
|
-
const newTree = arrayToTree(newNodes);
|
|
3591
|
-
// Step 3: Compare the trees
|
|
3592
|
-
const patches = [];
|
|
3593
|
-
diffTrees(oldTree, newTree, patches, []);
|
|
3594
|
-
// Remove trailing navigation patches since they serve no purpose
|
|
3595
|
-
return removeTrailingNavigationPatches(patches);
|
|
3596
|
-
};
|
|
3597
|
-
|
|
3598
|
-
const ComboBox = 'combobox';
|
|
3599
|
-
const ListBox = 'listbox';
|
|
3600
|
-
const None = 'none';
|
|
3601
|
-
const Option = 'option';
|
|
3602
|
-
|
|
3603
|
-
const ContainContent = 'ContainContent';
|
|
3604
|
-
const FileIcon = 'FileIcon';
|
|
3605
|
-
const InputBox = 'InputBox';
|
|
3606
|
-
const Label = 'Label';
|
|
3607
|
-
const List = 'List';
|
|
3608
|
-
const ListItems = 'ListItems';
|
|
3609
|
-
const MaskIcon = 'MaskIcon';
|
|
3610
|
-
const QuickPick$1 = 'QuickPick';
|
|
3611
|
-
const QuickPickHeader = 'QuickPickHeader';
|
|
3612
|
-
const QuickPickHighlight = 'QuickPickHighlight';
|
|
3613
|
-
const QuickPickItem = 'QuickPickItem';
|
|
3614
|
-
const QuickPickItemActive$1 = 'QuickPickItemActive';
|
|
3615
|
-
const QuickPickItemDescription = 'QuickPickItemDescription';
|
|
3616
|
-
const QuickPickItemLabel = 'QuickPickItemLabel';
|
|
3617
|
-
const QuickPickMaskIcon = 'QuickPickMaskIcon';
|
|
3618
|
-
const QuickPickStatus = 'QuickPickStatus';
|
|
3619
|
-
const ScrollBar = 'ScrollBar';
|
|
3620
|
-
const ScrollBarSmall = 'ScrollBarSmall';
|
|
3621
|
-
const ScrollBarThumb = 'ScrollBarThumb';
|
|
3622
|
-
const Viewlet = 'Viewlet';
|
|
3623
|
-
|
|
3624
|
-
const HandleWheel = 'handleWheel';
|
|
3625
|
-
const HandlePointerDown = 'handlePointerDown';
|
|
3626
|
-
const HandleBeforeInput = 'handleBeforeInput';
|
|
3627
|
-
const HandleBlur = 'handleBlur';
|
|
3628
|
-
const HandleFocus = 'handleFocus';
|
|
3629
|
-
const HandleInput = 'handleInput';
|
|
3630
|
-
|
|
3631
|
-
const QuickPick = 'QuickPick';
|
|
3632
|
-
const QuickPickItems = 'QuickPickItems';
|
|
3633
|
-
const QuickPickItemActive = 'QuickPickItemActive';
|
|
3634
|
-
|
|
3635
|
-
const getQuickPickInputVirtualDom = () => {
|
|
3636
|
-
const ariaLabel = typeNameofCommandToRun();
|
|
3637
|
-
return {
|
|
3638
|
-
ariaAutoComplete: 'list',
|
|
3639
|
-
ariaExpanded: true,
|
|
3640
|
-
ariaLabel: ariaLabel,
|
|
3641
|
-
autocapitalize: 'off',
|
|
3642
|
-
autocomplete: 'off',
|
|
3643
|
-
childCount: 0,
|
|
3644
|
-
className: InputBox,
|
|
3645
|
-
inputType: 'text',
|
|
3646
|
-
name: QuickPickInput,
|
|
3647
|
-
onBeforeInput: HandleBeforeInput,
|
|
3648
|
-
onBlur: HandleBlur,
|
|
3649
|
-
onFocus: HandleFocus,
|
|
3650
|
-
onInput: HandleInput,
|
|
3651
|
-
role: ComboBox,
|
|
3652
|
-
spellcheck: false,
|
|
3653
|
-
type: Input
|
|
3654
884
|
};
|
|
885
|
+
return rpc;
|
|
3655
886
|
};
|
|
3656
887
|
|
|
3657
|
-
const
|
|
3658
|
-
return
|
|
3659
|
-
childCount: 1,
|
|
3660
|
-
className: QuickPickHeader,
|
|
3661
|
-
type: Div
|
|
3662
|
-
}, getQuickPickInputVirtualDom()];
|
|
3663
|
-
};
|
|
3664
|
-
|
|
3665
|
-
const getFileIconVirtualDom = icon => {
|
|
3666
|
-
return {
|
|
3667
|
-
childCount: 0,
|
|
3668
|
-
className: FileIcon,
|
|
3669
|
-
role: None,
|
|
3670
|
-
src: icon,
|
|
3671
|
-
type: Img
|
|
3672
|
-
};
|
|
888
|
+
const requiresSocket = () => {
|
|
889
|
+
return false;
|
|
3673
890
|
};
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
childCount: 1,
|
|
3677
|
-
className: QuickPickHighlight,
|
|
3678
|
-
type: Span
|
|
3679
|
-
};
|
|
3680
|
-
const getHighlights = (sections, label) => {
|
|
3681
|
-
const labelDom = {
|
|
3682
|
-
childCount: 0,
|
|
3683
|
-
className: QuickPickItemLabel,
|
|
3684
|
-
type: Div
|
|
3685
|
-
};
|
|
3686
|
-
const nodes = [labelDom];
|
|
3687
|
-
if (sections.length === 0) {
|
|
3688
|
-
labelDom.childCount++;
|
|
3689
|
-
nodes.push(text(label));
|
|
3690
|
-
} else {
|
|
3691
|
-
for (const section of sections) {
|
|
3692
|
-
if (section.highlighted) {
|
|
3693
|
-
labelDom.childCount++;
|
|
3694
|
-
nodes.push(quickPickHighlight, text(section.text));
|
|
3695
|
-
} else {
|
|
3696
|
-
labelDom.childCount++;
|
|
3697
|
-
nodes.push(text(section.text));
|
|
3698
|
-
}
|
|
3699
|
-
}
|
|
3700
|
-
}
|
|
3701
|
-
return nodes;
|
|
891
|
+
const preparePrettyError = error => {
|
|
892
|
+
return error;
|
|
3702
893
|
};
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
const {
|
|
3706
|
-
description,
|
|
3707
|
-
fileIcon,
|
|
3708
|
-
highlights,
|
|
3709
|
-
icon,
|
|
3710
|
-
isActive,
|
|
3711
|
-
label,
|
|
3712
|
-
posInSet,
|
|
3713
|
-
setSize
|
|
3714
|
-
} = visibleItem;
|
|
3715
|
-
const dom = [{
|
|
3716
|
-
ariaPosInSet: posInSet,
|
|
3717
|
-
ariaSetSize: setSize,
|
|
3718
|
-
childCount: 1,
|
|
3719
|
-
className: QuickPickItem,
|
|
3720
|
-
role: Option,
|
|
3721
|
-
type: Div
|
|
3722
|
-
}];
|
|
3723
|
-
const parent = dom[0];
|
|
3724
|
-
if (isActive) {
|
|
3725
|
-
parent.id = QuickPickItemActive;
|
|
3726
|
-
parent.className += ' ' + QuickPickItemActive$1;
|
|
3727
|
-
}
|
|
3728
|
-
if (fileIcon) {
|
|
3729
|
-
parent.childCount++;
|
|
3730
|
-
dom.push(getFileIconVirtualDom(fileIcon));
|
|
3731
|
-
} else if (icon) {
|
|
3732
|
-
parent.childCount++;
|
|
3733
|
-
dom.push({
|
|
3734
|
-
childCount: 0,
|
|
3735
|
-
className: mergeClassNames(QuickPickMaskIcon, MaskIcon, `MaskIcon${icon}`),
|
|
3736
|
-
type: Div
|
|
3737
|
-
});
|
|
3738
|
-
}
|
|
3739
|
-
const highlightDom = getHighlights(highlights, label);
|
|
3740
|
-
dom.push(...highlightDom);
|
|
3741
|
-
if (description) {
|
|
3742
|
-
parent.childCount++;
|
|
3743
|
-
dom.push({
|
|
3744
|
-
childCount: 1,
|
|
3745
|
-
className: QuickPickItemDescription,
|
|
3746
|
-
type: Div
|
|
3747
|
-
}, text(description));
|
|
3748
|
-
}
|
|
3749
|
-
return dom;
|
|
894
|
+
const logError = () => {
|
|
895
|
+
// handled by renderer worker
|
|
3750
896
|
};
|
|
3751
|
-
|
|
3752
|
-
const
|
|
3753
|
-
const
|
|
3754
|
-
return
|
|
3755
|
-
childCount: 1,
|
|
3756
|
-
className: mergeClassNames(QuickPickItem, QuickPickItemActive$1, QuickPickStatus),
|
|
3757
|
-
type: Div
|
|
3758
|
-
}, {
|
|
3759
|
-
childCount: 1,
|
|
3760
|
-
className: Label,
|
|
3761
|
-
type: Div
|
|
3762
|
-
}, text(noResults$1)];
|
|
897
|
+
const handleMessage = event => {
|
|
898
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
899
|
+
const actualExecute = event?.target?.execute || execute;
|
|
900
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
3763
901
|
};
|
|
3764
902
|
|
|
3765
|
-
const
|
|
3766
|
-
if (
|
|
3767
|
-
|
|
903
|
+
const handleIpc = ipc => {
|
|
904
|
+
if ('addEventListener' in ipc) {
|
|
905
|
+
ipc.addEventListener('message', handleMessage);
|
|
906
|
+
} else if ('on' in ipc) {
|
|
907
|
+
// deprecated
|
|
908
|
+
ipc.on('message', handleMessage);
|
|
3768
909
|
}
|
|
3769
|
-
const dom = visibleItems.flatMap(getQuickPickItemVirtualDom);
|
|
3770
|
-
return dom;
|
|
3771
910
|
};
|
|
3772
911
|
|
|
3773
|
-
const
|
|
3774
|
-
const
|
|
3775
|
-
if (
|
|
3776
|
-
|
|
912
|
+
const listen$1 = async (module, options) => {
|
|
913
|
+
const rawIpc = await module.listen(options);
|
|
914
|
+
if (module.signal) {
|
|
915
|
+
module.signal(rawIpc);
|
|
3777
916
|
}
|
|
3778
|
-
const
|
|
3779
|
-
|
|
3780
|
-
return [{
|
|
3781
|
-
childCount: 1,
|
|
3782
|
-
className: mergeClassNames(ScrollBar, ScrollBarSmall),
|
|
3783
|
-
type: Div
|
|
3784
|
-
}, {
|
|
3785
|
-
childCount: 0,
|
|
3786
|
-
className: ScrollBarThumb,
|
|
3787
|
-
height: heightString,
|
|
3788
|
-
translate: translateString,
|
|
3789
|
-
type: Div
|
|
3790
|
-
}];
|
|
917
|
+
const ipc = module.wrap(rawIpc);
|
|
918
|
+
return ipc;
|
|
3791
919
|
};
|
|
3792
920
|
|
|
3793
|
-
const
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
role: ListBox,
|
|
3810
|
-
type: Div
|
|
3811
|
-
}, {
|
|
3812
|
-
childCount: visibleItems.length,
|
|
3813
|
-
className: mergeClassNames(ListItems, ContainContent),
|
|
3814
|
-
type: Div
|
|
3815
|
-
}, ...getQuickPickItemsVirtualDom(visibleItems), ...getScrollBarVirtualDom(scrollBarHeight, scrollBarTop)];
|
|
921
|
+
const create$4 = async ({
|
|
922
|
+
commandMap,
|
|
923
|
+
isMessagePortOpen = true,
|
|
924
|
+
messagePort
|
|
925
|
+
}) => {
|
|
926
|
+
// TODO create a commandMap per rpc instance
|
|
927
|
+
register$1(commandMap);
|
|
928
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
929
|
+
isMessagePortOpen,
|
|
930
|
+
messagePort
|
|
931
|
+
});
|
|
932
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
933
|
+
handleIpc(ipc);
|
|
934
|
+
const rpc = createRpc(ipc);
|
|
935
|
+
messagePort.start();
|
|
936
|
+
return rpc;
|
|
3816
937
|
};
|
|
3817
938
|
|
|
3818
|
-
const
|
|
939
|
+
const create$3 = async ({
|
|
940
|
+
commandMap,
|
|
941
|
+
isMessagePortOpen,
|
|
942
|
+
send
|
|
943
|
+
}) => {
|
|
3819
944
|
const {
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
945
|
+
port1,
|
|
946
|
+
port2
|
|
947
|
+
} = new MessageChannel();
|
|
948
|
+
await send(port1);
|
|
949
|
+
return create$4({
|
|
950
|
+
commandMap,
|
|
951
|
+
isMessagePortOpen,
|
|
952
|
+
messagePort: port2
|
|
953
|
+
});
|
|
3826
954
|
};
|
|
3827
955
|
|
|
3828
|
-
const
|
|
3829
|
-
|
|
3830
|
-
const
|
|
3831
|
-
|
|
3832
|
-
|
|
956
|
+
const createSharedLazyRpc = factory => {
|
|
957
|
+
let rpcPromise;
|
|
958
|
+
const getOrCreate = () => {
|
|
959
|
+
if (!rpcPromise) {
|
|
960
|
+
rpcPromise = factory();
|
|
961
|
+
}
|
|
962
|
+
return rpcPromise;
|
|
963
|
+
};
|
|
964
|
+
return {
|
|
965
|
+
async dispose() {
|
|
966
|
+
const rpc = await getOrCreate();
|
|
967
|
+
await rpc.dispose();
|
|
968
|
+
},
|
|
969
|
+
async invoke(method, ...params) {
|
|
970
|
+
const rpc = await getOrCreate();
|
|
971
|
+
return rpc.invoke(method, ...params);
|
|
972
|
+
},
|
|
973
|
+
async invokeAndTransfer(method, ...params) {
|
|
974
|
+
const rpc = await getOrCreate();
|
|
975
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
976
|
+
},
|
|
977
|
+
async send(method, ...params) {
|
|
978
|
+
const rpc = await getOrCreate();
|
|
979
|
+
rpc.send(method, ...params);
|
|
980
|
+
}
|
|
981
|
+
};
|
|
3833
982
|
};
|
|
3834
983
|
|
|
3835
|
-
const
|
|
3836
|
-
|
|
984
|
+
const create$2 = async ({
|
|
985
|
+
commandMap,
|
|
986
|
+
isMessagePortOpen,
|
|
987
|
+
send
|
|
988
|
+
}) => {
|
|
989
|
+
return createSharedLazyRpc(() => {
|
|
990
|
+
return create$3({
|
|
991
|
+
commandMap,
|
|
992
|
+
isMessagePortOpen,
|
|
993
|
+
send
|
|
994
|
+
});
|
|
995
|
+
});
|
|
3837
996
|
};
|
|
3838
997
|
|
|
3839
|
-
const
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
return renderFocusedIndex;
|
|
3849
|
-
case RenderIncremental:
|
|
3850
|
-
return renderIncremental;
|
|
3851
|
-
case RenderItems:
|
|
3852
|
-
return renderItems;
|
|
3853
|
-
case RenderValue:
|
|
3854
|
-
return renderValue;
|
|
3855
|
-
default:
|
|
3856
|
-
throw new Error('unknown renderer');
|
|
3857
|
-
}
|
|
998
|
+
const create$1 = async ({
|
|
999
|
+
commandMap
|
|
1000
|
+
}) => {
|
|
1001
|
+
// TODO create a commandMap per rpc instance
|
|
1002
|
+
register$1(commandMap);
|
|
1003
|
+
const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
|
|
1004
|
+
handleIpc(ipc);
|
|
1005
|
+
const rpc = createRpc(ipc);
|
|
1006
|
+
return rpc;
|
|
3858
1007
|
};
|
|
3859
1008
|
|
|
3860
|
-
const
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
if (
|
|
3868
|
-
|
|
1009
|
+
const createMockRpc = ({
|
|
1010
|
+
commandMap
|
|
1011
|
+
}) => {
|
|
1012
|
+
const invocations = [];
|
|
1013
|
+
const invoke = (method, ...params) => {
|
|
1014
|
+
invocations.push([method, ...params]);
|
|
1015
|
+
const command = commandMap[method];
|
|
1016
|
+
if (!command) {
|
|
1017
|
+
throw new Error(`command ${method} not found`);
|
|
3869
1018
|
}
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
1019
|
+
return command(...params);
|
|
1020
|
+
};
|
|
1021
|
+
const mockRpc = {
|
|
1022
|
+
invocations,
|
|
1023
|
+
invoke,
|
|
1024
|
+
invokeAndTransfer: invoke
|
|
1025
|
+
};
|
|
1026
|
+
return mockRpc;
|
|
3874
1027
|
};
|
|
3875
1028
|
|
|
3876
|
-
const
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
oldState
|
|
3880
|
-
} = get$1(uid);
|
|
3881
|
-
if (oldState === newState) {
|
|
3882
|
-
return [];
|
|
3883
|
-
}
|
|
3884
|
-
set(uid, newState, newState);
|
|
3885
|
-
const commands = applyRender(oldState, newState, diffResult);
|
|
3886
|
-
return commands;
|
|
1029
|
+
const rpcs = Object.create(null);
|
|
1030
|
+
const set$2 = (id, rpc) => {
|
|
1031
|
+
rpcs[id] = rpc;
|
|
3887
1032
|
};
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
return [{
|
|
3891
|
-
name: HandlePointerDown,
|
|
3892
|
-
params: ['handleClickAt', 'event.clientX', 'event.clientY'],
|
|
3893
|
-
preventDefault: true
|
|
3894
|
-
}, {
|
|
3895
|
-
name: HandleWheel,
|
|
3896
|
-
params: ['handleWheel', 'event.deltaMode', 'event.deltaY'],
|
|
3897
|
-
passive: true
|
|
3898
|
-
}, {
|
|
3899
|
-
name: HandleBlur,
|
|
3900
|
-
params: ['handleBlur']
|
|
3901
|
-
}, {
|
|
3902
|
-
name: HandleBeforeInput,
|
|
3903
|
-
params: ['handleBeforeInput']
|
|
3904
|
-
}, {
|
|
3905
|
-
name: HandleInput,
|
|
3906
|
-
params: ['handleInput', 'event.target.value']
|
|
3907
|
-
}, {
|
|
3908
|
-
name: HandleFocus,
|
|
3909
|
-
params: ['handleFocus']
|
|
3910
|
-
}];
|
|
1033
|
+
const get = id => {
|
|
1034
|
+
return rpcs[id];
|
|
3911
1035
|
};
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
const {
|
|
3915
|
-
focusedIndex
|
|
3916
|
-
} = state;
|
|
3917
|
-
return selectIndex(state, focusedIndex);
|
|
1036
|
+
const remove = id => {
|
|
1037
|
+
delete rpcs[id];
|
|
3918
1038
|
};
|
|
3919
1039
|
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
1040
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1041
|
+
const create = rpcId => {
|
|
1042
|
+
return {
|
|
1043
|
+
async dispose() {
|
|
1044
|
+
const rpc = get(rpcId);
|
|
1045
|
+
await rpc.dispose();
|
|
1046
|
+
},
|
|
1047
|
+
// @ts-ignore
|
|
1048
|
+
invoke(method, ...params) {
|
|
1049
|
+
const rpc = get(rpcId);
|
|
1050
|
+
// @ts-ignore
|
|
1051
|
+
return rpc.invoke(method, ...params);
|
|
1052
|
+
},
|
|
1053
|
+
// @ts-ignore
|
|
1054
|
+
invokeAndTransfer(method, ...params) {
|
|
1055
|
+
const rpc = get(rpcId);
|
|
1056
|
+
// @ts-ignore
|
|
1057
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1058
|
+
},
|
|
1059
|
+
registerMockRpc(commandMap) {
|
|
1060
|
+
const mockRpc = createMockRpc({
|
|
1061
|
+
commandMap
|
|
1062
|
+
});
|
|
1063
|
+
set$2(rpcId, mockRpc);
|
|
1064
|
+
// @ts-ignore
|
|
1065
|
+
mockRpc[Symbol.dispose] = () => {
|
|
1066
|
+
remove(rpcId);
|
|
1067
|
+
};
|
|
1068
|
+
// @ts-ignore
|
|
1069
|
+
return mockRpc;
|
|
1070
|
+
},
|
|
1071
|
+
set(rpc) {
|
|
1072
|
+
set$2(rpcId, rpc);
|
|
3924
1073
|
}
|
|
3925
|
-
}
|
|
3926
|
-
return -1;
|
|
1074
|
+
};
|
|
3927
1075
|
};
|
|
3928
1076
|
|
|
3929
|
-
const
|
|
3930
|
-
|
|
3931
|
-
const index = findLabelIndex(state.items, label);
|
|
3932
|
-
if (index === -1) {
|
|
3933
|
-
return state;
|
|
3934
|
-
}
|
|
3935
|
-
return selectIndex(state, index);
|
|
3936
|
-
};
|
|
1077
|
+
const EditorWorker = 99;
|
|
1078
|
+
const RendererWorker = 1;
|
|
3937
1079
|
|
|
3938
|
-
const
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
waitUntil
|
|
3942
|
-
}) => {
|
|
3943
|
-
// TODO ask renderer worker to create quickpick instance, with given options
|
|
3944
|
-
const picks = [];
|
|
3945
|
-
// const id=QuickPickCallbacks.registerCallback()
|
|
3946
|
-
await invoke$1('QuickPick.showCustom', picks, {
|
|
3947
|
-
ignoreFocusOut,
|
|
3948
|
-
initialValue,
|
|
3949
|
-
waitUntil
|
|
3950
|
-
});
|
|
3951
|
-
return {
|
|
3952
|
-
canceled: false,
|
|
3953
|
-
inputValue: ''
|
|
3954
|
-
};
|
|
3955
|
-
};
|
|
1080
|
+
const {
|
|
1081
|
+
set: set$1
|
|
1082
|
+
} = create(EditorWorker);
|
|
3956
1083
|
|
|
3957
|
-
const
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
'
|
|
3964
|
-
'
|
|
3965
|
-
'QuickPick.focusIndex': wrapCommand(focusIndex),
|
|
3966
|
-
'QuickPick.focusLast': wrapCommand(focusLast),
|
|
3967
|
-
'QuickPick.focusNext': wrapCommand(focusNext),
|
|
3968
|
-
'QuickPick.focusPrevious': wrapCommand(focusPrevious),
|
|
3969
|
-
'QuickPick.getCommandIds': getCommandIds,
|
|
3970
|
-
'QuickPick.getKeyBindings': getKeyBindings,
|
|
3971
|
-
'QuickPick.handleBeforeInput': wrapCommand(handleBeforeInput),
|
|
3972
|
-
'QuickPick.handleBlur': wrapCommand(handleBlur),
|
|
3973
|
-
'QuickPick.handleClickAt': wrapCommand(handleClickAt),
|
|
3974
|
-
'QuickPick.handleFocus': wrapCommand(handleFocus),
|
|
3975
|
-
'QuickPick.handleInput': wrapCommand(handleInput),
|
|
3976
|
-
'QuickPick.handleMessagePort': handleMessagePort,
|
|
3977
|
-
'QuickPick.handleWheel': wrapCommand(handleWheel),
|
|
3978
|
-
'QuickPick.initialize': initialize,
|
|
3979
|
-
'QuickPick.loadContent': wrapCommand(loadContent),
|
|
3980
|
-
'QuickPick.render2': render2,
|
|
3981
|
-
'QuickPick.renderEventListeners': renderEventListeners,
|
|
3982
|
-
'QuickPick.selectCurrentIndex': wrapCommand(selectCurrentIndex),
|
|
3983
|
-
'QuickPick.selectIndex': wrapCommand(selectIndex),
|
|
3984
|
-
'QuickPick.selectItem': wrapCommand(selectItem),
|
|
3985
|
-
'QuickPick.setDeltaY': wrapCommand(setDeltaY),
|
|
3986
|
-
'QuickPick.setValue': wrapCommand(setValue),
|
|
3987
|
-
'QuickPick.showQuickInput': showQuickInput
|
|
1084
|
+
const {
|
|
1085
|
+
invoke: invoke$1,
|
|
1086
|
+
invokeAndTransfer,
|
|
1087
|
+
set
|
|
1088
|
+
} = create(RendererWorker);
|
|
1089
|
+
const sendMessagePortToEditorWorker = async (port, rpcId) => {
|
|
1090
|
+
const command = 'HandleMessagePort.handleMessagePort';
|
|
1091
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
|
|
3988
1092
|
};
|
|
3989
1093
|
|
|
3990
1094
|
const initializeEditorWorker = async () => {
|
|
3991
|
-
const rpc = await create$
|
|
1095
|
+
const rpc = await create$2({
|
|
3992
1096
|
commandMap: {},
|
|
3993
1097
|
async send(port) {
|
|
3994
1098
|
await sendMessagePortToEditorWorker(port, 0);
|
|
3995
1099
|
}
|
|
3996
1100
|
});
|
|
3997
|
-
set$
|
|
1101
|
+
set$1(rpc);
|
|
1102
|
+
};
|
|
1103
|
+
|
|
1104
|
+
const RE_PROTOCOL = /^([a-z-]+):\/\//;
|
|
1105
|
+
const getProtocol = uri => {
|
|
1106
|
+
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
1107
|
+
if (protocolMatch) {
|
|
1108
|
+
return protocolMatch[1];
|
|
1109
|
+
}
|
|
1110
|
+
return '';
|
|
1111
|
+
};
|
|
1112
|
+
|
|
1113
|
+
const state = Object.create(null);
|
|
1114
|
+
const register = modules => {
|
|
1115
|
+
Object.assign(state, modules);
|
|
1116
|
+
};
|
|
1117
|
+
const getFn = protocol => {
|
|
1118
|
+
return state[protocol];
|
|
1119
|
+
};
|
|
1120
|
+
|
|
1121
|
+
const searchFile$4 = async (path, value, prepare, assetDir) => {
|
|
1122
|
+
const protocol = getProtocol(path);
|
|
1123
|
+
// TODO call different providers depending on protocol
|
|
1124
|
+
const fn = getFn(protocol);
|
|
1125
|
+
if (!fn) {
|
|
1126
|
+
throw new Error(`No search handler registered for protocol: ${protocol}`);
|
|
1127
|
+
}
|
|
1128
|
+
const result = await fn(path, value, prepare, assetDir);
|
|
1129
|
+
return result;
|
|
1130
|
+
};
|
|
1131
|
+
|
|
1132
|
+
const commandMap = {
|
|
1133
|
+
'FileSearch.searchFile': searchFile$4,
|
|
1134
|
+
'SearchFile.searchFile': searchFile$4
|
|
3998
1135
|
};
|
|
3999
1136
|
|
|
4000
1137
|
const initializeRendererWorker = async () => {
|
|
4001
|
-
const rpc = await create({
|
|
1138
|
+
const rpc = await create$1({
|
|
4002
1139
|
commandMap: commandMap
|
|
4003
1140
|
});
|
|
4004
|
-
set
|
|
1141
|
+
set(rpc);
|
|
4005
1142
|
};
|
|
4006
1143
|
|
|
4007
1144
|
const Memfs = 'memfs';
|
|
@@ -4034,6 +1171,13 @@ const invoke = (method, ...params) => {
|
|
|
4034
1171
|
return invoke$1('SearchProcess.invoke', method, ...params);
|
|
4035
1172
|
};
|
|
4036
1173
|
|
|
1174
|
+
const splitLines = lines => {
|
|
1175
|
+
if (!lines) {
|
|
1176
|
+
return [];
|
|
1177
|
+
}
|
|
1178
|
+
return lines.split('\n');
|
|
1179
|
+
};
|
|
1180
|
+
|
|
4037
1181
|
// TODO create direct connection from electron to file search worker using message ports
|
|
4038
1182
|
|
|
4039
1183
|
const searchFile = async (path, value, prepare) => {
|
|
@@ -4044,7 +1188,7 @@ const searchFile = async (path, value, prepare) => {
|
|
|
4044
1188
|
searchPath: path
|
|
4045
1189
|
};
|
|
4046
1190
|
const stdout = await invoke('SearchFile.searchFile', options);
|
|
4047
|
-
const lines = splitLines
|
|
1191
|
+
const lines = splitLines(stdout);
|
|
4048
1192
|
return lines;
|
|
4049
1193
|
};
|
|
4050
1194
|
|
|
@@ -4057,8 +1201,6 @@ const searchModules = {
|
|
|
4057
1201
|
};
|
|
4058
1202
|
|
|
4059
1203
|
const listen = async () => {
|
|
4060
|
-
Object.assign(commandMapRef, commandMap);
|
|
4061
|
-
registerCommands(commandMap);
|
|
4062
1204
|
register(searchModules);
|
|
4063
1205
|
await Promise.all([initializeRendererWorker(), initializeEditorWorker()]);
|
|
4064
1206
|
};
|