@codua/codeoutline-win32-x64 0.1.5 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DISTRIBUTION.md +60 -15
- package/README.md +7 -7
- package/README.zh-CN.md +7 -7
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/codeoutline +3 -1
- package/codeoutline.cmd +5 -1
- package/package.json +1 -1
- package/scripts/codeoutline/command.lua +103 -7
- package/scripts/codeoutline/common.lua +10 -2
- package/scripts/codeoutline/daemon.lua +223 -0
- package/scripts/codeoutline/explore.lua +46 -42
- package/scripts/codeoutline/graph.lua +89 -54
- package/scripts/codeoutline/http.lua +5 -0
- package/scripts/codeoutline/index.lua +246 -66
- package/scripts/codeoutline/index_worker.lua +1 -0
- package/scripts/codeoutline/main.lua +71 -11
- package/scripts/codeoutline/service.lua +25 -4
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/update_worker.lua +17 -7
- package/scripts/codeoutline/updater.lua +8 -5
- package/scripts/codeoutline/version.lua +1 -1
- package/scripts/codeoutline/xscan.lua +41 -2
- package/scripts/xupgate/client.lua +85 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
-- The shared background HTTP service: one per user, started at login and by
|
|
2
|
+
-- installation. It runs the newest installed version and restarts itself into
|
|
3
|
+
-- an update, so MCP clients connect to one URL and nothing else stays running.
|
|
4
|
+
local u = require('xutils')
|
|
5
|
+
local M = {}
|
|
6
|
+
M.PORT = 19876
|
|
7
|
+
local windows = package.config:sub(1, 1) == '\\'
|
|
8
|
+
local LABEL = 'io.github.1dao.codeoutline'
|
|
9
|
+
|
|
10
|
+
local function home() return (os.getenv('USERPROFILE') or os.getenv('HOME') or '.'):gsub('\\', '/') end
|
|
11
|
+
function M.state_dir() return home() .. '/.codeoutline' end
|
|
12
|
+
function M.logs_dir() return M.state_dir() .. '/logs' end
|
|
13
|
+
-- Created to ask the service on that port to exit (uninstall, reinstall).
|
|
14
|
+
function M.stop_file(port) return M.state_dir() .. '/service-' .. port .. '.stop' end
|
|
15
|
+
|
|
16
|
+
local function read(path)
|
|
17
|
+
local f = io.open(path, 'rb'); if not f then return nil end
|
|
18
|
+
local data = f:read('a'); f:close(); return data
|
|
19
|
+
end
|
|
20
|
+
local function write(path, data)
|
|
21
|
+
assert(u.mkdir_p(assert(path:match('^(.*)/[^/]+$'))))
|
|
22
|
+
local f = assert(io.open(path, 'wb'))
|
|
23
|
+
assert(f:write(data)); assert(f:close())
|
|
24
|
+
end
|
|
25
|
+
local function same_path(a, b)
|
|
26
|
+
local function norm(p) p = p:gsub('\\', '/'):gsub('/+$', ''); return windows and p:lower() or p end
|
|
27
|
+
return norm(a) == norm(b)
|
|
28
|
+
end
|
|
29
|
+
local function sequence(root)
|
|
30
|
+
local info = u.json_unpack(read(root .. '/build-info.json') or '')
|
|
31
|
+
return type(info) == 'table' and tonumber(info.updateSequence) or nil
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
-- Files root of the newest verified version: an installed update, or install
|
|
35
|
+
-- itself when it is newer (an npm upgrade) or nothing is installed. A source
|
|
36
|
+
-- checkout (no build-info.json) runs itself.
|
|
37
|
+
function M.current_root(install)
|
|
38
|
+
local own = sequence(install)
|
|
39
|
+
if not own then return install end
|
|
40
|
+
-- active() applies the same rule as launcher selection: this install's
|
|
41
|
+
-- sequence is the updater's minimum, so an older update is skipped.
|
|
42
|
+
local ok, current = pcall(function()
|
|
43
|
+
return require('xupgate.client').open(require('codeoutline.updater').config()).active()
|
|
44
|
+
end)
|
|
45
|
+
if ok and current then return current.root end
|
|
46
|
+
return install
|
|
47
|
+
end
|
|
48
|
+
function M.is_current(install) return same_path(M.current_root(install), install) end
|
|
49
|
+
|
|
50
|
+
-- argv of the service run from root. Paths reach a shell, the registry or a
|
|
51
|
+
-- unit file, so characters that would need escaping there are refused.
|
|
52
|
+
local function argv(root, port)
|
|
53
|
+
root = root:gsub('\\', '/'):gsub('/+$', '')
|
|
54
|
+
local runtime = root .. (windows and '/bin/xnet.exe' or '/bin/xnet')
|
|
55
|
+
local entry = root .. '/scripts/codeoutline/command.lua'
|
|
56
|
+
local logs = M.logs_dir()
|
|
57
|
+
for _, path in ipairs({ runtime, entry, logs }) do
|
|
58
|
+
assert(not path:find('[%%"\'`$\\!&|<>^;\r\n]'), 'unsupported characters in path: ' .. path)
|
|
59
|
+
end
|
|
60
|
+
if windows then runtime = runtime:gsub('/', '\\') end
|
|
61
|
+
return { runtime, entry, 'LOG_STDERR=0', 'LOG_LEVEL=WARN', 'LOG_DIR=' .. logs, 'daemon', '--port', tostring(port) }
|
|
62
|
+
end
|
|
63
|
+
local function quoted(args)
|
|
64
|
+
local out = {}
|
|
65
|
+
for i, a in ipairs(args) do out[i] = a:find('[%s=]') and '"' .. a .. '"' or a end
|
|
66
|
+
return table.concat(out, ' ')
|
|
67
|
+
end
|
|
68
|
+
local function sh_quote(s) return "'" .. s:gsub("'", "'\\''") .. "'" end
|
|
69
|
+
local function command_ok(command) local ok = os.execute(command); return ok == true or ok == 0 end
|
|
70
|
+
|
|
71
|
+
-- Start the service from root, detached: it must outlive the process that
|
|
72
|
+
-- starts it and must not inherit its stdio. A second instance exits by itself.
|
|
73
|
+
function M.spawn(root, port)
|
|
74
|
+
local args = argv(root, port or M.PORT)
|
|
75
|
+
local logs = M.logs_dir()
|
|
76
|
+
assert(u.mkdir_p(logs))
|
|
77
|
+
if windows then
|
|
78
|
+
-- Arguments travel through the environment, keeping the script ASCII.
|
|
79
|
+
local list = {}
|
|
80
|
+
for i = 2, #args do list[#list + 1] = "('\"'+$env:CO_ARG" .. i .. "+'\"')" end
|
|
81
|
+
local script = "$ProgressPreference='SilentlyContinue';Start-Process -WindowStyle Hidden -WorkingDirectory $env:CO_LOGS "
|
|
82
|
+
.. '-FilePath $env:CO_ARG1 -ArgumentList ' .. table.concat(list, ',')
|
|
83
|
+
local encoded = {}
|
|
84
|
+
for i = 1, #script do encoded[#encoded + 1] = script:sub(i, i) .. '\0' end
|
|
85
|
+
local env = { 'set "CO_LOGS=' .. logs .. '"' }
|
|
86
|
+
for i, a in ipairs(args) do env[#env + 1] = 'set "CO_ARG' .. i .. '=' .. a .. '"' end
|
|
87
|
+
return command_ok(table.concat(env, ' && ') .. ' && powershell -NoProfile -NonInteractive -WindowStyle Hidden -EncodedCommand '
|
|
88
|
+
.. u.base64_encode(table.concat(encoded)) .. ' >NUL 2>&1')
|
|
89
|
+
end
|
|
90
|
+
local parts = {}
|
|
91
|
+
for i, a in ipairs(args) do parts[i] = sh_quote(a) end
|
|
92
|
+
return command_ok('cd ' .. sh_quote(logs) .. ' && S=; command -v setsid >/dev/null 2>&1 && S=setsid; $S nohup '
|
|
93
|
+
.. table.concat(parts, ' ') .. ' </dev/null >/dev/null 2>&1 &')
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
-- Login entries. Each runs the service once per login; it then keeps itself
|
|
97
|
+
-- current, so entries only change when the installation moves.
|
|
98
|
+
local function entry_paths()
|
|
99
|
+
local h = home()
|
|
100
|
+
return {
|
|
101
|
+
darwin = h .. '/Library/LaunchAgents/' .. LABEL .. '.plist',
|
|
102
|
+
systemd = (os.getenv('XDG_CONFIG_HOME') or h .. '/.config') .. '/systemd/user/codeoutline.service',
|
|
103
|
+
}
|
|
104
|
+
end
|
|
105
|
+
local RUN_KEY = [[HKCU\Software\Microsoft\Windows\CurrentVersion\Run]]
|
|
106
|
+
|
|
107
|
+
-- The text of a login entry, by kind.
|
|
108
|
+
local function render(kind, args)
|
|
109
|
+
if kind == 'windows' then
|
|
110
|
+
-- conhost --headless gives the console runtime no window at all.
|
|
111
|
+
return 'conhost.exe --headless ' .. quoted(args)
|
|
112
|
+
elseif kind == 'darwin' then
|
|
113
|
+
local items = {}
|
|
114
|
+
for i, a in ipairs(args) do items[i] = ' <string>' .. a:gsub('&', '&'):gsub('<', '<') .. '</string>' end
|
|
115
|
+
return table.concat({ '<?xml version="1.0" encoding="UTF-8"?>',
|
|
116
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
117
|
+
'<plist version="1.0">', '<dict>', ' <key>Label</key><string>' .. LABEL .. '</string>',
|
|
118
|
+
' <key>ProgramArguments</key>', ' <array>', table.concat(items, '\n'), ' </array>',
|
|
119
|
+
' <key>RunAtLoad</key><true/>',
|
|
120
|
+
-- The service restarts itself as a new process; keep that one alive.
|
|
121
|
+
' <key>AbandonProcessGroup</key><true/>', '</dict>', '</plist>', '' }, '\n')
|
|
122
|
+
elseif kind == 'systemd' then
|
|
123
|
+
return table.concat({ '[Unit]', 'Description=CodeOutline shared MCP service', '', '[Service]', 'Type=simple',
|
|
124
|
+
'ExecStart=' .. quoted(args),
|
|
125
|
+
-- The service restarts itself as a new process; stopping this unit's
|
|
126
|
+
-- first process must not take the replacement with it.
|
|
127
|
+
'KillMode=process', '', '[Install]', 'WantedBy=default.target', '' }, '\n')
|
|
128
|
+
end
|
|
129
|
+
error('unknown entry kind ' .. tostring(kind))
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
local function platform()
|
|
133
|
+
if windows then return 'windows' end
|
|
134
|
+
local p = io.popen('uname -s 2>/dev/null')
|
|
135
|
+
local name = p and p:read('a') or ''
|
|
136
|
+
if p then p:close() end
|
|
137
|
+
return name:match('^Darwin') and 'darwin' or 'linux'
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
-- Register the login entry for the service run from root. Returns a description.
|
|
141
|
+
function M.register(root, port)
|
|
142
|
+
port = port or M.PORT
|
|
143
|
+
local args = argv(root, port)
|
|
144
|
+
local kind = platform()
|
|
145
|
+
if kind == 'windows' then
|
|
146
|
+
local value = render('windows', args):gsub('"', '\\"')
|
|
147
|
+
assert(command_ok('reg add "' .. RUN_KEY .. '" /v CodeOutline /t REG_SZ /d "' .. value .. '" /f >NUL 2>&1'),
|
|
148
|
+
'cannot write ' .. RUN_KEY)
|
|
149
|
+
kind = RUN_KEY .. '\\CodeOutline'
|
|
150
|
+
elseif kind == 'darwin' then
|
|
151
|
+
write(entry_paths().darwin, render('darwin', args))
|
|
152
|
+
kind = entry_paths().darwin
|
|
153
|
+
else
|
|
154
|
+
-- Systems without a systemd user manager (WSL, containers) rarely run
|
|
155
|
+
-- a login session that would start anything else either.
|
|
156
|
+
assert(command_ok('systemctl --user show-environment >/dev/null 2>&1'),
|
|
157
|
+
'no systemd user manager; start "codeoutline daemon" at login yourself')
|
|
158
|
+
local path = entry_paths().systemd
|
|
159
|
+
write(path, render('systemd', args))
|
|
160
|
+
assert(command_ok('systemctl --user daemon-reload >/dev/null 2>&1 && systemctl --user enable codeoutline.service >/dev/null 2>&1'),
|
|
161
|
+
'cannot enable ' .. path)
|
|
162
|
+
kind = path
|
|
163
|
+
end
|
|
164
|
+
return kind
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
function M.unregister()
|
|
168
|
+
local removed = {}
|
|
169
|
+
if windows then
|
|
170
|
+
if command_ok('reg query "' .. RUN_KEY .. '" /v CodeOutline >NUL 2>&1') then
|
|
171
|
+
assert(command_ok('reg delete "' .. RUN_KEY .. '" /v CodeOutline /f >NUL 2>&1'), 'cannot remove ' .. RUN_KEY .. '\\CodeOutline')
|
|
172
|
+
removed[#removed + 1] = RUN_KEY .. '\\CodeOutline'
|
|
173
|
+
end
|
|
174
|
+
else
|
|
175
|
+
local paths = entry_paths()
|
|
176
|
+
if u.stat(paths.systemd).exists then
|
|
177
|
+
os.execute('systemctl --user disable codeoutline.service >/dev/null 2>&1')
|
|
178
|
+
os.remove(paths.systemd)
|
|
179
|
+
os.execute('systemctl --user daemon-reload >/dev/null 2>&1')
|
|
180
|
+
removed[#removed + 1] = paths.systemd
|
|
181
|
+
end
|
|
182
|
+
if u.stat(paths.darwin).exists then os.remove(paths.darwin); removed[#removed + 1] = paths.darwin end
|
|
183
|
+
end
|
|
184
|
+
return removed
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
-- Calls done(true) once a connection to the port succeeds, done(false) when
|
|
188
|
+
-- refused. Needs an initialized xnet.
|
|
189
|
+
function M.probe(port, done)
|
|
190
|
+
local connected, finished = false, false
|
|
191
|
+
local function finish(value) if not finished then finished = true; done(value) end end
|
|
192
|
+
local conn = xnet.connect('127.0.0.1', port, {
|
|
193
|
+
on_connect = function(c) connected = true; c:close('probe') end,
|
|
194
|
+
on_packet = function(_, data) return #data end,
|
|
195
|
+
on_close = function() finish(connected) end,
|
|
196
|
+
})
|
|
197
|
+
if not conn then xtimer.add(1, function() finish(false) end, 1) end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
-- Poll the port until it is listening (want true) or closed (want false), up
|
|
201
|
+
-- to timeout_ms; done(reached). Needs an initialized xnet and xtimer.
|
|
202
|
+
local function poll(port, want, timeout_ms, done)
|
|
203
|
+
local deadline = xtimer.now_ms() + timeout_ms
|
|
204
|
+
local function check()
|
|
205
|
+
M.probe(port, function(listening)
|
|
206
|
+
if listening == want then done(true)
|
|
207
|
+
elseif xtimer.now_ms() >= deadline then done(false)
|
|
208
|
+
else xtimer.add(200, check, 1) end
|
|
209
|
+
end)
|
|
210
|
+
end
|
|
211
|
+
check()
|
|
212
|
+
end
|
|
213
|
+
function M.wait(port, timeout_ms, done) poll(port, true, timeout_ms, done) end
|
|
214
|
+
|
|
215
|
+
-- Ask the service on port to exit and wait up to timeout_ms for the port to
|
|
216
|
+
-- close; done(stopped). Needs an initialized xnet and xtimer.
|
|
217
|
+
function M.stop(port, timeout_ms, done)
|
|
218
|
+
local path = M.stop_file(port)
|
|
219
|
+
write(path, 'stop\n')
|
|
220
|
+
poll(port, false, timeout_ms, function(stopped) os.remove(path); done(stopped) end)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
return M
|
|
@@ -117,9 +117,8 @@ end
|
|
|
117
117
|
|
|
118
118
|
-- Rank one candidate node for a query term.
|
|
119
119
|
local function seed_score(G, id, exact)
|
|
120
|
-
local
|
|
121
|
-
|
|
122
|
-
if vendored(G.files[n.f].path) then s = s - 6 end
|
|
120
|
+
local s = (KIND_WEIGHT[G.nodes[id].kind] or 1) + (exact and 20 or 0)
|
|
121
|
+
if vendored(G.files[G.node_file[id]].path) then s = s - 6 end
|
|
123
122
|
return s
|
|
124
123
|
end
|
|
125
124
|
|
|
@@ -151,11 +150,11 @@ local function find_seeds(G, query)
|
|
|
151
150
|
local last = t.text:match('([%w_]+)$')
|
|
152
151
|
local first = t.text:match('^([%w_]+)')
|
|
153
152
|
for _, id in ipairs(G.by_name[last] or {}) do
|
|
154
|
-
local q = G.nodes[id].
|
|
153
|
+
local q = G.nodes[id].qualified:gsub('[:]+', '.')
|
|
155
154
|
if q == t.text or q:sub(-(#t.text + 1)) == '.' .. t.text then
|
|
156
155
|
consider(id, seed_score(G, id, true) + 10)
|
|
157
156
|
elseif select(2, t.text:gsub('%.', '')) == 1
|
|
158
|
-
and G.files[G.
|
|
157
|
+
and G.files[G.node_file[id]].path:match('([^/]+)%.[^./]+$') == first then
|
|
159
158
|
-- module.func where the module is the file: Lua's `local M`
|
|
160
159
|
-- tables and Python modules are named by their file
|
|
161
160
|
consider(id, seed_score(G, id, true) + 8)
|
|
@@ -205,15 +204,17 @@ local function path_between(G, a, b, depth)
|
|
|
205
204
|
for _ = 1, depth do
|
|
206
205
|
local next_frontier = {}
|
|
207
206
|
for _, x in ipairs(frontier) do
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
207
|
+
local out = G.out[x] or {}
|
|
208
|
+
for i = 1, #out, graph.EDGE do
|
|
209
|
+
local dst = out[i]
|
|
210
|
+
if not prev[dst] then
|
|
211
|
+
prev[dst] = x
|
|
212
|
+
if dst == b then
|
|
212
213
|
local path, y = { b }, b
|
|
213
214
|
while y ~= a do y = prev[y]; table.insert(path, 1, y) end
|
|
214
215
|
return path
|
|
215
216
|
end
|
|
216
|
-
next_frontier[#next_frontier + 1] =
|
|
217
|
+
next_frontier[#next_frontier + 1] = dst
|
|
217
218
|
end
|
|
218
219
|
end
|
|
219
220
|
end
|
|
@@ -246,9 +247,8 @@ end
|
|
|
246
247
|
-- Source block for one node, cut to `full` lines (head + tail beyond).
|
|
247
248
|
-- Classes/structs over the limit collapse to their member outline.
|
|
248
249
|
local function node_block(G, idx, id, full)
|
|
249
|
-
local
|
|
250
|
-
local
|
|
251
|
-
local lines = file_lines(idx, G.files[n.f].path)
|
|
250
|
+
local node = G.nodes[id]
|
|
251
|
+
local lines = file_lines(idx, G.files[G.node_file[id]].path)
|
|
252
252
|
local a, b = node.line, math.max(node.end_line, node.line)
|
|
253
253
|
local out = {}
|
|
254
254
|
local span = b - a + 1
|
|
@@ -264,7 +264,7 @@ local function node_block(G, idx, id, full)
|
|
|
264
264
|
-- one line and the later signature covers both
|
|
265
265
|
local rows, row_lines = {}, {}
|
|
266
266
|
for _, k in ipairs(kids) do
|
|
267
|
-
local kn = G.nodes[k]
|
|
267
|
+
local kn = G.nodes[k]
|
|
268
268
|
if not rows[kn.line] then row_lines[#row_lines + 1] = kn.line end
|
|
269
269
|
rows[kn.line] = kn.sig or kn.name
|
|
270
270
|
end
|
|
@@ -282,8 +282,8 @@ local function node_block(G, idx, id, full)
|
|
|
282
282
|
end
|
|
283
283
|
|
|
284
284
|
local function label(G, id)
|
|
285
|
-
local
|
|
286
|
-
return string.format('%s %s (%s)',
|
|
285
|
+
local node = G.nodes[id]
|
|
286
|
+
return string.format('%s %s (%s)', node.kind, node.qualified, graph.where(G, id))
|
|
287
287
|
end
|
|
288
288
|
|
|
289
289
|
-- Run a query. Returns the text and a table with what was selected.
|
|
@@ -299,12 +299,12 @@ function M.run(G, idx, query, opts)
|
|
|
299
299
|
-- among the matches (the definition's source is what the caller wants).
|
|
300
300
|
local defined = {}
|
|
301
301
|
for _, c in ipairs(ranked) do
|
|
302
|
-
local node = G.nodes[c.id]
|
|
302
|
+
local node = G.nodes[c.id]
|
|
303
303
|
if node.kind ~= 'prototype' and not node.decl then defined[node.name] = true end
|
|
304
304
|
end
|
|
305
305
|
local seeds, per_name = {}, {}
|
|
306
306
|
for _, c in ipairs(ranked) do
|
|
307
|
-
local node = G.nodes[c.id]
|
|
307
|
+
local node = G.nodes[c.id]
|
|
308
308
|
local name = node.name
|
|
309
309
|
if not ((node.kind == 'prototype' or node.decl) and defined[name]) then
|
|
310
310
|
per_name[name] = (per_name[name] or 0) + 1
|
|
@@ -323,7 +323,7 @@ function M.run(G, idx, query, opts)
|
|
|
323
323
|
if p then
|
|
324
324
|
local names = {}
|
|
325
325
|
for _, id in ipairs(p) do
|
|
326
|
-
names[#names + 1] = G.nodes[id].
|
|
326
|
+
names[#names + 1] = G.nodes[id].name
|
|
327
327
|
if not is_seed[id] and not on_spine[id] then
|
|
328
328
|
on_spine[id] = true
|
|
329
329
|
spine[#spine + 1] = id
|
|
@@ -348,8 +348,8 @@ function M.run(G, idx, query, opts)
|
|
|
348
348
|
|
|
349
349
|
-- Section 1: summary + flows.
|
|
350
350
|
local nfiles = {}
|
|
351
|
-
for _, id in ipairs(seeds) do nfiles[G.
|
|
352
|
-
for _, id in ipairs(spine) do nfiles[G.
|
|
351
|
+
for _, id in ipairs(seeds) do nfiles[G.node_file[id]] = true end
|
|
352
|
+
for _, id in ipairs(spine) do nfiles[G.node_file[id]] = true end
|
|
353
353
|
local nf = 0
|
|
354
354
|
for _ in pairs(nfiles) do nf = nf + 1 end
|
|
355
355
|
emit(string.format('Matched %d symbols in %d files, %d more on call paths between them; short ones bring their callees. Source below is verbatim with line numbers; treat it as already Read.',
|
|
@@ -369,16 +369,17 @@ function M.run(G, idx, query, opts)
|
|
|
369
369
|
local in_order = {}
|
|
370
370
|
for _, item in ipairs(order) do in_order[item.id] = true end
|
|
371
371
|
for _, id in ipairs(seeds) do
|
|
372
|
-
local node = G.nodes[id]
|
|
372
|
+
local node = G.nodes[id]
|
|
373
373
|
if node.end_line - node.line < M.CONTEXT_SEED_LINES then
|
|
374
374
|
local added = 0
|
|
375
|
-
|
|
375
|
+
local out = G.out[id] or {}
|
|
376
|
+
for i = 1, #out, graph.EDGE do
|
|
376
377
|
if added >= M.CONTEXT_PER_SEED then break end
|
|
377
|
-
local
|
|
378
|
-
local k =
|
|
379
|
-
if not in_order[
|
|
380
|
-
in_order[
|
|
381
|
-
order[#order + 1] = { id =
|
|
378
|
+
local dst = out[i]
|
|
379
|
+
local k = G.nodes[dst].kind
|
|
380
|
+
if not in_order[dst] and G.node_file[dst] == G.node_file[id] and (k == 'function' or k == 'method') then
|
|
381
|
+
in_order[dst] = true
|
|
382
|
+
order[#order + 1] = { id = dst, full = M.SPINE_FULL_LINES }
|
|
382
383
|
added = added + 1
|
|
383
384
|
end
|
|
384
385
|
end
|
|
@@ -386,7 +387,7 @@ function M.run(G, idx, query, opts)
|
|
|
386
387
|
end
|
|
387
388
|
local by_file, pointers = {}, {}
|
|
388
389
|
for _, item in ipairs(order) do
|
|
389
|
-
local f = G.
|
|
390
|
+
local f = G.node_file[item.id]
|
|
390
391
|
if not by_file[f] then by_file[f] = {}; file_order[#file_order + 1] = f end
|
|
391
392
|
table.insert(by_file[f], item)
|
|
392
393
|
end
|
|
@@ -401,10 +402,10 @@ function M.run(G, idx, query, opts)
|
|
|
401
402
|
-- producing any output. Unrelated project files remain speculative.
|
|
402
403
|
local selected, changed = {}, false
|
|
403
404
|
for _, f in ipairs(file_order) do selected[f] = true end
|
|
404
|
-
for _, c in ipairs(ranked) do selected[G.
|
|
405
|
+
for _, c in ipairs(ranked) do selected[G.node_file[c.id]] = true end
|
|
405
406
|
for _, id in ipairs(seeds) do
|
|
406
407
|
for _, edges in ipairs({ G.inn[id] or {}, G.out[id] or {} }) do
|
|
407
|
-
for
|
|
408
|
+
for i = 1, #edges, graph.EDGE do selected[G.node_file[edges[i]]] = true end
|
|
408
409
|
end
|
|
409
410
|
end
|
|
410
411
|
for f in pairs(selected) do
|
|
@@ -418,7 +419,7 @@ function M.run(G, idx, query, opts)
|
|
|
418
419
|
local rec = G.files[f]
|
|
419
420
|
local header = '\n## ' .. rec.path
|
|
420
421
|
local items = by_file[f]
|
|
421
|
-
table.sort(items, function(a, b) return G.nodes[a.id].
|
|
422
|
+
table.sort(items, function(a, b) return G.nodes[a.id].line < G.nodes[b.id].line end)
|
|
422
423
|
local wrote_header = false
|
|
423
424
|
if items.outline then
|
|
424
425
|
local ol = {}
|
|
@@ -452,21 +453,24 @@ function M.run(G, idx, query, opts)
|
|
|
452
453
|
for _, id in ipairs(seeds) do
|
|
453
454
|
local callers, callees = {}, {}
|
|
454
455
|
local seen_in, seen_out = {}, {}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
456
|
+
local inn, out = G.inn[id] or {}, G.out[id] or {}
|
|
457
|
+
for i = 1, #inn, graph.EDGE do
|
|
458
|
+
local src = inn[i]
|
|
459
|
+
if not seen_in[src] and #callers < M.LIST_CAP then
|
|
460
|
+
seen_in[src] = true
|
|
461
|
+
callers[#callers + 1] = string.format('%s (%s:%d)', G.nodes[src].name, G.files[G.node_file[src]].path, inn[i + 1])
|
|
459
462
|
end
|
|
460
463
|
end
|
|
461
|
-
for
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
464
|
+
for i = 1, #out, graph.EDGE do
|
|
465
|
+
local dst = out[i]
|
|
466
|
+
if not seen_out[dst] and #callees < M.LIST_CAP then
|
|
467
|
+
seen_out[dst] = true
|
|
468
|
+
callees[#callees + 1] = G.nodes[dst].name .. ' (' .. graph.where(G, dst) .. ')'
|
|
465
469
|
end
|
|
466
470
|
end
|
|
467
471
|
if #callers > 0 or #callees > 0 then
|
|
468
|
-
local nsites =
|
|
469
|
-
rel[#rel + 1] = string.format('%s:\n called by%s: %s\n calls: %s', G.nodes[id].
|
|
472
|
+
local nsites = math.floor(#inn / graph.EDGE)
|
|
473
|
+
rel[#rel + 1] = string.format('%s:\n called by%s: %s\n calls: %s', G.nodes[id].qualified,
|
|
470
474
|
nsites > #callers and string.format(' (%d call sites)', nsites) or '',
|
|
471
475
|
#callers > 0 and table.concat(callers, ', ') or '-',
|
|
472
476
|
#callees > 0 and table.concat(callees, ', ') or '-')
|