Skip to content

Commit f2de9d5

Browse files
authored
Support Rake outlines (#131)
Add support for rake tasks and namespaces in the outline. Namespaces are supported when the first positional argument is either a literal string or a literal symbol and the namespace is either in another namespace block or at the root of the program. Tasks are supported when the first positional argument is either a literal string or a literal symbol or there is a keyword argument with a literal symbol key. Tasks can be nested in namespaces or be at the root of the program. Since TreeSitter’s query language doesn't support recursion, it is possible for false-positives. The nested queries only check that they are inside a namespace call’s block. They don’t care if there’s a line of namespaces all the way from the `program` node. I think this is reasonable though given the limitations. <img width="1393" alt="Screenshot 2025-06-30 at 19 45 54" src="https://github.com/user-attachments/assets/d6d4b82e-5603-455e-a1ef-2781726172e2" />
1 parent b7453ac commit f2de9d5

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

languages/ruby/outline.scm

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,77 @@
239239
)
240240
)
241241
)
242+
243+
; Root rake namespace
244+
(program
245+
(call
246+
method: (identifier) @namespace @name (#any-of? @namespace "namespace")
247+
arguments: (argument_list . [
248+
(string) @name
249+
(simple_symbol) @name
250+
]
251+
)
252+
) @item
253+
)
254+
255+
; Nested rake namespace
256+
(call
257+
method: (identifier) @parent_namespace (#any-of? @parent_namespace "namespace")
258+
arguments: (argument_list . [
259+
(string)
260+
(simple_symbol)
261+
]+
262+
)
263+
block: (_
264+
(_
265+
(call
266+
method: (identifier) @namespace @name (#any-of? @namespace "namespace")
267+
arguments: (argument_list . [
268+
(string) @name
269+
(simple_symbol) @name
270+
]
271+
)
272+
) @item
273+
)
274+
)
275+
)
276+
277+
; Root rake task
278+
(program
279+
(call
280+
method: (identifier) @task @name (#any-of? @task "task")
281+
arguments: (argument_list . [
282+
(string) @name
283+
(simple_symbol) @name
284+
(pair
285+
key: (hash_key_symbol) @name
286+
)
287+
]
288+
)
289+
) @item
290+
)
291+
292+
; Nested rake task
293+
(call
294+
method: (identifier) @namespace (#any-of? @namespace "namespace")
295+
arguments: (argument_list . [
296+
(string)
297+
(simple_symbol)
298+
]+
299+
)
300+
block: (_
301+
(_
302+
(call
303+
method: (identifier) @task @name (#any-of? @task "task")
304+
arguments: (argument_list . [
305+
(string) @name
306+
(simple_symbol) @name
307+
(pair
308+
key: (hash_key_symbol) @name
309+
)
310+
]
311+
)
312+
) @item
313+
)
314+
)
315+
)

0 commit comments

Comments
 (0)