Skip to content

Commit 44008dc

Browse files
committed
feat(autodev): add toggle in naming for #132
1 parent 2d7d81c commit 44008dc

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

src/222/main/resources/META-INF/autodev-core.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@
180180
<listener topic="com.intellij.ide.plugins.DynamicPluginListener"
181181
class="cc.unitmesh.devti.AutoDevUnloadListener"/>
182182
</applicationListeners>
183+
184+
<projectListeners>
185+
<listener class="cc.unitmesh.devti.practise.RenameLookupManagerListener"
186+
topic="com.intellij.codeInsight.lookup.LookupManagerListener"/>
187+
</projectListeners>
188+
183189
<!-- <projectListeners>-->
184190
<!-- <listener topic="com.intellij.openapi.command.CommandListener"-->
185191
<!-- class="cc.unitmesh.devti.editor.inlay.LLMCommandListener"/>-->

src/main/kotlin/cc/unitmesh/devti/practise/RenameLookupManagerListener.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cc.unitmesh.devti.practise
22

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

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

21+
if (!project.coderSetting.state.enableRenameSuggestion) return
22+
2123
val lookupOriginalStart = lookupImpl.lookupOriginalStart
2224
val startOffset = if (lookupOriginalStart > -1) lookupOriginalStart else 0
2325
val psiElement = lookupImpl.psiFile?.findElementAt(startOffset)
@@ -56,8 +58,8 @@ class RenameLookupManagerListener(val project: Project) : LookupManagerListener
5658
// the prompt will be list format, split with \n and remove start number with regex
5759
val suggestionNames = prompt.split("\n").map {
5860
it.replace(Regex("^\\d+\\."), "")
59-
.removeSurrounding("`")
6061
.trim()
62+
.removeSurrounding("`")
6163
}
6264

6365
suggestionNames.map {

src/main/kotlin/cc/unitmesh/devti/settings/coder/AutoDevCoderConfigurable.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ class AutoDevCoderConfigurable(project: Project) : BoundConfigurable(AutoDevBund
7878
)
7979
}
8080

81+
row(AutoDevBundle.message("settings.autodev.coder.enableRenameSuggestion")) {
82+
fullWidthCell(JCheckBox())
83+
.bind(
84+
componentGet = { it.isSelected },
85+
componentSet = { component, value -> component.isSelected = value },
86+
prop = state::enableRenameSuggestion.toMutableProperty()
87+
)
88+
}
89+
8190
row(AutoDevBundle.message("settings.autodev.coder.useCustomerAgentWhenInlayCodeComplete")) {
8291
fullWidthCell(useCustomAIEngineWhenInlayCodeComplete)
8392
.bind(
@@ -173,6 +182,7 @@ class AutoDevCoderConfigurable(project: Project) : BoundConfigurable(AutoDevBund
173182
it.customEngineTokenParam = state.customEngineTokenParam
174183
it.customEnginePrompt = state.customEnginePrompt
175184
it.noChatHistory = state.noChatHistory
185+
it.enableRenameSuggestion = state.enableRenameSuggestion
176186
}
177187
}
178188
}

src/main/kotlin/cc/unitmesh/devti/settings/coder/AutoDevCoderSettingService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package cc.unitmesh.devti.settings.coder
22

3-
import cc.unitmesh.devti.AutoDevBundle
43
import cc.unitmesh.devti.settings.MAX_TOKEN_LENGTH
54
import cc.unitmesh.devti.settings.ResponseType
65
import com.intellij.openapi.components.*
@@ -27,6 +26,7 @@ class AutoDevCoderSettingService(
2726
var disableAdvanceContext by property(false)
2827
var inEditorCompletion by property(false)
2928
var noChatHistory by property(false)
29+
var enableRenameSuggestion by property(false)
3030

3131
var useCustomAIEngineWhenInlayCodeComplete by property(false)
3232
var maxTokenLengthParam: String by property(MAX_TOKEN_LENGTH.toString()) { it.isEmpty() }

src/main/resources/messages/AutoDevBundle_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,4 @@ prompts.autodev.generateTest= Generate test for {0} code
196196
prompts.autodev.fixProblem= Help me fix problem:
197197
prompts.autodev.generateReleaseNote= generate release note
198198
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
199+
settings.autodev.coder.enableRenameSuggestion=Enable Rename suggestion

src/main/resources/messages/AutoDevBundle_zh.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,5 @@ prompts.autodev.completeCode=完成 {0} 代码,返回剩余代码,不解释
193193
prompts.autodev.generateTest=为 {0} 代码生成测试
194194
prompts.autodev.fixProblem=帮我修复问题:
195195
prompts.autodev.generateReleaseNote=生成发布说明
196-
prompts.autodev.generateTestData=基于给定的 {0} 代码和请求/响应信息生成 JSON 数据(使用 markdown 代码块)。这样我们就可以用它来测试 API。\n响应格式:\n动作:// 请求方法,url:// 请求 URL\nbody:// 请求体\nresponse:// JSON 格式的响应体
196+
prompts.autodev.generateTestData=基于给定的 {0} 代码和请求/响应信息生成 JSON 数据(使用 markdown 代码块)。这样我们就可以用它来测试 API。\n响应格式:\n动作:// 请求方法,url:// 请求 URL\nbody:// 请求体\nresponse:// JSON 格式的响应体
197+
settings.autodev.coder.enableRenameSuggestion=启用重命名建议

0 commit comments

Comments
 (0)