Skip to content

Commit

Permalink
feat(autodev): add toggle in naming for #132
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 2, 2024
1 parent 2d7d81c commit 44008dc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/222/main/resources/META-INF/autodev-core.xml
Expand Up @@ -180,6 +180,12 @@
<listener topic="com.intellij.ide.plugins.DynamicPluginListener"
class="cc.unitmesh.devti.AutoDevUnloadListener"/>
</applicationListeners>

<projectListeners>
<listener class="cc.unitmesh.devti.practise.RenameLookupManagerListener"
topic="com.intellij.codeInsight.lookup.LookupManagerListener"/>
</projectListeners>

<!-- <projectListeners>-->
<!-- <listener topic="com.intellij.openapi.command.CommandListener"-->
<!-- class="cc.unitmesh.devti.editor.inlay.LLMCommandListener"/>-->
Expand Down
Expand Up @@ -2,6 +2,7 @@ package cc.unitmesh.devti.practise

import cc.unitmesh.devti.AutoDevIcons
import cc.unitmesh.devti.llms.LlmFactory
import cc.unitmesh.devti.settings.coder.coderSetting
import com.intellij.codeInsight.completion.PrefixMatcher
import com.intellij.codeInsight.lookup.*
import com.intellij.codeInsight.lookup.impl.LookupImpl
Expand All @@ -14,10 +15,11 @@ import kotlinx.coroutines.runBlocking
class RenameLookupManagerListener(val project: Project) : LookupManagerListener {
private val llm = LlmFactory.instance.create(project)

// Variable is a badgood name. 5 better options with prefix camelCase which use Hungarian naming convention are
override fun activeLookupChanged(oldLookup: Lookup?, newLookup: Lookup?) {
val lookupImpl = newLookup as? LookupImpl ?: return

if (!project.coderSetting.state.enableRenameSuggestion) return

val lookupOriginalStart = lookupImpl.lookupOriginalStart
val startOffset = if (lookupOriginalStart > -1) lookupOriginalStart else 0
val psiElement = lookupImpl.psiFile?.findElementAt(startOffset)
Expand Down Expand Up @@ -56,8 +58,8 @@ class RenameLookupManagerListener(val project: Project) : LookupManagerListener
// the prompt will be list format, split with \n and remove start number with regex
val suggestionNames = prompt.split("\n").map {
it.replace(Regex("^\\d+\\."), "")
.removeSurrounding("`")
.trim()
.removeSurrounding("`")
}

suggestionNames.map {
Expand Down
Expand Up @@ -78,6 +78,15 @@ class AutoDevCoderConfigurable(project: Project) : BoundConfigurable(AutoDevBund
)
}

row(AutoDevBundle.message("settings.autodev.coder.enableRenameSuggestion")) {
fullWidthCell(JCheckBox())
.bind(
componentGet = { it.isSelected },
componentSet = { component, value -> component.isSelected = value },
prop = state::enableRenameSuggestion.toMutableProperty()
)
}

row(AutoDevBundle.message("settings.autodev.coder.useCustomerAgentWhenInlayCodeComplete")) {
fullWidthCell(useCustomAIEngineWhenInlayCodeComplete)
.bind(
Expand Down Expand Up @@ -173,6 +182,7 @@ class AutoDevCoderConfigurable(project: Project) : BoundConfigurable(AutoDevBund
it.customEngineTokenParam = state.customEngineTokenParam
it.customEnginePrompt = state.customEnginePrompt
it.noChatHistory = state.noChatHistory
it.enableRenameSuggestion = state.enableRenameSuggestion
}
}
}
Expand Down
@@ -1,6 +1,5 @@
package cc.unitmesh.devti.settings.coder

import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.settings.MAX_TOKEN_LENGTH
import cc.unitmesh.devti.settings.ResponseType
import com.intellij.openapi.components.*
Expand All @@ -27,6 +26,7 @@ class AutoDevCoderSettingService(
var disableAdvanceContext by property(false)
var inEditorCompletion by property(false)
var noChatHistory by property(false)
var enableRenameSuggestion by property(false)

var useCustomAIEngineWhenInlayCodeComplete by property(false)
var maxTokenLengthParam: String by property(MAX_TOKEN_LENGTH.toString()) { it.isEmpty() }
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/AutoDevBundle_en.properties
Expand Up @@ -196,3 +196,4 @@ prompts.autodev.generateTest= Generate test for {0} code
prompts.autodev.fixProblem= Help me fix problem:
prompts.autodev.generateReleaseNote= generate release note
prompts.autodev.generateTestData= Generate JSON data (with markdown code block) based on given {0} code and request/response info. So that we can use it to test for APIs. \n response format: \n action: // request method, url: // the request url\n body: // the request body \n response: // the response body in json
settings.autodev.coder.enableRenameSuggestion=Enable Rename suggestion
3 changes: 2 additions & 1 deletion src/main/resources/messages/AutoDevBundle_zh.properties
Expand Up @@ -193,4 +193,5 @@ prompts.autodev.completeCode=完成 {0} 代码,返回剩余代码,不解释
prompts.autodev.generateTest=为 {0} 代码生成测试
prompts.autodev.fixProblem=帮我修复问题:
prompts.autodev.generateReleaseNote=生成发布说明
prompts.autodev.generateTestData=基于给定的 {0} 代码和请求/响应信息生成 JSON 数据(使用 markdown 代码块)。这样我们就可以用它来测试 API。\n响应格式:\n动作:// 请求方法,url:// 请求 URL\nbody:// 请求体\nresponse:// JSON 格式的响应体
prompts.autodev.generateTestData=基于给定的 {0} 代码和请求/响应信息生成 JSON 数据(使用 markdown 代码块)。这样我们就可以用它来测试 API。\n响应格式:\n动作:// 请求方法,url:// 请求 URL\nbody:// 请求体\nresponse:// JSON 格式的响应体
settings.autodev.coder.enableRenameSuggestion=启用重命名建议

0 comments on commit 44008dc

Please sign in to comment.