@codua/codeoutline-win32-x64 0.2.4 → 0.2.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/README.md +205 -3
- package/README.zh-CN.md +40 -2
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/package.json +1 -1
- package/scripts/codeoutline/affected.lua +145 -0
- package/scripts/codeoutline/automatic_events.lua +202 -0
- package/scripts/codeoutline/cache_repairs.lua +47 -0
- package/scripts/codeoutline/callers.lua +56 -16
- package/scripts/codeoutline/cargo_toml.lua +125 -0
- package/scripts/codeoutline/command.lua +26 -4
- package/scripts/codeoutline/common.lua +65 -9
- package/scripts/codeoutline/completion.lua +221 -65
- package/scripts/codeoutline/coverage.lua +63 -0
- package/scripts/codeoutline/cpp_bindings.lua +151 -0
- package/scripts/codeoutline/cpp_fragments.lua +143 -0
- package/scripts/codeoutline/cpp_implementations.lua +340 -0
- package/scripts/codeoutline/cpp_includes.lua +156 -0
- package/scripts/codeoutline/cpp_macros.lua +279 -0
- package/scripts/codeoutline/cpp_receivers.lua +342 -0
- package/scripts/codeoutline/cpp_types.lua +456 -0
- package/scripts/codeoutline/csharp_bindings.lua +498 -0
- package/scripts/codeoutline/definition_candidates.lua +180 -0
- package/scripts/codeoutline/dispatch_aliases.lua +479 -0
- package/scripts/codeoutline/documents.lua +32 -9
- package/scripts/codeoutline/explore.lua +274 -119
- package/scripts/codeoutline/external_headers.lua +171 -0
- package/scripts/codeoutline/foreign.lua +79 -14
- package/scripts/codeoutline/foreign_lua.lua +146 -19
- package/scripts/codeoutline/function_values.lua +69 -0
- package/scripts/codeoutline/go_methods.lua +931 -0
- package/scripts/codeoutline/go_modules.lua +329 -0
- package/scripts/codeoutline/graph.lua +346 -63
- package/scripts/codeoutline/implementations.lua +403 -0
- package/scripts/codeoutline/index.lua +165 -27
- package/scripts/codeoutline/index_worker.lua +11 -4
- package/scripts/codeoutline/indirect.lua +116 -40
- package/scripts/codeoutline/js_evidence.lua +32 -3
- package/scripts/codeoutline/js_resolution.lua +72 -10
- package/scripts/codeoutline/js_workspace.lua +325 -0
- package/scripts/codeoutline/lang/c.lua +15 -2
- package/scripts/codeoutline/lang/cpp.lua +7 -4
- package/scripts/codeoutline/lang/csharp.lua +15 -3
- package/scripts/codeoutline/lang/js.lua +56 -20
- package/scripts/codeoutline/lang/rust.lua +9 -1
- package/scripts/codeoutline/language_detect.lua +100 -0
- package/scripts/codeoutline/lsp.lua +173 -23
- package/scripts/codeoutline/lua_bindings.lua +228 -54
- package/scripts/codeoutline/lua_callback_loops.lua +210 -0
- package/scripts/codeoutline/lua_literal.lua +38 -0
- package/scripts/codeoutline/main.lua +32 -7
- package/scripts/codeoutline/mcp.lua +52 -9
- package/scripts/codeoutline/navigation.lua +593 -147
- package/scripts/codeoutline/on_demand.lua +93 -0
- package/scripts/codeoutline/ordinary_bindings.lua +396 -0
- package/scripts/codeoutline/parse.lua +18 -2
- package/scripts/codeoutline/parse_pool.lua +1 -1
- package/scripts/codeoutline/parse_worker.lua +1 -1
- package/scripts/codeoutline/python_bindings.lua +112 -0
- package/scripts/codeoutline/query_filters.lua +65 -0
- package/scripts/codeoutline/query_report.lua +135 -8
- package/scripts/codeoutline/resolution.lua +23 -0
- package/scripts/codeoutline/rules.lua +127 -0
- package/scripts/codeoutline/rust_packages.lua +203 -0
- package/scripts/codeoutline/rust_resolution.lua +301 -0
- package/scripts/codeoutline/search_ranking.lua +70 -0
- package/scripts/codeoutline/service.lua +47 -7
- package/scripts/codeoutline/shared_events.lua +369 -0
- package/scripts/codeoutline/static_dispatch.lua +569 -0
- package/scripts/codeoutline/text.lua +3 -2
- package/scripts/codeoutline/ts_implementations.lua +81 -0
- package/scripts/codeoutline/type_bases.lua +61 -0
- package/scripts/codeoutline/type_hierarchy.lua +324 -0
- package/scripts/codeoutline/type_references.lua +290 -0
- package/scripts/codeoutline/type_uses.lua +260 -0
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
|
@@ -27,6 +27,7 @@ function M.validate(query, opts)
|
|
|
27
27
|
assert(type(query) == 'string' and query:find('%S') and #query <= 4096 and not query:find('%z'),
|
|
28
28
|
'query must contain 1-4096 bytes of non-empty text without NUL')
|
|
29
29
|
assert(text.valid(query) == query, 'query must be valid UTF-8')
|
|
30
|
+
require('codeoutline.query_filters').parse(query)
|
|
30
31
|
assert(opts == nil or type(opts) == 'table', 'options must be a table')
|
|
31
32
|
local budget = M.DEFAULT_BUDGET
|
|
32
33
|
if opts and opts.budget ~= nil then budget = opts.budget end
|
|
@@ -59,16 +60,6 @@ for w in ([[the a an and or of to in on for with from by is are was be how what
|
|
|
59
60
|
STOP[w] = true
|
|
60
61
|
end
|
|
61
62
|
|
|
62
|
-
local VENDORED = { '/3rd/', '^3rd/', '/third_party/', '^third_party/', '/thirdparty/',
|
|
63
|
-
'/vendor/', '^vendor/', '/node_modules/', '/external/', '^external/', '/deps/', '^deps/' }
|
|
64
|
-
|
|
65
|
-
local function vendored(path)
|
|
66
|
-
for _, p in ipairs(VENDORED) do
|
|
67
|
-
if path:find(p) then return true end
|
|
68
|
-
end
|
|
69
|
-
return false
|
|
70
|
-
end
|
|
71
|
-
|
|
72
63
|
-- Split camelCase / snake_case into lowercase segments.
|
|
73
64
|
local function segments(name)
|
|
74
65
|
local out = {}
|
|
@@ -101,7 +92,7 @@ local function terms(query)
|
|
|
101
92
|
for _, p in ipairs(parts) do seen['name:' .. p] = true; seen['word:' .. p] = true end
|
|
102
93
|
end
|
|
103
94
|
end
|
|
104
|
-
for path in query:gmatch('[%w_%-%./]
|
|
95
|
+
for path in query:gmatch('[%w_%-%./]+%.[%a][%w_]*') do
|
|
105
96
|
local ext = path:match('%.(%a+)$')
|
|
106
97
|
if path:find('/') or (ext and SOURCE_EXT[ext:lower()]) then add('file', path) end
|
|
107
98
|
end
|
|
@@ -116,21 +107,21 @@ local function terms(query)
|
|
|
116
107
|
return out
|
|
117
108
|
end
|
|
118
109
|
|
|
119
|
-
|
|
120
|
-
local
|
|
121
|
-
local
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
local function find_seeds(G, query)
|
|
110
|
+
local function find_seeds(G, query, filters, ranking)
|
|
111
|
+
local predicate = require('codeoutline.query_filters')
|
|
112
|
+
local function seed_score(id, exact, explicit)
|
|
113
|
+
local s = (KIND_WEIGHT[G.nodes[id].kind] or 1) + (exact and 20 or 0)
|
|
114
|
+
return s - ranking.penalty(G.files[G.node_file[id]].path, explicit)
|
|
115
|
+
end
|
|
127
116
|
local cands = {} -- id -> score
|
|
128
117
|
local files = {} -- file indices named in the query
|
|
129
118
|
local considered = 0
|
|
130
119
|
local function consider(id, s)
|
|
131
120
|
considered = considered + 1
|
|
132
121
|
if considered % 128 == 0 then control.check() end
|
|
122
|
+
if not predicate.id(filters, G, id) then return end
|
|
133
123
|
if not cands[id] or cands[id] < s then cands[id] = s end
|
|
124
|
+
return true
|
|
134
125
|
end
|
|
135
126
|
local list_terms = terms(query)
|
|
136
127
|
local has_code = false
|
|
@@ -144,14 +135,18 @@ local function find_seeds(G, query)
|
|
|
144
135
|
-- matching, which is where English words pick up noise), and rank
|
|
145
136
|
-- below code-like terms when the query has any.
|
|
146
137
|
for _, id in ipairs(G.by_name[t.text] or {}) do
|
|
147
|
-
consider(id, seed_score(
|
|
138
|
+
consider(id, seed_score(id, true) - (has_code and 12 or 8))
|
|
148
139
|
end
|
|
149
140
|
elseif t.kind == 'file' then
|
|
150
141
|
local want = t.text:gsub('\\', '/')
|
|
151
142
|
for i, f in ipairs(G.file_order) do
|
|
152
143
|
if i % 128 == 0 then control.check() end
|
|
153
144
|
local rec = G.files[f]
|
|
154
|
-
if rec.path == want or rec.path:sub(-(#want + 1)) == '/' .. want
|
|
145
|
+
if (rec.path == want or rec.path:sub(-(#want + 1)) == '/' .. want) and predicate.file(filters, rec) then
|
|
146
|
+
for _, node in ipairs(rec.nodes) do
|
|
147
|
+
if predicate.node(filters, rec, node) then files[#files + 1] = f; break end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
155
150
|
end
|
|
156
151
|
elseif t.kind == 'qualified' then
|
|
157
152
|
local last = t.text:match('([%w_]+)$')
|
|
@@ -160,43 +155,74 @@ local function find_seeds(G, query)
|
|
|
160
155
|
if i % 128 == 0 then control.check() end
|
|
161
156
|
local q = G.nodes[id].qualified:gsub('[:]+', '.')
|
|
162
157
|
if q == t.text or q:sub(-(#t.text + 1)) == '.' .. t.text then
|
|
163
|
-
consider(id, seed_score(
|
|
158
|
+
consider(id, seed_score(id, true, true) + 10)
|
|
164
159
|
elseif select(2, t.text:gsub('%.', '')) == 1
|
|
165
160
|
and G.files[G.node_file[id]].path:match('([^/]+)%.[^./]+$') == first then
|
|
166
161
|
-- module.func where the module is the file: Lua's `local M`
|
|
167
162
|
-- tables and Python modules are named by their file
|
|
168
|
-
consider(id, seed_score(
|
|
163
|
+
consider(id, seed_score(id, true, true) + 8)
|
|
169
164
|
end
|
|
170
165
|
end
|
|
171
166
|
else
|
|
172
167
|
local exact = G.by_name[t.text]
|
|
173
168
|
if exact then
|
|
174
169
|
-- a name defined in many places is generic; keep its best few
|
|
175
|
-
for _, id in ipairs(exact) do consider(id, seed_score(
|
|
170
|
+
for _, id in ipairs(exact) do consider(id, seed_score(id, true) - math.min(#exact, 20) * 0.2) end
|
|
176
171
|
else
|
|
177
172
|
local ci = G.by_lname[t.text:lower()]
|
|
178
173
|
if ci then
|
|
179
|
-
for _, id in ipairs(ci) do consider(id, seed_score(
|
|
174
|
+
for _, id in ipairs(ci) do consider(id, seed_score(id, true) - 2) end
|
|
180
175
|
elseif #t.text >= 4 then
|
|
181
176
|
-- fuzzy: every query segment appears in the name's segments
|
|
182
177
|
local want = segments(t.text)
|
|
183
178
|
local hits, visited = 0, 0
|
|
184
|
-
for
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
179
|
+
for _, names in ipairs(G.query_base_names and { G.by_name, G.query_base_names } or { G.by_name }) do
|
|
180
|
+
for name, ids in pairs(names) do
|
|
181
|
+
if names ~= G.query_base_names or rawget(G.by_name, name) == nil then
|
|
182
|
+
visited = visited + 1
|
|
183
|
+
if visited % 128 == 0 then control.check() end
|
|
184
|
+
local lname = name:lower()
|
|
185
|
+
local ok = true
|
|
186
|
+
for _, w in ipairs(want) do
|
|
187
|
+
if not lname:find(w, 1, true) then ok = false; break end
|
|
188
|
+
end
|
|
189
|
+
if ok then
|
|
190
|
+
local accepted = false
|
|
191
|
+
for _, id in ipairs(ids) do
|
|
192
|
+
if consider(id, seed_score(id, false) - #name * 0.05) then accepted = true end
|
|
193
|
+
end
|
|
194
|
+
if accepted then hits = hits + 1 end
|
|
195
|
+
if hits > 200 then break end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
191
198
|
end
|
|
192
|
-
if
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
199
|
+
if hits > 200 then break end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
if query == '' then
|
|
206
|
+
local count = 0
|
|
207
|
+
-- With a configured policy, select the candidate window from preferred
|
|
208
|
+
-- files first so an early generated directory cannot fill all 512 slots.
|
|
209
|
+
for pass = 1, ranking.configured and 2 or 1 do
|
|
210
|
+
for _, f in ipairs(G.file_order) do
|
|
211
|
+
control.check()
|
|
212
|
+
local rec = G.files[f]
|
|
213
|
+
if predicate.file(filters, rec) and (not ranking.configured
|
|
214
|
+
or (ranking.penalty(rec.path) > 0) == (pass == 2)) then
|
|
215
|
+
for i, id in ipairs(G.id_of[f]) do
|
|
216
|
+
if i % 256 == 0 then control.check() end
|
|
217
|
+
if predicate.id(filters, G, id) then
|
|
218
|
+
if count >= 512 then filters.seed_limit_reached = true; break end
|
|
219
|
+
consider(id, seed_score(id, false)); count = count + 1
|
|
196
220
|
end
|
|
197
221
|
end
|
|
198
222
|
end
|
|
223
|
+
if filters.seed_limit_reached then break end
|
|
199
224
|
end
|
|
225
|
+
if filters.seed_limit_reached then break end
|
|
200
226
|
end
|
|
201
227
|
end
|
|
202
228
|
local list = {}
|
|
@@ -211,42 +237,56 @@ local function find_seeds(G, query)
|
|
|
211
237
|
return list, files
|
|
212
238
|
end
|
|
213
239
|
|
|
214
|
-
-- Shortest
|
|
240
|
+
-- Shortest dependency path a -> b, retaining edge kinds for presentation.
|
|
215
241
|
local function path_between(G, a, b, depth)
|
|
216
|
-
local prev, frontier = { [a] = a }, { a }
|
|
242
|
+
local prev, frontier, via = { [a] = a }, { a }, {}
|
|
243
|
+
local expansion_limited = false
|
|
217
244
|
for _ = 1, depth do
|
|
218
245
|
local next_frontier = {}
|
|
219
246
|
for _, x in ipairs(frontier) do
|
|
220
247
|
control.check()
|
|
221
|
-
local out = G.out[x]
|
|
248
|
+
local out = G.out[x]
|
|
249
|
+
if out == nil and G.incomplete then expansion_limited = true end
|
|
250
|
+
out = out or {}
|
|
222
251
|
for i = 1, #out, graph.EDGE do
|
|
223
252
|
if i % 128 == 1 then control.check() end
|
|
224
253
|
local dst = out[i]
|
|
225
254
|
if not prev[dst] then
|
|
226
255
|
prev[dst] = x
|
|
256
|
+
via[dst] = { source = x, target = dst, kind = out[i + 2], line = out[i + 1] }
|
|
227
257
|
if dst == b then
|
|
228
258
|
local path, y = { b }, b
|
|
229
259
|
while y ~= a do y = prev[y]; table.insert(path, 1, y) end
|
|
230
|
-
|
|
260
|
+
local hops = {}; for n = 2, #path do hops[#hops + 1] = via[path[n]] end
|
|
261
|
+
return path, false, prev, expansion_limited, hops
|
|
231
262
|
end
|
|
232
263
|
next_frontier[#next_frontier + 1] = dst
|
|
233
264
|
end
|
|
234
265
|
end
|
|
235
266
|
end
|
|
236
267
|
frontier = next_frontier
|
|
237
|
-
if #frontier == 0 then return nil end
|
|
238
|
-
if #frontier > 20000 then return nil, true end
|
|
268
|
+
if #frontier == 0 then return nil, false, prev, expansion_limited, nil, via end
|
|
269
|
+
if #frontier > 20000 then return nil, true, prev, expansion_limited, nil, via end
|
|
239
270
|
end
|
|
240
|
-
return nil, #frontier > 0
|
|
271
|
+
return nil, #frontier > 0, prev, expansion_limited, nil, via
|
|
241
272
|
end
|
|
242
273
|
|
|
243
|
-
local file_cache = {}
|
|
274
|
+
local file_cache, source_cache = {}, {}
|
|
275
|
+
local encoding_retry = {}
|
|
276
|
+
local function checked_source(idx, rel)
|
|
277
|
+
local key = idx.root .. '/' .. rel
|
|
278
|
+
if source_cache[key] then return source_cache[key] end
|
|
279
|
+
local source, repaired = idx:query_source(rel)
|
|
280
|
+
assert(source, 'cannot read source: ' .. rel)
|
|
281
|
+
if repaired then error(encoding_retry, 0) end
|
|
282
|
+
source_cache[key] = source; return source
|
|
283
|
+
end
|
|
244
284
|
local function file_lines(idx, rel)
|
|
245
285
|
local key = idx.root .. '/' .. rel
|
|
246
286
|
local lines = file_cache[key]
|
|
247
287
|
if lines then return lines end
|
|
248
288
|
lines = {}
|
|
249
|
-
local src =
|
|
289
|
+
local src = checked_source(idx, rel)
|
|
250
290
|
if src then
|
|
251
291
|
for line in (src .. '\n'):gmatch('([^\n]*)\n') do lines[#lines + 1] = (line:gsub('\r$', '')) end
|
|
252
292
|
end
|
|
@@ -282,7 +322,7 @@ local function node_block(G, idx, id, full)
|
|
|
282
322
|
for _, k in ipairs(kids) do
|
|
283
323
|
local kn = G.nodes[k]
|
|
284
324
|
if not rows[kn.line] then row_lines[#row_lines + 1] = kn.line end
|
|
285
|
-
rows[kn.line] = kn.sig or kn.name
|
|
325
|
+
rows[kn.line] = require('codeoutline.navigation').detail(G, G.node_file[k], kn).sig or kn.name
|
|
286
326
|
end
|
|
287
327
|
for _, ln in ipairs(row_lines) do
|
|
288
328
|
out[#out + 1] = string.format('%d\t %s', ln, rows[ln])
|
|
@@ -302,18 +342,55 @@ local function label(G, id)
|
|
|
302
342
|
return string.format('%s %s (%s)', node.kind, node.qualified, graph.where(G, id))
|
|
303
343
|
end
|
|
304
344
|
|
|
345
|
+
local edge_label = require('codeoutline.query_report').edge_label
|
|
346
|
+
|
|
347
|
+
local function candidate_text(G, idx, report, in_order)
|
|
348
|
+
if #report.entries == 0 then return nil end
|
|
349
|
+
local lines, references, used = {}, {}, 0
|
|
350
|
+
local function append(line, files)
|
|
351
|
+
line = text.valid(line)
|
|
352
|
+
if files then references[#references + 1] = { at = used, files = files } end
|
|
353
|
+
lines[#lines + 1] = line; used = used + #line + 1
|
|
354
|
+
end
|
|
355
|
+
append('\n## Unconfirmed definition candidates')
|
|
356
|
+
append('Suggestions for unresolved calls only, not call edges or verified bindings. Inspect the source before using them.')
|
|
357
|
+
local shown = {}
|
|
358
|
+
for _, group in ipairs(report.entries) do
|
|
359
|
+
append(string.format('- Unresolved %s at %s:%d: %s', group.call, group.path, group.line, group.resolution_reason),
|
|
360
|
+
{ G.node_file[group.source] })
|
|
361
|
+
for _, candidate in ipairs(group.candidates) do
|
|
362
|
+
local id = candidate.id
|
|
363
|
+
append(' Unconfirmed candidate: ' .. label(G, id) .. '; ' .. candidate.reason, { G.node_file[id] })
|
|
364
|
+
if not in_order[id] and not shown[id] then
|
|
365
|
+
local node = G.nodes[id]
|
|
366
|
+
local source = file_lines(idx, candidate.path)
|
|
367
|
+
for line = node.line, math.min(#source, node.end_line, node.line + 7) do
|
|
368
|
+
append(string.format('%d\t%s', line, source[line]), { G.node_file[id] })
|
|
369
|
+
end
|
|
370
|
+
if node.end_line > node.line + 7 then append('\t... (candidate snippet only; explore its file and name for more)') end
|
|
371
|
+
shown[id] = true
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
if report.truncated then append('Candidate lookup reached a site, source, evidence or result limit; more candidates may exist.') end
|
|
376
|
+
return table.concat(lines, '\n'), references
|
|
377
|
+
end
|
|
378
|
+
|
|
305
379
|
-- Run a query over symbol tables (graph.build). Returns the text and a table
|
|
306
380
|
-- with what was selected; relationships resolve per query.
|
|
307
|
-
function
|
|
381
|
+
local function run(G, idx, query, opts)
|
|
308
382
|
control.check()
|
|
309
383
|
opts = opts or {}
|
|
310
384
|
local budget = M.validate(query, opts)
|
|
311
385
|
local query_opts = {}
|
|
312
386
|
for key, value in pairs(opts) do query_opts[key] = value end
|
|
313
387
|
query_opts.explain = true
|
|
388
|
+
local ranking = require('codeoutline.search_ranking').policy(G.root or idx.root)
|
|
314
389
|
G = graph.query(G, query_opts)
|
|
315
|
-
|
|
316
|
-
|
|
390
|
+
G.stats.ranking = ranking.stats
|
|
391
|
+
file_cache, source_cache = {}, {}
|
|
392
|
+
local filters = require('codeoutline.query_filters').parse(query)
|
|
393
|
+
local ranked, named_files = find_seeds(G, filters.text, filters, ranking)
|
|
317
394
|
|
|
318
395
|
-- Seeds: top-ranked, but at most 3 definitions per name so one generic
|
|
319
396
|
-- name can't crowd out the others the query mentions.
|
|
@@ -324,46 +401,76 @@ function M.run(G, idx, query, opts)
|
|
|
324
401
|
local node = G.nodes[c.id]
|
|
325
402
|
if node.kind ~= 'prototype' and not node.decl then defined[node.name] = true end
|
|
326
403
|
end
|
|
327
|
-
local seeds, per_name = {}, {}
|
|
404
|
+
local seeds, per_name, seed_selection_limited = {}, {}, false
|
|
328
405
|
for _, c in ipairs(ranked) do
|
|
329
406
|
local node = G.nodes[c.id]
|
|
330
407
|
local name = node.name
|
|
331
408
|
if not ((node.kind == 'prototype' or node.decl) and defined[name]) then
|
|
332
409
|
per_name[name] = (per_name[name] or 0) + 1
|
|
333
|
-
if per_name[name] <= 3 and #seeds < M.MAX_SEEDS then seeds[#seeds + 1] = c.id
|
|
410
|
+
if per_name[name] <= 3 and #seeds < M.MAX_SEEDS then seeds[#seeds + 1] = c.id
|
|
411
|
+
else seed_selection_limited = true end
|
|
334
412
|
end
|
|
335
413
|
end
|
|
336
414
|
local is_seed = {}
|
|
337
415
|
for _, id in ipairs(seeds) do is_seed[id] = true end
|
|
338
416
|
|
|
339
417
|
-- Spine: nodes on call paths between seeds.
|
|
340
|
-
local flows, spine, on_spine = {}, {}, {}
|
|
418
|
+
local flows, spine, on_spine, flow_edges, flow_files, non_call_paths = {}, {}, {}, {}, {}, false
|
|
419
|
+
local reports = require('codeoutline.query_report')
|
|
420
|
+
local searches, missed, connected = {}, {}, {}
|
|
341
421
|
local path_limited = false
|
|
342
422
|
for _, a in ipairs(seeds) do
|
|
343
423
|
for _, b in ipairs(seeds) do
|
|
344
424
|
if a ~= b then
|
|
345
|
-
local p, limited = path_between(G, a, b, M.PATH_DEPTH)
|
|
425
|
+
local p, limited, prev, expansion_limited, hops, via = path_between(G, a, b, M.PATH_DEPTH)
|
|
346
426
|
path_limited = path_limited or limited or false
|
|
347
427
|
if p then
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
428
|
+
connected[a] = connected[a] or {}
|
|
429
|
+
connected[a][b] = true
|
|
430
|
+
local names, files = {}, {}
|
|
431
|
+
for n, id in ipairs(p) do
|
|
432
|
+
if n > 1 then
|
|
433
|
+
local kind = edge_label(hops[n - 1].kind)
|
|
434
|
+
names[#names + 1] = kind and (' -[' .. kind .. ']-> ') or ' -> '
|
|
435
|
+
non_call_paths = non_call_paths or kind ~= nil
|
|
436
|
+
end
|
|
437
|
+
names[#names + 1] = G.nodes[id].name; files[#files + 1] = G.node_file[id]
|
|
351
438
|
if not is_seed[id] and not on_spine[id] then
|
|
352
439
|
on_spine[id] = true
|
|
353
440
|
spine[#spine + 1] = id
|
|
354
441
|
end
|
|
355
442
|
end
|
|
356
|
-
flows[#flows + 1] = table.concat(names
|
|
443
|
+
flows[#flows + 1] = table.concat(names)
|
|
444
|
+
flow_edges[#flows], flow_files[#flows] = hops, files
|
|
445
|
+
else
|
|
446
|
+
if not missed[a] then
|
|
447
|
+
missed[a] = { root = a, targets = {}, limited = limited, incomplete = expansion_limited,
|
|
448
|
+
sites = reports.capture_paths(G.report, prev, a, via) }
|
|
449
|
+
searches[#searches + 1] = missed[a]
|
|
450
|
+
end
|
|
451
|
+
missed[a].targets[#missed[a].targets + 1] = b
|
|
357
452
|
end
|
|
358
453
|
end
|
|
359
454
|
end
|
|
360
455
|
end
|
|
361
456
|
|
|
362
|
-
local parts, used, omitted = {}, 0, false
|
|
363
|
-
local function emit(s)
|
|
457
|
+
local parts, dependencies, used, omitted = {}, {}, 0, false
|
|
458
|
+
local function emit(s, refs)
|
|
459
|
+
s = text.valid(s)
|
|
364
460
|
parts[#parts + 1] = s
|
|
461
|
+
dependencies[#parts] = refs or {}
|
|
365
462
|
used = used + #s + 1
|
|
366
463
|
end
|
|
464
|
+
local function prepend(s)
|
|
465
|
+
table.insert(parts, 1, s); table.insert(dependencies, 1, {})
|
|
466
|
+
end
|
|
467
|
+
local function location_refs(files) return { { at = 0, files = files } } end
|
|
468
|
+
local function emit_limited(s, limit, cut, refs)
|
|
469
|
+
local block, _, kept = text.limit(s, limit, cut)
|
|
470
|
+
local visible = {}
|
|
471
|
+
for _, ref in ipairs(refs or {}) do if ref.at < kept then visible[#visible + 1] = ref end end
|
|
472
|
+
emit(block, visible)
|
|
473
|
+
end
|
|
367
474
|
local shown, files_shown, file_order = {}, {}, {}
|
|
368
475
|
|
|
369
476
|
if #seeds == 0 and #named_files == 0 then
|
|
@@ -376,11 +483,12 @@ function M.run(G, idx, query, opts)
|
|
|
376
483
|
for _, id in ipairs(spine) do nfiles[G.node_file[id]] = true end
|
|
377
484
|
local nf = 0
|
|
378
485
|
for _ in pairs(nfiles) do nf = nf + 1 end
|
|
379
|
-
emit(string.format('Matched %d symbols in %d files, %d more on
|
|
380
|
-
#seeds, nf, #spine))
|
|
486
|
+
emit(string.format('Matched %d symbols in %d files, %d more on %s between them; short ones bring %s. Source below is verbatim with line numbers; treat it as already Read.',
|
|
487
|
+
#seeds, nf, #spine, non_call_paths and 'relationship paths' or 'call paths', non_call_paths and 'related functions' or 'their callees'))
|
|
381
488
|
if #flows > 0 then
|
|
382
|
-
emit('\n## Call paths')
|
|
383
|
-
|
|
489
|
+
emit(non_call_paths and '\n## Relationship paths' or '\n## Call paths')
|
|
490
|
+
if non_call_paths then emit('ref retains a function value; implementation, event and callback hops are static possibilities, not proof of execution.') end
|
|
491
|
+
for i = 1, math.min(#flows, M.LIST_CAP) do emit(' ' .. flows[i], location_refs(flow_files[i])) end
|
|
384
492
|
end
|
|
385
493
|
|
|
386
494
|
-- Section 2: source, grouped by file in first-appearance order.
|
|
@@ -422,34 +530,42 @@ function M.run(G, idx, query, opts)
|
|
|
422
530
|
end
|
|
423
531
|
|
|
424
532
|
if G.load_incoming then G:load_incoming(seeds) end
|
|
425
|
-
|
|
426
|
-
--
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
local source, repaired = idx:query_source(path)
|
|
440
|
-
assert(source, 'cannot read source: ' .. path)
|
|
441
|
-
changed = repaired or changed
|
|
442
|
-
end
|
|
443
|
-
if changed then return nil, { encoding_retry = true } end
|
|
444
|
-
|
|
445
|
-
local evidence_text = require('codeoutline.query_report').render(G.report, G)
|
|
533
|
+
-- Neighbors below already require these scans. Run them before diagnostics,
|
|
534
|
+
-- including for long seeds that did not take the short-wrapper context path.
|
|
535
|
+
for _, id in ipairs(seeds) do local _ = G.out[id] end
|
|
536
|
+
if #seeds == 1 then
|
|
537
|
+
searches[1] = { root = seeds[1], targets = {}, single = true,
|
|
538
|
+
sites = reports.capture_paths(G.report, { [seeds[1]] = seeds[1] }, seeds[1]) }
|
|
539
|
+
end
|
|
540
|
+
local breakpoints = reports.path_breakpoints(G.report, G, searches, connected)
|
|
541
|
+
local candidates = G:definition_candidates()
|
|
542
|
+
G.stats.definition_candidates = candidates.stats
|
|
543
|
+
|
|
544
|
+
-- Build output as a transaction. Check rendered locations before returning;
|
|
545
|
+
-- an encoding repair aborts immediately and retries with fresh node IDs.
|
|
546
|
+
local evidence_text, evidence_refs = reports.render(G.report, G)
|
|
446
547
|
local evidence_budget = math.min(4096, math.floor(budget / 4))
|
|
548
|
+
local breakpoint_text, breakpoint_refs = reports.render_breakpoints(breakpoints, G)
|
|
549
|
+
local breakpoint_budget = breakpoint_text and math.floor(evidence_budget / 2) or 0
|
|
550
|
+
evidence_budget = evidence_budget - breakpoint_budget
|
|
551
|
+
local breakpoint_cut = breakpoint_text and (#breakpoint_text > breakpoint_budget or breakpoints.truncated) or false
|
|
552
|
+
if breakpoint_budget >= 256 then emit_limited(breakpoint_text, breakpoint_budget, breakpoints.truncated, breakpoint_refs)
|
|
553
|
+
elseif breakpoint_text then breakpoint_cut = true end
|
|
554
|
+
omitted = omitted or breakpoint_cut
|
|
447
555
|
local evidence_cut = #evidence_text > evidence_budget
|
|
448
556
|
if evidence_budget >= 256 then
|
|
449
|
-
|
|
557
|
+
emit_limited(evidence_text, evidence_budget, G.report.truncated, evidence_refs)
|
|
450
558
|
else evidence_cut = #G.report.entries > 0 end
|
|
451
559
|
omitted = omitted or evidence_cut or G.report.truncated or #flows > M.LIST_CAP
|
|
452
560
|
|
|
561
|
+
local candidate_budget = math.min(3072, math.floor(budget / 5))
|
|
562
|
+
local candidate_block, candidate_refs
|
|
563
|
+
if candidate_budget >= 256 then candidate_block, candidate_refs = candidate_text(G, idx, candidates, in_order) end
|
|
564
|
+
local candidate_cut = candidate_block and (#candidate_block > candidate_budget or candidates.truncated) or candidates.truncated
|
|
565
|
+
if candidate_block then emit_limited(candidate_block, candidate_budget, candidates.truncated, candidate_refs)
|
|
566
|
+
elseif #candidates.entries > 0 then candidate_cut = true end
|
|
567
|
+
omitted = omitted or candidate_cut
|
|
568
|
+
|
|
453
569
|
local reserve = math.floor(budget * 0.15) -- keep room for sections 3-4
|
|
454
570
|
for _, f in ipairs(file_order) do
|
|
455
571
|
local rec = G.files[f]
|
|
@@ -457,30 +573,32 @@ function M.run(G, idx, query, opts)
|
|
|
457
573
|
local items = by_file[f]
|
|
458
574
|
table.sort(items, function(a, b) return G.nodes[a.id].line < G.nodes[b.id].line end)
|
|
459
575
|
local wrote_header = false
|
|
460
|
-
if items.outline then
|
|
576
|
+
if items.outline and used + #header + 16 < budget - reserve then
|
|
577
|
+
checked_source(idx, rec.path)
|
|
461
578
|
local ol = {}
|
|
462
579
|
for _, node in ipairs(rec.nodes) do
|
|
463
|
-
if not node.parent and node.kind ~= 'macro' then
|
|
464
|
-
ol[#ol + 1] = string.format('%d\t%s %s', node.line, node.kind, node.sig or node.name)
|
|
580
|
+
if not node.parent and node.kind ~= 'macro' and require('codeoutline.query_filters').node(filters, rec, node) then
|
|
581
|
+
ol[#ol + 1] = string.format('%d\t%s %s', node.line, node.kind, require('codeoutline.navigation').detail(G, f, node).sig or node.name)
|
|
465
582
|
end
|
|
466
583
|
if #ol >= 60 then ol[#ol + 1] = '\t...'; break end
|
|
467
584
|
end
|
|
468
585
|
local block = header .. ' (outline)\n' .. table.concat(ol, '\n')
|
|
469
|
-
if used + #block < budget - reserve then emit(block); wrote_header = true else omitted = true end
|
|
470
|
-
end
|
|
586
|
+
if used + #block < budget - reserve then emit(block, location_refs({ f })); wrote_header = true else omitted = true end
|
|
587
|
+
elseif items.outline then omitted = true end
|
|
471
588
|
for _, item in ipairs(items) do
|
|
472
|
-
if not shown[item.id] then
|
|
589
|
+
if not shown[item.id] and used + #header + 16 < budget - reserve then
|
|
473
590
|
local block, source_cut = node_block(G, idx, item.id, item.full)
|
|
474
591
|
omitted = omitted or source_cut
|
|
475
592
|
local need = #block + (wrote_header and 0 or #header + 1) + 1
|
|
476
593
|
if used + need < budget - reserve then
|
|
477
|
-
if not wrote_header then emit(header); wrote_header = true end
|
|
478
|
-
emit(block)
|
|
594
|
+
if not wrote_header then emit(header, location_refs({ f })); wrote_header = true end
|
|
595
|
+
emit(block, location_refs({ f }))
|
|
479
596
|
shown[item.id] = true
|
|
480
597
|
files_shown[f] = true
|
|
481
598
|
else
|
|
482
599
|
pointers[#pointers + 1] = item.id
|
|
483
600
|
end
|
|
601
|
+
elseif not shown[item.id] then pointers[#pointers + 1] = item.id
|
|
484
602
|
end
|
|
485
603
|
end
|
|
486
604
|
end
|
|
@@ -490,69 +608,106 @@ function M.run(G, idx, query, opts)
|
|
|
490
608
|
for _, id in ipairs(seeds) do
|
|
491
609
|
local callers, callees = {}, {}
|
|
492
610
|
local seen_in, seen_out = {}, {}
|
|
611
|
+
local caller_files, callee_files, incoming_special, outgoing_special = {}, {}, false, false
|
|
493
612
|
local inn, out = G.inn[id] or {}, G.out[id] or {}
|
|
494
613
|
for i = 1, #inn, graph.EDGE do
|
|
495
614
|
local src = inn[i]
|
|
496
|
-
|
|
497
|
-
|
|
615
|
+
local tag, key = edge_label(inn[i + 2]), src .. ':' .. inn[i + 2]
|
|
616
|
+
if not seen_in[key] and #callers < M.LIST_CAP then
|
|
617
|
+
seen_in[key] = true; caller_files[#caller_files + 1] = G.node_file[src]
|
|
618
|
+
incoming_special = incoming_special or tag ~= nil
|
|
498
619
|
callers[#callers + 1] = string.format('%s (%s:%d)', G.nodes[src].name, G.files[G.node_file[src]].path, inn[i + 1])
|
|
499
|
-
.. (
|
|
500
|
-
elseif not seen_in[
|
|
620
|
+
.. (tag and (' [' .. tag .. ']') or '')
|
|
621
|
+
elseif not seen_in[key] then omitted = true
|
|
501
622
|
end
|
|
502
623
|
end
|
|
503
624
|
for i = 1, #out, graph.EDGE do
|
|
504
625
|
local dst = out[i]
|
|
505
|
-
|
|
506
|
-
|
|
626
|
+
local tag, key = edge_label(out[i + 2]), dst .. ':' .. out[i + 2]
|
|
627
|
+
if not seen_out[key] and #callees < M.LIST_CAP then
|
|
628
|
+
seen_out[key] = true; callee_files[#callee_files + 1] = G.node_file[dst]
|
|
629
|
+
outgoing_special = outgoing_special or tag ~= nil
|
|
507
630
|
callees[#callees + 1] = G.nodes[dst].name .. ' (' .. graph.where(G, dst) .. ')'
|
|
508
|
-
.. (
|
|
509
|
-
elseif not seen_out[
|
|
631
|
+
.. (tag and (' [' .. tag .. ']') or '')
|
|
632
|
+
elseif not seen_out[key] then omitted = true
|
|
510
633
|
end
|
|
511
634
|
end
|
|
512
635
|
if #callers > 0 or #callees > 0 then
|
|
513
636
|
local nsites = math.floor(#inn / graph.EDGE)
|
|
514
|
-
rel[#rel + 1] =
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
#
|
|
637
|
+
rel[#rel + 1] = { line = G.nodes[id].qualified .. ':', files = { G.node_file[id] } }
|
|
638
|
+
rel[#rel + 1] = { line = string.format(' %s%s: %s', incoming_special and 'incoming relationships' or 'called by',
|
|
639
|
+
nsites > #callers and string.format(incoming_special and ' (%d sites)' or ' (%d call sites)', nsites) or '',
|
|
640
|
+
#callers > 0 and table.concat(callers, ', ') or '-'), files = caller_files }
|
|
641
|
+
rel[#rel + 1] = { line = ' ' .. (outgoing_special and 'outgoing relationships' or 'calls') .. ': '
|
|
642
|
+
.. (#callees > 0 and table.concat(callees, ', ') or '-'), files = callee_files }
|
|
518
643
|
end
|
|
519
644
|
end
|
|
520
645
|
if #rel > 0 then
|
|
521
|
-
|
|
522
|
-
emit(
|
|
646
|
+
emit('\n## Callers / callees')
|
|
647
|
+
for _, entry in ipairs(rel) do emit(entry.line, location_refs(entry.files)) end
|
|
523
648
|
end
|
|
524
649
|
|
|
525
650
|
-- Section 4: pointers for everything that matched but was not shown.
|
|
526
651
|
local more = {}
|
|
527
|
-
for _, id in ipairs(pointers) do more[#more + 1] =
|
|
652
|
+
for _, id in ipairs(pointers) do if #more < 15 then more[#more + 1] = id end end
|
|
528
653
|
local extra = 0
|
|
529
654
|
for _, c in ipairs(ranked) do
|
|
530
655
|
if not shown[c.id] and not is_seed[c.id] then
|
|
531
656
|
extra = extra + 1
|
|
532
|
-
if #more < 15 then more[#more + 1] =
|
|
657
|
+
if #more < 15 then more[#more + 1] = c.id end
|
|
533
658
|
end
|
|
534
659
|
end
|
|
535
660
|
if #more > 0 then
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
if
|
|
661
|
+
emit('\n## Not shown (explore these by name for their source)')
|
|
662
|
+
for _, id in ipairs(more) do emit(' ' .. label(G, id), location_refs({ G.node_file[id] })) end
|
|
663
|
+
if extra + #pointers > #more then emit(string.format(' ... %d more', extra + #pointers - #more)) end
|
|
539
664
|
end
|
|
540
665
|
|
|
541
666
|
if G.incomplete then
|
|
542
|
-
|
|
543
|
-
|
|
667
|
+
local reasons = require('codeoutline.coverage').relations({ relationships_incomplete = true, query_stats = G.stats })
|
|
668
|
+
prepend('Relationships incomplete: ' .. table.concat(reasons, ', ') .. '.')
|
|
544
669
|
end
|
|
545
670
|
if path_limited then
|
|
546
|
-
|
|
671
|
+
prepend('Call-path search reached its depth/frontier limit; no path found is not proof of no runtime connection.')
|
|
547
672
|
end
|
|
548
673
|
if evidence_cut or G.report.truncated then
|
|
549
|
-
|
|
674
|
+
prepend('Relationship explanations omitted due to evidence/output limits.')
|
|
675
|
+
end
|
|
676
|
+
if breakpoint_cut then
|
|
677
|
+
prepend('Call-path breakpoint explanations omitted due to site/evidence/output limits.')
|
|
678
|
+
end
|
|
679
|
+
if filters.seed_limit_reached then prepend('Seed selection stopped after 512 matching candidates; narrow the query filters.') end
|
|
680
|
+
if seed_selection_limited then prepend('Starting-symbol selection limited to eight symbols and three definitions per name; refine name/path filters for other matches.') end
|
|
681
|
+
if candidate_cut then prepend('Unconfirmed definition candidates were limited or omitted; they are not call edges.') end
|
|
682
|
+
local result, truncated, kept = text.limit(table.concat(parts, '\n'), budget, omitted or #pointers > 0)
|
|
683
|
+
-- Validate locations retained by section budgets and the final byte cut.
|
|
684
|
+
-- Encoding repair aborts this transaction before any text is returned.
|
|
685
|
+
local selected, offset = {}, 0
|
|
686
|
+
for i, part in ipairs(parts) do
|
|
687
|
+
if offset >= kept then break end
|
|
688
|
+
for _, ref in ipairs(dependencies[i]) do
|
|
689
|
+
if offset + ref.at < kept then for _, f in ipairs(ref.files) do selected[f] = true end end
|
|
690
|
+
end
|
|
691
|
+
offset = offset + #part + 1
|
|
550
692
|
end
|
|
551
|
-
|
|
552
|
-
|
|
693
|
+
for f in pairs(selected) do checked_source(idx, G.files[f].path) end
|
|
694
|
+
local source_files = 0; for _ in pairs(source_cache) do source_files = source_files + 1 end
|
|
695
|
+
G.stats.sources = { files = source_files }
|
|
696
|
+
return result, { seeds = seeds, spine = spine, shown = shown, flows = flows, flow_edges = flow_edges, truncated = truncated,
|
|
553
697
|
relationships_incomplete = G.incomplete or false, query_stats = G.stats,
|
|
698
|
+
seed_limit_reached = filters.seed_limit_reached or false,
|
|
699
|
+
seed_selection_limited = seed_selection_limited,
|
|
554
700
|
evidence = G.report.entries, evidence_truncated = evidence_cut or G.report.truncated,
|
|
555
|
-
|
|
701
|
+
unresolved_candidates = candidates.entries, unresolved_candidates_truncated = candidate_cut or false,
|
|
702
|
+
path_search_limited = path_limited, evidence_scope = G.report.scope,
|
|
703
|
+
path_breakpoints = breakpoints.entries, path_breakpoints_truncated = breakpoint_cut }
|
|
704
|
+
end
|
|
705
|
+
|
|
706
|
+
function M.run(...)
|
|
707
|
+
local ok, output, info = pcall(run, ...)
|
|
708
|
+
if not ok and output == encoding_retry then return nil, { encoding_retry = true } end
|
|
709
|
+
if not ok then error(output, 0) end
|
|
710
|
+
return output, info
|
|
556
711
|
end
|
|
557
712
|
|
|
558
713
|
return M
|