diff --git a/src/main/java/ee/carlrobert/codegpt/actions/GenerateGitCommitMessageAction.java b/src/main/java/ee/carlrobert/codegpt/actions/GenerateGitCommitMessageAction.java index 405088af..d1492e01 100644 --- a/src/main/java/ee/carlrobert/codegpt/actions/GenerateGitCommitMessageAction.java +++ b/src/main/java/ee/carlrobert/codegpt/actions/GenerateGitCommitMessageAction.java @@ -1,7 +1,6 @@ package ee.carlrobert.codegpt.actions; import static com.intellij.openapi.ui.Messages.OK; -import static com.intellij.util.ObjectUtils.tryCast; import static ee.carlrobert.codegpt.settings.service.ServiceType.YOU; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; @@ -14,9 +13,6 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.WriteCommandAction; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsDataKeys; @@ -97,14 +93,13 @@ public class GenerateGitCommitMessageAction extends AnAction { return; } - var editor = getCommitMessageEditor(event); - if (editor != null) { - ((EditorEx) editor).setCaretVisible(false); + var commitWorkflowUi = event.getData(VcsDataKeys.COMMIT_WORKFLOW_UI); + if (commitWorkflowUi != null) { CompletionRequestService.getInstance() .generateCommitMessageAsync( project.getService(CommitMessageTemplate.class).getSystemPrompt(), gitDiff, - getEventListener(project, editor.getDocument())); + getEventListener(project, commitWorkflowUi)); } } @@ -113,7 +108,9 @@ public class GenerateGitCommitMessageAction extends AnAction { return ActionUpdateThread.EDT; } - private CompletionEventListener getEventListener(Project project, Document document) { + private CompletionEventListener getEventListener( + Project project, + CommitWorkflowUi commitWorkflowUi) { return new CompletionEventListener<>() { private final StringBuilder messageBuilder = new StringBuilder(); @@ -124,7 +121,7 @@ public class GenerateGitCommitMessageAction extends AnAction { application.invokeLater(() -> application.runWriteAction(() -> WriteCommandAction.runWriteCommandAction(project, () -> - document.setText(messageBuilder)))); + commitWorkflowUi.getCommitMessageUi().setText(messageBuilder.toString())))); } @Override @@ -138,13 +135,6 @@ public class GenerateGitCommitMessageAction extends AnAction { }; } - private Editor getCommitMessageEditor(AnActionEvent event) { - var commitMessage = tryCast( - event.getData(VcsDataKeys.COMMIT_MESSAGE_CONTROL), - CommitMessage.class); - return commitMessage != null ? commitMessage.getEditorField().getEditor() : null; - } - private String getGitDiff( Project project, List includedChangesFilePaths, diff --git a/src/main/resources/prompts/generate-commit-message-system-prompt.txt b/src/main/resources/prompts/generate-commit-message-system-prompt.txt index 78d7cb09..88e05fce 100644 --- a/src/main/resources/prompts/generate-commit-message-system-prompt.txt +++ b/src/main/resources/prompts/generate-commit-message-system-prompt.txt @@ -1,3 +1,6 @@ +Branch: {BRANCH_NAME} +Date: {DATE_ISO_8601} + Write a short and descriptive git commit message for the following git diff. Use imperative mood, present tense, active voice and verbs. Your entire response will be passed directly into git commit. \ No newline at end of file diff --git a/src/test/kotlin/testsupport/mixin/ShortcutsTestMixin.kt b/src/test/kotlin/testsupport/mixin/ShortcutsTestMixin.kt index 2273ca08..1e325475 100644 --- a/src/test/kotlin/testsupport/mixin/ShortcutsTestMixin.kt +++ b/src/test/kotlin/testsupport/mixin/ShortcutsTestMixin.kt @@ -45,9 +45,10 @@ interface ShortcutsTestMixin { GeneralSettings.getCurrentState().selectedService = ServiceType.YOU } - fun useLlamaService() { + fun useLlamaService(codeCompletionsEnabled: Boolean = false) { GeneralSettings.getCurrentState().selectedService = ServiceType.LLAMA_CPP LlamaSettings.getCurrentState().serverPort = null + LlamaSettings.getCurrentState().isCodeCompletionsEnabled = codeCompletionsEnabled } fun useGoogleService() {