-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_impacted.lua
More file actions
78 lines (66 loc) · 2.27 KB
/
code_impacted.lua
File metadata and controls
78 lines (66 loc) · 2.27 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- MCP Tool: code_impacted
-- Impact analysis: what files are affected by changing a file/symbol
-- 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:impacted", {
file = arguments.file,
depth = arguments.depth or 2,
project = arguments.project,
})
if err then return tools.format_error(err) end
local lines = {}
table.insert(lines, "# Impact Analysis: " .. (result.source or arguments.file))
table.insert(lines, "")
-- Direct
local direct_count = 0
local direct_files = {}
for file, info in pairs(result.direct or {}) do
direct_count = direct_count + 1
table.insert(direct_files, {
file = file,
ref_count = #(info.refs or {}),
})
end
table.sort(direct_files, function(a, b) return a.ref_count > b.ref_count end)
table.insert(lines, string.format("## Directly Impacted — %d files", direct_count))
for _, df in ipairs(direct_files) do
table.insert(lines, string.format(
" %-50s — %d references", df.file, df.ref_count
))
end
table.insert(lines, "")
-- Transitive
local trans_count = 0
local trans_files = {}
for file, info in pairs(result.transitive or {}) do
trans_count = trans_count + 1
table.insert(trans_files, {
file = file,
via = info.via,
depth = info.depth,
})
end
table.sort(trans_files, function(a, b) return a.file < b.file end)
if trans_count > 0 then
table.insert(lines, string.format(
"## Transitively Impacted — %d additional files", trans_count
))
for _, tf in ipairs(trans_files) do
table.insert(lines, string.format(
" %-50s — via %s (depth %d)", tf.file, tf.via, tf.depth
))
end
table.insert(lines, "")
end
table.insert(lines, string.format(
"Total: %d files potentially impacted",
direct_count + trans_count
))
return table.concat(lines, "\n")
end
return { call = call }