diff --git a/build.gradle.kts b/build.gradle.kts index 2af83072..9dd81467 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "com.devoxx.genie" -version = "0.3.0" +version = "0.3.1" repositories { mavenCentral() diff --git a/src/main/java/com/devoxx/genie/model/ChatInteraction.java b/src/main/java/com/devoxx/genie/model/ChatInteraction.java deleted file mode 100644 index ac177f74..00000000 --- a/src/main/java/com/devoxx/genie/model/ChatInteraction.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.devoxx.genie.model; - -import com.devoxx.genie.model.request.ChatMessageContext; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@AllArgsConstructor -@Setter -@Getter -public class ChatInteraction { - private ChatMessageContext chatMessageContext; - private String response; -} diff --git a/src/main/java/com/devoxx/genie/service/MessageCreationService.java b/src/main/java/com/devoxx/genie/service/MessageCreationService.java index e1cee3e3..2bcaaa05 100644 --- a/src/main/java/com/devoxx/genie/service/MessageCreationService.java +++ b/src/main/java/com/devoxx/genie/service/MessageCreationService.java @@ -64,7 +64,7 @@ public UserMessage createUserMessage(@NotNull ChatMessageContext chatMessageCont } // If git diff is enabled, add special instructions - if (DevoxxGenieStateService.getInstance().getUseDiffMerge()) { + if (DevoxxGenieStateService.getInstance().getUseSimpleDiff()) { stringBuilder.append("").append(GIT_DIFF_INSTRUCTIONS).append("\n\n"); } @@ -137,8 +137,7 @@ public UserMessage createUserMessage(@NotNull ChatMessageContext chatMessageCont StringBuilder stringBuilder = new StringBuilder(); // If git diff is enabled, add special instructions at the beginning - if (DevoxxGenieStateService.getInstance().getUseDiffMerge() || - DevoxxGenieStateService.getInstance().getUseSimpleDiff()) { + if (DevoxxGenieStateService.getInstance().getUseSimpleDiff()) { stringBuilder.append("").append(GIT_DIFF_INSTRUCTIONS).append("\n\n"); } diff --git a/src/main/java/com/devoxx/genie/service/gitdiff/GitMergeService.java b/src/main/java/com/devoxx/genie/service/gitdiff/GitMergeService.java index 43a13323..4e73f47e 100644 --- a/src/main/java/com/devoxx/genie/service/gitdiff/GitMergeService.java +++ b/src/main/java/com/devoxx/genie/service/gitdiff/GitMergeService.java @@ -1,16 +1,11 @@ package com.devoxx.genie.service.gitdiff; -import com.devoxx.genie.ui.settings.DevoxxGenieStateService; import com.devoxx.genie.ui.util.NotificationUtil; -import com.intellij.diff.DiffContentFactory; -import com.intellij.diff.DiffManager; -import com.intellij.diff.DiffManagerImpl; +import com.intellij.diff.DiffManagerEx; import com.intellij.diff.contents.DiffContent; -import com.intellij.diff.contents.DocumentContent; import com.intellij.diff.contents.DocumentContentImpl; import com.intellij.diff.requests.DiffRequest; import com.intellij.diff.requests.SimpleDiffRequest; -import com.intellij.diff.requests.TextMergeRequestImpl; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; @@ -30,48 +25,6 @@ public static GitMergeService getInstance() { return ApplicationManager.getApplication().getService(GitMergeService.class); } - /** - * Shows a three-way merge view with: - * - Left: Original code - * - Center: Merge result (initially empty) - * - Right: LLM's modified version - */ - public void showMerge(@NotNull Project project, - @NotNull String originalContent, - @NotNull String modifiedContent, - @NotNull String title, - @NotNull Document targetDocument) { - DevoxxGenieStateService instance = DevoxxGenieStateService.getInstance(); - if (!instance.getUseSimpleDiff() && !instance.getUseDiffMerge()) { - LOG.info("Diff view is disabled"); - return; - } - - ApplicationManager.getApplication().invokeLater(() -> { - DiffContentFactory factory = DiffContentFactory.getInstance(); - - // Create contents for three-way merge - DocumentContent originalContentDoc = factory.create(project, originalContent); - - DocumentContent modifiedContent1 = factory.create(project, modifiedContent); - DocumentContent targetDocumentContent = factory.create(project, targetDocument); - - Document originalDocument = originalContentDoc.getDocument(); - - TextMergeRequestImpl request = new TextMergeRequestImpl( - project, - targetDocumentContent, - originalDocument.getCharsSequence(), - List.of(originalContentDoc, modifiedContent1, targetDocumentContent), - title, - List.of("Original Code", "LLM Modified Code", "Merge Result") - ); - - // Show the merge dialog - DiffManager.getInstance().showMerge(project, request); - }); - } - /** * Git diff view * @param project the project @@ -107,7 +60,7 @@ public void showDiffView(Project project, VirtualFile originalFile, String sugge ); ApplicationManager.getApplication().invokeLater(() -> - DiffManagerImpl.getInstance().showDiff(project, diffRequest)); + DiffManagerEx.getInstance().showDiff(project, diffRequest)); }); } } diff --git a/src/main/java/com/devoxx/genie/ui/DevoxxGenieToolWindowContent.java b/src/main/java/com/devoxx/genie/ui/DevoxxGenieToolWindowContent.java index 1bc4f0d4..4803d81d 100644 --- a/src/main/java/com/devoxx/genie/ui/DevoxxGenieToolWindowContent.java +++ b/src/main/java/com/devoxx/genie/ui/DevoxxGenieToolWindowContent.java @@ -21,11 +21,6 @@ import com.devoxx.genie.ui.settings.DevoxxGenieStateService; import com.devoxx.genie.ui.topic.AppTopics; import com.devoxx.genie.ui.util.NotificationUtil; -import com.intellij.diff.DiffManagerImpl; -import com.intellij.diff.contents.DiffContent; -import com.intellij.diff.contents.FileContentImpl; -import com.intellij.diff.requests.DiffRequest; -import com.intellij.diff.requests.SimpleDiffRequest; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -33,17 +28,13 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.NlsContexts; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.ToolWindow; import com.intellij.ui.OnePixelSplitter; import com.intellij.ui.components.JBScrollPane; import com.intellij.util.messages.MessageBusConnection; import lombok.Getter; -import org.apache.xmlbeans.impl.xb.xsdschema.SimpleContentDocument; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/com/devoxx/genie/ui/panel/ChatResponsePanel.java b/src/main/java/com/devoxx/genie/ui/panel/ChatResponsePanel.java index 055221d3..4ee8f6f8 100644 --- a/src/main/java/com/devoxx/genie/ui/panel/ChatResponsePanel.java +++ b/src/main/java/com/devoxx/genie/ui/panel/ChatResponsePanel.java @@ -10,12 +10,6 @@ import com.devoxx.genie.ui.processor.NodeProcessorFactory; import com.devoxx.genie.ui.settings.DevoxxGenieStateService; import com.devoxx.genie.util.DefaultLLMSettingsUtil; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.fileEditor.FileEditorManager; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.JBColor; import com.knuddels.jtokkit.api.Encoding; @@ -33,7 +27,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import java.util.Objects; import static com.devoxx.genie.ui.util.DevoxxGenieFontsUtil.SourceCodeProFontPlan14; @@ -68,9 +61,7 @@ private void addResponsePane(@NotNull ChatMessageContext chatMessageContext) { DevoxxGenieStateService stateService = DevoxxGenieStateService.getInstance(); // If git diff is enabled, try to extract code blocks and show diff - if (stateService.getUseDiffMerge()) { - processGitMerge(chatMessageContext, document); - } else if (stateService.getUseSimpleDiff()) { + if (stateService.getUseSimpleDiff()) { processGitDiff(chatMessageContext, document); } @@ -88,65 +79,6 @@ private void addResponsePane(@NotNull ChatMessageContext chatMessageContext) { } } - private void processGitMerge(@NotNull ChatMessageContext chatMessageContext, @NotNull Node document) { - // Get original code from context - String originalCode; - EditorInfo editorInfo = chatMessageContext.getEditorInfo(); - - // Wrap the document access in a read action - originalCode = ApplicationManager - .getApplication() - .runReadAction((Computable) () -> { - if (editorInfo.getSelectedText() != null) { - return editorInfo.getSelectedText(); - } else { - List selectedFiles = editorInfo.getSelectedFiles(); - if (selectedFiles == null || selectedFiles.isEmpty()) { - return null; - } - VirtualFile originalFile = selectedFiles.get(0); - Document originalDoc = FileDocumentManager.getInstance().getDocument(originalFile); - if (originalDoc == null) { - return null; - } - return originalDoc.getText(); - } - }); - - if (originalCode == null) { - return; - } - - - // Find the first code block in the response - Node node = document.getFirstChild(); - while (node != null) { - if (node instanceof FencedCodeBlock codeBlock) { - String modifiedCode = codeBlock.getLiteral(); - - Document editorDocument = com.intellij.openapi.application.ApplicationManager.getApplication() - .runReadAction((com.intellij.openapi.util.Computable) () -> - Objects.requireNonNull(FileEditorManager.getInstance(chatMessageContext.getProject()) - .getSelectedTextEditor()) - .getDocument() - ); - - // Show merge using our service - GitMergeService.getInstance().showMerge( - chatMessageContext.getProject(), - originalCode, - modifiedCode, - "Merge LLM Changes", - editorDocument - ); - - // Only show diff for first code block - break; - } - node = node.getNext(); - } - } - private void addMetricExecutionInfo(@NotNull ChatMessageContext chatMessageContext) { JPanel metricExecutionInfoPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); metricExecutionInfoPanel.setOpaque(false); @@ -191,34 +123,7 @@ private void processGitDiff(@NotNull ChatMessageContext chatMessageContext, @Not return; } - // Handle single file case - if (editorInfo.getSelectedText() != null) { - Editor editor = FileEditorManager.getInstance(chatMessageContext.getProject()) - .getSelectedTextEditor(); - - if (editor != null) { - String originalCode = editorInfo.getSelectedText(); - - // Find first code block in response - Node node = document.getFirstChild(); - while (node != null) { - if (node instanceof FencedCodeBlock codeBlock) { - - GitMergeService.getInstance().showMerge( - chatMessageContext.getProject(), - originalCode, - codeBlock.getLiteral(), - "Merge LLM Changes", - editor.getDocument() - ); - break; - } - node = node.getNext(); - } - } - } - // Handle multiple files case - else if (editorInfo.getSelectedFiles() != null && !editorInfo.getSelectedFiles().isEmpty()) { + if (editorInfo.getSelectedFiles() != null && !editorInfo.getSelectedFiles().isEmpty()) { List files = editorInfo.getSelectedFiles(); List modifiedContents = new ArrayList<>(); diff --git a/src/main/java/com/devoxx/genie/ui/renderer/FileListCellRenderer.java b/src/main/java/com/devoxx/genie/ui/renderer/FileListCellRenderer.java deleted file mode 100644 index b622fed8..00000000 --- a/src/main/java/com/devoxx/genie/ui/renderer/FileListCellRenderer.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.devoxx.genie.ui.renderer; - -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; - -import javax.swing.*; -import java.awt.*; - -public class FileListCellRenderer extends DefaultListCellRenderer { - - private final Project project; - - public FileListCellRenderer(Project project) { - this.project = project; - } - - @Override - public Component getListCellRendererComponent(JList list, - Object value, - int index, - boolean isSelected, - boolean cellHasFocus) { - JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - - if (value instanceof VirtualFile file) { - // label.setIcon(FileTypeIconUtil.getFileTypeIcon(project, file)); - label.setText(file.getName()); - } - - return label; - } -} diff --git a/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java b/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java index 0b4412a5..2688336c 100644 --- a/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java +++ b/src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java @@ -43,7 +43,6 @@ public static DevoxxGenieStateService getInstance() { private Boolean showExecutionTime = true; // Git Diff features - private Boolean useDiffMerge = false; private Boolean useSimpleDiff = false; // Local LLM URL fields diff --git a/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitDiffMode.java b/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitDiffMode.java index b749a572..0e4d2bcb 100644 --- a/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitDiffMode.java +++ b/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitDiffMode.java @@ -2,39 +2,6 @@ public enum GitDiffMode { DISABLED("Disabled", "", ""), - DIFF_MERGE("Git Diff Merge", "/images/diff_merge.jpg", - """ - - - - - -

Three-panel comparison

-

Shows three-way comparison between original, suggested, and merged changes

-
    -
  • Left panel: Original file labeled "Original code"
  • -
  • Center panel: Merge result labeled "Merged"
  • -
  • Right panel: LLM's modified version labeled "LLM suggested"
  • -
- - """), SIMPLE_DIFF("Simple Git Diff", "/images/simple_diff.jpg", """ diff --git a/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitMergeSettingsComponent.java b/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitMergeSettingsComponent.java index a4ef9a67..5a3d330c 100644 --- a/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitMergeSettingsComponent.java +++ b/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitMergeSettingsComponent.java @@ -52,9 +52,7 @@ public Component getListCellRendererComponent(JList list, Object value, } private GitDiffMode determineCurrentMode() { - if (stateService.getUseDiffMerge()) { - return GitDiffMode.DIFF_MERGE; - } else if (stateService.getUseSimpleDiff()) { + if (stateService.getUseSimpleDiff()) { return GitDiffMode.SIMPLE_DIFF; } return GitDiffMode.DISABLED; diff --git a/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitMergeSettingsConfigurable.java b/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitMergeSettingsConfigurable.java index 88d66f87..62fc8406 100644 --- a/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitMergeSettingsConfigurable.java +++ b/src/main/java/com/devoxx/genie/ui/settings/gitmerge/GitMergeSettingsConfigurable.java @@ -49,7 +49,6 @@ public void apply() { DevoxxGenieStateService stateService = DevoxxGenieStateService.getInstance(); GitDiffMode selectedMode = (GitDiffMode) diffSettingsComponent.getGitDiffModeComboBox().getSelectedItem(); - stateService.setUseDiffMerge(selectedMode == GitDiffMode.DIFF_MERGE); stateService.setUseSimpleDiff(selectedMode == GitDiffMode.SIMPLE_DIFF); } @@ -61,9 +60,7 @@ public void reset() { } private GitDiffMode determineCurrentMode(@NotNull DevoxxGenieStateService stateService) { - if (stateService.getUseDiffMerge()) { - return GitDiffMode.DIFF_MERGE; - } else if (stateService.getUseSimpleDiff()) { + if (stateService.getUseSimpleDiff()) { return GitDiffMode.SIMPLE_DIFF; } return GitDiffMode.DISABLED; diff --git a/src/main/java/com/devoxx/genie/ui/util/SettingsDialogUtil.java b/src/main/java/com/devoxx/genie/ui/util/SettingsDialogUtil.java index 2fa2ed03..e139ca96 100644 --- a/src/main/java/com/devoxx/genie/ui/util/SettingsDialogUtil.java +++ b/src/main/java/com/devoxx/genie/ui/util/SettingsDialogUtil.java @@ -5,9 +5,6 @@ public class SettingsDialogUtil { - /** - * Show the settings dialog. - */ public static void showSettingsDialog(Project project) { ShowSettingsUtil.getInstance().showSettingsDialog(project, "DevoxxGenie"); } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 4d4ae2ce..e05bb4d8 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -35,6 +35,10 @@ ]]> v0.3.1 +
    +
  • Feature #339: Use simple Git Diff using com.intellij.diff.DiffManagerEx
  • +

v0.3.0

  • Feature #339: Git Merge Diff
  • diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index cd4109b7..d9526910 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,2 @@ -#Mon Dec 02 18:40:46 CET 2024 -version=0.2.30 +#Wed Dec 04 16:52:16 CET 2024 +version=0.3.1