@opensumi/ide-ai-native 3.7.1 → 3.7.2-next-1739859371.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.contextkeys.d.ts +1 -0
- package/lib/browser/ai-core.contextkeys.d.ts.map +1 -1
- package/lib/browser/ai-core.contextkeys.js +1 -0
- package/lib/browser/ai-core.contextkeys.js.map +1 -1
- package/lib/browser/ai-core.contribution.d.ts +2 -1
- package/lib/browser/ai-core.contribution.d.ts.map +1 -1
- package/lib/browser/ai-core.contribution.js +60 -15
- 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 +14 -9
- package/lib/browser/contrib/intelligent-completions/index.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/index.js +6 -1
- package/lib/browser/contrib/intelligent-completions/index.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.d.ts +1 -0
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.js +26 -4
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.d.ts +5 -4
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.js +50 -42
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/source/base.d.ts +9 -3
- package/lib/browser/contrib/intelligent-completions/source/base.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/source/base.js +21 -3
- package/lib/browser/contrib/intelligent-completions/source/base.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/source/line-change.source.d.ts +10 -3
- 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 +95 -22
- 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 +1 -3
- 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 +13 -20
- package/lib/browser/contrib/intelligent-completions/source/lint-error.source.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/source/typing.source.d.ts +9 -0
- package/lib/browser/contrib/intelligent-completions/source/typing.source.d.ts.map +1 -0
- package/lib/browser/contrib/intelligent-completions/source/typing.source.js +36 -0
- package/lib/browser/contrib/intelligent-completions/source/typing.source.js.map +1 -0
- 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 +14 -2
- 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 +5 -6
- package/lib/browser/layout/tabbar.view.js.map +1 -1
- package/lib/browser/model/enhanceDecorationsCollection.d.ts +14 -10
- package/lib/browser/model/enhanceDecorationsCollection.d.ts.map +1 -1
- package/lib/browser/model/enhanceDecorationsCollection.js +42 -53
- package/lib/browser/model/enhanceDecorationsCollection.js.map +1 -1
- package/lib/browser/preferences/schema.d.ts.map +1 -1
- package/lib/browser/preferences/schema.js +4 -0
- package/lib/browser/preferences/schema.js.map +1 -1
- package/lib/browser/types.d.ts +7 -2
- 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 +2 -1
- 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 +20 -48
- 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 +3 -13
- 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 +24 -72
- 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 +1 -6
- package/lib/browser/widget/inline-chat/inline-chat.service.d.ts.map +1 -1
- package/lib/browser/widget/inline-chat/inline-chat.service.js +5 -17
- package/lib/browser/widget/inline-chat/inline-chat.service.js.map +1 -1
- package/lib/browser/widget/inline-chat/inline-content-widget.d.ts +2 -5
- package/lib/browser/widget/inline-chat/inline-content-widget.d.ts.map +1 -1
- package/lib/browser/widget/inline-chat/inline-content-widget.js +17 -42
- package/lib/browser/widget/inline-chat/inline-content-widget.js.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-previewer.d.ts +22 -5
- package/lib/browser/widget/inline-diff/inline-diff-previewer.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-previewer.js +61 -30
- package/lib/browser/widget/inline-diff/inline-diff-previewer.js.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff.controller.d.ts +8 -12
- package/lib/browser/widget/inline-diff/inline-diff.controller.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff.controller.js +68 -96
- package/lib/browser/widget/inline-diff/inline-diff.controller.js.map +1 -1
- package/lib/browser/widget/inline-hint/inline-hint.controller.d.ts +0 -1
- package/lib/browser/widget/inline-hint/inline-hint.controller.d.ts.map +1 -1
- package/lib/browser/widget/inline-hint/inline-hint.controller.js +0 -5
- package/lib/browser/widget/inline-hint/inline-hint.controller.js.map +1 -1
- package/lib/browser/widget/inline-input/inline-input-widget.d.ts +12 -2
- package/lib/browser/widget/inline-input/inline-input-widget.d.ts.map +1 -1
- package/lib/browser/widget/inline-input/inline-input-widget.js +26 -18
- package/lib/browser/widget/inline-input/inline-input-widget.js.map +1 -1
- package/lib/browser/widget/inline-input/inline-input.controller.d.ts +14 -5
- package/lib/browser/widget/inline-input/inline-input.controller.d.ts.map +1 -1
- package/lib/browser/widget/inline-input/inline-input.controller.js +321 -165
- package/lib/browser/widget/inline-input/inline-input.controller.js.map +1 -1
- package/lib/browser/widget/inline-input/inline-input.module.less +4 -0
- package/lib/browser/widget/inline-input/inline-input.service.d.ts +19 -7
- package/lib/browser/widget/inline-input/inline-input.service.d.ts.map +1 -1
- package/lib/browser/widget/inline-input/inline-input.service.js +72 -12
- package/lib/browser/widget/inline-input/inline-input.service.js.map +1 -1
- package/lib/browser/widget/inline-input/model.d.ts +34 -0
- package/lib/browser/widget/inline-input/model.d.ts.map +1 -0
- package/lib/browser/widget/inline-input/model.js +63 -0
- package/lib/browser/widget/inline-input/model.js.map +1 -0
- package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.d.ts +8 -19
- 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 +44 -39
- 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 +17 -4
- 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 +37 -5
- 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 +7 -11
- 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 +33 -77
- 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 +3 -0
- package/src/browser/ai-core.contribution.ts +68 -17
- package/src/browser/components/ChatMarkdown.tsx +1 -1
- package/src/browser/components/WelcomeMsg.tsx +1 -1
- package/src/browser/contrib/intelligent-completions/index.ts +16 -4
- package/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts +29 -8
- package/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts +86 -55
- package/src/browser/contrib/intelligent-completions/source/base.ts +28 -7
- package/src/browser/contrib/intelligent-completions/source/line-change.source.ts +129 -22
- package/src/browser/contrib/intelligent-completions/source/lint-error.source.ts +19 -31
- package/src/browser/contrib/intelligent-completions/source/typing.source.ts +34 -0
- 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 +12 -2
- package/src/browser/layout/ai-layout.tsx +5 -2
- package/src/browser/layout/layout.module.less +9 -9
- package/src/browser/layout/tabbar.view.tsx +10 -8
- package/src/browser/model/enhanceDecorationsCollection.ts +62 -77
- package/src/browser/preferences/schema.ts +4 -0
- package/src/browser/types.ts +5 -3
- package/src/browser/widget/inline-chat/inline-chat-editor.controller.ts +29 -64
- package/src/browser/widget/inline-chat/inline-chat.feature.registry.ts +23 -90
- package/src/browser/widget/inline-chat/inline-chat.service.ts +2 -17
- package/src/browser/widget/inline-chat/inline-content-widget.tsx +14 -69
- package/src/browser/widget/inline-diff/inline-diff-previewer.ts +87 -32
- package/src/browser/widget/inline-diff/inline-diff.controller.ts +90 -114
- package/src/browser/widget/inline-hint/inline-hint.controller.ts +1 -7
- package/src/browser/widget/inline-input/inline-input-widget.tsx +34 -12
- package/src/browser/widget/inline-input/inline-input.controller.ts +454 -242
- package/src/browser/widget/inline-input/inline-input.module.less +4 -0
- package/src/browser/widget/inline-input/inline-input.service.ts +92 -13
- package/src/browser/widget/inline-input/model.ts +74 -0
- package/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx +54 -67
- package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +45 -6
- package/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx +40 -112
- package/src/common/utils.ts +2 -2
- package/lib/browser/model/styles.module.less +0 -7
- package/src/browser/model/styles.module.less +0 -7
|
@@ -1,27 +1,106 @@
|
|
|
1
|
-
import { Injectable } from '@opensumi/di';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Autowired, Injectable } from '@opensumi/di';
|
|
2
|
+
import { KeybindingRegistry } from '@opensumi/ide-core-browser';
|
|
3
|
+
import { AI_INLINE_CHAT_INTERACTIVE_INPUT_VISIBLE } from '@opensumi/ide-core-browser/lib/ai-native/command';
|
|
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';
|
|
4
11
|
|
|
5
12
|
@Injectable()
|
|
6
|
-
export class
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
export class InlineInputService extends Disposable {
|
|
14
|
+
@Autowired(KeybindingRegistry)
|
|
15
|
+
private readonly keybindingRegistry: KeybindingRegistry;
|
|
16
|
+
|
|
17
|
+
@Autowired(LanguageParserService)
|
|
18
|
+
private readonly languageParserService: LanguageParserService;
|
|
19
|
+
|
|
20
|
+
private interactiveInputModel: InteractiveInputModel = new InteractiveInputModel();
|
|
11
21
|
|
|
12
22
|
private readonly _onInteractiveInputVisibleInPosition = new Emitter<Position | undefined>();
|
|
13
23
|
public readonly onInteractiveInputVisibleInPosition: Event<Position | undefined> =
|
|
14
24
|
this._onInteractiveInputVisibleInPosition.event;
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
private readonly _onInteractiveInputVisibleInSelection = new Emitter<Selection | undefined>();
|
|
27
|
+
public readonly onInteractiveInputVisibleInSelection: Event<Selection | undefined> =
|
|
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);
|
|
18
39
|
}
|
|
19
40
|
|
|
20
|
-
public
|
|
21
|
-
this.
|
|
41
|
+
public async visibleByNearestCodeBlock(position: Position, monacoEditor: ICodeEditor): Promise<void> {
|
|
42
|
+
const codeBlock = await this.findNearestCodeBlockWithPosition(position, monacoEditor);
|
|
43
|
+
if (codeBlock) {
|
|
44
|
+
this.visibleBySelection(codeBlock);
|
|
45
|
+
}
|
|
22
46
|
}
|
|
23
47
|
|
|
24
48
|
public hide(): void {
|
|
25
|
-
this.
|
|
49
|
+
this._onHidden.fire();
|
|
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;
|
|
26
105
|
}
|
|
27
106
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { InteractiveInput } from '@opensumi/ide-core-browser/lib/components/ai-native';
|
|
2
|
+
import { MaybePromise, uuid } from '@opensumi/ide-core-common';
|
|
3
|
+
import { ICodeEditor, IPosition, Selection } from '@opensumi/ide-monaco';
|
|
4
|
+
|
|
5
|
+
import { ERunStrategy, IInteractiveInputHandler } from '../../types';
|
|
6
|
+
|
|
7
|
+
type TRunStrategyFn = (editor: ICodeEditor, value: string) => MaybePromise<ERunStrategy>;
|
|
8
|
+
|
|
9
|
+
export class InteractiveInputModel {
|
|
10
|
+
static ID: string = `${InteractiveInput.displayName}:${uuid(4)}`;
|
|
11
|
+
|
|
12
|
+
private _handler: IInteractiveInputHandler | undefined;
|
|
13
|
+
private _strategyHandler: TRunStrategyFn;
|
|
14
|
+
|
|
15
|
+
public setHandler(h: IInteractiveInputHandler): void {
|
|
16
|
+
this._handler = h;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public handler(): IInteractiveInputHandler | undefined {
|
|
20
|
+
return this._handler;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public setStrategyHandler(fn: TRunStrategyFn): void {
|
|
24
|
+
this._strategyHandler = fn;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public strategyHandler(): TRunStrategyFn {
|
|
28
|
+
return this._strategyHandler;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public dispose(): void {
|
|
32
|
+
this._handler = undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class InlineInputWidgetStoreInEmptyLine {
|
|
37
|
+
constructor(private position: IPosition, private value?: string) {}
|
|
38
|
+
|
|
39
|
+
public getPosition(): IPosition {
|
|
40
|
+
return this.position;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public setPosition(position: IPosition): void {
|
|
44
|
+
this.position = position;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public getValue(): string | undefined {
|
|
48
|
+
return this.value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public setValue(value: string): void {
|
|
52
|
+
this.value = value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class InlineInputWidgetStoreInSelection {
|
|
57
|
+
constructor(private selection: Selection, private value?: string) {}
|
|
58
|
+
|
|
59
|
+
public getSelection(): Selection {
|
|
60
|
+
return this.selection;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public setSelection(selection: Selection): void {
|
|
64
|
+
this.selection = selection;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public getValue(): string | undefined {
|
|
68
|
+
return this.value;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public setValue(value: string): void {
|
|
72
|
+
this.value = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -3,6 +3,7 @@ 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';
|
|
6
7
|
import { LineRange } from '@opensumi/monaco-editor-core/esm/vs/editor/common/core/lineRange';
|
|
7
8
|
import { linesDiffComputers } from '@opensumi/monaco-editor-core/esm/vs/editor/common/diff/linesDiffComputers';
|
|
8
9
|
import { DetailedLineRangeMapping } from '@opensumi/monaco-editor-core/esm/vs/editor/common/diff/rangeMapping';
|
|
@@ -15,7 +16,7 @@ import { IDiffPreviewerOptions, IInlineDiffPreviewerNode } from '../inline-diff/
|
|
|
15
16
|
|
|
16
17
|
import { InlineStreamDiffComputer } from './inline-stream-diff-computer';
|
|
17
18
|
import { IRemovedWidgetState } from './live-preview.component';
|
|
18
|
-
import {
|
|
19
|
+
import { LivePreviewDiffDecorationModel } from './live-preview.decoration';
|
|
19
20
|
|
|
20
21
|
interface IRangeChangeData {
|
|
21
22
|
removedTextLines: string[];
|
|
@@ -29,7 +30,7 @@ interface IRangeChangeData {
|
|
|
29
30
|
| undefined;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
interface IComputeDiffData {
|
|
33
|
+
export interface IComputeDiffData {
|
|
33
34
|
newFullRangeTextLines: string[];
|
|
34
35
|
changes: IRangeChangeData[];
|
|
35
36
|
activeLine: number;
|
|
@@ -41,14 +42,6 @@ export enum EComputerMode {
|
|
|
41
42
|
default = 'default',
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
export interface IInlineStreamDiffSnapshotData {
|
|
45
|
-
rawOriginalTextLines: string[];
|
|
46
|
-
rawOriginalTextLinesTokens: LineTokens[];
|
|
47
|
-
undoRedoGroup: UndoRedoGroup;
|
|
48
|
-
decorationSnapshotData: ILivePreviewDiffDecorationSnapshotData;
|
|
49
|
-
previewerOptions: IDiffPreviewerOptions;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
45
|
const inlineStreamDiffComputer = new InlineStreamDiffComputer();
|
|
53
46
|
|
|
54
47
|
@Injectable({ multiple: true })
|
|
@@ -64,18 +57,21 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
64
57
|
private originalModel: ITextModel;
|
|
65
58
|
private virtualModel: ITextModel;
|
|
66
59
|
|
|
67
|
-
// Parts that require snapshots
|
|
68
60
|
private rawOriginalTextLines: string[];
|
|
69
61
|
private rawOriginalTextLinesTokens: LineTokens[] = [];
|
|
70
|
-
private undoRedoGroup: UndoRedoGroup;
|
|
62
|
+
private undoRedoGroup: UndoRedoGroup = new 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
|
+
);
|
|
71
69
|
|
|
72
70
|
public livePreviewDiffDecorationModel: LivePreviewDiffDecorationModel;
|
|
73
71
|
|
|
74
72
|
constructor(private readonly monacoEditor: ICodeEditor) {
|
|
75
73
|
super();
|
|
76
74
|
|
|
77
|
-
this.undoRedoGroup = new UndoRedoGroup();
|
|
78
|
-
|
|
79
75
|
const modelService = StandaloneServices.get(IModelService);
|
|
80
76
|
this.virtualModel = modelService.createModel(
|
|
81
77
|
'',
|
|
@@ -136,44 +132,6 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
136
132
|
this.livePreviewDiffDecorationModel.initialize(zone);
|
|
137
133
|
}
|
|
138
134
|
|
|
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
|
-
|
|
177
135
|
getVirtualModelValue() {
|
|
178
136
|
return this.virtualModel.getValue();
|
|
179
137
|
}
|
|
@@ -328,7 +286,9 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
328
286
|
preRemovedLen += removedLinesOriginalRange.length - addedRange.length;
|
|
329
287
|
}
|
|
330
288
|
|
|
331
|
-
this.livePreviewDiffDecorationModel.touchRemovedWidget(states)
|
|
289
|
+
this.livePreviewDiffDecorationModel.touchRemovedWidget(states, () => {
|
|
290
|
+
this._onDidEditChange.fire();
|
|
291
|
+
});
|
|
332
292
|
}
|
|
333
293
|
|
|
334
294
|
/**
|
|
@@ -343,7 +303,7 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
343
303
|
});
|
|
344
304
|
}
|
|
345
305
|
|
|
346
|
-
private
|
|
306
|
+
private renderDiffEdits(diffModel: IComputeDiffData): void {
|
|
347
307
|
const { activeLine, newFullRangeTextLines, pendingRange } = diffModel;
|
|
348
308
|
const eol = this.originalModel.getEOL();
|
|
349
309
|
const zone = this.getZone();
|
|
@@ -464,9 +424,8 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
464
424
|
}
|
|
465
425
|
|
|
466
426
|
private currentEditLine = 0;
|
|
467
|
-
private finallyDiffModel: IComputeDiffData | null = null;
|
|
468
427
|
private isEditing = false;
|
|
469
|
-
|
|
428
|
+
public async rateRenderEditController(): Promise<void> {
|
|
470
429
|
if (this.isEditing === false) {
|
|
471
430
|
this.isEditing = true;
|
|
472
431
|
|
|
@@ -478,15 +437,22 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
478
437
|
const virtualTextLines = this.virtualModel.getLinesContent();
|
|
479
438
|
const currentText = virtualTextLines.slice(0, this.currentEditLine);
|
|
480
439
|
const currentDiffModel = this.computeDiff(this.rawOriginalTextLines, currentText);
|
|
481
|
-
|
|
440
|
+
transaction((tx) => {
|
|
441
|
+
this.diffModel.set(currentDiffModel, tx);
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
if (this.originalModel.id === this.monacoEditor.getModel()?.id) {
|
|
445
|
+
this.renderDiffEdits(currentDiffModel);
|
|
446
|
+
}
|
|
482
447
|
|
|
483
448
|
this.currentEditLine += 1;
|
|
484
449
|
|
|
485
450
|
await sleep(FRAME_THREE);
|
|
486
451
|
}
|
|
487
452
|
|
|
488
|
-
|
|
489
|
-
|
|
453
|
+
const finallyDiffModel = this.finallyDiffModel.get();
|
|
454
|
+
if (finallyDiffModel) {
|
|
455
|
+
this.finallyRender(finallyDiffModel);
|
|
490
456
|
}
|
|
491
457
|
|
|
492
458
|
this.isEditing = false;
|
|
@@ -494,27 +460,48 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
|
|
|
494
460
|
}
|
|
495
461
|
|
|
496
462
|
public addLinesToDiff(newText: string, computerMode: EComputerMode = EComputerMode.default): void {
|
|
497
|
-
this.recompute(computerMode, newText);
|
|
498
|
-
|
|
463
|
+
const diffModel = this.recompute(computerMode, newText);
|
|
464
|
+
transaction((tx) => {
|
|
465
|
+
this.diffModel.set(diffModel, tx);
|
|
466
|
+
});
|
|
499
467
|
}
|
|
500
468
|
|
|
501
469
|
public pushRateFinallyDiffStack(diffModel: IComputeDiffData): void {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
// 可能存在 rate editr controller 处理完之后接口层流式才结束
|
|
470
|
+
// 可能存在 rate editor controller 处理完之后接口层流式才结束
|
|
505
471
|
if (this.isEditing === false) {
|
|
506
|
-
this.finallyRender(
|
|
472
|
+
this.finallyRender(diffModel);
|
|
507
473
|
}
|
|
508
474
|
}
|
|
509
475
|
|
|
510
476
|
public finallyRender(diffModel: IComputeDiffData): void {
|
|
511
|
-
|
|
477
|
+
transaction((tx) => {
|
|
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
|
+
|
|
512
486
|
this.renderPartialEditWidgets(diffModel);
|
|
513
|
-
this.
|
|
487
|
+
this.renderDiffEdits(diffModel);
|
|
514
488
|
this.pushStackElement();
|
|
515
489
|
this.monacoEditor.focus();
|
|
516
490
|
}
|
|
517
491
|
|
|
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
|
+
|
|
518
505
|
acceptAll(): void {
|
|
519
506
|
this.livePreviewDiffDecorationModel.acceptUnProcessed();
|
|
520
507
|
this.dispose();
|
|
@@ -21,6 +21,11 @@ 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';
|
|
24
29
|
import { renderLines } from '../ghost-text-widget/index';
|
|
25
30
|
|
|
26
31
|
import styles from './inline-stream-diff.module.less';
|
|
@@ -34,7 +39,7 @@ interface IPartialEditWidgetComponent {
|
|
|
34
39
|
discardSequence: string;
|
|
35
40
|
}
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
type IWidgetStatus = 'accept' | 'discard' | 'pending';
|
|
38
43
|
|
|
39
44
|
export interface IRemovedWidgetState {
|
|
40
45
|
textLines: ITextLinesTokens[];
|
|
@@ -141,7 +146,7 @@ export class AcceptPartialEditWidget extends ReactInlineContentWidget {
|
|
|
141
146
|
private readonly keybindingRegistry: KeybindingRegistry;
|
|
142
147
|
|
|
143
148
|
private _id: string;
|
|
144
|
-
private
|
|
149
|
+
private _addedRangeId: string;
|
|
145
150
|
|
|
146
151
|
private readonly _onAccept = this.registerDispose(new Emitter<void>());
|
|
147
152
|
public readonly onAccept: Event<void> = this._onAccept.event;
|
|
@@ -209,12 +214,12 @@ export class AcceptPartialEditWidget extends ReactInlineContentWidget {
|
|
|
209
214
|
return styles.accept_partial_edit_widget_id;
|
|
210
215
|
}
|
|
211
216
|
|
|
212
|
-
public
|
|
213
|
-
this.
|
|
217
|
+
public recordAddedRangeId(id: string): void {
|
|
218
|
+
this._addedRangeId = id;
|
|
214
219
|
}
|
|
215
220
|
|
|
216
|
-
public
|
|
217
|
-
return this.
|
|
221
|
+
public getAddedRangeId(): string {
|
|
222
|
+
return this._addedRangeId;
|
|
218
223
|
}
|
|
219
224
|
|
|
220
225
|
public resume(): void {
|
|
@@ -314,6 +319,8 @@ export class RemovedZoneWidget extends ZoneWidget {
|
|
|
314
319
|
return this._group;
|
|
315
320
|
}
|
|
316
321
|
|
|
322
|
+
public status: IWidgetStatus = 'pending';
|
|
323
|
+
|
|
317
324
|
constructor(editor: ICodeEditor, public readonly textLines: ITextLinesTokens[], options: IRemovedZoneWidgetOptions) {
|
|
318
325
|
super(editor, options);
|
|
319
326
|
|
|
@@ -362,12 +369,23 @@ export class RemovedZoneWidget extends ZoneWidget {
|
|
|
362
369
|
return this.position || this._recordPosition;
|
|
363
370
|
}
|
|
364
371
|
|
|
372
|
+
accept(): void {
|
|
373
|
+
this.status = 'accept';
|
|
374
|
+
this.hide();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
discard(): void {
|
|
378
|
+
this.status = 'discard';
|
|
379
|
+
super.hide();
|
|
380
|
+
}
|
|
381
|
+
|
|
365
382
|
hide(): void {
|
|
366
383
|
this._hidden = true;
|
|
367
384
|
super.hide();
|
|
368
385
|
}
|
|
369
386
|
|
|
370
387
|
resume(): void {
|
|
388
|
+
this.status = 'pending';
|
|
371
389
|
const position = this.getLastPosition();
|
|
372
390
|
if (position) {
|
|
373
391
|
this.show(position, this.height);
|
|
@@ -376,6 +394,7 @@ export class RemovedZoneWidget extends ZoneWidget {
|
|
|
376
394
|
|
|
377
395
|
override show(pos: IPosition, heightInLines: number): void {
|
|
378
396
|
this._hidden = false;
|
|
397
|
+
this.status = 'pending';
|
|
379
398
|
super.show(pos, heightInLines);
|
|
380
399
|
}
|
|
381
400
|
|
|
@@ -407,3 +426,23 @@ export class RemovedZoneWidget extends ZoneWidget {
|
|
|
407
426
|
super.dispose();
|
|
408
427
|
}
|
|
409
428
|
}
|
|
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
|
+
}
|