Skip to content

Commit

Permalink
fix(go): exclude braces for loops, conditions, class (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
ribru17 authored Sep 27, 2024
1 parent b1db8d5 commit c1a6b12
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions queries/go/textobjects.scm
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,86 @@
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
alternative: (_
(_) @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
(_
Expand Down

0 comments on commit c1a6b12

Please sign in to comment.