@codingame/monaco-vscode-chat-service-override 4.1.0 → 4.1.2
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/chat.js +9 -9
- package/external/tslib/tslib.es6.js +11 -0
- package/external/vscode-marked/lib/marked.esm.js +2200 -0
- package/override/vs/platform/dialogs/common/dialogs.js +10 -0
- package/package.json +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClear.js +17 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClearActions.js +115 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +503 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +82 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +77 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.js +110 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.js +171 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatTitleActions.js +271 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +317 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.js +60 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatContributionServiceImpl.js +423 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +98 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +285 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +90 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +185 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatHistoryVariables.js +26 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +618 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +600 -0
- package/vscode/src/vs/workbench/contrib/chat/common/voiceChat.js +141 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +40 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibleView.js +41 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatNotebook.js +72 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl.js +236 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/common/inlineChatServiceImpl.js +33 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { Emitter } from 'vscode/vscode/vs/base/common/event';
|
|
3
|
+
import { Disposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
4
|
+
import { rtrim } from 'vscode/vscode/vs/base/common/strings';
|
|
5
|
+
import 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
6
|
+
import { IChatAgentService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents';
|
|
7
|
+
import { chatAgentLeader, chatSubcommandLeader } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatParserTypes';
|
|
8
|
+
import { SpeechToTextStatus, ISpeechService } from 'vscode/vscode/vs/workbench/contrib/speech/common/speechService';
|
|
9
|
+
|
|
10
|
+
var VoiceChatService_1;
|
|
11
|
+
var PhraseTextType;
|
|
12
|
+
( (function(PhraseTextType) {
|
|
13
|
+
PhraseTextType[PhraseTextType["AGENT"] = 1] = "AGENT";
|
|
14
|
+
PhraseTextType[PhraseTextType["COMMAND"] = 2] = "COMMAND";
|
|
15
|
+
PhraseTextType[PhraseTextType["AGENT_AND_COMMAND"] = 3] = "AGENT_AND_COMMAND";
|
|
16
|
+
})(PhraseTextType || (PhraseTextType = {})));
|
|
17
|
+
let VoiceChatService = class VoiceChatService extends Disposable {
|
|
18
|
+
static { VoiceChatService_1 = this; }
|
|
19
|
+
static { this.AGENT_PREFIX = chatAgentLeader; }
|
|
20
|
+
static { this.COMMAND_PREFIX = chatSubcommandLeader; }
|
|
21
|
+
static { this.PHRASES_LOWER = {
|
|
22
|
+
[VoiceChatService_1.AGENT_PREFIX]: 'at',
|
|
23
|
+
[VoiceChatService_1.COMMAND_PREFIX]: 'slash'
|
|
24
|
+
}; }
|
|
25
|
+
static { this.PHRASES_UPPER = {
|
|
26
|
+
[VoiceChatService_1.AGENT_PREFIX]: 'At',
|
|
27
|
+
[VoiceChatService_1.COMMAND_PREFIX]: 'Slash'
|
|
28
|
+
}; }
|
|
29
|
+
static { this.CHAT_AGENT_ALIAS = ( new Map([['vscode', 'code']])); }
|
|
30
|
+
constructor(speechService, chatAgentService) {
|
|
31
|
+
super();
|
|
32
|
+
this.speechService = speechService;
|
|
33
|
+
this.chatAgentService = chatAgentService;
|
|
34
|
+
}
|
|
35
|
+
createPhrases(model) {
|
|
36
|
+
const phrases = ( new Map());
|
|
37
|
+
for (const agent of this.chatAgentService.getActivatedAgents()) {
|
|
38
|
+
const agentPhrase = `${VoiceChatService_1.PHRASES_LOWER[VoiceChatService_1.AGENT_PREFIX]} ${VoiceChatService_1.CHAT_AGENT_ALIAS.get(agent.id) ?? agent.id}`.toLowerCase();
|
|
39
|
+
phrases.set(agentPhrase, { agent: agent.id });
|
|
40
|
+
for (const slashCommand of agent.slashCommands) {
|
|
41
|
+
const slashCommandPhrase = `${VoiceChatService_1.PHRASES_LOWER[VoiceChatService_1.COMMAND_PREFIX]} ${slashCommand.name}`.toLowerCase();
|
|
42
|
+
phrases.set(slashCommandPhrase, { agent: agent.id, command: slashCommand.name });
|
|
43
|
+
const agentSlashCommandPhrase = `${agentPhrase} ${slashCommandPhrase}`.toLowerCase();
|
|
44
|
+
phrases.set(agentSlashCommandPhrase, { agent: agent.id, command: slashCommand.name });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return phrases;
|
|
48
|
+
}
|
|
49
|
+
toText(value, type) {
|
|
50
|
+
switch (type) {
|
|
51
|
+
case PhraseTextType.AGENT:
|
|
52
|
+
return `${VoiceChatService_1.AGENT_PREFIX}${value.agent}`;
|
|
53
|
+
case PhraseTextType.COMMAND:
|
|
54
|
+
return `${VoiceChatService_1.COMMAND_PREFIX}${value.command}`;
|
|
55
|
+
case PhraseTextType.AGENT_AND_COMMAND:
|
|
56
|
+
return `${VoiceChatService_1.AGENT_PREFIX}${value.agent} ${VoiceChatService_1.COMMAND_PREFIX}${value.command}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async createVoiceChatSession(token, options) {
|
|
60
|
+
const disposables = ( new DisposableStore());
|
|
61
|
+
disposables.add(token.onCancellationRequested(() => disposables.dispose()));
|
|
62
|
+
let detectedAgent = false;
|
|
63
|
+
let detectedSlashCommand = false;
|
|
64
|
+
const emitter = disposables.add(( new Emitter()));
|
|
65
|
+
const session = await this.speechService.createSpeechToTextSession(token, 'chat');
|
|
66
|
+
const phrases = this.createPhrases(options.model);
|
|
67
|
+
disposables.add(session.onDidChange(e => {
|
|
68
|
+
switch (e.status) {
|
|
69
|
+
case SpeechToTextStatus.Recognizing:
|
|
70
|
+
case SpeechToTextStatus.Recognized:
|
|
71
|
+
if (e.text) {
|
|
72
|
+
const startsWithAgent = e.text.startsWith(VoiceChatService_1.PHRASES_UPPER[VoiceChatService_1.AGENT_PREFIX]) || e.text.startsWith(VoiceChatService_1.PHRASES_LOWER[VoiceChatService_1.AGENT_PREFIX]);
|
|
73
|
+
const startsWithSlashCommand = e.text.startsWith(VoiceChatService_1.PHRASES_UPPER[VoiceChatService_1.COMMAND_PREFIX]) || e.text.startsWith(VoiceChatService_1.PHRASES_LOWER[VoiceChatService_1.COMMAND_PREFIX]);
|
|
74
|
+
if (startsWithAgent || startsWithSlashCommand) {
|
|
75
|
+
const originalWords = e.text.split(' ');
|
|
76
|
+
let transformedWords;
|
|
77
|
+
let waitingForInput = false;
|
|
78
|
+
if (options.usesAgents && startsWithAgent && !detectedAgent && !detectedSlashCommand && originalWords.length >= 4) {
|
|
79
|
+
const phrase = phrases.get(( originalWords.slice(0, 4).map(word => this.normalizeWord(word))).join(' '));
|
|
80
|
+
if (phrase) {
|
|
81
|
+
transformedWords = [this.toText(phrase, PhraseTextType.AGENT_AND_COMMAND), ...originalWords.slice(4)];
|
|
82
|
+
waitingForInput = originalWords.length === 4;
|
|
83
|
+
if (e.status === SpeechToTextStatus.Recognized) {
|
|
84
|
+
detectedAgent = true;
|
|
85
|
+
detectedSlashCommand = true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (options.usesAgents && startsWithAgent && !detectedAgent && !transformedWords && originalWords.length >= 2) {
|
|
90
|
+
const phrase = phrases.get(( originalWords.slice(0, 2).map(word => this.normalizeWord(word))).join(' '));
|
|
91
|
+
if (phrase) {
|
|
92
|
+
transformedWords = [this.toText(phrase, PhraseTextType.AGENT), ...originalWords.slice(2)];
|
|
93
|
+
waitingForInput = originalWords.length === 2;
|
|
94
|
+
if (e.status === SpeechToTextStatus.Recognized) {
|
|
95
|
+
detectedAgent = true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (startsWithSlashCommand && !detectedSlashCommand && !transformedWords && originalWords.length >= 2) {
|
|
100
|
+
const phrase = phrases.get(( originalWords.slice(0, 2).map(word => this.normalizeWord(word))).join(' '));
|
|
101
|
+
if (phrase) {
|
|
102
|
+
transformedWords = [this.toText(phrase, options.usesAgents && !detectedAgent ?
|
|
103
|
+
PhraseTextType.AGENT_AND_COMMAND :
|
|
104
|
+
PhraseTextType.COMMAND
|
|
105
|
+
), ...originalWords.slice(2)];
|
|
106
|
+
waitingForInput = originalWords.length === 2;
|
|
107
|
+
if (e.status === SpeechToTextStatus.Recognized) {
|
|
108
|
+
detectedSlashCommand = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
emitter.fire({
|
|
113
|
+
status: e.status,
|
|
114
|
+
text: (transformedWords ?? originalWords).join(' '),
|
|
115
|
+
waitingForInput
|
|
116
|
+
});
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
default:
|
|
121
|
+
emitter.fire(e);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}));
|
|
125
|
+
return {
|
|
126
|
+
onDidChange: emitter.event
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
normalizeWord(word) {
|
|
130
|
+
word = rtrim(word, '.');
|
|
131
|
+
word = rtrim(word, ',');
|
|
132
|
+
word = rtrim(word, '?');
|
|
133
|
+
return word.toLowerCase();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
VoiceChatService = VoiceChatService_1 = ( __decorate([
|
|
137
|
+
( __param(0, ISpeechService)),
|
|
138
|
+
( __param(1, IChatAgentService))
|
|
139
|
+
], VoiceChatService));
|
|
140
|
+
|
|
141
|
+
export { VoiceChatService };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { registerEditorContribution } from 'vscode/vscode/vs/editor/browser/editorExtensions';
|
|
2
|
+
import { registerAction2 } from 'vscode/vscode/vs/platform/actions/common/actions';
|
|
3
|
+
import { InlineChatController } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatController';
|
|
4
|
+
import { InlineAccessibilityHelpContribution, StartSessionAction, CloseAction, ConfigureInlineChatAction, UnstashSessionAction, ReRunRequestAction, ReRunRequestWithIntentDetectionAction, DiscardHunkAction, DiscardAction, DiscardToClipboardAction, DiscardUndoToNewFileAction, CancelSessionAction, MoveToNextHunk, MoveToPreviousHunk, ArrowOutUpAction, ArrowOutDownAction, FocusInlineChat, ViewInChatAction, ToggleDiffForChange, ReportIssueForBugCommand, AcceptChanges, CopyRecordings } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatActions';
|
|
5
|
+
import { INLINE_CHAT_ID, INTERACTIVE_EDITOR_ACCESSIBILITY_HELP_ID } from 'vscode/vscode/vs/workbench/contrib/inlineChat/common/inlineChat';
|
|
6
|
+
import '../common/inlineChatServiceImpl.js';
|
|
7
|
+
import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
|
|
8
|
+
import { InlineChatNotebookContribution } from './inlineChatNotebook.js';
|
|
9
|
+
import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
|
|
10
|
+
import './inlineChatSavingServiceImpl.js';
|
|
11
|
+
import { InlineChatAccessibleViewContribution } from './inlineChatAccessibleView.js';
|
|
12
|
+
import 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
13
|
+
import 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl';
|
|
14
|
+
|
|
15
|
+
registerEditorContribution(INLINE_CHAT_ID, InlineChatController, 0 );
|
|
16
|
+
registerEditorContribution(INTERACTIVE_EDITOR_ACCESSIBILITY_HELP_ID, InlineAccessibilityHelpContribution, 3 );
|
|
17
|
+
registerAction2(StartSessionAction);
|
|
18
|
+
registerAction2(CloseAction);
|
|
19
|
+
registerAction2(ConfigureInlineChatAction);
|
|
20
|
+
registerAction2(UnstashSessionAction);
|
|
21
|
+
registerAction2(ReRunRequestAction);
|
|
22
|
+
registerAction2(ReRunRequestWithIntentDetectionAction);
|
|
23
|
+
registerAction2(DiscardHunkAction);
|
|
24
|
+
registerAction2(DiscardAction);
|
|
25
|
+
registerAction2(DiscardToClipboardAction);
|
|
26
|
+
registerAction2(DiscardUndoToNewFileAction);
|
|
27
|
+
registerAction2(CancelSessionAction);
|
|
28
|
+
registerAction2(MoveToNextHunk);
|
|
29
|
+
registerAction2(MoveToPreviousHunk);
|
|
30
|
+
registerAction2(ArrowOutUpAction);
|
|
31
|
+
registerAction2(ArrowOutDownAction);
|
|
32
|
+
registerAction2(FocusInlineChat);
|
|
33
|
+
registerAction2(ViewInChatAction);
|
|
34
|
+
registerAction2(ToggleDiffForChange);
|
|
35
|
+
registerAction2(ReportIssueForBugCommand);
|
|
36
|
+
registerAction2(AcceptChanges);
|
|
37
|
+
registerAction2(CopyRecordings);
|
|
38
|
+
const workbenchContributionsRegistry = ( Registry.as(Extensions.Workbench));
|
|
39
|
+
workbenchContributionsRegistry.registerWorkbenchContribution(InlineChatNotebookContribution, 3 );
|
|
40
|
+
workbenchContributionsRegistry.registerWorkbenchContribution(InlineChatAccessibleViewContribution, 4 );
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { InlineChatController } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatController';
|
|
2
|
+
import { CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_RESPONSE_FOCUSED } from 'vscode/vscode/vs/workbench/contrib/inlineChat/common/inlineChat';
|
|
3
|
+
import { IAccessibleViewService } from 'vscode/vscode/vs/workbench/contrib/accessibility/browser/accessibleView';
|
|
4
|
+
import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
5
|
+
import { ICodeEditorService } from 'vscode/vscode/vs/editor/browser/services/codeEditorService';
|
|
6
|
+
import { ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
|
|
7
|
+
import { AccessibleViewAction } from 'vscode/vscode/vs/workbench/contrib/accessibility/browser/accessibleViewActions';
|
|
8
|
+
|
|
9
|
+
class InlineChatAccessibleViewContribution extends Disposable {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this._register(AccessibleViewAction.addImplementation(100, 'inlineChat', accessor => {
|
|
13
|
+
const accessibleViewService = accessor.get(IAccessibleViewService);
|
|
14
|
+
const codeEditorService = accessor.get(ICodeEditorService);
|
|
15
|
+
const editor = (codeEditorService.getActiveCodeEditor() || codeEditorService.getFocusedCodeEditor());
|
|
16
|
+
if (!editor) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const controller = InlineChatController.get(editor);
|
|
20
|
+
if (!controller) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const responseContent = controller?.getMessage();
|
|
24
|
+
if (!responseContent) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
accessibleViewService.show({
|
|
28
|
+
id: "inlineChat" ,
|
|
29
|
+
verbositySettingKey: "accessibility.verbosity.inlineChat" ,
|
|
30
|
+
provideContent() { return responseContent; },
|
|
31
|
+
onClose() {
|
|
32
|
+
controller.focus();
|
|
33
|
+
},
|
|
34
|
+
options: { type: "view" }
|
|
35
|
+
});
|
|
36
|
+
return true;
|
|
37
|
+
}, ( ContextKeyExpr.or(CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_RESPONSE_FOCUSED))));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { InlineChatAccessibleViewContribution };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { illegalState } from 'vscode/vscode/vs/base/common/errors';
|
|
3
|
+
import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
4
|
+
import { Schemas } from 'vscode/vscode/vs/base/common/network';
|
|
5
|
+
import { isEqual } from 'vscode/vscode/vs/base/common/resources';
|
|
6
|
+
import { InlineChatController } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatController';
|
|
7
|
+
import { IInlineChatSessionService } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService';
|
|
8
|
+
import { INotebookEditorService } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/services/notebookEditorService';
|
|
9
|
+
import { CellUri } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
|
|
10
|
+
|
|
11
|
+
let InlineChatNotebookContribution = class InlineChatNotebookContribution {
|
|
12
|
+
constructor(sessionService, notebookEditorService) {
|
|
13
|
+
this._store = ( new DisposableStore());
|
|
14
|
+
this._store.add(sessionService.registerSessionKeyComputer(Schemas.vscodeNotebookCell, {
|
|
15
|
+
getComparisonKey: (editor, uri) => {
|
|
16
|
+
const data = CellUri.parse(uri);
|
|
17
|
+
if (!data) {
|
|
18
|
+
throw illegalState('Expected notebook cell uri');
|
|
19
|
+
}
|
|
20
|
+
let fallback;
|
|
21
|
+
for (const notebookEditor of notebookEditorService.listNotebookEditors()) {
|
|
22
|
+
if (notebookEditor.hasModel() && isEqual(notebookEditor.textModel.uri, data.notebook)) {
|
|
23
|
+
const candidate = `<notebook>${notebookEditor.getId()}#${uri}`;
|
|
24
|
+
if (!fallback) {
|
|
25
|
+
fallback = candidate;
|
|
26
|
+
}
|
|
27
|
+
if (notebookEditor.codeEditors.find((tuple) => tuple[1] === editor)) {
|
|
28
|
+
return candidate;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (fallback) {
|
|
33
|
+
return fallback;
|
|
34
|
+
}
|
|
35
|
+
throw illegalState('Expected notebook editor');
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
this._store.add(sessionService.onWillStartSession(newSessionEditor => {
|
|
39
|
+
const candidate = CellUri.parse(newSessionEditor.getModel().uri);
|
|
40
|
+
if (!candidate) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
for (const notebookEditor of notebookEditorService.listNotebookEditors()) {
|
|
44
|
+
if (isEqual(notebookEditor.textModel?.uri, candidate.notebook)) {
|
|
45
|
+
let found = false;
|
|
46
|
+
const editors = [];
|
|
47
|
+
for (const [, codeEditor] of notebookEditor.codeEditors) {
|
|
48
|
+
editors.push(codeEditor);
|
|
49
|
+
found = codeEditor === newSessionEditor || found;
|
|
50
|
+
}
|
|
51
|
+
if (found) {
|
|
52
|
+
for (const editor of editors) {
|
|
53
|
+
if (editor !== newSessionEditor) {
|
|
54
|
+
InlineChatController.get(editor)?.finishExistingSession();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
dispose() {
|
|
64
|
+
this._store.dispose();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
InlineChatNotebookContribution = ( __decorate([
|
|
68
|
+
( __param(0, IInlineChatSessionService)),
|
|
69
|
+
( __param(1, INotebookEditorService))
|
|
70
|
+
], InlineChatNotebookContribution));
|
|
71
|
+
|
|
72
|
+
export { InlineChatNotebookContribution };
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { Queue, raceCancellation } from 'vscode/vscode/vs/base/common/async';
|
|
3
|
+
import { DisposableStore, MutableDisposable, dispose, combinedDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
4
|
+
import { isCodeEditor } from 'vscode/vscode/vs/editor/browser/editorBrowser';
|
|
5
|
+
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
6
|
+
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
|
|
7
|
+
import { IInlineChatSessionService } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService';
|
|
8
|
+
import { IEditorGroupsService } from 'vscode/vscode/vs/workbench/services/editor/common/editorGroupsService';
|
|
9
|
+
import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
|
|
10
|
+
import { IFilesConfigurationService } from 'vscode/vscode/vs/workbench/services/filesConfiguration/common/filesConfigurationService';
|
|
11
|
+
import { ITextFileService } from 'vscode/vscode/vs/workbench/services/textfile/common/textfiles';
|
|
12
|
+
import { Iterable } from 'vscode/vscode/vs/base/common/iterator';
|
|
13
|
+
import { Schemas } from 'vscode/vscode/vs/base/common/network';
|
|
14
|
+
import { CellUri } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
|
|
15
|
+
import { getNotebookEditorFromEditorPane } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
|
|
16
|
+
import { compare } from 'vscode/vscode/vs/base/common/strings';
|
|
17
|
+
import { IWorkingCopyFileService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyFileService';
|
|
18
|
+
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
19
|
+
import { Event } from 'vscode/vscode/vs/base/common/event';
|
|
20
|
+
import { InlineChatController } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatController';
|
|
21
|
+
|
|
22
|
+
let InlineChatSavingServiceImpl = class InlineChatSavingServiceImpl {
|
|
23
|
+
constructor(_fileConfigService, _editorGroupService, _textFileService, _editorService, _inlineChatSessionService, _configService, _workingCopyFileService, _logService) {
|
|
24
|
+
this._fileConfigService = _fileConfigService;
|
|
25
|
+
this._editorGroupService = _editorGroupService;
|
|
26
|
+
this._textFileService = _textFileService;
|
|
27
|
+
this._editorService = _editorService;
|
|
28
|
+
this._inlineChatSessionService = _inlineChatSessionService;
|
|
29
|
+
this._configService = _configService;
|
|
30
|
+
this._workingCopyFileService = _workingCopyFileService;
|
|
31
|
+
this._logService = _logService;
|
|
32
|
+
this._store = ( new DisposableStore());
|
|
33
|
+
this._saveParticipant = this._store.add(( new MutableDisposable()));
|
|
34
|
+
this._sessionData = ( new Map());
|
|
35
|
+
this._store.add(Event.any(_inlineChatSessionService.onDidEndSession, _inlineChatSessionService.onDidStashSession)(e => {
|
|
36
|
+
this._sessionData.get(e.session)?.dispose();
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
dispose() {
|
|
40
|
+
this._store.dispose();
|
|
41
|
+
dispose(( this._sessionData.values()));
|
|
42
|
+
}
|
|
43
|
+
markChanged(session) {
|
|
44
|
+
if (!( this._sessionData.has(session))) {
|
|
45
|
+
let uri = session.targetUri;
|
|
46
|
+
if (uri.scheme === Schemas.vscodeNotebookCell) {
|
|
47
|
+
const data = CellUri.parse(uri);
|
|
48
|
+
if (!data) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
uri = data?.notebook;
|
|
52
|
+
}
|
|
53
|
+
if (this._sessionData.size === 0) {
|
|
54
|
+
this._installSaveParticpant();
|
|
55
|
+
}
|
|
56
|
+
const saveConfigOverride = this._fileConfigService.disableAutoSave(uri);
|
|
57
|
+
this._sessionData.set(session, {
|
|
58
|
+
resourceUri: uri,
|
|
59
|
+
groupCandidate: this._editorGroupService.activeGroup,
|
|
60
|
+
session,
|
|
61
|
+
dispose: () => {
|
|
62
|
+
saveConfigOverride.dispose();
|
|
63
|
+
this._sessionData.delete(session);
|
|
64
|
+
if (this._sessionData.size === 0) {
|
|
65
|
+
this._saveParticipant.clear();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
_installSaveParticpant() {
|
|
72
|
+
const queue = ( new Queue());
|
|
73
|
+
const d1 = this._textFileService.files.addSaveParticipant({
|
|
74
|
+
participate: (model, ctx, progress, token) => {
|
|
75
|
+
return queue.queue(() => this._participate(ctx.savedFrom ?? model.textEditorModel?.uri, ctx.reason, progress, token));
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const d2 = this._workingCopyFileService.addSaveParticipant({
|
|
79
|
+
participate: (workingCopy, ctx, progress, token) => {
|
|
80
|
+
return queue.queue(() => this._participate(ctx.savedFrom ?? workingCopy.resource, ctx.reason, progress, token));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
this._saveParticipant.value = combinedDisposable(d1, d2, queue);
|
|
84
|
+
}
|
|
85
|
+
async _participate(uri, reason, progress, token) {
|
|
86
|
+
if (reason !== 1 ) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!this._configService.getValue("inlineChat.acceptedOrDiscardBeforeSave" )) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const sessions = ( new Map());
|
|
93
|
+
for (const [session, data] of this._sessionData) {
|
|
94
|
+
if (uri?.toString() === ( data.resourceUri.toString())) {
|
|
95
|
+
sessions.set(session, data);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (sessions.size === 0) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
progress.report({
|
|
102
|
+
message: sessions.size === 1
|
|
103
|
+
? ( localizeWithPath(
|
|
104
|
+
'vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl',
|
|
105
|
+
'inlineChat',
|
|
106
|
+
"Waiting for Inline Chat changes to be Accepted or Discarded..."
|
|
107
|
+
))
|
|
108
|
+
: ( localizeWithPath(
|
|
109
|
+
'vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl',
|
|
110
|
+
'inlineChat.N',
|
|
111
|
+
"Waiting for Inline Chat changes in {0} editors to be Accepted or Discarded...",
|
|
112
|
+
sessions.size
|
|
113
|
+
))
|
|
114
|
+
});
|
|
115
|
+
const { groups, orphans } = this._getGroupsAndOrphans(( sessions.values()));
|
|
116
|
+
const editorsOpenedAndSessionsEnded = this._openAndWait(groups, token).then(() => {
|
|
117
|
+
if (token.isCancellationRequested) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
return this._openAndWait(( Iterable.map(orphans, s => [this._editorGroupService.activeGroup, s])), token);
|
|
121
|
+
});
|
|
122
|
+
const allSessionsEnded = this._whenSessionsEnded(Iterable.concat(( groups.map(tuple => tuple[1])), orphans), token);
|
|
123
|
+
await Promise.race([allSessionsEnded, editorsOpenedAndSessionsEnded]);
|
|
124
|
+
}
|
|
125
|
+
_getGroupsAndOrphans(sessions) {
|
|
126
|
+
const groupByEditor = ( new Map());
|
|
127
|
+
for (const group of this._editorGroupService.getGroups(1 )) {
|
|
128
|
+
const candidate = group.activeEditorPane?.getControl();
|
|
129
|
+
if (isCodeEditor(candidate)) {
|
|
130
|
+
groupByEditor.set(candidate, group);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const groups = [];
|
|
134
|
+
const orphans = ( new Set());
|
|
135
|
+
for (const data of sessions) {
|
|
136
|
+
const editor = this._inlineChatSessionService.getCodeEditor(data.session);
|
|
137
|
+
const group = groupByEditor.get(editor);
|
|
138
|
+
if (group) {
|
|
139
|
+
groups.push([group, data]);
|
|
140
|
+
}
|
|
141
|
+
else if (this._editorGroupService.groups.includes(data.groupCandidate)) {
|
|
142
|
+
groups.push([data.groupCandidate, data]);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
orphans.add(data);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { groups, orphans };
|
|
149
|
+
}
|
|
150
|
+
async _openAndWait(groups, token) {
|
|
151
|
+
const dataByGroup = ( new Map());
|
|
152
|
+
for (const [group, data] of groups) {
|
|
153
|
+
let array = dataByGroup.get(group);
|
|
154
|
+
if (!array) {
|
|
155
|
+
array = [];
|
|
156
|
+
dataByGroup.set(group, array);
|
|
157
|
+
}
|
|
158
|
+
array.push(data);
|
|
159
|
+
}
|
|
160
|
+
for (const [group, array] of dataByGroup) {
|
|
161
|
+
if (token.isCancellationRequested) {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
array.sort((a, b) => compare(( a.session.targetUri.toString()), ( b.session.targetUri.toString())));
|
|
165
|
+
for (const data of array) {
|
|
166
|
+
const input = { resource: data.resourceUri };
|
|
167
|
+
const pane = await this._editorService.openEditor(input, group);
|
|
168
|
+
let editor;
|
|
169
|
+
if (data.session.targetUri.scheme === Schemas.vscodeNotebookCell) {
|
|
170
|
+
const notebookEditor = getNotebookEditorFromEditorPane(pane);
|
|
171
|
+
const uriData = CellUri.parse(data.session.targetUri);
|
|
172
|
+
if (notebookEditor && notebookEditor.hasModel() && uriData) {
|
|
173
|
+
const cell = notebookEditor.getCellByHandle(uriData.handle);
|
|
174
|
+
if (cell) {
|
|
175
|
+
await notebookEditor.revealRangeInCenterIfOutsideViewportAsync(cell, data.session.wholeRange.value);
|
|
176
|
+
}
|
|
177
|
+
const tuple = notebookEditor.codeEditors.find(tuple => tuple[1].getModel()?.uri.toString() === ( data.session.targetUri.toString()));
|
|
178
|
+
editor = tuple?.[1];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
if (isCodeEditor(pane?.getControl())) {
|
|
183
|
+
editor = pane.getControl();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (!editor) {
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
this._inlineChatSessionService.moveSession(data.session, editor);
|
|
190
|
+
InlineChatController.get(editor)?.showSaveHint();
|
|
191
|
+
this._logService.info('WAIT for session to end', editor.getId(), ( data.session.targetUri.toString()));
|
|
192
|
+
await this._whenSessionsEnded(Iterable.single(data), token);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async _whenSessionsEnded(iterable, token) {
|
|
197
|
+
const sessions = ( new Map());
|
|
198
|
+
for (const item of iterable) {
|
|
199
|
+
sessions.set(item.session, item);
|
|
200
|
+
}
|
|
201
|
+
if (sessions.size === 0) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
let listener;
|
|
205
|
+
const whenEnded = ( new Promise(resolve => {
|
|
206
|
+
listener = Event.any(this._inlineChatSessionService.onDidEndSession, this._inlineChatSessionService.onDidStashSession)(e => {
|
|
207
|
+
const data = sessions.get(e.session);
|
|
208
|
+
if (data) {
|
|
209
|
+
data.dispose();
|
|
210
|
+
sessions.delete(e.session);
|
|
211
|
+
if (sessions.size === 0) {
|
|
212
|
+
resolve();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}));
|
|
217
|
+
try {
|
|
218
|
+
await raceCancellation(whenEnded, token);
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
listener?.dispose();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
InlineChatSavingServiceImpl = ( __decorate([
|
|
226
|
+
( __param(0, IFilesConfigurationService)),
|
|
227
|
+
( __param(1, IEditorGroupsService)),
|
|
228
|
+
( __param(2, ITextFileService)),
|
|
229
|
+
( __param(3, IEditorService)),
|
|
230
|
+
( __param(4, IInlineChatSessionService)),
|
|
231
|
+
( __param(5, IConfigurationService)),
|
|
232
|
+
( __param(6, IWorkingCopyFileService)),
|
|
233
|
+
( __param(7, ILogService))
|
|
234
|
+
], InlineChatSavingServiceImpl));
|
|
235
|
+
|
|
236
|
+
export { InlineChatSavingServiceImpl };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
3
|
+
import { Emitter } from 'vscode/vscode/vs/base/common/event';
|
|
4
|
+
import { LinkedList } from 'vscode/vscode/vs/base/common/linkedList';
|
|
5
|
+
import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
|
|
6
|
+
import { CTX_INLINE_CHAT_HAS_PROVIDER } from 'vscode/vscode/vs/workbench/contrib/inlineChat/common/inlineChat';
|
|
7
|
+
|
|
8
|
+
let InlineChatServiceImpl = class InlineChatServiceImpl {
|
|
9
|
+
constructor(contextKeyService) {
|
|
10
|
+
this._onDidChangeProviders = ( new Emitter());
|
|
11
|
+
this._entries = ( new LinkedList());
|
|
12
|
+
this.onDidChangeProviders = this._onDidChangeProviders.event;
|
|
13
|
+
this._ctxHasProvider = CTX_INLINE_CHAT_HAS_PROVIDER.bindTo(contextKeyService);
|
|
14
|
+
}
|
|
15
|
+
addProvider(provider) {
|
|
16
|
+
const rm = this._entries.push(provider);
|
|
17
|
+
this._ctxHasProvider.set(true);
|
|
18
|
+
this._onDidChangeProviders.fire({ added: provider });
|
|
19
|
+
return toDisposable(() => {
|
|
20
|
+
rm();
|
|
21
|
+
this._ctxHasProvider.set(this._entries.size > 0);
|
|
22
|
+
this._onDidChangeProviders.fire({ removed: provider });
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
getAllProvider() {
|
|
26
|
+
return [...this._entries].reverse();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
InlineChatServiceImpl = ( __decorate([
|
|
30
|
+
( __param(0, IContextKeyService))
|
|
31
|
+
], InlineChatServiceImpl));
|
|
32
|
+
|
|
33
|
+
export { InlineChatServiceImpl };
|