diff options
| author | moonz <pmnarimani@gmail.com> | 2026-01-30 18:01:09 +0100 |
|---|---|---|
| committer | moonz <pmnarimani@gmail.com> | 2026-01-30 18:03:45 +0100 |
| commit | 80add289c43fa1d71e09779cf2188f228c2f1378 (patch) | |
| tree | 573e9baaa4597409cd92c314da50c60a62148caa | |
| parent | 25a0ad1bc36f5ff40b7f17e4240407712a02895f (diff) | |
fix: code action is no longer available inside the block of if statement
| -rw-r--r-- | src/server/action_invert_if_statements.odin | 13 | ||||
| -rw-r--r-- | tests/action_invert_if_test.odin | 18 |
2 files changed, 22 insertions, 9 deletions
diff --git a/src/server/action_invert_if_statements.odin b/src/server/action_invert_if_statements.odin index ab0c664..8e904e5 100644 --- a/src/server/action_invert_if_statements.odin +++ b/src/server/action_invert_if_statements.odin @@ -98,6 +98,9 @@ find_if_stmt_in_node :: proc(node: ^ast.Node, position: common.AbsolutePosition, if nested := find_if_stmt_in_node(n.body, position, false); nested != nil { return nested } + // Position is inside the body but no nested if found + // Don't return the current if statement + return nil } // Position is in the condition/init part or we're the closest if @@ -348,15 +351,7 @@ is_simple_expr :: proc(expr: ^ast.Expr) -> bool { return false } #partial switch e in expr.derived { - case ^ast.Ident: - return true - case ^ast.Paren_Expr: - return true - case ^ast.Call_Expr: - return true - case ^ast.Selector_Expr: - return true - case ^ast.Index_Expr: + case ^ast.Ident, ^ast.Paren_Expr, ^ast.Call_Expr, ^ast.Selector_Expr, ^ast.Index_Expr: return true } return false diff --git a/tests/action_invert_if_test.odin b/tests/action_invert_if_test.odin index 0639b69..bb12ad9 100644 --- a/tests/action_invert_if_test.odin +++ b/tests/action_invert_if_test.odin @@ -148,6 +148,24 @@ main :: proc() { test.expect_action(t, &source, {}) } + +@(test) +action_invert_if_inside_of_statement :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + +main :: proc() { + if x != 0 { + foo{*}() + } +} +`, + packages = {}, + } + + test.expect_action(t, &source, {}) +} + @(test) action_invert_if_not_eq :: proc(t: ^testing.T) { source := test.Source { |