@opensumi/ide-ai-native 3.7.1-next-1739781685.0 → 3.7.1
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.contextkeys.d.ts +0 -1
- package/lib/browser/ai-core.contextkeys.d.ts.map +1 -1
- package/lib/browser/ai-core.contextkeys.js +0 -1
- package/lib/browser/ai-core.contextkeys.js.map +1 -1
- package/lib/browser/ai-core.contribution.d.ts +1 -2
- package/lib/browser/ai-core.contribution.d.ts.map +1 -1
- package/lib/browser/ai-core.contribution.js +15 -60
- package/lib/browser/ai-core.contribution.js.map +1 -1
- package/lib/browser/components/ChatMarkdown.d.ts.map +1 -1
- package/lib/browser/components/ChatMarkdown.js.map +1 -1
- package/lib/browser/components/WelcomeMsg.js.map +1 -1
- package/lib/browser/components/utils.d.ts +2 -2
- package/lib/browser/contrib/intelligent-completions/index.d.ts +9 -14
- package/lib/browser/contrib/intelligent-completions/index.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/index.js +1 -6
- package/lib/browser/contrib/intelligent-completions/index.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.d.ts +0 -1
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.js +4 -26
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.d.ts +4 -5
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.js +42 -50
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/source/base.d.ts +3 -9
- package/lib/browser/contrib/intelligent-completions/source/base.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/source/base.js +3 -21
- package/lib/browser/contrib/intelligent-completions/source/base.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/source/line-change.source.d.ts +3 -10
- package/lib/browser/contrib/intelligent-completions/source/line-change.source.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/source/line-change.source.js +22 -95
- package/lib/browser/contrib/intelligent-completions/source/line-change.source.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/source/lint-error.source.d.ts +3 -1
- package/lib/browser/contrib/intelligent-completions/source/lint-error.source.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/source/lint-error.source.js +20 -13
- package/lib/browser/contrib/intelligent-completions/source/lint-error.source.js.map +1 -1
- package/lib/browser/contrib/terminal/component/terminal-command-suggest-controller.js +2 -2
- package/lib/browser/contrib/terminal/component/terminal-command-suggest-controller.js.map +1 -1
- package/lib/browser/index.js +1 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/languages/tree-sitter/wasm-manager.d.ts.map +1 -1
- package/lib/browser/languages/tree-sitter/wasm-manager.js +2 -14
- package/lib/browser/languages/tree-sitter/wasm-manager.js.map +1 -1
- package/lib/browser/layout/ai-layout.d.ts.map +1 -1
- package/lib/browser/layout/ai-layout.js +2 -2
- package/lib/browser/layout/ai-layout.js.map +1 -1
- package/lib/browser/layout/layout.module.less +9 -9
- package/lib/browser/layout/tabbar.view.d.ts.map +1 -1
- package/lib/browser/layout/tabbar.view.js +6 -5
- package/lib/browser/layout/tabbar.view.js.map +1 -1
- package/lib/browser/model/enhanceDecorationsCollection.d.ts +10 -14
- package/lib/browser/model/enhanceDecorationsCollection.d.ts.map +1 -1
- package/lib/browser/model/enhanceDecorationsCollection.js +53 -42
- package/lib/browser/model/enhanceDecorationsCollection.js.map +1 -1
- package/lib/browser/model/styles.module.less +7 -0
- package/lib/browser/preferences/schema.d.ts.map +1 -1
- package/lib/browser/preferences/schema.js +0 -4
- package/lib/browser/preferences/schema.js.map +1 -1
- package/lib/browser/types.d.ts +2 -7
- package/lib/browser/types.d.ts.map +1 -1
- package/lib/browser/types.js.map +1 -1
- package/lib/browser/widget/inline-chat/inline-chat-editor.controller.d.ts +1 -2
- package/lib/browser/widget/inline-chat/inline-chat-editor.controller.d.ts.map +1 -1
- package/lib/browser/widget/inline-chat/inline-chat-editor.controller.js +48 -20
- package/lib/browser/widget/inline-chat/inline-chat-editor.controller.js.map +1 -1
- package/lib/browser/widget/inline-chat/inline-chat.feature.registry.d.ts +13 -3
- package/lib/browser/widget/inline-chat/inline-chat.feature.registry.d.ts.map +1 -1
- package/lib/browser/widget/inline-chat/inline-chat.feature.registry.js +72 -24
- package/lib/browser/widget/inline-chat/inline-chat.feature.registry.js.map +1 -1
- package/lib/browser/widget/inline-chat/inline-chat.service.d.ts +6 -1
- package/lib/browser/widget/inline-chat/inline-chat.service.d.ts.map +1 -1
- package/lib/browser/widget/inline-chat/inline-chat.service.js +17 -5
- package/lib/browser/widget/inline-chat/inline-chat.service.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 +42 -17
- package/lib/browser/widget/inline-chat/inline-content-widget.js.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-previewer.d.ts +5 -22
- package/lib/browser/widget/inline-diff/inline-diff-previewer.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-previewer.js +30 -61
- package/lib/browser/widget/inline-diff/inline-diff-previewer.js.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff.controller.d.ts +12 -8
- package/lib/browser/widget/inline-diff/inline-diff.controller.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff.controller.js +96 -68
- package/lib/browser/widget/inline-diff/inline-diff.controller.js.map +1 -1
- package/lib/browser/widget/inline-hint/inline-hint.controller.d.ts +1 -0
- package/lib/browser/widget/inline-hint/inline-hint.controller.d.ts.map +1 -1
- package/lib/browser/widget/inline-hint/inline-hint.controller.js +5 -0
- package/lib/browser/widget/inline-hint/inline-hint.controller.js.map +1 -1
- package/lib/browser/widget/inline-input/inline-input-widget.d.ts +2 -12
- package/lib/browser/widget/inline-input/inline-input-widget.d.ts.map +1 -1
- package/lib/browser/widget/inline-input/inline-input-widget.js +18 -26
- package/lib/browser/widget/inline-input/inline-input-widget.js.map +1 -1
- package/lib/browser/widget/inline-input/inline-input.controller.d.ts +5 -14
- package/lib/browser/widget/inline-input/inline-input.controller.d.ts.map +1 -1
- package/lib/browser/widget/inline-input/inline-input.controller.js +165 -321
- package/lib/browser/widget/inline-input/inline-input.controller.js.map +1 -1
- package/lib/browser/widget/inline-input/inline-input.module.less +0 -4
- package/lib/browser/widget/inline-input/inline-input.service.d.ts +7 -19
- package/lib/browser/widget/inline-input/inline-input.service.d.ts.map +1 -1
- package/lib/browser/widget/inline-input/inline-input.service.js +12 -72
- package/lib/browser/widget/inline-input/inline-input.service.js.map +1 -1
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.d.ts +19 -8
- 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 +39 -44
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.js.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts +4 -17
- package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.component.js +5 -37
- package/lib/browser/widget/inline-stream-diff/live-preview.component.js.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.d.ts +11 -7
- 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 +77 -33
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.js.map +1 -1
- package/lib/common/utils.js +2 -2
- package/lib/common/utils.js.map +1 -1
- package/package.json +21 -21
- package/src/browser/ai-core.contextkeys.ts +0 -3
- package/src/browser/ai-core.contribution.ts +17 -68
- package/src/browser/components/ChatMarkdown.tsx +1 -1
- package/src/browser/components/WelcomeMsg.tsx +1 -1
- package/src/browser/contrib/intelligent-completions/index.ts +4 -16
- package/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts +8 -29
- package/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts +55 -86
- package/src/browser/contrib/intelligent-completions/source/base.ts +7 -28
- package/src/browser/contrib/intelligent-completions/source/line-change.source.ts +22 -129
- package/src/browser/contrib/intelligent-completions/source/lint-error.source.ts +31 -19
- package/src/browser/contrib/terminal/component/terminal-command-suggest-controller.tsx +1 -1
- package/src/browser/index.ts +2 -2
- package/src/browser/languages/tree-sitter/wasm-manager.ts +2 -12
- package/src/browser/layout/ai-layout.tsx +2 -5
- package/src/browser/layout/layout.module.less +9 -9
- package/src/browser/layout/tabbar.view.tsx +8 -10
- package/src/browser/model/enhanceDecorationsCollection.ts +77 -62
- package/src/browser/model/styles.module.less +7 -0
- package/src/browser/preferences/schema.ts +0 -4
- package/src/browser/types.ts +3 -5
- package/src/browser/widget/inline-chat/inline-chat-editor.controller.ts +64 -29
- package/src/browser/widget/inline-chat/inline-chat.feature.registry.ts +90 -23
- package/src/browser/widget/inline-chat/inline-chat.service.ts +17 -2
- package/src/browser/widget/inline-chat/inline-content-widget.tsx +69 -14
- package/src/browser/widget/inline-diff/inline-diff-previewer.ts +32 -87
- package/src/browser/widget/inline-diff/inline-diff.controller.ts +114 -90
- package/src/browser/widget/inline-hint/inline-hint.controller.ts +7 -1
- package/src/browser/widget/inline-input/inline-input-widget.tsx +12 -34
- package/src/browser/widget/inline-input/inline-input.controller.ts +242 -454
- package/src/browser/widget/inline-input/inline-input.module.less +0 -4
- package/src/browser/widget/inline-input/inline-input.service.ts +13 -92
- package/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx +67 -54
- package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +6 -45
- package/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx +112 -40
- package/src/common/utils.ts +2 -2
- package/lib/browser/contrib/intelligent-completions/source/typing.source.d.ts +0 -9
- package/lib/browser/contrib/intelligent-completions/source/typing.source.d.ts.map +0 -1
- package/lib/browser/contrib/intelligent-completions/source/typing.source.js +0 -36
- package/lib/browser/contrib/intelligent-completions/source/typing.source.js.map +0 -1
- package/lib/browser/widget/inline-input/model.d.ts +0 -34
- package/lib/browser/widget/inline-input/model.d.ts.map +0 -1
- package/lib/browser/widget/inline-input/model.js +0 -63
- package/lib/browser/widget/inline-input/model.js.map +0 -1
- package/src/browser/contrib/intelligent-completions/source/typing.source.ts +0 -34
- package/src/browser/widget/inline-input/model.ts +0 -74
|
@@ -1,106 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Disposable, Emitter, Event, IDisposable } from '@opensumi/ide-core-common';
|
|
5
|
-
import { ICodeEditor, Position, Selection } from '@opensumi/ide-monaco';
|
|
6
|
-
|
|
7
|
-
import { LanguageParserService } from '../../languages/service';
|
|
8
|
-
import { ERunStrategy, IInteractiveInputHandler, IInteractiveInputRunStrategy } from '../../types';
|
|
9
|
-
|
|
10
|
-
import { InteractiveInputModel } from './model';
|
|
1
|
+
import { Injectable } from '@opensumi/di';
|
|
2
|
+
import { Emitter, Event } from '@opensumi/ide-core-common';
|
|
3
|
+
import { Position } from '@opensumi/ide-monaco';
|
|
11
4
|
|
|
12
5
|
@Injectable()
|
|
13
|
-
export class
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
private readonly languageParserService: LanguageParserService;
|
|
19
|
-
|
|
20
|
-
private interactiveInputModel: InteractiveInputModel = new InteractiveInputModel();
|
|
6
|
+
export class InlineInputChatService {
|
|
7
|
+
private _currentVisiblePosition: Position | undefined;
|
|
8
|
+
public get currentVisiblePosition(): Position | undefined {
|
|
9
|
+
return this._currentVisiblePosition;
|
|
10
|
+
}
|
|
21
11
|
|
|
22
12
|
private readonly _onInteractiveInputVisibleInPosition = new Emitter<Position | undefined>();
|
|
23
13
|
public readonly onInteractiveInputVisibleInPosition: Event<Position | undefined> =
|
|
24
14
|
this._onInteractiveInputVisibleInPosition.event;
|
|
25
15
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this._onInteractiveInputVisibleInSelection.event;
|
|
29
|
-
|
|
30
|
-
private readonly _onHidden = new Emitter<void>();
|
|
31
|
-
public readonly onHidden: Event<void> = this._onHidden.event;
|
|
32
|
-
|
|
33
|
-
public visibleByPosition(position: Position): void {
|
|
34
|
-
this._onInteractiveInputVisibleInPosition.fire(position);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public visibleBySelection(selection: Selection): void {
|
|
38
|
-
this._onInteractiveInputVisibleInSelection.fire(selection);
|
|
16
|
+
public setCurrentVisiblePosition(position: Position | undefined): void {
|
|
17
|
+
this._currentVisiblePosition = position;
|
|
39
18
|
}
|
|
40
19
|
|
|
41
|
-
public
|
|
42
|
-
|
|
43
|
-
if (codeBlock) {
|
|
44
|
-
this.visibleBySelection(codeBlock);
|
|
45
|
-
}
|
|
20
|
+
public visible(): void {
|
|
21
|
+
this._onInteractiveInputVisibleInPosition.fire(this._currentVisiblePosition);
|
|
46
22
|
}
|
|
47
23
|
|
|
48
24
|
public hide(): void {
|
|
49
|
-
this.
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public getInteractiveInputHandler(): IInteractiveInputHandler | undefined {
|
|
53
|
-
return this.interactiveInputModel.handler();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public getInteractiveInputStrategyHandler() {
|
|
57
|
-
return this.interactiveInputModel.strategyHandler();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// 根据光标位置自动检测并选中临近的代码块
|
|
61
|
-
private async findNearestCodeBlockWithPosition(
|
|
62
|
-
position: Position,
|
|
63
|
-
monacoEditor: ICodeEditor,
|
|
64
|
-
): Promise<Selection | undefined> {
|
|
65
|
-
const editorModel = monacoEditor.getModel();
|
|
66
|
-
const cursor = editorModel?.getOffsetAt(position);
|
|
67
|
-
const language = editorModel?.getLanguageId();
|
|
68
|
-
const parser = this.languageParserService.createParser(language!);
|
|
69
|
-
const codeBlock = await parser?.findNearestCodeBlockWithPosition(editorModel?.getValue() || '', cursor!);
|
|
70
|
-
|
|
71
|
-
if (codeBlock) {
|
|
72
|
-
return new Selection(
|
|
73
|
-
codeBlock.range.start.line + 1,
|
|
74
|
-
codeBlock.range.start.character,
|
|
75
|
-
codeBlock.range.end.line + 1,
|
|
76
|
-
codeBlock.range.end.character,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public getSequenceKeyString() {
|
|
84
|
-
const keybindings = this.keybindingRegistry.getKeybindingsForCommand(AI_INLINE_CHAT_INTERACTIVE_INPUT_VISIBLE.id);
|
|
85
|
-
const resolved = keybindings[0]?.resolved;
|
|
86
|
-
if (!resolved) {
|
|
87
|
-
return '';
|
|
88
|
-
}
|
|
89
|
-
return this.keybindingRegistry.acceleratorForSequence(resolved, '+');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public registerInlineInput(
|
|
93
|
-
runStrategy: IInteractiveInputRunStrategy,
|
|
94
|
-
handler: IInteractiveInputHandler,
|
|
95
|
-
): IDisposable {
|
|
96
|
-
this.interactiveInputModel.setHandler(handler);
|
|
97
|
-
|
|
98
|
-
if (runStrategy.handleStrategy) {
|
|
99
|
-
this.interactiveInputModel.setStrategyHandler(runStrategy.handleStrategy);
|
|
100
|
-
} else {
|
|
101
|
-
this.interactiveInputModel.setStrategyHandler(() => runStrategy.strategy || ERunStrategy.EXECUTE);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return this.interactiveInputModel;
|
|
25
|
+
this._onInteractiveInputVisibleInPosition.fire(undefined);
|
|
105
26
|
}
|
|
106
27
|
}
|
|
@@ -3,7 +3,6 @@ import { Disposable, Emitter, Event, FRAME_THREE, Schemes, Uri, randomString, sl
|
|
|
3
3
|
import { ISingleEditOperation } from '@opensumi/ide-editor';
|
|
4
4
|
import { ICodeEditor, ITextModel, Range, Selection } from '@opensumi/ide-monaco';
|
|
5
5
|
import { StandaloneServices } from '@opensumi/ide-monaco/lib/browser/monaco-api/services';
|
|
6
|
-
import { ISettableObservable, observableValue, transaction } from '@opensumi/ide-monaco/lib/common/observable';
|
|
7
6
|
import { LineRange } from '@opensumi/monaco-editor-core/esm/vs/editor/common/core/lineRange';
|
|
8
7
|
import { linesDiffComputers } from '@opensumi/monaco-editor-core/esm/vs/editor/common/diff/linesDiffComputers';
|
|
9
8
|
import { DetailedLineRangeMapping } from '@opensumi/monaco-editor-core/esm/vs/editor/common/diff/rangeMapping';
|
|
@@ -16,7 +15,7 @@ import { IDiffPreviewerOptions, IInlineDiffPreviewerNode } from '../inline-diff/
|
|
|
16
15
|
|
|
17
16
|
import { InlineStreamDiffComputer } from './inline-stream-diff-computer';
|
|
18
17
|
import { IRemovedWidgetState } from './live-preview.component';
|
|
19
|
-
import { LivePreviewDiffDecorationModel } from './live-preview.decoration';
|
|
18
|
+
import { ILivePreviewDiffDecorationSnapshotData, LivePreviewDiffDecorationModel } from './live-preview.decoration';
|
|
20
19
|
|
|
21
20
|
interface IRangeChangeData {
|
|
22
21
|
removedTextLines: string[];
|
|
@@ -30,7 +29,7 @@ interface IRangeChangeData {
|
|
|
30
29
|
| undefined;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
interface IComputeDiffData {
|
|
34
33
|
newFullRangeTextLines: string[];
|
|
35
34
|
changes: IRangeChangeData[];
|
|
36
35
|
activeLine: number;
|
|
@@ -42,6 +41,14 @@ export enum EComputerMode {
|
|
|
42
41
|
default = 'default',
|
|
43
42
|
}
|
|
44
43
|
|
|
44
|
+
export interface IInlineStreamDiffSnapshotData {
|
|
45
|
+
rawOriginalTextLines: string[];
|
|
46
|
+
rawOriginalTextLinesTokens: LineTokens[];
|
|
47
|
+
undoRedoGroup: UndoRedoGroup;
|
|
48
|
+
decorationSnapshotData: ILivePreviewDiffDecorationSnapshotData;
|
|
49
|
+
previewerOptions: IDiffPreviewerOptions;
|
|
50
|
+
}
|
|
51
|
+
|
|
45
52
|
const inlineStreamDiffComputer = new InlineStreamDiffComputer();
|
|
46
53
|
|
|
47
54
|
@Injectable({ multiple: true })
|
|
@@ -57,21 +64,18 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
57
64
|
private originalModel: ITextModel;
|
|
58
65
|
private virtualModel: ITextModel;
|
|
59
66
|
|
|
67
|
+
// Parts that require snapshots
|
|
60
68
|
private rawOriginalTextLines: string[];
|
|
61
69
|
private rawOriginalTextLinesTokens: LineTokens[] = [];
|
|
62
|
-
private undoRedoGroup: UndoRedoGroup
|
|
63
|
-
|
|
64
|
-
private readonly diffModel: ISettableObservable<IComputeDiffData | undefined> = observableValue(this, undefined);
|
|
65
|
-
private readonly finallyDiffModel: ISettableObservable<IComputeDiffData | undefined> = observableValue(
|
|
66
|
-
this,
|
|
67
|
-
undefined,
|
|
68
|
-
);
|
|
70
|
+
private undoRedoGroup: UndoRedoGroup;
|
|
69
71
|
|
|
70
72
|
public livePreviewDiffDecorationModel: LivePreviewDiffDecorationModel;
|
|
71
73
|
|
|
72
74
|
constructor(private readonly monacoEditor: ICodeEditor) {
|
|
73
75
|
super();
|
|
74
76
|
|
|
77
|
+
this.undoRedoGroup = new UndoRedoGroup();
|
|
78
|
+
|
|
75
79
|
const modelService = StandaloneServices.get(IModelService);
|
|
76
80
|
this.virtualModel = modelService.createModel(
|
|
77
81
|
'',
|
|
@@ -132,6 +136,44 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
132
136
|
this.livePreviewDiffDecorationModel.initialize(zone);
|
|
133
137
|
}
|
|
134
138
|
|
|
139
|
+
private _snapshotStore: IInlineStreamDiffSnapshotData | undefined;
|
|
140
|
+
restoreSnapshot(snapshot: IInlineStreamDiffSnapshotData): void {
|
|
141
|
+
this._snapshotStore = snapshot;
|
|
142
|
+
const {
|
|
143
|
+
rawOriginalTextLines,
|
|
144
|
+
rawOriginalTextLinesTokens,
|
|
145
|
+
undoRedoGroup,
|
|
146
|
+
decorationSnapshotData,
|
|
147
|
+
previewerOptions,
|
|
148
|
+
} = snapshot;
|
|
149
|
+
|
|
150
|
+
this.setPreviewerOptions(previewerOptions);
|
|
151
|
+
|
|
152
|
+
this.rawOriginalTextLines = rawOriginalTextLines;
|
|
153
|
+
this.rawOriginalTextLinesTokens = rawOriginalTextLinesTokens;
|
|
154
|
+
this.undoRedoGroup = undoRedoGroup;
|
|
155
|
+
|
|
156
|
+
this.livePreviewDiffDecorationModel.initialize(decorationSnapshotData.zone);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
get currentSnapshotStore(): IInlineStreamDiffSnapshotData | undefined {
|
|
160
|
+
return this._snapshotStore;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
restoreDecorationSnapshot(decorationSnapshotData: ILivePreviewDiffDecorationSnapshotData): void {
|
|
164
|
+
this.livePreviewDiffDecorationModel.restoreSnapshot(decorationSnapshotData);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
createSnapshot(): IInlineStreamDiffSnapshotData {
|
|
168
|
+
return {
|
|
169
|
+
rawOriginalTextLines: this.rawOriginalTextLines,
|
|
170
|
+
rawOriginalTextLinesTokens: this.rawOriginalTextLinesTokens,
|
|
171
|
+
undoRedoGroup: this.undoRedoGroup,
|
|
172
|
+
decorationSnapshotData: this.livePreviewDiffDecorationModel.createSnapshot(),
|
|
173
|
+
previewerOptions: this.previewerOptions,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
135
177
|
getVirtualModelValue() {
|
|
136
178
|
return this.virtualModel.getValue();
|
|
137
179
|
}
|
|
@@ -286,9 +328,7 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
286
328
|
preRemovedLen += removedLinesOriginalRange.length - addedRange.length;
|
|
287
329
|
}
|
|
288
330
|
|
|
289
|
-
this.livePreviewDiffDecorationModel.touchRemovedWidget(states
|
|
290
|
-
this._onDidEditChange.fire();
|
|
291
|
-
});
|
|
331
|
+
this.livePreviewDiffDecorationModel.touchRemovedWidget(states);
|
|
292
332
|
}
|
|
293
333
|
|
|
294
334
|
/**
|
|
@@ -303,7 +343,7 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
303
343
|
});
|
|
304
344
|
}
|
|
305
345
|
|
|
306
|
-
private
|
|
346
|
+
private handleEdits(diffModel: IComputeDiffData): void {
|
|
307
347
|
const { activeLine, newFullRangeTextLines, pendingRange } = diffModel;
|
|
308
348
|
const eol = this.originalModel.getEOL();
|
|
309
349
|
const zone = this.getZone();
|
|
@@ -424,8 +464,9 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
424
464
|
}
|
|
425
465
|
|
|
426
466
|
private currentEditLine = 0;
|
|
467
|
+
private finallyDiffModel: IComputeDiffData | null = null;
|
|
427
468
|
private isEditing = false;
|
|
428
|
-
|
|
469
|
+
private async rateEditController(): Promise<void> {
|
|
429
470
|
if (this.isEditing === false) {
|
|
430
471
|
this.isEditing = true;
|
|
431
472
|
|
|
@@ -437,22 +478,15 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
437
478
|
const virtualTextLines = this.virtualModel.getLinesContent();
|
|
438
479
|
const currentText = virtualTextLines.slice(0, this.currentEditLine);
|
|
439
480
|
const currentDiffModel = this.computeDiff(this.rawOriginalTextLines, currentText);
|
|
440
|
-
|
|
441
|
-
this.diffModel.set(currentDiffModel, tx);
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
if (this.originalModel.id === this.monacoEditor.getModel()?.id) {
|
|
445
|
-
this.renderDiffEdits(currentDiffModel);
|
|
446
|
-
}
|
|
481
|
+
this.handleEdits(currentDiffModel);
|
|
447
482
|
|
|
448
483
|
this.currentEditLine += 1;
|
|
449
484
|
|
|
450
485
|
await sleep(FRAME_THREE);
|
|
451
486
|
}
|
|
452
487
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
this.finallyRender(finallyDiffModel);
|
|
488
|
+
if (this.finallyDiffModel) {
|
|
489
|
+
this.finallyRender(this.finallyDiffModel);
|
|
456
490
|
}
|
|
457
491
|
|
|
458
492
|
this.isEditing = false;
|
|
@@ -460,48 +494,27 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
460
494
|
}
|
|
461
495
|
|
|
462
496
|
public addLinesToDiff(newText: string, computerMode: EComputerMode = EComputerMode.default): void {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
this.diffModel.set(diffModel, tx);
|
|
466
|
-
});
|
|
497
|
+
this.recompute(computerMode, newText);
|
|
498
|
+
this.rateEditController();
|
|
467
499
|
}
|
|
468
500
|
|
|
469
501
|
public pushRateFinallyDiffStack(diffModel: IComputeDiffData): void {
|
|
470
|
-
|
|
502
|
+
this.finallyDiffModel = diffModel;
|
|
503
|
+
|
|
504
|
+
// 可能存在 rate editr controller 处理完之后接口层流式才结束
|
|
471
505
|
if (this.isEditing === false) {
|
|
472
|
-
this.finallyRender(
|
|
506
|
+
this.finallyRender(this.finallyDiffModel);
|
|
473
507
|
}
|
|
474
508
|
}
|
|
475
509
|
|
|
476
510
|
public finallyRender(diffModel: IComputeDiffData): void {
|
|
477
|
-
|
|
478
|
-
this.finallyDiffModel.set(diffModel, tx);
|
|
479
|
-
this.diffModel.set(diffModel, tx);
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
if (this.originalModel.id !== this.monacoEditor.getModel()?.id) {
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
|
|
511
|
+
// 流式结束后才会确定所有的 added range,再渲染 partial edit widgets
|
|
486
512
|
this.renderPartialEditWidgets(diffModel);
|
|
487
|
-
this.
|
|
513
|
+
this.handleEdits(diffModel);
|
|
488
514
|
this.pushStackElement();
|
|
489
515
|
this.monacoEditor.focus();
|
|
490
516
|
}
|
|
491
517
|
|
|
492
|
-
public hide(): void {
|
|
493
|
-
this.livePreviewDiffDecorationModel.hide();
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
public resume(): void {
|
|
497
|
-
const finallyDiffModel = this.finallyDiffModel.get();
|
|
498
|
-
if (!finallyDiffModel) {
|
|
499
|
-
this.rateRenderEditController();
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
this.livePreviewDiffDecorationModel.resume();
|
|
503
|
-
}
|
|
504
|
-
|
|
505
518
|
acceptAll(): void {
|
|
506
519
|
this.livePreviewDiffDecorationModel.acceptUnProcessed();
|
|
507
520
|
this.dispose();
|
|
@@ -21,11 +21,6 @@ import { LineTokens } from '@opensumi/monaco-editor-core/esm/vs/editor/common/to
|
|
|
21
21
|
import { IOptions, ZoneWidget } from '@opensumi/monaco-editor-core/esm/vs/editor/contrib/zoneWidget/browser/zoneWidget';
|
|
22
22
|
import { UndoRedoGroup } from '@opensumi/monaco-editor-core/esm/vs/platform/undoRedo/common/undoRedo';
|
|
23
23
|
|
|
24
|
-
import {
|
|
25
|
-
DeltaDecorations,
|
|
26
|
-
EnhanceDecorationsCollection,
|
|
27
|
-
IDeltaDecorationsOptions,
|
|
28
|
-
} from '../../model/enhanceDecorationsCollection';
|
|
29
24
|
import { renderLines } from '../ghost-text-widget/index';
|
|
30
25
|
|
|
31
26
|
import styles from './inline-stream-diff.module.less';
|
|
@@ -39,7 +34,7 @@ interface IPartialEditWidgetComponent {
|
|
|
39
34
|
discardSequence: string;
|
|
40
35
|
}
|
|
41
36
|
|
|
42
|
-
type IWidgetStatus = 'accept' | 'discard' | 'pending';
|
|
37
|
+
export type IWidgetStatus = 'accept' | 'discard' | 'pending';
|
|
43
38
|
|
|
44
39
|
export interface IRemovedWidgetState {
|
|
45
40
|
textLines: ITextLinesTokens[];
|
|
@@ -146,7 +141,7 @@ export class AcceptPartialEditWidget extends ReactInlineContentWidget {
|
|
|
146
141
|
private readonly keybindingRegistry: KeybindingRegistry;
|
|
147
142
|
|
|
148
143
|
private _id: string;
|
|
149
|
-
private
|
|
144
|
+
private _decorationId: string;
|
|
150
145
|
|
|
151
146
|
private readonly _onAccept = this.registerDispose(new Emitter<void>());
|
|
152
147
|
public readonly onAccept: Event<void> = this._onAccept.event;
|
|
@@ -214,12 +209,12 @@ export class AcceptPartialEditWidget extends ReactInlineContentWidget {
|
|
|
214
209
|
return styles.accept_partial_edit_widget_id;
|
|
215
210
|
}
|
|
216
211
|
|
|
217
|
-
public
|
|
218
|
-
this.
|
|
212
|
+
public recordDecorationId(id: string): void {
|
|
213
|
+
this._decorationId = id;
|
|
219
214
|
}
|
|
220
215
|
|
|
221
|
-
public
|
|
222
|
-
return this.
|
|
216
|
+
public getDecorationId(): string {
|
|
217
|
+
return this._decorationId;
|
|
223
218
|
}
|
|
224
219
|
|
|
225
220
|
public resume(): void {
|
|
@@ -319,8 +314,6 @@ export class RemovedZoneWidget extends ZoneWidget {
|
|
|
319
314
|
return this._group;
|
|
320
315
|
}
|
|
321
316
|
|
|
322
|
-
public status: IWidgetStatus = 'pending';
|
|
323
|
-
|
|
324
317
|
constructor(editor: ICodeEditor, public readonly textLines: ITextLinesTokens[], options: IRemovedZoneWidgetOptions) {
|
|
325
318
|
super(editor, options);
|
|
326
319
|
|
|
@@ -369,23 +362,12 @@ export class RemovedZoneWidget extends ZoneWidget {
|
|
|
369
362
|
return this.position || this._recordPosition;
|
|
370
363
|
}
|
|
371
364
|
|
|
372
|
-
accept(): void {
|
|
373
|
-
this.status = 'accept';
|
|
374
|
-
this.hide();
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
discard(): void {
|
|
378
|
-
this.status = 'discard';
|
|
379
|
-
super.hide();
|
|
380
|
-
}
|
|
381
|
-
|
|
382
365
|
hide(): void {
|
|
383
366
|
this._hidden = true;
|
|
384
367
|
super.hide();
|
|
385
368
|
}
|
|
386
369
|
|
|
387
370
|
resume(): void {
|
|
388
|
-
this.status = 'pending';
|
|
389
371
|
const position = this.getLastPosition();
|
|
390
372
|
if (position) {
|
|
391
373
|
this.show(position, this.height);
|
|
@@ -394,7 +376,6 @@ export class RemovedZoneWidget extends ZoneWidget {
|
|
|
394
376
|
|
|
395
377
|
override show(pos: IPosition, heightInLines: number): void {
|
|
396
378
|
this._hidden = false;
|
|
397
|
-
this.status = 'pending';
|
|
398
379
|
super.show(pos, heightInLines);
|
|
399
380
|
}
|
|
400
381
|
|
|
@@ -426,23 +407,3 @@ export class RemovedZoneWidget extends ZoneWidget {
|
|
|
426
407
|
super.dispose();
|
|
427
408
|
}
|
|
428
409
|
}
|
|
429
|
-
|
|
430
|
-
class AddedRangeDeltaDecorations extends DeltaDecorations {
|
|
431
|
-
public status: IWidgetStatus = 'pending';
|
|
432
|
-
|
|
433
|
-
accept(): void {
|
|
434
|
-
this.status = 'accept';
|
|
435
|
-
super.hide();
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
discard(): void {
|
|
439
|
-
this.status = 'discard';
|
|
440
|
-
super.hide();
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
export class AddedRangeDecorationsCollection extends EnhanceDecorationsCollection<AddedRangeDeltaDecorations> {
|
|
445
|
-
protected override createDecorations(metaData: IDeltaDecorationsOptions) {
|
|
446
|
-
return new AddedRangeDeltaDecorations(metaData);
|
|
447
|
-
}
|
|
448
|
-
}
|