mirror of
https://github.com/stevearc/aerial.nvim
synced 2024-09-16 14:34:08 +02:00
feat(ts): add ruby support for ruby operator methods (#292)
Ruby supports some operators overloading by declaring a method with the operator as the method name, e.g. `def <=>(other)`. Tree sitter ruby parser recognises these method names as operators, not identifiers, and as such existing queries skip over them. This commit adds a query that captures "operator" instance methods.
This commit is contained in:
parent
22ed2f75eb
commit
fa8c408b76
3 changed files with 75 additions and 48 deletions
|
@ -8,6 +8,11 @@
|
|||
(#set! "kind" "Method")
|
||||
) @type
|
||||
|
||||
(method
|
||||
name: (operator) @name
|
||||
(#set! "kind" "Method")
|
||||
) @type
|
||||
|
||||
(method
|
||||
name: (setter
|
||||
name: (identifier)) @name
|
||||
|
|
|
@ -9,7 +9,7 @@ describe("treesitter ruby", function()
|
|||
level = 0,
|
||||
lnum = 1,
|
||||
col = 0,
|
||||
end_lnum = 9,
|
||||
end_lnum = 13,
|
||||
end_col = 3,
|
||||
children = {
|
||||
{
|
||||
|
@ -50,42 +50,60 @@ describe("treesitter ruby", function()
|
|||
end_lnum = 8,
|
||||
end_col = 22,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "==",
|
||||
level = 1,
|
||||
lnum = 10,
|
||||
col = 2,
|
||||
end_lnum = 10,
|
||||
end_col = 19,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "oneline",
|
||||
level = 1,
|
||||
lnum = 12,
|
||||
col = 2,
|
||||
end_lnum = 12,
|
||||
end_col = 21,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "describe UnitTest",
|
||||
level = 0,
|
||||
lnum = 11,
|
||||
lnum = 15,
|
||||
col = 0,
|
||||
end_lnum = 18,
|
||||
end_lnum = 22,
|
||||
end_col = 3,
|
||||
children = {
|
||||
{
|
||||
kind = "Method",
|
||||
name = "before :all",
|
||||
level = 1,
|
||||
lnum = 12,
|
||||
lnum = 16,
|
||||
col = 2,
|
||||
end_lnum = 13,
|
||||
end_lnum = 17,
|
||||
end_col = 5,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "after",
|
||||
level = 1,
|
||||
lnum = 14,
|
||||
lnum = 18,
|
||||
col = 2,
|
||||
end_lnum = 15,
|
||||
end_lnum = 19,
|
||||
end_col = 5,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "it should describe the test",
|
||||
level = 1,
|
||||
lnum = 16,
|
||||
lnum = 20,
|
||||
col = 2,
|
||||
end_lnum = 17,
|
||||
end_lnum = 21,
|
||||
end_col = 5,
|
||||
},
|
||||
},
|
||||
|
@ -94,54 +112,54 @@ describe("treesitter ruby", function()
|
|||
kind = "Method",
|
||||
name = "namespace rake_namespace",
|
||||
level = 0,
|
||||
lnum = 20,
|
||||
lnum = 24,
|
||||
col = 0,
|
||||
end_lnum = 26,
|
||||
end_lnum = 30,
|
||||
end_col = 3,
|
||||
children = {
|
||||
{
|
||||
kind = "Method",
|
||||
name = "task :simple_task",
|
||||
level = 1,
|
||||
lnum = 21,
|
||||
lnum = 25,
|
||||
col = 2,
|
||||
end_lnum = 21,
|
||||
end_lnum = 25,
|
||||
end_col = 29,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "task inline_task",
|
||||
level = 1,
|
||||
lnum = 22,
|
||||
lnum = 26,
|
||||
col = 2,
|
||||
end_lnum = 22,
|
||||
end_lnum = 26,
|
||||
end_col = 43,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "task rake_task",
|
||||
level = 1,
|
||||
lnum = 23,
|
||||
lnum = 27,
|
||||
col = 2,
|
||||
end_lnum = 23,
|
||||
end_lnum = 27,
|
||||
end_col = 37,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "multitask parallel_prereqs",
|
||||
level = 1,
|
||||
lnum = 24,
|
||||
lnum = 28,
|
||||
col = 2,
|
||||
end_lnum = 24,
|
||||
end_lnum = 28,
|
||||
end_col = 58,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "file create_file",
|
||||
level = 1,
|
||||
lnum = 25,
|
||||
lnum = 29,
|
||||
col = 2,
|
||||
end_lnum = 25,
|
||||
end_lnum = 29,
|
||||
end_col = 30,
|
||||
},
|
||||
},
|
||||
|
@ -150,18 +168,18 @@ describe("treesitter ruby", function()
|
|||
kind = "Module",
|
||||
name = "Long::Mod::Name",
|
||||
level = 0,
|
||||
lnum = 29,
|
||||
lnum = 33,
|
||||
col = 0,
|
||||
end_lnum = 32,
|
||||
end_lnum = 36,
|
||||
end_col = 3,
|
||||
children = {
|
||||
{
|
||||
kind = "Class",
|
||||
name = "Long::Class::Name",
|
||||
level = 1,
|
||||
lnum = 30,
|
||||
lnum = 34,
|
||||
col = 2,
|
||||
end_lnum = 31,
|
||||
end_lnum = 35,
|
||||
end_col = 5,
|
||||
},
|
||||
},
|
||||
|
@ -170,33 +188,15 @@ describe("treesitter ruby", function()
|
|||
kind = "Method",
|
||||
name = "context Shoulda Context",
|
||||
level = 0,
|
||||
lnum = 34,
|
||||
lnum = 38,
|
||||
col = 0,
|
||||
end_lnum = 44,
|
||||
end_lnum = 48,
|
||||
end_col = 3,
|
||||
children = {
|
||||
{
|
||||
kind = "Method",
|
||||
name = "setup",
|
||||
level = 1,
|
||||
lnum = 35,
|
||||
col = 2,
|
||||
end_lnum = 36,
|
||||
end_col = 5,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "teardown",
|
||||
level = 1,
|
||||
lnum = 37,
|
||||
col = 2,
|
||||
end_lnum = 38,
|
||||
end_col = 5,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "should test something",
|
||||
level = 1,
|
||||
lnum = 39,
|
||||
col = 2,
|
||||
end_lnum = 40,
|
||||
|
@ -204,7 +204,7 @@ describe("treesitter ruby", function()
|
|||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "should_eventually actually work",
|
||||
name = "teardown",
|
||||
level = 1,
|
||||
lnum = 41,
|
||||
col = 2,
|
||||
|
@ -213,11 +213,29 @@ describe("treesitter ruby", function()
|
|||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "should_not validate_presence_of(:title)",
|
||||
name = "should test something",
|
||||
level = 1,
|
||||
lnum = 43,
|
||||
col = 2,
|
||||
end_lnum = 43,
|
||||
end_lnum = 44,
|
||||
end_col = 5,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "should_eventually actually work",
|
||||
level = 1,
|
||||
lnum = 45,
|
||||
col = 2,
|
||||
end_lnum = 46,
|
||||
end_col = 5,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "should_not validate_presence_of(:title)",
|
||||
level = 1,
|
||||
lnum = 47,
|
||||
col = 2,
|
||||
end_lnum = 47,
|
||||
end_col = 41,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -6,6 +6,10 @@ module Mod
|
|||
def meth_2() end
|
||||
|
||||
def name=(value) end
|
||||
|
||||
def ==(other) end
|
||||
|
||||
def oneline = "woo"
|
||||
end
|
||||
|
||||
describe 'UnitTest' do
|
||||
|
|
Loading…
Reference in a new issue