Skip to content

Commit

Permalink
runtime: avoid extra indentation on Go switches
Browse files Browse the repository at this point in the history
Unlike other languages, in Go, switches themselves are not indented;
it's just each case body which is indented by one level:

   switch foo {
   case "bar":
      baz()
   }

As such, we shouldn't @indent for type_switch_statement nor
expression_switch_statement, as otherwise inserted lines show up as:

   switch foo {
      // inserted with "o"
   case "bar":
         // inserted with "o"
      baz()
   }

We can remove the added special cases to properly unindent switches,
as now we're not indenting them at all.

With the fix, the inserted lines are indented properly:

   switch foo {
   // inserted with "o"
   case "bar":
      // inserted with "o"
      baz()
   }

I also verified that indentation on selects similarly works well.

Fixes #6772.
  • Loading branch information
mvdan committed Apr 19, 2023
1 parent 4f03c03 commit 93a0f1e
Showing 1 changed file with 0 additions and 5 deletions.
5 changes: 0 additions & 5 deletions runtime/queries/go/indents.scm
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@
(argument_list)
(field_declaration_list)
(block)
(type_switch_statement)
(expression_switch_statement)
(var_declaration)
] @indent

[
"]"
")"
] @outdent

((_ "}" @outdent) @outer (#not-kind-eq? @outer "select_statement"))
(communication_case) @extend

0 comments on commit 93a0f1e

Please sign in to comment.