Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ In addition, you will need to have either Treesitter or a working LSP client. Yo
- editorconfig
- elixir
- enforce
- fennel
- fish
- go
- groovy
Expand Down
19 changes: 19 additions & 0 deletions lua/aerial/backends/treesitter/extensions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,25 @@ M.zig = {
end,
}

M.fennel = {
postprocess = function(bufnr, item, match)
local node = node_from_match(match, "symbol")
local full_form = get_node_text(node, bufnr)

if item.kind == "Function" then
local name = string.match(full_form, "[λ fn lambda macro] (%S+) %[")
item.name = name ~= nil and name or "<Anonymous>"
elseif item.kind == "Class" or item.kind == "Struct" then
local kind = (item.kind == "Class") and "local" or "var"
local query = kind .. " (%S+)"
local name = string.match(full_form, query) or "<parse error>"
item.name = name
else
item.name = "<parse error>"
end
end,
Comment on lines +407 to +423
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using these extensions to extract the name, could you just adjust the treesitter queries? The @name capture group can be used to select the node that contains the name.

}

for _, lang in pairs(M) do
setmetatable(lang, { __index = default_methods })
end
Expand Down
14 changes: 14 additions & 0 deletions queries/fennel/aerial.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(lambda_form
(#set! "kind" "Function")) @symbol @root

(fn_form
(#set! "kind" "Function")) @symbol @root

(macro_form
(#set! "kind" "Function")) @symbol @root

(local_form
(#set! "kind" "Class")) @symbol @root

(var_form
(#set! "kind" "Struct")) @symbol @root
Comment on lines +10 to +14
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do Struct and Class make sense for these? I would assume that this more naturally maps to the Variable type

87 changes: 87 additions & 0 deletions tests/symbols/fennel_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[
{
"col": 0,
"end_col": 15,
"end_lnum": 2,
"kind": "Function",
"level": 0,
"lnum": 1,
"name": "foo"
},
{
"col": 0,
"end_col": 15,
"end_lnum": 5,
"kind": "Function",
"level": 0,
"lnum": 4,
"name": "_m__"
},
{
"col": 0,
"end_col": 15,
"end_lnum": 10,
"kind": "Function",
"level": 0,
"lnum": 7,
"name": "bar",
"children": [
{
"col": 2,
"end_col": 16,
"end_lnum": 8,
"kind": "Struct",
"level": 1,
"lnum": 8,
"name": "test"
},
{
"col": 2,
"end_col": 24,
"end_lnum": 9,
"kind": "Function",
"level": 1,
"lnum": 9,
"name": "foo->bar?!"
}
]
},
{
"col": 0,
"end_col": 15,
"end_lnum": 13,
"kind": "Function",
"level": 0,
"lnum": 12,
"name": "_G.baz"
},
{
"col": 0,
"end_col": 34,
"end_lnum": 15,
"kind": "Class",
"level": 0,
"lnum": 15,
"name": "!Aa3?+-*/<=>$%^_",
"children": [
{
"col": 24,
"end_col": 33,
"end_lnum": 15,
"kind": "Function",
"level": 1,
"lnum": 15,
"name": "<Anonymous>"
}
]
},
{
"col": 0,
"end_col": 30,
"end_lnum": 16,
"kind": "Function",
"level": 0,
"lnum": 16,
"name": "!Aa3?+-*/<=>$%^_"
}
]
16 changes: 16 additions & 0 deletions tests/treesitter/fennel_test.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(fn foo []
(print :foo))

(macro _m__ []
`(+ 1 2 3 4))

(λ bar []
(var test nil)
(fn foo->bar?! [] nil)
(print :bar))

(lambda _G.baz []
(print :baz))

(local !Aa3?+-*/<=>$%^_ (fn [] 1))
(lambda !Aa3?+-*/<=>$%^_ [] 2)
Loading