Skip to content

Commit

Permalink
fix(shirelang): ensure null safety in ShireVcsSingleAction #78
Browse files Browse the repository at this point in the history
Update the `ShireVcsSingleAction` to handle null cases properly. This prevents the action from crashing when no configurations are available. The changes include:
- Using `firstOrNull` to safely retrieve the first configuration.
- Adding a null check before accessing properties of `hobbitHole`.
- Returning early if `firstOrNull` returns null in the `actionPerformed` method.
  • Loading branch information
phodal committed Sep 7, 2024
1 parent 97901a3 commit 0c4665b
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ class ShireVcsSingleAction : DumbAwareAction() {
override fun update(e: AnActionEvent) {
val isOnlyOneConfig = shireActionConfigs().size == 1

val hobbitHole = shireActionConfigs().firstOrNull()?.hole ?: return
val hobbitHole = shireActionConfigs().firstOrNull()?.hole
e.presentation.isVisible = isOnlyOneConfig
e.presentation.isEnabled = hobbitHole.enabled

e.presentation.text = hobbitHole.name ?: "<Placeholder>"
e.presentation.isEnabled = hobbitHole != null && hobbitHole.enabled
if (hobbitHole != null) {
e.presentation.text = hobbitHole.name ?: "<Placeholder>"
}
}

override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return

VariableActionEventDataHolder.putData(VariableActionEventDataHolder(e.dataContext))

val config = shireActionConfigs().first()
val config = shireActionConfigs().firstOrNull() ?: return
ShireRunFileAction.executeShireFile(project, config, null)
}
}

0 comments on commit 0c4665b

Please sign in to comment.