mirror of
https://github.com/stevearc/aerial.nvim
synced 2024-09-16 14:34:08 +02:00
feat: add solidity treesitter support (#273)
* Add query for solidity * Add solidity to readme treesitter supported list * Add method in library * 修改方法图标显示 * interface包含function * Reformat solidity queries and add tests to solidity --------- Co-authored-by: lightnlightning <lightning004@outlook.com> Co-authored-by: lightnlightning <116029224+lightnlightning@users.noreply.github.com>
This commit is contained in:
parent
4b6da0b074
commit
7c2a432238
4 changed files with 141 additions and 0 deletions
|
@ -160,6 +160,7 @@ In addition, you will need to have either Treesitter or a working LSP client. Yo
|
|||
- ruby
|
||||
- rust
|
||||
- scala
|
||||
- solidity
|
||||
- teal
|
||||
- tsx
|
||||
- typescript
|
||||
|
|
43
queries/solidity/aerial.scm
Normal file
43
queries/solidity/aerial.scm
Normal file
|
@ -0,0 +1,43 @@
|
|||
(contract_declaration (_
|
||||
(function_definition
|
||||
name: (identifier) @name
|
||||
(#set! "kind" "Method")
|
||||
) @type))
|
||||
|
||||
(library_declaration (_
|
||||
(function_definition
|
||||
name: (identifier) @name
|
||||
(#set! "kind" "Function")
|
||||
) @type))
|
||||
|
||||
(interface_declaration (_
|
||||
(function_definition
|
||||
name: (identifier) @name
|
||||
(#set! "kind" "Function")
|
||||
) @type))
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier) @name
|
||||
(#set! "kind" "Function")
|
||||
) @type)
|
||||
|
||||
(contract_declaration
|
||||
name: (identifier) @name
|
||||
(#set! "kind" "Class")
|
||||
) @type
|
||||
|
||||
(interface_declaration
|
||||
name: (identifier) @name
|
||||
(#set! "kind" "Interface")
|
||||
) @type
|
||||
|
||||
(library_declaration
|
||||
name: (identifier) @name
|
||||
(#set! "kind" "Module")
|
||||
) @type
|
||||
|
||||
(event_definition
|
||||
name: (identifier) @name
|
||||
(#set! "kind" "Function")
|
||||
) @type
|
77
tests/treesitter/solidity_spec.lua
Normal file
77
tests/treesitter/solidity_spec.lua
Normal file
|
@ -0,0 +1,77 @@
|
|||
local util = require("tests.test_util")
|
||||
|
||||
describe("treesitter solidity", function()
|
||||
it("parses all symbols correctly", function()
|
||||
util.test_file_symbols("treesitter", "./tests/treesitter/solidity_test.sol", {
|
||||
{
|
||||
kind = "Module",
|
||||
name = "a",
|
||||
level = 0,
|
||||
lnum = 5,
|
||||
col = 0,
|
||||
end_lnum = 9,
|
||||
end_col = 1,
|
||||
children = {
|
||||
{
|
||||
kind = "Function",
|
||||
name = "f",
|
||||
level = 1,
|
||||
lnum = 6,
|
||||
col = 4,
|
||||
end_lnum = 8,
|
||||
end_col = 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
kind = "Class",
|
||||
name = "A",
|
||||
level = 0,
|
||||
lnum = 11,
|
||||
col = 0,
|
||||
end_lnum = 16,
|
||||
end_col = 1,
|
||||
children = {
|
||||
{
|
||||
kind = "Function",
|
||||
name = "Log",
|
||||
level = 1,
|
||||
lnum = 12,
|
||||
col = 4,
|
||||
end_lnum = 12,
|
||||
end_col = 54,
|
||||
},
|
||||
{
|
||||
kind = "Method",
|
||||
name = "m",
|
||||
level = 1,
|
||||
lnum = 13,
|
||||
col = 4,
|
||||
end_lnum = 15,
|
||||
end_col = 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
kind = "Interface",
|
||||
name = "I",
|
||||
level = 0,
|
||||
lnum = 18,
|
||||
col = 0,
|
||||
end_lnum = 20,
|
||||
end_col = 1,
|
||||
children = {
|
||||
{
|
||||
kind = "Function",
|
||||
name = "f",
|
||||
level = 1,
|
||||
lnum = 19,
|
||||
col = 4,
|
||||
end_lnum = 19,
|
||||
end_col = 17,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end)
|
||||
end)
|
20
tests/treesitter/solidity_test.sol
Normal file
20
tests/treesitter/solidity_test.sol
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Credit for this file goes to Gonçalo Sá and Federico Bond: https://github.com/ConsenSys/solidity-parser-antlr/commits/master/test/test.sol
|
||||
// I take part of that file
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
library a {
|
||||
function f() {
|
||||
uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6;
|
||||
}
|
||||
}
|
||||
|
||||
contract A {
|
||||
event Log(address indexed sender, string message);
|
||||
function m() {
|
||||
uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6;
|
||||
}
|
||||
}
|
||||
|
||||
interface I {
|
||||
function f();
|
||||
}
|
Loading…
Reference in a new issue