@codingame/monaco-vscode-chat-service-override 15.0.2 → 16.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.
- package/index.js +11 -8
- package/package.json +29 -20
- package/vscode/src/vs/editor/common/diff/documentDiffProvider.d.ts +22 -0
- package/vscode/src/vs/editor/common/diff/documentDiffProvider.js +10 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityHelp.d.ts +9 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityHelp.js +80 -55
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/chatAttachPromptAction.d.ts +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/chatAttachPromptAction.js +17 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/{askToSelectPrompt.d.ts → askToSelectPrompt/askToSelectPrompt.d.ts} +9 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt/askToSelectPrompt.js +79 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt/constants.d.ts +7 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt/constants.js +27 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt/utils/attachPrompts.d.ts +5 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt/utils/attachPrompts.js +53 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt/utils/createPlaceholderText.d.ts +2 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt/utils/createPlaceholderText.js +19 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt/utils/createPromptPickItem.d.ts +5 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt/utils/createPromptPickItem.js +27 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt/utils/handleButtonClick.d.ts +13 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt/utils/handleButtonClick.js +49 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +11 -11
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContextActions.d.ts +6 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContextActions.js +163 -72
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatDeveloperActions.js +22 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatGettingStarted.js +4 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.js +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.js +17 -17
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.js +9 -8
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatTransfer.d.ts +7 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatTransfer.js +17 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.js +15 -15
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +242 -74
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditing.d.ts +4 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditing.js +15 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingCodeEditorIntegration.d.ts +47 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingCodeEditorIntegration.js +688 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingEditorActions.d.ts +28 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingEditorActions.js +355 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingEditorOverlay.js +11 -11
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedDocumentEntry.d.ts +71 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedDocumentEntry.js +395 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedFileEntry.d.ts +98 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedFileEntry.js +216 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedNotebookEntry.d.ts +97 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedNotebookEntry.js +831 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingServiceImpl.d.ts +7 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingServiceImpl.js +32 -47
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.d.ts +110 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.js +985 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingTextModelContentProviders.d.ts +20 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingTextModelContentProviders.js +69 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingModifiedNotebookDiff.d.ts +15 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingModifiedNotebookDiff.js +67 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingModifiedNotebookSnapshot.d.ts +26 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingModifiedNotebookSnapshot.js +147 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingNotebookCellEntry.d.ts +56 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingNotebookCellEntry.js +284 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingNotebookEditorIntegration.d.ts +38 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingNotebookEditorIntegration.js +578 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingNotebookFileSystemProvider.d.ts +45 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/chatEditingNotebookFileSystemProvider.js +122 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/helpers.d.ts +15 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/helpers.js +320 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/notebookCellChanges.d.ts +31 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/notebook/notebookCellChanges.js +50 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.d.ts +5 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +22 -5
- package/vscode/src/vs/workbench/contrib/chat/browser/chatParticipant.contribution.d.ts +4 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatParticipant.contribution.js +166 -62
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup.d.ts +6 -104
- package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup.js +704 -732
- package/vscode/src/vs/workbench/contrib/chat/browser/chatStatus.d.ts +10 -25
- package/vscode/src/vs/workbench/contrib/chat/browser/chatStatus.js +329 -236
- package/vscode/src/vs/workbench/contrib/chat/browser/chatStatusItemService.d.ts +19 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatStatusItemService.js +27 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.d.ts +4 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +14 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorHover.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorHover.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/editorHoverWrapper.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/editorHoverWrapper.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/media/editorHoverWrapper.css +3 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/languageModelToolsService.d.ts +17 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/languageModelToolsService.js +217 -18
- package/vscode/src/vs/workbench/contrib/chat/browser/media/chatEditingEditorOverlay.css +114 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/media/chatEditorController.css +30 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/media/chatSetup.css +56 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/media/chatStatus.css +90 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/createPromptCommand.js +65 -19
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/dialogs/askForPromptName.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/dialogs/askForPromptSourceFolder.js +4 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/errors.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/utils/createPromptFile.d.ts +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/utils/createPromptFile.js +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/usePromptCommand.js +14 -12
- package/vscode/src/vs/workbench/contrib/chat/browser/viewsWelcome/chatViewsWelcomeHandler.js +5 -5
- package/vscode/src/vs/workbench/contrib/chat/common/chatProgressTypes/chatToolInvocation.d.ts +5 -3
- package/vscode/src/vs/workbench/contrib/chat/common/chatProgressTypes/chatToolInvocation.js +5 -2
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.d.ts +16 -8
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +175 -57
- package/vscode/src/vs/workbench/contrib/chat/common/chatSessionStore.d.ts +66 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatSessionStore.js +313 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatSlashCommands.d.ts +3 -2
- package/vscode/src/vs/workbench/contrib/chat/common/chatSlashCommands.js +4 -2
- package/vscode/src/vs/workbench/contrib/chat/common/chatTransferService.d.ts +14 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatTransferService.js +30 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/constants.d.ts +2 -3
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/constants.js +6 -2
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/contentProviders/textModelContentsProvider.d.ts +10 -2
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/contentProviders/textModelContentsProvider.js +18 -3
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptLinkDiagnosticsProvider.d.ts +9 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptLinkDiagnosticsProvider.js +117 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptPathAutocompletion.js +3 -4
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/textModelPromptParser.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsService.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.d.ts +6 -4
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.js +157 -65
- package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsContribution.d.ts +2 -1
- package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsContribution.js +39 -21
- package/vscode/src/vs/workbench/contrib/chat/common/voiceChatService.d.ts +0 -1
- package/vscode/src/vs/workbench/contrib/chat/common/voiceChatService.js +2 -3
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +4 -4
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatCurrentLine.js +11 -10
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatNotebook.js +1 -1
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookModifiedCellDecorator.d.ts +10 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookModifiedCellDecorator.js +47 -0
- package/vscode/src/vs/workbench/services/workspaces/common/workspaceUtils.d.ts +5 -0
- package/vscode/src/vs/workbench/services/workspaces/common/workspaceUtils.js +26 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt.js +0 -142
- package/vscode/src/vs/workbench/contrib/chat/browser/chatPasteProviders.d.ts +0 -52
- package/vscode/src/vs/workbench/contrib/chat/browser/chatPasteProviders.js +0 -331
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputRelatedFilesContrib.d.ts +0 -15
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputRelatedFilesContrib.js +0 -110
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/media/editorHoverWrapper.css.js +0 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/media/chatEditingEditorOverlay.css.js +0 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/media/chatStatus.css.js +0 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/media/chatViewSetup.css.js +0 -6
- package/vscode/src/vs/workbench/contrib/chat/common/chatEntitlementsService.d.ts +0 -19
- package/vscode/src/vs/workbench/contrib/chat/common/chatEntitlementsService.js +0 -13
- package/vscode/src/vs/workbench/contrib/chat/common/chatQuotasService.d.ts +0 -31
- package/vscode/src/vs/workbench/contrib/chat/common/chatQuotasService.js +0 -85
- package/vscode/src/vs/workbench/contrib/chat/common/tools/tools.d.ts +0 -11
- package/vscode/src/vs/workbench/contrib/chat/common/tools/tools.js +0 -22
|
@@ -0,0 +1,985 @@
|
|
|
1
|
+
|
|
2
|
+
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
|
+
import { equals, binarySearch2 } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
|
|
4
|
+
import { Sequencer, timeout, SequencerByKey, DeferredPromise } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
|
|
5
|
+
import { VSBuffer } from '@codingame/monaco-vscode-api/vscode/vs/base/common/buffer';
|
|
6
|
+
import { BugIndicatingError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
|
|
7
|
+
import { Emitter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
|
|
8
|
+
import { StringSHA1 } from '@codingame/monaco-vscode-api/vscode/vs/base/common/hash';
|
|
9
|
+
import { Iterable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/iterator';
|
|
10
|
+
import { Disposable, dispose } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
11
|
+
import { ResourceMap } from '@codingame/monaco-vscode-api/vscode/vs/base/common/map';
|
|
12
|
+
import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/index';
|
|
13
|
+
import { isEqual, joinPath } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
|
|
14
|
+
import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
|
|
15
|
+
import { IBulkEditService } from '@codingame/monaco-vscode-api/vscode/vs/editor/browser/services/bulkEditService.service';
|
|
16
|
+
import { OffsetEdit } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/offsetEdit';
|
|
17
|
+
import { ILanguageService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/languages/language.service';
|
|
18
|
+
import { IEditorWorkerService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/editorWorker.service';
|
|
19
|
+
import { IModelService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/model.service';
|
|
20
|
+
import { ITextModelService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/resolverService.service';
|
|
21
|
+
import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
|
|
22
|
+
import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service';
|
|
23
|
+
import { EditorActivation } from '@codingame/monaco-vscode-api/vscode/vs/platform/editor/common/editor';
|
|
24
|
+
import { IEnvironmentService } from '@codingame/monaco-vscode-api/vscode/vs/platform/environment/common/environment.service';
|
|
25
|
+
import { IFileService } from '@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files.service';
|
|
26
|
+
import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
|
|
27
|
+
import { ILogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service';
|
|
28
|
+
import { observableConfigValue } from '@codingame/monaco-vscode-api/vscode/vs/platform/observable/common/platformObservableUtils';
|
|
29
|
+
import { IWorkspaceContextService } from '@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace.service';
|
|
30
|
+
import { DiffEditorInput } from '@codingame/monaco-vscode-fdf643f9-94dd-5510-b97a-408abf26ad92-common/vscode/vs/workbench/common/editor/diffEditorInput';
|
|
31
|
+
import { IEditorGroupsService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorGroupsService.service';
|
|
32
|
+
import { IEditorService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService.service';
|
|
33
|
+
import { MultiDiffEditorInput } from '@codingame/monaco-vscode-1cc4ea0a-c5b6-54ed-bb60-078a99119b55-common/vscode/vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditorInput';
|
|
34
|
+
import { INotebookService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookService.service';
|
|
35
|
+
import { ChatEditingSessionState, ChatEditingSessionChangeType, WorkingSetEntryState, getMultiDiffSourceUri, ChatEditKind } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatEditingService';
|
|
36
|
+
import { IChatService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatService.service';
|
|
37
|
+
import { AbstractChatEditingModifiedFileEntry } from './chatEditingModifiedFileEntry.js';
|
|
38
|
+
import { ChatEditingModifiedDocumentEntry } from './chatEditingModifiedDocumentEntry.js';
|
|
39
|
+
import { ChatEditingTextModelContentProvider } from './chatEditingTextModelContentProviders.js';
|
|
40
|
+
import { CellUri } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
|
|
41
|
+
import { ChatEditingModifiedNotebookEntry } from './chatEditingModifiedNotebookEntry.js';
|
|
42
|
+
import { CancellationToken } from '@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation';
|
|
43
|
+
import { ChatEditingModifiedNotebookDiff } from './notebook/chatEditingModifiedNotebookDiff.js';
|
|
44
|
+
import { AccessibilitySignal } from '@codingame/monaco-vscode-api/vscode/vs/platform/accessibilitySignal/browser/accessibilitySignalService';
|
|
45
|
+
import { IAccessibilitySignalService } from '@codingame/monaco-vscode-api/vscode/vs/platform/accessibilitySignal/browser/accessibilitySignalService.service';
|
|
46
|
+
import { observableValue, asyncTransaction, transaction } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/base';
|
|
47
|
+
import { derived, derivedWithStore, derivedOpts } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/derived';
|
|
48
|
+
import { autorun } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/autorun';
|
|
49
|
+
import { ObservablePromise } from '@codingame/monaco-vscode-ae8a8ca1-f243-508b-9c37-c88ebbd295fa-common/vscode/vs/base/common/observableInternal/promise';
|
|
50
|
+
|
|
51
|
+
const STORAGE_CONTENTS_FOLDER = 'contents';
|
|
52
|
+
const STORAGE_STATE_FILE = 'state.json';
|
|
53
|
+
const POST_EDIT_STOP_ID = 'd19944f6-f46c-4e17-911b-79a8e843c7c0';
|
|
54
|
+
class ThrottledSequencer extends Sequencer {
|
|
55
|
+
constructor(_minDuration, _maxOverallDelay) {
|
|
56
|
+
super();
|
|
57
|
+
this._minDuration = _minDuration;
|
|
58
|
+
this._maxOverallDelay = _maxOverallDelay;
|
|
59
|
+
this._size = 0;
|
|
60
|
+
}
|
|
61
|
+
queue(promiseTask) {
|
|
62
|
+
this._size += 1;
|
|
63
|
+
const noDelay = this._size * this._minDuration > this._maxOverallDelay;
|
|
64
|
+
return super.queue(async () => {
|
|
65
|
+
try {
|
|
66
|
+
const p1 = promiseTask();
|
|
67
|
+
const p2 = noDelay
|
|
68
|
+
? Promise.resolve(undefined)
|
|
69
|
+
: timeout(this._minDuration, CancellationToken.None);
|
|
70
|
+
const [result] = await Promise.all([p1, p2]);
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
this._size -= 1;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function getMaxHistoryIndex(history) {
|
|
80
|
+
const lastHistory = history.at(-1);
|
|
81
|
+
return lastHistory ? lastHistory.startIndex + lastHistory.stops.length : 0;
|
|
82
|
+
}
|
|
83
|
+
function snapshotsEqualForDiff(a, b) {
|
|
84
|
+
if (!a || !b) {
|
|
85
|
+
return a === b;
|
|
86
|
+
}
|
|
87
|
+
return isEqual(a.snapshotUri, b.snapshotUri) && a.current === b.current;
|
|
88
|
+
}
|
|
89
|
+
function getCurrentAndNextStop(requestId, stopId, history) {
|
|
90
|
+
const snapshotIndex = history.findIndex(s => s.requestId === requestId);
|
|
91
|
+
if (snapshotIndex === -1) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const snapshot = history[snapshotIndex];
|
|
95
|
+
const stopIndex = snapshot.stops.findIndex(s => s.stopId === stopId);
|
|
96
|
+
if (stopIndex === -1) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const current = snapshot.stops[stopIndex].entries;
|
|
100
|
+
const next = stopIndex < snapshot.stops.length - 1
|
|
101
|
+
? snapshot.stops[stopIndex + 1].entries
|
|
102
|
+
: snapshot.postEdit || history[snapshotIndex + 1]?.stops[0].entries;
|
|
103
|
+
if (!next) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
return { current, next };
|
|
107
|
+
}
|
|
108
|
+
let ChatEditingSession = class ChatEditingSession extends Disposable {
|
|
109
|
+
get entries() {
|
|
110
|
+
this._assertNotDisposed();
|
|
111
|
+
return this._entriesObs;
|
|
112
|
+
}
|
|
113
|
+
get state() {
|
|
114
|
+
return this._state;
|
|
115
|
+
}
|
|
116
|
+
get onDidChange() {
|
|
117
|
+
this._assertNotDisposed();
|
|
118
|
+
return this._onDidChange.event;
|
|
119
|
+
}
|
|
120
|
+
get onDidDispose() {
|
|
121
|
+
this._assertNotDisposed();
|
|
122
|
+
return this._onDidDispose.event;
|
|
123
|
+
}
|
|
124
|
+
constructor(chatSessionId, isGlobalEditingSession, _lookupExternalEntry, _instantiationService, _modelService, _languageService, _textModelService, _bulkEditService, _editorGroupsService, _editorService, _chatService, _notebookService, _editorWorkerService, _configurationService, _accessibilitySignalService) {
|
|
125
|
+
super();
|
|
126
|
+
this.chatSessionId = chatSessionId;
|
|
127
|
+
this.isGlobalEditingSession = isGlobalEditingSession;
|
|
128
|
+
this._lookupExternalEntry = _lookupExternalEntry;
|
|
129
|
+
this._instantiationService = _instantiationService;
|
|
130
|
+
this._modelService = _modelService;
|
|
131
|
+
this._languageService = _languageService;
|
|
132
|
+
this._textModelService = _textModelService;
|
|
133
|
+
this._bulkEditService = _bulkEditService;
|
|
134
|
+
this._editorGroupsService = _editorGroupsService;
|
|
135
|
+
this._editorService = _editorService;
|
|
136
|
+
this._chatService = _chatService;
|
|
137
|
+
this._notebookService = _notebookService;
|
|
138
|
+
this._editorWorkerService = _editorWorkerService;
|
|
139
|
+
this._configurationService = _configurationService;
|
|
140
|
+
this._accessibilitySignalService = _accessibilitySignalService;
|
|
141
|
+
this._state = observableValue(this, ChatEditingSessionState.Initial);
|
|
142
|
+
this._linearHistory = observableValue(this, []);
|
|
143
|
+
this._linearHistoryIndex = observableValue(this, 0);
|
|
144
|
+
this._initialFileContents = ( new ResourceMap());
|
|
145
|
+
this._entriesObs = observableValue(this, []);
|
|
146
|
+
this._workingSet = ( new ResourceMap());
|
|
147
|
+
this.canUndo = derived((r) => {
|
|
148
|
+
if (this.state.read(r) !== ChatEditingSessionState.Idle) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
const linearHistoryIndex = this._linearHistoryIndex.read(r);
|
|
152
|
+
return linearHistoryIndex > 0;
|
|
153
|
+
});
|
|
154
|
+
this.canRedo = derived((r) => {
|
|
155
|
+
if (this.state.read(r) !== ChatEditingSessionState.Idle) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
const linearHistoryIndex = this._linearHistoryIndex.read(r);
|
|
159
|
+
return linearHistoryIndex < getMaxHistoryIndex(this._linearHistory.read(r));
|
|
160
|
+
});
|
|
161
|
+
this._onDidChange = this._register(( new Emitter()));
|
|
162
|
+
this._onDidDispose = ( new Emitter());
|
|
163
|
+
this._diffsBetweenStops = ( new Map());
|
|
164
|
+
this._ignoreTrimWhitespaceObservable = observableConfigValue('diffEditor.ignoreTrimWhitespace', true, this._configurationService);
|
|
165
|
+
this._streamingEditLocks = ( new SequencerByKey());
|
|
166
|
+
}
|
|
167
|
+
async init() {
|
|
168
|
+
const restoredSessionState = await this._instantiationService.createInstance(ChatEditingSessionStorage, this.chatSessionId).restoreState();
|
|
169
|
+
if (restoredSessionState) {
|
|
170
|
+
for (const [uri, content] of restoredSessionState.initialFileContents) {
|
|
171
|
+
this._initialFileContents.set(uri, content);
|
|
172
|
+
}
|
|
173
|
+
await asyncTransaction(async (tx) => {
|
|
174
|
+
this._pendingSnapshot = restoredSessionState.pendingSnapshot;
|
|
175
|
+
await this._restoreSnapshot(restoredSessionState.recentSnapshot, tx, false);
|
|
176
|
+
this._linearHistory.set(restoredSessionState.linearHistory, tx);
|
|
177
|
+
this._linearHistoryIndex.set(restoredSessionState.linearHistoryIndex, tx);
|
|
178
|
+
this._state.set(ChatEditingSessionState.Idle, tx);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
this._state.set(ChatEditingSessionState.Idle, undefined);
|
|
183
|
+
}
|
|
184
|
+
this._register(autorun(reader => {
|
|
185
|
+
const entries = this.entries.read(reader);
|
|
186
|
+
entries.forEach(entry => {
|
|
187
|
+
entry.state.read(reader);
|
|
188
|
+
});
|
|
189
|
+
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
_getEntry(uri) {
|
|
193
|
+
uri = CellUri.parse(uri)?.notebook ?? uri;
|
|
194
|
+
return this._entriesObs.get().find(e => isEqual(e.modifiedURI, uri));
|
|
195
|
+
}
|
|
196
|
+
getEntry(uri) {
|
|
197
|
+
return this._getEntry(uri);
|
|
198
|
+
}
|
|
199
|
+
readEntry(uri, reader) {
|
|
200
|
+
uri = CellUri.parse(uri)?.notebook ?? uri;
|
|
201
|
+
return this._entriesObs.read(reader).find(e => isEqual(e.modifiedURI, uri));
|
|
202
|
+
}
|
|
203
|
+
storeState() {
|
|
204
|
+
const storage = this._instantiationService.createInstance(ChatEditingSessionStorage, this.chatSessionId);
|
|
205
|
+
const state = {
|
|
206
|
+
initialFileContents: this._initialFileContents,
|
|
207
|
+
pendingSnapshot: this._pendingSnapshot,
|
|
208
|
+
recentSnapshot: this._createSnapshot(undefined, undefined),
|
|
209
|
+
linearHistoryIndex: this._linearHistoryIndex.get(),
|
|
210
|
+
linearHistory: this._linearHistory.get(),
|
|
211
|
+
};
|
|
212
|
+
return storage.storeState(state);
|
|
213
|
+
}
|
|
214
|
+
_findSnapshot(requestId) {
|
|
215
|
+
return this._linearHistory.get().find(s => s.requestId === requestId);
|
|
216
|
+
}
|
|
217
|
+
_findEditStop(requestId, undoStop) {
|
|
218
|
+
const snapshot = this._findSnapshot(requestId);
|
|
219
|
+
if (!snapshot) {
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
const idx = snapshot.stops.findIndex(s => s.stopId === undoStop);
|
|
223
|
+
return idx === -1 ? undefined : { stop: snapshot.stops[idx], snapshot, historyIndex: snapshot.startIndex + idx };
|
|
224
|
+
}
|
|
225
|
+
_ensurePendingSnapshot() {
|
|
226
|
+
this._pendingSnapshot ??= this._createSnapshot(undefined, undefined);
|
|
227
|
+
}
|
|
228
|
+
_entryDiffBetweenTextStops(entriesContent, modelUrisObservable) {
|
|
229
|
+
const modelRefsPromise = derivedWithStore(this, (reader, store) => {
|
|
230
|
+
const modelUris = modelUrisObservable.read(reader);
|
|
231
|
+
if (!modelUris) {
|
|
232
|
+
return undefined;
|
|
233
|
+
}
|
|
234
|
+
const promise = Promise.all(( modelUris.map(u => this._textModelService.createModelReference(u)))).then(refs => {
|
|
235
|
+
if (store.isDisposed) {
|
|
236
|
+
refs.forEach(r => r.dispose());
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
refs.forEach(r => store.add(r));
|
|
240
|
+
}
|
|
241
|
+
return refs;
|
|
242
|
+
});
|
|
243
|
+
return ( new ObservablePromise(promise));
|
|
244
|
+
});
|
|
245
|
+
return derived((reader) => {
|
|
246
|
+
const refs = modelRefsPromise.read(reader)?.promiseResult.read(reader)?.data;
|
|
247
|
+
if (!refs) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const entries = entriesContent.read(reader);
|
|
251
|
+
if (entries?.before && ChatEditingModifiedNotebookEntry.canHandleSnapshot(entries.before)) {
|
|
252
|
+
const diffService = this._instantiationService.createInstance(ChatEditingModifiedNotebookDiff, entries.before, entries.after);
|
|
253
|
+
return ( new ObservablePromise(diffService.computeDiff()));
|
|
254
|
+
}
|
|
255
|
+
const ignoreTrimWhitespace = this._ignoreTrimWhitespaceObservable.read(reader);
|
|
256
|
+
const promise = this._editorWorkerService.computeDiff(refs[0].object.textEditorModel.uri, refs[1].object.textEditorModel.uri, { ignoreTrimWhitespace, computeMoves: false, maxComputationTimeMs: 3000 }, 'advanced').then((diff) => {
|
|
257
|
+
const entryDiff = {
|
|
258
|
+
originalURI: refs[0].object.textEditorModel.uri,
|
|
259
|
+
modifiedURI: refs[1].object.textEditorModel.uri,
|
|
260
|
+
identical: !!diff?.identical,
|
|
261
|
+
quitEarly: !diff || diff.quitEarly,
|
|
262
|
+
added: 0,
|
|
263
|
+
removed: 0,
|
|
264
|
+
};
|
|
265
|
+
if (diff) {
|
|
266
|
+
for (const change of diff.changes) {
|
|
267
|
+
entryDiff.removed += change.original.endLineNumberExclusive - change.original.startLineNumber;
|
|
268
|
+
entryDiff.added += change.modified.endLineNumberExclusive - change.modified.startLineNumber;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return entryDiff;
|
|
272
|
+
});
|
|
273
|
+
return ( new ObservablePromise(promise));
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
_createDiffBetweenStopsObservable(uri, requestId, stopId) {
|
|
277
|
+
const entries = derivedOpts({
|
|
278
|
+
equalsFn: (a, b) => snapshotsEqualForDiff(a?.before, b?.before) && snapshotsEqualForDiff(a?.after, b?.after),
|
|
279
|
+
}, reader => {
|
|
280
|
+
const stops = getCurrentAndNextStop(requestId, stopId, this._linearHistory.read(reader));
|
|
281
|
+
if (!stops) {
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
const before = stops.current.get(uri);
|
|
285
|
+
const after = stops.next.get(uri);
|
|
286
|
+
if (!before || !after) {
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
return { before, after };
|
|
290
|
+
});
|
|
291
|
+
const modelUrisObservable = derivedOpts({ equalsFn: (a, b) => equals(a, b, isEqual) }, reader => {
|
|
292
|
+
const entriesValue = entries.read(reader);
|
|
293
|
+
if (!entriesValue) {
|
|
294
|
+
return undefined;
|
|
295
|
+
}
|
|
296
|
+
return [entriesValue.before.snapshotUri, entriesValue.after.snapshotUri];
|
|
297
|
+
});
|
|
298
|
+
const diff = this._entryDiffBetweenTextStops(entries, modelUrisObservable);
|
|
299
|
+
return derived(reader => {
|
|
300
|
+
return diff.read(reader)?.promiseResult.read(reader)?.data || undefined;
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
getEntryDiffBetweenStops(uri, requestId, stopId) {
|
|
304
|
+
const key = `${uri}\0${requestId}\0${stopId}`;
|
|
305
|
+
let observable = this._diffsBetweenStops.get(key);
|
|
306
|
+
if (!observable) {
|
|
307
|
+
observable = this._createDiffBetweenStopsObservable(uri, requestId, stopId);
|
|
308
|
+
this._diffsBetweenStops.set(key, observable);
|
|
309
|
+
}
|
|
310
|
+
return observable;
|
|
311
|
+
}
|
|
312
|
+
createSnapshot(requestId, undoStop) {
|
|
313
|
+
const snapshot = this._createSnapshot(requestId, undoStop);
|
|
314
|
+
for (const [uri, _] of this._workingSet) {
|
|
315
|
+
this._workingSet.set(uri, { state: WorkingSetEntryState.Sent });
|
|
316
|
+
}
|
|
317
|
+
const linearHistoryPtr = this._linearHistoryIndex.get();
|
|
318
|
+
const newLinearHistory = [];
|
|
319
|
+
for (const entry of this._linearHistory.get()) {
|
|
320
|
+
if (linearHistoryPtr - entry.startIndex < entry.stops.length) {
|
|
321
|
+
newLinearHistory.push({ requestId: entry.requestId, stops: entry.stops.slice(0, linearHistoryPtr - entry.startIndex), startIndex: entry.startIndex, postEdit: undefined });
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
newLinearHistory.push(entry);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
const lastEntry = newLinearHistory.at(-1);
|
|
328
|
+
if (requestId && lastEntry?.requestId === requestId) {
|
|
329
|
+
newLinearHistory[newLinearHistory.length - 1] = { ...lastEntry, stops: [...lastEntry.stops, snapshot], postEdit: undefined };
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
newLinearHistory.push({ requestId, startIndex: lastEntry ? lastEntry.startIndex + lastEntry.stops.length : 0, stops: [snapshot], postEdit: undefined });
|
|
333
|
+
}
|
|
334
|
+
transaction((tx) => {
|
|
335
|
+
const last = newLinearHistory[newLinearHistory.length - 1];
|
|
336
|
+
this._linearHistory.set(newLinearHistory, tx);
|
|
337
|
+
this._linearHistoryIndex.set(last.startIndex + last.stops.length, tx);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
_createSnapshot(requestId, undoStop) {
|
|
341
|
+
const workingSet = ( new ResourceMap(this._workingSet));
|
|
342
|
+
const entries = ( new ResourceMap());
|
|
343
|
+
for (const entry of this._entriesObs.get()) {
|
|
344
|
+
entries.set(entry.modifiedURI, entry.createSnapshot(requestId, undoStop));
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
stopId: undoStop,
|
|
348
|
+
workingSet,
|
|
349
|
+
entries,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
getSnapshot(requestId, undoStop, snapshotUri) {
|
|
353
|
+
const entries = undoStop === POST_EDIT_STOP_ID
|
|
354
|
+
? this._findSnapshot(requestId)?.postEdit
|
|
355
|
+
: this._findEditStop(requestId, undoStop)?.stop.entries;
|
|
356
|
+
return entries && [...( entries.values())].find((e) => isEqual(e.snapshotUri, snapshotUri));
|
|
357
|
+
}
|
|
358
|
+
async getSnapshotModel(requestId, undoStop, snapshotUri) {
|
|
359
|
+
const snapshotEntry = this.getSnapshot(requestId, undoStop, snapshotUri);
|
|
360
|
+
if (!snapshotEntry) {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
return this._modelService.createModel(snapshotEntry.current, this._languageService.createById(snapshotEntry.languageId), snapshotUri, false);
|
|
364
|
+
}
|
|
365
|
+
getSnapshotUri(requestId, uri, stopId) {
|
|
366
|
+
const stops = getCurrentAndNextStop(requestId, stopId, this._linearHistory.get());
|
|
367
|
+
return stops?.next.get(uri)?.snapshotUri;
|
|
368
|
+
}
|
|
369
|
+
async restoreSnapshot(requestId, stopId) {
|
|
370
|
+
if (requestId !== undefined) {
|
|
371
|
+
const stopRef = this._findEditStop(requestId, stopId);
|
|
372
|
+
if (stopRef) {
|
|
373
|
+
this._ensurePendingSnapshot();
|
|
374
|
+
await asyncTransaction(async (tx) => {
|
|
375
|
+
this._linearHistoryIndex.set(stopRef.historyIndex, tx);
|
|
376
|
+
await this._restoreSnapshot(stopRef.stop, tx);
|
|
377
|
+
});
|
|
378
|
+
this._updateRequestHiddenState();
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
const pendingSnapshot = this._pendingSnapshot;
|
|
383
|
+
if (!pendingSnapshot) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
this._pendingSnapshot = undefined;
|
|
387
|
+
await this._restoreSnapshot(pendingSnapshot, undefined);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
async _restoreSnapshot({ workingSet, entries }, tx, restoreResolvedToDisk = true) {
|
|
391
|
+
this._workingSet = ( new ResourceMap(workingSet));
|
|
392
|
+
for (const entry of this._entriesObs.get()) {
|
|
393
|
+
const snapshotEntry = entries.get(entry.modifiedURI);
|
|
394
|
+
if (!snapshotEntry) {
|
|
395
|
+
entry.resetToInitialContent();
|
|
396
|
+
entry.dispose();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const entriesArr = [];
|
|
400
|
+
for (const snapshotEntry of ( entries.values())) {
|
|
401
|
+
const entry = await this._getOrCreateModifiedFileEntry(snapshotEntry.resource, snapshotEntry.telemetryInfo);
|
|
402
|
+
const restoreToDisk = snapshotEntry.state === WorkingSetEntryState.Modified || restoreResolvedToDisk;
|
|
403
|
+
entry.restoreFromSnapshot(snapshotEntry, restoreToDisk);
|
|
404
|
+
entriesArr.push(entry);
|
|
405
|
+
}
|
|
406
|
+
this._entriesObs.set(entriesArr, tx);
|
|
407
|
+
}
|
|
408
|
+
remove(reason, ...uris) {
|
|
409
|
+
this._assertNotDisposed();
|
|
410
|
+
let didRemoveUris = false;
|
|
411
|
+
for (const uri of uris) {
|
|
412
|
+
const entry = this._entriesObs.get().find(e => isEqual(e.modifiedURI, uri));
|
|
413
|
+
if (entry) {
|
|
414
|
+
entry.dispose();
|
|
415
|
+
const newEntries = this._entriesObs.get().filter(e => !isEqual(e.modifiedURI, uri));
|
|
416
|
+
this._entriesObs.set(newEntries, undefined);
|
|
417
|
+
didRemoveUris = true;
|
|
418
|
+
}
|
|
419
|
+
const state = this._workingSet.get(uri);
|
|
420
|
+
if (state !== undefined) {
|
|
421
|
+
didRemoveUris = this._workingSet.delete(uri) || didRemoveUris;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (!didRemoveUris) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
428
|
+
}
|
|
429
|
+
_assertNotDisposed() {
|
|
430
|
+
if (this._state.get() === ChatEditingSessionState.Disposed) {
|
|
431
|
+
throw ( new BugIndicatingError(`Cannot access a disposed editing session`));
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
async accept(...uris) {
|
|
435
|
+
this._assertNotDisposed();
|
|
436
|
+
await asyncTransaction(async (tx) => {
|
|
437
|
+
if (uris.length === 0) {
|
|
438
|
+
await Promise.all(( this._entriesObs.get().map(entry => entry.accept(tx))));
|
|
439
|
+
}
|
|
440
|
+
for (const uri of uris) {
|
|
441
|
+
const entry = this._entriesObs.get().find(e => isEqual(e.modifiedURI, uri));
|
|
442
|
+
if (entry) {
|
|
443
|
+
await entry.accept(tx);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
this._accessibilitySignalService.playSignal(AccessibilitySignal.editsKept, { allowManyInParallel: true });
|
|
448
|
+
this._onDidChange.fire(ChatEditingSessionChangeType.Other);
|
|
449
|
+
}
|
|
450
|
+
async reject(...uris) {
|
|
451
|
+
this._assertNotDisposed();
|
|
452
|
+
await asyncTransaction(async (tx) => {
|
|
453
|
+
if (uris.length === 0) {
|
|
454
|
+
await Promise.all(( this._entriesObs.get().map(entry => entry.reject(tx))));
|
|
455
|
+
}
|
|
456
|
+
for (const uri of uris) {
|
|
457
|
+
const entry = this._entriesObs.get().find(e => isEqual(e.modifiedURI, uri));
|
|
458
|
+
if (entry) {
|
|
459
|
+
await entry.reject(tx);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
this._accessibilitySignalService.playSignal(AccessibilitySignal.editsUndone, { allowManyInParallel: true });
|
|
464
|
+
this._onDidChange.fire(ChatEditingSessionChangeType.Other);
|
|
465
|
+
}
|
|
466
|
+
async show() {
|
|
467
|
+
this._assertNotDisposed();
|
|
468
|
+
if (this._editorPane) {
|
|
469
|
+
if (this._editorPane.isVisible()) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
else if (this._editorPane.input) {
|
|
473
|
+
await this._editorGroupsService.activeGroup.openEditor(this._editorPane.input, { pinned: true, activation: EditorActivation.ACTIVATE });
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
const input = MultiDiffEditorInput.fromResourceMultiDiffEditorInput({
|
|
478
|
+
multiDiffSource: getMultiDiffSourceUri(this),
|
|
479
|
+
label: ( localize(4694, "Suggested Edits"))
|
|
480
|
+
}, this._instantiationService);
|
|
481
|
+
this._editorPane = await this._editorGroupsService.activeGroup.openEditor(input, { pinned: true, activation: EditorActivation.ACTIVATE });
|
|
482
|
+
}
|
|
483
|
+
async stop(clearState = false) {
|
|
484
|
+
this._stopPromise ??= Promise.allSettled([this._performStop(), this.storeState()]).then(() => { });
|
|
485
|
+
await this._stopPromise;
|
|
486
|
+
if (clearState) {
|
|
487
|
+
await this._instantiationService.createInstance(ChatEditingSessionStorage, this.chatSessionId).clearState();
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
async _performStop() {
|
|
491
|
+
const schemes = [AbstractChatEditingModifiedFileEntry.scheme, ChatEditingTextModelContentProvider.scheme];
|
|
492
|
+
await Promise.allSettled(this._editorGroupsService.groups.flatMap(async (g) => {
|
|
493
|
+
return ( g.editors.map(async (e) => {
|
|
494
|
+
if ((e instanceof MultiDiffEditorInput && e.initialResources?.some(r => r.originalUri && schemes.indexOf(r.originalUri.scheme) !== -1))
|
|
495
|
+
|| (e instanceof DiffEditorInput && e.original.resource && schemes.indexOf(e.original.resource.scheme) !== -1)) {
|
|
496
|
+
await g.closeEditor(e);
|
|
497
|
+
}
|
|
498
|
+
}));
|
|
499
|
+
}));
|
|
500
|
+
}
|
|
501
|
+
dispose() {
|
|
502
|
+
this._assertNotDisposed();
|
|
503
|
+
this._chatService.cancelCurrentRequestForSession(this.chatSessionId);
|
|
504
|
+
dispose(this._entriesObs.get());
|
|
505
|
+
super.dispose();
|
|
506
|
+
this._state.set(ChatEditingSessionState.Disposed, undefined);
|
|
507
|
+
this._onDidDispose.fire();
|
|
508
|
+
this._onDidDispose.dispose();
|
|
509
|
+
}
|
|
510
|
+
get isDisposed() {
|
|
511
|
+
return this._state.get() === ChatEditingSessionState.Disposed;
|
|
512
|
+
}
|
|
513
|
+
startStreamingEdits(resource, responseModel, inUndoStop) {
|
|
514
|
+
const completePromise = ( new DeferredPromise());
|
|
515
|
+
const startPromise = ( new DeferredPromise());
|
|
516
|
+
const sequencer = ( new ThrottledSequencer(15, 1000));
|
|
517
|
+
sequencer.queue(() => startPromise.p);
|
|
518
|
+
this._streamingEditLocks.queue(( resource.toString()), async () => {
|
|
519
|
+
if (!this.isDisposed) {
|
|
520
|
+
await this._acceptStreamingEditsStart(responseModel, inUndoStop, resource);
|
|
521
|
+
}
|
|
522
|
+
startPromise.complete();
|
|
523
|
+
return completePromise.p;
|
|
524
|
+
});
|
|
525
|
+
let didComplete = false;
|
|
526
|
+
return {
|
|
527
|
+
pushText: (edits) => {
|
|
528
|
+
sequencer.queue(async () => {
|
|
529
|
+
if (!this.isDisposed) {
|
|
530
|
+
await this._acceptEdits(resource, edits, false, responseModel);
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
},
|
|
534
|
+
pushNotebookCellText: (cell, edits) => {
|
|
535
|
+
sequencer.queue(async () => {
|
|
536
|
+
if (!this.isDisposed) {
|
|
537
|
+
await this._acceptEdits(cell, edits, false, responseModel);
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
},
|
|
541
|
+
pushNotebook: edits => {
|
|
542
|
+
sequencer.queue(async () => {
|
|
543
|
+
if (!this.isDisposed) {
|
|
544
|
+
await this._acceptEdits(resource, edits, false, responseModel);
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
},
|
|
548
|
+
complete: () => {
|
|
549
|
+
if (didComplete) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
didComplete = true;
|
|
553
|
+
sequencer.queue(async () => {
|
|
554
|
+
if (!this.isDisposed) {
|
|
555
|
+
await this._acceptEdits(resource, [], true, responseModel);
|
|
556
|
+
await this._resolve(responseModel.requestId, inUndoStop, resource);
|
|
557
|
+
completePromise.complete();
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
},
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
_getHistoryEntryByLinearIndex(index) {
|
|
564
|
+
const history = this._linearHistory.get();
|
|
565
|
+
const searchedIndex = binarySearch2(history.length, (e) => history[e].startIndex - index);
|
|
566
|
+
const entry = history[searchedIndex < 0 ? (~searchedIndex) - 1 : searchedIndex];
|
|
567
|
+
if (!entry || index - entry.startIndex >= entry.stops.length) {
|
|
568
|
+
return undefined;
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
entry,
|
|
572
|
+
stop: entry.stops[index - entry.startIndex]
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
async undoInteraction() {
|
|
576
|
+
const newIndex = this._linearHistoryIndex.get() - 1;
|
|
577
|
+
const previousSnapshot = this._getHistoryEntryByLinearIndex(newIndex);
|
|
578
|
+
if (!previousSnapshot) {
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
this._ensurePendingSnapshot();
|
|
582
|
+
await asyncTransaction(async (tx) => {
|
|
583
|
+
await this._restoreSnapshot(previousSnapshot.stop, tx);
|
|
584
|
+
this._linearHistoryIndex.set(newIndex, tx);
|
|
585
|
+
});
|
|
586
|
+
this._updateRequestHiddenState();
|
|
587
|
+
}
|
|
588
|
+
async redoInteraction() {
|
|
589
|
+
const maxIndex = getMaxHistoryIndex(this._linearHistory.get());
|
|
590
|
+
const newIndex = this._linearHistoryIndex.get() + 1;
|
|
591
|
+
if (newIndex > maxIndex) {
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
const nextSnapshot = newIndex === maxIndex ? this._pendingSnapshot : this._getHistoryEntryByLinearIndex(newIndex)?.stop;
|
|
595
|
+
if (!nextSnapshot) {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
await asyncTransaction(async (tx) => {
|
|
599
|
+
await this._restoreSnapshot(nextSnapshot, tx);
|
|
600
|
+
this._linearHistoryIndex.set(newIndex, tx);
|
|
601
|
+
});
|
|
602
|
+
this._updateRequestHiddenState();
|
|
603
|
+
}
|
|
604
|
+
_updateRequestHiddenState() {
|
|
605
|
+
const history = this._linearHistory.get();
|
|
606
|
+
const index = this._linearHistoryIndex.get();
|
|
607
|
+
const undoRequests = [];
|
|
608
|
+
for (const entry of history) {
|
|
609
|
+
if (!entry.requestId) ;
|
|
610
|
+
else if (entry.startIndex >= index) {
|
|
611
|
+
undoRequests.push({ requestId: entry.requestId });
|
|
612
|
+
}
|
|
613
|
+
else if (entry.startIndex + entry.stops.length > index) {
|
|
614
|
+
undoRequests.push({ requestId: entry.requestId, afterUndoStop: entry.stops[index - entry.startIndex].stopId });
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
this._chatService.getSession(this.chatSessionId)?.setDisabledRequests(undoRequests);
|
|
618
|
+
}
|
|
619
|
+
async _acceptStreamingEditsStart(responseModel, undoStop, resource) {
|
|
620
|
+
const entry = await this._getOrCreateModifiedFileEntry(resource, this._getTelemetryInfoForModel(responseModel));
|
|
621
|
+
transaction((tx) => {
|
|
622
|
+
this._state.set(ChatEditingSessionState.StreamingEdits, tx);
|
|
623
|
+
entry.acceptStreamingEditsStart(responseModel, tx);
|
|
624
|
+
this.ensureEditInUndoStopMatches(responseModel.requestId, undoStop, entry, false, tx);
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
ensureEditInUndoStopMatches(requestId, undoStop, entry, next, tx) {
|
|
628
|
+
const history = this._linearHistory.get();
|
|
629
|
+
const snapIndex = history.findIndex(s => s.requestId === requestId);
|
|
630
|
+
if (snapIndex === -1) {
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
const snap = history[snapIndex];
|
|
634
|
+
let stopIndex = snap.stops.findIndex(s => s.stopId === undoStop);
|
|
635
|
+
if (stopIndex === -1) {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (next) {
|
|
639
|
+
if (stopIndex === snap.stops.length - 1) {
|
|
640
|
+
const postEdit = ( new ResourceMap(snap.postEdit || this._createSnapshot(undefined, undefined).entries));
|
|
641
|
+
if (!snap.postEdit || !entry.equalsSnapshot(postEdit.get(entry.modifiedURI))) {
|
|
642
|
+
postEdit.set(entry.modifiedURI, entry.createSnapshot(requestId, POST_EDIT_STOP_ID));
|
|
643
|
+
const newHistory = history.slice();
|
|
644
|
+
newHistory[snapIndex] = { ...snap, postEdit };
|
|
645
|
+
this._linearHistory.set(newHistory, tx);
|
|
646
|
+
}
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
stopIndex++;
|
|
650
|
+
}
|
|
651
|
+
const stop = snap.stops[stopIndex];
|
|
652
|
+
if (entry.equalsSnapshot(stop.entries.get(entry.modifiedURI))) {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
const newMap = ( new ResourceMap(stop.entries));
|
|
656
|
+
newMap.set(entry.modifiedURI, entry.createSnapshot(requestId, stop.stopId));
|
|
657
|
+
const newStop = snap.stops.slice();
|
|
658
|
+
newStop[stopIndex] = { ...stop, entries: newMap };
|
|
659
|
+
const newHistory = history.slice();
|
|
660
|
+
newHistory[snapIndex] = { ...snap, stops: newStop };
|
|
661
|
+
this._linearHistory.set(newHistory, tx);
|
|
662
|
+
}
|
|
663
|
+
async _acceptEdits(resource, textEdits, isLastEdits, responseModel) {
|
|
664
|
+
const entry = await this._getOrCreateModifiedFileEntry(resource, this._getTelemetryInfoForModel(responseModel));
|
|
665
|
+
await entry.acceptAgentEdits(resource, textEdits, isLastEdits, responseModel);
|
|
666
|
+
}
|
|
667
|
+
_getTelemetryInfoForModel(responseModel) {
|
|
668
|
+
return new class {
|
|
669
|
+
get agentId() { return responseModel.agent?.id; }
|
|
670
|
+
get command() { return responseModel.slashCommand?.name; }
|
|
671
|
+
get sessionId() { return responseModel.session.sessionId; }
|
|
672
|
+
get requestId() { return responseModel.requestId; }
|
|
673
|
+
get result() { return responseModel.result; }
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
async _resolve(requestId, undoStop, resource) {
|
|
677
|
+
await asyncTransaction(async (tx) => {
|
|
678
|
+
const hasOtherTasks = ( Iterable.some(( this._streamingEditLocks.keys()), k => k !== ( resource.toString())));
|
|
679
|
+
if (!hasOtherTasks) {
|
|
680
|
+
this._state.set(ChatEditingSessionState.Idle, tx);
|
|
681
|
+
}
|
|
682
|
+
const entry = this._getEntry(resource);
|
|
683
|
+
if (!entry) {
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
this.ensureEditInUndoStopMatches(requestId, undoStop, entry, true, tx);
|
|
687
|
+
return entry.acceptStreamingEditsEnd(tx);
|
|
688
|
+
});
|
|
689
|
+
this._onDidChange.fire(ChatEditingSessionChangeType.Other);
|
|
690
|
+
}
|
|
691
|
+
async _getOrCreateModifiedFileEntry(resource, telemetryInfo) {
|
|
692
|
+
resource = CellUri.parse(resource)?.notebook ?? resource;
|
|
693
|
+
const existingEntry = this._entriesObs.get().find(e => isEqual(e.modifiedURI, resource));
|
|
694
|
+
if (existingEntry) {
|
|
695
|
+
if (telemetryInfo.requestId !== existingEntry.telemetryInfo.requestId) {
|
|
696
|
+
existingEntry.updateTelemetryInfo(telemetryInfo);
|
|
697
|
+
}
|
|
698
|
+
return existingEntry;
|
|
699
|
+
}
|
|
700
|
+
let entry;
|
|
701
|
+
const existingExternalEntry = this._lookupExternalEntry(resource);
|
|
702
|
+
if (existingExternalEntry) {
|
|
703
|
+
entry = existingExternalEntry;
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
const initialContent = this._initialFileContents.get(resource);
|
|
707
|
+
entry = await this._createModifiedFileEntry(resource, telemetryInfo, false, initialContent);
|
|
708
|
+
if (!initialContent) {
|
|
709
|
+
this._initialFileContents.set(resource, entry.initialContent);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
const listener = entry.onDidDelete(() => {
|
|
713
|
+
const newEntries = this._entriesObs.get().filter(e => !isEqual(e.modifiedURI, entry.modifiedURI));
|
|
714
|
+
this._entriesObs.set(newEntries, undefined);
|
|
715
|
+
this._workingSet.delete(entry.modifiedURI);
|
|
716
|
+
this._editorService.closeEditors(this._editorService.findEditors(entry.modifiedURI));
|
|
717
|
+
if (!existingExternalEntry) {
|
|
718
|
+
entry.dispose();
|
|
719
|
+
}
|
|
720
|
+
this._store.delete(listener);
|
|
721
|
+
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
722
|
+
});
|
|
723
|
+
this._store.add(listener);
|
|
724
|
+
const entriesArr = [...this._entriesObs.get(), entry];
|
|
725
|
+
this._entriesObs.set(entriesArr, undefined);
|
|
726
|
+
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
727
|
+
return entry;
|
|
728
|
+
}
|
|
729
|
+
async _createModifiedFileEntry(resource, telemetryInfo, mustExist = false, initialContent) {
|
|
730
|
+
const multiDiffEntryDelegate = { collapse: (transaction) => this._collapse(resource, transaction) };
|
|
731
|
+
const chatKind = mustExist ? ChatEditKind.Created : ChatEditKind.Modified;
|
|
732
|
+
const notebookUri = CellUri.parse(resource)?.notebook || resource;
|
|
733
|
+
try {
|
|
734
|
+
if (this._notebookService.hasSupportedNotebooks(notebookUri) && (this._notebookService.getNotebookTextModel(notebookUri) || ChatEditingModifiedNotebookEntry.canHandleSnapshotContent(initialContent))) {
|
|
735
|
+
return await ChatEditingModifiedNotebookEntry.create(notebookUri, multiDiffEntryDelegate, telemetryInfo, chatKind, initialContent, this._instantiationService);
|
|
736
|
+
}
|
|
737
|
+
else {
|
|
738
|
+
const ref = await this._textModelService.createModelReference(resource);
|
|
739
|
+
return this._instantiationService.createInstance(ChatEditingModifiedDocumentEntry, ref, multiDiffEntryDelegate, telemetryInfo, chatKind, initialContent);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
catch (err) {
|
|
743
|
+
if (mustExist) {
|
|
744
|
+
throw err;
|
|
745
|
+
}
|
|
746
|
+
await this._bulkEditService.apply({ edits: [{ newResource: resource }] });
|
|
747
|
+
this._editorService.openEditor({ resource, options: { inactive: true, preserveFocus: true, pinned: true } });
|
|
748
|
+
if (this._notebookService.hasSupportedNotebooks(notebookUri)) {
|
|
749
|
+
return await ChatEditingModifiedNotebookEntry.create(resource, multiDiffEntryDelegate, telemetryInfo, ChatEditKind.Created, initialContent, this._instantiationService);
|
|
750
|
+
}
|
|
751
|
+
else {
|
|
752
|
+
return this._createModifiedFileEntry(resource, telemetryInfo, true, initialContent);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
_collapse(resource, transaction) {
|
|
757
|
+
const multiDiffItem = this._editorPane?.findDocumentDiffItem(resource);
|
|
758
|
+
if (multiDiffItem) {
|
|
759
|
+
this._editorPane?.viewModel?.items.get().find((documentDiffItem) => isEqual(documentDiffItem.originalUri, multiDiffItem.originalUri) &&
|
|
760
|
+
isEqual(documentDiffItem.modifiedUri, multiDiffItem.modifiedUri))
|
|
761
|
+
?.collapsed.set(true, transaction);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
ChatEditingSession = ( __decorate([
|
|
766
|
+
( __param(3, IInstantiationService)),
|
|
767
|
+
( __param(4, IModelService)),
|
|
768
|
+
( __param(5, ILanguageService)),
|
|
769
|
+
( __param(6, ITextModelService)),
|
|
770
|
+
( __param(7, IBulkEditService)),
|
|
771
|
+
( __param(8, IEditorGroupsService)),
|
|
772
|
+
( __param(9, IEditorService)),
|
|
773
|
+
( __param(10, IChatService)),
|
|
774
|
+
( __param(11, INotebookService)),
|
|
775
|
+
( __param(12, IEditorWorkerService)),
|
|
776
|
+
( __param(13, IConfigurationService)),
|
|
777
|
+
( __param(14, IAccessibilitySignalService))
|
|
778
|
+
], ChatEditingSession));
|
|
779
|
+
let ChatEditingSessionStorage = class ChatEditingSessionStorage {
|
|
780
|
+
constructor(chatSessionId, _fileService, _environmentService, _logService, _workspaceContextService) {
|
|
781
|
+
this.chatSessionId = chatSessionId;
|
|
782
|
+
this._fileService = _fileService;
|
|
783
|
+
this._environmentService = _environmentService;
|
|
784
|
+
this._logService = _logService;
|
|
785
|
+
this._workspaceContextService = _workspaceContextService;
|
|
786
|
+
}
|
|
787
|
+
_getStorageLocation() {
|
|
788
|
+
const workspaceId = this._workspaceContextService.getWorkspace().id;
|
|
789
|
+
return joinPath(this._environmentService.workspaceStorageHome, workspaceId, 'chatEditingSessions', this.chatSessionId);
|
|
790
|
+
}
|
|
791
|
+
async restoreState() {
|
|
792
|
+
const storageLocation = this._getStorageLocation();
|
|
793
|
+
const fileContents = ( new Map());
|
|
794
|
+
const getFileContent = (hash) => {
|
|
795
|
+
let readPromise = fileContents.get(hash);
|
|
796
|
+
if (!readPromise) {
|
|
797
|
+
readPromise = this._fileService.readFile(joinPath(storageLocation, STORAGE_CONTENTS_FOLDER, hash)).then(content => ( content.value.toString()));
|
|
798
|
+
fileContents.set(hash, readPromise);
|
|
799
|
+
}
|
|
800
|
+
return readPromise;
|
|
801
|
+
};
|
|
802
|
+
const deserializeResourceMap = (resourceMap, deserialize, result) => {
|
|
803
|
+
resourceMap.forEach(([resourceURI, value]) => {
|
|
804
|
+
result.set(( URI.parse(resourceURI)), deserialize(value));
|
|
805
|
+
});
|
|
806
|
+
return result;
|
|
807
|
+
};
|
|
808
|
+
const deserializeSnapshotEntriesDTO = async (dtoEntries) => {
|
|
809
|
+
const entries = ( new ResourceMap());
|
|
810
|
+
for (const entryDTO of dtoEntries) {
|
|
811
|
+
const entry = await deserializeSnapshotEntry(entryDTO);
|
|
812
|
+
entries.set(entry.resource, entry);
|
|
813
|
+
}
|
|
814
|
+
return entries;
|
|
815
|
+
};
|
|
816
|
+
const deserializeChatEditingStopDTO = async (stopDTO) => {
|
|
817
|
+
const entries = await deserializeSnapshotEntriesDTO(stopDTO.entries);
|
|
818
|
+
const workingSet = deserializeResourceMap(stopDTO.workingSet, (value) => value, ( new ResourceMap()));
|
|
819
|
+
return { stopId: 'stopId' in stopDTO ? stopDTO.stopId : undefined, workingSet, entries };
|
|
820
|
+
};
|
|
821
|
+
const normalizeSnapshotDtos = (snapshot) => {
|
|
822
|
+
if ('stops' in snapshot) {
|
|
823
|
+
return snapshot;
|
|
824
|
+
}
|
|
825
|
+
return { requestId: snapshot.requestId, stops: [{ stopId: undefined, entries: snapshot.entries, workingSet: snapshot.workingSet }], postEdit: undefined };
|
|
826
|
+
};
|
|
827
|
+
const deserializeChatEditingSessionSnapshot = async (startIndex, snapshot) => {
|
|
828
|
+
const stops = await Promise.all(( snapshot.stops.map(deserializeChatEditingStopDTO)));
|
|
829
|
+
return { startIndex, requestId: snapshot.requestId, stops, postEdit: snapshot.postEdit && (await deserializeSnapshotEntriesDTO(snapshot.postEdit)) };
|
|
830
|
+
};
|
|
831
|
+
const deserializeSnapshotEntry = async (entry) => {
|
|
832
|
+
return {
|
|
833
|
+
resource: ( URI.parse(entry.resource)),
|
|
834
|
+
languageId: entry.languageId,
|
|
835
|
+
original: await getFileContent(entry.originalHash),
|
|
836
|
+
current: await getFileContent(entry.currentHash),
|
|
837
|
+
originalToCurrentEdit: OffsetEdit.fromJson(entry.originalToCurrentEdit),
|
|
838
|
+
state: entry.state,
|
|
839
|
+
snapshotUri: ( URI.parse(entry.snapshotUri)),
|
|
840
|
+
telemetryInfo: { requestId: entry.telemetryInfo.requestId, agentId: entry.telemetryInfo.agentId, command: entry.telemetryInfo.command, sessionId: this.chatSessionId, result: undefined }
|
|
841
|
+
};
|
|
842
|
+
};
|
|
843
|
+
try {
|
|
844
|
+
const stateFilePath = joinPath(storageLocation, STORAGE_STATE_FILE);
|
|
845
|
+
if (!(await this._fileService.exists(stateFilePath))) {
|
|
846
|
+
this._logService.debug(`chatEditingSession: No editing session state found at ${( stateFilePath.toString())}`);
|
|
847
|
+
return undefined;
|
|
848
|
+
}
|
|
849
|
+
this._logService.debug(`chatEditingSession: Restoring editing session at ${( stateFilePath.toString())}`);
|
|
850
|
+
const stateFileContent = await this._fileService.readFile(stateFilePath);
|
|
851
|
+
const data = JSON.parse(( stateFileContent.value.toString()));
|
|
852
|
+
if (!COMPATIBLE_STORAGE_VERSIONS.includes(data.version)) {
|
|
853
|
+
return undefined;
|
|
854
|
+
}
|
|
855
|
+
let linearHistoryIndex = 0;
|
|
856
|
+
const linearHistory = await Promise.all(( data.linearHistory.map(snapshot => {
|
|
857
|
+
const norm = normalizeSnapshotDtos(snapshot);
|
|
858
|
+
const result = deserializeChatEditingSessionSnapshot(linearHistoryIndex, norm);
|
|
859
|
+
linearHistoryIndex += norm.stops.length;
|
|
860
|
+
return result;
|
|
861
|
+
})));
|
|
862
|
+
const initialFileContents = ( new ResourceMap());
|
|
863
|
+
for (const fileContentDTO of data.initialFileContents) {
|
|
864
|
+
initialFileContents.set(( URI.parse(fileContentDTO[0])), await getFileContent(fileContentDTO[1]));
|
|
865
|
+
}
|
|
866
|
+
const pendingSnapshot = data.pendingSnapshot ? await deserializeChatEditingStopDTO(data.pendingSnapshot) : undefined;
|
|
867
|
+
const recentSnapshot = await deserializeChatEditingStopDTO(data.recentSnapshot);
|
|
868
|
+
return {
|
|
869
|
+
initialFileContents,
|
|
870
|
+
pendingSnapshot,
|
|
871
|
+
recentSnapshot,
|
|
872
|
+
linearHistoryIndex: data.linearHistoryIndex,
|
|
873
|
+
linearHistory
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
catch (e) {
|
|
877
|
+
this._logService.error(`Error restoring chat editing session from ${( storageLocation.toString())}`, e);
|
|
878
|
+
}
|
|
879
|
+
return undefined;
|
|
880
|
+
}
|
|
881
|
+
async storeState(state) {
|
|
882
|
+
const storageFolder = this._getStorageLocation();
|
|
883
|
+
const contentsFolder = URI.joinPath(storageFolder, STORAGE_CONTENTS_FOLDER);
|
|
884
|
+
const existingContents = ( new Set());
|
|
885
|
+
try {
|
|
886
|
+
const stat = await this._fileService.resolve(contentsFolder);
|
|
887
|
+
stat.children?.forEach(child => {
|
|
888
|
+
if (child.isFile) {
|
|
889
|
+
existingContents.add(child.name);
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
catch (e) {
|
|
894
|
+
try {
|
|
895
|
+
await this._fileService.createFolder(contentsFolder);
|
|
896
|
+
}
|
|
897
|
+
catch (e) {
|
|
898
|
+
this._logService.error(`Error creating chat editing session content folder ${( contentsFolder.toString())}`, e);
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
const fileContents = ( new Map());
|
|
903
|
+
const addFileContent = (content) => {
|
|
904
|
+
const shaComputer = ( new StringSHA1());
|
|
905
|
+
shaComputer.update(content);
|
|
906
|
+
const sha = shaComputer.digest().substring(0, 7);
|
|
907
|
+
fileContents.set(sha, content);
|
|
908
|
+
return sha;
|
|
909
|
+
};
|
|
910
|
+
const serializeResourceMap = (resourceMap, serialize) => {
|
|
911
|
+
return ( Array.from(resourceMap.entries()).map(([resourceURI, value]) => [( resourceURI.toString()), serialize(value)]));
|
|
912
|
+
};
|
|
913
|
+
const serializeChatEditingSessionStop = (stop) => {
|
|
914
|
+
return {
|
|
915
|
+
stopId: stop.stopId,
|
|
916
|
+
workingSet: serializeResourceMap(stop.workingSet, value => value),
|
|
917
|
+
entries: ( Array.from(( stop.entries.values())).map(serializeSnapshotEntry))
|
|
918
|
+
};
|
|
919
|
+
};
|
|
920
|
+
const serializeChatEditingSessionSnapshot = (snapshot) => {
|
|
921
|
+
return {
|
|
922
|
+
requestId: snapshot.requestId,
|
|
923
|
+
stops: ( snapshot.stops.map(serializeChatEditingSessionStop)),
|
|
924
|
+
postEdit: snapshot.postEdit ? ( Array.from(( snapshot.postEdit.values())).map(serializeSnapshotEntry)) : undefined
|
|
925
|
+
};
|
|
926
|
+
};
|
|
927
|
+
const serializeSnapshotEntry = (entry) => {
|
|
928
|
+
return {
|
|
929
|
+
resource: ( entry.resource.toString()),
|
|
930
|
+
languageId: entry.languageId,
|
|
931
|
+
originalHash: addFileContent(entry.original),
|
|
932
|
+
currentHash: addFileContent(entry.current),
|
|
933
|
+
originalToCurrentEdit: ( entry.originalToCurrentEdit.edits.map(
|
|
934
|
+
edit => ({ pos: edit.replaceRange.start, len: edit.replaceRange.length, txt: edit.newText })
|
|
935
|
+
)),
|
|
936
|
+
state: entry.state,
|
|
937
|
+
snapshotUri: ( entry.snapshotUri.toString()),
|
|
938
|
+
telemetryInfo: { requestId: entry.telemetryInfo.requestId, agentId: entry.telemetryInfo.agentId, command: entry.telemetryInfo.command }
|
|
939
|
+
};
|
|
940
|
+
};
|
|
941
|
+
try {
|
|
942
|
+
const data = {
|
|
943
|
+
version: STORAGE_VERSION,
|
|
944
|
+
sessionId: this.chatSessionId,
|
|
945
|
+
linearHistory: ( state.linearHistory.map(serializeChatEditingSessionSnapshot)),
|
|
946
|
+
linearHistoryIndex: state.linearHistoryIndex,
|
|
947
|
+
initialFileContents: serializeResourceMap(state.initialFileContents, value => addFileContent(value)),
|
|
948
|
+
pendingSnapshot: state.pendingSnapshot ? serializeChatEditingSessionStop(state.pendingSnapshot) : undefined,
|
|
949
|
+
recentSnapshot: serializeChatEditingSessionStop(state.recentSnapshot),
|
|
950
|
+
};
|
|
951
|
+
this._logService.debug(`chatEditingSession: Storing editing session at ${( storageFolder.toString())}: ${fileContents.size} files`);
|
|
952
|
+
for (const [hash, content] of fileContents) {
|
|
953
|
+
if (!( existingContents.has(hash))) {
|
|
954
|
+
await this._fileService.writeFile(joinPath(contentsFolder, hash), VSBuffer.fromString(content));
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
await this._fileService.writeFile(joinPath(storageFolder, STORAGE_STATE_FILE), VSBuffer.fromString(JSON.stringify(data, undefined, 2)));
|
|
958
|
+
}
|
|
959
|
+
catch (e) {
|
|
960
|
+
this._logService.debug(`Error storing chat editing session to ${( storageFolder.toString())}`, e);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
async clearState() {
|
|
964
|
+
const storageFolder = this._getStorageLocation();
|
|
965
|
+
if (await this._fileService.exists(storageFolder)) {
|
|
966
|
+
this._logService.debug(`chatEditingSession: Clearing editing session at ${( storageFolder.toString())}`);
|
|
967
|
+
try {
|
|
968
|
+
await this._fileService.del(storageFolder, { recursive: true });
|
|
969
|
+
}
|
|
970
|
+
catch (e) {
|
|
971
|
+
this._logService.debug(`Error clearing chat editing session from ${( storageFolder.toString())}`, e);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
ChatEditingSessionStorage = ( __decorate([
|
|
977
|
+
( __param(1, IFileService)),
|
|
978
|
+
( __param(2, IEnvironmentService)),
|
|
979
|
+
( __param(3, ILogService)),
|
|
980
|
+
( __param(4, IWorkspaceContextService))
|
|
981
|
+
], ChatEditingSessionStorage));
|
|
982
|
+
const COMPATIBLE_STORAGE_VERSIONS = [1, 2];
|
|
983
|
+
const STORAGE_VERSION = 2;
|
|
984
|
+
|
|
985
|
+
export { ChatEditingSession };
|