fix: commit message placeholders

This commit is contained in:
Carl-Robert Linnupuu 2024-06-17 16:54:06 +03:00
parent 479ae947ff
commit 78e4353f91
3 changed files with 12 additions and 18 deletions

View file

@ -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<String> getEventListener(Project project, Document document) {
private CompletionEventListener<String> 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<String> includedChangesFilePaths,

View file

@ -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.

View file

@ -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() {