From c1a6b121e67231d6cfe230584691bd7ffa157110 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Thu, 26 Sep 2024 19:40:01 -0700 Subject: [PATCH] fix(go): exclude braces for loops, conditions, class (#694) --- queries/go/textobjects.scm | 62 +++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/queries/go/textobjects.scm b/queries/go/textobjects.scm index 93817040..9b7ac620 100644 --- a/queries/go/textobjects.scm +++ b/queries/go/textobjects.scm @@ -46,25 +46,54 @@ body: (block)?) @function.outer ; struct and interface declaration as class textobject? +(type_declaration + (type_spec + (type_identifier) + (struct_type))) @class.outer + (type_declaration (type_spec (type_identifier) (struct_type (field_declaration_list - (_)?) @class.inner))) @class.outer + "{" + . + _ @_start @_end + _? @_end + . + "}" + (#make-range! "class.inner" @_start @_end))))) + +(type_declaration + (type_spec + (type_identifier) + (interface_type))) @class.outer (type_declaration (type_spec (type_identifier) - (interface_type) @class.inner)) @class.outer + (interface_type + "{" + . + _ @_start @_end + _? @_end + . + "}" + (#make-range! "class.inner" @_start @_end)))) ; struct literals as class textobject (composite_literal - (type_identifier)? - (struct_type - (_))? + (literal_value)) @class.outer + +(composite_literal (literal_value - (_)) @class.inner) @class.outer + "{" + . + _ @_start @_end + _? @_end + . + "}") + (#make-range! "class.inner" @_start @_end)) ; conditionals (if_statement @@ -72,14 +101,31 @@ (_) @conditional.inner)?) @conditional.outer (if_statement - consequence: (block)? @conditional.inner) + consequence: (block + "{" + . + _ @_start @_end + _? @_end + . + "}" + (#make-range! "conditional.inner" @_start @_end))) (if_statement condition: (_) @conditional.inner) ; loops +(for_statement) @loop.outer + (for_statement - body: (block)? @loop.inner) @loop.outer + body: (block + . + "{" + . + _ @_start @_end + _? @_end + . + "}" + (#make-range! "loop.inner" @_start @_end))) ; blocks (_