@lvce-editor/editor-worker 4.5.0 → 4.7.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.
@@ -1736,6 +1736,7 @@ const {
1736
1736
  const CompletionExecute = 'ExtensionHostCompletion.execute';
1737
1737
  const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
1738
1738
  const HoverExecute = 'ExtensionHostHover.execute';
1739
+ const RenameExecuteRename = 'ExtensionHostRename.executeRenameProvider';
1739
1740
  const TabCompletionExecuteTabCompletionProvider = 'ExtensionHost.executeTabCompletionProvider';
1740
1741
  const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
1741
1742
 
@@ -2273,6 +2274,21 @@ const cancelSelection = editor => {
2273
2274
  return scheduleSelections(editor, newSelections);
2274
2275
  };
2275
2276
 
2277
+ const getIndex = (widgets, id) => {
2278
+ for (let i = 0; i < widgets.length; i++) {
2279
+ const widget = widgets[i];
2280
+ if (widget.id === id) {
2281
+ return i;
2282
+ }
2283
+ }
2284
+ return -1;
2285
+ };
2286
+ const removeEditorWidget = (widgets, id) => {
2287
+ const index = getIndex(widgets, id);
2288
+ const newWidgets = [...widgets.slice(0, index), ...widgets.slice(index + 1)];
2289
+ return newWidgets;
2290
+ };
2291
+
2276
2292
  // TODO use numeric widget id
2277
2293
  const ColorPicker$1 = 'colorPicker';
2278
2294
  const Completion = 'completion';
@@ -2293,7 +2309,7 @@ const closeCompletion = editor => {
2293
2309
  if (completionWidgetIndex === -1) {
2294
2310
  return editor;
2295
2311
  }
2296
- const newWidgets = [...widgets.slice(0, completionWidgetIndex), ...widgets.slice(completionWidgetIndex + 1)];
2312
+ const newWidgets = removeEditorWidget(widgets, Completion);
2297
2313
  return {
2298
2314
  ...editor,
2299
2315
  widgets: newWidgets
@@ -2311,7 +2327,7 @@ const closeFind = editor => {
2311
2327
  if (index === -1) {
2312
2328
  return editor;
2313
2329
  }
2314
- const newWidgets = [...widgets.slice(0, index), ...widgets.slice(index + 1)];
2330
+ const newWidgets = removeEditorWidget(widgets, Find);
2315
2331
  return {
2316
2332
  ...editor,
2317
2333
  widgets: newWidgets
@@ -2330,7 +2346,7 @@ const closeRename = editor => {
2330
2346
  if (renameWidgetIndex === -1) {
2331
2347
  return editor;
2332
2348
  }
2333
- const newWidgets = [...widgets.slice(0, renameWidgetIndex), ...widgets.slice(renameWidgetIndex + 1)];
2349
+ const newWidgets = removeEditorWidget(widgets, Rename);
2334
2350
  return {
2335
2351
  ...editor,
2336
2352
  focused: true,
@@ -2349,7 +2365,7 @@ const closeSourceAction = editor => {
2349
2365
  if (index === -1) {
2350
2366
  return editor;
2351
2367
  }
2352
- const newWidgets = [...widgets.slice(0, index), ...widgets.slice(index + 1)];
2368
+ const newWidgets = removeEditorWidget(widgets, SourceAction);
2353
2369
  return {
2354
2370
  ...editor,
2355
2371
  widgets: newWidgets
@@ -3341,7 +3357,8 @@ const UiStrings$1 = {
3341
3357
  Replace: 'Replace',
3342
3358
  SourceAction: 'Source Action',
3343
3359
  OrganizeImports: 'Organize Imports',
3344
- SortImports: 'Sort Imports'
3360
+ SortImports: 'Sort Imports',
3361
+ NoCodeActionsAvailable: 'No code actions available'
3345
3362
  };
3346
3363
  const noDefinitionFound = () => {
3347
3364
  return i18nString(UiStrings$1.NoDefinitionFound);
@@ -3365,6 +3382,9 @@ const noResults$1 = () => {
3365
3382
  const sourceAction = () => {
3366
3383
  return i18nString(UiStrings$1.SourceAction);
3367
3384
  };
3385
+ const noCodeActionsAvailable = () => {
3386
+ return i18nString(UiStrings$1.NoCodeActionsAvailable);
3387
+ };
3368
3388
 
3369
3389
  // @ts-ignore
3370
3390
  const goTo = async ({
@@ -4546,6 +4566,7 @@ const create$5 = () => {
4546
4566
  return completionWidget;
4547
4567
  };
4548
4568
 
4569
+ const OnRename = 'onRename';
4549
4570
  const OnCompletion = 'onCompletion';
4550
4571
  const OnHover = 'onHover';
4551
4572
  const OnTabCompletion = 'onTabCompletion';
@@ -4569,7 +4590,7 @@ const execute = async ({
4569
4590
  return result;
4570
4591
  };
4571
4592
 
4572
- const combineResults$1 = results => {
4593
+ const combineResults$2 = results => {
4573
4594
  return results[0] ?? [];
4574
4595
  };
4575
4596
  const executeCompletionProvider = (editor, offset) => {
@@ -4580,7 +4601,7 @@ const executeCompletionProvider = (editor, offset) => {
4580
4601
  args: [offset],
4581
4602
  noProviderFoundMessage: 'no completion provider found',
4582
4603
  noProviderFoundResult: [],
4583
- combineResults: combineResults$1
4604
+ combineResults: combineResults$2
4584
4605
  });
4585
4606
  };
4586
4607
  const combineResultsResolve = items => {
@@ -6704,12 +6725,19 @@ const getEditorSourceActions = async () => {
6704
6725
  return sourceActions;
6705
6726
  };
6706
6727
 
6707
- const getSourceActionWidgetPosition = editor => {
6728
+ const getHeight = sourceActionCount => {
6729
+ if (sourceActionCount === 0) {
6730
+ return 45;
6731
+ }
6732
+ return 150;
6733
+ };
6734
+ const getSourceActionWidgetPosition = (editor, sourceActionCount) => {
6708
6735
  const width = 300;
6709
- const height = 150;
6736
+ const height = getHeight(sourceActionCount);
6710
6737
  const cursor = getPositionAtCursor(editor);
6711
6738
  const x = cursor.x;
6712
6739
  const y = cursor.y;
6740
+ // TODO support virtual list
6713
6741
  return {
6714
6742
  x,
6715
6743
  y,
@@ -6728,7 +6756,7 @@ const loadSourceActions = async (editor, state) => {
6728
6756
  y,
6729
6757
  width,
6730
6758
  height
6731
- } = getSourceActionWidgetPosition(editor);
6759
+ } = getSourceActionWidgetPosition(editor, sourceActions.length);
6732
6760
  return {
6733
6761
  ...state,
6734
6762
  sourceActions,
@@ -6835,7 +6863,7 @@ const sortLinesAscending = editor => {
6835
6863
  return scheduleDocumentAndCursorsSelections(editor, changes);
6836
6864
  };
6837
6865
 
6838
- const combineResults = results => {
6866
+ const combineResults$1 = results => {
6839
6867
  return results[0];
6840
6868
  };
6841
6869
  const executeTabCompletionProvider = (editor, offset) => {
@@ -6845,7 +6873,7 @@ const executeTabCompletionProvider = (editor, offset) => {
6845
6873
  method: TabCompletionExecuteTabCompletionProvider,
6846
6874
  args: [offset],
6847
6875
  noProviderFoundMessage: 'No tab completion provider found',
6848
- combineResults,
6876
+ combineResults: combineResults$1,
6849
6877
  noProviderFoundResult: undefined
6850
6878
  });
6851
6879
  };
@@ -7727,9 +7755,6 @@ const getEdits = async (editor, completionItem) => {
7727
7755
  const changes = replaceRange(editor, replaceRange$1, [inserted], '');
7728
7756
  return changes;
7729
7757
  };
7730
- const isCompletion = widget => {
7731
- return widget.id === Completion;
7732
- };
7733
7758
  const select = async (editor, completionItem) => {
7734
7759
  const changes = await getEdits(editor, completionItem);
7735
7760
  const index = editor.widgets.indexOf
@@ -7746,8 +7771,7 @@ const select = async (editor, completionItem) => {
7746
7771
  const {
7747
7772
  widgets
7748
7773
  } = editor;
7749
- const completionWidgetIndex = editor.widgets.findIndex(isCompletion);
7750
- const newWidgets = [...widgets.slice(0, completionWidgetIndex), ...widgets.slice(completionWidgetIndex + 1)];
7774
+ const newWidgets = removeEditorWidget(widgets, Completion);
7751
7775
  const intermediateEditor = await applyEdit(editor, changes);
7752
7776
  return {
7753
7777
  ...intermediateEditor,
@@ -7848,6 +7872,7 @@ const ColorPickerSliderThumb = 'ColorPickerSliderThumb';
7848
7872
  const SourceActionItem = 'SourceActionItem';
7849
7873
  const SourceActionItemFocused = 'SourceActionItemFocused';
7850
7874
  const CompletionDetailCloseButton = 'CompletionDetailCloseButton';
7875
+ const EditorSourceActionsList = 'EditorSourceActionsList';
7851
7876
  const IconButtonDisabled = 'IconButtonDisabled';
7852
7877
  const IconButton = 'IconButton';
7853
7878
  const SourceActionHeading = 'SourceActionHeading';
@@ -8021,6 +8046,50 @@ const renderHover = (oldState, newState) => {
8021
8046
  return commands;
8022
8047
  };
8023
8048
 
8049
+ const combineResults = results => {
8050
+ return results[0] ?? [];
8051
+ };
8052
+ const executeRenameProvider = (editor, offset, newName) => {
8053
+ return execute({
8054
+ editor,
8055
+ event: OnRename,
8056
+ method: RenameExecuteRename,
8057
+ args: [offset, newName],
8058
+ noProviderFoundMessage: 'no rename provider found',
8059
+ noProviderFoundResult: [],
8060
+ combineResults
8061
+ });
8062
+ };
8063
+
8064
+ const getRenameState = editor => {
8065
+ return getWidgetState(editor, Rename);
8066
+ };
8067
+
8068
+ const accept = async editor => {
8069
+ const child = getRenameState(editor);
8070
+ if (!child) {
8071
+ return editor;
8072
+ }
8073
+ const {
8074
+ widgets
8075
+ } = editor;
8076
+ const newWidgets = removeEditorWidget(widgets, Rename);
8077
+ // TODO
8078
+ const offset = getOffsetAtCursor(editor);
8079
+ const result = await executeRenameProvider(editor, offset, child.newValue);
8080
+ console.log({
8081
+ result
8082
+ });
8083
+ // 1. ask extension host for rename edits
8084
+ // 2. apply rename edit across editor (and whole workspace)
8085
+ // 3. close rename widget
8086
+ return {
8087
+ ...editor,
8088
+ focused: true,
8089
+ widgets: newWidgets
8090
+ };
8091
+ };
8092
+
8024
8093
  const handleBlur = editor => {
8025
8094
  return closeRename(editor);
8026
8095
  };
@@ -9297,6 +9366,7 @@ const commandMap = {
9297
9366
  'EditorCompletion.selectCurrent': selectCurrent,
9298
9367
  'EditorCompletion.selectIndex': selectIndex,
9299
9368
  'EditorCompletion.toggleDetails': toggleDetails,
9369
+ 'EditorRename.accept': accept,
9300
9370
  'EditorRename.handleBlur': handleBlur,
9301
9371
  'EditorSourceActions.focusNext': focusNext,
9302
9372
  'FindWidget.close': close$1,
@@ -10942,7 +11012,32 @@ const getSourceActionListItemVirtualDom = sourceAction => {
10942
11012
  }, text(name)];
10943
11013
  };
10944
11014
 
11015
+ const getEditorMessageVirtualDom = message => {
11016
+ const dom = [{
11017
+ type: Div,
11018
+ className: 'Viewlet EditorMessage',
11019
+ tabIndex: -1,
11020
+ childCount: 2
11021
+ }, {
11022
+ type: Div,
11023
+ className: 'EditorMessageText',
11024
+ childCount: 1
11025
+ }, text(message), {
11026
+ type: Div,
11027
+ className: 'EditorMessageTriangle',
11028
+ childCount: 0
11029
+ }];
11030
+ return dom;
11031
+ };
11032
+
11033
+ const getEmptySourceActionsVirtualDom = () => {
11034
+ return getEditorMessageVirtualDom(noCodeActionsAvailable());
11035
+ };
11036
+
10945
11037
  const getSourceActionsVirtualDom = sourceActions => {
11038
+ if (sourceActions.length === 0) {
11039
+ return getEmptySourceActionsVirtualDom();
11040
+ }
10946
11041
  const dom = [{
10947
11042
  type: Div,
10948
11043
  className: 'Viewlet EditorSourceActions',
@@ -10955,7 +11050,7 @@ const getSourceActionsVirtualDom = sourceActions => {
10955
11050
  childCount: 1
10956
11051
  }, text(sourceAction()), {
10957
11052
  type: Div,
10958
- className: 'EditorSourceActionsList',
11053
+ className: EditorSourceActionsList,
10959
11054
  childCount: sourceActions.length,
10960
11055
  onClick: HandleClick
10961
11056
  }, ...sourceActions.flatMap(getSourceActionListItemVirtualDom)];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "4.5.0",
3
+ "version": "4.7.0",
4
4
  "description": "",
5
5
  "main": "dist/editorWorkerMain.js",
6
6
  "type": "module",