Skip to content

Commit 0afe92f

Browse files
committed
feat(coder): add auto lint code feature
- Add enableAutoLintCode setting to AutoDevCoderConfigurable and AutoDevCoderSettingService - Implement auto lint code functionality in SingleFileDiffSketch - Update MarkdownPreviewHighlightSketch and MarkdownPreviewSketchProvider to support markdown preview - Improve language detection for code blocks in SketchToolWindow - Add new setting messages in AutoDevBundle properties files
1 parent 6a2ca3d commit 0afe92f

File tree

8 files changed

+30
-13
lines changed

8 files changed

+30
-13
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AutoDevCoderConfigurable(private val project: Project) : BoundConfigurable
3030
private val trimCodeBeforeSend = JCheckBox()
3131
private val enableAutoRepairDiff = JCheckBox()
3232
private val enableAutoRunTerminal = JCheckBox()
33+
private val enableAutoLintCode = JCheckBox()
3334

3435

3536
val settings = project.service<AutoDevCoderSettingService>()
@@ -135,6 +136,15 @@ class AutoDevCoderConfigurable(private val project: Project) : BoundConfigurable
135136
)
136137
}
137138

139+
row(jLabel("settings.autodev.coder.enableAutoLintCode")) {
140+
fullWidthCell(enableAutoLintCode)
141+
.bind(
142+
componentGet = { it.isSelected },
143+
componentSet = { component, value -> component.isSelected = value },
144+
prop = state::enableAutoLintCode.toMutableProperty()
145+
)
146+
}
147+
138148
row(jLabel("settings.external.team.prompts.path")) {
139149
fullWidthCell(teamPromptsField)
140150
.bind(
@@ -157,6 +167,7 @@ class AutoDevCoderConfigurable(private val project: Project) : BoundConfigurable
157167
it.enableObserver = state.enableObserver
158168
it.enableAutoRepairDiff = state.enableAutoRepairDiff
159169
it.enableAutoRunTerminal = state.enableAutoRunTerminal
170+
it.enableAutoLintCode = state.enableAutoLintCode
160171
}
161172
}
162173
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AutoDevCoderSettingService(
3030
var trimCodeBeforeSend by property(false)
3131
var enableRenameSuggestion by property(false)
3232
var enableAutoRunTerminal by property(false)
33+
var enableAutoLintCode by property(false)
3334
var teamPromptsDir by property("prompts") { it.isEmpty() }
3435

3536
override fun copy(): AutoDevCoderSettings {

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchToolWindow.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ open class SketchToolWindow(
288288

289289
val isCanHtml = codeFence.language.displayName.lowercase() == "markdown"
290290
if (isCanHtml && codeFence.isComplete && blockViews[index] !is ExtensionLangSketch) {
291-
langSketch = MarkdownPreviewHighlightSketch(project, codeFence.text)
291+
langSketch = if (codeFence.text.contains("\n```") && codeFence.text.startsWith("/")) {
292+
MarkdownPreviewHighlightSketch(project, codeFence.text)
293+
} else {
294+
MarkdownPreviewHighlightSketch(project, codeFence.text)
295+
}
292296
}
293297

294298
if (langSketch != null) {
@@ -307,11 +311,10 @@ open class SketchToolWindow(
307311
}
308312
}
309313

310-
//// simple fix for langauge error
311314
var language = codeFence.language
312315
if (codeFence.text.contains("\n```") && codeFence.text.startsWith("/")) {
313316
if (language.displayName == "Markdown") {
314-
println("Try to fix language error")
317+
com.intellij.openapi.diagnostic.logger<SketchToolWindow>().warn("Try to fix language error")
315318
language = findLanguage("DevIn")
316319
originLanguage = "DevIn"
317320
}

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/MarkdownPreviewHighlightSketch.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import cc.unitmesh.devti.fullWidth
44
import cc.unitmesh.devti.sketch.ui.code.MarkdownWebViewer
55
import cc.unitmesh.devti.util.parser.convertMarkdownToHtml
66
import com.intellij.ide.BrowserUtil
7-
import com.intellij.lang.Language
87
import com.intellij.openapi.project.Project
98
import com.intellij.ui.dsl.builder.panel
109
import com.intellij.util.ui.JBUI

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/MarkdownPreviewSketchProvider.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ class MarkdownPreviewSketchProvider : LanguageSketchProvider {
77
* Since Webview had a bad performance, we disable it by default.
88
*/
99
override fun isSupported(lang: String): Boolean {
10-
// return lang.lowercase() == "markdown"
11-
return false
10+
return lang.lowercase() == "markdown"
1211
}
1312

1413
override fun create(project: Project, content: String): ExtensionLangSketch = MarkdownPreviewHighlightSketch(project, content)

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/patch/SingleFileDiffSketch.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,17 @@ class SingleFileDiffSketch(
230230

231231
isRepaired = true
232232

233-
ApplicationManager.getApplication().invokeLater {
234-
val task = object : Task.Backgroundable(myProject, "Analysis code style", false) {
235-
override fun run(indicator: ProgressIndicator) {
236-
lintCheckForNewCode(currentFile)
233+
if (myProject.coderSetting.state.enableAutoLintCode) {
234+
ApplicationManager.getApplication().invokeLater {
235+
val task = object : Task.Backgroundable(myProject, "Analysis code style", false) {
236+
override fun run(indicator: ProgressIndicator) {
237+
lintCheckForNewCode(currentFile)
238+
}
237239
}
238-
}
239240

240-
ProgressManager.getInstance()
241-
.runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
241+
ProgressManager.getInstance()
242+
.runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
243+
}
242244
}
243245
}
244246

core/src/main/resources/messages/AutoDevBundle_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ prompts.autodev.generateTestData=Generate API test request (with `http request`
130130
settings.autodev.coder.enableRenameSuggestion=Enable Rename suggestion
131131
settings.autodev.coder.enableAutoRepairDiff=Enable auto repair diff
132132
settings.autodev.coder.enableAutoRunTerminal=Enable auto run terminal
133+
settings.autodev.coder.enableAutoLintCode=Enable auto lint patch code
133134
shell.command.suggestion.action.default.text=How to check out a branch?
134135
batch.nothing.to.testing=Nothing to AutoTest
135136
intentions.chat.code.test.verify=Verify test

core/src/main/resources/messages/AutoDevBundle_zh.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ prompts.autodev.generateTestData=基于给定的 {0} 代码和请求/响应信
130130
settings.autodev.coder.enableRenameSuggestion=启用重命名建议
131131
settings.autodev.coder.enableAutoRepairDiff=启用自动修复 diff
132132
settings.autodev.coder.enableAutoRunTerminal=启用自动运行终端(有风险)
133+
settings.autodev.coder.enableAutoLintCode=启用自动修复 Lint 代码
133134
shell.command.suggestion.action.default.text=如何创建一个新的分支?
134135
batch.nothing.to.testing=没有要 AutoTest 的内容
135136
intentions.chat.code.test.verify=验证测试中

0 commit comments

Comments
 (0)