@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.
Files changed (77) hide show
  1. package/README.md +205 -3
  2. package/README.zh-CN.md +40 -2
  3. package/bin/xnet.exe +0 -0
  4. package/build-info.json +1 -1
  5. package/package.json +1 -1
  6. package/scripts/codeoutline/affected.lua +145 -0
  7. package/scripts/codeoutline/automatic_events.lua +202 -0
  8. package/scripts/codeoutline/cache_repairs.lua +47 -0
  9. package/scripts/codeoutline/callers.lua +56 -16
  10. package/scripts/codeoutline/cargo_toml.lua +125 -0
  11. package/scripts/codeoutline/command.lua +26 -4
  12. package/scripts/codeoutline/common.lua +65 -9
  13. package/scripts/codeoutline/completion.lua +221 -65
  14. package/scripts/codeoutline/coverage.lua +63 -0
  15. package/scripts/codeoutline/cpp_bindings.lua +151 -0
  16. package/scripts/codeoutline/cpp_fragments.lua +143 -0
  17. package/scripts/codeoutline/cpp_implementations.lua +340 -0
  18. package/scripts/codeoutline/cpp_includes.lua +156 -0
  19. package/scripts/codeoutline/cpp_macros.lua +279 -0
  20. package/scripts/codeoutline/cpp_receivers.lua +342 -0
  21. package/scripts/codeoutline/cpp_types.lua +456 -0
  22. package/scripts/codeoutline/csharp_bindings.lua +498 -0
  23. package/scripts/codeoutline/definition_candidates.lua +180 -0
  24. package/scripts/codeoutline/dispatch_aliases.lua +479 -0
  25. package/scripts/codeoutline/documents.lua +32 -9
  26. package/scripts/codeoutline/explore.lua +274 -119
  27. package/scripts/codeoutline/external_headers.lua +171 -0
  28. package/scripts/codeoutline/foreign.lua +79 -14
  29. package/scripts/codeoutline/foreign_lua.lua +146 -19
  30. package/scripts/codeoutline/function_values.lua +69 -0
  31. package/scripts/codeoutline/go_methods.lua +931 -0
  32. package/scripts/codeoutline/go_modules.lua +329 -0
  33. package/scripts/codeoutline/graph.lua +346 -63
  34. package/scripts/codeoutline/implementations.lua +403 -0
  35. package/scripts/codeoutline/index.lua +165 -27
  36. package/scripts/codeoutline/index_worker.lua +11 -4
  37. package/scripts/codeoutline/indirect.lua +116 -40
  38. package/scripts/codeoutline/js_evidence.lua +32 -3
  39. package/scripts/codeoutline/js_resolution.lua +72 -10
  40. package/scripts/codeoutline/js_workspace.lua +325 -0
  41. package/scripts/codeoutline/lang/c.lua +15 -2
  42. package/scripts/codeoutline/lang/cpp.lua +7 -4
  43. package/scripts/codeoutline/lang/csharp.lua +15 -3
  44. package/scripts/codeoutline/lang/js.lua +56 -20
  45. package/scripts/codeoutline/lang/rust.lua +9 -1
  46. package/scripts/codeoutline/language_detect.lua +100 -0
  47. package/scripts/codeoutline/lsp.lua +173 -23
  48. package/scripts/codeoutline/lua_bindings.lua +228 -54
  49. package/scripts/codeoutline/lua_callback_loops.lua +210 -0
  50. package/scripts/codeoutline/lua_literal.lua +38 -0
  51. package/scripts/codeoutline/main.lua +32 -7
  52. package/scripts/codeoutline/mcp.lua +52 -9
  53. package/scripts/codeoutline/navigation.lua +593 -147
  54. package/scripts/codeoutline/on_demand.lua +93 -0
  55. package/scripts/codeoutline/ordinary_bindings.lua +396 -0
  56. package/scripts/codeoutline/parse.lua +18 -2
  57. package/scripts/codeoutline/parse_pool.lua +1 -1
  58. package/scripts/codeoutline/parse_worker.lua +1 -1
  59. package/scripts/codeoutline/python_bindings.lua +112 -0
  60. package/scripts/codeoutline/query_filters.lua +65 -0
  61. package/scripts/codeoutline/query_report.lua +135 -8
  62. package/scripts/codeoutline/resolution.lua +23 -0
  63. package/scripts/codeoutline/rules.lua +127 -0
  64. package/scripts/codeoutline/rust_packages.lua +203 -0
  65. package/scripts/codeoutline/rust_resolution.lua +301 -0
  66. package/scripts/codeoutline/search_ranking.lua +70 -0
  67. package/scripts/codeoutline/service.lua +47 -7
  68. package/scripts/codeoutline/shared_events.lua +369 -0
  69. package/scripts/codeoutline/static_dispatch.lua +569 -0
  70. package/scripts/codeoutline/text.lua +3 -2
  71. package/scripts/codeoutline/ts_implementations.lua +81 -0
  72. package/scripts/codeoutline/type_bases.lua +61 -0
  73. package/scripts/codeoutline/type_hierarchy.lua +324 -0
  74. package/scripts/codeoutline/type_references.lua +290 -0
  75. package/scripts/codeoutline/type_uses.lua +260 -0
  76. package/scripts/codeoutline/update_sequence.lua +1 -1
  77. package/scripts/codeoutline/version.lua +1 -1
@@ -0,0 +1,202 @@
1
+ -- Possible Node EventEmitter deliveries, proven to share one local object.
2
+ -- No global event-name matching, execution-order inference or resident graph.
3
+ local M = { MAX_FILES = 128, MAX_SITES = 512, MAX_TARGETS = 64 }
4
+ local control = require('codeoutline.control')
5
+ local registrations = { on = true, once = true, addListener = true }
6
+ local function supported(rec) return rec.language == 'javascript' or rec.language == 'typescript' end
7
+ local function node_events(rec)
8
+ for _, imp in ipairs(rec.js_imports or {}) do if imp.path == 'events' or imp.path == 'node:events' then return true end end
9
+ return false
10
+ end
11
+
12
+ function M.candidate(rec)
13
+ if not supported(rec) or not node_events(rec) then return false end
14
+ for _, call in ipairs(rec.dispatch_calls or {}) do
15
+ if call:match('^[%w_$]+%.emit$') then return true end
16
+ end
17
+ return false
18
+ end
19
+
20
+ local function literal(T, i)
21
+ local s = T:text(i)
22
+ if T.k[i] == 'str' and (s:sub(1, 1) == '"' or s:sub(1, 1) == "'")
23
+ and s:sub(-1) == s:sub(1, 1) and not s:find('[\\$]') then return s:sub(2, -2) end
24
+ end
25
+
26
+ local function statement_end(T, close)
27
+ if not close then return false end
28
+ local ending = T:text(close + 1)
29
+ return ending == ';' or ending == '}' or ending == ''
30
+ or T.l[close + 1] > T.l[close] and (T.k[close + 1] == 'id' or T.k[close + 1] == 'kw')
31
+ and ending ~= 'as' and ending ~= 'satisfies' and ending ~= 'in' and ending ~= 'instanceof'
32
+ end
33
+
34
+ local function statement_start(T, i)
35
+ local previous = T:text(i - 1)
36
+ return previous == '' or previous == ';' or previous == '{' or previous == '}'
37
+ or i > 1 and T.l[i] > T.l[i - 1] and (T.k[i - 1] == 'id' or T.k[i - 1] == 'str'
38
+ or T.k[i - 1] == 'num' or previous == ')' or previous == ']')
39
+ end
40
+
41
+ function M.collect(r, T)
42
+ if not supported(r) or not node_events(r) then return end
43
+ local has_emit = false
44
+ for _, ref in ipairs(r.refs) do if ref.name == 'emit' and ref.recv then has_emit = true; break end end
45
+ if not has_emit then return end
46
+ local expand, binding = require('codeoutline.dispatch_aliases').prepare(r, T)
47
+ -- Unrepresented anonymous function scopes cannot safely share outer locals.
48
+ -- Named handlers and variable-bound arrow functions have parser nodes.
49
+ local headers = {}
50
+ for _, n in ipairs(r.nodes) do
51
+ if n.kind == 'function' or n.kind == 'method' or n.kind == 'constructor' then
52
+ for i = n.ti, n.tj do
53
+ local s = T:text(i)
54
+ if s == 'function' or s == '=>' then headers[i] = true end
55
+ if s == '{' then break end
56
+ end
57
+ end
58
+ end
59
+ for i = 1, T.n do
60
+ if i % 4096 == 0 then control.check() end
61
+ if (T:text(i) == '=>' or T:text(i) == 'function') and not headers[i] then return end
62
+ end
63
+ local objects, by_token, type_names = {}, {}, {}
64
+ for _, n in ipairs(r.nodes) do
65
+ if n.kind == 'class' or n.kind == 'interface' or n.kind == 'namespace' or n.kind == 'enum' or n.kind == 'type' then type_names[n.name] = true end
66
+ end
67
+ for i = 1, T.n do
68
+ if i % 4096 == 0 then control.check() end
69
+ if T:text(i - 1) == 'const' and T:text(i - 2) ~= 'export' and T.k[i] == 'id' and T:text(i + 1) == '=' and T:text(i + 2) == 'new' then
70
+ local a, last = i + 3, i + 3
71
+ if T:text(last + 1) == '.' and T.k[last + 2] == 'id' then last = last + 2 end
72
+ local open = last + 1
73
+ local factory = T.k[a] == 'id' and expand({ symbol = T.src:sub(T.s[a], T.e[last]):gsub('%s+', '') }, a)
74
+ local token = binding(T:text(i), i)
75
+ if token == i and not type_names[T:text(a)] and T:text(open) == '(' and T.m[open] == open + 1
76
+ and statement_end(T, T.m[open])
77
+ and factory and factory.import and (factory.import.path == 'events' or factory.import.path == 'node:events')
78
+ and (factory.member == 'EventEmitter' or factory.member == 'default') then
79
+ local object = { token = i, name = T:text(i), registrations = {}, emissions = {} }
80
+ objects[#objects + 1], by_token[i] = object, object
81
+ end
82
+ end
83
+ end
84
+ if #objects == 0 then return end
85
+ local refs = {}; for _, ref in ipairs(r.refs) do refs[ref.tok] = ref end
86
+ local count = 0
87
+ for i = 1, T.n do
88
+ if i % 4096 == 0 then control.check() end
89
+ if T.k[i] == 'id' then
90
+ local object = by_token[binding(T:text(i), i)]
91
+ if object and i ~= object.token then
92
+ local method, ref = T:text(i + 2), refs[i + 2]
93
+ local previous = T:text(i - 1)
94
+ if not statement_start(T, i) or T:text(i + 1) ~= '.' or previous == '.' or previous == '?.' or not ref
95
+ or T:text(i + 3) ~= '(' or not (registrations[method] or method == 'emit') then object.invalid = true
96
+ else
97
+ local close, event = T.m[i + 3], literal(T, i + 4)
98
+ count = count + 1
99
+ if count > M.MAX_SITES then r.automatic_events = { incomplete = true }; return end
100
+ if not statement_end(T, close) or not event or (T:text(i + 5) ~= ',' and i + 5 ~= close) then object.invalid = true
101
+ elseif registrations[method] then
102
+ local a, b = i + 6, close - 1
103
+ local text = T.src:sub(T.s[a] or 1, T.e[b] or 0):gsub('%s+', '')
104
+ local handler = text:match('^[%a_$][%w_$.]*$') and not type_names[text:match('^[%w_$]+')]
105
+ and expand({ symbol = text }, a)
106
+ if handler and (handler.node or handler.import) then
107
+ object.registrations[#object.registrations + 1] = { event = event, handler = handler,
108
+ from = ref.from, line = ref.line, token = i }
109
+ end
110
+ else object.emissions[#object.emissions + 1] = { event = event, from = ref.from, line = ref.line, token = i } end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ local result = {}
116
+ for _, object in ipairs(objects) do
117
+ if not object.invalid then
118
+ for _, site in ipairs(object.emissions) do
119
+ if site.from > 0 then
120
+ for _, registration in ipairs(object.registrations) do
121
+ if site.event == registration.event and (registration.from == 0 or registration.from == site.from
122
+ and registration.token < site.token) then
123
+ result[#result + 1] = { from = site.from, line = site.line, handler = registration.handler,
124
+ registered_at = registration.line, event = site.event, recv = object.name }
125
+ if #result >= M.MAX_SITES then result.incomplete = true; r.automatic_events = result; return end
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+ r.automatic_events = result
133
+ end
134
+
135
+ function M.context(G, ctx, report)
136
+ local C = { incomplete = false, stats = { files = 0, sites = 0, links = 0 } }
137
+ local shared = require('codeoutline.shared_events').context(G, ctx, report)
138
+ C.stats.shared = shared.stats
139
+ local cache, js = {}, require('codeoutline.js_resolution')
140
+ local function data(f)
141
+ if cache[f] then return cache[f] end
142
+ if not M.candidate(G.files[f]) then return {} end
143
+ if C.stats.files >= M.MAX_FILES then C.incomplete = true; return {} end
144
+ C.stats.files = C.stats.files + 1
145
+ local evidence = ctx.ordinary.data(f).automatic_events or {}
146
+ if evidence.incomplete then C.incomplete = true end
147
+ local result = {}
148
+ for _, site in ipairs(evidence) do
149
+ control.check(); C.stats.sites = C.stats.sites + 1
150
+ local ids = site.handler.node and { G.id_of[f][site.handler.node] }
151
+ or js.imported(G, f, site.handler.import.path, site.handler.member, ctx)
152
+ if ctx.workspace_incomplete then C.incomplete = true end
153
+ if #ids == 1 then
154
+ local id, n = ids[1], G.nodes[ids[1]]
155
+ if n.kind == 'function' or n.kind == 'method' then result[#result + 1] = { source = G.id_of[f][site.from],
156
+ target = id, line = site.line, kind = 'automatic:event', site = site } end
157
+ end
158
+ end
159
+ cache[f] = result; return result
160
+ end
161
+ local function scan(f, only, wanted, out)
162
+ local count, seen = 0, {}
163
+ for _, edge in ipairs(data(f)) do
164
+ if (not only or edge.source == only) and (not wanted or wanted[edge.target]) then
165
+ local key = edge.source .. ':' .. edge.target .. ':' .. edge.line
166
+ if not seen[key] then
167
+ if count >= M.MAX_TARGETS then C.incomplete = true; break end
168
+ seen[key], count = true, count + 1; C.stats.links = C.stats.links + 1
169
+ out[edge.source] = out[edge.source] or {}; out[edge.source][#out[edge.source] + 1] = edge
170
+ if report then report:add({ source = edge.source, target = edge.target, line = edge.line,
171
+ call = edge.site.recv .. '.emit', kind = 'possible event delivery (same local Node EventEmitter and literal event)',
172
+ registered_at = G.files[f].path .. ':' .. edge.site.registered_at }) end
173
+ end
174
+ end
175
+ end
176
+ end
177
+ function C.outgoing(id)
178
+ local out = {}; scan(G.node_file[id], id, nil, out)
179
+ out[id] = out[id] or {}
180
+ for _, edge in ipairs(shared.outgoing(id)) do out[id][#out[id] + 1] = edge end
181
+ C.incomplete = C.incomplete or shared.incomplete
182
+ return out[id]
183
+ end
184
+ function C.incoming(wanted)
185
+ local out, relevant = {}, false
186
+ for id in pairs(wanted) do if supported(G.files[G.node_file[id]]) then relevant = true; break end end
187
+ if not relevant then return out end
188
+ -- Same-file objects can only register local handlers or imported exports.
189
+ -- Reuse the ordinary binding import closure instead of opening every emitter.
190
+ local candidates = ctx.ordinary.candidates(wanted)
191
+ for _, f in ipairs(G.file_order) do control.check(); if candidates[f] then scan(f, nil, wanted, out) end end
192
+ for source, edges in pairs(shared.incoming(wanted)) do
193
+ out[source] = out[source] or {}
194
+ for _, edge in ipairs(edges) do out[source][#out[source] + 1] = edge end
195
+ end
196
+ C.incomplete = C.incomplete or shared.incomplete
197
+ return out
198
+ end
199
+ return C
200
+ end
201
+
202
+ return M
@@ -0,0 +1,47 @@
1
+ -- Small atomic overlays for query-discovered encoding repairs. Bound to the
2
+ -- exact base cache payload; ordinary saves merge them and invalidate the sidecar.
3
+ local M = { MAX_RECORDS = 256, MAX_BYTES = 8 * 1024 * 1024 }
4
+
5
+ function M.load(path, hash, version, root)
6
+ local f = io.open(path .. '.repairs', 'rb')
7
+ if not f then return {} end
8
+ local raw = f:read(M.MAX_BYTES + 1); f:close()
9
+ local ok, records = pcall(function()
10
+ assert(#raw <= M.MAX_BYTES)
11
+ local e = cmsgpack.unpack(raw)
12
+ assert(e.base == hash and e.version == version and e.root == root)
13
+ assert(type(e.payload) == 'string' and e.sha256 == xutils.sha256_hex(e.payload))
14
+ local entries = cmsgpack.unpack(e.payload)
15
+ assert(type(entries) == 'table')
16
+ local count = 0
17
+ for key, rec in pairs(entries) do
18
+ count = count + 1
19
+ assert(count <= M.MAX_RECORDS and type(key) == 'string' and type(rec) == 'table' and rec.path == key)
20
+ end
21
+ return entries
22
+ end)
23
+ return ok and records or {}
24
+ end
25
+
26
+ function M.save(path, hash, version, root, records)
27
+ local count = 0
28
+ for _ in pairs(records) do count = count + 1 end
29
+ if count > M.MAX_RECORDS then return false, 'encoding repair cache record limit reached; a normal index save is required' end
30
+ local payload = cmsgpack.pack(records)
31
+ local blob = cmsgpack.pack({ base = hash, version = version, root = root,
32
+ payload = payload, sha256 = xutils.sha256_hex(payload) })
33
+ if #blob > M.MAX_BYTES then return false, 'encoding repair cache byte limit reached; a normal index save is required' end
34
+ local dir = path:match('^(.*)/[^/]*$') or '.'
35
+ local tmp, err = xutils.temp_file(dir)
36
+ if not tmp then return false, err end
37
+ local f; f, err = io.open(tmp, 'wb')
38
+ if not f then os.remove(tmp); return false, err end
39
+ local wrote, write_err = f:write(blob)
40
+ local closed, close_err = f:close()
41
+ if not wrote or not closed then os.remove(tmp); return false, write_err or close_err end
42
+ local published; published, err = xutils.replace_file(tmp, path .. '.repairs')
43
+ if not published then os.remove(tmp); return false, err end
44
+ return true
45
+ end
46
+
47
+ return M
@@ -6,6 +6,7 @@ local M = {}
6
6
 
7
7
  function M.validate(query, opts)
8
8
  require('codeoutline.explore').validate(query, opts)
9
+ assert(require('codeoutline.query_filters').parse(query).text ~= '', 'callers requires an exact symbol name in addition to filters')
9
10
  opts = opts or {}
10
11
  for _, item in ipairs({ { 'depth', 3, 8 }, { 'max_nodes', 200, 2000 } }) do
11
12
  local value = opts[item[1]]
@@ -15,21 +16,16 @@ function M.validate(query, opts)
15
16
  end
16
17
  end
17
18
 
18
- function M.run(symbols, idx, query, opts)
19
- M.validate(query, opts)
19
+ -- Shared by symbol callers and file-change impact. Ordered targets are bounded below.
20
+ function M.from_targets(symbols, idx, ordered, opts)
20
21
  opts = opts or {}
21
22
  local depth, cap = opts.depth or 3, opts.max_nodes or 200
22
- local budget = require('codeoutline.explore').validate(query, opts)
23
23
  local Q = graph.query(symbols, opts)
24
24
  local result = { targets = {}, callers = {}, files = {}, depth = depth,
25
25
  node_limit_reached = false, depth_limit_reached = false }
26
26
  local function describe(id)
27
27
  return { id = id, name = Q.nodes[id].qualified, file = Q.files[Q.node_file[id]].path, line = Q.nodes[id].line }
28
28
  end
29
- local candidates = symbols.by_qualified[query] or symbols.by_name[query] or {}
30
- local ordered = {}
31
- for _, id in ipairs(candidates) do ordered[#ordered + 1] = id end
32
- table.sort(ordered, function(a, b) return graph.before(Q, a, b) end)
33
29
  local frontier, seen, next_hop = {}, {}, {}
34
30
  for _, id in ipairs(ordered) do
35
31
  if #frontier >= cap then result.node_limit_reached = true; break end
@@ -37,13 +33,11 @@ function M.run(symbols, idx, query, opts)
37
33
  result.targets[#result.targets + 1] = describe(id)
38
34
  end
39
35
  local files = {}
40
- for level = 1, depth do
41
- if #frontier == 0 then break end
42
- control.check()
43
- Q:load_incoming(frontier) -- one project reference scan per layer
36
+ local partial, active_level
37
+ local function append(incoming, level)
44
38
  local pending, links = {}, {}
45
39
  for _, dst in ipairs(frontier) do
46
- local edges = Q.inn[dst] or {}
40
+ local edges = incoming[dst] or rawget(Q.inn, dst) or {}
47
41
  for i = 1, #edges, graph.EDGE do
48
42
  if i % 384 == 1 then control.check() end
49
43
  local src = edges[i]
@@ -73,8 +67,33 @@ function M.run(symbols, idx, query, opts)
73
67
  result.callers[#result.callers + 1] = entry
74
68
  files[entry.file] = true
75
69
  end
76
- if level == depth and #frontier > 0 then result.depth_limit_reached = true end
77
- if result.node_limit_reached then break end
70
+ end
71
+ local previous, expired = control.callback, control.deadline()
72
+ local deadline = opts.time_limit_ms and (xtimer.now_ms() + opts.time_limit_ms)
73
+ if deadline then
74
+ control.callback = function()
75
+ if previous then previous() end
76
+ if xtimer.now_ms() >= deadline then error(expired, 0) end
77
+ end
78
+ end
79
+ local ok, err = pcall(function()
80
+ for level = 1, depth do
81
+ if #frontier == 0 then break end
82
+ control.check()
83
+ active_level, partial = level, nil
84
+ Q:load_incoming(frontier, deadline and function(edges) partial = edges end or nil)
85
+ append(Q.inn, level)
86
+ partial = nil
87
+ if level == depth and #frontier > 0 then result.depth_limit_reached = true end
88
+ if result.node_limit_reached then break end
89
+ end
90
+ end)
91
+ control.callback = previous
92
+ if not ok then
93
+ if err == expired then
94
+ result.time_limit_reached = true
95
+ if partial then append(partial, active_level) end
96
+ else error(err, 0) end
78
97
  end
79
98
  for file in pairs(files) do result.files[#result.files + 1] = file end
80
99
  table.sort(result.files)
@@ -88,7 +107,26 @@ function M.run(symbols, idx, query, opts)
88
107
  assert(source, 'cannot read source: ' .. path)
89
108
  changed = changed or repaired
90
109
  end
91
- if changed then return nil, { encoding_retry = true } end
110
+ if changed then return { encoding_retry = true } end
111
+ result.relationships_incomplete = Q.incomplete or false
112
+ result.query_stats = Q.stats
113
+ return result
114
+ end
115
+
116
+ function M.run(symbols, idx, query, opts)
117
+ M.validate(query, opts)
118
+ opts = opts or {}
119
+ local filters = require('codeoutline.query_filters').parse(query)
120
+ local candidates = symbols.by_qualified[filters.text] or symbols.by_name[filters.text] or {}
121
+ local ordered = {}
122
+ for _, id in ipairs(candidates) do
123
+ if require('codeoutline.query_filters').id(filters, symbols, id) then ordered[#ordered + 1] = id end
124
+ end
125
+ table.sort(ordered, function(a, b) return graph.before(symbols, a, b) end)
126
+ local result = M.from_targets(symbols, idx, ordered, opts)
127
+ if result.encoding_retry then return nil, result end
128
+ local depth = opts.depth or 3
129
+ local budget = require('codeoutline.explore').validate(query, opts)
92
130
  local lines = { string.format('Matched %d target(s); %d potential callers in %d files, searched up to %d levels.',
93
131
  #result.targets, #result.callers, #result.files, depth),
94
132
  'Static potential impact; each caller has one shortest path. This is not proof of runtime execution or complete impact coverage.' }
@@ -96,6 +134,8 @@ function M.run(symbols, idx, query, opts)
96
134
  if #result.targets > 1 then lines[#lines + 1] = 'Multiple definitions matched; results cover the listed targets.' end
97
135
  if result.node_limit_reached then lines[#lines + 1] = 'Node limit reached; targets or callers were omitted.' end
98
136
  if result.depth_limit_reached then lines[#lines + 1] = 'Depth limit reached; callers beyond this depth were not checked.' end
137
+ if result.relationships_incomplete then lines[#lines + 1] = 'Relationships incomplete: '
138
+ .. table.concat(require('codeoutline.coverage').relations(result), ', ') .. '.' end
99
139
  for _, target in ipairs(result.targets) do
100
140
  lines[#lines + 1] = string.format('Target: %s (%s:%d)', target.name, target.file, target.line)
101
141
  end
@@ -109,7 +149,7 @@ function M.run(symbols, idx, query, opts)
109
149
  end
110
150
  if #result.files > 0 then lines[#lines + 1] = 'Affected caller files:\n' .. table.concat(result.files, '\n') end
111
151
  local output, cut = text.limit(table.concat(lines, '\n'), budget, result.node_limit_reached)
112
- result.truncated, result.query_stats = cut, Q.stats
152
+ result.truncated = cut
113
153
  return output, result
114
154
  end
115
155
 
@@ -0,0 +1,125 @@
1
+ -- Finite, non-executing TOML reader for Cargo lookup. Reject unsupported values
2
+ -- in relevant tables; unrelated metadata and array-of-table targets are skipped.
3
+ local M = {}
4
+ local function parse_value(raw)
5
+ local i, n = 1, #raw
6
+ local value
7
+ local function space() while i <= n and raw:sub(i, i):match('%s') do i = i + 1 end end
8
+ local function string_value()
9
+ local quote, first = raw:sub(i, i), i
10
+ i = i + 1
11
+ local escaped = false
12
+ while i <= n do
13
+ local c = raw:sub(i, i)
14
+ if c == quote and not escaped then
15
+ local text = raw:sub(first, i); i = i + 1
16
+ if quote == "'" then return text:sub(2, -2) end
17
+ local ok, decoded = pcall(xutils.json_unpack, text)
18
+ if not ok then error('unsupported Cargo TOML string', 0) end
19
+ return decoded
20
+ end
21
+ escaped = quote == '"' and c == '\\' and not escaped
22
+ i = i + 1
23
+ end
24
+ error('unterminated Cargo TOML string', 0)
25
+ end
26
+ value = function(depth)
27
+ if depth > 16 then error('Cargo TOML nesting limit reached', 0) end
28
+ space()
29
+ local c = raw:sub(i, i)
30
+ if c == '"' or c == "'" then return string_value() end
31
+ if c == '[' or c == '{' then
32
+ local object, result = c == '{', {}; i = i + 1; space()
33
+ local close = object and '}' or ']'
34
+ while raw:sub(i, i) ~= close do
35
+ if i > n then error('unterminated Cargo TOML collection', 0) end
36
+ local key
37
+ if object then
38
+ if raw:sub(i, i) == '"' or raw:sub(i, i) == "'" then key = string_value()
39
+ else key = raw:match('^([%w_-]+)', i); if key then i = i + #key end end
40
+ space()
41
+ if not key or raw:sub(i, i) ~= '=' then error('unsupported Cargo TOML key', 0) end
42
+ i = i + 1
43
+ if result[key] ~= nil then error('duplicate Cargo TOML key', 0) end
44
+ end
45
+ local item = value(depth + 1)
46
+ if object then result[key] = item else result[#result + 1] = item end
47
+ space()
48
+ if raw:sub(i, i) == ',' then i = i + 1; space()
49
+ elseif raw:sub(i, i) ~= close then error('unsupported Cargo TOML collection', 0) end
50
+ end
51
+ i = i + 1; return result
52
+ end
53
+ local word = raw:match('^([^,%s}%]]+)', i)
54
+ if word == 'true' then i = i + 4; return true end
55
+ if word == 'false' then i = i + 5; return false end
56
+ if word and tonumber(word) then i = i + #word; return tonumber(word) end
57
+ error('unsupported Cargo TOML value', 0)
58
+ end
59
+ local result = value(0); space()
60
+ if i <= n then error('unsupported Cargo TOML value suffix', 0) end
61
+ return result
62
+ end
63
+
64
+ local function clean(raw)
65
+ local out, quote, escaped, comment = {}, nil, false, false
66
+ for i = 1, #raw do
67
+ local c = raw:sub(i, i)
68
+ if comment then
69
+ if c == '\n' then comment = false; out[#out + 1] = c end
70
+ elseif quote then
71
+ out[#out + 1] = c
72
+ if c == quote and not escaped then quote = nil end
73
+ escaped = quote == '"' and c == '\\' and not escaped
74
+ elseif c == '#' then comment = true
75
+ else
76
+ out[#out + 1] = c
77
+ if c == '"' or c == "'" then quote = c; escaped = false end
78
+ end
79
+ end
80
+ return table.concat(out)
81
+ end
82
+
83
+ function M.parse(raw)
84
+ local result, section, pending, balance, quote, escaped = {}, '', '', 0, nil, false
85
+ local function relevant(s)
86
+ return s == 'package' or s == 'lib' or s == 'workspace' or s == 'dependencies'
87
+ or s == 'workspace.dependencies' or s:match('^dependencies%.') or s:match('^workspace%.dependencies%.')
88
+ end
89
+ local function statement(line)
90
+ line = line:match('^%s*(.-)%s*$')
91
+ if line == '' then return end
92
+ if line:sub(1, 2) == '[[' then section = ''; return end
93
+ if line:sub(1, 1) == '[' then
94
+ section = line:match('^%[([%w_.-]+)%]$') or ''
95
+ if relevant(section) then result[section] = result[section] or {} end
96
+ return
97
+ end
98
+ if not relevant(section) then return end
99
+ local key, raw_value = line:match('^([%w_.-]+)%s*=%s*(.+)$')
100
+ if not key then error('unsupported Cargo TOML assignment', 0) end
101
+ local entries = result[section]
102
+ if entries[key] ~= nil then error('duplicate Cargo TOML assignment', 0) end
103
+ entries[key] = parse_value(raw_value)
104
+ end
105
+ for line in (clean(raw) .. '\n'):gmatch('(.-)\r?\n') do
106
+ if pending == '' and line:match('^%s*%[') then statement(line)
107
+ else
108
+ for i = 1, #line do
109
+ local c = line:sub(i, i)
110
+ if quote then
111
+ if c == quote and not escaped then quote = nil end
112
+ escaped = quote == '"' and c == '\\' and not escaped
113
+ elseif c == '"' or c == "'" then quote = c; escaped = false
114
+ elseif c == '[' or c == '{' then balance = balance + 1
115
+ elseif c == ']' or c == '}' then balance = balance - 1 end
116
+ end
117
+ pending = pending .. line .. '\n'
118
+ if balance == 0 and not quote then statement(pending); pending = '' end
119
+ end
120
+ end
121
+ if pending:match('%S') or quote or balance ~= 0 then error('incomplete Cargo TOML value', 0) end
122
+ return result
123
+ end
124
+
125
+ return M
@@ -20,6 +20,9 @@ Usage:
20
20
  codeoutline serve --http [--host HOST] [--port PORT] [--project PATH] [--allow-root PATH ...]
21
21
  codeoutline explore --project PATH --query QUERY [--budget BYTES]
22
22
  codeoutline callers --project PATH --query SYMBOL [--depth 3] [--max-nodes 200] [--budget BYTES]
23
+ codeoutline affected --project PATH --file FILE [--file FILE ...] [--files-from PATH|-] [--depth 3] [--max-nodes 200] [--budget BYTES]
24
+ codeoutline type-hierarchy --project PATH --query TYPE [--direction both|ancestors|descendants] [--depth 8] [--max-nodes 200] [--budget BYTES]
25
+ codeoutline type-references --project PATH --query TYPE [--max-nodes 200] [--budget BYTES]
23
26
  codeoutline status [--project PATH]
24
27
  codeoutline rebuild [--project PATH]
25
28
  codeoutline doctor [--project PATH]
@@ -62,6 +65,9 @@ local function parse(args)
62
65
  daemon = { port = true }, install = { port = true, npm = true }, uninstall = { port = true },
63
66
  explore = { project = true, query = true, budget = true },
64
67
  callers = { project = true, query = true, budget = true, depth = true, ['max-nodes'] = true },
68
+ affected = { project = true, file = true, ['files-from'] = true, budget = true, depth = true, ['max-nodes'] = true },
69
+ ['type-hierarchy'] = { project = true, query = true, budget = true, depth = true, ['max-nodes'] = true, direction = true },
70
+ ['type-references'] = { project = true, query = true, budget = true, ['max-nodes'] = true },
65
71
  update = { check = true, channel = true },
66
72
  status = { project = true }, rebuild = { project = true }, doctor = { project = true },
67
73
  }
@@ -81,7 +87,7 @@ local function parse(args)
81
87
  assert(value and not value:match('^%-%-'), 'missing value for --' .. name)
82
88
  end
83
89
  assert(value ~= '', 'empty value for --' .. name)
84
- if name:match('^allow-') then
90
+ if name:match('^allow-') or name == 'file' then
85
91
  options[name] = options[name] or {}
86
92
  table.insert(options[name], value)
87
93
  else
@@ -239,13 +245,29 @@ local function run()
239
245
  local root = options.project or '.'
240
246
  if command == 'doctor' then return doctor(root) end
241
247
  local svc = require('codeoutline.service')
242
- if command == 'explore' or command == 'callers' then
243
- assert(options.query, command .. ' requires --query')
248
+ if command == 'explore' or command == 'callers' or command == 'type-hierarchy' or command == 'type-references' or command == 'affected' then
249
+ local query = options.query
250
+ if command == 'affected' then
251
+ query = options.file or {}
252
+ if options['files-from'] then
253
+ local from = options['files-from']
254
+ local f = from == '-' and io.stdin or assert(io.open(from, 'rb'))
255
+ local raw = f:read(65537) or ''
256
+ if from ~= '-' then f:close() end
257
+ assert(#raw <= 65536, '--files-from exceeds 64 KiB')
258
+ raw = raw:gsub('^\239\187\191', '')
259
+ for line in (raw .. '\n'):gmatch('(.-)\n') do
260
+ line = line:gsub('\r$', '')
261
+ if line ~= '' then query[#query + 1] = line end
262
+ end
263
+ end
264
+ else assert(query, command .. ' requires --query') end
244
265
  local budget
245
266
  if options.budget then budget = assert(tonumber(options.budget), '--budget must be a number') end
246
267
  local depth = options.depth and assert(tonumber(options.depth), '--depth must be a number')
247
268
  local max_nodes = options['max-nodes'] and assert(tonumber(options['max-nodes']), '--max-nodes must be a number')
248
- local text = svc[command](root, options.query, { budget = budget, depth = depth, max_nodes = max_nodes })
269
+ local text = svc[command:gsub('-', '_')](root, query,
270
+ { budget = budget, depth = depth, max_nodes = max_nodes, direction = options.direction })
249
271
  io.write(text, '\n')
250
272
  else
251
273
  io.write(xutils.json_pack(svc[command](root)), '\n')