@lvce-editor/editor-worker 1.2.0 → 1.4.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.
@@ -966,11 +966,11 @@ const setText = (editor, text) => {
966
966
  };
967
967
 
968
968
  const editors = Object.create(null);
969
- const get$5 = id => {
969
+ const get$6 = id => {
970
970
  number$1(id);
971
971
  return editors[id];
972
972
  };
973
- const set$5 = (id, oldEditor, newEditor) => {
973
+ const set$6 = (id, oldEditor, newEditor) => {
974
974
  number$1(id);
975
975
  object(oldEditor);
976
976
  object(newEditor);
@@ -1046,10 +1046,10 @@ const number = value => {
1046
1046
  const state$1$1 = {
1047
1047
  callbacks: Object.create(null)
1048
1048
  };
1049
- const set$4 = (id, fn) => {
1049
+ const set$5 = (id, fn) => {
1050
1050
  state$1$1.callbacks[id] = fn;
1051
1051
  };
1052
- const get$4 = id => {
1052
+ const get$5 = id => {
1053
1053
  return state$1$1.callbacks[id];
1054
1054
  };
1055
1055
  const remove = id => {
@@ -1083,7 +1083,7 @@ const registerPromise = () => {
1083
1083
  resolve,
1084
1084
  promise
1085
1085
  } = withResolvers$2();
1086
- set$4(id, resolve);
1086
+ set$5(id, resolve);
1087
1087
  return {
1088
1088
  id,
1089
1089
  promise
@@ -1091,7 +1091,7 @@ const registerPromise = () => {
1091
1091
  };
1092
1092
  const resolve = (id, args) => {
1093
1093
  number(id);
1094
- const fn = get$4(id);
1094
+ const fn = get$5(id);
1095
1095
  if (!fn) {
1096
1096
  console.log(args);
1097
1097
  warn$1(`callback ${id} may already be disposed`);
@@ -1283,7 +1283,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
1283
1283
  const errorProperty = getErrorProperty(error, prettyError);
1284
1284
  return create$1$1(message, errorProperty);
1285
1285
  };
1286
- const create$4 = (message, result) => {
1286
+ const create$5 = (message, result) => {
1287
1287
  return {
1288
1288
  jsonrpc: Two,
1289
1289
  id: message.id,
@@ -1292,7 +1292,7 @@ const create$4 = (message, result) => {
1292
1292
  };
1293
1293
  const getSuccessResponse = (message, result) => {
1294
1294
  const resultProperty = result ?? null;
1295
- return create$4(message, resultProperty);
1295
+ return create$5(message, resultProperty);
1296
1296
  };
1297
1297
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
1298
1298
  try {
@@ -1323,7 +1323,7 @@ const handleJsonRpcMessage = async (ipc, message, execute, resolve, preparePrett
1323
1323
  }
1324
1324
  throw new JsonRpcError('unexpected message');
1325
1325
  };
1326
- const invoke$4 = async (ipc, method, ...params) => {
1326
+ const invoke$5 = async (ipc, method, ...params) => {
1327
1327
  const {
1328
1328
  message,
1329
1329
  promise
@@ -1400,6 +1400,7 @@ const handleIpc = ipc => {
1400
1400
 
1401
1401
  const RendererProcess = 9;
1402
1402
  const ExtensionHostWorker = 10;
1403
+ const SyntaxHighlightingWorker = 11;
1403
1404
 
1404
1405
  // @ts-ignore
1405
1406
  const getData = event => {
@@ -1430,27 +1431,27 @@ const state$8 = {
1430
1431
  */
1431
1432
  ipc: undefined
1432
1433
  };
1433
- const get$3 = () => {
1434
+ const get$4 = () => {
1434
1435
  return state$8.ipc;
1435
1436
  };
1436
- const set$3 = ipc => {
1437
+ const set$4 = ipc => {
1437
1438
  state$8.ipc = ipc;
1438
1439
  };
1439
1440
 
1440
- const invoke$3 = (method, ...params) => {
1441
- const ipc = get$3();
1442
- return invoke$4(ipc, method, ...params);
1441
+ const invoke$4 = (method, ...params) => {
1442
+ const ipc = get$4();
1443
+ return invoke$5(ipc, method, ...params);
1443
1444
  };
1444
1445
  const invokeAndTransfer$1 = async (transfer, method, ...params) => {
1445
- const ipc = get$3();
1446
+ const ipc = get$4();
1446
1447
  return invokeAndTransfer$2(ipc, transfer, method, ...params);
1447
1448
  };
1448
- const listen$7 = ipc => {
1449
- set$3(ipc);
1449
+ const listen$8 = ipc => {
1450
+ set$4(ipc);
1450
1451
  };
1451
1452
 
1452
- const invoke$2 = async (method, ...params) => {
1453
- return invoke$3(method, ...params);
1453
+ const invoke$3 = async (method, ...params) => {
1454
+ return invoke$4(method, ...params);
1454
1455
  };
1455
1456
  const invokeAndTransfer = async (transfer, method, ...params) => {
1456
1457
  return invokeAndTransfer$1(transfer, method, ...params);
@@ -1488,7 +1489,7 @@ const waitForFirstMessage$1 = async port => {
1488
1489
  return event;
1489
1490
  };
1490
1491
 
1491
- const create$3 = async () => {
1492
+ const create$4 = async () => {
1492
1493
  const {
1493
1494
  port1,
1494
1495
  port2
@@ -1500,7 +1501,7 @@ const create$3 = async () => {
1500
1501
  }
1501
1502
  return port2;
1502
1503
  };
1503
- const wrap$1 = port => {
1504
+ const wrap$3 = port => {
1504
1505
  return {
1505
1506
  port,
1506
1507
  /**
@@ -1532,6 +1533,59 @@ const wrap$1 = port => {
1532
1533
  };
1533
1534
 
1534
1535
  const IpcParentWithExtensionHostWorker = {
1536
+ __proto__: null,
1537
+ create: create$4,
1538
+ wrap: wrap$3
1539
+ };
1540
+
1541
+ const sendMessagePortToSyntaxHighlightingWorker = async port => {
1542
+ await invokeAndTransfer([port], 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort');
1543
+ };
1544
+
1545
+ const create$3 = async () => {
1546
+ const {
1547
+ port1,
1548
+ port2
1549
+ } = getPortTuple();
1550
+ await sendMessagePortToSyntaxHighlightingWorker(port1);
1551
+ const event = await waitForFirstMessage$1(port2);
1552
+ if (event.data !== 'ready') {
1553
+ throw new IpcError$1('unexpected first message');
1554
+ }
1555
+ return port2;
1556
+ };
1557
+ const wrap$1 = port => {
1558
+ return {
1559
+ port,
1560
+ /**
1561
+ * @type {any}
1562
+ */
1563
+ listener: undefined,
1564
+ get onmessage() {
1565
+ return this.listener;
1566
+ },
1567
+ set onmessage(listener) {
1568
+ this.listener = listener;
1569
+ const wrappedListener = event => {
1570
+ const data = getData(event);
1571
+ // @ts-ignore
1572
+ listener({
1573
+ target: this,
1574
+ data
1575
+ });
1576
+ };
1577
+ this.port.onmessage = wrappedListener;
1578
+ },
1579
+ send(message) {
1580
+ this.port.postMessage(message);
1581
+ },
1582
+ sendAndTransfer(message, transfer) {
1583
+ this.port.postMessage(message, transfer);
1584
+ }
1585
+ };
1586
+ };
1587
+
1588
+ const IpcParentWithSyntaxHighlightingWorker = {
1535
1589
  __proto__: null,
1536
1590
  create: create$3,
1537
1591
  wrap: wrap$1
@@ -1596,6 +1650,8 @@ const getModule$1 = method => {
1596
1650
  return IpcParentWithRendererProcess;
1597
1651
  case ExtensionHostWorker:
1598
1652
  return IpcParentWithExtensionHostWorker;
1653
+ case SyntaxHighlightingWorker:
1654
+ return IpcParentWithSyntaxHighlightingWorker;
1599
1655
  default:
1600
1656
  throw new Error('unexpected ipc type');
1601
1657
  }
@@ -1616,18 +1672,29 @@ const create$1 = async ({
1616
1672
  return ipc;
1617
1673
  };
1618
1674
 
1619
- let _ipc$1;
1620
- const listen$6 = async () => {
1621
- const ipc = await create$1({
1622
- method: ExtensionHostWorker
1623
- });
1624
- handleIpc(ipc);
1625
- _ipc$1 = ipc;
1626
- };
1627
- const invoke$1 = (method, ...params) => {
1628
- return invoke$4(_ipc$1, method, ...params);
1675
+ const createRpc = method => {
1676
+ let _ipc;
1677
+ const listen = async () => {
1678
+ const ipc = await create$1({
1679
+ method
1680
+ });
1681
+ handleIpc(ipc);
1682
+ _ipc = ipc;
1683
+ };
1684
+ const invoke = (method, ...params) => {
1685
+ return invoke$5(_ipc, method, ...params);
1686
+ };
1687
+ return {
1688
+ listen,
1689
+ invoke
1690
+ };
1629
1691
  };
1630
1692
 
1693
+ const {
1694
+ listen: listen$7,
1695
+ invoke: invoke$2
1696
+ } = createRpc(ExtensionHostWorker);
1697
+
1631
1698
  const HoverExecute = 'ExtensionHostHover.execute';
1632
1699
  const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
1633
1700
 
@@ -1754,8 +1821,8 @@ const createEditor = async ({
1754
1821
  focused: true
1755
1822
  };
1756
1823
  // console.log({ newEditor })
1757
- set$5(id, emptyEditor, newEditor4);
1758
- await invoke$1(TextDocumentSyncFull, uri, id, languageId, content);
1824
+ set$6(id, emptyEditor, newEditor4);
1825
+ await invoke$2(TextDocumentSyncFull, uri, id, languageId, content);
1759
1826
  };
1760
1827
 
1761
1828
  // @ts-ignore
@@ -2093,7 +2160,7 @@ const editorShowMessage = async (editor, rowIndex, columnIndex, message, isError
2093
2160
  const x$1 = x(editor, rowIndex, columnIndex);
2094
2161
  const y$1 = y(editor, rowIndex);
2095
2162
  const displayErrorMessage = message;
2096
- await invoke$2('Editor.showOverlayMessage', editor, 'Viewlet.send', editor.uid, 'showOverlayMessage', x$1, y$1, displayErrorMessage);
2163
+ await invoke$3('Editor.showOverlayMessage', editor, 'Viewlet.send', editor.uid, 'showOverlayMessage', x$1, y$1, displayErrorMessage);
2097
2164
  if (!isError) {
2098
2165
  const handleTimeout = () => {
2099
2166
  editorHideMessage(editor);
@@ -2149,7 +2216,7 @@ const braceCompletion = async (editor, text) => {
2149
2216
  try {
2150
2217
  // @ts-ignore
2151
2218
  const offset = offsetAt(editor, editor.cursor);
2152
- const result = await invoke$2('ExtensionHostBraceCompletion.executeBraceCompletionProvider', editor, offset, text);
2219
+ const result = await invoke$3('ExtensionHostBraceCompletion.executeBraceCompletionProvider', editor, offset, text);
2153
2220
  if (result) {
2154
2221
  const closingBrace = getMatchingClosingBrace$1(text);
2155
2222
  const insertText = text + closingBrace;
@@ -2183,7 +2250,7 @@ const cancelSelection = editor => {
2183
2250
  const closeCompletion = async editor => {
2184
2251
  // TODO
2185
2252
  const completionUid = editor.completionUid;
2186
- await invoke$2('Viewlet.dispose', completionUid);
2253
+ await invoke$3('Viewlet.dispose', completionUid);
2187
2254
  editor.completionUid = 0;
2188
2255
  return editor;
2189
2256
  };
@@ -2321,7 +2388,7 @@ let VError$1 = class VError extends Error {
2321
2388
  const writeText = async text => {
2322
2389
  try {
2323
2390
  string(text);
2324
- await invoke$2('ClipBoard.writeText', /* text */text);
2391
+ await invoke$3('ClipBoard.writeText', /* text */text);
2325
2392
  } catch (error) {
2326
2393
  throw new VError$1(error, 'Failed to write text to clipboard');
2327
2394
  }
@@ -3005,7 +3072,7 @@ const deleteWordRight = editor => {
3005
3072
  };
3006
3073
 
3007
3074
  const findAllReferences = async editor => {
3008
- await invoke$2('SideBar.show', 'References', /* focus */true);
3075
+ await invoke$3('SideBar.show', 'References', /* focus */true);
3009
3076
  return editor;
3010
3077
  };
3011
3078
 
@@ -3019,7 +3086,7 @@ const findAllReferences = async editor => {
3019
3086
  // TODO should be in editor folder
3020
3087
 
3021
3088
  const format$1 = async editor => {
3022
- const edits = await invoke$2('Format.format', editor);
3089
+ const edits = await invoke$3('Format.format', editor);
3023
3090
  return edits;
3024
3091
  };
3025
3092
 
@@ -3129,7 +3196,7 @@ const getWordBefore = (editor, rowIndex, columnIndex) => {
3129
3196
 
3130
3197
  // @ts-ignore
3131
3198
  const getDefinition = async (editor, offset) => {
3132
- const definition = await invoke$2('ExtensionHostDefinition.executeDefinitionProvider', editor, offset);
3199
+ const definition = await invoke$3('ExtensionHostDefinition.executeDefinitionProvider', editor, offset);
3133
3200
  return definition;
3134
3201
  };
3135
3202
 
@@ -3268,7 +3335,7 @@ const goTo = async ({
3268
3335
  endRowIndex: definition.endRowIndex,
3269
3336
  endColumnIndex: definition.endColumnIndex
3270
3337
  };
3271
- await invoke$2( /* Main.openUri */'Main.openUri', /* uri */uri, /* focus */true, context);
3338
+ await invoke$3( /* Main.openUri */'Main.openUri', /* uri */uri, /* focus */true, context);
3272
3339
  return editor;
3273
3340
  } catch (error) {
3274
3341
  // TODO if editor is already disposed at this point, do nothing
@@ -3349,7 +3416,7 @@ const getNoLocationFoundMessage = info => {
3349
3416
  };
3350
3417
 
3351
3418
  const getTypeDefinition = async (editor, offset) => {
3352
- const definition = await invoke$2('ExtensionHostTypeDefinition.executeTypeDefinitionProvider', editor, offset);
3419
+ const definition = await invoke$3('ExtensionHostTypeDefinition.executeTypeDefinitionProvider', editor, offset);
3353
3420
  return definition;
3354
3421
  };
3355
3422
 
@@ -3393,7 +3460,7 @@ const goToTypeDefinition = (editor, explicit = true) => {
3393
3460
  const Editor = 3;
3394
3461
 
3395
3462
  const handleContextMenu = async (editor, button, x, y) => {
3396
- await invoke$2( /* ContextMenu.show */'ContextMenu.show', /* x */x, /* y */y, /* id */Editor);
3463
+ await invoke$3( /* ContextMenu.show */'ContextMenu.show', /* x */x, /* y */y, /* id */Editor);
3397
3464
  return editor;
3398
3465
  };
3399
3466
 
@@ -3431,7 +3498,7 @@ const WhenExpressionEditorText = 12;
3431
3498
  const handleFocus = editor => {
3432
3499
  // TODO make change events functional,
3433
3500
  // when rendering, send focus changes to renderer worker
3434
- invoke$2('Focus.setFocus', WhenExpressionEditorText);
3501
+ invoke$3('Focus.setFocus', WhenExpressionEditorText);
3435
3502
  return editor;
3436
3503
  };
3437
3504
 
@@ -3594,10 +3661,10 @@ const state$4 = {
3594
3661
  y: 0,
3595
3662
  editor: undefined
3596
3663
  };
3597
- const get$2 = () => {
3664
+ const get$3 = () => {
3598
3665
  return state$4;
3599
3666
  };
3600
- const set$2 = (editor, timeout, x, y) => {
3667
+ const set$3 = (editor, timeout, x, y) => {
3601
3668
  state$4.editor = editor;
3602
3669
  state$4.timeout = timeout;
3603
3670
  state$4.x = x;
@@ -3623,7 +3690,7 @@ const onHoverIdle = async () => {
3623
3690
  x,
3624
3691
  y,
3625
3692
  editor
3626
- } = get$2();
3693
+ } = get$3();
3627
3694
  at(editor, x, y);
3628
3695
  await showHover$1();
3629
3696
  };
@@ -3634,12 +3701,12 @@ const handleMouseMove = (editor, x, y) => {
3634
3701
  if (!editor.hoverEnabled) {
3635
3702
  return editor;
3636
3703
  }
3637
- const oldState = get$2();
3704
+ const oldState = get$3();
3638
3705
  if (oldState.timeout !== -1) {
3639
3706
  clearTimeout(oldState.timeout);
3640
3707
  }
3641
3708
  const timeout = setTimeout(onHoverIdle, hoverDelay);
3642
- set$2(editor, timeout, x, y);
3709
+ set$3(editor, timeout, x, y);
3643
3710
  return editor;
3644
3711
  };
3645
3712
 
@@ -4174,7 +4241,7 @@ const indentMore = editor => {
4174
4241
  };
4175
4242
 
4176
4243
  const getLanguageConfiguration = editor => {
4177
- return invoke$2('Languages.getLanguageConfiguration', {
4244
+ return invoke$3('Languages.getLanguageConfiguration', {
4178
4245
  uri: editor.uri,
4179
4246
  languageId: editor.languageId
4180
4247
  });
@@ -4391,13 +4458,13 @@ const moveSelectionPx = (editor, x, y) => {
4391
4458
 
4392
4459
  const FindWidget = 'FindWidget';
4393
4460
  const openFind = async state => {
4394
- await invoke$2('Viewlet.openWidget', FindWidget);
4461
+ await invoke$3('Viewlet.openWidget', FindWidget);
4395
4462
  return state;
4396
4463
  };
4397
4464
 
4398
4465
  const organizeImports = async editor => {
4399
4466
  // TODO ask extension host worker directly
4400
- const edits = await invoke$2('ExtensionHostOrganizeImports.organizeImports', editor);
4467
+ const edits = await invoke$3('ExtensionHostOrganizeImports.organizeImports', editor);
4401
4468
  console.log({
4402
4469
  edits
4403
4470
  });
@@ -4414,7 +4481,7 @@ const pasteText = (editor, text) => {
4414
4481
  };
4415
4482
 
4416
4483
  const paste = async editor => {
4417
- const text = await invoke$2('ClipBoard.readText');
4484
+ const text = await invoke$3('ClipBoard.readText');
4418
4485
  string(text);
4419
4486
  return pasteText(editor, text);
4420
4487
  };
@@ -4552,7 +4619,7 @@ const save = async editor => {
4552
4619
  const uri = editor.uri;
4553
4620
  const newEditor = await getNewEditor(editor);
4554
4621
  const content = getText(newEditor);
4555
- await invoke$2('FileSystem.writeFile', uri, content);
4622
+ await invoke$3('FileSystem.writeFile', uri, content);
4556
4623
  return newEditor;
4557
4624
  } catch (error) {
4558
4625
  // @ts-ignore
@@ -5083,7 +5150,7 @@ const selectWordRight = editor => {
5083
5150
  // import * as ExtensionHostSelection from '../ExtensionHost/ExtensionHostSelection.ts'
5084
5151
 
5085
5152
  const getNewSelections = async (editor, selections) => {
5086
- const newSelections = await invoke$2('ExtensionHostSelection.executeGrowSelection', editor, selections);
5153
+ const newSelections = await invoke$3('ExtensionHostSelection.executeGrowSelection', editor, selections);
5087
5154
  if (newSelections.length === 0) {
5088
5155
  return selections;
5089
5156
  }
@@ -5109,7 +5176,7 @@ const setDecorations = (editor, decorations, diagnostics) => {
5109
5176
  };
5110
5177
 
5111
5178
  const getEditor = editorUid => {
5112
- const instance = get$5(editorUid);
5179
+ const instance = get$6(editorUid);
5113
5180
  if (!instance) {
5114
5181
  throw new Error(`editor ${editorUid} not found`);
5115
5182
  }
@@ -5169,21 +5236,47 @@ const state$1 = {
5169
5236
  const has = languageId => {
5170
5237
  return languageId in state$1.tokenizers;
5171
5238
  };
5172
- const set$1 = (languageId, tokenizer) => {
5239
+ const set$2 = (languageId, tokenizer) => {
5173
5240
  state$1.tokenizers[languageId] = tokenizer;
5174
5241
  };
5175
- const get$1 = languageId => {
5242
+ const get$2 = languageId => {
5176
5243
  return state$1.tokenizers[languageId];
5177
5244
  };
5178
5245
  const isPending = languageId => {
5179
5246
  return languageId in state$1.pending;
5180
5247
  };
5181
5248
 
5249
+ let enabled = false;
5250
+ const setEnabled = value => {
5251
+ enabled = value;
5252
+ };
5253
+ const getEnabled = () => {
5254
+ return enabled;
5255
+ };
5256
+
5257
+ const {
5258
+ listen: listen$6,
5259
+ invoke: invoke$1
5260
+ } = createRpc(SyntaxHighlightingWorker);
5261
+
5262
+ const tokenMaps = Object.create(null);
5263
+ const set$1 = (languageId, tokenMap) => {
5264
+ tokenMaps[languageId] = tokenMap;
5265
+ };
5266
+ const get$1 = languageId => {
5267
+ return tokenMaps[languageId] || {};
5268
+ };
5269
+
5182
5270
  // TODO loadTokenizer should be invoked from renderer worker
5183
5271
  const loadTokenizer = async (languageId, tokenizePath) => {
5184
5272
  if (!tokenizePath) {
5185
5273
  return;
5186
5274
  }
5275
+ if (getEnabled()) {
5276
+ const tokenMap = await invoke$1('Tokenizer.load', languageId, tokenizePath);
5277
+ set$1(languageId, tokenMap);
5278
+ return;
5279
+ }
5187
5280
  try {
5188
5281
  // TODO check that tokenizer is valid
5189
5282
  // 1. tokenizeLine should be of type function
@@ -5197,7 +5290,8 @@ const loadTokenizer = async (languageId, tokenizePath) => {
5197
5290
  console.warn(`tokenizer.TokenMap should be an object in "${tokenizePath}"`);
5198
5291
  return;
5199
5292
  }
5200
- set$1(languageId, tokenizer);
5293
+ set$1(languageId, tokenizer.TokenMap);
5294
+ set$2(languageId, tokenizer);
5201
5295
  } catch (error) {
5202
5296
  // TODO better error handling
5203
5297
  console.error(error);
@@ -5206,7 +5300,7 @@ const loadTokenizer = async (languageId, tokenizePath) => {
5206
5300
  };
5207
5301
  const getTokenizer = languageId => {
5208
5302
  if (has(languageId)) {
5209
- return get$1(languageId);
5303
+ return get$2(languageId);
5210
5304
  }
5211
5305
  if (isPending(languageId)) {
5212
5306
  return TokenizePlainText;
@@ -5287,7 +5381,7 @@ const setSelections = (editor, selections) => {
5287
5381
 
5288
5382
  const EditorHover = 'EditorHover';
5289
5383
  const showHover = async state => {
5290
- await invoke$2('Viewlet.openWidget', EditorHover);
5384
+ await invoke$3('Viewlet.openWidget', EditorHover);
5291
5385
  return state;
5292
5386
  };
5293
5387
 
@@ -5298,7 +5392,7 @@ const showSourceActions = async editor => {
5298
5392
  // 2. query source actions from extension host
5299
5393
  // 3. show source actions menu
5300
5394
 
5301
- await invoke$2('Viewlet.openWidget', EditorSourceActions);
5395
+ await invoke$3('Viewlet.openWidget', EditorSourceActions);
5302
5396
  return editor;
5303
5397
  };
5304
5398
 
@@ -5369,7 +5463,7 @@ const getTabCompletion = async editor => {
5369
5463
  const rowIndex = selections[0];
5370
5464
  const columnIndex = selections[1];
5371
5465
  const offset = offsetAt(editor, rowIndex, columnIndex);
5372
- const tabCompletion = await invoke$2('ExtensionHostTabCompletion.executeTabCompletionProvider', editor, offset);
5466
+ const tabCompletion = await invoke$3('ExtensionHostTabCompletion.executeTabCompletionProvider', editor, offset);
5373
5467
  return tabCompletion;
5374
5468
  };
5375
5469
 
@@ -5866,7 +5960,7 @@ const typeWithAutoClosingQuote = (editor, text) => {
5866
5960
 
5867
5961
  const typeWithAutoClosingTag = async (editor, text) => {
5868
5962
  const offset = offsetAt(editor, editor.selections[0], editor.selections[1]);
5869
- const result = await invoke$2('ExtensionHostClosingTagCompletion.executeClosingTagProvider', editor, offset, text);
5963
+ const result = await invoke$3('ExtensionHostClosingTagCompletion.executeClosingTagProvider', editor, offset, text);
5870
5964
  if (!result) {
5871
5965
  const changes = editorReplaceSelections(editor, [text], EditorType);
5872
5966
  return scheduleDocumentAndCursorsSelections(editor, changes);
@@ -6286,7 +6380,7 @@ const OnHover = 'onHover';
6286
6380
 
6287
6381
  // TODO add tests for this
6288
6382
  const activateByEvent = async event => {
6289
- await invoke$2('ExtensionHostManagement.activateByEvent', event);
6383
+ await invoke$3('ExtensionHostManagement.activateByEvent', event);
6290
6384
  };
6291
6385
 
6292
6386
  const execute = async ({
@@ -6299,7 +6393,7 @@ const execute = async ({
6299
6393
  }) => {
6300
6394
  const fullEvent = `${event}:${editor.languageId}`;
6301
6395
  await activateByEvent(fullEvent);
6302
- const result = await invoke$1(method, editor.uid, ...args);
6396
+ const result = await invoke$2(method, editor.uid, ...args);
6303
6397
  return result;
6304
6398
  };
6305
6399
 
@@ -6332,7 +6426,7 @@ const listen$5 = async () => {
6332
6426
  _ipc = ipc;
6333
6427
  };
6334
6428
  const invoke = async (method, ...args) => {
6335
- return invoke$4(_ipc, method, ...args);
6429
+ return invoke$5(_ipc, method, ...args);
6336
6430
  };
6337
6431
 
6338
6432
  const measureTextBlockHeight = (text, fontFamily, fontSize, lineHeight, width) => {
@@ -6474,7 +6568,7 @@ const getHoverPositionXy = (editor, rowIndex, wordStart, documentationHeight) =>
6474
6568
  };
6475
6569
  const getEditorHoverInfo = async (editorUid, position) => {
6476
6570
  number$1(editorUid);
6477
- const instance = get$5(editorUid);
6571
+ const instance = get$6(editorUid);
6478
6572
  const editor = instance.newState;
6479
6573
  const {
6480
6574
  selections
@@ -6524,9 +6618,13 @@ const handleBeforeInput = (editor, inputType, data) => {
6524
6618
  }
6525
6619
  };
6526
6620
 
6527
- const intialize = async () => {
6621
+ const intialize = async syntaxHighlightingEnabled => {
6528
6622
  await listen$5();
6529
- await listen$6();
6623
+ if (syntaxHighlightingEnabled) {
6624
+ setEnabled(true);
6625
+ await listen$6();
6626
+ }
6627
+ await listen$7();
6530
6628
  };
6531
6629
 
6532
6630
  // TODO move cursor
@@ -6785,6 +6883,15 @@ const getTokensViewport = (editor, startLineIndex, endLineIndex) => {
6785
6883
  };
6786
6884
  };
6787
6885
 
6886
+ // TODO only send changed lines to renderer process instead of all lines in viewport
6887
+ const getTokensViewport2 = (editor, startLineIndex, endLineIndex) => {
6888
+ if (getEnabled()) {
6889
+ // TODO only send needed lines of text
6890
+ return invoke$1('GetTokensViewport.getTokensViewport', editor, startLineIndex, endLineIndex);
6891
+ }
6892
+ return getTokensViewport(editor, startLineIndex, endLineIndex);
6893
+ };
6894
+
6788
6895
  const loadTokenizers = async languageIds => {
6789
6896
  for (const languageId of languageIds) {
6790
6897
  // @ts-ignore
@@ -6970,13 +7077,10 @@ const getLineInfosViewport = (editor, tokens, embeddedResults, minLineY, maxLine
6970
7077
  const differences = [];
6971
7078
  const {
6972
7079
  lines,
6973
- tokenizerId,
6974
- decorations
7080
+ decorations,
7081
+ languageId
6975
7082
  } = editor;
6976
- const tokenizer = get(tokenizerId);
6977
- const {
6978
- TokenMap
6979
- } = tokenizer;
7083
+ const tokenMap = get$1(languageId);
6980
7084
  let offset = minLineOffset;
6981
7085
  const tabSize = 2;
6982
7086
  for (let i = minLineY; i < maxLineY; i++) {
@@ -6985,7 +7089,7 @@ const getLineInfosViewport = (editor, tokens, embeddedResults, minLineY, maxLine
6985
7089
  const {
6986
7090
  lineInfo,
6987
7091
  difference
6988
- } = getLineInfo(line, tokens[i - minLineY], embeddedResults, decorations, TokenMap, offset, normalize, tabSize, width, deltaX, averageCharWidth);
7092
+ } = getLineInfo(line, tokens[i - minLineY], embeddedResults, decorations, tokenMap, offset, normalize, tabSize, width, deltaX, averageCharWidth);
6989
7093
  result.push(lineInfo);
6990
7094
  differences.push(difference);
6991
7095
  offset += line.length + 1;
@@ -6995,7 +7099,7 @@ const getLineInfosViewport = (editor, tokens, embeddedResults, minLineY, maxLine
6995
7099
  differences
6996
7100
  };
6997
7101
  };
6998
- const getVisible = editor => {
7102
+ const getVisible = async editor => {
6999
7103
  // console.log({ editor })
7000
7104
  // TODO should separate rendering from business logic somehow
7001
7105
  // currently hard to test because need to mock editor height, top, left,
@@ -7019,7 +7123,7 @@ const getVisible = editor => {
7019
7123
  tokens,
7020
7124
  tokenizersToLoad,
7021
7125
  embeddedResults
7022
- } = getTokensViewport(editor, minLineY, maxLineY);
7126
+ } = await getTokensViewport2(editor, minLineY, maxLineY);
7023
7127
  const minLineOffset = offsetAtSync(editor, minLineY, 0);
7024
7128
  const averageCharWidth = charWidth;
7025
7129
  const {
@@ -7214,7 +7318,7 @@ const renderLines = {
7214
7318
  isEqual(oldState, newState) {
7215
7319
  return oldState.lines === newState.lines && oldState.tokenizerId === newState.tokenizerId && oldState.minLineY === newState.minLineY && oldState.decorations === newState.decorations && oldState.embeds === newState.embeds && oldState.deltaX === newState.deltaX && oldState.width === newState.width;
7216
7320
  },
7217
- apply(oldState, newState) {
7321
+ async apply(oldState, newState) {
7218
7322
  const incrementalEdits = getIncrementalEdits(oldState, newState);
7219
7323
  if (incrementalEdits) {
7220
7324
  return [/* method */'setIncrementalEdits', /* incrementalEdits */incrementalEdits];
@@ -7222,7 +7326,7 @@ const renderLines = {
7222
7326
  const {
7223
7327
  textInfos,
7224
7328
  differences
7225
- } = getVisible(newState);
7329
+ } = await getVisible(newState);
7226
7330
  newState.differences = differences;
7227
7331
  const dom = getEditorRowsVirtualDom(textInfos, differences);
7228
7332
  return [/* method */'setText', dom];
@@ -7301,8 +7405,8 @@ const renderGutterInfo = {
7301
7405
  }
7302
7406
  };
7303
7407
  const render = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus, renderDecorations, renderGutterInfo];
7304
- const renderEditor = id => {
7305
- const instance = get$5(id);
7408
+ const renderEditor = async id => {
7409
+ const instance = get$6(id);
7306
7410
  if (!instance) {
7307
7411
  return [];
7308
7412
  }
@@ -7313,10 +7417,10 @@ const renderEditor = id => {
7313
7417
  const commands = [];
7314
7418
  for (const item of render) {
7315
7419
  if (!item.isEqual(oldState, newState)) {
7316
- commands.push(item.apply(oldState, newState));
7420
+ commands.push(await item.apply(oldState, newState));
7317
7421
  }
7318
7422
  }
7319
- set$5(id, newState, newState);
7423
+ set$6(id, newState, newState);
7320
7424
  return commands;
7321
7425
  };
7322
7426
 
@@ -7325,10 +7429,11 @@ const keep = ['ColorPicker.handleSliderPointerDown', 'ColorPicker.handleSliderPo
7325
7429
  // TODO wrap commands globally, not per editor
7326
7430
  // TODO only store editor state in editor worker, not in renderer worker also
7327
7431
  const wrapCommand = fn => async (editorUid, ...args) => {
7328
- const oldInstance = get$5(editorUid);
7432
+ const oldInstance = get$6(editorUid);
7329
7433
  const newEditor = await fn(oldInstance.newState, ...args);
7330
- set$5(editorUid, oldInstance.newState, newEditor);
7331
- const commands = renderEditor(editorUid);
7434
+ set$6(editorUid, oldInstance.newState, newEditor);
7435
+ // TODO if possible, rendering should be sync
7436
+ const commands = await renderEditor(editorUid);
7332
7437
  newEditor.commands = commands;
7333
7438
  return newEditor;
7334
7439
  };
@@ -7899,7 +8004,7 @@ const listen = async () => {
7899
8004
  method: Auto()
7900
8005
  });
7901
8006
  handleIpc(ipc);
7902
- listen$7(ipc);
8007
+ listen$8(ipc);
7903
8008
  };
7904
8009
 
7905
8010
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "main": "dist/testWorkerMain.js",
6
6
  "type": "module",
@@ -49,5 +49,12 @@
49
49
  "ignores": [
50
50
  "distmin"
51
51
  ]
52
+ },
53
+ "nodemonConfig": {
54
+ "watch": [
55
+ "src"
56
+ ],
57
+ "ext": "ts,js",
58
+ "exec": "node scripts/build.js"
52
59
  }
53
60
  }