Skip to content

Commit d47aec1

Browse files
committed
feat: 增加新特性,可以正则过滤编辑器选中的内容,提问内容更加精简,明确
1 parent 7bb3d77 commit d47aec1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/main/kotlin/cc/unitmesh/devti/custom/CustomActionBaseIntention.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CustomActionBaseIntention(private val intentionConfig: CustomIntentionConf
4646
val afterCursor = editor.document.text.substring(editor.caretModel.offset)
4747

4848
val prompt: CustomIntentionPrompt = constructCustomPrompt(
49-
psiElement!!, selectedText,
49+
psiElement!!, findAllMatches(selectedText, intentionConfig.selectedRegex),
5050
beforeCursor, afterCursor
5151
)
5252

@@ -67,6 +67,20 @@ class CustomActionBaseIntention(private val intentionConfig: CustomIntentionConf
6767
}
6868
}
6969

70+
private fun findAllMatches(input: String, regex: String): String {
71+
if (regex == "") return input
72+
if (input = "") return input
73+
val builder = StringBuilder()
74+
val pattern = Pattern.compile(regex)
75+
val matcher = pattern.matcher(input)
76+
77+
while (matcher.find()) {
78+
builder.append(matcher.group()).append("\n")
79+
}
80+
81+
return builder.toString()
82+
}
83+
7084
private fun constructCustomPrompt(
7185
psiElement: PsiElement,
7286
selectedText: String,

src/main/kotlin/cc/unitmesh/devti/custom/action/CustomIntentionConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ class CustomIntentionConfig {
1010
var template: String = ""
1111
val isBuiltIn: Boolean = false
1212
val priority: Int = 0
13+
var selectedRegex: String = ""
1314
}

0 commit comments

Comments
 (0)