@theia/plugin-ext 1.71.0-next.72 → 1.71.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.
Files changed (35) hide show
  1. package/lib/common/plugin-api-rpc.d.ts +71 -0
  2. package/lib/common/plugin-api-rpc.d.ts.map +1 -1
  3. package/lib/common/plugin-api-rpc.js +8 -1
  4. package/lib/common/plugin-api-rpc.js.map +1 -1
  5. package/lib/main/browser/menus/menus-contribution-handler.d.ts.map +1 -1
  6. package/lib/main/browser/menus/menus-contribution-handler.js +2 -0
  7. package/lib/main/browser/menus/menus-contribution-handler.js.map +1 -1
  8. package/lib/main/browser/menus/plugin-menu-command-adapter.d.ts +1 -0
  9. package/lib/main/browser/menus/plugin-menu-command-adapter.d.ts.map +1 -1
  10. package/lib/main/browser/menus/plugin-menu-command-adapter.js +12 -0
  11. package/lib/main/browser/menus/plugin-menu-command-adapter.js.map +1 -1
  12. package/lib/main/browser/menus/vscode-theia-menu-mappings.d.ts +1 -1
  13. package/lib/main/browser/menus/vscode-theia-menu-mappings.d.ts.map +1 -1
  14. package/lib/main/browser/menus/vscode-theia-menu-mappings.js +7 -0
  15. package/lib/main/browser/menus/vscode-theia-menu-mappings.js.map +1 -1
  16. package/lib/main/browser/scm-main.d.ts +33 -2
  17. package/lib/main/browser/scm-main.d.ts.map +1 -1
  18. package/lib/main/browser/scm-main.js +213 -2
  19. package/lib/main/browser/scm-main.js.map +1 -1
  20. package/lib/plugin/scm.d.ts +7 -1
  21. package/lib/plugin/scm.d.ts.map +1 -1
  22. package/lib/plugin/scm.js +165 -0
  23. package/lib/plugin/scm.js.map +1 -1
  24. package/lib/plugin/scm.spec.d.ts +2 -0
  25. package/lib/plugin/scm.spec.d.ts.map +1 -0
  26. package/lib/plugin/scm.spec.js +461 -0
  27. package/lib/plugin/scm.spec.js.map +1 -0
  28. package/package.json +30 -30
  29. package/src/common/plugin-api-rpc.ts +72 -0
  30. package/src/main/browser/menus/menus-contribution-handler.ts +2 -0
  31. package/src/main/browser/menus/plugin-menu-command-adapter.ts +14 -1
  32. package/src/main/browser/menus/vscode-theia-menu-mappings.ts +9 -0
  33. package/src/main/browser/scm-main.ts +247 -3
  34. package/src/plugin/scm.spec.ts +615 -0
  35. package/src/plugin/scm.ts +198 -2
package/src/plugin/scm.ts CHANGED
@@ -28,16 +28,22 @@ import {
28
28
  ScmMain, ScmRawResource, ScmRawResourceGroup,
29
29
  ScmRawResourceSplice, ScmRawResourceSplices,
30
30
  SourceControlGroupFeatures,
31
- ScmActionButton
31
+ ScmActionButton,
32
+ ScmHistoryItemRefDto,
33
+ ScmHistoryItemDto,
34
+ ScmHistoryItemChangeDto,
35
+ ScmHistoryOptionsDto,
36
+ ScmHistoryItemRefsChangeEventDto
32
37
  } from '../common';
33
38
  import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
39
+ import { CancellationToken } from '@theia/core/lib/common/cancellation';
34
40
  import { CommandRegistryImpl } from '../plugin/command-registry';
35
41
  import { Splice } from '../common/arrays';
36
42
  import { UriComponents } from '../common/uri-components';
37
43
  import { Command } from '../common/plugin-api-rpc-model';
38
44
  import { RPCProtocol } from '../common/rpc-protocol';
39
45
  import { URI, ThemeIcon } from './types-impl';
40
- import { ScmCommandArg } from '../common/plugin-api-rpc';
46
+ import { ScmCommandArg, ScmHistoryItemCommandArg } from '../common/plugin-api-rpc';
41
47
  import { sep } from '@theia/core/lib/common/paths';
42
48
  import { PluginIconPath } from './plugin-icon-path';
43
49
  import { createAPIObject } from './plugin-context';
@@ -538,6 +544,47 @@ class ScmResourceGroupImpl implements theia.SourceControlResourceGroup {
538
544
  }
539
545
  }
540
546
 
547
+ function historyItemRefToDto(ref: theia.SourceControlHistoryItemRef): ScmHistoryItemRefDto {
548
+ return {
549
+ id: ref.id,
550
+ name: ref.name,
551
+ description: ref.description,
552
+ revision: ref.revision,
553
+ icon: ref.icon,
554
+ category: ref.category,
555
+ };
556
+ }
557
+
558
+ function historyItemToDto(item: theia.SourceControlHistoryItem): ScmHistoryItemDto {
559
+ return {
560
+ id: item.id,
561
+ parentIds: item.parentIds ? [...item.parentIds] : undefined,
562
+ subject: item.subject,
563
+ message: item.message,
564
+ author: item.author,
565
+ authorEmail: item.authorEmail,
566
+ authorIcon: item.authorIcon,
567
+ displayId: item.displayId,
568
+ timestamp: item.timestamp,
569
+ tooltip: item.tooltip,
570
+ statistics: item.statistics ? {
571
+ files: item.statistics.files,
572
+ insertions: item.statistics.insertions,
573
+ deletions: item.statistics.deletions,
574
+ } : undefined,
575
+ references: item.references ? item.references.map(historyItemRefToDto) : undefined,
576
+ };
577
+ }
578
+
579
+ function historyItemChangeToDto(change: theia.SourceControlHistoryItemChange): ScmHistoryItemChangeDto {
580
+ return {
581
+ uri: change.uri,
582
+ originalUri: change.originalUri,
583
+ modifiedUri: change.modifiedUri,
584
+ renameUri: change.renameUri,
585
+ };
586
+ }
587
+
541
588
  class SourceControlImpl implements theia.SourceControl {
542
589
 
543
590
  private static handlePool: number = 0;
@@ -689,6 +736,53 @@ class SourceControlImpl implements theia.SourceControl {
689
736
  this.proxy.$updateSourceControl(this.handle, { contextValue });
690
737
  }
691
738
 
739
+ private _historyProvider: theia.SourceControlHistoryProvider | undefined = undefined;
740
+ private _historyProviderDisposables = new DisposableCollection();
741
+
742
+ readonly historyItems = new Map<string, theia.SourceControlHistoryItem>();
743
+ readonly historyItemRefs = new Map<string, theia.SourceControlHistoryItemRef>();
744
+
745
+ get historyProvider(): theia.SourceControlHistoryProvider | undefined {
746
+ return this._historyProvider;
747
+ }
748
+
749
+ set historyProvider(provider: theia.SourceControlHistoryProvider | undefined) {
750
+ this._historyProviderDisposables.dispose();
751
+ this._historyProviderDisposables = new DisposableCollection();
752
+ this._historyProvider = provider;
753
+
754
+ if (provider) {
755
+ this._historyProviderDisposables.push(
756
+ provider.onDidChangeCurrentHistoryItemRefs(() => {
757
+ this.proxy.$updateSourceControl(this.handle, {
758
+ hasHistoryProvider: true,
759
+ currentHistoryItemRef: provider.currentHistoryItemRef ? historyItemRefToDto(provider.currentHistoryItemRef) : undefined,
760
+ currentHistoryItemRemoteRef: provider.currentHistoryItemRemoteRef ? historyItemRefToDto(provider.currentHistoryItemRemoteRef) : undefined,
761
+ currentHistoryItemBaseRef: provider.currentHistoryItemBaseRef ? historyItemRefToDto(provider.currentHistoryItemBaseRef) : undefined,
762
+ });
763
+ this.proxy.$onDidChangeCurrentHistoryItemRefs(this.handle);
764
+ })
765
+ );
766
+ this._historyProviderDisposables.push(
767
+ provider.onDidChangeHistoryItemRefs(event => {
768
+ const dto: ScmHistoryItemRefsChangeEventDto = {
769
+ added: event.added.map(historyItemRefToDto),
770
+ removed: event.removed.map(historyItemRefToDto),
771
+ modified: event.modified.map(historyItemRefToDto),
772
+ };
773
+ this.proxy.$onDidChangeHistoryItemRefs(this.handle, dto);
774
+ })
775
+ );
776
+ }
777
+
778
+ this.proxy.$updateSourceControl(this.handle, {
779
+ hasHistoryProvider: !!provider,
780
+ currentHistoryItemRef: provider?.currentHistoryItemRef ? historyItemRefToDto(provider.currentHistoryItemRef) : undefined,
781
+ currentHistoryItemRemoteRef: provider?.currentHistoryItemRemoteRef ? historyItemRefToDto(provider.currentHistoryItemRemoteRef) : undefined,
782
+ currentHistoryItemBaseRef: provider?.currentHistoryItemBaseRef ? historyItemRefToDto(provider.currentHistoryItemBaseRef) : undefined,
783
+ });
784
+ }
785
+
692
786
  private readonly onDidDisposeEmitter = new Emitter<void>();
693
787
  readonly onDidDispose = this.onDidDisposeEmitter.event;
694
788
 
@@ -783,6 +877,14 @@ class SourceControlImpl implements theia.SourceControl {
783
877
  return this.groups.get(handle);
784
878
  }
785
879
 
880
+ getHistoryItem(id: string): theia.SourceControlHistoryItem | undefined {
881
+ return this.historyItems.get(id);
882
+ }
883
+
884
+ getHistoryItemRef(id: string): theia.SourceControlHistoryItemRef | undefined {
885
+ return this.historyItemRefs.get(id);
886
+ }
887
+
786
888
  setSelectionState(selected: boolean): void {
787
889
  this._selected = selected;
788
890
  this.onDidChangeSelectionEmitter.fire(selected);
@@ -792,6 +894,7 @@ class SourceControlImpl implements theia.SourceControl {
792
894
  this.acceptInputDisposables.dispose();
793
895
  this._statusBarDisposables.dispose();
794
896
  this._actionButtonDisposables.dispose();
897
+ this._historyProviderDisposables.dispose();
795
898
 
796
899
  this.groups.forEach(group => group.dispose());
797
900
  this.proxy.$unregisterSourceControl(this.handle);
@@ -817,6 +920,32 @@ export class ScmExtImpl implements ScmExt {
817
920
  constructor(rpc: RPCProtocol, private commands: CommandRegistryImpl) {
818
921
  this.proxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.SCM_MAIN);
819
922
 
923
+ // Register history item arg processor before the generic ScmCommandArg processor
924
+ // so the more-specific guard matches first.
925
+ commands.registerArgumentProcessor({
926
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
927
+ processArgument: (arg: any) => {
928
+ if (!ScmHistoryItemCommandArg.is(arg) || arg.type !== 'historyItem') {
929
+ return arg;
930
+ }
931
+ const sourceControl = this.sourceControls.get(arg.sourceControlHandle);
932
+ const item = sourceControl?.getHistoryItem(arg.id);
933
+ return item ?? { id: arg.id };
934
+ }
935
+ });
936
+
937
+ commands.registerArgumentProcessor({
938
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
939
+ processArgument: (arg: any) => {
940
+ if (!ScmHistoryItemCommandArg.is(arg) || arg.type !== 'historyItemRef') {
941
+ return arg;
942
+ }
943
+ const sourceControl = this.sourceControls.get(arg.sourceControlHandle);
944
+ const ref = sourceControl?.getHistoryItemRef(arg.id);
945
+ return ref ?? { id: arg.id };
946
+ }
947
+ });
948
+
820
949
  commands.registerArgumentProcessor({
821
950
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
822
951
  processArgument: (arg: any) => {
@@ -942,6 +1071,73 @@ export class ScmExtImpl implements ScmExt {
942
1071
  return [result.message, result.type];
943
1072
  }
944
1073
 
1074
+ async $provideHistoryItemRefs(sourceControlHandle: number, historyItemRefs: string[] | undefined, token: CancellationToken): Promise<ScmHistoryItemRefDto[] | undefined> {
1075
+ const sourceControl = this.sourceControls.get(sourceControlHandle);
1076
+ if (!sourceControl || !sourceControl.historyProvider) {
1077
+ return undefined;
1078
+ }
1079
+ const result = await sourceControl.historyProvider.provideHistoryItemRefs(historyItemRefs, token);
1080
+ if (!result) {
1081
+ return undefined;
1082
+ }
1083
+ sourceControl.historyItemRefs.clear();
1084
+ for (const ref of result) {
1085
+ sourceControl.historyItemRefs.set(ref.id, ref);
1086
+ }
1087
+ return result.map(historyItemRefToDto);
1088
+ }
1089
+
1090
+ async $provideHistoryItems(sourceControlHandle: number, options: ScmHistoryOptionsDto, token: CancellationToken): Promise<ScmHistoryItemDto[] | undefined> {
1091
+ const sourceControl = this.sourceControls.get(sourceControlHandle);
1092
+ if (!sourceControl || !sourceControl.historyProvider) {
1093
+ return undefined;
1094
+ }
1095
+ const result = await sourceControl.historyProvider.provideHistoryItems(options, token);
1096
+ if (!result) {
1097
+ return undefined;
1098
+ }
1099
+ for (const item of result) {
1100
+ sourceControl.historyItems.set(item.id, item);
1101
+ }
1102
+ return result.map(historyItemToDto);
1103
+ }
1104
+
1105
+ async $provideHistoryItemChanges(
1106
+ sourceControlHandle: number, historyItemId: string,
1107
+ historyItemParentId: string | undefined, token: CancellationToken
1108
+ ): Promise<ScmHistoryItemChangeDto[] | undefined> {
1109
+ const sourceControl = this.sourceControls.get(sourceControlHandle);
1110
+ if (!sourceControl || !sourceControl.historyProvider) {
1111
+ return undefined;
1112
+ }
1113
+ const result = await sourceControl.historyProvider.provideHistoryItemChanges(historyItemId, historyItemParentId, token);
1114
+ if (!result) {
1115
+ return undefined;
1116
+ }
1117
+ return result.map(historyItemChangeToDto);
1118
+ }
1119
+
1120
+ async $resolveHistoryItem(sourceControlHandle: number, historyItemId: string, token: CancellationToken): Promise<ScmHistoryItemDto | undefined> {
1121
+ const sourceControl = this.sourceControls.get(sourceControlHandle);
1122
+ if (!sourceControl || !sourceControl.historyProvider) {
1123
+ return undefined;
1124
+ }
1125
+ const result = await sourceControl.historyProvider.resolveHistoryItem(historyItemId, token);
1126
+ if (!result) {
1127
+ return undefined;
1128
+ }
1129
+ return historyItemToDto(result);
1130
+ }
1131
+
1132
+ async $resolveHistoryItemRefsCommonAncestor(sourceControlHandle: number, historyItemRefs: string[], token: CancellationToken): Promise<string | undefined> {
1133
+ const sourceControl = this.sourceControls.get(sourceControlHandle);
1134
+ if (!sourceControl || !sourceControl.historyProvider) {
1135
+ return undefined;
1136
+ }
1137
+ const result = await sourceControl.historyProvider.resolveHistoryItemRefsCommonAncestor(historyItemRefs, token);
1138
+ return result ?? undefined;
1139
+ }
1140
+
945
1141
  $setSelectedSourceControl(selectedSourceControlHandle: number | undefined): Promise<void> {
946
1142
  if (selectedSourceControlHandle !== undefined) {
947
1143
  this.sourceControls.get(selectedSourceControlHandle)?.setSelectionState(true);