Skip to content

Commit

Permalink
feat(ts): support for more solidity symbols (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
madlabman committed Sep 16, 2023
1 parent 9bcfbaf commit bed048d
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 18 deletions.
41 changes: 33 additions & 8 deletions queries/solidity/aerial.scm
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
(contract_declaration
name: (identifier) @name
(#set! "kind" "Class")
) @type

(contract_declaration (_
(function_definition
name: (identifier) @name
(#set! "kind" "Method")
) @type))

(contract_declaration (_
(modifier_definition
name: (identifier) @name
(#set! "kind" "Method")
) @type))

(library_declaration (_
(function_definition
name: (identifier) @name
(#set! "kind" "Function")
) @type))

(interface_declaration
name: (identifier) @name
(#set! "kind" "Interface")
) @type

(interface_declaration (_
(function_definition
name: (identifier) @name
Expand All @@ -22,22 +38,31 @@
(#set! "kind" "Function")
) @type)

(contract_declaration
(library_declaration
name: (identifier) @name
(#set! "kind" "Class")
(#set! "kind" "Module")
) @type

(interface_declaration
(enum_declaration
name: (identifier) @name
(#set! "kind" "Interface")
(#set! "kind" "Enum")
) @type

(library_declaration
(event_definition
name: (identifier) @name
(#set! "kind" "Module")
(#set! "kind" "Event")
) @type

(event_definition
(struct_declaration
name: (identifier) @name
(#set! "kind" "Function")
(#set! "kind" "Struct")
) @type

(constructor_definition
("constructor") @name
(#set! "kind" "Constructor")
) @type

(state_variable_declaration
name: (identifier) @name @type
(#set! "kind" "Field"))
65 changes: 55 additions & 10 deletions tests/treesitter/solidity_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,52 @@ describe("treesitter solidity", function()
level = 0,
lnum = 11,
col = 0,
end_lnum = 16,
end_lnum = 25,
end_col = 1,
children = {
{
kind = "Function",
name = "Log",
kind = "Field",
name = "flag",
level = 1,
lnum = 12,
col = 4,
col = 9,
end_lnum = 12,
end_col = 13,
},
{
kind = "Event",
name = "Log",
level = 1,
lnum = 13,
col = 4,
end_lnum = 13,
end_col = 54,
},
{
kind = "Constructor",
name = "constructor",
level = 1,
lnum = 15,
col = 4,
end_lnum = 15,
end_col = 27,
},
{
kind = "Method",
name = "m",
level = 1,
lnum = 13,
lnum = 17,
col = 4,
end_lnum = 15,
end_lnum = 19,
end_col = 5,
},
{
kind = "Method",
name = "never",
level = 1,
lnum = 21,
col = 4,
end_lnum = 24,
end_col = 5,
},
},
Expand All @@ -56,22 +83,40 @@ describe("treesitter solidity", function()
kind = "Interface",
name = "I",
level = 0,
lnum = 18,
lnum = 27,
col = 0,
end_lnum = 20,
end_lnum = 29,
end_col = 1,
children = {
{
kind = "Function",
name = "f",
level = 1,
lnum = 19,
lnum = 28,
col = 4,
end_lnum = 19,
end_lnum = 28,
end_col = 17,
},
},
},
{
kind = "Struct",
name = "S",
level = 0,
lnum = 31,
col = 0,
end_lnum = 34,
end_col = 1,
},
{
kind = "Enum",
name = "E",
level = 0,
lnum = 36,
col = 0,
end_lnum = 40,
end_col = 1,
},
})
end)
end)
20 changes: 20 additions & 0 deletions tests/treesitter/solidity_test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,32 @@ library a {
}

contract A {
bool flag;
event Log(address indexed sender, string message);

constructor() public {}

function m() {
uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6;
}

modifier never() {
require(false);
_;
}
}

interface I {
function f();
}

struct S {
uint x;
uint y;
}

enum E {
A,
B,
C
}

0 comments on commit bed048d

Please sign in to comment.