Skip to content

Commit 40f1c0d

Browse files
committed
fix(gui): handle exceptions in language detection
Move editor initialization to correct position and add exception handling for language detection to prevent crashes.
1 parent 9f456a3 commit 40f1c0d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ class AutoDevRunDevInsAction : DumbAwareAction() {
1313
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
1414

1515
override fun update(e: AnActionEvent) {
16-
val editor = e.getData(com.intellij.openapi.actionSystem.PlatformDataKeys.EDITOR) ?: return
1716
val project = e.project ?: return
17+
val editor = e.getData(com.intellij.openapi.actionSystem.PlatformDataKeys.EDITOR) ?: return
1818
val document = editor.document
1919
val file = FileDocumentManager.getInstance().getFile(document) ?: return
2020

21-
val language = PsiManager.getInstance(project).findFile(file)?.language?.id ?: return
21+
val language = try {
22+
PsiManager.getInstance(project).findFile(file)?.language?.id
23+
} catch (e: Exception) {
24+
null
25+
} ?: return
26+
2227
e.presentation.isEnabled = language == "HTTP Request" || (language == "DevIn" && hasDevInProcessor(language))
2328
}
2429

0 commit comments

Comments
 (0)