@codua/codeoutline-win32-x64 0.3.3 → 0.3.7

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} +78 -41
  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} +18 -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} +136 -12
  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 +559 -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} +19 -13
  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} +172 -57
  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,559 @@
1
+ -- Query-owned receiver bindings shared by graph, navigation and completion.
2
+ -- Language adapters establish identity; names alone never establish ownership.
3
+ local M = { MAX_BINDINGS = 8192, MAX_CANDIDATES = 512, MAX_DEPTH = 16 }
4
+ local control = require('codeoutline.shared.control')
5
+ local classes = { class = true, interface = true, struct = true, record = true, enum = true, union = true }
6
+ local callable = { ['function'] = true, method = true, constructor = true }
7
+ local function js(language) return language == 'javascript' or language == 'typescript' or language == 'arkts' end
8
+
9
+ function M.at(meta, name, offset)
10
+ local best, index, future
11
+ for _, i in ipairs(meta and meta.by_name[name] or {}) do
12
+ local b = meta.bindings[i]
13
+ if b.first <= offset and offset < b.last and b.at <= offset
14
+ and (not best or b.first > best.first or b.first == best.first and b.at > best.at) then best, index = b, i end
15
+ if b.hoisted and b.first <= offset and offset < b.last and b.at > offset
16
+ and (not future or b.first > future.first) then future = b end
17
+ end
18
+ if future and (not best or future.first > best.first) then return { blocked = true }, 0 end
19
+ return best, index
20
+ end
21
+
22
+ function M.collect(r, T)
23
+ local language = r.language
24
+ if language ~= 'python' and language ~= 'kotlin' and not js(language) then return end
25
+ local meta = { bindings = {}, by_name = {}, statics = {}, fields = {}, weight = 128 }
26
+ r.receivers = meta
27
+ local function add(name, token, first, last, value)
28
+ if #meta.bindings >= M.MAX_BINDINGS then meta.incomplete = true; return end
29
+ local b = { name = name, at = token > 0 and T.s[token] - 1 or 0, first = first, last = last,
30
+ owner = value and value.owner, type = value and value.type, static = value and value.static,
31
+ super = value and value.super }
32
+ local n = #meta.bindings + 1; meta.bindings[n] = b
33
+ meta.by_name[name] = meta.by_name[name] or {}; table.insert(meta.by_name[name], n)
34
+ meta.weight = meta.weight + 192 + #name + #(b.type or '')
35
+ if name == 'this' and js(language) then
36
+ add('super', token, first, last, { owner = b.owner, type = b.type, static = b.static, super = true })
37
+ end
38
+ return b
39
+ end
40
+ local function text(i) return i >= 1 and i <= T.n and T:text(i) or '' end
41
+ local function bounds(node) return T.s[node.ti] - 1, T.e[node.tj] + 1 end
42
+ local function enclosing(i)
43
+ local found, index
44
+ for n, node in ipairs(r.nodes) do
45
+ if callable[node.kind] and node.ti <= i and i <= node.tj
46
+ and (not found or node.tj - node.ti < found.tj - found.ti) then found, index = node, n end
47
+ end
48
+ return found, index
49
+ end
50
+ local function written(i)
51
+ if T.k[i] ~= 'id' then return nil end
52
+ local parts = { text(i) }; local j = i + 1
53
+ while text(j) == '.' and T.k[j + 1] == 'id' do parts[#parts + 1] = text(j + 1); j = j + 2 end
54
+ return table.concat(parts, '.'), j
55
+ end
56
+ if language == 'kotlin' then
57
+ local declarations = {}
58
+ for _, node in ipairs(r.nodes) do
59
+ if callable[node.kind] then
60
+ for i = node.ti, node.tj do
61
+ if text(i) == '(' then declarations[i - 1] = true; break end
62
+ if text(i) == '{' then break end
63
+ end
64
+ local first, last = bounds(node)
65
+ local p = node.parent
66
+ while p and not classes[r.nodes[p].kind] do p = r.nodes[p].parent end
67
+ local value = node.receiver and { type = node.receiver } or p and { owner = p }
68
+ add('this', node.ti, first, last, value)
69
+ if node.receiver then add('this@' .. node.name, node.ti, first, last, value) end
70
+ while p do
71
+ add('this@' .. r.nodes[p].name, node.ti, first, last, { owner = p })
72
+ if not (r.nodes[p].sig or ''):match('%f[%a]inner%f[%A]') then break end
73
+ p = r.nodes[p].parent
74
+ while p and not classes[r.nodes[p].kind] do p = r.nodes[p].parent end
75
+ end
76
+ end
77
+ end
78
+ local function value(at)
79
+ local name = text(at)
80
+ if T.k[at] == 'id' and text(at + 1) == '(' then return { type = name } end
81
+ local best
82
+ for _, b in ipairs((T.jvm_bindings or {})[name] or {}) do
83
+ if b.token <= at and b.first <= at and at <= b.last
84
+ and (not best or b.first > best.first or b.first == best.first and b.token > best.token) then best = b end
85
+ end
86
+ return best and best.type and { type = best.type } or nil
87
+ end
88
+ for i = 1, T.n do
89
+ local body, bound, label
90
+ if not declarations[i] and text(i) == 'with' and text(i + 1) == '(' and T.m[i + 1] then
91
+ body, bound, label = T.m[i + 1] + 1, value(i + 2), 'with'
92
+ elseif not declarations[i] and (text(i) == 'run' or text(i) == 'apply') and text(i - 1) == '.' then
93
+ body, label = text(i + 1) == '(' and T.m[i + 1] and T.m[i + 1] + 1 or i + 1, text(i)
94
+ local at = text(i - 2) == ')' and T.m[i - 2] and T.m[i - 2] - 1 or i - 2
95
+ bound = value(at)
96
+ end
97
+ if body and text(body) == '{' and T.m[body] then
98
+ for _, node in ipairs(r.nodes) do if node.name == label and callable[node.kind] then bound = nil end end
99
+ for _, imp in ipairs(r.imports) do if (imp.alias or imp.path:match('([^.]+)$')) == label then bound = nil end end
100
+ add('this', body, T.s[body] - 1, T.e[T.m[body]] + 1, bound)
101
+ add('this@' .. label, body, T.s[body] - 1, T.e[T.m[body]] + 1, bound)
102
+ if text(i - 1) == '@' and T.k[i - 2] == 'id' then
103
+ add('this@' .. text(i - 2), body, T.s[body] - 1, T.e[T.m[body]] + 1, bound)
104
+ end
105
+ end
106
+ end
107
+ elseif language == 'python' then
108
+ add('self', 0, 0, #T.src + 1); add('cls', 0, 0, #T.src + 1)
109
+ for n, node in ipairs(r.nodes) do
110
+ if callable[node.kind] then
111
+ local p = node.ti
112
+ while p < node.tj and text(p) ~= 'def' do p = p + 1 end
113
+ p = p + 2
114
+ local close = text(p) == '(' and T.m[p]
115
+ if close then
116
+ local first, last = bounds(node)
117
+ local owner = node.parent and classes[r.nodes[node.parent].kind] and node.parent
118
+ local static, classmethod = false, false
119
+ for _, decorator in ipairs(node.decorators or {}) do
120
+ static = static or decorator == 'staticmethod'
121
+ classmethod = classmethod or decorator == 'classmethod'
122
+ end
123
+ for i = p + 1, close - 1 do
124
+ if T.k[i] == 'id' and (i == p + 1 or text(i - 1) == ',') then
125
+ local value = text(i + 1) == ':' and { type = written(i + 2) } or nil
126
+ if i == p + 1 and owner and not static then value = { owner = owner, static = classmethod } end
127
+ add(text(i), i, first, last, value)
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+ local depth, brackets = 0, {}
134
+ for i = 1, T.n do
135
+ if i % 1024 == 0 then control.check() end
136
+ local prev, next = text(i - 1), text(i + 1)
137
+ if T.k[i] == 'id' and prev ~= '.' and depth == 0 and
138
+ (next == '=' or next == ':=' or prev == 'for' and next == 'in') then
139
+ local node = enclosing(i)
140
+ local first, last = 0, #T.src + 1
141
+ if node then first, last = bounds(node) end
142
+ local value
143
+ if next == '=' or next == ':=' then
144
+ local name, after = written(i + 2)
145
+ if name and text(after) == '(' then value = { type = name }
146
+ elseif name then value = M.at(meta, name, T.s[i] - 1) end
147
+ end
148
+ local b = add(text(i), i, first, last, value)
149
+ if b then b.hoisted = true end
150
+ end
151
+ if T.k[i] == 'id' and prev == 'for' and next == 'in' and depth > 0 then
152
+ local open = brackets[#brackets]
153
+ if open and T.m[open] then
154
+ local b = add(text(i), i, T.s[open] - 1, T.e[T.m[open]] + 1)
155
+ if b then b.hoisted = true end
156
+ end
157
+ end
158
+ if text(i) == 'lambda' then
159
+ local colon = i + 1
160
+ while colon < T.n and text(colon) ~= ':' do
161
+ if T.m[colon] and T.m[colon] > colon then colon = T.m[colon] end
162
+ colon = colon + 1
163
+ end
164
+ local last = colon + 1
165
+ while last <= T.n and T.k[last] ~= 'nl' and text(last) ~= ',' and text(last) ~= ';'
166
+ and text(last) ~= ')' and text(last) ~= ']' and text(last) ~= '}' do
167
+ last = (T.m[last] and T.m[last] > last and T.m[last] or last) + 1
168
+ end
169
+ for j = i + 1, colon - 1 do
170
+ if T.k[j] == 'id' and (j == i + 1 or text(j - 1) == ',') then
171
+ add(text(j), j, T.s[i] - 1, T.s[last] and T.s[last] - 1 or #T.src + 1)
172
+ end
173
+ end
174
+ end
175
+ if text(i) == '(' or text(i) == '[' or text(i) == '{' then depth = depth + 1; brackets[#brackets + 1] = i
176
+ elseif text(i) == ')' or text(i) == ']' or text(i) == '}' then depth = math.max(0, depth - 1); brackets[#brackets] = nil end
177
+ end
178
+ else
179
+ add('this', 0, 0, #T.src + 1)
180
+ for n, node in ipairs(r.nodes) do
181
+ if callable[node.kind] then
182
+ local first, last = bounds(node)
183
+ local owner = node.parent and classes[r.nodes[node.parent].kind] and node.parent
184
+ local arrow, static = false, false
185
+ for i = node.ti, node.tj do
186
+ if text(i) == '=>' then arrow = true; break end
187
+ if text(i) == 'static' then static = true end
188
+ if text(i) == '{' then break end
189
+ end
190
+ meta.statics[n] = static
191
+ local value = owner and { owner = owner, static = static } or arrow and M.at(meta, 'this', first)
192
+ add('this', node.ti, first, last, value)
193
+ elseif node.kind == 'field' then
194
+ meta.statics[n] = text(node.ti) == 'static'
195
+ end
196
+ end
197
+ -- Anonymous ordinary functions introduce their own dynamic this.
198
+ for i = 1, T.n do
199
+ if text(i) == 'function' then
200
+ local p = i + 1
201
+ while p < T.n and text(p) ~= '(' and text(p) ~= '{' do p = p + 1 end
202
+ local close = T.m[p]
203
+ local body = close and close + 1
204
+ while body and body < T.n and text(body) ~= '{' and text(body) ~= ';' do body = body + 1 end
205
+ if body and T.m[body] then
206
+ local value
207
+ if text(p + 1) == 'this' and text(p + 2) == ':' then value = { type = written(p + 3) } end
208
+ add('this', i, T.s[i] - 1, T.e[T.m[body]] + 1, value)
209
+ end
210
+ end
211
+ end
212
+ local bindings = {}
213
+ for _, list in pairs(T.js_bindings or {}) do for _, b in ipairs(list) do bindings[#bindings + 1] = b end end
214
+ table.sort(bindings, function(a, b) return a.token < b.token end)
215
+ for _, b in ipairs(bindings) do
216
+ local first = b.a > 0 and T.s[b.a] - 1 or 0
217
+ local last = b.b > 0 and T.e[b.b] + 1 or #T.src + 1
218
+ local value = b.type ~= '?' and { type = b.type } or nil
219
+ if text(b.token + 1) == '=' and (text(b.token + 2) == 'this' or T.k[b.token + 2] == 'id') then
220
+ value = value or M.at(meta, text(b.token + 2), T.s[b.token] - 1)
221
+ end
222
+ local added = add(b.name, b.token, first, last, value)
223
+ if added then added.hoisted = b.declaration end
224
+ end
225
+ end
226
+ for _, ref in ipairs(r.refs) do
227
+ if ref.recv and text(ref.tok - 3) ~= '.' and text(ref.tok - 3) ~= '?.' then
228
+ local name = ref.recv
229
+ if language == 'kotlin' and text(ref.tok - 3) == '@' and text(ref.tok - 4) == 'this' then name = 'this@' .. name end
230
+ local _, index = M.at(meta, name, T.s[ref.tok] - 1)
231
+ if index then ref.receiver = 'receiver:' .. index end
232
+ end
233
+ end
234
+ for i = 1, T.n - 3 do
235
+ if T.k[i] == 'id' or text(i) == 'this' then
236
+ if text(i + 1) == '.' and T.k[i + 2] == 'id' and text(i + 3) == '=' then
237
+ local _, index = M.at(meta, text(i), T.s[i] - 1)
238
+ if index then meta.fields[#meta.fields + 1] = { binding = index, name = text(i + 2) }; meta.weight = meta.weight + 96 end
239
+ end
240
+ end
241
+ end
242
+ end
243
+
244
+ local function detail(G, f, ctx)
245
+ local rec = G.files[f]
246
+ return ctx and ctx.ordinary and ctx.ordinary.available(f) and ctx.ordinary.data(f) or rec
247
+ end
248
+
249
+ local function owner(G, f, src)
250
+ local p = src and G.nodes[src].parent
251
+ while p do
252
+ local node = G.files[f].nodes[p]
253
+ if classes[node.kind] then return G.id_of[f][p] end
254
+ p = node.parent
255
+ end
256
+ end
257
+
258
+ function M.types(G, f, written, ctx, scope)
259
+ if not written or not written:match('^[%a_$][%w_$.]*$') then return {} end
260
+ local language, rec = G.files[f].language, G.files[f]
261
+ if language == 'java' or language == 'kotlin' then
262
+ return require('codeoutline.analysis.implementations').types(G, f, written, ctx, scope)
263
+ elseif language == 'csharp' then
264
+ return require('codeoutline.analysis.csharp.csharp_bindings').types(G, f, written, 0, ctx, { scope = scope })
265
+ end
266
+ local head, tail = written:match('^([%w_$]+)%.(.+)$')
267
+ if js(language) then
268
+ for _, imp in ipairs(rec.js_imports or {}) do
269
+ if imp.local_name == (head or written) then
270
+ if tail and imp.imported ~= '*' or not tail and imp.imported == '*' then return {} end
271
+ return require('codeoutline.analysis.js.js_resolution').imported(G, f, imp.path, tail or imp.imported, ctx)
272
+ end
273
+ end
274
+ elseif language == 'python' then
275
+ for _, imp in ipairs(detail(G, f, ctx).python_imports or {}) do
276
+ if imp.name == (head or written) then
277
+ if imp.blocked then return {} end
278
+ return require('codeoutline.analysis.python.python_bindings').imported(G, f, imp.path,
279
+ imp.imported == '*' and (tail or '') or imp.imported .. (tail and '.' .. tail or ''), ctx)
280
+ end
281
+ end
282
+ end
283
+ local result = {}
284
+ for i, id in ipairs(G.by_name[written:match('([^.]+)$')] or {}) do
285
+ if i > M.MAX_CANDIDATES then ctx.receiver_incomplete = true; break end
286
+ local n = G.nodes[id]
287
+ if G.node_file[id] == f and classes[n.kind] and (n.qualified == written or n.name == written) then result[#result + 1] = id end
288
+ end
289
+ return result
290
+ end
291
+
292
+ local function from_binding(G, f, b, ctx)
293
+ if not b then return nil end
294
+ local ids = b.owner and { G.id_of[f][b.owner] } or M.types(G, f, b.type, ctx)
295
+ if b.super then
296
+ local bases = {}
297
+ for _, id in ipairs(ids) do
298
+ for _, base in ipairs(G.nodes[id].extends or G.nodes[id].bases or {}) do
299
+ for _, bid in ipairs(M.types(G, G.node_file[id], base, ctx, G.nodes[id].qualified)) do bases[#bases + 1] = bid end
300
+ end
301
+ end
302
+ ids = bases
303
+ end
304
+ return { kind = 'types', ids = ids, static = b.static, language = G.files[f].language, file = f }
305
+ end
306
+
307
+ local function hierarchy(G, id, ctx, seen, depth)
308
+ seen, depth = seen or {}, depth or 0
309
+ if seen[id] or depth > M.MAX_DEPTH then ctx.receiver_incomplete = true; return nil end
310
+ seen[id] = true
311
+ local node, f = G.nodes[id], G.node_file[id]
312
+ local bases = node.bases or node.extends or {}
313
+ local sequences, direct = {}, {}
314
+ for _, base in ipairs(bases) do
315
+ local ids = M.types(G, f, base, ctx, node.qualified)
316
+ if #ids ~= 1 then ctx.receiver_incomplete = true; seen[id] = nil; return nil end
317
+ local chain = hierarchy(G, ids[1], ctx, seen, depth + 1)
318
+ if not chain then seen[id] = nil; return nil end
319
+ sequences[#sequences + 1] = chain; direct[#direct + 1] = ids[1]
320
+ end
321
+ sequences[#sequences + 1] = direct
322
+ local result = { id }
323
+ while true do
324
+ local candidate, remaining
325
+ for _, sequence in ipairs(sequences) do
326
+ if #sequence > 0 then
327
+ remaining = true
328
+ local eligible = true
329
+ for _, other in ipairs(sequences) do
330
+ for j = 2, #other do if other[j] == sequence[1] then eligible = false end end
331
+ end
332
+ if eligible then candidate = sequence[1]; break end
333
+ end
334
+ end
335
+ if not remaining then break end
336
+ if not candidate or #result >= M.MAX_CANDIDATES then ctx.receiver_incomplete = true; seen[id] = nil; return nil end
337
+ result[#result + 1] = candidate
338
+ for _, sequence in ipairs(sequences) do if sequence[1] == candidate then table.remove(sequence, 1) end end
339
+ end
340
+ seen[id] = nil
341
+ return result
342
+ end
343
+
344
+ local function ancestors(G, id, ctx)
345
+ local cache = ctx.receiver_hierarchies or {}; ctx.receiver_hierarchies = cache
346
+ if cache[id] then return cache[id] end
347
+ local result = hierarchy(G, id, ctx) or { id }
348
+ if (ctx.receiver_hierarchy_count or 0) < M.MAX_CANDIDATES then
349
+ ctx.receiver_hierarchy_count = (ctx.receiver_hierarchy_count or 0) + 1; cache[id] = result
350
+ end
351
+ return result
352
+ end
353
+
354
+ local function field_visible(target, bound)
355
+ if js(target.language) then return not not target.static == not not bound.static end
356
+ return target.language ~= 'python' or not target.static or bound.static == true
357
+ end
358
+
359
+ function M.member_ids(G, target, name, ctx, accept)
360
+ local result = {}
361
+ for _, cls in ipairs(target.ids or {}) do
362
+ local chain = ancestors(G, cls, ctx)
363
+ for _, id in ipairs(chain or {}) do
364
+ local found, f, shadowed = {}, G.node_file[id], false
365
+ local meta = detail(G, f, ctx).receivers
366
+ for _, field in ipairs(meta and meta.fields or {}) do
367
+ if field.name == name then
368
+ local bound = from_binding(G, f, meta.bindings[field.binding], ctx)
369
+ if bound.ids[1] == id and field_visible(target, bound) then shadowed = true; break end
370
+ end
371
+ end
372
+ if shadowed then break end
373
+ for i, mid in ipairs(G.by_name[name] or {}) do
374
+ if i > M.MAX_CANDIDATES then ctx.receiver_incomplete = true; break end
375
+ local node, mf = G.nodes[mid], G.node_file[mid]
376
+ if mf == f and node.parent and G.id_of[mf][node.parent] == id then
377
+ local n = mid - G.id_of[mf][1] + 1
378
+ if not js(target.language) or not not (meta and meta.statics[n]) == not not target.static then
379
+ shadowed = true
380
+ if not accept or accept[node.kind] then found[#found + 1] = mid end
381
+ end
382
+ end
383
+ end
384
+ if shadowed then for _, mid in ipairs(found) do result[#result + 1] = mid end; break end
385
+ end
386
+ end
387
+ return result
388
+ end
389
+
390
+ function M.binding(G, f, src, name, ctx, options)
391
+ options = options or {}
392
+ local language = G.files[f].language
393
+ if language == 'kotlin' then
394
+ local meta = (options.record or detail(G, f, ctx)).receivers
395
+ if meta and meta.incomplete then ctx.receiver_incomplete = true end
396
+ local index = options.evidence and tonumber(options.evidence:match('^receiver:(%d+)$'))
397
+ local b = index and meta and meta.bindings[index] or options.offset and M.at(meta, name, options.offset)
398
+ if b then return from_binding(G, f, b, ctx) end
399
+ end
400
+ if language == 'lua' and options.tokens then
401
+ local target, bound = require('codeoutline.analysis.lua.lua_bindings').receiver(G, options.record, options.tokens, name, options.offset, ctx.lua)
402
+ if target then return { kind = 'lua', value = target, file = f } end
403
+ if bound then return { kind = 'lua', value = name == 'self' and { lua_self = { members = {}, fields = {} } }
404
+ or { owner = name, local_only = true }, file = f } end
405
+ return nil
406
+ elseif language == 'rust' and (name == 'Self' or name == 'self') then
407
+ return { kind = 'rust', source = src, instance = name == 'self', file = f }
408
+ elseif language == 'go' and options.offset then
409
+ local value = require('codeoutline.analysis.go.go_methods').context(G, ctx).receiver(f, name, options.offset)
410
+ if value ~= nil then return { kind = 'go', value = value, file = f } end
411
+ elseif language == 'python' or js(language) then
412
+ local meta = (options.record or detail(G, f, ctx)).receivers
413
+ if meta and meta.incomplete then ctx.receiver_incomplete = true end
414
+ local index = options.evidence and tonumber(options.evidence:match('^receiver:(%d+)$'))
415
+ local b = index == 0 and { blocked = true } or index and meta and meta.bindings[index]
416
+ or options.offset and M.at(meta, name, options.offset)
417
+ if b and (index or b.blocked or b.owner or b.type or language == 'python' or name == 'this') then return from_binding(G, f, b, ctx) end
418
+ if js(language) and (name == 'this' or name == 'super') or language == 'python' and (name == 'self' or name == 'cls') then
419
+ return { kind = 'types', ids = {}, language = language, file = f }
420
+ end
421
+ elseif (language == 'java' or language == 'kotlin' or language == 'csharp' or language == 'cpp')
422
+ and (name == 'this' or name == 'super' or name == 'base') then
423
+ local cls = owner(G, f, src)
424
+ if language == 'cpp' and not cls and src then cls = require('codeoutline.analysis.cpp.cpp_types').owner(G, f, G.nodes[src], ctx) end
425
+ local ids = cls and { cls } or {}
426
+ if src then
427
+ local index = src - G.id_of[f][1] + 1
428
+ local info = (detail(G, f, ctx).implementation_evidence or {})[index]
429
+ if info and info.static or G.nodes[src].static then ids = {} end
430
+ end
431
+ if language == 'kotlin' and src and G.nodes[src].receiver then ids = M.types(G, f, G.nodes[src].receiver, ctx) end
432
+ if name ~= 'this' and #ids > 0 then
433
+ if language == 'csharp' then
434
+ ids = require('codeoutline.analysis.csharp.csharp_bindings').base_classes(G, ids, ctx)
435
+ else
436
+ local node = cls and G.nodes[cls]
437
+ local bases = node and (language == 'java' and node.extends or node.bases)
438
+ ids = {}
439
+ for _, base in ipairs(bases or {}) do
440
+ for _, id in ipairs(M.types(G, f, base, ctx, node.qualified)) do ids[#ids + 1] = id end
441
+ end
442
+ end
443
+ end
444
+ return { kind = 'types', ids = ids, language = language, file = f }
445
+ end
446
+ end
447
+
448
+ function M.resolve(G, f, src, name, kind, recv, evidence, ctx, accept, offset)
449
+ if not ctx then return nil end
450
+ local language = G.files[f].language
451
+ if language == 'go' then
452
+ local ids, reason = require('codeoutline.analysis.go.go_methods').resolve(G, f, name, recv, evidence, ctx)
453
+ if ids ~= nil then return ids, reason or 'receiver: Go method set' end
454
+ return require('codeoutline.analysis.go.go_modules').resolve(G, f, name, recv, ctx)
455
+ end
456
+ if evidence == '?' or evidence == 'py:?' then return nil end
457
+ if language == 'java' and recv == 'super' and evidence == 'jvm:?' then return {}, 'receiver: qualified Java super' end
458
+ if language == 'lua' and (recv == 'self' or evidence and evidence:match('^lua%-self:')) then
459
+ local ids = require('codeoutline.analysis.lua.lua_bindings').resolve(G, f, name, evidence, ctx.lua, recv)
460
+ return ids or {}, 'receiver: Lua lexical binding'
461
+ elseif language == 'rust' and (recv == 'self' or recv == 'Self' or evidence and evidence:match('^rust:path:Self::')) then
462
+ return require('codeoutline.analysis.rust.rust_resolution').receiver_targets(G, f, src, name, recv == 'self', ctx, accept), 'receiver: Rust impl binding'
463
+ end
464
+ local target = recv and M.binding(G, f, src, recv, ctx, { evidence = evidence, offset = offset })
465
+ if not target then return nil end
466
+ if target.kind == 'types' then
467
+ if language == 'cpp' then
468
+ local ids = {}
469
+ for _, id in ipairs(target.ids) do
470
+ local found = require('codeoutline.analysis.cpp.cpp_bindings').resolve(G, f, src, name,
471
+ 'cpp:type:::' .. G.nodes[id].qualified .. '\0' .. (offset or 0), nil, ctx, accept)
472
+ for _, mid in ipairs(found or {}) do ids[#ids + 1] = mid end
473
+ end
474
+ return ids, 'receiver: C++ this binding'
475
+ elseif language == 'csharp' then
476
+ local cls = owner(G, f, src)
477
+ return require('codeoutline.analysis.csharp.csharp_bindings').members(G, f, target.ids, name, false, ctx,
478
+ cls and G.nodes[cls].qualified, recv == 'base'), 'receiver: C# instance binding'
479
+ elseif language == 'java' or language == 'kotlin' then
480
+ local ids = {}
481
+ for _, id in ipairs(target.ids) do
482
+ local found = require('codeoutline.analysis.implementations').resolve(G, f, src, name,
483
+ 'jvm:type:' .. G.nodes[id].qualified .. '\0' .. (offset or 0), ctx)
484
+ for _, mid in ipairs(found or {}) do ids[#ids + 1] = mid end
485
+ end
486
+ return ids, 'receiver: JVM binding'
487
+ end
488
+ return M.member_ids(G, target, name, ctx, accept), 'receiver: lexical binding'
489
+ end
490
+ end
491
+
492
+ function M.completion(C, item)
493
+ local source = C.fn and C.V.id_of[C.f][C.fn]
494
+ local name = item.name
495
+ if C.language == 'kotlin' then
496
+ for i = 3, C.T.n do
497
+ if C.T:text(i) == name and C.T:text(i - 1) == '@' and C.T:text(i - 2) == 'this'
498
+ and C.T:text(i + 1) == '.' and C.T.s[i + 1] - 1 < C.offset
499
+ and (not C.T.e[i + 2] or C.offset <= C.T.e[i + 2]) then name = 'this@' .. name; break end
500
+ end
501
+ end
502
+ local target = M.binding(C.V, C.f, source, name, C.V.js_context,
503
+ { record = C.rec, tokens = C.T, offset = C.offset })
504
+ return target and { receiver = target }
505
+ end
506
+
507
+ function M.entries(C, target)
508
+ local G, ctx = C.V, C.V.js_context
509
+ if target.kind == 'lua' then
510
+ local info = target.value.lua_self
511
+ if not info then return C:entries(target.value) end
512
+ local out = {}
513
+ for name, n in pairs(info.members) do
514
+ local node = C.rec.nodes[n]
515
+ out[#out + 1] = { name = name, node = node, kind = node.kind, file = C.f }
516
+ end
517
+ for name in pairs(info.fields) do out[#out + 1] = { name = name, kind = 'field' } end
518
+ if target.value.modules then
519
+ for _, entry in ipairs(C:module_members(target.value.modules, target.value.module_name)) do
520
+ if not info.members[entry.name] and not info.fields[entry.name] then out[#out + 1] = entry end
521
+ end
522
+ end
523
+ return out
524
+ end
525
+ if target.kind == 'rust' then
526
+ return require('codeoutline.analysis.rust.rust_resolution').receiver_members(G, C.f, target.source, target.instance, ctx,
527
+ function() return C:expired() end)
528
+ elseif target.kind == 'go' then
529
+ return target.value and require('codeoutline.analysis.go.go_methods').context(G, ctx).members(target.value, C.f) or {}
530
+ end
531
+ if target.kind ~= 'types' then return {} end
532
+ if not js(target.language) and target.language ~= 'python' then return C:members(target.ids) end
533
+ local result, names = {}, {}
534
+ for _, cls in ipairs(target.ids) do
535
+ for _, id in ipairs(ancestors(G, cls, ctx)) do
536
+ if C:expired() then return result end
537
+ local f, n = G.node_file[id], id - G.id_of[G.node_file[id]][1] + 1
538
+ local rec = G.files[f]
539
+ local meta = detail(G, f, ctx).receivers
540
+ for _, field in ipairs(meta and meta.fields or {}) do
541
+ local bound = from_binding(G, f, meta.bindings[field.binding], ctx)
542
+ if bound and bound.ids[1] == id and field_visible(target, bound) and not names[field.name] then
543
+ names[field.name] = true; result[#result + 1] = { name = field.name, kind = 'field' }
544
+ end
545
+ end
546
+ for i, node in ipairs(rec.nodes) do
547
+ if node.parent == n and not names[node.name] then
548
+ for _, mid in ipairs(M.member_ids(G, target, node.name, ctx)) do
549
+ result[#result + 1] = { name = node.name, node = G.nodes[mid], kind = G.nodes[mid].kind, file = G.node_file[mid] }
550
+ end
551
+ names[node.name] = true
552
+ end
553
+ end
554
+ end
555
+ end
556
+ return result
557
+ end
558
+
559
+ return M
@@ -1,7 +1,7 @@
1
1
  -- Local Cargo package identity is configuration evidence owned by one query.
2
2
  local M = { MAX_CONFIGS = 1024, MAX_CONFIG_BYTES = 1048576, MAX_TOTAL_BYTES = 8388608,
3
3
  MAX_DEPENDENCIES = 512, MAX_DEPTH = 32 }
4
- local control, paths = require('codeoutline.control'), require('codeoutline.path')
4
+ local control, paths = require('codeoutline.shared.control'), require('codeoutline.shared.path')
5
5
  local function dir(p) return p:match('^(.*)/[^/]+$') or '' end
6
6
  local function join(a, b) return a == '' and b or b == '' and a or a .. '/' .. b end
7
7
  local function relative(base, p)
@@ -43,7 +43,7 @@ local function context(G, ctx)
43
43
  local raw = file:read(M.MAX_CONFIG_BYTES + 1); file:close()
44
44
  C.bytes = C.bytes + #raw
45
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
46
+ local config = require('codeoutline.analysis.rust.cargo_toml').parse(raw); config.root = root
47
47
  if config.package and (type(config.package.name) ~= 'string' or not config.package.name:match('^[%w_-]+$')) then
48
48
  error('invalid Cargo package name', 0)
49
49
  end