mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-19 07:54:46 +00:00
fix: long running task on EDT
This commit is contained in:
parent
23437c1cea
commit
bcf1e6fcf8
3 changed files with 44 additions and 32 deletions
|
|
@ -3,6 +3,7 @@ package ee.carlrobert.codegpt;
|
|||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
|
@ -17,7 +18,7 @@ public record ReferencedFile(String fileName, String filePath, String fileConten
|
|||
return new ReferencedFile(
|
||||
file.getName(),
|
||||
file.getPath(),
|
||||
readContent(file)
|
||||
FileUtil.readContent(file)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -35,23 +36,7 @@ public record ReferencedFile(String fileName, String filePath, String fileConten
|
|||
if (document != null && documentManager.isDocumentUnsaved(document)) {
|
||||
return document.getText();
|
||||
}
|
||||
return readContent(virtualFile);
|
||||
}
|
||||
|
||||
private static String readContent(File file) {
|
||||
try {
|
||||
return new String(Files.readAllBytes(Paths.get(file.getPath())));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read file content", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String readContent(VirtualFile virtualFile) {
|
||||
try {
|
||||
return VfsUtilCore.loadText(virtualFile);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read virtual file content", e);
|
||||
}
|
||||
return FileUtil.readContent(virtualFile);
|
||||
}
|
||||
|
||||
public String getFileExtension() {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import com.intellij.openapi.project.Project
|
|||
import com.intellij.openapi.ui.JBMenuItem
|
||||
import com.intellij.openapi.ui.JBPopupMenu
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.readText
|
||||
import com.intellij.ui.components.JBLabel
|
||||
import com.intellij.util.IconUtil
|
||||
import com.intellij.util.ui.JBUI
|
||||
|
|
@ -24,6 +23,10 @@ import ee.carlrobert.codegpt.ui.textarea.header.tag.*
|
|||
import ee.carlrobert.codegpt.ui.textarea.suggestion.SuggestionsPopupManager
|
||||
import ee.carlrobert.codegpt.util.EditorUtil
|
||||
import ee.carlrobert.codegpt.util.EditorUtil.getSelectedEditor
|
||||
import ee.carlrobert.codegpt.util.file.FileUtil
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.awt.*
|
||||
import java.awt.event.ActionListener
|
||||
import javax.swing.JButton
|
||||
|
|
@ -168,17 +171,19 @@ class UserInputHeaderPanel(
|
|||
}
|
||||
|
||||
private fun updateReferencedFilesTokens(tags: Set<TagDetails>) {
|
||||
val referencedFileContents = tags.asSequence()
|
||||
.filter { it.selected }
|
||||
.mapNotNull { tag ->
|
||||
when (tag) {
|
||||
is FileTagDetails -> tag.virtualFile.readText()
|
||||
is EditorTagDetails -> tag.virtualFile.readText()
|
||||
else -> null
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val referencedFileContents = tags.asSequence()
|
||||
.filter { it.selected }
|
||||
.mapNotNull { tag ->
|
||||
when (tag) {
|
||||
is FileTagDetails -> FileUtil.readContent(tag.virtualFile)
|
||||
is EditorTagDetails -> FileUtil.readContent(tag.virtualFile)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
.toList()
|
||||
totalTokensPanel.updateReferencedFilesTokens(referencedFileContents)
|
||||
.toList()
|
||||
totalTokensPanel.updateReferencedFilesTokens(referencedFileContents)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initializeEventListeners() {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ import com.fasterxml.jackson.core.JsonProcessingException
|
|||
import com.fasterxml.jackson.core.type.TypeReference
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.diagnostic.thisLogger
|
||||
import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ProjectFileIndex
|
||||
import com.intellij.openapi.util.io.FileUtil.createDirectory
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.VirtualFileFilter
|
||||
import ee.carlrobert.codegpt.settings.service.llama.LlamaSettings.getLlamaModelsPath
|
||||
|
|
@ -29,7 +30,28 @@ import java.util.*
|
|||
import java.util.regex.Pattern
|
||||
|
||||
object FileUtil {
|
||||
private val LOG = Logger.getInstance(FileUtil::class.java)
|
||||
|
||||
private val logger = thisLogger()
|
||||
|
||||
@JvmStatic
|
||||
fun readContent(file: File): String {
|
||||
try {
|
||||
return String(Files.readAllBytes(Paths.get(file.path)))
|
||||
} catch (e: IOException) {
|
||||
logger.error("Failed to read file content", e)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun readContent(virtualFile: VirtualFile): String {
|
||||
try {
|
||||
return VfsUtilCore.loadText(virtualFile)
|
||||
} catch (e: IOException) {
|
||||
logger.error("Failed to read virtual file content", e)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun createFile(directoryPath: Any, fileName: String?, fileContent: String?): File {
|
||||
|
|
@ -120,7 +142,7 @@ object FileUtil {
|
|||
object : TypeReference<List<LanguageFileExtensionDetails>>() {
|
||||
})
|
||||
} catch (e: JsonProcessingException) {
|
||||
LOG.error("Unable to extract file extension", e)
|
||||
logger.error("Unable to extract file extension", e)
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue