Skip to content

Commit ef4a738

Browse files
authored
feat(ruby): add additional textobjects queries (#249)
Add additional `textobjects` queries for Ruby lang.
1 parent b371cba commit ef4a738

4 files changed

Lines changed: 1672 additions & 42 deletions

File tree

.tsqueryrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
"script": "Also captures the script name (for different purposes)",
6666
"RUBY_TEST_NAME": "A ruby test name",
6767
"_ruby-test": "A ruby test name"
68+
},
69+
"textobjects": {
70+
"function.around": "An entire function definition or equivalent small section of a file.",
71+
"function.inside": "The function body (the stuff within the braces).",
72+
"class.around": "An entire class definition or equivalent large section of a file.",
73+
"class.inside": "The contents of a class definition.",
74+
"comment.around": "An entire comment (e.g. all adjacent line comments, or a block comment).",
75+
"comment.inside": "The contents of a comment."
6876
}
6977
}
7078
}

languages/ruby/textobjects.scm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
value: (_)
88
(_)+ @class.inside) @class.around
99

10+
(call
11+
receiver: (constant) @_class_const
12+
method: (identifier) @_class_method
13+
(#match? @_class_const "Class")
14+
(#match? @_class_method "new")
15+
(do_block
16+
(_)+ @class.inside)) @class.around
17+
1018
(module
1119
body: (_)? @class.inside) @class.around
1220

@@ -17,5 +25,13 @@
1725
(method
1826
body: (_)? @function.inside) @function.around
1927

28+
(do_block
29+
body: (_)? @function.inside) @function.around
30+
31+
(block
32+
body: (_)? @function.inside) @function.around
33+
2034
; Comments
2135
(comment) @comment.inside
36+
37+
(comment)+ @comment.around

0 commit comments

Comments
 (0)