Skip to content

Commit

Permalink
Merge pull request #214 from devchat-ai/log_completion
Browse files Browse the repository at this point in the history
feat: Update workflow installation, optimize caching, and refactor folded content handling
  • Loading branch information
kagami-l authored Nov 26, 2024
2 parents f21975d + 3707998 commit 7edfc61
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
11 changes: 8 additions & 3 deletions src/main/kotlin/ai/devchat/common/IDEUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import com.intellij.psi.SmartPsiElementPointer


object IDEUtils {
private const val MAX_CACHE_SIZE = 1000
private const val MAX_CACHE_SIZE = 100
private const val MAX_FOLD_CACHE_SIZE = 100 // 可以根据需要调整

private data class CacheEntry(val filePath: String, val offset: Int, val element: SoftReference<SymbolTypeDeclaration>)

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

private val foldCache = ConcurrentHashMap<String, SoftReference<FoldCacheEntry>>()

private val foldCache = object : LinkedHashMap<String, SoftReference<FoldCacheEntry>>(MAX_FOLD_CACHE_SIZE, 0.75f, true) {
override fun removeEldestEntry(eldest: Map.Entry<String, SoftReference<FoldCacheEntry>>): Boolean {
return size > MAX_FOLD_CACHE_SIZE
}
}

fun <T> runInEdtAndGet(block: () -> T): T {
val app = ApplicationManager.getApplication()
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/ai/devchat/plugin/DevChatToolWindowFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ private suspend fun setupPython(envManager: PythonEnvManager, devChatService: De
private suspend fun installWorkflows() {
Log.info("Start checking and copying workflows files")
val workflowMericoDir = File(PathUtils.workflowMericoPath)
var update_public_workflows = CONFIG["update_public_workflow"]
val overwrite = devChatVersion != DevChatState.instance.lastVersion

if (!workflowMericoDir.exists() || !workflowMericoDir.isDirectory || workflowMericoDir.listFiles()?.isEmpty() == true) {
if ((overwrite && update_public_workflows == false) || !workflowMericoDir.exists() || !workflowMericoDir.isDirectory || workflowMericoDir.listFiles()?.isEmpty() == true) {
Log.info("Workflow Merico directory is missing or empty. Creating and populating it.")
PathUtils.copyResourceDirToPath("/workflows", PathUtils.workflowPath)
PathUtils.copyResourceDirToPath("/workflows", PathUtils.workflowPath, true)
} else {
Log.info("Workflow Merico directory exists and is not empty. Skipping copy.")
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/kotlin/ai/devchat/plugin/completion/agent/Agent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Agent(val scope: CoroutineScope) {
@SerializedName("llm_time") val llmRequestElapse: Long,
@SerializedName("model") val model: String? = null,
@SerializedName("cache_hit") val cacheHit: Boolean = false,
@SerializedName("is_manual_trigger") var isManualTrigger: Boolean = false
@SerializedName("is_manual_trigger") val isManualTrigger: Boolean = false,
) {
enum class EventType {
@SerializedName("view") VIEW,
Expand Down Expand Up @@ -340,8 +340,11 @@ private fun requestDevChatAPI(prompt: String): Flow<CodeCompletionChunk> = flow
"command" to "logEvent",
"id" to logEventRequest.completionId,
"language" to logEventRequest.language,
"name" to logEventRequest.type,
"value" to logEventRequest
"name" to when(logEventRequest.type) {
LogEventRequest.EventType.VIEW -> "view"
LogEventRequest.EventType.SELECT -> "select"
},
"value" to gson.toJson(logEventRequest)
)

// 使用 Browser 类的 sendToWebView 方法发送消息
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ data class CodeSnippet (

class ContextBuilder(val file: PsiFile, val offset: Int) {
private val CURSOR_MARKER = "<<<CURSOR>>>"
private val foldedContentCache = ConcurrentHashMap<Int, Pair<String, Int>>()
private val MAX_FOLDED_CONTENT_CACHE_SIZE = 10 // 可以根据需要调整

private val foldedContentCache = object : LinkedHashMap<Int, Pair<String, Int>>(MAX_FOLDED_CONTENT_CACHE_SIZE, 0.75f, true) {
override fun removeEldestEntry(eldest: Map.Entry<Int, Pair<String, Int>>): Boolean {
return size > MAX_FOLDED_CONTENT_CACHE_SIZE
}
}
private val foldCounter = AtomicInteger(0)

val filepath: String = file.virtualFile.path
Expand Down
2 changes: 1 addition & 1 deletion tools
Submodule tools updated 35 files
+0 −61 site-packages/pydantic-1.10.14.dist-info/RECORD
+0 −0 site-packages/pydantic-1.10.16.dist-info/INSTALLER
+0 −0 site-packages/pydantic-1.10.16.dist-info/LICENSE
+16 −4 site-packages/pydantic-1.10.16.dist-info/METADATA
+63 −0 site-packages/pydantic-1.10.16.dist-info/RECORD
+0 −0 site-packages/pydantic-1.10.16.dist-info/REQUESTED
+1 −1 site-packages/pydantic-1.10.16.dist-info/WHEEL
+0 −0 site-packages/pydantic-1.10.16.dist-info/entry_points.txt
+0 −0 site-packages/pydantic-1.10.16.dist-info/top_level.txt
+16 −16 site-packages/pydantic/__init__.py
+3 −3 site-packages/pydantic/annotated_types.py
+7 −7 site-packages/pydantic/class_validators.py
+3 −3 site-packages/pydantic/color.py
+5 −5 site-packages/pydantic/config.py
+9 −9 site-packages/pydantic/dataclasses.py
+1 −1 site-packages/pydantic/datetime_parse.py
+7 −7 site-packages/pydantic/decorator.py
+6 −6 site-packages/pydantic/env_settings.py
+5 −5 site-packages/pydantic/error_wrappers.py
+3 −3 site-packages/pydantic/errors.py
+15 −15 site-packages/pydantic/fields.py
+6 −6 site-packages/pydantic/generics.py
+4 −4 site-packages/pydantic/json.py
+15 −15 site-packages/pydantic/main.py
+2 −1 site-packages/pydantic/mypy.py
+6 −6 site-packages/pydantic/networks.py
+1 −1 site-packages/pydantic/parse.py
+12 −12 site-packages/pydantic/schema.py
+5 −5 site-packages/pydantic/tools.py
+7 −7 site-packages/pydantic/types.py
+6 −4 site-packages/pydantic/typing.py
+10 −10 site-packages/pydantic/utils.py
+130 −0 site-packages/pydantic/v1.py
+10 −10 site-packages/pydantic/validators.py
+1 −1 site-packages/pydantic/version.py
2 changes: 1 addition & 1 deletion workflows
Submodule workflows updated 40 files
+2 −1 lib/chatmark/__init__.py
+51 −0 lib/chatmark/widgets.py
+7 −7 merico/github/commit/commit.py
+90 −12 merico/github/git_api.py
+24 −0 merico/gitlab/code_task_summary/README.md
+124 −0 merico/gitlab/code_task_summary/command.py
+5 −0 merico/gitlab/code_task_summary/command.yml
+1 −0 merico/gitlab/command.yml
+23 −0 merico/gitlab/commit/README.md
+0 −0 merico/gitlab/commit/__init__py
+6 −0 merico/gitlab/commit/command.yml
+427 −0 merico/gitlab/commit/commit.py
+39 −0 merico/gitlab/commit/diffCommitMessagePrompt.txt
+5 −0 merico/gitlab/commit/zh/command.yml
+78 −0 merico/gitlab/common_util.py
+19 −0 merico/gitlab/config/README.md
+88 −0 merico/gitlab/config/command.py
+4 −0 merico/gitlab/config/command.yml
+611 −0 merico/gitlab/git_api.py
+19 −0 merico/gitlab/list_issue_tasks/README.md
+53 −0 merico/gitlab/list_issue_tasks/command.py
+5 −0 merico/gitlab/list_issue_tasks/command.yml
+21 −0 merico/gitlab/new_branch/README.md
+95 −0 merico/gitlab/new_branch/command.py
+5 −0 merico/gitlab/new_branch/command.yml
+21 −0 merico/gitlab/new_issue/README.md
+52 −0 merico/gitlab/new_issue/command.py
+5 −0 merico/gitlab/new_issue/command.yml
+0 −0 merico/gitlab/new_issue/from_task/README.md
+94 −0 merico/gitlab/new_issue/from_task/command.py
+5 −0 merico/gitlab/new_issue/from_task/command.yml
+22 −0 merico/gitlab/new_pr/README.md
+120 −0 merico/gitlab/new_pr/command.py
+5 −0 merico/gitlab/new_pr/command.yml
+22 −0 merico/gitlab/update_issue_tasks/README.md
+101 −0 merico/gitlab/update_issue_tasks/command.py
+5 −0 merico/gitlab/update_issue_tasks/command.yml
+20 −0 merico/gitlab/update_pr/README.md
+122 −0 merico/gitlab/update_pr/command.py
+5 −0 merico/gitlab/update_pr/command.yml

0 comments on commit 7edfc61

Please sign in to comment.