@codua/codeoutline-win32-x64 0.3.3 → 0.3.6

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 (100) hide show
  1. package/README.md +13 -1
  2. package/README.zh-CN.md +11 -1
  3. package/bin/xnet.exe +0 -0
  4. package/build-info.json +1 -1
  5. package/editors/codeoutline.vsix +0 -0
  6. package/editors/zed/extension.wasm +0 -0
  7. package/package.json +1 -1
  8. package/scripts/codeoutline/{automatic_events.lua → analysis/automatic_events.lua} +4 -4
  9. package/scripts/codeoutline/{cpp_bindings.lua → analysis/cpp/cpp_bindings.lua} +7 -7
  10. package/scripts/codeoutline/{cpp_implementations.lua → analysis/cpp/cpp_implementations.lua} +3 -3
  11. package/scripts/codeoutline/{cpp_includes.lua → analysis/cpp/cpp_includes.lua} +3 -3
  12. package/scripts/codeoutline/{cpp_macros.lua → analysis/cpp/cpp_macros.lua} +3 -3
  13. package/scripts/codeoutline/{cpp_receivers.lua → analysis/cpp/cpp_receivers.lua} +7 -7
  14. package/scripts/codeoutline/{cpp_types.lua → analysis/cpp/cpp_types.lua} +5 -5
  15. package/scripts/codeoutline/{csharp_bindings.lua → analysis/csharp/csharp_bindings.lua} +1 -1
  16. package/scripts/codeoutline/{dispatch_aliases.lua → analysis/dispatch_aliases.lua} +3 -3
  17. package/scripts/codeoutline/{foreign.lua → analysis/foreign.lua} +2 -2
  18. package/scripts/codeoutline/{function_values.lua → analysis/function_values.lua} +2 -2
  19. package/scripts/codeoutline/analysis/go/go_frameworks.lua +327 -0
  20. package/scripts/codeoutline/{go_methods.lua → analysis/go/go_methods.lua} +2 -2
  21. package/scripts/codeoutline/{go_modules.lua → analysis/go/go_modules.lua} +2 -2
  22. package/scripts/codeoutline/{graph.lua → analysis/graph.lua} +53 -47
  23. package/scripts/codeoutline/{implementations.lua → analysis/implementations.lua} +16 -9
  24. package/scripts/codeoutline/{indirect.lua → analysis/indirect.lua} +71 -13
  25. package/scripts/codeoutline/{js_evidence.lua → analysis/js/js_evidence.lua} +4 -3
  26. package/scripts/codeoutline/{js_resolution.lua → analysis/js/js_resolution.lua} +2 -2
  27. package/scripts/codeoutline/{js_workspace.lua → analysis/js/js_workspace.lua} +2 -2
  28. package/scripts/codeoutline/{ts_implementations.lua → analysis/js/ts_implementations.lua} +3 -3
  29. package/scripts/codeoutline/{foreign_lua.lua → analysis/lua/foreign_lua.lua} +3 -3
  30. package/scripts/codeoutline/{lua_bindings.lua → analysis/lua/lua_bindings.lua} +97 -11
  31. package/scripts/codeoutline/{lua_callback_loops.lua → analysis/lua/lua_callback_loops.lua} +1 -1
  32. package/scripts/codeoutline/{ordinary_bindings.lua → analysis/ordinary_bindings.lua} +45 -21
  33. package/scripts/codeoutline/{python_bindings.lua → analysis/python/python_bindings.lua} +2 -2
  34. package/scripts/codeoutline/analysis/receivers.lua +547 -0
  35. package/scripts/codeoutline/{rust_packages.lua → analysis/rust/rust_packages.lua} +2 -2
  36. package/scripts/codeoutline/analysis/rust/rust_resolution.lua +609 -0
  37. package/scripts/codeoutline/{shared_events.lua → analysis/shared_events.lua} +3 -3
  38. package/scripts/codeoutline/{static_dispatch.lua → analysis/static_dispatch.lua} +5 -5
  39. package/scripts/codeoutline/{type_uses.lua → analysis/type_uses.lua} +1 -1
  40. package/scripts/codeoutline/cli.lua +1 -1
  41. package/scripts/codeoutline/command.lua +10 -8
  42. package/scripts/codeoutline/{cpp_fragments.lua → indexing/cpp_fragments.lua} +4 -4
  43. package/scripts/codeoutline/{index.lua → indexing/index.lua} +12 -12
  44. package/scripts/codeoutline/{parse_pool.lua → indexing/parse_pool.lua} +1 -1
  45. package/scripts/codeoutline/{agent_config.lua → install/agent_config.lua} +21 -1
  46. package/scripts/codeoutline/{agent_install.lua → install/agent_install.lua} +2 -2
  47. package/scripts/codeoutline/{editor_install.lua → install/editor_install.lua} +34 -6
  48. package/scripts/codeoutline/lang/c.lua +2 -2
  49. package/scripts/codeoutline/lang/cpp.lua +2 -2
  50. package/scripts/codeoutline/lang/csharp.lua +2 -2
  51. package/scripts/codeoutline/lang/go.lua +2 -2
  52. package/scripts/codeoutline/lang/java.lua +2 -2
  53. package/scripts/codeoutline/lang/js.lua +2 -2
  54. package/scripts/codeoutline/lang/kotlin.lua +4 -2
  55. package/scripts/codeoutline/lang/lua.lua +3 -3
  56. package/scripts/codeoutline/lang/python.lua +2 -2
  57. package/scripts/codeoutline/lang/rust.lua +3 -3
  58. package/scripts/codeoutline/main.lua +9 -9
  59. package/scripts/codeoutline/{common.lua → parsing/common.lua} +22 -17
  60. package/scripts/codeoutline/{language_detect.lua → parsing/language_detect.lua} +1 -1
  61. package/scripts/codeoutline/{parse.lua → parsing/parse.lua} +4 -4
  62. package/scripts/codeoutline/{http.lua → protocol/http.lua} +1 -1
  63. package/scripts/codeoutline/{lsp.lua → protocol/lsp.lua} +4 -4
  64. package/scripts/codeoutline/{mcp.lua → protocol/mcp.lua} +9 -9
  65. package/scripts/codeoutline/{affected.lua → query/affected.lua} +6 -6
  66. package/scripts/codeoutline/{callers.lua → query/callers.lua} +9 -9
  67. package/scripts/codeoutline/{completion.lua → query/completion.lua} +37 -49
  68. package/scripts/codeoutline/{definition_candidates.lua → query/definition_candidates.lua} +6 -6
  69. package/scripts/codeoutline/{documents.lua → query/documents.lua} +4 -4
  70. package/scripts/codeoutline/{explore.lua → query/explore.lua} +85 -25
  71. package/scripts/codeoutline/{external_headers.lua → query/external_headers.lua} +6 -6
  72. package/scripts/codeoutline/{navigation.lua → query/navigation.lua} +53 -54
  73. package/scripts/codeoutline/{on_demand.lua → query/on_demand.lua} +6 -6
  74. package/scripts/codeoutline/{query_report.lua → query/query_report.lua} +9 -5
  75. package/scripts/codeoutline/{search_ranking.lua → query/search_ranking.lua} +10 -7
  76. package/scripts/codeoutline/{type_hierarchy.lua → query/type_hierarchy.lua} +11 -11
  77. package/scripts/codeoutline/{type_references.lua → query/type_references.lua} +17 -17
  78. package/scripts/codeoutline/{index_worker.lua → runtime/index_worker.lua} +10 -10
  79. package/scripts/codeoutline/{parse_worker.lua → runtime/parse_worker.lua} +2 -2
  80. package/scripts/codeoutline/{update_worker.lua → runtime/update_worker.lua} +1 -1
  81. package/scripts/codeoutline/service.lua +11 -11
  82. package/scripts/codeoutline/update_sequence.lua +1 -1
  83. package/scripts/codeoutline/version.lua +1 -1
  84. package/scripts/codeoutline/rust_resolution.lua +0 -301
  85. /package/scripts/codeoutline/{lua_literal.lua → analysis/lua/lua_literal.lua} +0 -0
  86. /package/scripts/codeoutline/{resolution.lua → analysis/resolution.lua} +0 -0
  87. /package/scripts/codeoutline/{cargo_toml.lua → analysis/rust/cargo_toml.lua} +0 -0
  88. /package/scripts/codeoutline/{type_bases.lua → analysis/type_bases.lua} +0 -0
  89. /package/scripts/codeoutline/{cache_repairs.lua → indexing/cache_repairs.lua} +0 -0
  90. /package/scripts/codeoutline/{daemon.lua → install/daemon.lua} +0 -0
  91. /package/scripts/codeoutline/{install_prompt.lua → install/install_prompt.lua} +0 -0
  92. /package/scripts/codeoutline/{xscan.lua → parsing/xscan.lua} +0 -0
  93. /package/scripts/codeoutline/{lsp_trace.lua → protocol/lsp_trace.lua} +0 -0
  94. /package/scripts/codeoutline/{coverage.lua → query/coverage.lua} +0 -0
  95. /package/scripts/codeoutline/{query_filters.lua → query/query_filters.lua} +0 -0
  96. /package/scripts/codeoutline/{idle_gc.lua → runtime/idle_gc.lua} +0 -0
  97. /package/scripts/codeoutline/{control.lua → shared/control.lua} +0 -0
  98. /package/scripts/codeoutline/{path.lua → shared/path.lua} +0 -0
  99. /package/scripts/codeoutline/{rules.lua → shared/rules.lua} +0 -0
  100. /package/scripts/codeoutline/{text.lua → shared/text.lua} +0 -0
@@ -0,0 +1,609 @@
1
+ -- Rust crate/module evidence is produced only for queries, never serialized.
2
+ local M = { MAX_DEPTH = 16, MAX_RESULTS = 128, MAX_ALIAS_FILES = 64, MAX_NODES = 8192 }
3
+ local cargo, control = require('codeoutline.analysis.rust.rust_packages'), require('codeoutline.shared.control')
4
+ local function join(a, b) return a == '' and b or b == '' and a or a .. '::' .. b end
5
+ local function text(T, i) return i >= 1 and i <= T.n and T:text(i) or '' end
6
+
7
+ -- Keep complete impl targets in query evidence; compact declaration names omit
8
+ -- module prefixes and generic arguments and cannot identify an impl's type.
9
+ local function impl_header(T, node)
10
+ local i = node.ti
11
+ while i < node.tj and text(T, i) ~= 'impl' do i = i + 1 end
12
+ i = i + 1
13
+ local function angle_end(at)
14
+ local depth = 0
15
+ for j = at, node.tj do
16
+ local token = text(T, j)
17
+ if token == '<' then depth = depth + 1
18
+ elseif token == '>' then depth = depth - 1
19
+ elseif token == '>>' then depth = depth - 2 end
20
+ if depth <= 0 then return j + 1 end
21
+ end
22
+ return node.tj
23
+ end
24
+ local generics, constrained = {}, false
25
+ if text(T, i) == '<' then
26
+ local finish = angle_end(i)
27
+ for j = i + 1, finish - 2 do
28
+ if T.k[j] == 'id' and (text(T, j - 1) == '<' or text(T, j - 1) == ',') then generics[text(T, j)] = true
29
+ elseif text(T, j) ~= ',' then constrained = true end
30
+ end
31
+ i = finish
32
+ end
33
+ local first, trait, depth, last = i, nil, 0, i - 1
34
+ for j = i, node.tj do
35
+ local token = text(T, j)
36
+ if depth == 0 and (token == 'where' or token == '{') then
37
+ if token == 'where' then constrained = true end
38
+ break
39
+ end
40
+ if token == 'for' and depth == 0 then
41
+ local parts = {}; for k = first, j - 1 do parts[#parts + 1] = text(T, k) end
42
+ trait, first = table.concat(parts), j + 1
43
+ end
44
+ if token == '<' then depth = depth + 1
45
+ elseif token == '>' then depth = depth - 1
46
+ elseif token == '>>' then depth = depth - 2 end
47
+ last = j
48
+ end
49
+ local path, args, target = {}, {}, {}
50
+ local j = first
51
+ while j <= last do
52
+ local token = text(T, j); target[#target + 1] = token
53
+ if token == '<' then
54
+ local finish = angle_end(j)
55
+ for k = j, finish - 1 do args[#args + 1] = text(T, k) end
56
+ j = finish
57
+ elseif T.k[j] == 'id' or T.k[j] == 'kw' or token == '::' then
58
+ path[#path + 1] = token; j = j + 1
59
+ else return { target = table.concat(target), trait = trait } end
60
+ end
61
+ return { path = table.concat(path), args = table.concat(args), trait = trait, generics = generics, constrained = constrained }
62
+ end
63
+
64
+ local function compatible_args(candidate, current)
65
+ if candidate.args == current.args then
66
+ if candidate.constrained and candidate ~= current then return nil end
67
+ return true
68
+ end
69
+ if not candidate.args or not current.args then return false end
70
+ local pattern = candidate.args:match('^<([%w_,]+)>$')
71
+ if not pattern then return false end
72
+ local args, first, depth = {}, 2, 0
73
+ for i = 2, #current.args do
74
+ local c = current.args:sub(i, i)
75
+ if c == ',' and depth == 0 or i == #current.args then args[#args + 1] = current.args:sub(first, i - 1); first = i + 1
76
+ elseif c == '<' or c == '(' or c == '[' then depth = depth + 1
77
+ elseif c == '>' or c == ')' or c == ']' then depth = depth - 1 end
78
+ end
79
+ local at, bindings = 0, {}
80
+ for name in pattern:gmatch('[^,]+') do
81
+ at = at + 1
82
+ if not args[at] then return false end
83
+ if candidate.generics[name] then
84
+ if bindings[name] and bindings[name] ~= args[at] then return false end
85
+ bindings[name] = args[at]
86
+ elseif name ~= args[at] then return false end
87
+ end
88
+ if at ~= #args then return false end
89
+ if candidate.constrained then return nil end
90
+ return true
91
+ end
92
+
93
+ function M.collect(r, T)
94
+ r.rust_imports, r.rust_public, r.rust_impls, r.rust_instance, r.has_bindings = {}, {}, {}, {}, true
95
+ for n, node in ipairs(r.nodes) do
96
+ r.rust_public[n] = text(T, node.ti) == 'pub' and text(T, node.ti + 1) ~= '('
97
+ if node.kind == 'impl' then r.rust_impls[n] = impl_header(T, node) end
98
+ if node.kind == 'method' then
99
+ local p = node.ti
100
+ while p < node.tj and text(T, p) ~= '(' do p = p + 1 end
101
+ for i = p + 1, (T.m[p] or p) - 1 do
102
+ if text(T, i) == ',' then break end
103
+ if text(T, i) == 'self' then r.rust_instance[n] = true; break end
104
+ end
105
+ end
106
+ end
107
+ for i = 1, T.n do
108
+ if text(T, i) == 'use' then
109
+ local parent, in_function, last, j = nil, false, i + 1, i + 1
110
+ for n, node in ipairs(r.nodes) do
111
+ if node.ti <= i and i <= node.tj then
112
+ if node.kind == 'namespace' then parent = n
113
+ elseif node.kind == 'function' or node.kind == 'method' then in_function = true end
114
+ end
115
+ end
116
+ while j <= T.n and text(T, j) ~= ';' do
117
+ if T.m[j] and T.m[j] > j then j = T.m[j] end
118
+ j = j + 1
119
+ end
120
+ last = j - 1
121
+ local cursor, count = i + 1, 0
122
+ if text(T, cursor) == '::' then cursor = cursor + 1 end
123
+ local branch
124
+ branch = function(prefix, depth)
125
+ if depth > M.MAX_DEPTH then error('Rust use nesting limit reached', 0) end
126
+ local path = prefix
127
+ while cursor <= last do
128
+ local token = text(T, cursor)
129
+ if token == '{' then
130
+ cursor = cursor + 1
131
+ while cursor <= last and text(T, cursor) ~= '}' do
132
+ branch(path, depth + 1)
133
+ if text(T, cursor) == ',' then cursor = cursor + 1 else break end
134
+ end
135
+ if text(T, cursor) ~= '}' then error('unsupported Rust use group', 0) end
136
+ cursor = cursor + 1; return
137
+ end
138
+ if token == '' or token == ',' or token == '}' then break end
139
+ if token ~= 'self' or path == '' then path = join(path, token) end
140
+ cursor = cursor + 1
141
+ if text(T, cursor) == '::' then cursor = cursor + 1 else break end
142
+ end
143
+ local alias = path:match('([^:]+)$')
144
+ if text(T, cursor) == 'as' then alias = text(T, cursor + 1); cursor = cursor + 2 end
145
+ count = count + 1
146
+ if count > M.MAX_RESULTS then error('Rust use binding limit reached', 0) end
147
+ if not in_function then r.rust_imports[#r.rust_imports + 1] = { path = path, alias = alias,
148
+ parent = parent, public = text(T, i - 1) == 'pub', line = T:line(i) } end
149
+ end
150
+ branch('', 0)
151
+ end
152
+ end
153
+ for _, ref in ipairs(r.refs) do
154
+ local i, path = ref.tok, ref.name
155
+ if text(T, i - 1) == '.' then ref.binding = 'rust:member'
156
+ else
157
+ while text(T, i - 1) == '::' and (T.k[i - 2] == 'id' or T.k[i - 2] == 'kw') do
158
+ path, i = text(T, i - 2) .. '::' .. path, i - 2
159
+ end
160
+ ref.binding = 'rust:path:' .. path
161
+ end
162
+ end
163
+ end
164
+
165
+ local function data(G, f, ctx)
166
+ local rec = G.files[f]
167
+ if rec.rust_imports then return rec end
168
+ return ctx.ordinary and cargo.guard(ctx, function() return ctx.ordinary.data(f) end) or rec
169
+ end
170
+ local function scope_of(G, f, src)
171
+ local node = src and G.nodes[src]
172
+ local p = node and node.parent
173
+ while p do
174
+ local owner = G.files[f].nodes[p]
175
+ if owner.kind == 'namespace' then return owner.qualified end
176
+ p = owner.parent
177
+ end
178
+ return ''
179
+ end
180
+ local function parent_scope(G, f, p) return p and G.files[f].nodes[p].qualified or '' end
181
+ local function nodes(G, f, ctx)
182
+ local list = G.files[f].nodes
183
+ if #list > M.MAX_NODES then
184
+ ctx.rust_incomplete, ctx.rust_error = true, 'Rust module node limit reached'
185
+ return {}
186
+ end
187
+ return list
188
+ end
189
+ local function child(G, entry, name, ctx)
190
+ local wanted, found = join(entry.scope, name), nil
191
+ local rec, detail = G.files[entry.file], data(G, entry.file, ctx)
192
+ for n, node in ipairs(nodes(G, entry.file, ctx)) do
193
+ if node.kind == 'namespace' and node.qualified == wanted then
194
+ if entry.external and not (detail.rust_public or {})[n] then return nil end
195
+ local external = false
196
+ for _, imp in ipairs(rec.imports) do if imp.kind == 'mod' and imp.path == name then external = true; break end end
197
+ if not external then return { file = entry.file, scope = wanted, external = entry.external, root = entry.root } end
198
+ local path = rec.path
199
+ local directory, stem = cargo.dir(path), path:match('([^/]+)%.rs$')
200
+ if not entry.root and stem ~= 'lib' and stem ~= 'main' and stem ~= 'mod' then directory = cargo.join(directory, stem) end
201
+ if entry.scope ~= '' then directory = cargo.join(directory, entry.scope:gsub('::', '/')) end
202
+ for _, candidate in ipairs({ cargo.join(directory, name .. '.rs'), cargo.join(directory, name .. '/mod.rs') }) do
203
+ local id = G.file_index[candidate]
204
+ if id then
205
+ if found then return nil end
206
+ if cargo.owner(G, id, ctx) ~= cargo.owner(G, entry.file, ctx) then return nil end
207
+ found = { file = id, scope = '', external = entry.external }
208
+ end
209
+ end
210
+ return found
211
+ end
212
+ end
213
+ end
214
+
215
+ local walk
216
+ local function terminal(G, entry, name, ctx, seen, depth)
217
+ local result, rec, detail = {}, G.files[entry.file], data(G, entry.file, ctx)
218
+ local wanted = join(entry.scope, name)
219
+ for n, node in ipairs(nodes(G, entry.file, ctx)) do
220
+ if node.qualified == wanted and node.kind ~= 'namespace'
221
+ and (not entry.external or (detail.rust_public or {})[n]) then
222
+ result[#result + 1] = G.id_of[entry.file][n]
223
+ end
224
+ end
225
+ if #result > 0 then return { ids = result } end
226
+ for _, imp in ipairs(detail.rust_imports or {}) do
227
+ if imp.alias == name and parent_scope(G, entry.file, imp.parent) == entry.scope
228
+ and (not entry.external or imp.public) then
229
+ local found = walk(G, entry.file, imp.path, ctx, entry.scope, seen, depth + 1)
230
+ if entry.external and found and found.ids then
231
+ local visible = {}
232
+ for _, id in ipairs(found.ids) do
233
+ local f = G.node_file[id]
234
+ for n, local_id in ipairs(G.id_of[f]) do
235
+ if local_id == id and (data(G, f, ctx).rust_public or {})[n] then visible[#visible + 1] = id end
236
+ end
237
+ end
238
+ found.ids = visible
239
+ end
240
+ return found
241
+ end
242
+ end
243
+ end
244
+ walk = function(G, f, path, ctx, scope, seen, depth)
245
+ control.check()
246
+ if depth > M.MAX_DEPTH then error('Rust module resolution depth limit reached', 0) end
247
+ local key = G.files[f].path .. '\0' .. scope .. '\0' .. path
248
+ if seen[key] then return nil end
249
+ seen[key] = true
250
+ local parts = {}; for name in path:gmatch('[^:]+') do parts[#parts + 1] = name end
251
+ if #parts == 0 then return nil end
252
+ local owner = cargo.owner(G, f, ctx)
253
+ if not owner then return nil end
254
+ local first, index, entry = parts[1], 2, nil
255
+ if first == 'crate' then
256
+ local id = cargo.entry(G, owner, ctx, f)
257
+ if id then entry = { file = id, scope = '', root = true } end
258
+ elseif first == 'self' then entry = { file = f, scope = scope, root = cargo.entry(G, owner, ctx, f) == f }
259
+ elseif first == 'super' then
260
+ if scope ~= '' then entry = { file = f, scope = scope:match('^(.*)::[^:]+$') or '', root = cargo.entry(G, owner, ctx, f) == f }
261
+ else
262
+ local root = cargo.entry(G, owner, ctx, f)
263
+ if root and root ~= f then
264
+ local directory = cargo.dir(G.files[f].path)
265
+ if G.files[f].path:match('/mod%.rs$') then directory = cargo.dir(directory) end
266
+ local candidates = directory == cargo.dir(G.files[root].path) and { G.files[root].path }
267
+ or { directory .. '.rs', cargo.join(directory, 'mod.rs') }
268
+ for _, candidate in ipairs(candidates) do
269
+ local id = G.file_index[candidate]
270
+ if id and cargo.owner(G, id, ctx) == owner then
271
+ if entry then return nil end
272
+ entry = { file = id, scope = '', root = id == root }
273
+ end
274
+ end
275
+ end
276
+ end
277
+ else
278
+ for _, imp in ipairs(data(G, f, ctx).rust_imports or {}) do
279
+ if imp.alias == first and parent_scope(G, f, imp.parent) == scope then
280
+ local replacement = imp.path
281
+ if #parts > 1 then replacement = replacement .. '::' .. table.concat(parts, '::', 2) end
282
+ if replacement ~= path then return walk(G, f, replacement, ctx, scope, seen, depth + 1) end
283
+ end
284
+ end
285
+ local id = cargo.crates(G, f, ctx)[first]
286
+ if id then entry = { file = id, scope = '', external = cargo.owner(G, id, ctx) ~= owner, root = true }
287
+ else entry, index = { file = f, scope = scope }, 1 end
288
+ end
289
+ if not entry then return nil end
290
+ if first == 'super' and parts[2] == 'super' then
291
+ return walk(G, entry.file, table.concat(parts, '::', 2), ctx, entry.scope, seen, depth + 1)
292
+ end
293
+ while index <= #parts do
294
+ local next_entry = child(G, entry, parts[index], ctx)
295
+ if next_entry then entry = next_entry
296
+ else
297
+ local found = terminal(G, entry, parts[index], ctx, seen, depth)
298
+ if index == #parts then return found end
299
+ if found and found.module then
300
+ found.module.external = entry.external; entry = found.module
301
+ elseif found and found.ids and index + 1 == #parts then
302
+ local ids = {}
303
+ for _, type_id in ipairs(found.ids) do
304
+ local ty, tf = G.nodes[type_id], G.node_file[type_id]
305
+ for _, id in ipairs(G.by_name[parts[index + 1]] or {}) do
306
+ local method, mf = G.nodes[id], G.node_file[id]
307
+ if mf == tf and method.kind == 'method' and method.qualified == ty.qualified .. '::' .. parts[index + 1] then
308
+ for n, local_id in ipairs(G.id_of[mf]) do
309
+ if local_id == id and (not entry.external or (data(G, mf, ctx).rust_public or {})[n]) then ids[#ids + 1] = id end
310
+ end
311
+ end
312
+ end
313
+ end
314
+ return { ids = ids }
315
+ else return nil end
316
+ end
317
+ index = index + 1
318
+ end
319
+ return { module = entry }
320
+ end
321
+
322
+ function M.path(G, f, path, ctx, scope)
323
+ return cargo.guard(ctx, walk, G, f, path, ctx, scope or '', {}, 0)
324
+ end
325
+
326
+ local function type_id(G, f, path, scope, ctx, kind)
327
+ if not path or path == '' then return nil end
328
+ if cargo.owner(G, f, ctx) then
329
+ local found = M.path(G, f, path, ctx, scope)
330
+ local id
331
+ for _, candidate in ipairs(found and found.ids or {}) do
332
+ local node = G.nodes[candidate]
333
+ if kind and node.kind == kind or not kind and (node.kind == 'struct' or node.kind == 'enum') then
334
+ if id then return nil end
335
+ id = candidate
336
+ end
337
+ end
338
+ return id
339
+ end
340
+ -- Standalone files have no Cargo module graph. Stay inside their lexical
341
+ -- namespaces instead of matching a same-named type in another file.
342
+ if path:match('^crate::') then path, scope = path:sub(8), ''
343
+ elseif path:match('^self::') then path = path:sub(7)
344
+ else
345
+ while path:match('^super::') do
346
+ path, scope = path:sub(8), scope:match('^(.*)::[^:]+$') or ''
347
+ end
348
+ end
349
+ local wanted, found = join(scope, path), nil
350
+ for n, node in ipairs(nodes(G, f, ctx)) do
351
+ if node.qualified == wanted and (kind and node.kind == kind
352
+ or not kind and (node.kind == 'struct' or node.kind == 'enum')) then
353
+ if found then return nil end
354
+ found = G.id_of[f][n]
355
+ end
356
+ end
357
+ return found
358
+ end
359
+
360
+ local function self_targets(G, f, src, member, ctx)
361
+ local parent = src and G.nodes[src] and G.nodes[src].parent
362
+ local rec = G.files[f]
363
+ while parent do
364
+ local owner = rec.nodes[parent]
365
+ if owner.kind == 'impl' or owner.kind == 'interface' then
366
+ local own = {}
367
+ for n, candidate in ipairs(nodes(G, f, ctx)) do
368
+ if candidate.parent == parent and candidate.name == member
369
+ and (candidate.kind == 'method' or candidate.kind == 'constant') then own[#own + 1] = G.id_of[f][n] end
370
+ end
371
+ if owner.kind == 'interface' then return own, 'Rust trait Self binding' end
372
+ local header = (data(G, f, ctx).rust_impls or {})[parent]
373
+ local scope = scope_of(G, f, src)
374
+ local target = header and type_id(G, f, header.path, scope, ctx)
375
+ if target then
376
+ local inherent, files, count, candidates, truncated, constrained = {}, {}, 0, 0, false, false
377
+ for i, id in ipairs(G.by_name[member] or {}) do
378
+ if i > M.MAX_NODES then ctx.rust_incomplete, truncated = true, true; break end
379
+ control.check()
380
+ local mf, method = G.node_file[id], G.nodes[id]
381
+ local impl = method.parent and G.files[mf].nodes[method.parent]
382
+ local plausible = impl and (impl.name == owner.name or impl.name == G.nodes[target].name)
383
+ if impl and not plausible then
384
+ for _, imp in ipairs(G.files[mf].imports or {}) do
385
+ for _, alias in ipairs(imp.type_aliases or {}) do
386
+ if alias.alias == impl.name and alias.name == G.nodes[target].name then plausible = true end
387
+ end
388
+ end
389
+ end
390
+ -- Names only narrow discovery; query-only target paths and
391
+ -- generic arguments below establish the actual type identity.
392
+ if impl and impl.kind == 'impl' and not impl.trait
393
+ and plausible
394
+ and (method.kind == 'method' or method.kind == 'constant')
395
+ and (mf == f or cargo.owner(G, mf, ctx) == cargo.owner(G, f, ctx) and cargo.owner(G, f, ctx)) then
396
+ candidates = candidates + 1
397
+ if candidates > M.MAX_RESULTS then ctx.rust_incomplete, truncated = true, true; break end
398
+ if not files[mf] then files[mf] = true; count = count + 1 end
399
+ if count > M.MAX_ALIAS_FILES then ctx.rust_incomplete, truncated = true, true; break end
400
+ local other = (data(G, mf, ctx).rust_impls or {})[method.parent]
401
+ if other and type_id(G, mf, other.path, parent_scope(G, mf, impl.parent), ctx) == target then
402
+ local compatible = compatible_args(other, header)
403
+ if compatible then inherent[#inherent + 1] = id
404
+ elseif compatible == nil then constrained = true end
405
+ end
406
+ end
407
+ end
408
+ if #inherent > 0 then return inherent, 'Rust inherent Self binding' end
409
+ if truncated then return {}, 'Rust Self candidate scan limit reached' end
410
+ if constrained then return {}, 'Rust Self generic constraints are not proven' end
411
+ end
412
+ if #own > 0 then return own, 'Rust lexical impl binding' end
413
+ local trait = header and header.trait and type_id(G, f, header.trait:gsub('%b<>', ''), scope, ctx, 'interface')
414
+ if trait then
415
+ local tf, index = G.node_file[trait], trait - G.id_of[G.node_file[trait]][1] + 1
416
+ local result = {}
417
+ for n, candidate in ipairs(nodes(G, tf, ctx)) do
418
+ if candidate.parent == index and candidate.name == member
419
+ and (candidate.kind == 'method' or candidate.kind == 'constant') then result[#result + 1] = G.id_of[tf][n] end
420
+ end
421
+ return result, 'Rust trait default Self binding'
422
+ end
423
+ return {}, 'Self member is not declared in a resolved impl or trait'
424
+ end
425
+ parent = owner.parent
426
+ end
427
+ return {}, 'Self has no enclosing impl or trait'
428
+ end
429
+
430
+ function M.resolve(G, f, src, name, recv, evidence, ctx)
431
+ if evidence == 'rust:member' then return nil end
432
+ local path = evidence and evidence:match('^rust:path:(.*)$') or (recv and recv .. '::' .. name or name)
433
+ if path:match('^Self::') then
434
+ local member = path:match('^Self::([%w_]+)$')
435
+ if not member then return {}, 'unsupported Self path' end
436
+ local key = tostring(src) .. '\0' .. member
437
+ local cache = ctx.rust_self_cache or {}; ctx.rust_self_cache = cache
438
+ if cache[key] then return cache[key][1], cache[key][2] end
439
+ local ids, reason = self_targets(G, f, src, member, ctx)
440
+ if (ctx.rust_self_count or 0) < M.MAX_RESULTS then
441
+ cache[key] = { ids, reason }; ctx.rust_self_count = (ctx.rust_self_count or 0) + 1
442
+ end
443
+ return ids, reason
444
+ end
445
+ if not cargo.owner(G, f, ctx) then return ctx.rust_incomplete and {} or nil, ctx.rust_error end
446
+ local found, reason = M.path(G, f, path, ctx, scope_of(G, f, src))
447
+ return found and found.ids or {}, reason or 'Cargo crate/module target is not indexed or visible'
448
+ end
449
+
450
+ function M.self_members(G, f, src, ctx, expired)
451
+ local parent = src and G.nodes[src] and G.nodes[src].parent
452
+ while parent do
453
+ local owner = G.files[f].nodes[parent]
454
+ if owner.kind == 'impl' or owner.kind == 'interface' then
455
+ local names, result, count = {}, {}, 0
456
+ local function collect(file, index)
457
+ for _, candidate in ipairs(nodes(G, file, ctx)) do
458
+ if candidate.parent == index and (candidate.kind == 'method' or candidate.kind == 'constant') then
459
+ names[candidate.name] = true
460
+ end
461
+ end
462
+ end
463
+ collect(f, parent)
464
+ local function owned(name)
465
+ for i, id in ipairs(G.by_owner[name] or {}) do
466
+ if i > M.MAX_NODES then ctx.rust_incomplete = true; break end
467
+ names[G.nodes[id].name] = true
468
+ end
469
+ end
470
+ owned(owner.name)
471
+ local header = owner.kind == 'impl' and (data(G, f, ctx).rust_impls or {})[parent]
472
+ local target = header and type_id(G, f, header.path, scope_of(G, f, src), ctx)
473
+ if target then owned(G.nodes[target].name) end
474
+ local trait = header and header.trait and type_id(G, f, header.trait:gsub('%b<>', ''), scope_of(G, f, src), ctx, 'interface')
475
+ if trait then collect(G.node_file[trait], trait - G.id_of[G.node_file[trait]][1] + 1) end
476
+ local ordered = {}; for name in pairs(names) do ordered[#ordered + 1] = name end; table.sort(ordered)
477
+ for _, name in ipairs(ordered) do
478
+ if expired and expired() then ctx.rust_incomplete = true; break end
479
+ count = count + 1
480
+ if count > M.MAX_RESULTS then ctx.rust_incomplete = true; break end
481
+ for _, id in ipairs(M.resolve(G, f, src, name, 'Self', 'rust:path:Self::' .. name, ctx)) do
482
+ result[#result + 1] = { name = name, node = G.nodes[id], file = G.node_file[id], kind = G.nodes[id].kind, id = id }
483
+ end
484
+ end
485
+ return result
486
+ end
487
+ parent = owner.parent
488
+ end
489
+ return {}
490
+ end
491
+
492
+ local function receiver_fields(G, f, src, ctx)
493
+ local parent = src and G.nodes[src] and G.nodes[src].parent
494
+ while parent do
495
+ local owner = G.files[f].nodes[parent]
496
+ if owner.kind == 'impl' then
497
+ local header = (data(G, f, ctx).rust_impls or {})[parent]
498
+ local target = header and type_id(G, f, header.path, scope_of(G, f, src), ctx)
499
+ local result = {}
500
+ if target then
501
+ local tf = G.node_file[target]
502
+ for n, node in ipairs(nodes(G, tf, ctx)) do
503
+ if node.kind == 'field' and node.parent and G.id_of[tf][node.parent] == target then
504
+ result[#result + 1] = G.id_of[tf][n]
505
+ end
506
+ end
507
+ end
508
+ return result
509
+ end
510
+ parent = owner.parent
511
+ end
512
+ return {}
513
+ end
514
+
515
+ function M.receiver_targets(G, f, src, name, instance, ctx, accept)
516
+ if instance and (not src or not (data(G, f, ctx).rust_instance or {})[src - G.id_of[f][1] + 1]) then return {} end
517
+ local ids = M.resolve(G, f, src, name, 'Self', 'rust:path:Self::' .. name, ctx)
518
+ if not instance then return ids end
519
+ local result = {}
520
+ for _, id in ipairs(ids) do
521
+ local tf = G.node_file[id]
522
+ local index = id - G.id_of[tf][1] + 1
523
+ if (data(G, tf, ctx).rust_instance or {})[index] then result[#result + 1] = id end
524
+ end
525
+ if not accept or accept.field then
526
+ for _, id in ipairs(receiver_fields(G, f, src, ctx)) do if G.nodes[id].name == name then result[#result + 1] = id end end
527
+ end
528
+ return result
529
+ end
530
+
531
+ function M.receiver_members(G, f, src, instance, ctx, expired)
532
+ if instance and (not src or not (data(G, f, ctx).rust_instance or {})[src - G.id_of[f][1] + 1]) then return {} end
533
+ local result = M.self_members(G, f, src, ctx, expired)
534
+ if not instance then return result end
535
+ local filtered = {}
536
+ for _, entry in ipairs(result) do
537
+ local index = entry.id - G.id_of[entry.file][1] + 1
538
+ if (data(G, entry.file, ctx).rust_instance or {})[index] then filtered[#filtered + 1] = entry end
539
+ end
540
+ for _, id in ipairs(receiver_fields(G, f, src, ctx)) do
541
+ filtered[#filtered + 1] = { name = G.nodes[id].name, node = G.nodes[id], kind = 'field', file = G.node_file[id] }
542
+ end
543
+ return filtered
544
+ end
545
+ function M.imports(G, f, imp, ctx)
546
+ if not cargo.owner(G, f, ctx) then return ctx.rust_incomplete and {} or nil end
547
+ local result, seen = {}, {}
548
+ local function add(id) if id and not seen[id] then seen[id] = true; result[#result + 1] = id end end
549
+ if imp.kind == 'mod' then
550
+ local entry = child(G, { file = f, scope = '' }, imp.path, ctx)
551
+ if entry then add(entry.file) end
552
+ else
553
+ for _, binding in ipairs(data(G, f, ctx).rust_imports or {}) do
554
+ if binding.line == imp.line then
555
+ local found = M.path(G, f, binding.path, ctx, parent_scope(G, f, binding.parent))
556
+ if found then
557
+ if found.module then add(found.module.file) end
558
+ for _, id in ipairs(found.ids or {}) do add(G.node_file[id]) end
559
+ end
560
+ end
561
+ end
562
+ end
563
+ return result
564
+ end
565
+ function M.members(G, entry, ctx)
566
+ return cargo.guard(ctx, function()
567
+ local result, names, detail = {}, {}, data(G, entry.file, ctx)
568
+ for n, node in ipairs(nodes(G, entry.file, ctx)) do
569
+ if node.kind ~= 'impl' and parent_scope(G, entry.file, node.parent) == entry.scope
570
+ and (not entry.external or (detail.rust_public or {})[n]) then
571
+ names[node.name] = true
572
+ result[#result + 1] = { name = node.name, node = node, file = entry.file, kind = node.kind }
573
+ end
574
+ end
575
+ for _, imp in ipairs(detail.rust_imports or {}) do
576
+ if imp.public and imp.alias ~= '*' and not names[imp.alias]
577
+ and parent_scope(G, entry.file, imp.parent) == entry.scope then
578
+ local found = M.path(G, entry.file, imp.path, ctx, entry.scope)
579
+ for _, id in ipairs(found and found.ids or {}) do
580
+ result[#result + 1] = { name = imp.alias, node = G.nodes[id], file = G.node_file[id], kind = G.nodes[id].kind }
581
+ end
582
+ end
583
+ end
584
+ if #result > M.MAX_RESULTS then error('Rust module member limit reached', 0) end
585
+ return result
586
+ end) or {}
587
+ end
588
+
589
+ function M.alias_refs(G, f, wanted, ctx)
590
+ local rec = G.files[f]
591
+ if rec.language ~= 'rust' or #rec.imports == 0 or not cargo.owner(G, f, ctx) then return {} end
592
+ local relevant = false
593
+ for id in pairs(wanted) do
594
+ local target = cargo.owner(G, G.node_file[id], ctx)
595
+ if cargo.reaches(G, f, target, ctx) then relevant = true end
596
+ end
597
+ if not relevant then return {} end
598
+ ctx.rust_alias_files = ctx.rust_alias_files or {}
599
+ if not ctx.rust_alias_files[f] then
600
+ ctx.rust_alias_count = (ctx.rust_alias_count or 0) + 1
601
+ if ctx.rust_alias_count > M.MAX_ALIAS_FILES then ctx.rust_incomplete = true; return {} end
602
+ ctx.rust_alias_files[f] = true
603
+ end
604
+ local refs, result = data(G, f, ctx).refs, {}
605
+ for i, binding in ipairs(refs.binding or {}) do if binding:match('^rust:path:') then result[i] = true end end
606
+ return result
607
+ end
608
+ M.scope = scope_of
609
+ return M
@@ -1,7 +1,7 @@
1
1
  -- Query-owned ES module EventEmitter identities. Indexing keeps only role bits.
2
2
  local M = { MAX_FILES = 32, MAX_BYTES = 2097152, MAX_FILE_BYTES = 262144,
3
3
  MAX_SITES = 512, MAX_TARGETS = 64, MAX_DEPTH = 8, MAX_MS = 200 }
4
- local control = require('codeoutline.control')
4
+ local control = require('codeoutline.shared.control')
5
5
  local methods = { emit = 1, on = 2, once = 2, addListener = 2,
6
6
  off = 4, removeListener = 4, removeAllListeners = 4 }
7
7
  local function supported(r) return r.language == 'javascript' or r.language == 'typescript' end
@@ -53,7 +53,7 @@ function M.collect(r, T)
53
53
  end
54
54
  end
55
55
  if not candidate then return end
56
- local expand, binding = require('codeoutline.dispatch_aliases').prepare(r, T)
56
+ local expand, binding = require('codeoutline.analysis.dispatch_aliases').prepare(r, T)
57
57
  local result = { objects = {}, exports = {}, entities = {}, sites = {}, weight = 0 }
58
58
  r.shared_events = result
59
59
  local headers, classes, skip, objects, refs, variables = {}, {}, {}, {}, {}, {}
@@ -172,7 +172,7 @@ function M.context(G, ctx, report)
172
172
  incomplete_reasons = reasons } }
173
173
  local function incomplete(reason) C.incomplete = true; reasons[reason] = true end
174
174
  ctx.shared_event_context = C
175
- local js = require('codeoutline.js_resolution')
175
+ local js = require('codeoutline.analysis.js.js_resolution')
176
176
  local cache, identities, buses, started = {}, {}, {}, nil
177
177
  local all_files, emitting = nil, {}
178
178
  local function files()
@@ -1,6 +1,6 @@
1
1
  -- Bounded static registrations, derived on demand; never evaluate source.
2
2
  local M = {}
3
- local control = require('codeoutline.control')
3
+ local control = require('codeoutline.shared.control')
4
4
  local callable = { ['function'] = true, method = true, constructor = true }
5
5
 
6
6
  local function site_key(from, line, recv, name)
@@ -63,7 +63,7 @@ function M.collect(r, T)
63
63
  local executable
64
64
  for _, node in ipairs(r.nodes) do if callable[node.kind] then executable = true; break end end
65
65
  if not executable then return end
66
- local loops = lua and r.ordinary_bindings and require('codeoutline.lua_callback_loops').tokens_candidate(T)
66
+ local loops = lua and r.ordinary_bindings and require('codeoutline.analysis.lua.lua_callback_loops').tokens_candidate(T)
67
67
  -- Reject cheap negatives before collecting compact query hints.
68
68
  for i = 1, T.n do
69
69
  if i % 4096 == 0 then control.check() end
@@ -437,7 +437,7 @@ function M.collect(r, T)
437
437
  end
438
438
  ::continue::
439
439
  end
440
- if loops then require('codeoutline.lua_callback_loops').collect(r, T, {
440
+ if loops then require('codeoutline.analysis.lua.lua_callback_loops').collect(r, T, {
441
441
  binding = binding, parts = parts, scopes = scopes, ends = ends,
442
442
  owners = owners, function_target = function_target, assignment_end = assignment_end,
443
443
  }) end
@@ -465,7 +465,7 @@ function M.collect(r, T)
465
465
  end
466
466
 
467
467
  function M.query(G, report, ctx)
468
- local graph = require('codeoutline.graph')
468
+ local graph = require('codeoutline.analysis.graph')
469
469
  local cache, entries = {}, 0
470
470
  local empty = { sites = {} }
471
471
  local function remember(f, result)
@@ -492,7 +492,7 @@ function M.query(G, report, ctx)
492
492
  if rec.encoding ~= 'utf-8' and rec.encoding ~= 'utf-8-bom' then
493
493
  source = assert(xutils.to_utf8(raw, rec.encoding == 'gbk' and 'gbk' or 'auto'))
494
494
  end
495
- local parsed = require('codeoutline.parse').parse(rec.path, source,
495
+ local parsed = require('codeoutline.parsing.parse').parse(rec.path, source,
496
496
  { ranges = false, dispatch_only = true, static_dispatch = true, language = rec.language })
497
497
  assert(#parsed.nodes == #rec.nodes, 'source encoding changed; refresh index: ' .. rec.path)
498
498
  for i, n in ipairs(parsed.nodes) do