@opensumi/ide-ai-native 3.2.4 → 3.2.5-next-1724062137.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/lib/browser/ai-core.contribution.d.ts +1 -0
- package/lib/browser/ai-core.contribution.d.ts.map +1 -1
- package/lib/browser/ai-core.contribution.js +14 -25
- package/lib/browser/ai-core.contribution.js.map +1 -1
- package/lib/browser/ai-editor.contribution.d.ts +1 -0
- package/lib/browser/ai-editor.contribution.d.ts.map +1 -1
- package/lib/browser/ai-editor.contribution.js +8 -0
- package/lib/browser/ai-editor.contribution.js.map +1 -1
- package/lib/browser/chat/chat-agent.service.d.ts +1 -0
- package/lib/browser/chat/chat-agent.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-agent.service.js +1 -3
- package/lib/browser/chat/chat-agent.service.js.map +1 -1
- package/lib/browser/chat/chat.view.d.ts.map +1 -1
- package/lib/browser/chat/chat.view.js +22 -4
- package/lib/browser/chat/chat.view.js.map +1 -1
- package/lib/browser/components/ChatEditor.d.ts +2 -1
- package/lib/browser/components/ChatEditor.d.ts.map +1 -1
- package/lib/browser/components/ChatEditor.js +8 -8
- package/lib/browser/components/ChatEditor.js.map +1 -1
- package/lib/browser/components/ChatMarkdown.d.ts +1 -0
- package/lib/browser/components/ChatMarkdown.d.ts.map +1 -1
- package/lib/browser/components/ChatMarkdown.js +2 -2
- package/lib/browser/components/ChatMarkdown.js.map +1 -1
- package/lib/browser/components/ChatThinking.d.ts.map +1 -1
- package/lib/browser/components/ChatThinking.js +2 -2
- package/lib/browser/components/ChatThinking.js.map +1 -1
- package/lib/browser/contextkey/ai-native.contextkey.service.d.ts +1 -0
- package/lib/browser/contextkey/ai-native.contextkey.service.d.ts.map +1 -1
- package/lib/browser/contextkey/ai-native.contextkey.service.js +1 -0
- package/lib/browser/contextkey/ai-native.contextkey.service.js.map +1 -1
- package/lib/browser/contrib/inline-completions/completeProvider.d.ts +4 -31
- package/lib/browser/contrib/inline-completions/completeProvider.d.ts.map +1 -1
- package/lib/browser/contrib/inline-completions/completeProvider.js +3 -224
- package/lib/browser/contrib/inline-completions/completeProvider.js.map +1 -1
- package/lib/browser/contrib/inline-completions/inline-completions.handler.d.ts +1 -3
- package/lib/browser/contrib/inline-completions/inline-completions.handler.d.ts.map +1 -1
- package/lib/browser/contrib/inline-completions/inline-completions.handler.js +8 -20
- package/lib/browser/contrib/inline-completions/inline-completions.handler.js.map +1 -1
- package/lib/browser/contrib/inline-completions/model/competionModel.d.ts +2 -2
- package/lib/browser/contrib/inline-completions/model/competionModel.d.ts.map +1 -1
- package/lib/browser/contrib/inline-completions/model/inlineCompletionRequestTask.d.ts +28 -0
- package/lib/browser/contrib/inline-completions/model/inlineCompletionRequestTask.d.ts.map +1 -0
- package/lib/browser/contrib/inline-completions/model/inlineCompletionRequestTask.js +210 -0
- package/lib/browser/contrib/inline-completions/model/inlineCompletionRequestTask.js.map +1 -0
- package/lib/browser/contrib/inline-completions/promptCache.d.ts +3 -2
- package/lib/browser/contrib/inline-completions/promptCache.d.ts.map +1 -1
- package/lib/browser/contrib/inline-completions/promptCache.js.map +1 -1
- package/lib/browser/contrib/inline-completions/service/ai-completions.service.d.ts +7 -6
- package/lib/browser/contrib/inline-completions/service/ai-completions.service.d.ts.map +1 -1
- package/lib/browser/contrib/inline-completions/service/ai-completions.service.js +48 -25
- package/lib/browser/contrib/inline-completions/service/ai-completions.service.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/diff-computer.d.ts +18 -0
- package/lib/browser/contrib/intelligent-completions/diff-computer.d.ts.map +1 -0
- package/lib/browser/contrib/intelligent-completions/diff-computer.js +144 -0
- package/lib/browser/contrib/intelligent-completions/diff-computer.js.map +1 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.d.ts +8 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.d.ts.map +1 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.js +47 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.js.map +1 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.d.ts +15 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.d.ts.map +1 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.feature.registry.d.ts +8 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.feature.registry.d.ts.map +1 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.feature.registry.js +19 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.feature.registry.js.map +1 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.handler.d.ts +20 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.handler.d.ts.map +1 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.handler.js +94 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.handler.js.map +1 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.js +3 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.js.map +1 -0
- package/lib/browser/contrib/intelligent-completions/multi-line.decoration.d.ts +33 -0
- package/lib/browser/contrib/intelligent-completions/multi-line.decoration.d.ts.map +1 -0
- package/lib/browser/contrib/intelligent-completions/multi-line.decoration.js +258 -0
- package/lib/browser/contrib/intelligent-completions/multi-line.decoration.js.map +1 -0
- package/lib/browser/contrib/merge-conflict/merge-conflict.feature.registry.d.ts +0 -1
- package/lib/browser/contrib/merge-conflict/merge-conflict.feature.registry.d.ts.map +1 -1
- package/lib/browser/contrib/merge-conflict/merge-conflict.feature.registry.js +0 -3
- package/lib/browser/contrib/merge-conflict/merge-conflict.feature.registry.js.map +1 -1
- package/lib/browser/contrib/rename/rename.handler.d.ts.map +1 -1
- package/lib/browser/contrib/rename/rename.handler.js +1 -0
- package/lib/browser/contrib/rename/rename.handler.js.map +1 -1
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +7 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/layout/ai-layout.d.ts.map +1 -1
- package/lib/browser/layout/ai-layout.js +4 -4
- package/lib/browser/layout/ai-layout.js.map +1 -1
- package/lib/browser/model/enhanceDecorationsCollection.d.ts +38 -4
- package/lib/browser/model/enhanceDecorationsCollection.d.ts.map +1 -1
- package/lib/browser/model/enhanceDecorationsCollection.js +44 -23
- package/lib/browser/model/enhanceDecorationsCollection.js.map +1 -1
- package/lib/browser/types.d.ts +20 -13
- package/lib/browser/types.d.ts.map +1 -1
- package/lib/browser/types.js +0 -4
- package/lib/browser/types.js.map +1 -1
- package/lib/browser/widget/inline-chat/inline-chat.handler.d.ts.map +1 -1
- package/lib/browser/widget/inline-chat/inline-chat.handler.js +31 -12
- package/lib/browser/widget/inline-chat/inline-chat.handler.js.map +1 -1
- package/lib/browser/widget/inline-chat/inline-content-widget.d.ts +5 -2
- package/lib/browser/widget/inline-chat/inline-content-widget.d.ts.map +1 -1
- package/lib/browser/widget/inline-chat/inline-content-widget.js +45 -53
- package/lib/browser/widget/inline-chat/inline-content-widget.js.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-previewer.d.ts +20 -14
- package/lib/browser/widget/inline-diff/inline-diff-previewer.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-previewer.js +114 -46
- package/lib/browser/widget/inline-diff/inline-diff-previewer.js.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-widget.d.ts +5 -2
- package/lib/browser/widget/inline-diff/inline-diff-widget.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-widget.js +3 -0
- package/lib/browser/widget/inline-diff/inline-diff-widget.js.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff.handler.d.ts +13 -13
- package/lib/browser/widget/inline-diff/inline-diff.handler.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff.handler.js +71 -76
- package/lib/browser/widget/inline-diff/inline-diff.handler.js.map +1 -1
- package/lib/browser/widget/inline-input/inline-input-widget.d.ts +1 -0
- package/lib/browser/widget/inline-input/inline-input-widget.d.ts.map +1 -1
- package/lib/browser/widget/inline-input/inline-input-widget.js +1 -0
- package/lib/browser/widget/inline-input/inline-input-widget.js.map +1 -1
- package/lib/browser/widget/inline-input/inline-input.handler.js +2 -2
- package/lib/browser/widget/inline-input/inline-input.handler.js.map +1 -1
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.d.ts +28 -15
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.d.ts.map +1 -1
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.js +52 -31
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.js.map +1 -1
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.module.less +9 -6
- package/lib/browser/widget/inline-stream-diff/live-preview-stack.d.ts +21 -0
- package/lib/browser/widget/inline-stream-diff/live-preview-stack.d.ts.map +1 -0
- package/lib/browser/widget/inline-stream-diff/live-preview-stack.js +41 -0
- package/lib/browser/widget/inline-stream-diff/live-preview-stack.js.map +1 -0
- package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts +105 -0
- package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts.map +1 -0
- package/lib/browser/widget/inline-stream-diff/live-preview.component.js +237 -0
- package/lib/browser/widget/inline-stream-diff/live-preview.component.js.map +1 -0
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.d.ts +27 -103
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.d.ts.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.js +185 -369
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.js.map +1 -1
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js.map +1 -1
- package/package.json +19 -19
- package/src/browser/ai-core.contribution.ts +14 -28
- package/src/browser/ai-editor.contribution.ts +9 -0
- package/src/browser/chat/chat-agent.service.ts +1 -3
- package/src/browser/chat/chat.view.tsx +49 -4
- package/src/browser/components/ChatEditor.tsx +21 -7
- package/src/browser/components/ChatMarkdown.tsx +8 -2
- package/src/browser/components/ChatThinking.tsx +3 -1
- package/src/browser/contextkey/ai-native.contextkey.service.ts +3 -0
- package/src/browser/contrib/inline-completions/completeProvider.ts +7 -289
- package/src/browser/contrib/inline-completions/inline-completions.handler.ts +15 -22
- package/src/browser/contrib/inline-completions/model/competionModel.ts +3 -2
- package/src/browser/contrib/inline-completions/model/inlineCompletionRequestTask.ts +272 -0
- package/src/browser/contrib/inline-completions/promptCache.ts +3 -2
- package/src/browser/contrib/inline-completions/service/ai-completions.service.ts +55 -38
- package/src/browser/contrib/intelligent-completions/diff-computer.ts +185 -0
- package/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts +54 -0
- package/src/browser/contrib/intelligent-completions/intelligent-completions.feature.registry.ts +17 -0
- package/src/browser/contrib/intelligent-completions/intelligent-completions.handler.ts +130 -0
- package/src/browser/contrib/intelligent-completions/intelligent-completions.ts +15 -0
- package/src/browser/contrib/intelligent-completions/multi-line.decoration.ts +325 -0
- package/src/browser/contrib/merge-conflict/merge-conflict.feature.registry.ts +0 -4
- package/src/browser/contrib/rename/rename.handler.ts +1 -0
- package/src/browser/index.ts +8 -1
- package/src/browser/layout/ai-layout.tsx +7 -1
- package/src/browser/model/enhanceDecorationsCollection.ts +71 -34
- package/src/browser/types.ts +27 -14
- package/src/browser/widget/inline-chat/inline-chat.handler.ts +34 -19
- package/src/browser/widget/inline-chat/inline-content-widget.tsx +58 -61
- package/src/browser/widget/inline-diff/inline-diff-previewer.ts +118 -61
- package/src/browser/widget/inline-diff/inline-diff-widget.tsx +8 -2
- package/src/browser/widget/inline-diff/inline-diff.handler.ts +83 -92
- package/src/browser/widget/inline-input/inline-input-widget.tsx +1 -0
- package/src/browser/widget/inline-input/inline-input.handler.ts +2 -2
- package/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx +98 -44
- package/src/browser/widget/inline-stream-diff/inline-stream-diff.module.less +9 -6
- package/src/browser/widget/inline-stream-diff/live-preview-stack.ts +52 -0
- package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +388 -0
- package/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx +243 -543
- package/src/common/index.ts +2 -0
|
@@ -21,13 +21,12 @@ import { EResultKind } from '../inline-chat/inline-chat.service';
|
|
|
21
21
|
import {
|
|
22
22
|
BaseInlineDiffPreviewer,
|
|
23
23
|
IDiffPreviewerOptions,
|
|
24
|
-
IExtendedSerializedState,
|
|
25
24
|
LiveInlineDiffPreviewer,
|
|
26
25
|
SideBySideInlineDiffWidget,
|
|
27
26
|
} from '../inline-diff/inline-diff-previewer';
|
|
28
27
|
import { InlineDiffWidget } from '../inline-diff/inline-diff-widget';
|
|
29
28
|
import { InlineStreamDiffHandler } from '../inline-stream-diff/inline-stream-diff.handler';
|
|
30
|
-
import { IPartialEditEvent } from '../inline-stream-diff/live-preview.
|
|
29
|
+
import { IPartialEditEvent } from '../inline-stream-diff/live-preview.component';
|
|
31
30
|
|
|
32
31
|
@Injectable()
|
|
33
32
|
export class InlineDiffHandler extends IAIMonacoContribHandler {
|
|
@@ -51,70 +50,85 @@ export class InlineDiffHandler extends IAIMonacoContribHandler {
|
|
|
51
50
|
private readonly _onMaxLineCount = new Emitter<number>();
|
|
52
51
|
public readonly onMaxLineCount: Event<number> = this._onMaxLineCount.event;
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
monaco.ICodeEditor,
|
|
56
|
-
BaseInlineDiffPreviewer<InlineDiffWidget | InlineStreamDiffHandler> | undefined
|
|
57
|
-
>();
|
|
53
|
+
private previewer: BaseInlineDiffPreviewer<InlineDiffWidget | InlineStreamDiffHandler> | undefined;
|
|
58
54
|
|
|
59
|
-
|
|
55
|
+
private _previewerNodeStore = new Map<string, InlineStreamDiffHandler | null>();
|
|
60
56
|
|
|
61
57
|
constructor() {
|
|
62
58
|
super();
|
|
63
|
-
this.registerDispose(
|
|
59
|
+
this.registerDispose(
|
|
60
|
+
this.eventBus.on(EditorGroupCloseEvent, (e: EditorGroupCloseEvent) => {
|
|
61
|
+
const uriString = e.payload.resource.uri.toString();
|
|
62
|
+
const node = this._previewerNodeStore.get(uriString);
|
|
63
|
+
|
|
64
|
+
if (node && node.previewerOptions.disposeWhenEditorClosed) {
|
|
65
|
+
this.destroyPreviewer(uriString);
|
|
66
|
+
}
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
64
69
|
}
|
|
70
|
+
|
|
65
71
|
doContribute(): IDisposable {
|
|
66
72
|
this.logger.log('InlineDiffHandler doContribute');
|
|
67
73
|
return Disposable.NULL;
|
|
68
74
|
}
|
|
69
75
|
|
|
70
|
-
storeState(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
storeState(key: string) {
|
|
77
|
+
if (!this.previewer) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 存储的是快照
|
|
82
|
+
const node = this.previewer.createNodeSnapshot();
|
|
83
|
+
if (node) {
|
|
84
|
+
this._previewerNodeStore.set(key, node as InlineStreamDiffHandler);
|
|
77
85
|
}
|
|
78
|
-
return previous;
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
tryRestoreState(monacoEditor: monaco.ICodeEditor, key: string) {
|
|
82
|
-
const
|
|
83
|
-
if (!
|
|
89
|
+
const node = this._previewerNodeStore.get(key);
|
|
90
|
+
if (!node) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (node.disposed) {
|
|
95
|
+
this.destroyPreviewer(key);
|
|
84
96
|
return;
|
|
85
97
|
}
|
|
86
98
|
|
|
87
|
-
return this.restoreState(monacoEditor,
|
|
99
|
+
return this.restoreState(monacoEditor, node);
|
|
88
100
|
}
|
|
89
101
|
|
|
90
|
-
restoreState(monacoEditor: monaco.ICodeEditor,
|
|
91
|
-
const
|
|
92
|
-
if (oldDiffPreviewer) {
|
|
93
|
-
oldDiffPreviewer.dispose();
|
|
94
|
-
}
|
|
102
|
+
restoreState(monacoEditor: monaco.ICodeEditor, node: InlineStreamDiffHandler) {
|
|
103
|
+
const uri = monacoEditor.getModel()?.uri;
|
|
95
104
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
previewer.
|
|
99
|
-
}
|
|
105
|
+
if (uri) {
|
|
106
|
+
this.previewer = this.injector.get(LiveInlineDiffPreviewer, [monacoEditor]);
|
|
107
|
+
this.previewer.attachNode(node);
|
|
100
108
|
|
|
101
|
-
|
|
109
|
+
const dispose = this.previewer.onDispose(() => {
|
|
110
|
+
this.destroyPreviewer();
|
|
111
|
+
dispose.dispose();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
registerInlineDiffFeature(editor: IEditor): IDisposable {
|
|
105
117
|
const disposable = new Disposable();
|
|
106
118
|
|
|
107
119
|
const monacoEditor = editor.monacoEditor;
|
|
120
|
+
const model = monacoEditor.getModel();
|
|
108
121
|
|
|
109
122
|
disposable.addDispose(
|
|
110
123
|
monacoEditor.onWillChangeModel((e) => {
|
|
111
124
|
if (!e.oldModelUrl) {
|
|
112
125
|
return;
|
|
113
126
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
127
|
+
|
|
128
|
+
const urlString = e.oldModelUrl.toString();
|
|
129
|
+
this.storeState(urlString);
|
|
130
|
+
|
|
131
|
+
this.destroyPreviewer();
|
|
118
132
|
}),
|
|
119
133
|
);
|
|
120
134
|
|
|
@@ -127,16 +141,16 @@ export class InlineDiffHandler extends IAIMonacoContribHandler {
|
|
|
127
141
|
}),
|
|
128
142
|
);
|
|
129
143
|
|
|
130
|
-
|
|
131
|
-
|
|
144
|
+
if (model) {
|
|
145
|
+
disposable.addDispose(
|
|
146
|
+
model.onWillDispose(() => {
|
|
147
|
+
const uriString = model.uri.toString();
|
|
148
|
+
this.destroyPreviewer(uriString);
|
|
149
|
+
}),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
132
152
|
|
|
133
|
-
|
|
134
|
-
const leadingWhitespaceMatch = crossCode.match(/^\s*/);
|
|
135
|
-
const indent = leadingWhitespaceMatch ? leadingWhitespaceMatch[0] : ' ';
|
|
136
|
-
return answer
|
|
137
|
-
.split('\n')
|
|
138
|
-
.map((line) => `${indent}${line}`)
|
|
139
|
-
.join('\n');
|
|
153
|
+
return disposable;
|
|
140
154
|
}
|
|
141
155
|
|
|
142
156
|
showPreviewerByStream(
|
|
@@ -195,87 +209,64 @@ export class InlineDiffHandler extends IAIMonacoContribHandler {
|
|
|
195
209
|
}
|
|
196
210
|
|
|
197
211
|
createDiffPreviewer(monacoEditor: monaco.ICodeEditor, selection: monaco.Selection, options?: IDiffPreviewerOptions) {
|
|
198
|
-
let previewer: BaseInlineDiffPreviewer<InlineDiffWidget | InlineStreamDiffHandler>;
|
|
199
|
-
|
|
200
212
|
const inlineDiffMode = this.preferenceService.getValid<EInlineDiffPreviewMode>(
|
|
201
213
|
AINativeSettingSectionsId.InlineDiffPreviewMode,
|
|
202
214
|
EInlineDiffPreviewMode.inlineLive,
|
|
203
215
|
);
|
|
216
|
+
|
|
217
|
+
this.destroyPreviewer();
|
|
218
|
+
|
|
204
219
|
if (inlineDiffMode === EInlineDiffPreviewMode.sideBySide) {
|
|
205
|
-
previewer = this.injector.get(SideBySideInlineDiffWidget, [monacoEditor
|
|
220
|
+
this.previewer = this.injector.get(SideBySideInlineDiffWidget, [monacoEditor]);
|
|
206
221
|
} else {
|
|
207
|
-
previewer = this.injector.get(LiveInlineDiffPreviewer, [monacoEditor
|
|
222
|
+
this.previewer = this.injector.get(LiveInlineDiffPreviewer, [monacoEditor]);
|
|
208
223
|
}
|
|
209
224
|
|
|
210
|
-
previewer.
|
|
211
|
-
|
|
212
|
-
const previous = this._editorsStore.get(monacoEditor);
|
|
225
|
+
this.previewer.create(selection, options);
|
|
226
|
+
this.previewer.show(selection.startLineNumber - 1, selection.endLineNumber - selection.startLineNumber + 2);
|
|
213
227
|
|
|
214
|
-
|
|
228
|
+
this.listenPreviewer(this.previewer);
|
|
215
229
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
previewer.dispose();
|
|
219
|
-
});
|
|
220
|
-
}
|
|
230
|
+
return this.previewer;
|
|
231
|
+
}
|
|
221
232
|
|
|
222
|
-
|
|
223
|
-
|
|
233
|
+
private listenPreviewer(previewer: BaseInlineDiffPreviewer<InlineDiffWidget | InlineStreamDiffHandler> | undefined) {
|
|
234
|
+
if (!previewer) {
|
|
235
|
+
return;
|
|
224
236
|
}
|
|
225
237
|
|
|
226
|
-
this._editorsStore.set(monacoEditor, previewer);
|
|
227
|
-
|
|
228
238
|
if (previewer instanceof LiveInlineDiffPreviewer) {
|
|
229
239
|
previewer.addDispose(
|
|
230
|
-
previewer.onPartialEditEvent((event) => {
|
|
240
|
+
previewer.onPartialEditEvent!((event) => {
|
|
231
241
|
this._onPartialEditEvent.fire(event);
|
|
232
242
|
}),
|
|
233
243
|
);
|
|
234
244
|
}
|
|
235
245
|
|
|
236
246
|
previewer.addDispose(previewer.onLineCount((lineCount) => this._onMaxLineCount.fire(lineCount)));
|
|
237
|
-
return previewer;
|
|
238
247
|
}
|
|
239
248
|
|
|
240
|
-
getPreviewer(
|
|
241
|
-
|
|
242
|
-
): BaseInlineDiffPreviewer<InlineDiffWidget | InlineStreamDiffHandler> | undefined {
|
|
243
|
-
return this._editorsStore.get(monacoEditor);
|
|
249
|
+
getPreviewer(): BaseInlineDiffPreviewer<InlineDiffWidget | InlineStreamDiffHandler> | undefined {
|
|
250
|
+
return this.previewer;
|
|
244
251
|
}
|
|
245
252
|
|
|
246
|
-
handleAction(
|
|
247
|
-
|
|
248
|
-
if (diffPreviewer) {
|
|
249
|
-
diffPreviewer.handleAction(action);
|
|
250
|
-
}
|
|
253
|
+
handleAction(action: EResultKind): void {
|
|
254
|
+
this.previewer?.handleAction(action);
|
|
251
255
|
}
|
|
252
256
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if (diffPreviewer) {
|
|
256
|
-
diffPreviewer.dispose();
|
|
257
|
-
this._editorsStore.delete(monacoEditor);
|
|
258
|
-
}
|
|
257
|
+
getModifyContent() {
|
|
258
|
+
return this.previewer?.getValueByEnd();
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
destroyPreviewer(uriString?: string) {
|
|
262
|
+
this.previewer?.dispose();
|
|
263
|
+
this.previewer = undefined;
|
|
264
|
+
if (uriString) {
|
|
265
|
+
this._previewerNodeStore.delete(uriString);
|
|
265
266
|
}
|
|
266
267
|
}
|
|
267
268
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const previewer = this._editorsStore.get(e.payload.group.codeEditor.monacoEditor);
|
|
272
|
-
|
|
273
|
-
if (previewer) {
|
|
274
|
-
if (previewer.disposeWhenEditorClosed && previewer.isModel(uriString)) {
|
|
275
|
-
previewer.dispose();
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
this._store.delete(uriString);
|
|
269
|
+
revealFirstDiff() {
|
|
270
|
+
this.previewer?.revealFirstDiff();
|
|
280
271
|
}
|
|
281
272
|
}
|
|
@@ -88,6 +88,7 @@ export class InlineInputChatWidget extends AIInlineContentWidget {
|
|
|
88
88
|
@Autowired(InlineInputChatService)
|
|
89
89
|
private inlineInputChatService: InlineInputChatService;
|
|
90
90
|
|
|
91
|
+
allowEditorOverflow = true;
|
|
91
92
|
positionPreference = [ContentWidgetPositionPreference.ABOVE];
|
|
92
93
|
|
|
93
94
|
override dispose(): void {
|
|
@@ -74,8 +74,8 @@ export class InlineInputHandler extends Disposable {
|
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
if (strategy === ERunStrategy.PREVIEW && handler.
|
|
78
|
-
const previewResponse = await handler.
|
|
77
|
+
if (strategy === ERunStrategy.PREVIEW && handler.providePreviewStrategy) {
|
|
78
|
+
const previewResponse = await handler.providePreviewStrategy(monacoEditor, value, this.cancelIndicator.token);
|
|
79
79
|
|
|
80
80
|
if (CancelResponse.is(previewResponse)) {
|
|
81
81
|
widget.launchChatStatus(EInlineChatStatus.READY);
|
|
@@ -11,13 +11,11 @@ import { LineTokens } from '@opensumi/monaco-editor-core/esm/vs/editor/common/to
|
|
|
11
11
|
import { UndoRedoGroup } from '@opensumi/monaco-editor-core/esm/vs/platform/undoRedo/common/undoRedo';
|
|
12
12
|
|
|
13
13
|
import { IDecorationSerializableState } from '../../model/enhanceDecorationsCollection';
|
|
14
|
+
import { IDiffPreviewerOptions, IInlineDiffPreviewerNode } from '../inline-diff/inline-diff-previewer';
|
|
14
15
|
|
|
15
16
|
import { InlineStreamDiffComputer } from './inline-stream-diff-computer';
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
LivePreviewDiffDecorationModel,
|
|
19
|
-
SerializableState,
|
|
20
|
-
} from './live-preview.decoration';
|
|
17
|
+
import { IRemovedWidgetState } from './live-preview.component';
|
|
18
|
+
import { ILivePreviewDiffDecorationSnapshotData, LivePreviewDiffDecorationModel } from './live-preview.decoration';
|
|
21
19
|
|
|
22
20
|
interface IRangeChangeData {
|
|
23
21
|
removedTextLines: string[];
|
|
@@ -43,25 +41,36 @@ export enum EComputerMode {
|
|
|
43
41
|
default = 'default',
|
|
44
42
|
}
|
|
45
43
|
|
|
44
|
+
export interface IInlineStreamDiffSnapshotData {
|
|
45
|
+
rawOriginalTextLines: string[];
|
|
46
|
+
rawOriginalTextLinesTokens: LineTokens[];
|
|
47
|
+
undoRedoGroup: UndoRedoGroup;
|
|
48
|
+
decorationSnapshotData: ILivePreviewDiffDecorationSnapshotData;
|
|
49
|
+
previewerOptions: IDiffPreviewerOptions;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const inlineStreamDiffComputer = new InlineStreamDiffComputer();
|
|
53
|
+
|
|
46
54
|
@Injectable({ multiple: true })
|
|
47
|
-
export class InlineStreamDiffHandler extends Disposable {
|
|
55
|
+
export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPreviewerNode {
|
|
48
56
|
@Autowired(INJECTOR_TOKEN)
|
|
49
57
|
private readonly injector: Injector;
|
|
50
58
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
private rawOriginalTextLinesTokens: LineTokens[] = [];
|
|
59
|
+
protected readonly _onDidEditChange = this.registerDispose(new Emitter<void>());
|
|
60
|
+
public readonly onDidEditChange: Event<void> = this._onDidEditChange.event;
|
|
54
61
|
|
|
55
|
-
|
|
62
|
+
public previewerOptions: IDiffPreviewerOptions;
|
|
56
63
|
|
|
57
|
-
private
|
|
64
|
+
private livePreviewDiffDecorationModel: LivePreviewDiffDecorationModel;
|
|
58
65
|
private originalModel: ITextModel;
|
|
59
|
-
private
|
|
66
|
+
private virtualModel: ITextModel;
|
|
60
67
|
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
// Parts that require snapshots
|
|
69
|
+
private rawOriginalTextLines: string[];
|
|
70
|
+
private rawOriginalTextLinesTokens: LineTokens[] = [];
|
|
71
|
+
private undoRedoGroup: UndoRedoGroup;
|
|
63
72
|
|
|
64
|
-
constructor(private readonly monacoEditor: ICodeEditor
|
|
73
|
+
constructor(private readonly monacoEditor: ICodeEditor) {
|
|
65
74
|
super();
|
|
66
75
|
|
|
67
76
|
this.undoRedoGroup = new UndoRedoGroup();
|
|
@@ -70,9 +79,25 @@ export class InlineStreamDiffHandler extends Disposable {
|
|
|
70
79
|
this.virtualModel = modelService.createModel('', null);
|
|
71
80
|
this.originalModel = this.monacoEditor.getModel()!;
|
|
72
81
|
|
|
82
|
+
this.livePreviewDiffDecorationModel = this.injector.get(LivePreviewDiffDecorationModel, [this.monacoEditor]);
|
|
83
|
+
this.addDispose(this.livePreviewDiffDecorationModel);
|
|
84
|
+
|
|
85
|
+
// 将 diff handler 和 decoration model 的生命周期绑定在一起
|
|
86
|
+
const dispose = this.livePreviewDiffDecorationModel.onDispose(() => {
|
|
87
|
+
this.dispose();
|
|
88
|
+
dispose.dispose();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
setPreviewerOptions(options: IDiffPreviewerOptions): void {
|
|
93
|
+
this.previewerOptions = options;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
initialize(selection: Selection): void {
|
|
73
97
|
const eol = this.originalModel.getEOL();
|
|
74
|
-
const startPosition =
|
|
75
|
-
const endPosition =
|
|
98
|
+
const startPosition = selection.getStartPosition();
|
|
99
|
+
const endPosition = selection.getEndPosition();
|
|
100
|
+
|
|
76
101
|
this.rawOriginalTextLines = this.originalModel
|
|
77
102
|
.getValueInRange(Range.fromPositions(startPosition, endPosition))
|
|
78
103
|
.split(eol);
|
|
@@ -84,16 +109,52 @@ export class InlineStreamDiffHandler extends Disposable {
|
|
|
84
109
|
return lineTokens;
|
|
85
110
|
});
|
|
86
111
|
|
|
87
|
-
|
|
112
|
+
const zone = LineRange.fromRangeInclusive(
|
|
113
|
+
Range.fromPositions(
|
|
114
|
+
{ lineNumber: selection.startLineNumber, column: 1 },
|
|
115
|
+
{ lineNumber: selection.endLineNumber, column: Number.MAX_SAFE_INTEGER },
|
|
116
|
+
),
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
this.livePreviewDiffDecorationModel.initialize(zone);
|
|
88
120
|
}
|
|
89
121
|
|
|
90
|
-
private
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
122
|
+
private _snapshotStore: IInlineStreamDiffSnapshotData | undefined;
|
|
123
|
+
restoreSnapshot(snapshot: IInlineStreamDiffSnapshotData): void {
|
|
124
|
+
this._snapshotStore = snapshot;
|
|
125
|
+
const {
|
|
126
|
+
rawOriginalTextLines,
|
|
127
|
+
rawOriginalTextLinesTokens,
|
|
128
|
+
undoRedoGroup,
|
|
129
|
+
decorationSnapshotData,
|
|
130
|
+
previewerOptions,
|
|
131
|
+
} = snapshot;
|
|
95
132
|
|
|
96
|
-
this.
|
|
133
|
+
this.setPreviewerOptions(previewerOptions);
|
|
134
|
+
|
|
135
|
+
this.rawOriginalTextLines = rawOriginalTextLines;
|
|
136
|
+
this.rawOriginalTextLinesTokens = rawOriginalTextLinesTokens;
|
|
137
|
+
this.undoRedoGroup = undoRedoGroup;
|
|
138
|
+
|
|
139
|
+
this.livePreviewDiffDecorationModel.initialize(decorationSnapshotData.zone);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
get currentSnapshotStore(): IInlineStreamDiffSnapshotData | undefined {
|
|
143
|
+
return this._snapshotStore;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
restoreDecorationSnapshot(decorationSnapshotData: ILivePreviewDiffDecorationSnapshotData): void {
|
|
147
|
+
this.livePreviewDiffDecorationModel.restoreSnapshot(decorationSnapshotData);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
createSnapshot(): IInlineStreamDiffSnapshotData {
|
|
151
|
+
return {
|
|
152
|
+
rawOriginalTextLines: this.rawOriginalTextLines,
|
|
153
|
+
rawOriginalTextLinesTokens: this.rawOriginalTextLinesTokens,
|
|
154
|
+
undoRedoGroup: this.undoRedoGroup,
|
|
155
|
+
decorationSnapshotData: this.livePreviewDiffDecorationModel.createSnapshot(),
|
|
156
|
+
previewerOptions: this.previewerOptions,
|
|
157
|
+
};
|
|
97
158
|
}
|
|
98
159
|
|
|
99
160
|
get onPartialEditWidgetListChange() {
|
|
@@ -106,7 +167,7 @@ export class InlineStreamDiffHandler extends Disposable {
|
|
|
106
167
|
computerMode: EComputerMode = EComputerMode.default,
|
|
107
168
|
): IComputeDiffData {
|
|
108
169
|
const computeResult = (
|
|
109
|
-
computerMode === EComputerMode.default ?
|
|
170
|
+
computerMode === EComputerMode.default ? inlineStreamDiffComputer : linesDiffComputers.getLegacy()
|
|
110
171
|
).computeDiff(originalTextLines, newTextLines, {
|
|
111
172
|
computeMoves: false,
|
|
112
173
|
maxComputationTimeMs: 200,
|
|
@@ -184,10 +245,6 @@ export class InlineStreamDiffHandler extends Disposable {
|
|
|
184
245
|
};
|
|
185
246
|
}
|
|
186
247
|
|
|
187
|
-
public getZone(): LineRange {
|
|
188
|
-
return this.livePreviewDiffDecorationModel.getZone();
|
|
189
|
-
}
|
|
190
|
-
|
|
191
248
|
private calculateAddedDecorationCollectionState(diffModel: IComputeDiffData): IDecorationSerializableState[] {
|
|
192
249
|
const zone = this.getZone();
|
|
193
250
|
|
|
@@ -211,7 +268,6 @@ export class InlineStreamDiffHandler extends Disposable {
|
|
|
211
268
|
|
|
212
269
|
private renderPartialEditWidgets(diffModel: IComputeDiffData): void {
|
|
213
270
|
const decorationRange = this.calculateAddedDecorationCollectionState(diffModel);
|
|
214
|
-
|
|
215
271
|
this.livePreviewDiffDecorationModel.touchPartialEditWidgets(decorationRange.map((v) => v.startPosition.lineNumber));
|
|
216
272
|
}
|
|
217
273
|
|
|
@@ -226,7 +282,7 @@ export class InlineStreamDiffHandler extends Disposable {
|
|
|
226
282
|
|
|
227
283
|
let preRemovedLen: number = 0;
|
|
228
284
|
|
|
229
|
-
const states = [] as
|
|
285
|
+
const states = [] as IRemovedWidgetState[];
|
|
230
286
|
|
|
231
287
|
for (const change of changes) {
|
|
232
288
|
const { removedTextLines, removedLinesOriginalRange, addedRange } = change;
|
|
@@ -255,12 +311,10 @@ export class InlineStreamDiffHandler extends Disposable {
|
|
|
255
311
|
* 一旦撤销到最顶层则关闭当前的 inline diff
|
|
256
312
|
*/
|
|
257
313
|
private pushStackElement(): void {
|
|
258
|
-
this.livePreviewDiffDecorationModel.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
},
|
|
263
|
-
group: this.undoRedoGroup,
|
|
314
|
+
const stack = this.livePreviewDiffDecorationModel.createEditStackElement(this.undoRedoGroup);
|
|
315
|
+
stack.attachModel(this.livePreviewDiffDecorationModel);
|
|
316
|
+
stack.registerUndo((decorationModel) => {
|
|
317
|
+
decorationModel.dispose();
|
|
264
318
|
});
|
|
265
319
|
}
|
|
266
320
|
|
|
@@ -377,7 +431,7 @@ export class InlineStreamDiffHandler extends Disposable {
|
|
|
377
431
|
|
|
378
432
|
public recompute(computerMode: EComputerMode, newContent?: string): IComputeDiffData {
|
|
379
433
|
if (newContent) {
|
|
380
|
-
this.virtualModel.setValue(newContent);
|
|
434
|
+
this.virtualModel.setValue(newContent.trim());
|
|
381
435
|
}
|
|
382
436
|
|
|
383
437
|
const newTextLines = this.virtualModel.getLinesContent();
|
|
@@ -440,21 +494,21 @@ export class InlineStreamDiffHandler extends Disposable {
|
|
|
440
494
|
return this.livePreviewDiffDecorationModel.onPartialEditEvent;
|
|
441
495
|
}
|
|
442
496
|
|
|
443
|
-
serializeState(): SerializableState {
|
|
444
|
-
return this.livePreviewDiffDecorationModel.serializeState();
|
|
445
|
-
}
|
|
446
|
-
restoreState(state: SerializableState): void {
|
|
447
|
-
this.livePreviewDiffDecorationModel.restoreSerializedState(state);
|
|
448
|
-
}
|
|
449
497
|
acceptAll(): void {
|
|
450
498
|
this.livePreviewDiffDecorationModel.acceptUnProcessed();
|
|
451
499
|
this.dispose();
|
|
452
500
|
}
|
|
501
|
+
|
|
453
502
|
rejectAll(): void {
|
|
454
503
|
this.livePreviewDiffDecorationModel.discardUnProcessed();
|
|
455
504
|
this.dispose();
|
|
456
505
|
}
|
|
506
|
+
|
|
457
507
|
revealFirstDiff() {
|
|
458
508
|
this.livePreviewDiffDecorationModel.revealFirstDiff();
|
|
459
509
|
}
|
|
510
|
+
|
|
511
|
+
getZone(): LineRange {
|
|
512
|
+
return this.livePreviewDiffDecorationModel.getZone();
|
|
513
|
+
}
|
|
460
514
|
}
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
width: 1e6px;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
@line-height: 18px;
|
|
38
|
+
|
|
37
39
|
.inline_diff_accept_partial_widget_container {
|
|
38
40
|
width: 100%;
|
|
39
41
|
|
|
@@ -42,9 +44,9 @@
|
|
|
42
44
|
display: flex;
|
|
43
45
|
border-radius: 4px;
|
|
44
46
|
overflow: hidden;
|
|
45
|
-
margin-right:
|
|
46
|
-
max-height:
|
|
47
|
-
height:
|
|
47
|
+
margin-right: 12px;
|
|
48
|
+
max-height: @line-height;
|
|
49
|
+
height: @line-height;
|
|
48
50
|
align-items: center;
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -53,16 +55,17 @@
|
|
|
53
55
|
border: none;
|
|
54
56
|
font-size: 12px;
|
|
55
57
|
cursor: pointer;
|
|
56
|
-
padding: 2px;
|
|
58
|
+
padding: 2px 6px;
|
|
59
|
+
height: @line-height;
|
|
57
60
|
|
|
58
61
|
&.accept_btn {
|
|
59
62
|
background-color: var(--aiNative-inlineDiffAcceptPartialEdit);
|
|
60
|
-
color:
|
|
63
|
+
color: var(--aiNative-inlineDiffAcceptPartialEdit-foreground);
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
&.discard_btn {
|
|
64
67
|
background-color: var(--aiNative-inlineDiffDiscardPartialEdit);
|
|
65
|
-
color:
|
|
68
|
+
color: var(--aiNative-inlineDiffAcceptPartialEdit-foreground);
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ITextModel, Uri } from '@opensumi/ide-monaco';
|
|
2
|
+
import {
|
|
3
|
+
IResourceUndoRedoElement,
|
|
4
|
+
UndoRedoElementType,
|
|
5
|
+
} from '@opensumi/monaco-editor-core/esm/vs/platform/undoRedo/common/undoRedo';
|
|
6
|
+
|
|
7
|
+
import { LivePreviewDiffDecorationModel } from './live-preview.decoration';
|
|
8
|
+
|
|
9
|
+
export class LivePreviewUndoRedoStackElement implements IResourceUndoRedoElement {
|
|
10
|
+
private decorationModel: LivePreviewDiffDecorationModel;
|
|
11
|
+
|
|
12
|
+
get type(): UndoRedoElementType.Resource {
|
|
13
|
+
return UndoRedoElementType.Resource;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get label(): string {
|
|
17
|
+
return 'Live.Preview.UndoRedo';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get code(): string {
|
|
21
|
+
return 'Live.Preview.UndoRedo';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get resource(): Uri {
|
|
25
|
+
return this.model.uri;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
confirmBeforeUndo = false;
|
|
29
|
+
|
|
30
|
+
constructor(private readonly model: ITextModel) {}
|
|
31
|
+
|
|
32
|
+
attachModel(newDecorationModel: LivePreviewDiffDecorationModel): void {
|
|
33
|
+
this.decorationModel = newDecorationModel;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private _undo: (model: LivePreviewDiffDecorationModel) => void;
|
|
37
|
+
registerUndo(undo: (model: LivePreviewDiffDecorationModel) => void): void {
|
|
38
|
+
this._undo = undo;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
undo(): void | Promise<void> {
|
|
42
|
+
this._undo?.(this.decorationModel);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private _redo: (model: LivePreviewDiffDecorationModel) => void;
|
|
46
|
+
registerRedo(redo: (model: LivePreviewDiffDecorationModel) => void): void {
|
|
47
|
+
this._redo = redo;
|
|
48
|
+
}
|
|
49
|
+
redo() {
|
|
50
|
+
this._redo?.(this.decorationModel);
|
|
51
|
+
}
|
|
52
|
+
}
|