-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_deps.lua
More file actions
49 lines (40 loc) · 1.43 KB
/
code_deps.lua
File metadata and controls
49 lines (40 loc) · 1.43 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_deps
-- File/namespace dependency tree
-- Entry kind: function.lua
local tools = require("tools")
local fmt = require("fmt")
local function call(arguments)
if not arguments.file or arguments.file == "" then
return tools.format_error("'file' parameter is required")
end
local result, err = tools.request("query:deps", {
file = arguments.file,
direction = arguments.direction or "both",
depth = arguments.depth or 3,
project = arguments.project,
})
if err then return tools.format_error(err) end
local lines = {}
table.insert(lines, "# Dependencies: " .. arguments.file)
table.insert(lines, "")
if result.imports then
table.insert(lines, "## Imports (what this file uses)")
table.insert(lines, "")
local tree_lines = fmt.render_tree(result.imports, {max_depth = arguments.depth or 3})
for _, l in ipairs(tree_lines) do
table.insert(lines, l)
end
table.insert(lines, "")
end
if result.imported_by then
table.insert(lines, "## Imported By (who uses this file)")
table.insert(lines, "")
local tree_lines = fmt.render_tree(result.imported_by, {max_depth = arguments.depth or 3})
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 }