@codingame/monaco-vscode-notebook-service-override 13.1.7 → 14.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.
Files changed (100) hide show
  1. package/index.js +3 -3
  2. package/package.json +29 -28
  3. package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.js +8 -8
  4. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/cellCommands.js +25 -24
  5. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticEditorContrib.d.ts +1 -1
  6. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticEditorContrib.js +2 -2
  7. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticsActions.js +6 -6
  8. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/diagnosticCellStatusBarContrib.d.ts +1 -1
  9. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/diagnosticCellStatusBarContrib.js +2 -2
  10. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/contributedStatusBarItemController.d.ts +1 -1
  11. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/contributedStatusBarItemController.js +1 -1
  12. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/statusBarProviders.js +4 -4
  13. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookCellDecorators.d.ts +60 -0
  14. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookCellDecorators.js +536 -0
  15. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookChatActionsOverlay.d.ts +24 -0
  16. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookChatActionsOverlay.js +310 -0
  17. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookChatEditController.d.ts +9 -0
  18. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookChatEditController.js +182 -0
  19. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookOriginalCellModelFactory.d.ts +21 -0
  20. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookOriginalCellModelFactory.js +42 -0
  21. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookOriginalModelRefFactory.d.ts +23 -0
  22. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookOriginalModelRefFactory.js +72 -0
  23. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookSynchronizer.d.ts +62 -0
  24. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookSynchronizer.js +425 -0
  25. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookSynchronizerService.d.ts +1 -1
  26. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookSynchronizerService.js +0 -1
  27. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.d.ts +2 -2
  28. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.js +9 -9
  29. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookBreakpoints.js +1 -1
  30. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookDebugDecorations.d.ts +1 -1
  31. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookDebugDecorations.js +3 -3
  32. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint.js +1 -1
  33. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.js +11 -11
  34. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/execute/executionEditorProgress.d.ts +1 -1
  35. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/execute/executionEditorProgress.js +1 -1
  36. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFind.js +5 -5
  37. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.js +6 -6
  38. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/gettingStarted/notebookGettingStarted.js +4 -4
  39. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/layout/layoutActions.js +1 -1
  40. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider.js +2 -2
  41. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/multicursor/notebookMulticursor.d.ts +1 -1
  42. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/multicursor/notebookMulticursor.js +9 -9
  43. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/multicursor/notebookSelectionHighlight.js +2 -1
  44. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.js +15 -15
  45. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookInlineVariables.d.ts +29 -0
  46. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookInlineVariables.js +310 -0
  47. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.js +2 -2
  48. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesDataSource.js +1 -1
  49. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesTree.js +2 -2
  50. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.js +4 -4
  51. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.d.ts +4 -3
  52. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.js +35 -25
  53. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.js +1 -1
  54. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants.js +14 -14
  55. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout.d.ts +1 -1
  56. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout.js +5 -5
  57. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/undoRedo/notebookUndoRedo.js +1 -1
  58. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/viewportWarmup/viewportWarmup.js +3 -3
  59. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/cellChatActions.d.ts +1 -1
  60. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/cellChatActions.js +32 -32
  61. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/notebook.chat.contribution.js +3 -3
  62. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/editActions.js +29 -26
  63. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/executeActions.js +25 -25
  64. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.js +25 -25
  65. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/layoutActions.js +19 -19
  66. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/notebookIndentationActions.js +8 -8
  67. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/sectionActions.d.ts +1 -1
  68. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/sectionActions.js +14 -14
  69. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/variablesActions.js +2 -2
  70. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.js +21 -21
  71. package/vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.js +92 -74
  72. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibilityHelp.d.ts +2 -2
  73. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibilityHelp.js +11 -11
  74. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibleView.d.ts +2 -2
  75. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibleView.js +2 -2
  76. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.js +33 -33
  77. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.d.ts +2 -2
  78. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.js +2 -2
  79. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.d.ts +1 -1
  80. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.js +1 -1
  81. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl.d.ts +1 -1
  82. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl.js +1 -1
  83. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl.js +1 -1
  84. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKeymapServiceImpl.js +4 -4
  85. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookLoggingServiceImpl.js +2 -1
  86. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.d.ts +3 -3
  87. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.js +5 -5
  88. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineEntryFactory.d.ts +1 -1
  89. package/vscode/src/vs/workbench/contrib/notebook/common/model/cellEdit.d.ts +1 -1
  90. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.d.ts +1 -1
  91. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.js +3 -3
  92. package/vscode/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.js +1 -1
  93. package/vscode/src/vs/workbench/services/workingCopy/common/abstractFileWorkingCopyManager.d.ts +1 -1
  94. package/vscode/src/vs/workbench/services/workingCopy/common/fileWorkingCopyManager.d.ts +1 -1
  95. package/vscode/src/vs/workbench/services/workingCopy/common/fileWorkingCopyManager.js +16 -13
  96. package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopyManager.js +5 -3
  97. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopy.d.ts +2 -2
  98. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopy.js +2 -2
  99. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopyManager.d.ts +9 -0
  100. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopyManager.js +5 -0
@@ -0,0 +1,72 @@
1
+
2
+ import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
+ import { ReferenceCollection, AsyncReferenceCollection } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
4
+ import { INotebookService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookService.service';
5
+ import { VSBuffer, bufferToStream } from '@codingame/monaco-vscode-api/vscode/vs/base/common/buffer';
6
+ import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
7
+
8
+ let OriginalNotebookModelReferenceCollection = class OriginalNotebookModelReferenceCollection extends ReferenceCollection {
9
+ constructor(notebookService) {
10
+ super();
11
+ this.notebookService = notebookService;
12
+ this.modelsToDispose = ( new Set());
13
+ }
14
+ async createReferencedObject(key, fileEntry, viewType) {
15
+ this.modelsToDispose.delete(key);
16
+ const uri = fileEntry.originalURI;
17
+ const model = this.notebookService.getNotebookTextModel(uri);
18
+ if (model) {
19
+ return model;
20
+ }
21
+ const bytes = VSBuffer.fromString(fileEntry.originalModel.getValue());
22
+ const stream = bufferToStream(bytes);
23
+ return this.notebookService.createNotebookTextModel(viewType, uri, stream);
24
+ }
25
+ destroyReferencedObject(key, modelPromise) {
26
+ this.modelsToDispose.add(key);
27
+ (async () => {
28
+ try {
29
+ const model = await modelPromise;
30
+ if (!( this.modelsToDispose.has(key))) {
31
+ return;
32
+ }
33
+ model.dispose();
34
+ }
35
+ catch (error) {
36
+ }
37
+ finally {
38
+ this.modelsToDispose.delete(key);
39
+ }
40
+ })();
41
+ }
42
+ };
43
+ OriginalNotebookModelReferenceCollection = ( __decorate([
44
+ ( __param(0, INotebookService))
45
+ ], OriginalNotebookModelReferenceCollection));
46
+ let NotebookOriginalModelReferenceFactory = class NotebookOriginalModelReferenceFactory {
47
+ get resourceModelCollection() {
48
+ if (!this._resourceModelCollection) {
49
+ this._resourceModelCollection = this.instantiationService.createInstance(OriginalNotebookModelReferenceCollection);
50
+ }
51
+ return this._resourceModelCollection;
52
+ }
53
+ get asyncModelCollection() {
54
+ if (!this._asyncModelCollection) {
55
+ this._asyncModelCollection = ( new AsyncReferenceCollection(this.resourceModelCollection));
56
+ }
57
+ return this._asyncModelCollection;
58
+ }
59
+ constructor(instantiationService) {
60
+ this.instantiationService = instantiationService;
61
+ this._resourceModelCollection = undefined;
62
+ this._asyncModelCollection = undefined;
63
+ }
64
+ getOrCreate(fileEntry, viewType) {
65
+ return this.asyncModelCollection.acquire(( fileEntry.originalURI.toString()), fileEntry, viewType);
66
+ }
67
+ };
68
+ NotebookOriginalModelReferenceFactory = ( __decorate([
69
+ ( __param(0, IInstantiationService))
70
+ ], NotebookOriginalModelReferenceFactory));
71
+
72
+ export { NotebookOriginalModelReferenceFactory, OriginalNotebookModelReferenceCollection };
@@ -0,0 +1,62 @@
1
+ import { Disposable, IReference } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
2
+ import { IChatEditingService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatEditingService.service";
3
+ import { INotebookService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookService.service";
4
+ import { NotebookTextModel } from "../../../common/model/notebookTextModel.js";
5
+ import { CellDiffInfo } from "@codingame/monaco-vscode-e4d0fd26-1b26-5583-b3f7-582e08d7b389-common/vscode/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel";
6
+ import { CancellationToken } from "@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation";
7
+ import { INotebookEditorWorkerService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/services/notebookWorkerService.service";
8
+ import { IConfigurationService } from "@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service";
9
+ import { INotebookLoggingService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookLoggingService.service";
10
+ import { INotebookEditorModelResolverService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookEditorModelResolverService.service";
11
+ import { IChatService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatService.service";
12
+ import { IInstantiationService } from "@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation";
13
+ import { INotebookOriginalModelReferenceFactory } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookOriginalModelRefFactory.service";
14
+ import { IObservable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/observable";
15
+ import { ITextModelService } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/services/resolverService";
16
+ import { INotebookEditorService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/services/notebookEditorService.service";
17
+ import { INotebookModelSynchronizerFactory } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookSynchronizer.service";
18
+ export declare class NotebookModelSynchronizerFactory implements INotebookModelSynchronizerFactory {
19
+ readonly _serviceBrand: undefined;
20
+ private readonly _data;
21
+ constructor(instantiationService: IInstantiationService);
22
+ getOrCreate(model: NotebookTextModel): IReference<NotebookModelSynchronizer>;
23
+ }
24
+ export declare class NotebookModelSynchronizer extends Disposable {
25
+ private readonly model;
26
+ private readonly notebookService;
27
+ private readonly notebookEditorService;
28
+ private readonly textModelService;
29
+ private readonly logService;
30
+ private readonly configurationService;
31
+ private readonly notebookEditorWorkerService;
32
+ private readonly notebookModelResolverService;
33
+ private readonly originalModelRefFactory;
34
+ private readonly throttledUpdateNotebookModel;
35
+ private _diffInfo;
36
+ get diffInfo(): IObservable<{
37
+ cellDiff: CellDiffInfo[];
38
+ modelVersion: number;
39
+ } | undefined>;
40
+ private snapshot?;
41
+ private isEditFromUs;
42
+ private isTextEditFromUs;
43
+ private isReverting;
44
+ private throttledTextModelUpdate;
45
+ constructor(model: NotebookTextModel, _chatEditingService: IChatEditingService, notebookService: INotebookService, notebookEditorService: INotebookEditorService, chatService: IChatService, textModelService: ITextModelService, logService: INotebookLoggingService, configurationService: IConfigurationService, notebookEditorWorkerService: INotebookEditorWorkerService, notebookModelResolverService: INotebookEditorModelResolverService, originalModelRefFactory: INotebookOriginalModelReferenceFactory);
46
+ private createSnapshot;
47
+ revert(): Promise<void>;
48
+ private revertImpl;
49
+ private updateNotebook;
50
+ private accept;
51
+ private updateTextDocumentModel;
52
+ getNotebookSerializer(): Promise<import("@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookService").INotebookSerializer>;
53
+ private _originalModel?;
54
+ private getOriginalModel;
55
+ private updateNotebookModel;
56
+ private previousUriOfModelForDiff?;
57
+ private getModifiedModelForDiff;
58
+ computeDiff(original: NotebookTextModel, modified: NotebookTextModel, token: CancellationToken): Promise<{
59
+ cellDiffInfo: CellDiffInfo[];
60
+ firstChangeIndex: number;
61
+ } | undefined>;
62
+ }
@@ -0,0 +1,425 @@
1
+
2
+ import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
3
+ import { isEqual } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
4
+ import { ReferenceCollection, Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
5
+ import { IChatEditingService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatEditingService.service';
6
+ import { INotebookService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookService.service';
7
+ import { VSBuffer, streamToBuffer, bufferToStream } from '@codingame/monaco-vscode-api/vscode/vs/base/common/buffer';
8
+ import { ThrottledDelayer, raceCancellation } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
9
+ import { prettyChanges, computeDiff } from '@codingame/monaco-vscode-e4d0fd26-1b26-5583-b3f7-582e08d7b389-common/vscode/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel';
10
+ import { CancellationTokenSource, CancellationToken } from '@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation';
11
+ import { INotebookEditorWorkerService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/services/notebookWorkerService.service';
12
+ import { NotebookSetting, CellEditType } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
13
+ import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service';
14
+ import { EditOperation } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/editOperation';
15
+ import { INotebookLoggingService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookLoggingService.service';
16
+ import { filter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/objects';
17
+ import { INotebookEditorModelResolverService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookEditorModelResolverService.service';
18
+ import { IChatService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatService.service';
19
+ import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
20
+ import { INotebookOriginalModelReferenceFactory } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookOriginalModelRefFactory.service';
21
+ import { observableValue } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/base';
22
+ import '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
23
+ import '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
24
+ import { autorunWithStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/autorun';
25
+ import { derived } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/derived';
26
+ import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/utils';
27
+ import { SaveReason } from '@codingame/monaco-vscode-api/vscode/vs/workbench/common/editor';
28
+ import { ITextModelService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/resolverService';
29
+ import { SnapshotContext } from '@codingame/monaco-vscode-99f24462-c56d-5407-83fb-2ea9dd33cc8c-common/vscode/vs/workbench/services/workingCopy/common/fileWorkingCopy';
30
+ import { INotebookEditorService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/services/notebookEditorService.service';
31
+ import { CellEditState } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
32
+
33
+ let NotebookModelSynchronizerReferenceCollection = class NotebookModelSynchronizerReferenceCollection extends ReferenceCollection {
34
+ constructor(instantiationService) {
35
+ super();
36
+ this.instantiationService = instantiationService;
37
+ }
38
+ createReferencedObject(_key, model) {
39
+ return this.instantiationService.createInstance(NotebookModelSynchronizer, model);
40
+ }
41
+ destroyReferencedObject(_key, object) {
42
+ object.dispose();
43
+ }
44
+ };
45
+ NotebookModelSynchronizerReferenceCollection = ( __decorate([
46
+ ( __param(0, IInstantiationService))
47
+ ], NotebookModelSynchronizerReferenceCollection));
48
+ let NotebookModelSynchronizerFactory = class NotebookModelSynchronizerFactory {
49
+ constructor(instantiationService) {
50
+ this._data = instantiationService.createInstance(NotebookModelSynchronizerReferenceCollection);
51
+ }
52
+ getOrCreate(model) {
53
+ return this._data.acquire(( model.uri.toString()), model);
54
+ }
55
+ };
56
+ NotebookModelSynchronizerFactory = ( __decorate([
57
+ ( __param(0, IInstantiationService))
58
+ ], NotebookModelSynchronizerFactory));
59
+ let NotebookModelSynchronizer = class NotebookModelSynchronizer extends Disposable {
60
+ get diffInfo() {
61
+ return this._diffInfo;
62
+ }
63
+ constructor(model, _chatEditingService, notebookService, notebookEditorService, chatService, textModelService, logService, configurationService, notebookEditorWorkerService, notebookModelResolverService, originalModelRefFactory) {
64
+ super();
65
+ this.model = model;
66
+ this.notebookService = notebookService;
67
+ this.notebookEditorService = notebookEditorService;
68
+ this.textModelService = textModelService;
69
+ this.logService = logService;
70
+ this.configurationService = configurationService;
71
+ this.notebookEditorWorkerService = notebookEditorWorkerService;
72
+ this.notebookModelResolverService = notebookModelResolverService;
73
+ this.originalModelRefFactory = originalModelRefFactory;
74
+ this.throttledUpdateNotebookModel = ( new ThrottledDelayer(200));
75
+ this._diffInfo = observableValue('diffInfo', undefined);
76
+ this.isEditFromUs = false;
77
+ this.isTextEditFromUs = false;
78
+ this.isReverting = false;
79
+ this.throttledTextModelUpdate = ( new ThrottledDelayer(100));
80
+ const entryObs = derived((r) => {
81
+ const session = _chatEditingService.currentEditingSessionObs.read(r);
82
+ if (!session) {
83
+ return;
84
+ }
85
+ return session.readEntry(model.uri, r);
86
+ }).recomputeInitiallyAndOnChange(this._store);
87
+ this._register(chatService.onDidPerformUserAction(async (e) => {
88
+ const entry = entryObs.read(undefined);
89
+ if (!entry) {
90
+ return;
91
+ }
92
+ if (e.action.kind === 'chatEditingSessionAction' && !e.action.hasRemainingEdits && isEqual(e.action.uri, entry.modifiedURI)) {
93
+ if (e.action.outcome === 'accepted') {
94
+ await this.accept(entry);
95
+ await this.createSnapshot();
96
+ this._diffInfo.set(undefined, undefined);
97
+ }
98
+ else if (e.action.outcome === 'rejected') {
99
+ await this.revertImpl();
100
+ }
101
+ }
102
+ }));
103
+ const updateNotebookModel = (entry, token) => {
104
+ this.throttledUpdateNotebookModel.trigger(() => this.updateNotebookModel(entry, token));
105
+ };
106
+ let snapshotCreated = false;
107
+ this._register(autorunWithStore((r, store) => {
108
+ const entry = entryObs.read(r);
109
+ if (!entry) {
110
+ return;
111
+ }
112
+ if (!snapshotCreated) {
113
+ this.createSnapshot();
114
+ snapshotCreated = true;
115
+ }
116
+ const modifiedModel = entry.modifiedModel;
117
+ let cancellationToken = store.add(( new CancellationTokenSource()));
118
+ store.add(modifiedModel.onDidChangeContent(async () => {
119
+ if (!this.isTextEditFromUs && !modifiedModel.isDisposed() && !entry.originalModel.isDisposed() && modifiedModel.getValue() !== entry.originalModel.getValue()) {
120
+ cancellationToken = store.add(( new CancellationTokenSource()));
121
+ updateNotebookModel(entry, cancellationToken.token);
122
+ }
123
+ }));
124
+ updateNotebookModel(entry, cancellationToken.token);
125
+ }));
126
+ this._register(model.onDidChangeContent(() => {
127
+ if (!this.isEditFromUs && this.snapshot) {
128
+ this.snapshot.dirty = true;
129
+ const entry = entryObs.get();
130
+ if (entry) {
131
+ this.throttledTextModelUpdate.trigger(() => this.updateTextDocumentModel(entry));
132
+ }
133
+ }
134
+ }));
135
+ }
136
+ async createSnapshot() {
137
+ const [serializer, ref] = await Promise.all([
138
+ this.getNotebookSerializer(),
139
+ this.notebookModelResolverService.resolve(this.model.uri)
140
+ ]);
141
+ try {
142
+ const data = {
143
+ metadata: filter(this.model.metadata, key => !serializer.options.transientDocumentMetadata[key]),
144
+ cells: [],
145
+ };
146
+ const indentAmount = this.model.metadata.indentAmount || ref.object.notebook.metadata.indentAmount || undefined;
147
+ if (typeof indentAmount === 'string' && indentAmount) {
148
+ data.metadata.indentAmount = indentAmount;
149
+ }
150
+ let outputSize = 0;
151
+ for (const cell of this.model.cells) {
152
+ const cellData = {
153
+ cellKind: cell.cellKind,
154
+ language: cell.language,
155
+ mime: cell.mime,
156
+ source: cell.getValue(),
157
+ outputs: [],
158
+ internalMetadata: cell.internalMetadata
159
+ };
160
+ const outputSizeLimit = this.configurationService.getValue(NotebookSetting.outputBackupSizeLimit) * 1024;
161
+ if (outputSizeLimit > 0) {
162
+ cell.outputs.forEach(output => {
163
+ output.outputs.forEach(item => {
164
+ outputSize += item.data.byteLength;
165
+ });
166
+ });
167
+ if (outputSize > outputSizeLimit) {
168
+ return;
169
+ }
170
+ }
171
+ cellData.outputs = !serializer.options.transientOutputs ? cell.outputs : [];
172
+ cellData.metadata = filter(cell.metadata, key => !serializer.options.transientCellMetadata[key]);
173
+ data.cells.push(cellData);
174
+ }
175
+ const bytes = await serializer.notebookToData(data);
176
+ this.snapshot = { bytes, dirty: ref.object.isDirty() };
177
+ }
178
+ finally {
179
+ ref.dispose();
180
+ }
181
+ }
182
+ async revert() {
183
+ await this.revertImpl();
184
+ }
185
+ async revertImpl() {
186
+ if (!this.snapshot || this.isReverting) {
187
+ return;
188
+ }
189
+ this.isReverting = true;
190
+ try {
191
+ await this.updateNotebook(this.snapshot.bytes, !this.snapshot.dirty);
192
+ }
193
+ finally {
194
+ this.isReverting = false;
195
+ this._diffInfo.set(undefined, undefined);
196
+ }
197
+ }
198
+ async updateNotebook(bytes, saveForRevert) {
199
+ const oldEditIsFromus = this.isEditFromUs;
200
+ this.isEditFromUs = true;
201
+ const ref = await this.notebookModelResolverService.resolve(this.model.uri);
202
+ try {
203
+ const serializer = await this.getNotebookSerializer();
204
+ const data = await serializer.dataToNotebook(bytes);
205
+ this.model.reset(data.cells, data.metadata, serializer.options);
206
+ if (saveForRevert) {
207
+ await ref.object.save({ reason: SaveReason.EXPLICIT, force: true, ignoreModifiedSince: true });
208
+ }
209
+ }
210
+ finally {
211
+ ref.dispose();
212
+ this.isEditFromUs = oldEditIsFromus;
213
+ }
214
+ }
215
+ async accept(entry) {
216
+ const modifiedModel = entry.modifiedModel;
217
+ const content = modifiedModel.getValue();
218
+ await this.updateNotebook(VSBuffer.fromString(content), false);
219
+ this._diffInfo.set(undefined, undefined);
220
+ const stream = await this.notebookService.createNotebookTextDocumentSnapshot(this.model.uri, SnapshotContext.Save, CancellationToken.None);
221
+ const originalModel = await this.getOriginalModel(entry);
222
+ await this.notebookService.restoreNotebookTextModelFromSnapshot(originalModel.uri, originalModel.viewType, stream);
223
+ }
224
+ async updateTextDocumentModel(entry) {
225
+ const modifiedModel = entry.modifiedModel;
226
+ const stream = await this.notebookService.createNotebookTextDocumentSnapshot(this.model.uri, SnapshotContext.Save, CancellationToken.None);
227
+ const buffer = await streamToBuffer(stream);
228
+ const text = ( new TextDecoder()).decode(buffer.buffer);
229
+ this.isTextEditFromUs = true;
230
+ modifiedModel.pushEditOperations(null, [{ range: modifiedModel.getFullModelRange(), text }], () => null);
231
+ this.isTextEditFromUs = false;
232
+ }
233
+ async getNotebookSerializer() {
234
+ const info = await this.notebookService.withNotebookDataProvider(this.model.viewType);
235
+ return info.serializer;
236
+ }
237
+ async getOriginalModel(entry) {
238
+ if (!this._originalModel) {
239
+ this._originalModel = this.originalModelRefFactory.getOrCreate(entry, this.model.viewType).then(ref => {
240
+ if (this._store.isDisposed) {
241
+ ref.dispose();
242
+ return ref.object;
243
+ }
244
+ else {
245
+ return this._register(ref).object;
246
+ }
247
+ });
248
+ }
249
+ return this._originalModel;
250
+ }
251
+ async updateNotebookModel(entry, token) {
252
+ const modifiedModelVersion = entry.modifiedModel.getVersionId();
253
+ const currentModel = this.model;
254
+ const modelVersion = currentModel?.versionId ?? 0;
255
+ const modelWithChatEdits = await this.getModifiedModelForDiff(entry, token);
256
+ if (!modelWithChatEdits || token.isCancellationRequested || !currentModel) {
257
+ return;
258
+ }
259
+ const originalModel = await this.getOriginalModel(entry);
260
+ const cellDiffInfo = (await this.computeDiff(originalModel, modelWithChatEdits, token))?.cellDiffInfo;
261
+ const cellDiffInfoToApplyEdits = (await this.computeDiff(currentModel, modelWithChatEdits, token))?.cellDiffInfo;
262
+ const currentVersion = entry.modifiedModel.getVersionId();
263
+ if (!cellDiffInfo || !cellDiffInfoToApplyEdits || token.isCancellationRequested || currentVersion !== modifiedModelVersion || modelVersion !== currentModel.versionId) {
264
+ return;
265
+ }
266
+ if (cellDiffInfoToApplyEdits.every(d => d.type === 'unchanged')) {
267
+ return;
268
+ }
269
+ this.isEditFromUs = true;
270
+ try {
271
+ const edits = [];
272
+ const mappings = ( new Map());
273
+ const deletedIndexes = [];
274
+ await Promise.all(( cellDiffInfoToApplyEdits.reverse().map(async (diff) => {
275
+ if (diff.type === 'delete') {
276
+ deletedIndexes.push(diff.originalCellIndex);
277
+ edits.push({
278
+ editType: CellEditType.Replace,
279
+ index: diff.originalCellIndex,
280
+ cells: [],
281
+ count: 1
282
+ });
283
+ }
284
+ })));
285
+ if (edits.length) {
286
+ currentModel.applyEdits(edits, true, undefined, () => undefined, undefined, false);
287
+ edits.length = 0;
288
+ }
289
+ const notebookEditor = this.notebookEditorService.retrieveExistingWidgetFromURI(this.model.uri)?.value;
290
+ cellDiffInfoToApplyEdits.reverse().forEach(diff => {
291
+ if (diff.type === 'modified' || diff.type === 'unchanged') {
292
+ mappings.set(diff.modifiedCellIndex, diff.originalCellIndex);
293
+ }
294
+ if (diff.type === 'insert') {
295
+ const originalIndex = mappings.get(diff.modifiedCellIndex - 1) ?? 0;
296
+ mappings.set(diff.modifiedCellIndex, originalIndex);
297
+ const index = currentModel.cells.length ? originalIndex + 1 : originalIndex;
298
+ const cell = modelWithChatEdits.cells[diff.modifiedCellIndex];
299
+ const newCell = {
300
+ source: cell.getValue(),
301
+ cellKind: cell.cellKind,
302
+ language: cell.language,
303
+ outputs: ( cell.outputs.map(output => output.asDto())),
304
+ mime: cell.mime,
305
+ metadata: cell.metadata,
306
+ collapseState: cell.collapseState,
307
+ internalMetadata: cell.internalMetadata
308
+ };
309
+ edits.push({
310
+ editType: CellEditType.Replace,
311
+ index,
312
+ cells: [newCell],
313
+ count: 0
314
+ });
315
+ }
316
+ });
317
+ if (edits.length) {
318
+ currentModel.applyEdits(edits, true, undefined, () => undefined, undefined, false);
319
+ for (const edit of edits.filter(e => e.editType === CellEditType.Replace)) {
320
+ const cell = currentModel.cells[edit.index];
321
+ if (cell) {
322
+ const cellViewModel = notebookEditor?.getCellByHandle(cell.handle);
323
+ cellViewModel?.updateEditState(CellEditState.Editing, 'chatEdit');
324
+ }
325
+ }
326
+ edits.length = 0;
327
+ }
328
+ await Promise.all(( cellDiffInfoToApplyEdits.map(async (diff) => {
329
+ if (diff.type === 'modified') {
330
+ const cell = currentModel.cells[diff.originalCellIndex];
331
+ const cellModelRef = await this.textModelService.createModelReference(cell.uri);
332
+ try {
333
+ const modifiedCell = modelWithChatEdits.cells[diff.modifiedCellIndex];
334
+ if (modifiedCell.cellKind === cell.cellKind) {
335
+ const cellViewModel = notebookEditor?.getCellByHandle(cell.handle);
336
+ cellViewModel?.updateEditState(CellEditState.Editing, 'chatEdit');
337
+ const textModel = cellModelRef.object.textEditorModel;
338
+ textModel.pushEditOperations(null, [
339
+ EditOperation.replace(textModel.getFullModelRange(), modifiedCell.getValue())
340
+ ], () => null);
341
+ }
342
+ else {
343
+ const newCellDto = {
344
+ source: modifiedCell.getValue(),
345
+ cellKind: modifiedCell.cellKind,
346
+ language: modifiedCell.language,
347
+ outputs: ( modifiedCell.outputs.map(output => output.asDto())),
348
+ mime: modifiedCell.mime,
349
+ metadata: modifiedCell.metadata,
350
+ collapseState: modifiedCell.collapseState,
351
+ internalMetadata: modifiedCell.internalMetadata
352
+ };
353
+ const edit = {
354
+ editType: CellEditType.Replace,
355
+ index: diff.originalCellIndex,
356
+ cells: [newCellDto],
357
+ count: 1
358
+ };
359
+ currentModel.applyEdits([edit], true, undefined, () => undefined, undefined, false);
360
+ const newCell = currentModel.cells[diff.originalCellIndex];
361
+ const cellViewModel = notebookEditor?.getCellByHandle(newCell.handle);
362
+ cellViewModel?.updateEditState(CellEditState.Editing, 'chatEdit');
363
+ }
364
+ }
365
+ finally {
366
+ cellModelRef.dispose();
367
+ }
368
+ }
369
+ })));
370
+ if (edits.length) {
371
+ currentModel.applyEdits(edits, true, undefined, () => undefined, undefined, false);
372
+ }
373
+ this._diffInfo.set({ cellDiff: cellDiffInfo, modelVersion: currentModel.versionId }, undefined);
374
+ }
375
+ finally {
376
+ this.isEditFromUs = false;
377
+ }
378
+ }
379
+ async getModifiedModelForDiff(entry, token) {
380
+ const text = entry.modifiedModel.getValue();
381
+ const bytes = VSBuffer.fromString(text);
382
+ const uri = entry.modifiedURI.with({ scheme: `NotebookChatEditorController.modifiedScheme${( Date.now().toString())}` });
383
+ const stream = bufferToStream(bytes);
384
+ if (this.previousUriOfModelForDiff) {
385
+ this.notebookService.getNotebookTextModel(this.previousUriOfModelForDiff)?.dispose();
386
+ }
387
+ this.previousUriOfModelForDiff = uri;
388
+ try {
389
+ const model = await this.notebookService.createNotebookTextModel(this.model.viewType, uri, stream);
390
+ if (token.isCancellationRequested) {
391
+ model.dispose();
392
+ return;
393
+ }
394
+ this._register(model);
395
+ return model;
396
+ }
397
+ catch (ex) {
398
+ this.logService.warn('NotebookChatEdit', `Failed to deserialize Notebook for ${uri.toString}, ${ex.message}`);
399
+ this.logService.debug('NotebookChatEdit', ( ex.toString()));
400
+ return;
401
+ }
402
+ }
403
+ async computeDiff(original, modified, token) {
404
+ const diffResult = await raceCancellation(this.notebookEditorWorkerService.computeDiff(original.uri, modified.uri), token);
405
+ if (!diffResult || token.isCancellationRequested) {
406
+ return;
407
+ }
408
+ prettyChanges(original, modified, diffResult.cellsDiff);
409
+ return computeDiff(original, modified, diffResult);
410
+ }
411
+ };
412
+ NotebookModelSynchronizer = ( __decorate([
413
+ ( __param(1, IChatEditingService)),
414
+ ( __param(2, INotebookService)),
415
+ ( __param(3, INotebookEditorService)),
416
+ ( __param(4, IChatService)),
417
+ ( __param(5, ITextModelService)),
418
+ ( __param(6, INotebookLoggingService)),
419
+ ( __param(7, IConfigurationService)),
420
+ ( __param(8, INotebookEditorWorkerService)),
421
+ ( __param(9, INotebookEditorModelResolverService)),
422
+ ( __param(10, INotebookOriginalModelReferenceFactory))
423
+ ], NotebookModelSynchronizer));
424
+
425
+ export { NotebookModelSynchronizer, NotebookModelSynchronizerFactory };
@@ -3,7 +3,7 @@ import { IStoredFileWorkingCopy } from "@codingame/monaco-vscode-99f24462-c56d-5
3
3
  import { IUntitledFileWorkingCopy } from "../../../../../services/workingCopy/common/untitledFileWorkingCopy.js";
4
4
  import { IWorkingCopyFileService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/workingCopy/common/workingCopyFileService.service";
5
5
  import { IChatEditingService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatEditingService.service";
6
- import { NotebookFileWorkingCopyModel } from "@codingame/monaco-vscode-99f24462-c56d-5407-83fb-2ea9dd33cc8c-common/vscode/vs/workbench/contrib/notebook/common/notebookEditorModel";
6
+ import { NotebookFileWorkingCopyModel } from "@codingame/monaco-vscode-168b98e5-dc20-5807-b1f9-798f1f92b37f-common/vscode/vs/workbench/contrib/notebook/common/notebookEditorModel";
7
7
  import { INotebookSynchronizerService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookSynchronizerService.service";
8
8
  import { Disposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
9
9
  import { IInstantiationService } from "@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation";
@@ -17,7 +17,6 @@ let NotebookSynchronizerSaveParticipant = class NotebookSynchronizerSaveParticip
17
17
  this._fileService = _fileService;
18
18
  }
19
19
  async participate(workingCopy, context, progress, token) {
20
- console.log('notebook synchronizer participate');
21
20
  const session = this._chatEditingService.currentEditingSessionObs.get();
22
21
  if (!session) {
23
22
  return;
@@ -1,7 +1,7 @@
1
1
  import { Disposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
2
2
  import { IEditorService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService.service";
3
- import { ICellViewModel, INotebookEditor } from "@codingame/monaco-vscode-271a23cd-c7d7-5761-ae35-a923a42987b8-common/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser";
4
- import { NotebookCellTextModel } from "@codingame/monaco-vscode-c465110a-57c0-59d7-a6b2-be0a4db7e517-common/vscode/vs/workbench/contrib/notebook/common/model/notebookCellTextModel";
3
+ import { ICellViewModel, INotebookEditor } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser";
4
+ import { NotebookCellTextModel } from "@codingame/monaco-vscode-e28ac690-06d5-5ee9-92d1-02df70296354-common/vscode/vs/workbench/contrib/notebook/common/model/notebookCellTextModel";
5
5
  import { ServicesAccessor } from "@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation";
6
6
  export declare function runPasteCells(editor: INotebookEditor, activeCell: ICellViewModel | undefined, pasteCells: {
7
7
  items: NotebookCellTextModel[];