-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathinit.lua
More file actions
26 lines (20 loc) · 697 Bytes
/
init.lua
File metadata and controls
26 lines (20 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
local queries = require('java.treesitter.queries')
local M = {}
---Finds a main method in the given buffer and returns the line number
---@return integer | nil line number of the main method
function M.find_main_method(buffer)
local query = vim.treesitter.query.parse('java', queries.main_class)
local parser = vim.treesitter.get_parser(buffer, 'java')
local root = parser:parse()[1]:root()
for _, match, _ in query:iter_matches(root, buffer, 0, -1) do
for id, node in pairs(match) do
local capture_name = query.captures[id]
if capture_name == 'main_method' then
-- first element is the line number
return ({ node:start() })[1]
end
end
end
return nil
end
return M