Skip to content

Commit

Permalink
feat: check for nullness of a PSI file in TestSparkAction.update
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Artiukhov committed Oct 4, 2024
1 parent 797180b commit b40a077
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ class TestSparkAction : AnAction() {
/**
* Updates the state of the action based on the provided event.
*
* @param e the AnActionEvent object representing the event
* @param e `AnActionEvent` object representing the event
*/
override fun update(e: AnActionEvent) {
val file = e.dataContext.getData(CommonDataKeys.PSI_FILE)!!
val file = e.dataContext.getData(CommonDataKeys.PSI_FILE)

if (file == null) {
e.presentation.isEnabledAndVisible = false
return
}

val psiHelper = PsiHelperProvider.getPsiHelper(file)
e.presentation.isEnabledAndVisible = psiHelper != null && psiHelper.availableForGeneration(e)
e.presentation.isEnabledAndVisible = (psiHelper != null) && psiHelper.availableForGeneration(e)
}

/**
Expand Down

0 comments on commit b40a077

Please sign in to comment.