Skip to content

Commit 7edfc61

Browse files
authored
Merge pull request #214 from devchat-ai/log_completion
feat: Update workflow installation, optimize caching, and refactor folded content handling
2 parents f21975d + 3707998 commit 7edfc61

File tree

7 files changed

+28
-12
lines changed

7 files changed

+28
-12
lines changed

src/main/kotlin/ai/devchat/common/IDEUtils.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import com.intellij.psi.SmartPsiElementPointer
3131

3232

3333
object IDEUtils {
34-
private const val MAX_CACHE_SIZE = 1000
34+
private const val MAX_CACHE_SIZE = 100
35+
private const val MAX_FOLD_CACHE_SIZE = 100 // 可以根据需要调整
36+
3537
private data class CacheEntry(val filePath: String, val offset: Int, val element: SoftReference<SymbolTypeDeclaration>)
3638

3739
private val variableCache = object : LinkedHashMap<String, CacheEntry>(MAX_CACHE_SIZE, 0.75f, true) {
@@ -48,8 +50,11 @@ object IDEUtils {
4850
val elementHash: Int
4951
)
5052

51-
private val foldCache = ConcurrentHashMap<String, SoftReference<FoldCacheEntry>>()
52-
53+
private val foldCache = object : LinkedHashMap<String, SoftReference<FoldCacheEntry>>(MAX_FOLD_CACHE_SIZE, 0.75f, true) {
54+
override fun removeEldestEntry(eldest: Map.Entry<String, SoftReference<FoldCacheEntry>>): Boolean {
55+
return size > MAX_FOLD_CACHE_SIZE
56+
}
57+
}
5358

5459
fun <T> runInEdtAndGet(block: () -> T): T {
5560
val app = ApplicationManager.getApplication()

src/main/kotlin/ai/devchat/plugin/DevChatToolWindowFactory.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,12 @@ private suspend fun setupPython(envManager: PythonEnvManager, devChatService: De
209209
private suspend fun installWorkflows() {
210210
Log.info("Start checking and copying workflows files")
211211
val workflowMericoDir = File(PathUtils.workflowMericoPath)
212+
var update_public_workflows = CONFIG["update_public_workflow"]
213+
val overwrite = devChatVersion != DevChatState.instance.lastVersion
212214

213-
if (!workflowMericoDir.exists() || !workflowMericoDir.isDirectory || workflowMericoDir.listFiles()?.isEmpty() == true) {
215+
if ((overwrite && update_public_workflows == false) || !workflowMericoDir.exists() || !workflowMericoDir.isDirectory || workflowMericoDir.listFiles()?.isEmpty() == true) {
214216
Log.info("Workflow Merico directory is missing or empty. Creating and populating it.")
215-
PathUtils.copyResourceDirToPath("/workflows", PathUtils.workflowPath)
217+
PathUtils.copyResourceDirToPath("/workflows", PathUtils.workflowPath, true)
216218
} else {
217219
Log.info("Workflow Merico directory exists and is not empty. Skipping copy.")
218220
}

src/main/kotlin/ai/devchat/plugin/completion/agent/Agent.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Agent(val scope: CoroutineScope) {
8080
@SerializedName("llm_time") val llmRequestElapse: Long,
8181
@SerializedName("model") val model: String? = null,
8282
@SerializedName("cache_hit") val cacheHit: Boolean = false,
83-
@SerializedName("is_manual_trigger") var isManualTrigger: Boolean = false
83+
@SerializedName("is_manual_trigger") val isManualTrigger: Boolean = false,
8484
) {
8585
enum class EventType {
8686
@SerializedName("view") VIEW,
@@ -340,8 +340,11 @@ private fun requestDevChatAPI(prompt: String): Flow<CodeCompletionChunk> = flow
340340
"command" to "logEvent",
341341
"id" to logEventRequest.completionId,
342342
"language" to logEventRequest.language,
343-
"name" to logEventRequest.type,
344-
"value" to logEventRequest
343+
"name" to when(logEventRequest.type) {
344+
LogEventRequest.EventType.VIEW -> "view"
345+
LogEventRequest.EventType.SELECT -> "select"
346+
},
347+
"value" to gson.toJson(logEventRequest)
345348
)
346349

347350
// 使用 Browser 类的 sendToWebView 方法发送消息

src/main/kotlin/ai/devchat/plugin/completion/agent/ContextBuilder.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ data class CodeSnippet (
8080

8181
class ContextBuilder(val file: PsiFile, val offset: Int) {
8282
private val CURSOR_MARKER = "<<<CURSOR>>>"
83-
private val foldedContentCache = ConcurrentHashMap<Int, Pair<String, Int>>()
83+
private val MAX_FOLDED_CONTENT_CACHE_SIZE = 10 // 可以根据需要调整
84+
85+
private val foldedContentCache = object : LinkedHashMap<Int, Pair<String, Int>>(MAX_FOLDED_CONTENT_CACHE_SIZE, 0.75f, true) {
86+
override fun removeEldestEntry(eldest: Map.Entry<Int, Pair<String, Int>>): Boolean {
87+
return size > MAX_FOLDED_CONTENT_CACHE_SIZE
88+
}
89+
}
8490
private val foldCounter = AtomicInteger(0)
8591

8692
val filepath: String = file.virtualFile.path

tools

workflows

Submodule workflows updated 40 files

0 commit comments

Comments
 (0)