Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] Support for multiple files in side-by-side diff #343

Open
mydeveloperplanet opened this issue Dec 3, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@mydeveloperplanet
Copy link
Collaborator

Follow-up from #339

Support multiple files in the side-by-side diff. In v0.3.0 only one file is supported.
Test:

  • Use the DevoxxGeniePlugin source code
  • Add files `AddDirectoryAction' and 'AddFileAction'
  • Select 'Simple Git Diff' in the settings
  • Prompt: Add javadoc to both files
  • Ollama with Llam3.2 is used

Git diff is: both files are present in the 'LLM suggested' side, the 'original code' of AddFileAction is present. So only these changes can be applied easily
image

LLM response is:

// Filename: AddDirectoryAction.java
package com.devoxx.genie.action;

import com.devoxx.genie.model.LanguageModel;
import com.devoxx.genie.model.ScanContentResult;
import com.devoxx.genie.model.enumarations.ModelProvider;
import com.devoxx.genie.service.DevoxxGenieSettingsService;
import com.devoxx.genie.service.FileListManager;
import com.devoxx.genie.service.LLMModelRegistryService;
import com.devoxx.genie.service.ProjectContentService;
import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
import com.devoxx.genie.ui.util.NotificationUtil;
import com.devoxx.genie.ui.util.WindowContextFormatterUtil;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

/**
 * Action to add directory content to clipboard.
 */
public class AddDirectoryAction extends DumbAwareAction {

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        Project project = e.getProject();
        if (project == null) {
            return;
        }

        ensureToolWindowVisible(project);

        FileListManager fileListManager = FileListManager.getInstance();
        VirtualFile[] children = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
        List<VirtualFile> filesToAdd = new ArrayList<>();

        for (VirtualFile child : children) {
            if (!child.isDirectory() && !fileListManager.contains(child)) {
                filesToAdd.add(child);
            }
        }

        if (!filesToAdd.isEmpty()) {
            fileListManager.addFiles(filesToAdd);
            NotificationUtil.sendNotification(project, "Added " + filesToAdd.size() + " file(s) to prompt context");
        } else {
            NotificationUtil.sendNotification(project, "No new files to add or only directories selected");
        }
    }

    @Override
    public void update(@NotNull AnActionEvent e) {
        VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
        e.getPresentation().setEnabledAndVisible(files != null && files.length > 0);
    }

    @Override
    public @NotNull ActionUpdateThread getActionUpdateThread() {
        return ActionUpdateThread.BGT;
    }

    @Override
    public boolean isDumbAware() {
        return true;
    }
}

// Filename: AddFileAction.java
package com.devoxx.genie.action;

import com.devoxx.genie.service.FileListManager;
import com.devoxx.genie.ui.util.NotificationUtil;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

/**
 * Action to add file(s) to prompt context.
 */
public class AddFileAction extends DumbAwareAction {

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        Project project = e.getProject();
        if (project == null) {
            return;
        }

        ensureToolWindowVisible(project);

        FileListManager fileListManager = FileListManager.getInstance();
        VirtualFile[] selectedFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);

        if (selectedFiles != null && selectedFiles.length > 0) {
            List<VirtualFile> filesToAdd = new ArrayList<>();

            for (VirtualFile file : selectedFiles) {
                if (!file.isDirectory() && !fileListManager.contains(file)) {
                    filesToAdd.add(file);
                }
            }

            if (!filesToAdd.isEmpty()) {
                fileListManager.addFiles(filesToAdd);
                NotificationUtil.sendNotification(project, "Added " + filesToAdd.size() + " file(s) to prompt context");
            } else {
                NotificationUtil.sendNotification(project, "No new files to add or only directories selected");
            }
        } else {
            NotificationUtil.sendNotification(project, "No files selected");
        }
    }

    @Override
    public void update(@NotNull AnActionEvent e) {
        VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
        e.getPresentation().setEnabledAndVisible(files != null && files.length > 0);
    }

    @Override
    public @NotNull ActionUpdateThread getActionUpdateThread() {
        return ActionUpdateThread.BGT;
    }

    @Override
    public boolean isDumbAware() {
        return true;
    }
}
@stephanj stephanj added the enhancement New feature or request label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants