Skip to content

Commit

Permalink
feat: add treesitter support for julia (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jan 6, 2022
1 parent 92c205c commit 0788ae5
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lua/aerial/backends/treesitter/language_kind_map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ return {
json = {
object = "Class",
},
julia = {
const_statement = "Constant",
abstract_definition = "Interface",
call_expression = "Function",
function_definition = "Function",
module_definition = "Module",
struct_definition = "Class",
},
lua = {
function_definition = "Function",
local_function = "Function",
Expand Down
19 changes: 19 additions & 0 deletions queries/julia/aerial.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(module_definition
name: (identifier) @name) @type

(function_definition
name: (identifier) @name) @type

(assignment_expression
. (call_expression
(identifier) @name) @type) @location

(abstract_definition
name: (identifier) @name) @type

(struct_definition
name: (identifier) @name) @type

(const_statement
(variable_declaration
. (identifier) @name)) @type
6 changes: 3 additions & 3 deletions tests/test_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ end
M.assert_tree_equals = function(received, expected, path)
path = path or {}
assert.equals(
type(received),
type(expected),
type(received),
string.format(
"Symbol list mismatch at %s: %s ~= %s",
table.concat(path, "/"),
Expand All @@ -28,8 +28,8 @@ M.assert_tree_equals = function(received, expected, path)
return
end
assert.equals(
#received,
#expected,
#received,
string.format(
"Number of symbols at '/%s' do not match %d ~= %d",
table.concat(path, "/"),
Expand Down Expand Up @@ -60,7 +60,7 @@ M.assert_tree_equals = function(received, expected, path)
)
local fields = { "kind", "name", "level", "lnum", "col" }
for _, field in ipairs(fields) do
assert.equals(child[field], exp_child[field], err_msg)
assert.equals(exp_child[field], child[field], err_msg)
end
table.insert(path, exp_child.name)
M.assert_tree_equals(child.children, exp_child.children, path)
Expand Down
68 changes: 68 additions & 0 deletions tests/treesitter/julia_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
local util = require("tests.test_util")

describe("treesitter julia", function()
it("parses all symbols correctly", function()
util.test_file_symbols("treesitter", "./tests/treesitter/julia_test.jl", {
{
kind = "Module",
name = "mod",
level = 0,
lnum = 1,
col = 0,
children = {
{
kind = "Constant",
name = "constant",
level = 1,
lnum = 3,
col = 0,
},
{
kind = "Function",
name = "func",
level = 1,
lnum = 5,
col = 0,
},
{
kind = "Function",
name = "myfunc",
level = 1,
lnum = 8,
col = 0,
},
{
kind = "Interface",
name = "MyType",
level = 1,
lnum = 10,
col = 0,
},
{
kind = "Class",
name = "MyStruct",
level = 1,
lnum = 12,
col = 0,
children = {
{
kind = "Function",
name = "MyStruct",
level = 2,
lnum = 13,
col = 4,
},
{
kind = "Function",
name = "method",
level = 2,
lnum = 14,
col = 4,
},
},
},
},
},
})
end)
end)
17 changes: 17 additions & 0 deletions tests/treesitter/julia_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module mod

const constant = nothing

function func()
end

myfunc() = nothing

abstract type MyType end

struct MyStruct <: MyType
MyStruct() = new()
method() = nothing
end

end

0 comments on commit 0788ae5

Please sign in to comment.