1
1
import type { Selection , TextEditor } from 'vscode'
2
- import { ProgressLocation , Range , extensions , window } from 'vscode'
2
+ import { Position , ProgressLocation , Range , Uri , extensions , window , workspace } from 'vscode'
3
3
import type { AI , Action , Prompt } from '../types/index.js'
4
4
import { ai as aiIndex } from '../ai/index.js'
5
5
import type { BaseAI } from '../ai/base_ai.js'
@@ -13,7 +13,6 @@ export class RunActionCommand extends BaseCommand {
13
13
const configuration = await this . getAIConfiguration ( action )
14
14
const prompt = await this . getPrompt ( action )
15
15
16
- this . logger . log ( 'Commit changes before action...' )
17
16
await this . commitWithAction ( action , 'before' )
18
17
19
18
const message = `Ask '${ configuration . name } ' to '${ prompt . name } '...`
@@ -27,11 +26,14 @@ export class RunActionCommand extends BaseCommand {
27
26
const ai = await this . createAI ( configuration )
28
27
const completion = await ai . ask ( prompt . content , this . getActiveEditorText ( ) )
29
28
30
- this . logger . log ( 'Apply changes...' )
31
- await this . applyChanges ( completion )
29
+ if ( action . target === 'inplace' ) {
30
+ await this . applyChanges ( completion )
31
+ }
32
+ else if ( action . target === 'newfile' ) {
33
+ await this . showCompletion ( completion )
34
+ }
32
35
} )
33
36
34
- this . logger . log ( 'Commit changes after action...' )
35
37
await this . commitWithAction ( action , 'after' )
36
38
37
39
this . logger . log (
@@ -137,6 +139,8 @@ export class RunActionCommand extends BaseCommand {
137
139
}
138
140
139
141
protected async applyChanges ( content : string ) : Promise < void > {
142
+ this . logger . log ( 'Apply changes...' )
143
+
140
144
this . getActiveEditor ( ) . edit ( ( editBuilder ) => {
141
145
const range = this . hasActiveEditorSelection ( ) ? this . getActiveEditorSelection ( ) : new Range ( 0 , 0 , this . getActiveEditorText ( ) . length , 0 )
142
146
@@ -147,7 +151,16 @@ export class RunActionCommand extends BaseCommand {
147
151
await this . saveActiveEditor ( )
148
152
}
149
153
154
+ protected async showCompletion ( content : string ) : Promise < void > {
155
+ this . logger . log ( 'Show completion...' )
156
+
157
+ const editor = await workspace . openTextDocument ( { content, language : 'plaintext' } )
158
+ await window . showTextDocument ( editor )
159
+ }
160
+
150
161
protected async commitWithAction ( action : Action , when : 'before' | 'after' ) : Promise < void > {
162
+ this . logger . log ( `Commit changes ${ when } action...` )
163
+
151
164
let commitMessage = when === 'before' ? action . git ?. commitMessageBeforeAction : action . git ?. commitMessageAfterAction
152
165
153
166
if ( ! commitMessage ) {
0 commit comments