mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-19 07:54:46 +00:00
fix: find referenced files outside of edt
This commit is contained in:
parent
db9b8d177c
commit
d19dd4bb23
2 changed files with 20 additions and 10 deletions
|
|
@ -5,7 +5,7 @@ import static java.lang.String.format;
|
|||
import com.intellij.icons.AllIcons.General;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.components.ActionLink;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import java.awt.BorderLayout;
|
||||
|
|
@ -24,24 +24,22 @@ public class SelectedFilesAccordion extends JPanel {
|
|||
|
||||
public SelectedFilesAccordion(
|
||||
@NotNull Project project,
|
||||
@NotNull List<String> referencedFilePaths) {
|
||||
@NotNull List<VirtualFile> referencedFiles) {
|
||||
super(new BorderLayout());
|
||||
setOpaque(false);
|
||||
|
||||
var contentPanel = createContentPanel(project, referencedFilePaths);
|
||||
add(createToggleButton(contentPanel, referencedFilePaths.size()), BorderLayout.NORTH);
|
||||
var contentPanel = createContentPanel(project, referencedFiles);
|
||||
add(createToggleButton(contentPanel, referencedFiles.size()), BorderLayout.NORTH);
|
||||
add(contentPanel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private JPanel createContentPanel(Project project, List<String> referencedFilePaths) {
|
||||
private JPanel createContentPanel(Project project, List<VirtualFile> referencedFiles) {
|
||||
var panel = new JPanel();
|
||||
panel.setOpaque(false);
|
||||
panel.setVisible(true);
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||
panel.setBorder(JBUI.Borders.empty(4, 0));
|
||||
referencedFilePaths.stream()
|
||||
.map(filePath -> LocalFileSystem.getInstance().findFileByPath(filePath))
|
||||
.filter(Objects::nonNull)
|
||||
referencedFiles.stream()
|
||||
.map(virtualFile -> {
|
||||
var actionLink = new ActionLink(
|
||||
Paths.get(virtualFile.getPath()).getFileName().toString(),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.intellij.openapi.Disposable
|
|||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.ui.ColorUtil
|
||||
import com.intellij.ui.JBColor
|
||||
import com.intellij.ui.RoundedIcon
|
||||
|
|
@ -22,6 +23,10 @@ import ee.carlrobert.codegpt.toolwindow.chat.ui.ChatMessageResponseBody
|
|||
import ee.carlrobert.codegpt.toolwindow.chat.ui.ImageAccordion
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ui.SelectedFilesAccordion
|
||||
import ee.carlrobert.codegpt.ui.IconActionButton
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.awt.Image
|
||||
import java.io.IOException
|
||||
import java.nio.file.Files
|
||||
|
|
@ -147,7 +152,7 @@ class UserMessagePanel(
|
|||
)
|
||||
}
|
||||
|
||||
private fun getAdditionalContextPanel(project: Project?, message: Message): JPanel? {
|
||||
private fun getAdditionalContextPanel(project: Project, message: Message): JPanel? {
|
||||
val documentationDetails = message.documentationDetails
|
||||
val referencedFilePaths = message.referencedFilePaths ?: emptyList()
|
||||
if (documentationDetails == null && referencedFilePaths.isEmpty() && message.personaName.isNullOrEmpty()) {
|
||||
|
|
@ -188,7 +193,14 @@ class UserMessagePanel(
|
|||
}
|
||||
|
||||
if (referencedFilePaths.isNotEmpty()) {
|
||||
additionalContextPanel.add(SelectedFilesAccordion(project!!, referencedFilePaths))
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val referencedFiles = referencedFilePaths.mapNotNull {
|
||||
LocalFileSystem.getInstance().findFileByPath(it)
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
additionalContextPanel.add(SelectedFilesAccordion(project, referencedFiles))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue