-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_callers.lua
More file actions
49 lines (39 loc) · 1.32 KB
/
code_callers.lua
File metadata and controls
49 lines (39 loc) · 1.32 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- MCP Tool: code_callers
-- Caller chain (upward): who calls this function/method?
-- Entry kind: function.lua
local tools = require("tools")
local fmt = require("fmt")
local function call(arguments)
if not arguments.symbol or arguments.symbol == "" then
return tools.format_error("'symbol' parameter is required")
end
local result, err = tools.request("query:callers", {
symbol = arguments.symbol,
depth = arguments.depth or 3,
project = arguments.project,
})
if err then return tools.format_error(err) end
local lines = {}
table.insert(lines, "# Callers of " .. result.name)
table.insert(lines, "")
local tree_lines = fmt.render_tree(result, {max_depth = arguments.depth or 3})
for _, l in ipairs(tree_lines) do
table.insert(lines, l)
end
-- Count totals
local function count_nodes(node)
local c = #(node.children or {})
for _, child in ipairs(node.children or {}) do
c = c + count_nodes(child)
end
return c
end
local direct = #(result.children or {})
local total = count_nodes(result)
table.insert(lines, "")
table.insert(lines, string.format(
"Summary: %d direct callers, %d total in chain", direct, total
))
return table.concat(lines, "\n")
end
return { call = call }