diff --git a/README.md b/README.md index 398d57f..2396fa0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/aerial/backends/treesitter/extensions.lua b/lua/aerial/backends/treesitter/extensions.lua index 17658be..fec9926 100644 --- a/lua/aerial/backends/treesitter/extensions.lua +++ b/lua/aerial/backends/treesitter/extensions.lua @@ -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 "" + 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 "" + item.name = name + else + item.name = "" + end + end, +} + for _, lang in pairs(M) do setmetatable(lang, { __index = default_methods }) end diff --git a/queries/fennel/aerial.scm b/queries/fennel/aerial.scm new file mode 100644 index 0000000..8983f8c --- /dev/null +++ b/queries/fennel/aerial.scm @@ -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 diff --git a/tests/symbols/fennel_test.json b/tests/symbols/fennel_test.json new file mode 100644 index 0000000..47cbf4d --- /dev/null +++ b/tests/symbols/fennel_test.json @@ -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": "" + } + ] + }, + { + "col": 0, + "end_col": 30, + "end_lnum": 16, + "kind": "Function", + "level": 0, + "lnum": 16, + "name": "!Aa3?+-*/<=>$%^_" + } +] diff --git a/tests/treesitter/fennel_test.fnl b/tests/treesitter/fennel_test.fnl new file mode 100644 index 0000000..ced3e3d --- /dev/null +++ b/tests/treesitter/fennel_test.fnl @@ -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)