Skip to content

Commit 58d8bcc

Browse files
committed
feat(devti): add 'rule' command to retrieve code quality guidelines #349
1 parent a1156f9 commit 58d8bcc

File tree

8 files changed

+54
-14
lines changed

8 files changed

+54
-14
lines changed

core/src/main/kotlin/cc/unitmesh/devti/AutoDevIcons.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,7 @@ object AutoDevIcons {
7373

7474
@JvmField
7575
val EDIT: Icon = IconLoader.getIcon("/icons/edit.svg", AutoDevIcons::class.java)
76+
77+
@JvmField
78+
val RULE: Icon = IconLoader.getIcon("/icons/rule.svg", AutoDevIcons::class.java)
7679
}

core/src/main/kotlin/cc/unitmesh/devti/devin/dataprovider/BuiltinCommand.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ enum class BuiltinCommand(
112112
),
113113
OPEN("open", "Open a file in the editor", AllIcons.Actions.MenuOpen, false, true),
114114
RIPGREP_SEARCH("ripgrepSearch", "Search text in the project with ripgrep", AllIcons.Actions.Regex, false, true),
115+
RULE(
116+
"rule",
117+
"Get the rule from one file, such as code style, code quality, and code smell",
118+
AutoDevIcons.RULE,
119+
true,
120+
true
121+
),
115122
TOOLCHAIN_COMMAND(
116123
"x",
117124
"Execute custom toolchain command",

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
package cc.unitmesh.devti.sketch
22

33
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
4-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.BROWSE
5-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.DATABASE
6-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.DIR
7-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.FILE
8-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.LOCAL_SEARCH
9-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.PATCH
10-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.RELATED
11-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.REV
12-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.RIPGREP_SEARCH
13-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.STRUCTURE
14-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.SYMBOL
15-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.WRITE
4+
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.*
165
import cc.unitmesh.devti.observer.agent.AgentStateService
176
import cc.unitmesh.devti.provider.devins.LanguageProcessor
187
import cc.unitmesh.devti.provider.toolchain.ToolchainFunctionProvider
@@ -90,6 +79,7 @@ class AutoSketchMode(val project: Project) {
9079
DATABASE, // should be handle in run sql
9180
RELATED,
9281
RIPGREP_SEARCH,
82+
RULE,
9383
BROWSE,
9484
PATCH,
9585
WRITE
Lines changed: 12 additions & 0 deletions
Loading

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ class DevInsCompiler(
303303
RelatedSymbolInsCommand(myProject, prop)
304304
}
305305

306+
BuiltinCommand.RULE -> {
307+
result.isLocalCommand = true
308+
RuleInsCommand(myProject, prop)
309+
}
310+
306311
BuiltinCommand.OPEN -> {
307312
result.isLocalCommand = true
308313
OpenInsCommand(myProject, prop)

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/OpenInsCommand.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ class OpenInsCommand(val myProject: Project, private val filename: String) : Ins
1111
override val commandName: BuiltinCommand = BuiltinCommand.OPEN
1212

1313
override suspend fun execute(): String? {
14-
FileDocumentManager.getInstance().saveAllDocuments()
15-
1614
val file = myProject.lookupFile(filename)
1715
if (file != null) {
1816
FileEditorManager.getInstance(myProject).openFile(file, true)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cc.unitmesh.devti.language.compiler.exec
2+
3+
import cc.unitmesh.devti.devin.InsCommand
4+
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
5+
import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR
6+
import cc.unitmesh.devti.language.utils.lookupFile
7+
import cc.unitmesh.devti.sketch.ui.patch.readText
8+
import com.intellij.openapi.project.Project
9+
10+
class RuleInsCommand(val myProject: Project, private val filename: String) : InsCommand {
11+
override val commandName: BuiltinCommand = BuiltinCommand.OPEN
12+
13+
override suspend fun execute(): String? {
14+
val fullname = "prompts/rule/$filename.md"
15+
val file = myProject.lookupFile(fullname)
16+
17+
if (file != null) {
18+
return file.readText()
19+
}
20+
21+
return "$DEVINS_ERROR rule file not found: $fullname"
22+
}
23+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
获取 service 相关的规则(将读取 promtps/rule/service.md 文件,请确保文件存在)
2+
/rule:service

0 commit comments

Comments
 (0)