-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_hierarchy.lua
More file actions
50 lines (41 loc) · 1.47 KB
/
code_hierarchy.lua
File metadata and controls
50 lines (41 loc) · 1.47 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
50
-- MCP Tool: code_hierarchy
-- Inheritance and implementation tree
-- 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:hierarchy", {
symbol = arguments.symbol,
direction = arguments.direction or "both",
project = arguments.project,
})
if err then return tools.format_error(err) end
local lines = {}
table.insert(lines, "# Hierarchy: " .. result.name)
if result.kind then
table.insert(lines, "Kind: " .. result.kind)
end
table.insert(lines, "")
-- Ancestors (upward)
if result.ancestors and #result.ancestors > 0 then
table.insert(lines, "## Ancestors (extends chain)")
for i, ancestor in ipairs(result.ancestors) do
table.insert(lines, string.rep(" ", i - 1) .. "└── " .. ancestor)
end
table.insert(lines, "")
end
-- Descendants (downward)
if result.descendants then
table.insert(lines, "## Descendants (subclasses / implementations)")
local tree_lines = fmt.render_tree(result.descendants, {max_depth = 10})
for _, l in ipairs(tree_lines) do
table.insert(lines, l)
end
table.insert(lines, "")
end
return table.concat(lines, "\n")
end
return { call = call }