Skip to content

Commit

Permalink
fix(gui): handle exceptions in language detection
Browse files Browse the repository at this point in the history
Move editor initialization to correct position and add exception handling for language detection to prevent crashes.
  • Loading branch information
phodal committed Sep 8, 2024
1 parent 9f456a3 commit 40f1c0d
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ class AutoDevRunDevInsAction : DumbAwareAction() {
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT

override fun update(e: AnActionEvent) {
val editor = e.getData(com.intellij.openapi.actionSystem.PlatformDataKeys.EDITOR) ?: return
val project = e.project ?: return
val editor = e.getData(com.intellij.openapi.actionSystem.PlatformDataKeys.EDITOR) ?: return
val document = editor.document
val file = FileDocumentManager.getInstance().getFile(document) ?: return

val language = PsiManager.getInstance(project).findFile(file)?.language?.id ?: return
val language = try {
PsiManager.getInstance(project).findFile(file)?.language?.id
} catch (e: Exception) {
null
} ?: return

e.presentation.isEnabled = language == "HTTP Request" || (language == "DevIn" && hasDevInProcessor(language))
}

Expand Down

0 comments on commit 40f1c0d

Please sign in to comment.