@lvce-editor/completion-worker 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/completionWorkerMain.js +433 -119
- package/package.json +1 -1
|
@@ -82,12 +82,24 @@ const getType = value => {
|
|
|
82
82
|
return 'unknown';
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
+
const object = value => {
|
|
86
|
+
const type = getType(value);
|
|
87
|
+
if (type !== 'object') {
|
|
88
|
+
throw new AssertionError('expected value to be of type object');
|
|
89
|
+
}
|
|
90
|
+
};
|
|
85
91
|
const number = value => {
|
|
86
92
|
const type = getType(value);
|
|
87
93
|
if (type !== 'number') {
|
|
88
94
|
throw new AssertionError('expected value to be of type number');
|
|
89
95
|
}
|
|
90
96
|
};
|
|
97
|
+
const string = value => {
|
|
98
|
+
const type = getType(value);
|
|
99
|
+
if (type !== 'string') {
|
|
100
|
+
throw new AssertionError('expected value to be of type string');
|
|
101
|
+
}
|
|
102
|
+
};
|
|
91
103
|
|
|
92
104
|
const isMessagePort = value => {
|
|
93
105
|
return value && value instanceof MessagePort;
|
|
@@ -848,11 +860,11 @@ const commands = Object.create(null);
|
|
|
848
860
|
const register = commandMap => {
|
|
849
861
|
Object.assign(commands, commandMap);
|
|
850
862
|
};
|
|
851
|
-
const getCommand = key => {
|
|
863
|
+
const getCommand$1 = key => {
|
|
852
864
|
return commands[key];
|
|
853
865
|
};
|
|
854
866
|
const execute$1 = (command, ...args) => {
|
|
855
|
-
const fn = getCommand(command);
|
|
867
|
+
const fn = getCommand$1(command);
|
|
856
868
|
if (!fn) {
|
|
857
869
|
throw new Error(`command not found ${command}`);
|
|
858
870
|
}
|
|
@@ -1046,16 +1058,20 @@ const create$1 = (uid, x, y, width, height, editorUid, editorLanguageId) => {
|
|
|
1046
1058
|
set$2(uid, state, state);
|
|
1047
1059
|
};
|
|
1048
1060
|
|
|
1049
|
-
const isEqual$
|
|
1061
|
+
const isEqual$4 = (oldState, newState) => {
|
|
1050
1062
|
return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
|
|
1051
1063
|
};
|
|
1052
1064
|
|
|
1065
|
+
const isEqual$3 = (oldState, newState) => {
|
|
1066
|
+
return oldState.version === newState.version;
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1053
1069
|
const isEqual$2 = (oldState, newState) => {
|
|
1054
1070
|
return oldState.version === newState.version;
|
|
1055
1071
|
};
|
|
1056
1072
|
|
|
1057
1073
|
const isEqual$1 = (oldState, newState) => {
|
|
1058
|
-
return oldState.items === newState.items;
|
|
1074
|
+
return oldState.items === newState.items && oldState.focusedIndex === newState.focusedIndex;
|
|
1059
1075
|
};
|
|
1060
1076
|
|
|
1061
1077
|
const isEqual = (oldState, newState) => {
|
|
@@ -1067,9 +1083,10 @@ const RenderBounds = 8;
|
|
|
1067
1083
|
const RenderEventListeners = 11;
|
|
1068
1084
|
const RenderUid = 12;
|
|
1069
1085
|
const RenderContent = 13;
|
|
1086
|
+
const RenderFocusContext = 14;
|
|
1070
1087
|
|
|
1071
|
-
const modules = [isEqual$
|
|
1072
|
-
const numbers = [RenderEventListeners, RenderItems, RenderBounds, RenderUid];
|
|
1088
|
+
const modules = [isEqual$3, isEqual$1, isEqual$4, isEqual, isEqual$2];
|
|
1089
|
+
const numbers = [RenderEventListeners, RenderItems, RenderBounds, RenderUid, RenderFocusContext];
|
|
1073
1090
|
|
|
1074
1091
|
const diff = (oldState, newState) => {
|
|
1075
1092
|
const diffResult = [];
|
|
@@ -1091,12 +1108,327 @@ const diff2 = uid => {
|
|
|
1091
1108
|
return diffResult;
|
|
1092
1109
|
};
|
|
1093
1110
|
|
|
1111
|
+
const focusIndex = (state, index) => {
|
|
1112
|
+
const newState = {
|
|
1113
|
+
...state,
|
|
1114
|
+
focusedIndex: index,
|
|
1115
|
+
focused: true
|
|
1116
|
+
};
|
|
1117
|
+
return newState;
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1120
|
+
const focusFirst = state => {
|
|
1121
|
+
const firstIndex = 0;
|
|
1122
|
+
return focusIndex(state, firstIndex);
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1125
|
+
const focusNext = state => {
|
|
1126
|
+
const {
|
|
1127
|
+
focusedIndex
|
|
1128
|
+
} = state;
|
|
1129
|
+
const nextIndex = focusedIndex + 1;
|
|
1130
|
+
return focusIndex(state, nextIndex);
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
const focusPrevious = state => {
|
|
1134
|
+
const previousIndex = state.focusedIndex - 1;
|
|
1135
|
+
return focusIndex(state, previousIndex);
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
const openDetails = async state => {
|
|
1139
|
+
// TODO ask editor worker to add completion details widget
|
|
1140
|
+
return state;
|
|
1141
|
+
};
|
|
1142
|
+
|
|
1143
|
+
const rpcs = Object.create(null);
|
|
1144
|
+
const set$a = (id, rpc) => {
|
|
1145
|
+
rpcs[id] = rpc;
|
|
1146
|
+
};
|
|
1147
|
+
const get = id => {
|
|
1148
|
+
return rpcs[id];
|
|
1149
|
+
};
|
|
1150
|
+
|
|
1151
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1152
|
+
|
|
1153
|
+
const create = rpcId => {
|
|
1154
|
+
return {
|
|
1155
|
+
// @ts-ignore
|
|
1156
|
+
invoke(method, ...params) {
|
|
1157
|
+
const rpc = get(rpcId);
|
|
1158
|
+
// @ts-ignore
|
|
1159
|
+
return rpc.invoke(method, ...params);
|
|
1160
|
+
},
|
|
1161
|
+
// @ts-ignore
|
|
1162
|
+
invokeAndTransfer(method, ...params) {
|
|
1163
|
+
const rpc = get(rpcId);
|
|
1164
|
+
// @ts-ignore
|
|
1165
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1166
|
+
},
|
|
1167
|
+
set(rpc) {
|
|
1168
|
+
set$a(rpcId, rpc);
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
};
|
|
1172
|
+
const EditorWorker$1 = 99;
|
|
1173
|
+
const ExtensionHostWorker = 44;
|
|
1174
|
+
const {
|
|
1175
|
+
invoke: invoke$9,
|
|
1176
|
+
invokeAndTransfer: invokeAndTransfer$9,
|
|
1177
|
+
set: set$9
|
|
1178
|
+
} = create(EditorWorker$1);
|
|
1179
|
+
const EditorWorker = {
|
|
1180
|
+
__proto__: null,
|
|
1181
|
+
invoke: invoke$9,
|
|
1182
|
+
invokeAndTransfer: invokeAndTransfer$9,
|
|
1183
|
+
set: set$9
|
|
1184
|
+
};
|
|
1185
|
+
const {
|
|
1186
|
+
invoke: invoke$7,
|
|
1187
|
+
set: set$7
|
|
1188
|
+
} = create(ExtensionHostWorker);
|
|
1189
|
+
const ExtensionHost = {
|
|
1190
|
+
__proto__: null,
|
|
1191
|
+
invoke: invoke$7,
|
|
1192
|
+
set: set$7
|
|
1193
|
+
};
|
|
1194
|
+
|
|
1195
|
+
const {
|
|
1196
|
+
invoke: invoke$1,
|
|
1197
|
+
set: set$1,
|
|
1198
|
+
invokeAndTransfer
|
|
1199
|
+
} = EditorWorker;
|
|
1200
|
+
|
|
1201
|
+
const OnCompletion = 'onCompletion';
|
|
1202
|
+
|
|
1203
|
+
const CompletionExecute = 'ExtensionHostCompletion.execute';
|
|
1204
|
+
const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
|
|
1205
|
+
|
|
1206
|
+
// TODO add tests for this
|
|
1207
|
+
const activateByEvent = async event => {
|
|
1208
|
+
// @ts-ignore
|
|
1209
|
+
await invoke$1('ActivateByEvent.activateByEvent', event);
|
|
1210
|
+
};
|
|
1211
|
+
|
|
1212
|
+
const {
|
|
1213
|
+
invoke,
|
|
1214
|
+
set
|
|
1215
|
+
} = ExtensionHost;
|
|
1216
|
+
|
|
1217
|
+
const execute = async ({
|
|
1218
|
+
editorLanguageId,
|
|
1219
|
+
editorUid,
|
|
1220
|
+
args,
|
|
1221
|
+
event,
|
|
1222
|
+
method,
|
|
1223
|
+
noProviderFoundMessage,
|
|
1224
|
+
noProviderFoundResult = undefined
|
|
1225
|
+
}) => {
|
|
1226
|
+
const fullEvent = `${event}:${editorLanguageId}`;
|
|
1227
|
+
await activateByEvent(fullEvent);
|
|
1228
|
+
const result = await invoke(method, editorUid, ...args);
|
|
1229
|
+
return result;
|
|
1230
|
+
};
|
|
1231
|
+
|
|
1232
|
+
const executeCompletionProvider = async (editorUid, editorLanguageId, offset) => {
|
|
1233
|
+
return execute({
|
|
1234
|
+
editorUid,
|
|
1235
|
+
editorLanguageId,
|
|
1236
|
+
event: OnCompletion,
|
|
1237
|
+
method: CompletionExecute,
|
|
1238
|
+
args: [offset],
|
|
1239
|
+
noProviderFoundMessage: 'no completion provider found',
|
|
1240
|
+
noProviderFoundResult: []});
|
|
1241
|
+
};
|
|
1242
|
+
const executeResolveCompletionItem = async (editor, offset, name, completionItem) => {
|
|
1243
|
+
return execute({
|
|
1244
|
+
event: OnCompletion,
|
|
1245
|
+
method: CompletionResolveExecute,
|
|
1246
|
+
args: [offset, name, completionItem],
|
|
1247
|
+
noProviderFoundMessage: 'no completion provider found',
|
|
1248
|
+
noProviderFoundResult: []});
|
|
1249
|
+
};
|
|
1250
|
+
|
|
1251
|
+
const getOffsetAtCursor = editorUid => {
|
|
1252
|
+
// TODO ask editor worker
|
|
1253
|
+
return 0;
|
|
1254
|
+
};
|
|
1255
|
+
|
|
1256
|
+
// TODO possible to do this with events/state machine instead of promises -> enables canceling operations / concurrent calls
|
|
1257
|
+
const getCompletions = async (editorUid, editorLanguageId) => {
|
|
1258
|
+
const offset = getOffsetAtCursor();
|
|
1259
|
+
const completions = await executeCompletionProvider(editorUid, editorLanguageId, offset);
|
|
1260
|
+
return completions;
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
// TODO don't send unnecessary parts of completion item like matches
|
|
1264
|
+
const resolveCompletion = async (editorUid, name, completionItem) => {
|
|
1265
|
+
try {
|
|
1266
|
+
string(name);
|
|
1267
|
+
object(completionItem);
|
|
1268
|
+
const offset = getOffsetAtCursor(editorUid);
|
|
1269
|
+
// @ts-ignore
|
|
1270
|
+
const resolvedCompletionItem = await executeResolveCompletionItem(editor, offset, name, completionItem);
|
|
1271
|
+
return resolvedCompletionItem;
|
|
1272
|
+
} catch {
|
|
1273
|
+
return undefined;
|
|
1274
|
+
}
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
const getSelectionPairs = (selections, i) => {
|
|
1278
|
+
const first = selections[i];
|
|
1279
|
+
const second = selections[i + 1];
|
|
1280
|
+
const third = selections[i + 2];
|
|
1281
|
+
const fourth = selections[i + 3];
|
|
1282
|
+
if (first > third || first === third && second >= fourth) {
|
|
1283
|
+
return [third, fourth, first, second, 1];
|
|
1284
|
+
}
|
|
1285
|
+
return [first, second, third, fourth, 0];
|
|
1286
|
+
};
|
|
1287
|
+
|
|
1288
|
+
const getSelectionText = (lines, range) => {
|
|
1289
|
+
const startRowIndex = range.start.rowIndex;
|
|
1290
|
+
const startColumnIndex = range.start.columnIndex;
|
|
1291
|
+
const endRowIndex = Math.min(range.end.rowIndex, lines.length - 1);
|
|
1292
|
+
const endColumnIndex = range.end.columnIndex;
|
|
1293
|
+
if (startRowIndex === endRowIndex) {
|
|
1294
|
+
return [lines[startRowIndex].slice(startColumnIndex, endColumnIndex)];
|
|
1295
|
+
}
|
|
1296
|
+
const selectedLines = [lines[startRowIndex].slice(startColumnIndex), ...lines.slice(startRowIndex + 1, endRowIndex), lines[endRowIndex].slice(0, endColumnIndex)];
|
|
1297
|
+
return selectedLines;
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
// TODO add more exact types
|
|
1301
|
+
const replaceRange = (lines, ranges, replacement, origin) => {
|
|
1302
|
+
const changes = [];
|
|
1303
|
+
const rangesLength = ranges.length;
|
|
1304
|
+
for (let i = 0; i < rangesLength; i += 4) {
|
|
1305
|
+
const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(ranges, i);
|
|
1306
|
+
const start = {
|
|
1307
|
+
rowIndex: selectionStartRow,
|
|
1308
|
+
columnIndex: selectionStartColumn
|
|
1309
|
+
};
|
|
1310
|
+
const end = {
|
|
1311
|
+
rowIndex: selectionEndRow,
|
|
1312
|
+
columnIndex: selectionEndColumn
|
|
1313
|
+
};
|
|
1314
|
+
const selection = {
|
|
1315
|
+
start,
|
|
1316
|
+
end
|
|
1317
|
+
};
|
|
1318
|
+
changes.push({
|
|
1319
|
+
start: start,
|
|
1320
|
+
end: end,
|
|
1321
|
+
inserted: replacement,
|
|
1322
|
+
deleted: getSelectionText(lines, selection),
|
|
1323
|
+
origin
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
return changes;
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
const getEdits = async (editorUid, leadingWord, completionItem) => {
|
|
1330
|
+
const word = completionItem.label;
|
|
1331
|
+
const resolvedItem = await resolveCompletion(editorUid, word, completionItem);
|
|
1332
|
+
const inserted = resolvedItem ? resolvedItem.snippet : word;
|
|
1333
|
+
const lines = await invoke$1('Editor.getLines2', editorUid);
|
|
1334
|
+
const selections = await invoke$1('Editor.getSelections2', editorUid);
|
|
1335
|
+
const [startRowIndex, startColumnIndex] = selections;
|
|
1336
|
+
const leadingWordLength = leadingWord.length;
|
|
1337
|
+
const replaceRange$1 = new Uint32Array([startRowIndex, startColumnIndex - leadingWordLength, startRowIndex, startColumnIndex]);
|
|
1338
|
+
const changes = replaceRange(lines, replaceRange$1, [inserted], '');
|
|
1339
|
+
return changes;
|
|
1340
|
+
};
|
|
1341
|
+
|
|
1342
|
+
const select = async (state, completionItem) => {
|
|
1343
|
+
const {
|
|
1344
|
+
editorUid,
|
|
1345
|
+
leadingWord
|
|
1346
|
+
} = state;
|
|
1347
|
+
const changes = await getEdits(editorUid, leadingWord, completionItem);
|
|
1348
|
+
// @ts-ignore
|
|
1349
|
+
await invoke$1('Editor.applyEdit2', editorUid, changes);
|
|
1350
|
+
// TODO remove completion widget from editor
|
|
1351
|
+
return {
|
|
1352
|
+
...state
|
|
1353
|
+
};
|
|
1354
|
+
};
|
|
1355
|
+
|
|
1356
|
+
const selectIndex = async (state, index) => {
|
|
1357
|
+
const {
|
|
1358
|
+
items
|
|
1359
|
+
} = state;
|
|
1360
|
+
if (index === -1) {
|
|
1361
|
+
return state;
|
|
1362
|
+
}
|
|
1363
|
+
if (index > items.length) {
|
|
1364
|
+
throw new Error('index too large');
|
|
1365
|
+
}
|
|
1366
|
+
const actualIndex = index;
|
|
1367
|
+
const completionItem = items[actualIndex];
|
|
1368
|
+
return select(state, completionItem);
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
const selectCurrent = state => {
|
|
1372
|
+
const {
|
|
1373
|
+
focusedIndex
|
|
1374
|
+
} = state;
|
|
1375
|
+
return selectIndex(state, focusedIndex);
|
|
1376
|
+
};
|
|
1377
|
+
|
|
1094
1378
|
const commandIds = ['handleSliderPointerDown', 'handleSliderPointerMove', 'initialize'];
|
|
1095
1379
|
|
|
1096
1380
|
const getCommandIds = () => {
|
|
1097
1381
|
return commandIds;
|
|
1098
1382
|
};
|
|
1099
1383
|
|
|
1384
|
+
const Enter = 3;
|
|
1385
|
+
const Space$1 = 9;
|
|
1386
|
+
const End = 255;
|
|
1387
|
+
const Home = 12;
|
|
1388
|
+
const UpArrow = 14;
|
|
1389
|
+
const DownArrow = 16;
|
|
1390
|
+
|
|
1391
|
+
const CtrlCmd = 1 << 11 >>> 0;
|
|
1392
|
+
|
|
1393
|
+
const FocusEditorCompletions = 9;
|
|
1394
|
+
const FocusEditorRename = 11;
|
|
1395
|
+
|
|
1396
|
+
const Completion = 3;
|
|
1397
|
+
|
|
1398
|
+
const getCommand = shortId => {
|
|
1399
|
+
return {
|
|
1400
|
+
command: 'Editor.executeWidgetCommand',
|
|
1401
|
+
args: ['Completions', `Completions.${shortId}`, 0, Completion]
|
|
1402
|
+
};
|
|
1403
|
+
};
|
|
1404
|
+
const getKeyBindings = () => {
|
|
1405
|
+
return [{
|
|
1406
|
+
key: DownArrow,
|
|
1407
|
+
...getCommand('focusNext'),
|
|
1408
|
+
when: FocusEditorCompletions
|
|
1409
|
+
}, {
|
|
1410
|
+
key: UpArrow,
|
|
1411
|
+
...getCommand('focusPrevious'),
|
|
1412
|
+
when: FocusEditorCompletions
|
|
1413
|
+
}, {
|
|
1414
|
+
key: Enter,
|
|
1415
|
+
...getCommand('selectCurrent'),
|
|
1416
|
+
when: FocusEditorCompletions
|
|
1417
|
+
}, {
|
|
1418
|
+
key: End,
|
|
1419
|
+
...getCommand('focusLast'),
|
|
1420
|
+
when: FocusEditorCompletions
|
|
1421
|
+
}, {
|
|
1422
|
+
key: Home,
|
|
1423
|
+
...getCommand('focusFirst'),
|
|
1424
|
+
when: FocusEditorCompletions
|
|
1425
|
+
}, {
|
|
1426
|
+
key: CtrlCmd | Space$1,
|
|
1427
|
+
...getCommand('toggleDetails'),
|
|
1428
|
+
when: FocusEditorCompletions
|
|
1429
|
+
}];
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1100
1432
|
const Diagonal = 1;
|
|
1101
1433
|
const Left = 2;
|
|
1102
1434
|
|
|
@@ -1304,63 +1636,40 @@ const getListHeight = (itemsLength, itemHeight, maxHeight) => {
|
|
|
1304
1636
|
return Math.min(totalHeight, maxHeight);
|
|
1305
1637
|
};
|
|
1306
1638
|
|
|
1307
|
-
const
|
|
1308
|
-
|
|
1309
|
-
rpcs[id] = rpc;
|
|
1310
|
-
};
|
|
1311
|
-
const get = id => {
|
|
1312
|
-
return rpcs[id];
|
|
1639
|
+
const getWordAtOffset = async editorUid => {
|
|
1640
|
+
return invoke$1('Editor.getWordAtOffset2', editorUid);
|
|
1313
1641
|
};
|
|
1314
1642
|
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1643
|
+
const handleEditorDeleteLeft = async state => {
|
|
1644
|
+
const {
|
|
1645
|
+
unfilteredItems,
|
|
1646
|
+
itemHeight,
|
|
1647
|
+
maxHeight,
|
|
1648
|
+
editorUid
|
|
1649
|
+
} = state;
|
|
1650
|
+
const x = 0; // TODO
|
|
1651
|
+
// @ts-ignore
|
|
1652
|
+
const y = 0; // TODP
|
|
1653
|
+
const wordAtOffset = await getWordAtOffset(editorUid);
|
|
1654
|
+
if (!wordAtOffset) {
|
|
1655
|
+
return {
|
|
1656
|
+
...state,
|
|
1657
|
+
disposed: true
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
const items = filterCompletionItems(unfilteredItems, wordAtOffset);
|
|
1661
|
+
const newMaxLineY = Math.min(items.length, 8);
|
|
1662
|
+
const height = getListHeight(items.length, itemHeight, maxHeight);
|
|
1318
1663
|
return {
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
invokeAndTransfer(method, ...params) {
|
|
1327
|
-
const rpc = get(rpcId);
|
|
1328
|
-
// @ts-ignore
|
|
1329
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
1330
|
-
},
|
|
1331
|
-
set(rpc) {
|
|
1332
|
-
set$a(rpcId, rpc);
|
|
1333
|
-
}
|
|
1664
|
+
...state,
|
|
1665
|
+
items,
|
|
1666
|
+
x,
|
|
1667
|
+
y,
|
|
1668
|
+
maxLineY: newMaxLineY,
|
|
1669
|
+
leadingWord: wordAtOffset,
|
|
1670
|
+
height
|
|
1334
1671
|
};
|
|
1335
1672
|
};
|
|
1336
|
-
const EditorWorker$1 = 99;
|
|
1337
|
-
const ExtensionHostWorker = 44;
|
|
1338
|
-
const {
|
|
1339
|
-
invoke: invoke$9,
|
|
1340
|
-
invokeAndTransfer: invokeAndTransfer$9,
|
|
1341
|
-
set: set$9
|
|
1342
|
-
} = create(EditorWorker$1);
|
|
1343
|
-
const EditorWorker = {
|
|
1344
|
-
__proto__: null,
|
|
1345
|
-
invoke: invoke$9,
|
|
1346
|
-
invokeAndTransfer: invokeAndTransfer$9,
|
|
1347
|
-
set: set$9
|
|
1348
|
-
};
|
|
1349
|
-
const {
|
|
1350
|
-
invoke: invoke$7,
|
|
1351
|
-
set: set$7
|
|
1352
|
-
} = create(ExtensionHostWorker);
|
|
1353
|
-
const ExtensionHost = {
|
|
1354
|
-
__proto__: null,
|
|
1355
|
-
invoke: invoke$7,
|
|
1356
|
-
set: set$7
|
|
1357
|
-
};
|
|
1358
|
-
|
|
1359
|
-
const {
|
|
1360
|
-
invoke: invoke$1,
|
|
1361
|
-
set: set$1,
|
|
1362
|
-
invokeAndTransfer
|
|
1363
|
-
} = EditorWorker;
|
|
1364
1673
|
|
|
1365
1674
|
const getPositionAtCursor = async parentUid => {
|
|
1366
1675
|
const position = await invoke$1('Editor.getPositionAtCursor', parentUid);
|
|
@@ -1368,7 +1677,6 @@ const getPositionAtCursor = async parentUid => {
|
|
|
1368
1677
|
};
|
|
1369
1678
|
|
|
1370
1679
|
const getWordBefore = async (editorUid, rowIndex, columnIndex) => {
|
|
1371
|
-
// @ts-ignore
|
|
1372
1680
|
return invoke$1('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
|
|
1373
1681
|
};
|
|
1374
1682
|
|
|
@@ -1404,6 +1712,52 @@ const handleEditorType = async state => {
|
|
|
1404
1712
|
};
|
|
1405
1713
|
};
|
|
1406
1714
|
|
|
1715
|
+
const clamp = (num, min, max) => {
|
|
1716
|
+
number(num);
|
|
1717
|
+
number(min);
|
|
1718
|
+
number(max);
|
|
1719
|
+
return Math.min(Math.max(num, min), max);
|
|
1720
|
+
};
|
|
1721
|
+
|
|
1722
|
+
// TODO optimize this function to return the minimum number
|
|
1723
|
+
// of visible items needed, e.g. when not scrolled 5 items with
|
|
1724
|
+
// 20px fill 100px but when scrolled 6 items are needed
|
|
1725
|
+
const getNumberOfVisibleItems = (listHeight, itemHeight) => {
|
|
1726
|
+
return Math.ceil(listHeight / itemHeight) + 1;
|
|
1727
|
+
};
|
|
1728
|
+
|
|
1729
|
+
const setDeltaY = (state, value) => {
|
|
1730
|
+
object(state);
|
|
1731
|
+
number(value);
|
|
1732
|
+
const {
|
|
1733
|
+
itemHeight,
|
|
1734
|
+
finalDeltaY,
|
|
1735
|
+
deltaY,
|
|
1736
|
+
height,
|
|
1737
|
+
headerHeight
|
|
1738
|
+
} = state;
|
|
1739
|
+
const listHeight = height - headerHeight;
|
|
1740
|
+
const newDeltaY = clamp(value, 0, finalDeltaY);
|
|
1741
|
+
if (deltaY === newDeltaY) {
|
|
1742
|
+
return state;
|
|
1743
|
+
}
|
|
1744
|
+
// TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
|
|
1745
|
+
const minLineY = Math.floor(newDeltaY / itemHeight);
|
|
1746
|
+
const maxLineY = minLineY + getNumberOfVisibleItems(listHeight, itemHeight);
|
|
1747
|
+
return {
|
|
1748
|
+
...state,
|
|
1749
|
+
deltaY: newDeltaY,
|
|
1750
|
+
minLineY,
|
|
1751
|
+
maxLineY
|
|
1752
|
+
};
|
|
1753
|
+
};
|
|
1754
|
+
|
|
1755
|
+
const handleWheel = (state, deltaMode, deltaY) => {
|
|
1756
|
+
number(deltaMode);
|
|
1757
|
+
number(deltaY);
|
|
1758
|
+
return setDeltaY(state, state.deltaY + deltaY);
|
|
1759
|
+
};
|
|
1760
|
+
|
|
1407
1761
|
const getPortTuple = () => {
|
|
1408
1762
|
const {
|
|
1409
1763
|
port1,
|
|
@@ -1441,74 +1795,17 @@ const createExtensionHostRpc = async () => {
|
|
|
1441
1795
|
}
|
|
1442
1796
|
};
|
|
1443
1797
|
|
|
1444
|
-
const {
|
|
1445
|
-
invoke,
|
|
1446
|
-
set
|
|
1447
|
-
} = ExtensionHost;
|
|
1448
|
-
|
|
1449
1798
|
const initialize = async () => {
|
|
1450
1799
|
const rpc = await createExtensionHostRpc();
|
|
1451
1800
|
set(rpc);
|
|
1452
1801
|
};
|
|
1453
1802
|
|
|
1454
|
-
const OnCompletion = 'onCompletion';
|
|
1455
|
-
|
|
1456
|
-
const CompletionExecute = 'ExtensionHostCompletion.execute';
|
|
1457
|
-
|
|
1458
|
-
// TODO add tests for this
|
|
1459
|
-
const activateByEvent = async event => {
|
|
1460
|
-
// @ts-ignore
|
|
1461
|
-
await invoke$1('ActivateByEvent.activateByEvent', event);
|
|
1462
|
-
};
|
|
1463
|
-
|
|
1464
|
-
const execute = async ({
|
|
1465
|
-
editorLanguageId,
|
|
1466
|
-
editorUid,
|
|
1467
|
-
args,
|
|
1468
|
-
event,
|
|
1469
|
-
method,
|
|
1470
|
-
noProviderFoundMessage,
|
|
1471
|
-
noProviderFoundResult = undefined
|
|
1472
|
-
}) => {
|
|
1473
|
-
const fullEvent = `${event}:${editorLanguageId}`;
|
|
1474
|
-
await activateByEvent(fullEvent);
|
|
1475
|
-
const result = await invoke(method, editorUid, ...args);
|
|
1476
|
-
return result;
|
|
1477
|
-
};
|
|
1478
|
-
|
|
1479
|
-
const executeCompletionProvider = async (editorUid, editorLanguageId, offset) => {
|
|
1480
|
-
return execute({
|
|
1481
|
-
editorUid,
|
|
1482
|
-
editorLanguageId,
|
|
1483
|
-
event: OnCompletion,
|
|
1484
|
-
method: CompletionExecute,
|
|
1485
|
-
args: [offset],
|
|
1486
|
-
noProviderFoundMessage: 'no completion provider found',
|
|
1487
|
-
noProviderFoundResult: []});
|
|
1488
|
-
};
|
|
1489
|
-
|
|
1490
|
-
const getOffsetAtCursor = editorUid => {
|
|
1491
|
-
// TODO ask editor worker
|
|
1492
|
-
return 0;
|
|
1493
|
-
};
|
|
1494
|
-
|
|
1495
|
-
// TODO possible to do this with events/state machine instead of promises -> enables canceling operations / concurrent calls
|
|
1496
|
-
const getCompletions = async (editorUid, editorLanguageId) => {
|
|
1497
|
-
const offset = getOffsetAtCursor();
|
|
1498
|
-
const completions = await executeCompletionProvider(editorUid, editorLanguageId, offset);
|
|
1499
|
-
return completions;
|
|
1500
|
-
};
|
|
1501
|
-
|
|
1502
1803
|
const getFinalDeltaY = (height, itemHeight, itemsLength) => {
|
|
1503
1804
|
const contentHeight = itemsLength * itemHeight;
|
|
1504
1805
|
const finalDeltaY = Math.max(contentHeight - height, 0);
|
|
1505
1806
|
return finalDeltaY;
|
|
1506
1807
|
};
|
|
1507
1808
|
|
|
1508
|
-
const getWordAtOffset = async editorUid => {
|
|
1509
|
-
return invoke$1('Editor.getWordAtOffset2', editorUid);
|
|
1510
|
-
};
|
|
1511
|
-
|
|
1512
1809
|
const loadContent = async state => {
|
|
1513
1810
|
const {
|
|
1514
1811
|
itemHeight,
|
|
@@ -1545,7 +1842,8 @@ const loadContent = async state => {
|
|
|
1545
1842
|
// @ts-ignore
|
|
1546
1843
|
rowIndex,
|
|
1547
1844
|
columnIndex,
|
|
1548
|
-
width: 200
|
|
1845
|
+
width: 200,
|
|
1846
|
+
version: 1
|
|
1549
1847
|
};
|
|
1550
1848
|
};
|
|
1551
1849
|
|
|
@@ -1585,6 +1883,10 @@ const renderEventListeners = state => {
|
|
|
1585
1883
|
return [SetEventListeners, uid, eventListeners];
|
|
1586
1884
|
};
|
|
1587
1885
|
|
|
1886
|
+
const renderFocusContext = (oldState, newState) => {
|
|
1887
|
+
return [/* method */'Viewlet.setFocusContext', FocusEditorRename];
|
|
1888
|
+
};
|
|
1889
|
+
|
|
1588
1890
|
const ColoredMaskIcon = 'ColoredMaskIcon';
|
|
1589
1891
|
const EditorCompletion = 'EditorCompletion';
|
|
1590
1892
|
const EditorCompletionItem = 'EditorCompletionItem';
|
|
@@ -1870,6 +2172,8 @@ const getRenderer = diffType => {
|
|
|
1870
2172
|
return renderUid;
|
|
1871
2173
|
case RenderItems:
|
|
1872
2174
|
return renderItems;
|
|
2175
|
+
case RenderFocusContext:
|
|
2176
|
+
return renderFocusContext;
|
|
1873
2177
|
default:
|
|
1874
2178
|
throw new Error('unknown renderer');
|
|
1875
2179
|
}
|
|
@@ -1901,12 +2205,22 @@ const terminate = () => {
|
|
|
1901
2205
|
const commandMap = {
|
|
1902
2206
|
'Completions.create': create$1,
|
|
1903
2207
|
'Completions.diff2': diff2,
|
|
2208
|
+
'Completions.focusFirst': wrapCommand(focusFirst),
|
|
2209
|
+
'Completions.focusIndex': wrapCommand(focusIndex),
|
|
2210
|
+
'Completions.focusNext': wrapCommand(focusNext),
|
|
2211
|
+
'Completions.focusPrevious': wrapCommand(focusPrevious),
|
|
1904
2212
|
'Completions.getCommandIds': getCommandIds,
|
|
2213
|
+
'Completions.getKeyBindings': getKeyBindings,
|
|
2214
|
+
'Completions.handleEditorDeleteLeft': wrapCommand(handleEditorDeleteLeft),
|
|
2215
|
+
'Completions.handleEditorType': handleEditorType,
|
|
2216
|
+
'Completions.handleWheel': wrapCommand(handleWheel),
|
|
2217
|
+
'Completions.initialize': initialize,
|
|
1905
2218
|
'Completions.loadContent': wrapCommand(loadContent),
|
|
1906
2219
|
'Completions.render2': render2,
|
|
2220
|
+
'Completions.selectCurrent': wrapCommand(selectCurrent),
|
|
2221
|
+
'Completions.selectIndex': wrapCommand(selectIndex),
|
|
1907
2222
|
'Completions.terminate': terminate,
|
|
1908
|
-
'Completions.
|
|
1909
|
-
'Completions.handleEditorType': handleEditorType
|
|
2223
|
+
'Completions.openDetails': wrapCommand(openDetails)
|
|
1910
2224
|
};
|
|
1911
2225
|
|
|
1912
2226
|
const listen = async () => {
|