@@ -21,6 +21,7 @@ import { EditorManager } from '@theia/editor/lib/browser';
21
21
import { FileService } from '@theia/filesystem/lib/browser/file-service' ;
22
22
import { MonacoWorkspace } from '@theia/monaco/lib/browser/monaco-workspace' ;
23
23
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service' ;
24
+ import { ChangeSetFileElement } from './change-set-file-element' ;
24
25
25
26
@injectable ( )
26
27
export class ChangeSetFileService {
@@ -82,28 +83,15 @@ export class ChangeSetFileService {
82
83
return this . labelProvider . getLongName ( uri . parent ) ;
83
84
}
84
85
85
- async open ( uri : URI , targetState : string ) : Promise < void > {
86
- const exists = await this . fileService . exists ( uri ) ;
86
+ async open ( element : ChangeSetFileElement ) : Promise < void > {
87
+ const exists = await this . fileService . exists ( element . uri ) ;
87
88
if ( exists ) {
88
- open ( this . openerService , uri ) ;
89
+ await open ( this . openerService , element . uri ) ;
89
90
return ;
90
91
}
91
- const editor = await this . editorManager . open ( uri . withScheme ( UNTITLED_SCHEME ) , {
92
+ await this . editorManager . open ( element . changedUri , {
92
93
mode : 'reveal'
93
94
} ) ;
94
- editor . editor . executeEdits ( [ {
95
- newText : targetState ,
96
- range : {
97
- start : {
98
- character : 1 ,
99
- line : 1 ,
100
- } ,
101
- end : {
102
- character : 1 ,
103
- line : 1 ,
104
- } ,
105
- }
106
- } ] ) ;
107
95
}
108
96
109
97
async openDiff ( originalUri : URI , suggestedUri : URI ) : Promise < void > {
@@ -112,7 +100,7 @@ export class ChangeSetFileService {
112
100
// Currently we don't have a great way to show the suggestions in a diff editor with accept/reject buttons
113
101
// So we just use plain diffs with the suggestions as original and the current state as modified, so users can apply changes in their current state
114
102
// But this leads to wrong colors and wrong label (revert change instead of accept change)
115
- const diffUri = DiffUris . encode ( suggestedUri , openedUri ,
103
+ const diffUri = DiffUris . encode ( openedUri , suggestedUri ,
116
104
`AI Changes: ${ this . labelProvider . getName ( originalUri ) } ` ,
117
105
) ;
118
106
open ( this . openerService , diffUri ) ;
@@ -139,7 +127,7 @@ export class ChangeSetFileService {
139
127
await this . monacoWorkspace . applyBackgroundEdit ( document , [ {
140
128
range : document . textEditorModel . getFullModelRange ( ) ,
141
129
text
142
- } ] , true ) ;
130
+ } ] , ( editor , wasDirty ) => editor === undefined || ! wasDirty ) ;
143
131
} else {
144
132
await this . fileService . write ( uri , text ) ;
145
133
}
0 commit comments