mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-20 01:02:02 +00:00
fix: long running task on EDT
This commit is contained in:
parent
44a834af8d
commit
3ef1ac4098
2 changed files with 39 additions and 31 deletions
|
|
@ -25,6 +25,9 @@ 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
|
||||
|
|
@ -169,17 +172,19 @@ class UserInputHeaderPanel(
|
|||
}
|
||||
|
||||
private fun updateReferencedFilesTokens(tags: Set<TagDetails>) {
|
||||
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
|
||||
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,7 +4,7 @@ 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
|
||||
|
|
@ -30,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 {
|
||||
|
|
@ -121,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
|
||||
}
|
||||
|
||||
|
|
@ -263,24 +284,6 @@ object FileUtil {
|
|||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun readContent(file: File): String {
|
||||
try {
|
||||
return String(Files.readAllBytes(Paths.get(file.path)))
|
||||
} catch (e: IOException) {
|
||||
throw java.lang.RuntimeException("Failed to read file content", e)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun readContent(virtualFile: VirtualFile): String {
|
||||
try {
|
||||
return VfsUtilCore.loadText(virtualFile)
|
||||
} catch (e: IOException) {
|
||||
throw java.lang.RuntimeException("Failed to read virtual file content", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class SearchResult(val file: VirtualFile, val score: Int)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue