From e8cefce6519df3d97136304e9d00e0a10a836276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 19 Apr 2023 11:39:08 +0200 Subject: [PATCH] runtime: avoid extra indentation on Go switches 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() } 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. --- runtime/queries/go/indents.scm | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/runtime/queries/go/indents.scm b/runtime/queries/go/indents.scm index e439a9055fcaa..b2befab08ef01 100644 --- a/runtime/queries/go/indents.scm +++ b/runtime/queries/go/indents.scm @@ -14,8 +14,6 @@ (argument_list) (field_declaration_list) (block) - (type_switch_statement) - (expression_switch_statement) (var_declaration) ] @indent @@ -24,5 +22,19 @@ ")" ] @outdent -((_ "}" @outdent) @outer (#not-kind-eq? @outer "select_statement")) -(communication_case) @extend +; Switches and selects aren't indented, only their case bodies are. +; Outdent all closing braces except those closing switches or selects. +( + (_ "}" @outdent) @outer + (#not-kind-eq? @outer "select_statement") + (#not-kind-eq? @outer "type_switch_statement") + (#not-kind-eq? @outer "expression_switch_statement") +) + +; Starting a line after a new case should indent. +[ + (communication_case) + (expression_case) + (default_case) + (type_case) +] @extend