@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,65 @@
|
|
|
1
|
+
-- Seed selection only. These predicates never restrict graph expansion.
|
|
2
|
+
local M = {}
|
|
3
|
+
local fields = { kind = 'kinds', lang = 'languages', language = 'languages', path = 'paths', name = 'names' }
|
|
4
|
+
local aliases = { js = 'javascript', ts = 'typescript', py = 'python', ['c++'] = 'cpp', ['c#'] = 'csharp', cs = 'csharp', kt = 'kotlin', rs = 'rust' }
|
|
5
|
+
local languages = { c = true, cpp = true, csharp = true, javascript = true, typescript = true,
|
|
6
|
+
arkts = true, python = true, lua = true, kotlin = true, java = true, go = true, rust = true }
|
|
7
|
+
|
|
8
|
+
function M.parse(query)
|
|
9
|
+
local out = { text = '', kinds = {}, languages = {}, paths = {}, names = {}, count = 0 }
|
|
10
|
+
local words, at = {}, 1
|
|
11
|
+
while at <= #query do
|
|
12
|
+
local first = query:find('%S', at)
|
|
13
|
+
if not first then break end
|
|
14
|
+
local key, value_at = query:match('^([%a]+):()', first)
|
|
15
|
+
local field = key and fields[key:lower()]
|
|
16
|
+
if field then
|
|
17
|
+
local value, last
|
|
18
|
+
if query:sub(value_at, value_at) == '"' then
|
|
19
|
+
last = assert(query:find('"', value_at + 1, true), 'unterminated quoted query filter')
|
|
20
|
+
value = query:sub(value_at + 1, last - 1)
|
|
21
|
+
assert(last == #query or query:sub(last + 1, last + 1):match('%s'), 'query filter must end at whitespace')
|
|
22
|
+
else
|
|
23
|
+
last = (query:find('%s', value_at) or #query + 1) - 1
|
|
24
|
+
value = query:sub(value_at, last)
|
|
25
|
+
end
|
|
26
|
+
assert(value ~= '' and value:find('%S'), 'query filter value must not be empty')
|
|
27
|
+
value = value:lower()
|
|
28
|
+
if field == 'languages' then
|
|
29
|
+
value = aliases[value] or value
|
|
30
|
+
assert(languages[value], 'unsupported query language: ' .. value)
|
|
31
|
+
elseif field == 'paths' then value = value:gsub('\\', '/') end
|
|
32
|
+
out[field][#out[field] + 1] = value
|
|
33
|
+
out.count = out.count + 1
|
|
34
|
+
at = last + 1
|
|
35
|
+
else
|
|
36
|
+
local last = (query:find('%s', first) or #query + 1) - 1
|
|
37
|
+
words[#words + 1] = query:sub(first, last); at = last + 1
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
out.text = table.concat(words, ' ')
|
|
41
|
+
return out
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
local function matches(values, value, exact)
|
|
45
|
+
if #values == 0 then return true end
|
|
46
|
+
value = value:lower()
|
|
47
|
+
for _, wanted in ipairs(values) do
|
|
48
|
+
if exact and value == wanted or not exact and value:find(wanted, 1, true) then return true end
|
|
49
|
+
end
|
|
50
|
+
return false
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
function M.file(filters, rec)
|
|
54
|
+
return matches(filters.languages, rec.language, true) and matches(filters.paths, (rec.path:gsub('\\', '/')))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
function M.node(filters, rec, node)
|
|
58
|
+
return M.file(filters, rec) and matches(filters.kinds, node.kind, true) and matches(filters.names, node.qualified)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
function M.id(filters, G, id)
|
|
62
|
+
return filters.count == 0 or M.node(filters, G.files[G.node_file[id]], G.nodes[id])
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
return M
|
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
-- Bounded, query-owned explanations; never stored on index records.
|
|
2
|
-
local M = {}
|
|
2
|
+
local M = { MAX_PATH_BREAKPOINTS = 4 }
|
|
3
|
+
function M.edge_label(kind)
|
|
4
|
+
if kind == 'ref' then return 'ref' end
|
|
5
|
+
if kind == 'implementation' then return 'possible implementation' end
|
|
6
|
+
if kind == 'automatic:event' then return 'possible event' end
|
|
7
|
+
if kind == 'call' or kind == 'member_call' or kind == 'new' then return nil end
|
|
8
|
+
return kind
|
|
9
|
+
end
|
|
10
|
+
local function renderer(G, initial)
|
|
11
|
+
local lines, references, size = {}, {}, 0
|
|
12
|
+
local function append(line, ids, registration)
|
|
13
|
+
line = require('codeoutline.text').valid(line)
|
|
14
|
+
local files, seen = {}, {}
|
|
15
|
+
local function add(f) if f and not seen[f] then seen[f] = true; files[#files + 1] = f end end
|
|
16
|
+
for _, id in ipairs(ids or {}) do add(G.node_file[id]) end
|
|
17
|
+
if registration then add(G.file_index[registration:match('^(.*):%d+$') or '']) end
|
|
18
|
+
if #files > 0 then references[#references + 1] = { at = size, files = files } end
|
|
19
|
+
lines[#lines + 1] = line; size = size + #line + 1
|
|
20
|
+
end
|
|
21
|
+
for _, line in ipairs(initial) do append(line) end
|
|
22
|
+
return append, function() return table.concat(lines, '\n'), references end
|
|
23
|
+
end
|
|
3
24
|
|
|
4
25
|
function M.new(limit)
|
|
5
|
-
local report = { entries = {}, truncated = false, scope = 'indexed references and configured dispatch rules' }
|
|
26
|
+
local report = { entries = {}, truncated = false, scope = 'indexed references, possible implementations, automatic callbacks and configured dispatch rules' }
|
|
6
27
|
local seen = {}
|
|
7
28
|
function report:add(entry)
|
|
8
29
|
local key = table.concat({ entry.source or '', entry.target or '', entry.line or '',
|
|
@@ -15,9 +36,115 @@ function M.new(limit)
|
|
|
15
36
|
return report
|
|
16
37
|
end
|
|
17
38
|
|
|
39
|
+
-- Capture only evidence already produced by a failed BFS. The predecessor
|
|
40
|
+
-- table is not retained, and this never loads edges or parses another file.
|
|
41
|
+
function M.capture_paths(report, prev, root, via)
|
|
42
|
+
local result = {}
|
|
43
|
+
for _, entry in ipairs(report.entries) do
|
|
44
|
+
if entry.reason and not entry.target and prev[entry.source] then
|
|
45
|
+
local path, id = { entry.source }, entry.source
|
|
46
|
+
while id ~= root do
|
|
47
|
+
id = prev[id]
|
|
48
|
+
table.insert(path, 1, id)
|
|
49
|
+
end
|
|
50
|
+
local hops = {}
|
|
51
|
+
for i = 2, #path do hops[#hops + 1] = via and via[path[i]] or { kind = 'call' } end
|
|
52
|
+
result[#result + 1] = { evidence = entry, path = path, hops = hops }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
return result
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
function M.path_breakpoints(report, G, searches, connected)
|
|
59
|
+
local candidates = {}
|
|
60
|
+
for _, search in ipairs(searches) do
|
|
61
|
+
local goal
|
|
62
|
+
for _, target in ipairs(search.targets) do
|
|
63
|
+
-- A reverse path already explains how these two symbols connect.
|
|
64
|
+
if not (connected[target] and connected[target][search.root]) then goal = target; break end
|
|
65
|
+
end
|
|
66
|
+
if goal or search.single then
|
|
67
|
+
for _, site in ipairs(search.sites) do
|
|
68
|
+
local e = site.evidence
|
|
69
|
+
local priority = e.reason:find('dynamic', 1, true) and 3
|
|
70
|
+
or e.reason == 'no indexed target' and 1 or 2
|
|
71
|
+
candidates[#candidates + 1] = { status = 'unresolved', from = search.root, goal = goal,
|
|
72
|
+
path = site.path, hops = site.hops, source = e.source, line = e.line, call = e.call, reason = e.reason,
|
|
73
|
+
rule = e.rule, argument = e.argument, evidence = e, priority = priority }
|
|
74
|
+
end
|
|
75
|
+
if search.limited or search.incomplete then
|
|
76
|
+
candidates[#candidates + 1] = { status = 'search_limit', from = search.root, goal = goal,
|
|
77
|
+
path = { search.root }, reason = search.incomplete and 'relationship expansion limit reached'
|
|
78
|
+
or 'path depth/frontier limit reached', priority = 0 }
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
table.sort(candidates, function(a, b)
|
|
83
|
+
if a.priority ~= b.priority then return a.priority > b.priority end
|
|
84
|
+
if #a.path ~= #b.path then return #a.path > #b.path end
|
|
85
|
+
if a.from ~= b.from then return require('codeoutline.graph').before(G, a.from, b.from) end
|
|
86
|
+
if (a.line or 0) ~= (b.line or 0) then return (a.line or 0) < (b.line or 0) end
|
|
87
|
+
return (a.call or '') < (b.call or '')
|
|
88
|
+
end)
|
|
89
|
+
local result, seen = { entries = {}, truncated = report.truncated }, {}
|
|
90
|
+
for _, entry in ipairs(candidates) do
|
|
91
|
+
local key = entry.evidence and (entry.source .. ':' .. (entry.line or 0) .. ':' .. (entry.call or ''))
|
|
92
|
+
or ('limit:' .. math.min(entry.from, entry.goal or entry.from)
|
|
93
|
+
.. ':' .. math.max(entry.from, entry.goal or entry.from))
|
|
94
|
+
if not seen[key] then
|
|
95
|
+
seen[key] = true
|
|
96
|
+
if #result.entries >= M.MAX_PATH_BREAKPOINTS then result.truncated = true
|
|
97
|
+
else
|
|
98
|
+
entry.evidence, entry.priority = nil, nil
|
|
99
|
+
result.entries[#result.entries + 1] = entry
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
return result
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
function M.render_breakpoints(report, G)
|
|
107
|
+
if #report.entries == 0 then return nil end
|
|
108
|
+
local graph = require('codeoutline.graph')
|
|
109
|
+
local function label(id) return G.nodes[id].qualified .. ' (' .. graph.where(G, id) .. ')' end
|
|
110
|
+
local special = false
|
|
111
|
+
for _, entry in ipairs(report.entries) do
|
|
112
|
+
for _, hop in ipairs(entry.hops or {}) do if M.edge_label(hop.kind) then special = true end end
|
|
113
|
+
end
|
|
114
|
+
local append, finish = renderer(G, { special and '\n## Relationship-path breakpoints' or '\n## Call-path breakpoints',
|
|
115
|
+
'Unresolved sites on explored indexed prefixes; these are not proven causes of disconnection.' })
|
|
116
|
+
for _, entry in ipairs(report.entries) do
|
|
117
|
+
local destination = entry.goal and (' toward ' .. label(entry.goal)) or ''
|
|
118
|
+
if entry.status == 'search_limit' then
|
|
119
|
+
append('- Search from ' .. label(entry.from) .. destination .. ': ' .. entry.reason
|
|
120
|
+
.. '; continuation was not checked completely.', { entry.from, entry.goal })
|
|
121
|
+
else
|
|
122
|
+
local path = {}
|
|
123
|
+
for i, id in ipairs(entry.path) do
|
|
124
|
+
if i > 1 then
|
|
125
|
+
local hop = entry.hops and entry.hops[i - 1]
|
|
126
|
+
local kind = M.edge_label(hop and hop.kind or 'call')
|
|
127
|
+
path[#path + 1] = kind and (' -[' .. kind .. ']-> ') or ' -> '
|
|
128
|
+
end
|
|
129
|
+
path[#path + 1] = label(id)
|
|
130
|
+
end
|
|
131
|
+
local file = G.files[G.node_file[entry.source]].path
|
|
132
|
+
local reason = entry.reason
|
|
133
|
+
if entry.rule then reason = reason .. string.format(' (rule #%d, argument %d)', entry.rule, entry.argument) end
|
|
134
|
+
local ids = {}; for _, id in ipairs(entry.path) do ids[#ids + 1] = id end
|
|
135
|
+
ids[#ids + 1] = entry.source
|
|
136
|
+
if entry.goal then ids[#ids + 1] = entry.goal end
|
|
137
|
+
append(string.format('- %s; unresolved at %s:%d via %s: %s; continuation%s is unverified.',
|
|
138
|
+
table.concat(path), file, entry.line or 0, entry.call or '?', reason, destination), ids)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
if report.truncated then append('Additional sites or relationship evidence were omitted.') end
|
|
142
|
+
return finish()
|
|
143
|
+
end
|
|
144
|
+
|
|
18
145
|
function M.render(report, G)
|
|
19
|
-
local
|
|
20
|
-
'Scope: indexed references and configured dispatch rules; unresolved does not mean no runtime call.' }
|
|
146
|
+
local append, finish = renderer(G, { '\n## Relationship evidence / unresolved references',
|
|
147
|
+
'Scope: indexed references, possible implementations and configured dispatch rules; unresolved does not mean no runtime call.' })
|
|
21
148
|
for _, e in ipairs(report.entries) do
|
|
22
149
|
local source = G.nodes[e.source]
|
|
23
150
|
local path = source and G.files[G.node_file[e.source]].path or '?'
|
|
@@ -26,11 +153,11 @@ function M.render(report, G)
|
|
|
26
153
|
if e.call then detail = detail .. ' via ' .. e.call end
|
|
27
154
|
if e.rule then detail = detail .. ' (rule #' .. e.rule .. ', argument ' .. e.argument .. ')' end
|
|
28
155
|
if e.registered_at then detail = detail .. '; registered at ' .. e.registered_at end
|
|
29
|
-
|
|
30
|
-
source and source.qualified or '?', target and ' -> ' .. target or '', detail)
|
|
156
|
+
append(string.format('- %s:%d %s%s: %s', path, e.line or 0,
|
|
157
|
+
source and source.qualified or '?', target and ' -> ' .. target or '', detail), { e.source, e.target }, e.registered_at)
|
|
31
158
|
end
|
|
32
|
-
if report.truncated then
|
|
33
|
-
return
|
|
159
|
+
if report.truncated then append('Evidence limit reached; additional explanations omitted.') end
|
|
160
|
+
return finish()
|
|
34
161
|
end
|
|
35
162
|
|
|
36
163
|
return M
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- Bounded diagnostics for reference sites actually examined by this query.
|
|
2
|
+
local M = { MAX_SITES = 512 }
|
|
3
|
+
function M.new()
|
|
4
|
+
local result = { scope = 'examined_reference_sites', observed_sites = 0,
|
|
5
|
+
unresolved_sites = 0, ambiguous_sites = 0, heuristic_matches = 0, counts_limited = false }
|
|
6
|
+
local seen = {}
|
|
7
|
+
local function record(file, reference, kind, targets, reason)
|
|
8
|
+
if result.counts_limited or kind ~= 'call' and kind ~= 'member_call' then return end
|
|
9
|
+
local key = file .. ':' .. reference
|
|
10
|
+
if seen[key] then return end
|
|
11
|
+
if result.observed_sites >= M.MAX_SITES then result.counts_limited = true; return end
|
|
12
|
+
seen[key] = true; result.observed_sites = result.observed_sites + 1
|
|
13
|
+
local count = targets and #targets or 0
|
|
14
|
+
reason = reason or ''
|
|
15
|
+
if count == 0 then result.unresolved_sites = result.unresolved_sites + 1 end
|
|
16
|
+
if count > 1 or reason:find('ambigu', 1, true) or reason:find('multiple name/', 1, true) then
|
|
17
|
+
result.ambiguous_sites = result.ambiguous_sites + 1
|
|
18
|
+
end
|
|
19
|
+
if count > 0 and reason:find('name/locality', 1, true) then result.heuristic_matches = result.heuristic_matches + 1 end
|
|
20
|
+
end
|
|
21
|
+
return result, record
|
|
22
|
+
end
|
|
23
|
+
return M
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
-- One project-local contract, two consumers. Legacy arrays keep their scope.
|
|
2
|
+
local M = {}
|
|
3
|
+
local function copy(value)
|
|
4
|
+
local result = {}; for k, v in pairs(value) do result[k] = v end; return result
|
|
5
|
+
end
|
|
6
|
+
local function array(value, label)
|
|
7
|
+
if value == nil then value = {} end
|
|
8
|
+
assert(type(value) == 'table' and #value <= 32, label .. ' must contain at most 32 rules')
|
|
9
|
+
local count = 0
|
|
10
|
+
for k in pairs(value) do
|
|
11
|
+
assert(type(k) == 'number' and k >= 1 and k <= #value and k % 1 == 0, label .. ' must be an array')
|
|
12
|
+
count = count + 1
|
|
13
|
+
end
|
|
14
|
+
assert(count == #value, label .. ' must be an array')
|
|
15
|
+
return value
|
|
16
|
+
end
|
|
17
|
+
local function position(r, key, label)
|
|
18
|
+
local n = r[key]
|
|
19
|
+
assert(type(n) == 'number' and n >= 1 and n <= 32 and n % 1 == 0,
|
|
20
|
+
label .. '.' .. key .. ' must be an integer from 1 to 32')
|
|
21
|
+
end
|
|
22
|
+
local function call(r, key, label)
|
|
23
|
+
assert(type(r[key]) == 'string' and r[key]:match('^[%a_][%w_%.:>%-]*$'), 'invalid ' .. label .. '.' .. key)
|
|
24
|
+
end
|
|
25
|
+
local function qualifiers(r, label)
|
|
26
|
+
if r.qualifiers == nil then return nil end
|
|
27
|
+
local result = {}
|
|
28
|
+
assert(type(r.qualifiers) == 'table', label .. '.qualifiers must be an array of names')
|
|
29
|
+
local count = 0
|
|
30
|
+
for k, q in pairs(r.qualifiers) do
|
|
31
|
+
assert(type(k) == 'number' and k >= 1 and k <= #r.qualifiers and k % 1 == 0,
|
|
32
|
+
label .. '.qualifiers must be an array of names')
|
|
33
|
+
assert(type(q) == 'string' and q:match('^[%a_][%w_]*$'), label .. '.qualifiers must contain plain names')
|
|
34
|
+
result[q], count = true, count + 1
|
|
35
|
+
end
|
|
36
|
+
assert(count == #r.qualifiers, label .. '.qualifiers must be an array of names')
|
|
37
|
+
return result
|
|
38
|
+
end
|
|
39
|
+
local function dispatch(r, label)
|
|
40
|
+
assert(type(r) == 'table', 'invalid ' .. label .. ' rule')
|
|
41
|
+
call(r, 'call', label); position(r, 'argument', label)
|
|
42
|
+
assert(r.language == nil or type(r.language) == 'string', 'invalid ' .. label .. '.language')
|
|
43
|
+
assert(r.kind == 'target' or r.kind == 'callback' or r.kind == 'event', 'invalid ' .. label .. '.kind')
|
|
44
|
+
if r.serviceArgument ~= nil then
|
|
45
|
+
assert(r.kind == 'target', 'serviceArgument requires a target rule')
|
|
46
|
+
position(r, 'serviceArgument', label)
|
|
47
|
+
end
|
|
48
|
+
if r.kind == 'event' then
|
|
49
|
+
call(r, 'register', label); position(r, 'keyArgument', label); position(r, 'handlerArgument', label)
|
|
50
|
+
end
|
|
51
|
+
local result = copy(r)
|
|
52
|
+
-- Declaration qualifiers restrict editor candidates, not graph inference.
|
|
53
|
+
result.qualifiers = nil
|
|
54
|
+
return result
|
|
55
|
+
end
|
|
56
|
+
local function definition(r, label)
|
|
57
|
+
assert(type(r) == 'table', 'invalid ' .. label .. ' rule')
|
|
58
|
+
assert(r.language == nil or r.language == 'lua', label .. ' currently support language lua')
|
|
59
|
+
call(r, 'call', label); position(r, 'argument', label)
|
|
60
|
+
local result = copy(r)
|
|
61
|
+
result.targetKind = r.targetKind or 'call'
|
|
62
|
+
assert(result.targetKind == 'call' or result.targetKind == 'declaration' or result.targetKind == 'key',
|
|
63
|
+
"invalid " .. label .. '.targetKind')
|
|
64
|
+
if result.targetKind == 'call' then
|
|
65
|
+
call(r, 'target', label); position(r, 'targetArgument', label)
|
|
66
|
+
else
|
|
67
|
+
assert(r.target == nil and r.targetArgument == nil, 'declaration and key rules must not set target or targetArgument')
|
|
68
|
+
result.qualifiers = qualifiers(r, label)
|
|
69
|
+
end
|
|
70
|
+
return result
|
|
71
|
+
end
|
|
72
|
+
function M.read(root)
|
|
73
|
+
local f = root and io.open(root .. '/.codeoutline.json', 'rb')
|
|
74
|
+
if not f then return {} end
|
|
75
|
+
local raw = f:read(65537); f:close()
|
|
76
|
+
assert(#raw <= 65536, '.codeoutline.json exceeds 64 KiB')
|
|
77
|
+
local ok, config = pcall(xutils.json_unpack, raw)
|
|
78
|
+
assert(ok and type(config) == 'table', 'invalid .codeoutline.json')
|
|
79
|
+
return config
|
|
80
|
+
end
|
|
81
|
+
function M.normalize(config)
|
|
82
|
+
local result = { definitions = {}, dispatch = {} }
|
|
83
|
+
local seen = { definitions = {}, dispatch = {} }
|
|
84
|
+
local function add(consumer, r)
|
|
85
|
+
local fields = consumer == 'dispatch' and { 'kind', 'language', 'call', 'argument', 'register', 'keyArgument', 'handlerArgument', 'serviceArgument' }
|
|
86
|
+
or { 'language', 'call', 'argument', 'targetKind', 'target', 'targetArgument', 'serviceArgument' }
|
|
87
|
+
local key = {}
|
|
88
|
+
for _, f in ipairs(fields) do key[#key + 1] = tostring(r[f]) end
|
|
89
|
+
if r.qualifiers then
|
|
90
|
+
local q = {}; for name in pairs(r.qualifiers) do q[#q + 1] = name end; table.sort(q)
|
|
91
|
+
key[#key + 1] = table.concat(q, ',')
|
|
92
|
+
end
|
|
93
|
+
key = table.concat(key, '\0')
|
|
94
|
+
if not seen[consumer][key] then
|
|
95
|
+
seen[consumer][key] = r
|
|
96
|
+
result[consumer][#result[consumer] + 1] = r
|
|
97
|
+
assert(#result[consumer] <= 32, 'combined ' .. consumer .. ' rules must contain at most 32 rules')
|
|
98
|
+
elseif consumer == 'definitions' and not r.shared then
|
|
99
|
+
-- Keep the legacy literal/method matcher when an equivalent shared
|
|
100
|
+
-- contract is also configured; their alias semantics differ.
|
|
101
|
+
seen[consumer][key].legacy = true
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
for _, r in ipairs(array(config.rules, 'rules')) do
|
|
105
|
+
assert(type(r) == 'table', 'invalid rules rule')
|
|
106
|
+
if r.kind == 'definition' then add('definitions', definition(r, 'rules'))
|
|
107
|
+
else
|
|
108
|
+
local d = dispatch(r, 'rules')
|
|
109
|
+
add('dispatch', d)
|
|
110
|
+
local n = copy(d); n.shared = true
|
|
111
|
+
if d.kind == 'event' then n.targetKind, n.target, n.targetArgument = 'call', d.register, d.keyArgument
|
|
112
|
+
elseif d.kind == 'target' then n.targetKind, n.qualifiers = 'declaration', qualifiers(r, 'rules')
|
|
113
|
+
else n.targetKind = 'callback' end
|
|
114
|
+
add('definitions', n)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
for _, r in ipairs(array(config.definitionRules, 'definitionRules')) do add('definitions', definition(r, 'definitionRules')) end
|
|
118
|
+
for _, r in ipairs(array(config.dispatchRules, 'dispatchRules')) do add('dispatch', dispatch(r, 'dispatchRules')) end
|
|
119
|
+
return result
|
|
120
|
+
end
|
|
121
|
+
function M.load(root) return M.normalize(M.read(root)) end
|
|
122
|
+
function M.dispatch(rules)
|
|
123
|
+
local result = {}
|
|
124
|
+
for _, r in ipairs(array(rules, 'dispatchRules')) do result[#result + 1] = dispatch(r, 'dispatchRules') end
|
|
125
|
+
return result
|
|
126
|
+
end
|
|
127
|
+
return M
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
-- Local Cargo package identity is configuration evidence owned by one query.
|
|
2
|
+
local M = { MAX_CONFIGS = 1024, MAX_CONFIG_BYTES = 1048576, MAX_TOTAL_BYTES = 8388608,
|
|
3
|
+
MAX_DEPENDENCIES = 512, MAX_DEPTH = 32 }
|
|
4
|
+
local control, paths = require('codeoutline.control'), require('codeoutline.path')
|
|
5
|
+
local function dir(p) return p:match('^(.*)/[^/]+$') or '' end
|
|
6
|
+
local function join(a, b) return a == '' and b or b == '' and a or a .. '/' .. b end
|
|
7
|
+
local function relative(base, p)
|
|
8
|
+
if type(p) ~= 'string' or p:find('[\\:%z]') or p:sub(1, 1) == '/' then error('unsupported or external Cargo path', 0) end
|
|
9
|
+
local parts = {}
|
|
10
|
+
for s in join(base, p):gmatch('[^/]+') do
|
|
11
|
+
if s == '..' then
|
|
12
|
+
if #parts == 0 then error('Cargo path escapes indexed project', 0) end
|
|
13
|
+
parts[#parts] = nil
|
|
14
|
+
elseif s ~= '.' then parts[#parts + 1] = s end
|
|
15
|
+
end
|
|
16
|
+
return table.concat(parts, '/')
|
|
17
|
+
end
|
|
18
|
+
local function crate_name(s) return type(s) == 'string' and s:gsub('-', '_') end
|
|
19
|
+
local function matches(pattern, value)
|
|
20
|
+
if type(pattern) ~= 'string' or pattern:find('[{}%[%]\\%z]') or pattern:find('..', 1, true) then
|
|
21
|
+
error('unsupported Cargo workspace glob', 0)
|
|
22
|
+
end
|
|
23
|
+
pattern = pattern:gsub('^%./', ''):gsub('/+$', '')
|
|
24
|
+
local escaped = pattern:gsub('([^%w*?])', '%%%1'):gsub('%*', '[^/]*'):gsub('%?', '[^/]')
|
|
25
|
+
return value:match('^' .. escaped .. '$') ~= nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
local function context(G, ctx)
|
|
29
|
+
if ctx.rust_packages then return ctx.rust_packages end
|
|
30
|
+
local C = { configs = {}, owners = {}, deps = {}, reaches = {}, probes = 0, bytes = 0 }
|
|
31
|
+
ctx.rust_packages = C
|
|
32
|
+
ctx.rust_stats = ctx.rust_stats or { reads = 0, bytes = 0, packages = 0 }
|
|
33
|
+
function C.read(root)
|
|
34
|
+
if C.configs[root] ~= nil then return C.configs[root] or nil end
|
|
35
|
+
control.check(); C.probes = C.probes + 1
|
|
36
|
+
if C.probes > M.MAX_CONFIGS then error('Cargo configuration probe limit reached', 0) end
|
|
37
|
+
local abs = join(G.root, join(root, 'Cargo.toml'))
|
|
38
|
+
local real = xutils.realpath(abs)
|
|
39
|
+
if not real then C.configs[root] = false; return nil end
|
|
40
|
+
if not paths.contains(G.root, real) then error('Cargo manifest escapes indexed project', 0) end
|
|
41
|
+
local file = io.open(abs, 'rb')
|
|
42
|
+
if not file then C.configs[root] = false; return nil end
|
|
43
|
+
local raw = file:read(M.MAX_CONFIG_BYTES + 1); file:close()
|
|
44
|
+
C.bytes = C.bytes + #raw
|
|
45
|
+
if #raw > M.MAX_CONFIG_BYTES or C.bytes > M.MAX_TOTAL_BYTES then error('Cargo configuration size limit reached', 0) end
|
|
46
|
+
local config = require('codeoutline.cargo_toml').parse(raw); config.root = root
|
|
47
|
+
if config.package and (type(config.package.name) ~= 'string' or not config.package.name:match('^[%w_-]+$')) then
|
|
48
|
+
error('invalid Cargo package name', 0)
|
|
49
|
+
end
|
|
50
|
+
local stat = ctx.rust_stats
|
|
51
|
+
stat.reads, stat.bytes = stat.reads + 1, C.bytes
|
|
52
|
+
if config.package then stat.packages = stat.packages + 1 end
|
|
53
|
+
C.configs[root] = config; return config
|
|
54
|
+
end
|
|
55
|
+
function C.owner(file)
|
|
56
|
+
local directory = dir(G.files[file].path)
|
|
57
|
+
if C.owners[directory] ~= nil then return C.owners[directory] or nil end
|
|
58
|
+
local current = directory
|
|
59
|
+
while true do
|
|
60
|
+
local config = C.read(current)
|
|
61
|
+
if config then
|
|
62
|
+
C.owners[directory] = config.package and config or false
|
|
63
|
+
return config.package and config or nil
|
|
64
|
+
end
|
|
65
|
+
if current == '' then break end
|
|
66
|
+
current = dir(current)
|
|
67
|
+
end
|
|
68
|
+
C.owners[directory] = false
|
|
69
|
+
end
|
|
70
|
+
function C.workspace(owner)
|
|
71
|
+
local override = owner.package.workspace
|
|
72
|
+
if override ~= nil then
|
|
73
|
+
local config = C.read(relative(owner.root, override))
|
|
74
|
+
if not config or not config.workspace then error('Cargo workspace root is unavailable', 0) end
|
|
75
|
+
return config
|
|
76
|
+
end
|
|
77
|
+
local current = owner.root
|
|
78
|
+
while true do
|
|
79
|
+
local config = C.read(current)
|
|
80
|
+
if config and config.workspace then return config end
|
|
81
|
+
if current == '' then return nil end
|
|
82
|
+
current = dir(current)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
function C.dependencies(owner)
|
|
86
|
+
if C.deps[owner.root] then return C.deps[owner.root] end
|
|
87
|
+
local dependencies, result, count = {}, {}, 0
|
|
88
|
+
for key, value in pairs(owner.dependencies or {}) do
|
|
89
|
+
local name, field = key:match('^([%w_-]+)%.([%w_-]+)$')
|
|
90
|
+
if name then
|
|
91
|
+
dependencies[name] = dependencies[name] or {}
|
|
92
|
+
if type(dependencies[name]) ~= 'table' then error('conflicting Cargo dependency assignment', 0) end
|
|
93
|
+
dependencies[name][field] = value
|
|
94
|
+
else dependencies[key] = value end
|
|
95
|
+
end
|
|
96
|
+
for section, value in pairs(owner) do
|
|
97
|
+
local name = section:match('^dependencies%.([%w_-]+)$')
|
|
98
|
+
if name then
|
|
99
|
+
if dependencies[name] then error('conflicting Cargo dependency table', 0) end
|
|
100
|
+
dependencies[name] = value
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
for key, value in pairs(dependencies) do
|
|
104
|
+
control.check(); count = count + 1
|
|
105
|
+
if count > M.MAX_DEPENDENCIES then error('Cargo dependency limit reached', 0) end
|
|
106
|
+
local base, dependency = owner.root, value
|
|
107
|
+
if type(value) == 'table' and value.workspace == true then
|
|
108
|
+
local workspace = C.workspace(owner)
|
|
109
|
+
if not workspace then error('Cargo inherited dependency has no workspace', 0) end
|
|
110
|
+
local rel = owner.root == workspace.root and '' or workspace.root == '' and owner.root or owner.root:sub(#workspace.root + 2)
|
|
111
|
+
for _, pattern in ipairs(workspace.workspace.exclude or {}) do
|
|
112
|
+
if matches(pattern, rel) then error('Cargo package is excluded from workspace', 0) end
|
|
113
|
+
end
|
|
114
|
+
dependency = (workspace['workspace.dependencies'] or {})[key] or workspace['workspace.dependencies.' .. key]
|
|
115
|
+
if not dependency then error('Cargo inherited dependency is not declared: ' .. key, 0) end
|
|
116
|
+
base = workspace.root
|
|
117
|
+
end
|
|
118
|
+
local descriptor = { alias = crate_name(key), source = dependency }
|
|
119
|
+
if type(dependency) == 'table' and dependency.path ~= nil then
|
|
120
|
+
local root = relative(base, dependency.path)
|
|
121
|
+
local target = C.read(root)
|
|
122
|
+
if target and target.package and type(target.package.name) == 'string'
|
|
123
|
+
and (dependency.package == nil or dependency.package == target.package.name) then
|
|
124
|
+
descriptor.package = target
|
|
125
|
+
if dependency.package == nil and target.package.name ~= key then descriptor.package = nil end
|
|
126
|
+
if descriptor.package and dependency.package == nil then
|
|
127
|
+
descriptor.alias = crate_name((target.lib or {}).name or target.package.name)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
if result[descriptor.alias] then error('ambiguous Cargo crate alias: ' .. descriptor.alias, 0) end
|
|
132
|
+
result[descriptor.alias] = descriptor
|
|
133
|
+
end
|
|
134
|
+
C.deps[owner.root] = result; return result
|
|
135
|
+
end
|
|
136
|
+
return C
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
function M.guard(ctx, fn, ...)
|
|
140
|
+
if ctx.rust_error then return nil, ctx.rust_error end
|
|
141
|
+
local ok, a, b = pcall(fn, ...)
|
|
142
|
+
if ok then return a, b end
|
|
143
|
+
if control.is_interrupted(a) then error(a, 0) end
|
|
144
|
+
ctx.rust_incomplete, ctx.rust_error = true, tostring(a)
|
|
145
|
+
return nil, ctx.rust_error
|
|
146
|
+
end
|
|
147
|
+
function M.owner(G, f, ctx)
|
|
148
|
+
if not G.root then return nil end
|
|
149
|
+
return M.guard(ctx, function() return context(G, ctx).owner(f) end)
|
|
150
|
+
end
|
|
151
|
+
function M.dependencies(G, f, ctx)
|
|
152
|
+
return M.guard(ctx, function()
|
|
153
|
+
local C = context(G, ctx); local owner = C.owner(f)
|
|
154
|
+
return owner and C.dependencies(owner) or {}
|
|
155
|
+
end) or {}
|
|
156
|
+
end
|
|
157
|
+
function M.entry(G, owner, ctx, file)
|
|
158
|
+
return M.guard(ctx, function()
|
|
159
|
+
local lib = owner.lib or {}
|
|
160
|
+
local root = relative(owner.root, lib.path or 'src/lib.rs')
|
|
161
|
+
if file and G.files[file].path == join(owner.root, 'src/main.rs') then root = G.files[file].path end
|
|
162
|
+
if file and not lib.path and not G.file_index[root] then root = join(owner.root, 'src/main.rs') end
|
|
163
|
+
local id = G.file_index[root]
|
|
164
|
+
if not id or G.files[id].language ~= 'rust' then return nil, 'Cargo library target is not indexed' end
|
|
165
|
+
if context(G, ctx).owner(id) ~= owner then return nil, 'Cargo target crosses a package boundary' end
|
|
166
|
+
return id
|
|
167
|
+
end)
|
|
168
|
+
end
|
|
169
|
+
function M.crates(G, f, ctx)
|
|
170
|
+
local result = {}
|
|
171
|
+
for alias, descriptor in pairs(M.dependencies(G, f, ctx)) do
|
|
172
|
+
if descriptor.package then result[alias] = M.entry(G, descriptor.package, ctx) end
|
|
173
|
+
end
|
|
174
|
+
local owner = M.owner(G, f, ctx)
|
|
175
|
+
if owner then
|
|
176
|
+
local alias = crate_name((owner.lib or {}).name or owner.package.name)
|
|
177
|
+
if alias and not result[alias] then result[alias] = M.entry(G, owner, ctx) end
|
|
178
|
+
end
|
|
179
|
+
return result
|
|
180
|
+
end
|
|
181
|
+
function M.reaches(G, f, target, ctx)
|
|
182
|
+
local owner = M.owner(G, f, ctx)
|
|
183
|
+
if not owner or not target then return false end
|
|
184
|
+
return M.guard(ctx, function()
|
|
185
|
+
local C, seen = context(G, ctx), {}
|
|
186
|
+
local key = owner.root .. '\0' .. target.root
|
|
187
|
+
if C.reaches[key] ~= nil then return C.reaches[key] end
|
|
188
|
+
local function visit(package, depth)
|
|
189
|
+
if package == target then return true end
|
|
190
|
+
if seen[package.root] then return false end
|
|
191
|
+
if depth > M.MAX_DEPTH then error('Cargo dependency traversal limit reached', 0) end
|
|
192
|
+
seen[package.root] = true
|
|
193
|
+
for _, descriptor in pairs(C.dependencies(package)) do
|
|
194
|
+
control.check()
|
|
195
|
+
if descriptor.package and visit(descriptor.package, depth + 1) then return true end
|
|
196
|
+
end
|
|
197
|
+
return false
|
|
198
|
+
end
|
|
199
|
+
local result = visit(owner, 0); C.reaches[key] = result; return result
|
|
200
|
+
end) or false
|
|
201
|
+
end
|
|
202
|
+
M.dir, M.join, M.relative = dir, join, relative
|
|
203
|
+
return M
|