Skip to content

Commit

Permalink
feat: commit file before correcting
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbapapazes committed Oct 25, 2023
1 parent 3879945 commit 8e5c7c3
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion packages/utils-ai-vscode/src/commands/correct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,40 @@ export function correctCommand(context: vscode.ExtensionContext) {
const editor = vscode.window.activeTextEditor

if (editor) {
const editorFilename = editor.document.fileName // Full path to the file
const filename = editorFilename.split('/').pop()

// Commit current file to git before correcting. This is useful for tracking changes.
const gitExtension = vscode.extensions.getExtension('vscode.git')?.exports
const isActivated = gitExtension.enabled

if (!isActivated) {
vscode.window.showErrorMessage('Git is not activated. Please activate Git in VSCode.')
return
}

if (isActivated) {
const git = gitExtension.getAPI(1)

if (git.repositories.length > 0) {
const repository = git.repositories[0]

vscode.window.showInformationMessage(`Committing ${filename}...`)

// Save to be sure to commit the latest changes
await editor.document.save()

try {
await repository.add([editorFilename])
await repository.commit(`chore: save ${filename} before correcting`)
}
catch (error: any) {
// Ignore error because it's mean that the file is already committed
}
}
}

const prompt = getPrompt('spell-checker-md', 'en')
const filename = editor.document.fileName

const hasSelection = !editor.selection.isEmpty
const selection = editor.selection
Expand Down

0 comments on commit 8e5c7c3

Please sign in to comment.