@opensumi/ide-ai-native 3.7.1-next-1739439717.0 → 3.7.1-next-1739521933.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.
Files changed (138) hide show
  1. package/lib/browser/ai-core.contextkeys.d.ts +1 -0
  2. package/lib/browser/ai-core.contextkeys.d.ts.map +1 -1
  3. package/lib/browser/ai-core.contextkeys.js +1 -0
  4. package/lib/browser/ai-core.contextkeys.js.map +1 -1
  5. package/lib/browser/ai-core.contribution.d.ts +2 -1
  6. package/lib/browser/ai-core.contribution.d.ts.map +1 -1
  7. package/lib/browser/ai-core.contribution.js +55 -14
  8. package/lib/browser/ai-core.contribution.js.map +1 -1
  9. package/lib/browser/components/utils.d.ts +2 -2
  10. package/lib/browser/contrib/intelligent-completions/index.d.ts +8 -12
  11. package/lib/browser/contrib/intelligent-completions/index.d.ts.map +1 -1
  12. package/lib/browser/contrib/intelligent-completions/index.js.map +1 -1
  13. package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.d.ts +1 -0
  14. package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.d.ts.map +1 -1
  15. package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.js +26 -4
  16. package/lib/browser/contrib/intelligent-completions/intelligent-completions.contribution.js.map +1 -1
  17. package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.d.ts +3 -1
  18. package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.d.ts.map +1 -1
  19. package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.js +9 -1
  20. package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.js.map +1 -1
  21. package/lib/browser/contrib/intelligent-completions/source/base.d.ts +9 -3
  22. package/lib/browser/contrib/intelligent-completions/source/base.d.ts.map +1 -1
  23. package/lib/browser/contrib/intelligent-completions/source/base.js +21 -3
  24. package/lib/browser/contrib/intelligent-completions/source/base.js.map +1 -1
  25. package/lib/browser/contrib/intelligent-completions/source/line-change.source.d.ts +0 -3
  26. package/lib/browser/contrib/intelligent-completions/source/line-change.source.d.ts.map +1 -1
  27. package/lib/browser/contrib/intelligent-completions/source/line-change.source.js +20 -22
  28. package/lib/browser/contrib/intelligent-completions/source/line-change.source.js.map +1 -1
  29. package/lib/browser/contrib/intelligent-completions/source/lint-error.source.d.ts +1 -3
  30. package/lib/browser/contrib/intelligent-completions/source/lint-error.source.d.ts.map +1 -1
  31. package/lib/browser/contrib/intelligent-completions/source/lint-error.source.js +13 -20
  32. package/lib/browser/contrib/intelligent-completions/source/lint-error.source.js.map +1 -1
  33. package/lib/browser/contrib/intelligent-completions/source/typing.source.d.ts +2 -2
  34. package/lib/browser/contrib/intelligent-completions/source/typing.source.d.ts.map +1 -1
  35. package/lib/browser/contrib/intelligent-completions/source/typing.source.js +6 -8
  36. package/lib/browser/contrib/intelligent-completions/source/typing.source.js.map +1 -1
  37. package/lib/browser/contrib/terminal/component/terminal-command-suggest-controller.js +2 -2
  38. package/lib/browser/contrib/terminal/component/terminal-command-suggest-controller.js.map +1 -1
  39. package/lib/browser/index.js +1 -1
  40. package/lib/browser/index.js.map +1 -1
  41. package/lib/browser/layout/ai-layout.d.ts.map +1 -1
  42. package/lib/browser/layout/ai-layout.js +2 -2
  43. package/lib/browser/layout/ai-layout.js.map +1 -1
  44. package/lib/browser/model/enhanceDecorationsCollection.d.ts +14 -10
  45. package/lib/browser/model/enhanceDecorationsCollection.d.ts.map +1 -1
  46. package/lib/browser/model/enhanceDecorationsCollection.js +42 -53
  47. package/lib/browser/model/enhanceDecorationsCollection.js.map +1 -1
  48. package/lib/browser/types.d.ts +2 -1
  49. package/lib/browser/types.d.ts.map +1 -1
  50. package/lib/browser/widget/inline-chat/inline-chat-editor.controller.d.ts +2 -1
  51. package/lib/browser/widget/inline-chat/inline-chat-editor.controller.d.ts.map +1 -1
  52. package/lib/browser/widget/inline-chat/inline-chat-editor.controller.js +13 -41
  53. package/lib/browser/widget/inline-chat/inline-chat-editor.controller.js.map +1 -1
  54. package/lib/browser/widget/inline-chat/inline-chat.feature.registry.d.ts +3 -13
  55. package/lib/browser/widget/inline-chat/inline-chat.feature.registry.d.ts.map +1 -1
  56. package/lib/browser/widget/inline-chat/inline-chat.feature.registry.js +24 -72
  57. package/lib/browser/widget/inline-chat/inline-chat.feature.registry.js.map +1 -1
  58. package/lib/browser/widget/inline-chat/inline-chat.service.d.ts +1 -6
  59. package/lib/browser/widget/inline-chat/inline-chat.service.d.ts.map +1 -1
  60. package/lib/browser/widget/inline-chat/inline-chat.service.js +5 -19
  61. package/lib/browser/widget/inline-chat/inline-chat.service.js.map +1 -1
  62. package/lib/browser/widget/inline-chat/inline-content-widget.d.ts +2 -5
  63. package/lib/browser/widget/inline-chat/inline-content-widget.d.ts.map +1 -1
  64. package/lib/browser/widget/inline-chat/inline-content-widget.js +17 -42
  65. package/lib/browser/widget/inline-chat/inline-content-widget.js.map +1 -1
  66. package/lib/browser/widget/inline-diff/inline-diff-previewer.d.ts +22 -5
  67. package/lib/browser/widget/inline-diff/inline-diff-previewer.d.ts.map +1 -1
  68. package/lib/browser/widget/inline-diff/inline-diff-previewer.js +61 -30
  69. package/lib/browser/widget/inline-diff/inline-diff-previewer.js.map +1 -1
  70. package/lib/browser/widget/inline-diff/inline-diff.controller.d.ts +8 -12
  71. package/lib/browser/widget/inline-diff/inline-diff.controller.d.ts.map +1 -1
  72. package/lib/browser/widget/inline-diff/inline-diff.controller.js +68 -96
  73. package/lib/browser/widget/inline-diff/inline-diff.controller.js.map +1 -1
  74. package/lib/browser/widget/inline-hint/inline-hint.controller.d.ts +0 -1
  75. package/lib/browser/widget/inline-hint/inline-hint.controller.d.ts.map +1 -1
  76. package/lib/browser/widget/inline-hint/inline-hint.controller.js +0 -5
  77. package/lib/browser/widget/inline-hint/inline-hint.controller.js.map +1 -1
  78. package/lib/browser/widget/inline-input/inline-input-widget.d.ts +12 -2
  79. package/lib/browser/widget/inline-input/inline-input-widget.d.ts.map +1 -1
  80. package/lib/browser/widget/inline-input/inline-input-widget.js +26 -18
  81. package/lib/browser/widget/inline-input/inline-input-widget.js.map +1 -1
  82. package/lib/browser/widget/inline-input/inline-input.controller.d.ts +14 -6
  83. package/lib/browser/widget/inline-input/inline-input.controller.d.ts.map +1 -1
  84. package/lib/browser/widget/inline-input/inline-input.controller.js +320 -169
  85. package/lib/browser/widget/inline-input/inline-input.controller.js.map +1 -1
  86. package/lib/browser/widget/inline-input/inline-input.module.less +4 -0
  87. package/lib/browser/widget/inline-input/inline-input.service.d.ts +19 -7
  88. package/lib/browser/widget/inline-input/inline-input.service.d.ts.map +1 -1
  89. package/lib/browser/widget/inline-input/inline-input.service.js +72 -12
  90. package/lib/browser/widget/inline-input/inline-input.service.js.map +1 -1
  91. package/lib/browser/widget/inline-input/model.d.ts +34 -0
  92. package/lib/browser/widget/inline-input/model.d.ts.map +1 -0
  93. package/lib/browser/widget/inline-input/model.js +63 -0
  94. package/lib/browser/widget/inline-input/model.js.map +1 -0
  95. package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.d.ts +8 -19
  96. package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.d.ts.map +1 -1
  97. package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.js +48 -41
  98. package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.js.map +1 -1
  99. package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts +17 -4
  100. package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts.map +1 -1
  101. package/lib/browser/widget/inline-stream-diff/live-preview.component.js +37 -5
  102. package/lib/browser/widget/inline-stream-diff/live-preview.component.js.map +1 -1
  103. package/lib/browser/widget/inline-stream-diff/live-preview.decoration.d.ts +7 -11
  104. package/lib/browser/widget/inline-stream-diff/live-preview.decoration.d.ts.map +1 -1
  105. package/lib/browser/widget/inline-stream-diff/live-preview.decoration.js +33 -77
  106. package/lib/browser/widget/inline-stream-diff/live-preview.decoration.js.map +1 -1
  107. package/package.json +21 -21
  108. package/src/browser/ai-core.contextkeys.ts +3 -0
  109. package/src/browser/ai-core.contribution.ts +63 -16
  110. package/src/browser/contrib/intelligent-completions/index.ts +9 -4
  111. package/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts +29 -8
  112. package/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts +13 -1
  113. package/src/browser/contrib/intelligent-completions/source/base.ts +28 -7
  114. package/src/browser/contrib/intelligent-completions/source/line-change.source.ts +31 -26
  115. package/src/browser/contrib/intelligent-completions/source/lint-error.source.ts +19 -31
  116. package/src/browser/contrib/intelligent-completions/source/typing.source.ts +7 -9
  117. package/src/browser/contrib/terminal/component/terminal-command-suggest-controller.tsx +1 -1
  118. package/src/browser/index.ts +2 -2
  119. package/src/browser/layout/ai-layout.tsx +5 -2
  120. package/src/browser/model/enhanceDecorationsCollection.ts +62 -77
  121. package/src/browser/types.ts +2 -2
  122. package/src/browser/widget/inline-chat/inline-chat-editor.controller.ts +21 -56
  123. package/src/browser/widget/inline-chat/inline-chat.feature.registry.ts +23 -90
  124. package/src/browser/widget/inline-chat/inline-chat.service.ts +2 -19
  125. package/src/browser/widget/inline-chat/inline-content-widget.tsx +14 -71
  126. package/src/browser/widget/inline-diff/inline-diff-previewer.ts +87 -32
  127. package/src/browser/widget/inline-diff/inline-diff.controller.ts +90 -114
  128. package/src/browser/widget/inline-hint/inline-hint.controller.ts +1 -7
  129. package/src/browser/widget/inline-input/inline-input-widget.tsx +34 -12
  130. package/src/browser/widget/inline-input/inline-input.controller.ts +453 -247
  131. package/src/browser/widget/inline-input/inline-input.module.less +4 -0
  132. package/src/browser/widget/inline-input/inline-input.service.ts +92 -13
  133. package/src/browser/widget/inline-input/model.ts +74 -0
  134. package/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx +58 -69
  135. package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +45 -6
  136. package/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx +40 -112
  137. package/lib/browser/model/styles.module.less +0 -7
  138. package/src/browser/model/styles.module.less +0 -7
@@ -5,3 +5,7 @@
5
5
  .input_wrapper {
6
6
  transform: translateY(-4px);
7
7
  }
8
+
9
+ .input_decoration_pending_container {
10
+ background-color: var(--vscode-diffEditor-unchangedCodeBackground);
11
+ }
@@ -1,27 +1,106 @@
1
- import { Injectable } from '@opensumi/di';
2
- import { Emitter, Event } from '@opensumi/ide-core-common';
3
- import { Position } from '@opensumi/ide-monaco';
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 InlineInputChatService {
7
- private _currentVisiblePosition: Position | undefined;
8
- public get currentVisiblePosition(): Position | undefined {
9
- return this._currentVisiblePosition;
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
- public setCurrentVisiblePosition(position: Position | undefined): void {
17
- this._currentVisiblePosition = position;
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 visible(): void {
21
- this._onInteractiveInputVisibleInPosition.fire(this._currentVisiblePosition);
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._onInteractiveInputVisibleInPosition.fire(undefined);
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 { ILivePreviewDiffDecorationSnapshotData, LivePreviewDiffDecorationModel } from './live-preview.decoration';
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 handleEdits(diffModel: IComputeDiffData): void {
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
- private async rateEditController(): Promise<void> {
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
- this.handleEdits(currentDiffModel);
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
- if (this.finallyDiffModel) {
489
- this.finallyRender(this.finallyDiffModel);
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,50 @@ 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
- this.rateEditController();
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
- this.finallyDiffModel = diffModel;
503
-
504
- // 可能存在 rate editr controller 处理完之后接口层流式才结束
505
- if (this.isEditing === false) {
506
- this.finallyRender(this.finallyDiffModel);
507
- }
470
+ transaction((tx) => {
471
+ this.finallyDiffModel.set(diffModel, tx);
472
+ // 可能存在 rate editor controller 处理完之后接口层流式才结束
473
+ if (this.isEditing === false) {
474
+ this.finallyRender(diffModel);
475
+ }
476
+ });
508
477
  }
509
478
 
510
479
  public finallyRender(diffModel: IComputeDiffData): void {
511
- // 流式结束后才会确定所有的 added range,再渲染 partial edit widgets
480
+ transaction((tx) => {
481
+ this.diffModel.set(diffModel, tx);
482
+ });
483
+
484
+ if (this.originalModel.id !== this.monacoEditor.getModel()?.id) {
485
+ return;
486
+ }
487
+
512
488
  this.renderPartialEditWidgets(diffModel);
513
- this.handleEdits(diffModel);
489
+ this.renderDiffEdits(diffModel);
514
490
  this.pushStackElement();
515
491
  this.monacoEditor.focus();
516
492
  }
517
493
 
494
+ public hide(): void {
495
+ this.livePreviewDiffDecorationModel.hide();
496
+ }
497
+
498
+ public resume(): void {
499
+ const finallyDiffModel = this.finallyDiffModel.get();
500
+ if (!finallyDiffModel) {
501
+ this.rateRenderEditController();
502
+ }
503
+
504
+ this.livePreviewDiffDecorationModel.resume();
505
+ }
506
+
518
507
  acceptAll(): void {
519
508
  this.livePreviewDiffDecorationModel.acceptUnProcessed();
520
509
  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
- export type IWidgetStatus = 'accept' | 'discard' | 'pending';
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 _decorationId: string;
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 recordDecorationId(id: string): void {
213
- this._decorationId = id;
217
+ public recordAddedRangeId(id: string): void {
218
+ this._addedRangeId = id;
214
219
  }
215
220
 
216
- public getDecorationId(): string {
217
- return this._decorationId;
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
+ }