Skip to content

Commit 198956f

Browse files
committed
refactor(gui): improve language processor handling
#196 - Refactored language processor handling in AutoDevRunDevInsAction for better readability and extensibility.
1 parent f08942b commit 198956f

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/main/kotlin/cc/unitmesh/devti/gui/snippet/AutoDevRunDevInsAction.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.ActionUpdateThread
55
import com.intellij.openapi.actionSystem.AnActionEvent
66
import com.intellij.openapi.fileEditor.FileDocumentManager
77
import com.intellij.openapi.project.DumbAwareAction
8+
import com.intellij.openapi.util.NlsSafe
89
import com.intellij.psi.PsiManager
910

1011
class AutoDevRunDevInsAction : DumbAwareAction() {
@@ -17,17 +18,30 @@ class AutoDevRunDevInsAction : DumbAwareAction() {
1718
val file = FileDocumentManager.getInstance().getFile(document) ?: return
1819

1920
val language = PsiManager.getInstance(project).findFile(file)?.language?.id ?: return
20-
e.presentation.isEnabled = language == "DevIn" && LanguagePromptProcessor.instance(language).isNotEmpty()
21+
e.presentation.isEnabled = language == "http request" || (language == "DevIn" && hasDevInProcessor(language))
2122
}
2223

24+
private fun hasDevInProcessor(language: @NlsSafe String) =
25+
LanguagePromptProcessor.instance(language).isNotEmpty()
26+
2327
override fun actionPerformed(e: AnActionEvent) {
2428
val editor = e.getData(com.intellij.openapi.actionSystem.PlatformDataKeys.EDITOR) ?: return
2529
val project = e.project ?: return
2630

2731
val document = editor.document
2832
val text = document.text
33+
val file = FileDocumentManager.getInstance().getFile(document) ?: return
2934

30-
LanguagePromptProcessor.instance("DevIn").firstOrNull()?.compile(project, text)
31-
}
35+
val language = PsiManager.getInstance(project).findFile(file)?.language?.id ?: return
36+
37+
when (language) {
38+
"http request" -> {
39+
// call http request processor
40+
}
3241

42+
"DevIn" -> {
43+
LanguagePromptProcessor.instance("DevIn").firstOrNull()?.compile(project, text)
44+
}
45+
}
46+
}
3347
}

0 commit comments

Comments
 (0)