File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed
packages/utils-ai-vscode/src/commands Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,40 @@ export function correctCommand(context: vscode.ExtensionContext) {
17
17
const editor = vscode . window . activeTextEditor
18
18
19
19
if ( editor ) {
20
+ const editorFilename = editor . document . fileName // Full path to the file
21
+ const filename = editorFilename . split ( '/' ) . pop ( )
22
+
23
+ // Commit current file to git before correcting. This is useful for tracking changes.
24
+ const gitExtension = vscode . extensions . getExtension ( 'vscode.git' ) ?. exports
25
+ const isActivated = gitExtension . enabled
26
+
27
+ if ( ! isActivated ) {
28
+ vscode . window . showErrorMessage ( 'Git is not activated. Please activate Git in VSCode.' )
29
+ return
30
+ }
31
+
32
+ if ( isActivated ) {
33
+ const git = gitExtension . getAPI ( 1 )
34
+
35
+ if ( git . repositories . length > 0 ) {
36
+ const repository = git . repositories [ 0 ]
37
+
38
+ vscode . window . showInformationMessage ( `Committing ${ filename } ...` )
39
+
40
+ // Save to be sure to commit the latest changes
41
+ await editor . document . save ( )
42
+
43
+ try {
44
+ await repository . add ( [ editorFilename ] )
45
+ await repository . commit ( `chore: save ${ filename } before correcting` )
46
+ }
47
+ catch ( error : any ) {
48
+ // Ignore error because it's mean that the file is already committed
49
+ }
50
+ }
51
+ }
52
+
20
53
const prompt = getPrompt ( 'spell-checker-md' , 'en' )
21
- const filename = editor . document . fileName
22
54
23
55
const hasSelection = ! editor . selection . isEmpty
24
56
const selection = editor . selection
You can’t perform that action at this time.
0 commit comments