@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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
-- Query-only verification of base syntax: compact parser headers erase generics.
|
|
2
|
+
local M = {}
|
|
3
|
+
|
|
4
|
+
function M.collect(T, n, language)
|
|
5
|
+
local ni
|
|
6
|
+
for i = n.ti, n.tj do
|
|
7
|
+
local s = T:text(i)
|
|
8
|
+
if s == '<' or s == '>' then return nil end
|
|
9
|
+
if T.k[i] == 'id' and s == n.name then ni = i; break end
|
|
10
|
+
if s == '{' then return nil end
|
|
11
|
+
end
|
|
12
|
+
if not ni then return nil end
|
|
13
|
+
local result, words, mode = {}, {}, nil
|
|
14
|
+
local separator = language == 'cpp' and '::' or '.'
|
|
15
|
+
local function flush()
|
|
16
|
+
if #words == 0 then return false end
|
|
17
|
+
local written = table.concat(words)
|
|
18
|
+
local normalized = written:gsub('^::', '')
|
|
19
|
+
if language == 'csharp' then normalized = normalized:gsub('^global::', '') end
|
|
20
|
+
local pattern = separator == '.' and '^[%a_$][%w_$]*[%.%w_$]*$' or '^[%a_][%w_:]*$'
|
|
21
|
+
if not normalized:match(pattern) or normalized:match('[%.:]$') then return false end
|
|
22
|
+
result[#result + 1] = { written = written, kind = mode ~= 'base' and mode or nil }
|
|
23
|
+
words = {}; return true
|
|
24
|
+
end
|
|
25
|
+
local i = ni + 1
|
|
26
|
+
while i <= n.tj do
|
|
27
|
+
local s = T:text(i)
|
|
28
|
+
if s == '{' or s == ';' or s == 'where' or s == 'permits' then break end
|
|
29
|
+
if s == '<' or s == '>' then return nil end
|
|
30
|
+
if s == ':' and not mode then mode = 'base'
|
|
31
|
+
elseif s == 'extends' or s == 'implements' then
|
|
32
|
+
if #words > 0 and not flush() then return nil end
|
|
33
|
+
mode = s
|
|
34
|
+
elseif s == '(' and T.m[i] then
|
|
35
|
+
if mode then
|
|
36
|
+
if language ~= 'kotlin' or #words == 0 then return nil end
|
|
37
|
+
elseif language ~= 'kotlin' and language ~= 'csharp' and not (language == 'java' and n.kind == 'record') then return nil end
|
|
38
|
+
i = T.m[i]
|
|
39
|
+
elseif mode then
|
|
40
|
+
if s == ',' then
|
|
41
|
+
if not flush() then return nil end
|
|
42
|
+
elseif language == 'cpp' and (s == 'public' or s == 'protected' or s == 'private' or s == 'virtual') then
|
|
43
|
+
if #words > 0 then return nil end
|
|
44
|
+
elseif s == separator or language == 'csharp' and s == '::' then
|
|
45
|
+
if #words == 0 and not (language == 'cpp' and s == '::') then return nil end
|
|
46
|
+
words[#words + 1] = s
|
|
47
|
+
elseif T.k[i] == 'id' then
|
|
48
|
+
-- Adjacent names (TS factory expressions, Kotlin delegation, etc.)
|
|
49
|
+
-- are not a named base. Never discard the intervening syntax.
|
|
50
|
+
if #words > 0 and words[#words] ~= separator and words[#words] ~= '::' then return nil end
|
|
51
|
+
words[#words + 1] = s
|
|
52
|
+
else return nil end
|
|
53
|
+
elseif s ~= 'final' and s ~= 'sealed' and s ~= 'constructor'
|
|
54
|
+
and s ~= 'public' and s ~= 'private' and s ~= 'protected' and s ~= 'internal' then return nil end
|
|
55
|
+
i = i + 1
|
|
56
|
+
end
|
|
57
|
+
if #words > 0 and not flush() then return nil end
|
|
58
|
+
return result
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
return M
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
-- Declared type relationships over resident headers, resolved only for this query.
|
|
2
|
+
local M = { MAX_CANDIDATES = 512, MAX_SCAN_NODES = 1000000, MAX_FILES = 128,
|
|
3
|
+
MAX_BYTES = 8 * 1024 * 1024, MAX_BASES = 64, MAX_EDGES = 4096 }
|
|
4
|
+
local graph = require('codeoutline.graph')
|
|
5
|
+
local control = require('codeoutline.control')
|
|
6
|
+
local kinds = { class = true, interface = true, struct = true, record = true }
|
|
7
|
+
local languages = { csharp = true, java = true, kotlin = true, typescript = true, cpp = true }
|
|
8
|
+
|
|
9
|
+
function M.validate(query, opts)
|
|
10
|
+
local budget = require('codeoutline.explore').validate(query, opts)
|
|
11
|
+
assert(require('codeoutline.query_filters').parse(query).text ~= '', 'type hierarchy requires an exact type name in addition to filters')
|
|
12
|
+
opts = opts or {}
|
|
13
|
+
for _, item in ipairs({ { 'depth', 8, 32 }, { 'max_nodes', 200, 2000 } }) do
|
|
14
|
+
local value = opts[item[1]]
|
|
15
|
+
if value == nil then value = item[2] end
|
|
16
|
+
assert(type(value) == 'number' and value % 1 == 0 and value >= 1 and value <= item[3],
|
|
17
|
+
item[1] .. ' must be an integer between 1 and ' .. item[3])
|
|
18
|
+
end
|
|
19
|
+
assert(opts.direction == nil or opts.direction == 'ancestors' or opts.direction == 'descendants' or opts.direction == 'both',
|
|
20
|
+
'direction must be ancestors, descendants or both')
|
|
21
|
+
return budget
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
local function bases(n)
|
|
25
|
+
local out = {}
|
|
26
|
+
for _, value in ipairs(n.bases or {}) do out[#out + 1] = { written = value } end
|
|
27
|
+
for _, value in ipairs(n.extends or {}) do out[#out + 1] = { written = value, kind = 'extends' } end
|
|
28
|
+
for _, value in ipairs(n.implements or {}) do out[#out + 1] = { written = value, kind = 'implements' } end
|
|
29
|
+
return out
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
local function run(G, idx, query, opts, retry)
|
|
33
|
+
local budget = M.validate(query, opts)
|
|
34
|
+
local depth, cap, direction = opts.depth or 8, opts.max_nodes or 200, opts.direction or 'both'
|
|
35
|
+
local result = { targets = {}, ancestors = {}, descendants = {}, unresolved = {}, edges = {},
|
|
36
|
+
depth = depth, direction = direction, node_limit_reached = false, depth_limit_reached = false,
|
|
37
|
+
relationships_incomplete = false, cycle_detected = false,
|
|
38
|
+
query_stats = { scanned_nodes = 0, candidates = 0, source_files = 0, source_bytes = 0, reverse_unresolved = 0 } }
|
|
39
|
+
local stats, limited = result.query_stats, {}
|
|
40
|
+
local ctx = require('codeoutline.js_resolution').context(G)
|
|
41
|
+
ctx.include_paths = opts.include_paths
|
|
42
|
+
local loaded, summaries, parents, issues = {}, {}, {}, {}
|
|
43
|
+
local function source(f)
|
|
44
|
+
if not loaded[f] then
|
|
45
|
+
if stats.source_files >= M.MAX_FILES or stats.source_bytes + (G.files[f].size or 0) > M.MAX_BYTES then
|
|
46
|
+
result.candidate_limit_reached = true; error(limited, 0)
|
|
47
|
+
end
|
|
48
|
+
loaded[f] = true
|
|
49
|
+
stats.source_files = stats.source_files + 1
|
|
50
|
+
stats.source_bytes = stats.source_bytes + (G.files[f].size or 0)
|
|
51
|
+
end
|
|
52
|
+
if idx then
|
|
53
|
+
local path = G.files[f].path
|
|
54
|
+
local raw, repaired = idx:query_source(path)
|
|
55
|
+
if repaired then error(retry, 0) end
|
|
56
|
+
assert(raw, 'cannot read source: ' .. path)
|
|
57
|
+
return raw
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
ctx.ordinary = require('codeoutline.ordinary_bindings').context(G, ctx,
|
|
61
|
+
(idx or G.root) and function(f)
|
|
62
|
+
if idx then return source(f) end
|
|
63
|
+
source(f) -- enforce the same budget for direct graph embeddings
|
|
64
|
+
end or nil)
|
|
65
|
+
stats.ordinary = ctx.ordinary.stats
|
|
66
|
+
local function guard(fn)
|
|
67
|
+
local ok, value = pcall(fn)
|
|
68
|
+
if ok then return value end
|
|
69
|
+
if value ~= limited then error(value, 0) end
|
|
70
|
+
end
|
|
71
|
+
local function data(f)
|
|
72
|
+
if not summaries[f] then
|
|
73
|
+
if not idx and not G.root then source(f) end
|
|
74
|
+
local d = ctx.ordinary.hierarchy(f)
|
|
75
|
+
-- Share the source FIFO; retain only bounded declaration and alias summaries.
|
|
76
|
+
local evidence = {}
|
|
77
|
+
for i, n in ipairs(G.files[f].nodes) do
|
|
78
|
+
if kinds[n.kind] then evidence[i] = (d.implementation_evidence or {})[i] end
|
|
79
|
+
end
|
|
80
|
+
summaries[f] = { evidence = evidence, aliases = d.cpp_aliases or {} }
|
|
81
|
+
end
|
|
82
|
+
return summaries[f]
|
|
83
|
+
end
|
|
84
|
+
local function describe(id)
|
|
85
|
+
local n, f = G.nodes[id], G.node_file[id]
|
|
86
|
+
return { id = id, name = n.qualified, kind = n.kind, language = G.files[f].language,
|
|
87
|
+
file = G.files[f].path, line = n.line }
|
|
88
|
+
end
|
|
89
|
+
local function info(id)
|
|
90
|
+
local f = G.node_file[id]
|
|
91
|
+
return data(f).evidence[id - G.id_of[f][1] + 1]
|
|
92
|
+
end
|
|
93
|
+
local function supported(id)
|
|
94
|
+
return kinds[G.nodes[id].kind] and languages[G.files[G.node_file[id]].language]
|
|
95
|
+
end
|
|
96
|
+
local function direct(id)
|
|
97
|
+
if parents[id] then return parents[id] end
|
|
98
|
+
local out, missing, seen = {}, {}, {}
|
|
99
|
+
parents[id], issues[id] = out, missing
|
|
100
|
+
local n, f = G.nodes[id], G.node_file[id]
|
|
101
|
+
local language, declared = G.files[f].language, bases(n)
|
|
102
|
+
local ok = guard(function()
|
|
103
|
+
local evidence = info(id)
|
|
104
|
+
-- Existing parsers erase generic arguments from resident base names.
|
|
105
|
+
-- Never turn that erasure into a non-generic relationship.
|
|
106
|
+
if #declared > 0 and (not evidence or not evidence.hierarchy_bases or evidence.generic or evidence.unsupported
|
|
107
|
+
or language == 'typescript' and (n.parent or evidence.declare)) then
|
|
108
|
+
for index, base in ipairs(declared) do
|
|
109
|
+
if index > M.MAX_BASES then result.candidate_limit_reached = true; break end
|
|
110
|
+
missing[#missing + 1] = { written = base.written, reason = 'unsupported declaration' }
|
|
111
|
+
end
|
|
112
|
+
return true
|
|
113
|
+
end
|
|
114
|
+
declared = evidence and evidence.hierarchy_bases or declared
|
|
115
|
+
for index, base in ipairs(declared) do
|
|
116
|
+
control.check()
|
|
117
|
+
if index > M.MAX_BASES then
|
|
118
|
+
result.candidate_limit_reached = true
|
|
119
|
+
missing[#missing + 1] = { reason = 'base limit reached' }; break
|
|
120
|
+
end
|
|
121
|
+
local ids
|
|
122
|
+
if language == 'cpp' then
|
|
123
|
+
ids = require('codeoutline.cpp_types').resolve(G, f, base.written, {
|
|
124
|
+
context = ctx, scope = n.qualified, at = evidence.at, accept = kinds,
|
|
125
|
+
undecorated = true, definitions = true, aliases = function(g) return data(g).aliases end })
|
|
126
|
+
else
|
|
127
|
+
ids = require('codeoutline.implementations').types(G, f, base.written, ctx, n.qualified, evidence.at)
|
|
128
|
+
end
|
|
129
|
+
if #ids == 1 and supported(ids[1]) then
|
|
130
|
+
local parent = ids[1]
|
|
131
|
+
if not seen[parent] then
|
|
132
|
+
seen[parent] = true
|
|
133
|
+
local kind = base.kind or (G.nodes[parent].kind == 'interface'
|
|
134
|
+
and n.kind ~= 'interface' and 'implements' or 'extends')
|
|
135
|
+
out[#out + 1] = { source = id, target = parent, written = base.written,
|
|
136
|
+
kind = kind, file = G.files[f].path, line = n.line }
|
|
137
|
+
end
|
|
138
|
+
else
|
|
139
|
+
missing[#missing + 1] = { written = base.written, reason = #ids > 1 and 'ambiguous type' or 'unresolved type' }
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
return true
|
|
143
|
+
end)
|
|
144
|
+
if not ok then
|
|
145
|
+
-- A resolver interrupted by a budget must not publish partial guesses.
|
|
146
|
+
out = {}; parents[id] = out
|
|
147
|
+
missing[#missing + 1] = { reason = 'source budget reached' }
|
|
148
|
+
end
|
|
149
|
+
if ctx.include_incomplete then
|
|
150
|
+
result.candidate_limit_reached = true
|
|
151
|
+
out = {}; parents[id] = out
|
|
152
|
+
missing[#missing + 1] = { reason = 'include visibility budget reached' }
|
|
153
|
+
end
|
|
154
|
+
table.sort(out, function(a, b) return graph.before(G, a.target, b.target) end)
|
|
155
|
+
return out
|
|
156
|
+
end
|
|
157
|
+
local ordered = {}
|
|
158
|
+
local filters = require('codeoutline.query_filters').parse(query)
|
|
159
|
+
for i, id in ipairs(G.by_qualified[filters.text] or G.by_name[filters.text] or {}) do
|
|
160
|
+
if i % 256 == 0 then control.check() end
|
|
161
|
+
if supported(id) and not G.nodes[id].decl and require('codeoutline.query_filters').id(filters, G, id) then
|
|
162
|
+
if #ordered >= cap then result.node_limit_reached = true; break end
|
|
163
|
+
ordered[#ordered + 1] = id
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
table.sort(ordered, function(a, b) return graph.before(G, a, b) end)
|
|
167
|
+
local seeds, total, seed_names, seed_languages = {}, 0, {}, {}
|
|
168
|
+
for _, id in ipairs(ordered) do
|
|
169
|
+
if total >= cap then result.node_limit_reached = true; break end
|
|
170
|
+
if guard(function() info(id); return true end) then
|
|
171
|
+
seeds[#seeds + 1] = id; result.targets[#result.targets + 1] = describe(id); total = total + 1
|
|
172
|
+
seed_names[G.nodes[id].name], seed_languages[G.files[G.node_file[id]].language] = true, true
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
local reported, edge_seen = {}, {}
|
|
176
|
+
local function report(id)
|
|
177
|
+
if reported[id] then return end
|
|
178
|
+
reported[id] = true
|
|
179
|
+
for _, issue in ipairs(issues[id] or {}) do
|
|
180
|
+
local entry = describe(id); entry.written, entry.reason = issue.written, issue.reason
|
|
181
|
+
result.unresolved[#result.unresolved + 1] = entry
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
local reverse
|
|
185
|
+
local function descendants()
|
|
186
|
+
if reverse then return reverse end
|
|
187
|
+
reverse = {}
|
|
188
|
+
-- No parallel resident index: scan compact declarations, never project source.
|
|
189
|
+
-- Prefer literal base-name matches, then examine other declarations for aliases.
|
|
190
|
+
local preferred, other, count, stop = {}, {}, 0, false
|
|
191
|
+
for _, f in ipairs(G.file_order) do
|
|
192
|
+
if stop then break end
|
|
193
|
+
if seed_languages[G.files[f].language] then
|
|
194
|
+
for _, id in ipairs(G.id_of[f]) do
|
|
195
|
+
stats.scanned_nodes = stats.scanned_nodes + 1
|
|
196
|
+
if stats.scanned_nodes % 1024 == 0 then control.check() end
|
|
197
|
+
if stats.scanned_nodes > M.MAX_SCAN_NODES then result.candidate_limit_reached = true; stop = true; break end
|
|
198
|
+
if supported(id) then
|
|
199
|
+
local list = bases(G.nodes[id])
|
|
200
|
+
if #list > 0 then
|
|
201
|
+
count = count + 1
|
|
202
|
+
local priority = false
|
|
203
|
+
for _, base in ipairs(list) do
|
|
204
|
+
if seed_names[base.written:match('([%w_$]+)$')] then priority = true end
|
|
205
|
+
end
|
|
206
|
+
local bucket = priority and preferred or other
|
|
207
|
+
if #bucket < M.MAX_CANDIDATES then bucket[#bucket + 1] = id end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
if count > M.MAX_CANDIDATES then result.candidate_limit_reached = true end
|
|
214
|
+
for _, bucket in ipairs({ preferred, other }) do
|
|
215
|
+
for _, id in ipairs(bucket) do
|
|
216
|
+
if stats.candidates >= M.MAX_CANDIDATES then break end
|
|
217
|
+
control.check(); stats.candidates = stats.candidates + 1
|
|
218
|
+
for _, edge in ipairs(direct(id)) do
|
|
219
|
+
reverse[edge.target] = reverse[edge.target] or {}
|
|
220
|
+
reverse[edge.target][#reverse[edge.target] + 1] = edge
|
|
221
|
+
end
|
|
222
|
+
if #issues[id] > 0 then stats.reverse_unresolved = stats.reverse_unresolved + 1 end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
for _, list in pairs(reverse) do table.sort(list, function(a, b) return graph.before(G, a.source, b.source) end) end
|
|
226
|
+
return reverse
|
|
227
|
+
end
|
|
228
|
+
local function walk(up, entries)
|
|
229
|
+
local seen, paths, frontier = {}, {}, {}
|
|
230
|
+
for _, id in ipairs(seeds) do seen[id], paths[id] = true, { id }; frontier[#frontier + 1] = id end
|
|
231
|
+
for level = 0, depth do
|
|
232
|
+
local next_level = {}
|
|
233
|
+
for _, id in ipairs(frontier) do
|
|
234
|
+
control.check()
|
|
235
|
+
local list = up and direct(id) or descendants()[id] or {}
|
|
236
|
+
if up then report(id) end
|
|
237
|
+
for _, edge in ipairs(list) do
|
|
238
|
+
local target = up and edge.target or edge.source
|
|
239
|
+
if not seen[target] then
|
|
240
|
+
if level == depth then result.depth_limit_reached = true
|
|
241
|
+
elseif total >= cap then result.node_limit_reached = true
|
|
242
|
+
elseif guard(function() info(target); return true end) then
|
|
243
|
+
seen[target], total = true, total + 1
|
|
244
|
+
local path = {}; for _, step in ipairs(paths[id]) do path[#path + 1] = step end
|
|
245
|
+
path[#path + 1] = target; paths[target] = path
|
|
246
|
+
local entry = describe(target); entry.depth, entry.path, entry.via = level + 1, {}, edge
|
|
247
|
+
for _, step in ipairs(path) do entry.path[#entry.path + 1] = describe(step) end
|
|
248
|
+
entries[#entries + 1] = entry; next_level[#next_level + 1] = target
|
|
249
|
+
if not up then report(target) end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
if seen[target] then
|
|
253
|
+
local key = edge.source .. ':' .. edge.target
|
|
254
|
+
if not edge_seen[key] then
|
|
255
|
+
if #result.edges >= M.MAX_EDGES then result.candidate_limit_reached = true
|
|
256
|
+
else edge_seen[key] = true; result.edges[#result.edges + 1] = edge end
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
frontier = next_level
|
|
262
|
+
if #frontier == 0 then break end
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
if #seeds > 0 then
|
|
266
|
+
if direction ~= 'descendants' then walk(true, result.ancestors) end
|
|
267
|
+
if direction ~= 'ancestors' then walk(false, result.descendants) end
|
|
268
|
+
end
|
|
269
|
+
-- Check only returned relationships; diamonds are not cycles.
|
|
270
|
+
local adjacency, colors = {}, {}
|
|
271
|
+
for _, edge in ipairs(result.edges) do
|
|
272
|
+
adjacency[edge.source] = adjacency[edge.source] or {}; table.insert(adjacency[edge.source], edge.target)
|
|
273
|
+
end
|
|
274
|
+
local function visit(id)
|
|
275
|
+
control.check()
|
|
276
|
+
if colors[id] == 1 then result.cycle_detected = true; return end
|
|
277
|
+
if colors[id] then return end
|
|
278
|
+
colors[id] = 1
|
|
279
|
+
for _, parent in ipairs(adjacency[id] or {}) do visit(parent) end
|
|
280
|
+
colors[id] = 2
|
|
281
|
+
end
|
|
282
|
+
for id in pairs(adjacency) do visit(id) end
|
|
283
|
+
result.relationships_incomplete = result.candidate_limit_reached or result.node_limit_reached or result.depth_limit_reached
|
|
284
|
+
or result.cycle_detected or #result.unresolved > 0 or stats.reverse_unresolved > 0 or false
|
|
285
|
+
local lines = { string.format('Matched %d type(s); %d ancestors, %d descendants.', #seeds, #result.ancestors, #result.descendants),
|
|
286
|
+
'Declared type relationships only; no structural compatibility, runtime dispatch or implicit library bases are inferred.' }
|
|
287
|
+
if #seeds == 0 then lines[#lines + 1] = 'No supported type matched; use an exact type name or qualified name (C#, Java, Kotlin, TS, C++).' end
|
|
288
|
+
if #seeds > 1 then lines[#lines + 1] = 'Multiple declarations matched; relationships cover the listed targets.' end
|
|
289
|
+
if result.node_limit_reached then lines[#lines + 1] = 'Node limit reached; some types were omitted.' end
|
|
290
|
+
if result.depth_limit_reached then lines[#lines + 1] = 'Depth limit reached; deeper types were omitted.' end
|
|
291
|
+
if result.candidate_limit_reached then lines[#lines + 1] = 'Candidate/source budget reached; relationships are incomplete.' end
|
|
292
|
+
if result.cycle_detected then lines[#lines + 1] = 'Inheritance cycle detected; relationships are incomplete.' end
|
|
293
|
+
if stats.reverse_unresolved > 0 then lines[#lines + 1] = string.format('%d reverse candidate(s) had unresolved/unsupported bases; descendants may be incomplete.', stats.reverse_unresolved) end
|
|
294
|
+
for _, target in ipairs(result.targets) do lines[#lines + 1] = string.format('Target: %s (%s:%d)', target.name, target.file, target.line) end
|
|
295
|
+
for _, group in ipairs({ { 'Ancestor', result.ancestors }, { 'Descendant', result.descendants } }) do
|
|
296
|
+
for _, entry in ipairs(group[2]) do
|
|
297
|
+
local path = {}; for _, step in ipairs(entry.path) do path[#path + 1] = step.name end
|
|
298
|
+
local edge = entry.via
|
|
299
|
+
lines[#lines + 1] = string.format('%s depth %d: %s (%s:%d); path %s; declared %s %s at %s:%d',
|
|
300
|
+
group[1], entry.depth, entry.name, entry.file, entry.line, table.concat(path, ' -> '),
|
|
301
|
+
edge.kind, edge.written, edge.file, edge.line)
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
for _, entry in ipairs(result.unresolved) do
|
|
305
|
+
lines[#lines + 1] = string.format('Unresolved: %s -> %s (%s:%d): %s', entry.name,
|
|
306
|
+
entry.written or '?', entry.file, entry.line, entry.reason)
|
|
307
|
+
end
|
|
308
|
+
local output, cut = require('codeoutline.text').limit(table.concat(lines, '\n'), budget)
|
|
309
|
+
result.truncated = cut
|
|
310
|
+
return output, result
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
function M.run(G, idx, query, opts)
|
|
314
|
+
M.validate(query, opts)
|
|
315
|
+
local retry = {}
|
|
316
|
+
local ok, output, result = pcall(run, G, idx, query, opts or {}, retry)
|
|
317
|
+
if not ok then
|
|
318
|
+
if output == retry then return nil, { encoding_retry = true } end
|
|
319
|
+
error(output, 0)
|
|
320
|
+
end
|
|
321
|
+
return output, result
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
return M
|