@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
@@ -1,7 +1,7 @@
1
1
  -- Query-owned interface/virtual relationships over existing names and bases.
2
2
  -- These are possible implementations, not evidence of a particular runtime type.
3
3
  local M = { MAX_CANDIDATES = 512, MAX_TARGETS = 64, MAX_DEPTH = 16, MAX_HIERARCHY = 1024 }
4
- local control = require('codeoutline.control')
4
+ local control = require('codeoutline.shared.control')
5
5
  local languages = { csharp = true, java = true, kotlin = true, typescript = true }
6
6
  local types = { class = true, interface = true, struct = true, record = true, enum = true }
7
7
  local callable = { method = true, ['function'] = true, constructor = true }
@@ -55,16 +55,16 @@ local function parameters(T, first, last, language)
55
55
  end
56
56
 
57
57
  function M.collect(r, T)
58
- if r.language == 'go' then return require('codeoutline.go_methods').collect(r, T) end
59
- if r.language == 'cpp' then return require('codeoutline.cpp_implementations').collect(r, T) end
60
- if r.language == 'typescript' then return require('codeoutline.ts_implementations').collect(r, T) end
58
+ if r.language == 'go' then return require('codeoutline.analysis.go.go_methods').collect(r, T) end
59
+ if r.language == 'cpp' then return require('codeoutline.analysis.cpp.cpp_implementations').collect(r, T) end
60
+ if r.language == 'typescript' then return require('codeoutline.analysis.js.ts_implementations').collect(r, T) end
61
61
  if not languages[r.language] then return end
62
62
  local evidence = {}
63
63
  for index, n in ipairs(r.nodes) do
64
64
  if index % 128 == 0 then control.check() end
65
65
  if types[n.kind] or n.kind == 'method' then
66
66
  local d = { at = T.s[n.ti] - 1 }
67
- if types[n.kind] then d.hierarchy_bases = require('codeoutline.type_bases').collect(T, n, r.language) end
67
+ if types[n.kind] then d.hierarchy_bases = require('codeoutline.analysis.type_bases').collect(T, n, r.language) end
68
68
  local opening, ni
69
69
  for i = n.ti, n.tj do
70
70
  local s = T:text(i)
@@ -92,6 +92,12 @@ function M.collect(r, T)
92
92
  -- C#/C++ bindings. No assignment flow or factory-return inference is done.
93
93
  local wanted, stack, scopes, bindings = {}, {}, {}, {}
94
94
  for _, ref in ipairs(r.refs) do if (ref.kind == 'member_call' or ref.kind == 'ref') and ref.recv then wanted[ref.recv] = true end end
95
+ if r.language == 'kotlin' then
96
+ for i = 1, T.n - 2 do
97
+ if T:text(i) == 'with' and T:text(i + 1) == '(' and T.k[i + 2] == 'id' then wanted[T:text(i + 2)] = true end
98
+ if (T:text(i) == 'apply' or T:text(i) == 'run') and T:text(i - 1) == '.' and T.k[i - 2] == 'id' then wanted[T:text(i - 2)] = true end
99
+ end
100
+ end
95
101
  if not next(wanted) then return end
96
102
  for i = 1, T.n do
97
103
  if T:text(i) == '{' and T.m[i] then stack[#stack + 1] = i end
@@ -134,6 +140,7 @@ function M.collect(r, T)
134
140
  end
135
141
  end
136
142
  end
143
+ T.jvm_bindings = bindings
137
144
  for _, ref in ipairs(r.refs) do
138
145
  if (ref.kind == 'member_call' or ref.kind == 'ref') and ref.recv then
139
146
  local best
@@ -144,6 +151,8 @@ function M.collect(r, T)
144
151
  if best then
145
152
  ref.binding = best.type and 'jvm:type:' .. best.type .. '\0' .. (T.s[best.token] - 1) or 'jvm:?'
146
153
  if T:text(ref.tok - 3) == '.' or T:text(ref.tok - 3) == '?.' then ref.binding = 'jvm:?' end
154
+ elseif r.language == 'java' and ref.recv == 'super' and T:text(ref.tok - 3) == '.' then
155
+ ref.binding = 'jvm:?'
147
156
  elseif ref.recv == 'this' or ref.recv == 'super' then ref.binding = 'jvm:self:' .. ref.recv end
148
157
  r.has_bindings = true
149
158
  end
@@ -152,10 +161,10 @@ end
152
161
 
153
162
  function M.types(G, f, written, ctx, scope, at)
154
163
  if G.files[f].language == 'typescript' then
155
- return require('codeoutline.ts_implementations').types(G, f, written, ctx)
164
+ return require('codeoutline.analysis.js.ts_implementations').types(G, f, written, ctx)
156
165
  end
157
166
  if G.files[f].language == 'csharp' then
158
- return require('codeoutline.csharp_bindings').types(G, f, written, at or 0, ctx, { scope = scope })
167
+ return require('codeoutline.analysis.csharp.csharp_bindings').types(G, f, written, at or 0, ctx, { scope = scope })
159
168
  end
160
169
  written = name(written)
161
170
  if not written then return {} end
@@ -237,11 +246,11 @@ function M.context(G, ctx, report)
237
246
  local cpp
238
247
  local go
239
248
  local function go_context()
240
- if not go then go = require('codeoutline.go_methods').context(G, ctx, report); C.stats.go = go.stats end
249
+ if not go then go = require('codeoutline.analysis.go.go_methods').context(G, ctx, report); C.stats.go = go.stats end
241
250
  return go
242
251
  end
243
252
  local function cpp_context()
244
- if not cpp then cpp = require('codeoutline.cpp_implementations').context(G, ctx, report, M, C) end
253
+ if not cpp then cpp = require('codeoutline.analysis.cpp.cpp_implementations').context(G, ctx, report, M, C) end
245
254
  return cpp
246
255
  end
247
256
  local details, ancestors, outgoing, incoming = {}, {}, {}, {}
@@ -1,14 +1,14 @@
1
1
  -- Explicit dispatch contracts. No wildcard API guesses or source evaluation.
2
- local control = require('codeoutline.control')
2
+ local control = require('codeoutline.shared.control')
3
3
  local M = {}
4
- local aliases = require('codeoutline.dispatch_aliases')
4
+ local aliases = require('codeoutline.analysis.dispatch_aliases')
5
5
  local member = { ['.'] = true, [':'] = true, ['::'] = true, ['->'] = true }
6
6
 
7
7
  local function value(T, a, b, language)
8
8
  if a == b and T.k[a] == 'str' then
9
9
  local raw = T:text(a)
10
10
  if language == 'lua' then
11
- local literal = require('codeoutline.lua_literal').decode(raw)
11
+ local literal = require('codeoutline.analysis.lua.lua_literal').decode(raw)
12
12
  return literal and { literal = literal } or false
13
13
  end
14
14
  local q = raw:sub(1, 1)
@@ -75,13 +75,13 @@ function M.collect(r, T)
75
75
  for name in pairs(calls) do names[#names + 1] = name end
76
76
  table.sort(names)
77
77
  if #names > 0 then r.dispatch_calls = names end
78
- local roles = require('codeoutline.shared_events').roles(r, calls)
78
+ local roles = require('codeoutline.analysis.shared_events').roles(r, calls)
79
79
  if roles ~= 0 then r.event_roles = roles end
80
80
  if r.collect_dispatch then r.dispatch_sites = sites end
81
81
  end
82
82
 
83
83
  local function rules_for(G, rules)
84
- local config = require('codeoutline.rules')
84
+ local config = require('codeoutline.shared.rules')
85
85
  if rules ~= nil then return config.dispatch(rules) end
86
86
  return config.load(G.root).dispatch
87
87
  end
@@ -103,7 +103,7 @@ end
103
103
  function M.query(G, rules, report)
104
104
  rules = rules_for(G, rules)
105
105
  if #rules == 0 then return { outgoing = function() return {} end, incoming = function() return {} end } end
106
- local graph = require('codeoutline.graph')
106
+ local graph = require('codeoutline.analysis.graph')
107
107
  local names, cache, order, bytes, registrations_by_rule = {}, {}, {}, 0, {}
108
108
  local dependencies = {}
109
109
  for _, rule in ipairs(rules) do names[rule.call] = true; if rule.register then names[rule.register] = true end end
@@ -129,7 +129,7 @@ function M.query(G, rules, report)
129
129
  for name in pairs(literals) do if source:find(name, 1, true) then relevant = true; break end end
130
130
  if not relevant and source:find('\\', 1, true) then
131
131
  local T = require('codeoutline.lang.lua').lang:tokenize(source)
132
- local decode = require('codeoutline.lua_literal').decode
132
+ local decode = require('codeoutline.analysis.lua.lua_literal').decode
133
133
  for i = 1, T.n do
134
134
  if i % 4096 == 0 then control.check() end
135
135
  if T.k[i] == 'str' and literals[decode(T:text(i))] then relevant = true; break end
@@ -139,7 +139,7 @@ function M.query(G, rules, report)
139
139
  -- targets within this same query, and outgoing needs all sites.
140
140
  if not relevant then return {} end
141
141
  end
142
- local parsed = assert(require('codeoutline.parse').parse(rec.path, source,
142
+ local parsed = assert(require('codeoutline.parsing.parse').parse(rec.path, source,
143
143
  { ranges = false, dispatch = names, dispatch_only = true, language = rec.language }))
144
144
  assert(#parsed.nodes == #rec.nodes, 'source encoding changed; refresh index before indirect query: ' .. rec.path)
145
145
  for i, n in ipairs(parsed.nodes) do
@@ -163,16 +163,16 @@ function M.query(G, rules, report)
163
163
  local imp = arg.import
164
164
  local rec = G.files[f]
165
165
  if rec.language == 'javascript' or rec.language == 'typescript' or rec.language == 'arkts' then
166
- local js = require('codeoutline.js_resolution')
166
+ local js = require('codeoutline.analysis.js.js_resolution')
167
167
  dependencies.js = dependencies.js or js.context(G)
168
168
  return js.imported(G, f, imp.path, arg.member, dependencies.js) or {}
169
169
  elseif rec.language == 'lua' then
170
- local bindings = require('codeoutline.lua_bindings')
170
+ local bindings = require('codeoutline.analysis.lua.lua_bindings')
171
171
  dependencies.lua = dependencies.lua or bindings.context(G)
172
172
  local result = {}
173
173
  for _, file in ipairs(bindings.modules(G, { path = imp.path, kind = imp.loader }, dependencies.lua)) do
174
174
  local record = G.files[file]
175
- local exports = require('codeoutline.foreign').exports(record, 'lua', imp.path) or record.lua_exports
175
+ local exports = require('codeoutline.analysis.foreign').exports(record, 'lua', imp.path) or record.lua_exports
176
176
  local id = exports and exports[arg.member]
177
177
  if id then result[#result + 1] = G.id_of[file][id] end
178
178
  end
@@ -236,6 +236,52 @@ function M.query(G, rules, report)
236
236
  registrations_by_rule[ri] = registrations
237
237
  return registrations
238
238
  end
239
+ -- A command string is not a receiver binding. Keep member handlers and
240
+ -- service-addressed commands as suggestions until registration evidence
241
+ -- proves which module/instance receives them. Never traverse suggestions.
242
+ local function command_targets(f, site, arg, rule)
243
+ if not arg or not arg.literal then return {}, {} end
244
+ local name = arg.literal
245
+ local short = name:match('^([%a_][%w_]*)$')
246
+ local address = site.args[rule.serviceArgument or (rule.argument - 1)]
247
+ local scoped = rule.serviceArgument ~= nil or address and (address.symbol or address.service or address.literal)
248
+ if not short then
249
+ local ids = targets(f, site, arg, true)
250
+ if not scoped then return ids, {} end
251
+ local candidates = {}
252
+ for i = 1, math.min(#ids, 4) do candidates[i] = ids[i] end
253
+ if #ids > 4 and report then report.truncated = true end
254
+ return {}, candidates
255
+ end
256
+ local service = address and address.service
257
+ if not service and rule.serviceArgument then service = address and address.literal end
258
+ local candidates, edges, seen, resolved = {}, {}, {}, {}
259
+ if not scoped then for _, id in ipairs(targets(f, site, arg, true)) do resolved[id] = true end end
260
+ -- Prefer explicit handler conventions before generic library methods.
261
+ local keys = G.files[f].language == 'lua' and { 'CMD_' .. short, 'NTF_' .. short, short } or { short }
262
+ for _, key in ipairs(keys) do
263
+ local list = G.by_name[key] or {}
264
+ if #list > 128 and report then report.truncated = true end
265
+ for i = 1, math.min(#list, 128) do
266
+ if i % 32 == 0 then control.check() end
267
+ local id = list[i]
268
+ local node, rec = G.nodes[id], G.files[G.node_file[id]]
269
+ local callable = node.kind == 'function' or node.kind == 'method'
270
+ local suffix = service and service .. '.lua'
271
+ local fits = not suffix or rec.path == suffix or rec.path:sub(-#suffix - 1) == '/' .. suffix
272
+ if callable and rec.language == G.files[f].language and fits and not seen[id] then
273
+ seen[id] = true
274
+ if resolved[id] and key == short and node.qualified == short then
275
+ -- An explicit name-dispatch contract can still name a
276
+ -- free function; ordinary lexical checks remain authoritative.
277
+ edges[#edges + 1] = id
278
+ elseif #candidates < 4 then candidates[#candidates + 1] = id
279
+ elseif report then report.truncated = true end
280
+ end
281
+ end
282
+ end
283
+ return edges, candidates
284
+ end
239
285
  local function scan(only, wanted)
240
286
  local out = {}
241
287
  local literals
@@ -247,6 +293,8 @@ function M.query(G, rules, report)
247
293
  for id in pairs(wanted) do
248
294
  local node = G.nodes[id]
249
295
  literals[node.name], literals[node.qualified or node.name] = true, true
296
+ local command = node.name:match('^CMD_(.+)$') or node.name:match('^NTF_(.+)$')
297
+ if command then literals[command] = true end
250
298
  end
251
299
  end
252
300
  end
@@ -261,13 +309,23 @@ function M.query(G, rules, report)
261
309
  file_sites = file_sites or sites(f, literals)
262
310
  for _, site in ipairs(file_sites) do
263
311
  if (site.call == rule.call or site.api == rule.call) and site.from > 0 and (not only or G.id_of[f][site.from] == only) then
264
- local ids, arg, registered = {}, site.args[rule.argument], nil
312
+ local ids, arg, registered, suggestions = {}, site.args[rule.argument], nil, {}
265
313
  if rule.kind == 'event' then
266
314
  registered = registrations(ri, rule)
267
315
  for id in pairs(arg and arg.literal and registered[rec.language .. '\0' .. arg.literal] or {}) do ids[#ids + 1] = id end
268
316
  table.sort(ids, function(a, b) return graph.before(G, a, b) end)
269
- else ids = targets(f, site, arg, rule.kind == 'target') end
317
+ elseif rule.kind == 'target' then ids, suggestions = command_targets(f, site, arg, rule)
318
+ else ids = targets(f, site, arg, false) end
270
319
  local src = G.id_of[f][site.from]
320
+ if report and (only or wanted) then
321
+ for _, id in ipairs(suggestions) do
322
+ if not wanted or wanted[id] then
323
+ report:add({ source = src, candidate = id, line = site.line, rule = ri,
324
+ argument = rule.argument, call = rule.call,
325
+ reason = 'command name matches; receiving service/module binding unconfirmed' })
326
+ end
327
+ end
328
+ end
271
329
  if report and only and #ids == 0 then
272
330
  local static = arg and (rule.kind == 'callback' and arg.symbol or rule.kind ~= 'callback' and arg.literal)
273
331
  report:add({ source = src, line = site.line, rule = ri, argument = rule.argument, call = rule.call,
@@ -1,6 +1,6 @@
1
1
  -- Token-derived ES module bindings and bounded lexical receiver declarations.
2
2
  local M = {}
3
- local control = require('codeoutline.control')
3
+ local control = require('codeoutline.shared.control')
4
4
  local function identifier(T, i) return T.k[i] == 'id' or T:text(i) == 'default' end
5
5
  local function literal(T, i)
6
6
  if T.k[i] ~= 'str' then return nil end
@@ -144,7 +144,7 @@ function M.collect(r, T)
144
144
  local a, b = scope_for(i, parameter)
145
145
  local eq = next == '=' and i + 1 or after
146
146
  if r.ordinary_bindings and declaration and eq and T:text(eq) == '=' and T.k[eq + 1] == 'id' then
147
- alias_tokens[i] = require('codeoutline.dispatch_aliases').simple(T, eq + 1, r.language, true) and 'simple' or true
147
+ alias_tokens[i] = require('codeoutline.analysis.dispatch_aliases').simple(T, eq + 1, r.language, true) and 'simple' or true
148
148
  end
149
149
  bindings[#bindings + 1] = { name = T:text(i), type = typ or '?', token = i, a = a, b = b,
150
150
  declaration = declaration or parameter, target = declaration and callable_at[i] or nil }
@@ -156,12 +156,13 @@ function M.collect(r, T)
156
156
  by_name[binding.name] = by_name[binding.name] or {}
157
157
  by_name[binding.name][#by_name[binding.name] + 1] = binding
158
158
  end
159
+ T.js_bindings = by_name
159
160
  -- Reuse dispatch's bounded lexical validation in explicit query parses.
160
161
  -- Ordinary indexing leaves this extra evidence ungenerated.
161
162
  local expand
162
163
  local function alias_evidence(name, at, token)
163
164
  if alias_tokens[token] ~= 'simple' then return '?' end
164
- expand = expand or require('codeoutline.dispatch_aliases').prepare(r, T)
165
+ expand = expand or require('codeoutline.analysis.dispatch_aliases').prepare(r, T)
165
166
  local v = expand({ symbol = name }, at)
166
167
  if v and v.node then return 'node:' .. v.node end
167
168
  if v and v.import then return 'import:' .. v.import.path .. '\0' .. v.member end
@@ -1,6 +1,6 @@
1
1
  -- JS/TS module and receiver evidence; deliberately not a type checker.
2
2
  local M = {}
3
- local control = require('codeoutline.control')
3
+ local control = require('codeoutline.shared.control')
4
4
  local function js(rec) return rec and (rec.language == 'javascript' or rec.language == 'typescript' or rec.language == 'arkts') end
5
5
  local function dir(p) return p:match('^(.*)/[^/]*$') or '' end
6
6
  local function norm(p)
@@ -121,7 +121,7 @@ function M.module(G, f, spec, ctx, mode)
121
121
  ctx.modules[key], ctx.module_reasons[key] = false, ctx.workspace_error
122
122
  return nil, ctx.workspace_error
123
123
  end
124
- local ok, target, reason = pcall(require('codeoutline.js_workspace').resolve, G, f, spec, ctx, mode, find)
124
+ local ok, target, reason = pcall(require('codeoutline.analysis.js.js_workspace').resolve, G, f, spec, ctx, mode, find)
125
125
  if not ok then
126
126
  if control.is_interrupted(target) then error(target, 0) end
127
127
  ctx.workspace_incomplete = true; reason, target = tostring(target), nil
@@ -2,8 +2,8 @@
2
2
  -- directories; never walk node_modules, execute package scripts, or guess src/.
3
3
  local M = { MAX_CONFIG_BYTES = 1048576, MAX_TOTAL_BYTES = 8388608, MAX_CONFIGS = 1024,
4
4
  MAX_DIRECTORIES = 4096, MAX_PACKAGES = 512, MAX_PATTERNS = 256 }
5
- local control = require('codeoutline.control')
6
- local paths = require('codeoutline.path')
5
+ local control = require('codeoutline.shared.control')
6
+ local paths = require('codeoutline.shared.path')
7
7
  local function dir(p) return p:match('^(.*)/[^/]+$') or '' end
8
8
  local function join(a, b) return a == '' and b or a .. '/' .. b end
9
9
  local function object(t) return type(t) == 'table' and getmetatable(t) ~= xutils.json_array_mt end
@@ -1,6 +1,6 @@
1
1
  -- Conservative named TS contracts. All token evidence belongs to one query.
2
2
  local M = {}
3
- local control = require('codeoutline.control')
3
+ local control = require('codeoutline.shared.control')
4
4
 
5
5
  function M.collect(r, T)
6
6
  local evidence = {}
@@ -13,7 +13,7 @@ function M.collect(r, T)
13
13
  if index % 128 == 0 then control.check() end
14
14
  if n.kind == 'class' or n.kind == 'interface' or n.kind == 'method' then
15
15
  local d = { at = T.s[n.ti] - 1 }
16
- if n.kind ~= 'method' then d.hierarchy_bases = require('codeoutline.type_bases').collect(T, n, r.language) end
16
+ if n.kind ~= 'method' then d.hierarchy_bases = require('codeoutline.analysis.type_bases').collect(T, n, r.language) end
17
17
  local opening, ni
18
18
  for i = n.ti, n.tj do
19
19
  local s = T:text(i)
@@ -59,7 +59,7 @@ function M.types(G, f, written, ctx)
59
59
  for _, imp in ipairs(G.files[f].js_imports or {}) do
60
60
  if imp.local_name == (head or written) then
61
61
  if tail and imp.imported ~= '*' or not tail and imp.imported == '*' then return {} end
62
- ids = require('codeoutline.js_resolution').imported(G, f, imp.path, tail or imp.imported, ctx)
62
+ ids = require('codeoutline.analysis.js.js_resolution').imported(G, f, imp.path, tail or imp.imported, ctx)
63
63
  break
64
64
  end
65
65
  end
@@ -1,6 +1,6 @@
1
1
  -- Lua C API adapter for the language-neutral foreign interface model.
2
2
  local M = {}
3
- local control = require('codeoutline.control')
3
+ local control = require('codeoutline.shared.control')
4
4
  local function literal(T, i)
5
5
  local s = T:text(i)
6
6
  if T.k[i] ~= 'str' or s:find('\\', 1, true) then return nil end
@@ -258,12 +258,12 @@ function M.collect(r, T)
258
258
  end
259
259
  for name, entries in pairs(metas) do
260
260
  if next(entries) then
261
- require('codeoutline.foreign').register(r, 'lua', name, entries)
261
+ require('codeoutline.analysis.foreign').register(r, 'lua', name, entries)
262
262
  for _, n in pairs(entries) do signature(n, name) end
263
263
  end
264
264
  end
265
265
  if next(exports) then
266
- require('codeoutline.foreign').register(r, 'lua', module, exports)
266
+ require('codeoutline.analysis.foreign').register(r, 'lua', module, exports)
267
267
  for _, n in pairs(exports) do signature(n, nil) end
268
268
  end
269
269
  end
@@ -1,6 +1,6 @@
1
1
  -- Static Lua module return bindings. Never execute indexed source.
2
2
  local M = {}
3
- local control = require('codeoutline.control')
3
+ local control = require('codeoutline.shared.control')
4
4
  local loaders = { require = true, dofile = true, loadfile = true }
5
5
  local EXPORT_OWNER = '__exports'
6
6
  -- Loader call at token j: a known loader name, or any dotted/plain name whose
@@ -32,6 +32,33 @@ local function value_end(T, i)
32
32
  return (T.k[i] ~= 'op' or tail == ';' or tail == ',') and tail ~= 'and' and tail ~= 'or'
33
33
  end
34
34
 
35
+ local function binding_at(bindings, name, token)
36
+ local best
37
+ for _, b in ipairs(bindings[name] or {}) do
38
+ if b.token <= token and b.a <= token and b.b >= token
39
+ and (not best or b.a > best.a or b.a == best.a and b.token > best.token) then best = b end
40
+ end
41
+ return best
42
+ end
43
+
44
+ local function metatable_import(T, bindings, bound)
45
+ if not bound then return nil end
46
+ local call = bound.token + 2
47
+ if T:text(bound.token + 1) ~= '=' or T:text(call) ~= 'setmetatable'
48
+ or binding_at(bindings, 'setmetatable', call) or T:text(call + 1) ~= '('
49
+ or T:text(call + 2) ~= '{' then return nil end
50
+ local object_end = T.m[call + 2]
51
+ if not object_end or T:text(object_end + 1) ~= ',' or T:text(object_end + 2) ~= '{' then return nil end
52
+ local key = object_end + 3
53
+ if T:text(key) ~= '__index' or T:text(key + 1) ~= '=' or T.k[key + 2] ~= 'id' then return nil end
54
+ local close = key + 3
55
+ if T:text(close) == ',' or T:text(close) == ';' then close = close + 1 end
56
+ if T.m[object_end + 2] ~= close or T.m[call + 1] ~= close + 1
57
+ or not value_end(T, close + 2) then return nil end
58
+ local base = binding_at(bindings, T:text(key + 2), key + 2)
59
+ return base and tonumber(base.hint:match('^lua:(%d+)$'))
60
+ end
61
+
35
62
  -- Shared lexical table-member lookup for normal references and query-only
36
63
  -- configured callback aliases. Results are local parser node indices.
37
64
  function M.local_members(nodes, scopes, name, token, scope, finish)
@@ -129,17 +156,86 @@ function M.collect(r, T, bm)
129
156
  end
130
157
  end
131
158
  end
159
+ -- Derive method receivers only in query parses. Closures capture this
160
+ -- binding; a later local or parameter named self hides it normally.
161
+ r.lua_self = {}
162
+ local by_close, owners, receiver_tables = {}, {}, {}
163
+ for n, node in ipairs(r.nodes) do by_close[node.tj] = n end
164
+ for i = 1, T.n do
165
+ if T:text(i) == 'function' and T.k[i] == 'kw' then
166
+ local n = by_close[bm[i]]
167
+ local node = n and r.nodes[n]
168
+ local p = i + 1
169
+ while p < (bm[i] or i) and T:text(p) ~= '(' do p = p + 1 end
170
+ local implicit = T:text(p - 2) == ':'
171
+ local explicit = not implicit and T:text(p + 1) == 'self'
172
+ local owner = node and node.qualified:match('^(.*)[.:][%w_]+$')
173
+ if node and node.parent and T:text(i + 2) == '(' then owner = nil end
174
+ if implicit then
175
+ for j = p + 1, (T.m[p] or p) - 1 do
176
+ if T:text(j) == 'self' then implicit = false; break end
177
+ end
178
+ end
179
+ if owner and (implicit or explicit) then
180
+ local bound = binding_at(bindings, owner, i)
181
+ local scope = bound and bound.a or scopes[i]
182
+ local key = bound or owner .. '\0' .. scope
183
+ local info = owners[key]
184
+ if not info then
185
+ local first, finish = bound and bound.token or 0, bound and bound.b or bm[scope] or T.n
186
+ for _, later in ipairs(bindings[owner] or {}) do
187
+ if later.a == scope and later.token > first then finish = math.min(finish, later.token - 1) end
188
+ end
189
+ info = { members = M.local_members(r.nodes, scopes, owner, first, scope, finish), fields = {},
190
+ base_import = metatable_import(T, bindings, bound) }
191
+ owners[key] = info
192
+ if bound then receiver_tables[bound] = info end
193
+ end
194
+ r.lua_self[n] = info
195
+ local b
196
+ if implicit then
197
+ add('self', i, i, 'lua-self:' .. n)
198
+ b = bindings.self[#bindings.self]
199
+ else b = binding_at(bindings, 'self', p + 1) end
200
+ b.hint, b.imported, b.self_info = 'lua-self:' .. n, false, info
201
+ receiver_tables[b] = info
202
+ end
203
+ end
204
+ end
205
+ -- A shadowing self may itself be a literal table or an unknown
206
+ -- parameter. Keep its assigned fields separate from method receivers.
207
+ for _, b in ipairs(bindings.self or {}) do
208
+ local index = tonumber(b.hint:match('^lua%-local:(%d+)$'))
209
+ if not b.self_info and (index or b.hint == '?') and not b.imported then
210
+ b.self_info = { members = index and r.lua_locals[index] or {}, fields = {} }
211
+ receiver_tables[b] = b.self_info
212
+ end
213
+ end
214
+ for i = 1, T.n - 3 do
215
+ if i % 4096 == 0 then control.check() end
216
+ if T.k[i] == 'id' then
217
+ local info = receiver_tables[binding_at(bindings, T:text(i), i)]
218
+ if info and T:text(i + 1) == '.' and T.k[i + 2] == 'id' and T:text(i + 3) == '=' then
219
+ info.fields[T:text(i + 2)] = true
220
+ elseif info and T:text(i + 1) == '=' and T:text(i + 2) == '{' then
221
+ local j, close = i + 3, T.m[i + 2] or i + 2
222
+ while j < close do
223
+ if T.k[j] == 'id' and T:text(j + 1) == '=' then info.fields[T:text(j)] = true end
224
+ if T.m[j] and T.m[j] > j then j = T.m[j]
225
+ elseif bm[j] and bm[j] > j then j = bm[j] end
226
+ j = j + 1
227
+ end
228
+ end
229
+ end
230
+ end
132
231
  for _, ref in ipairs(r.refs) do
133
232
  if not ref.lua_binding then
134
- local best
135
- for _, b in ipairs(bindings[ref.recv or ref.name] or {}) do
136
- if b.token <= ref.tok and b.a <= ref.tok and b.b >= ref.tok
137
- and (not best or b.a > best.a or (b.a == best.a and b.token > best.token)) then best = b end
138
- end
233
+ local best = binding_at(bindings, ref.recv or ref.name, ref.tok)
139
234
  if best and (ref.recv or best.imported) then
140
235
  local value = best.hint:match('^lua%-value:')
141
236
  ref.lua_binding = value and (not ref.recv and best.hint or '?') or (ref.recv and best.hint or '?')
142
237
  end
238
+ if ref.recv == 'self' and not best then ref.lua_binding = '?' end
143
239
  if ref.recv and (T:text(ref.tok - 3) == '.' or T:text(ref.tok - 3) == ':') then ref.lua_binding = '?' end
144
240
  end
145
241
  end
@@ -437,16 +533,20 @@ function M.modules(G, imp, ctx)
437
533
  return result
438
534
  end
439
535
  function M.native_modules(G, name, ctx)
440
- return require('codeoutline.foreign').modules(G, 'lua', name, ctx)
536
+ return require('codeoutline.analysis.foreign').modules(G, 'lua', name, ctx)
441
537
  end
442
538
 
443
539
  -- Shared query-time receiver resolution for completion and navigation. Reuse
444
540
  -- the parser's lexical bindings and loader contracts; never execute Lua.
541
+ local function module_target(G, imp, ctx)
542
+ return { modules = M.modules(G, imp, ctx), module_name = imp.path }
543
+ end
544
+
445
545
  function M.member(G, target, name)
446
546
  local result = {}
447
547
  for _, f in ipairs(target and target.modules or {}) do
448
548
  local rec = G.files[f]
449
- local exports = require('codeoutline.foreign').exports(rec, 'lua', target.module_name) or rec.lua_exports
549
+ local exports = require('codeoutline.analysis.foreign').exports(rec, 'lua', target.module_name) or rec.lua_exports
450
550
  local n = exports and exports[name]
451
551
  if n then result[#result + 1] = { node = rec.nodes[n], file = f, index = n } end
452
552
  end
@@ -454,7 +554,7 @@ function M.member(G, target, name)
454
554
  end
455
555
 
456
556
  function M.return_target(G, node, ctx)
457
- local name = require('codeoutline.foreign').returns(node, 'lua')
557
+ local name = require('codeoutline.analysis.foreign').returns(node, 'lua')
458
558
  local files = name and M.native_modules(G, name, ctx)
459
559
  if files and #files > 0 then return { modules = files, module_name = name } end
460
560
  end
@@ -469,13 +569,20 @@ function M.receiver(G, rec, T, name, offset, ctx, depth)
469
569
  and (not best or b.a > best.a or b.a == best.a and b.token > best.token) then best = b end
470
570
  end
471
571
  if not best then
572
+ if name == 'self' then return nil, true end
472
573
  local files = M.native_modules(G, name, ctx)
473
574
  return #files > 0 and { modules = files, module_name = name } or nil, (T.lua_bindings or {})[name] ~= nil
474
575
  end
576
+ if best.self_info then
577
+ local imp = rec.lua_imports[best.self_info.base_import]
578
+ local target = imp and module_target(G, imp, ctx) or {}
579
+ target.lua_self = best.self_info
580
+ return target, true
581
+ end
475
582
  local imported = tonumber(best.hint:match('^lua:(%d+)$'))
476
583
  if imported then
477
584
  local imp = rec.lua_imports[imported]
478
- return { modules = M.modules(G, imp, ctx), module_name = imp.path }, true
585
+ return module_target(G, imp, ctx), true
479
586
  end
480
587
  local i = best.token + 2
481
588
  if best.imported or T:text(best.token + 1) ~= '=' or T.k[i] ~= 'id' then return nil, true end
@@ -504,12 +611,29 @@ function M.resolve(G, f, name, hint, ctx, recv)
504
611
  if not hint or hint == '' then
505
612
  local result = {}
506
613
  for _, target in ipairs(M.native_modules(G, recv, ctx)) do
507
- local n = require('codeoutline.foreign').exports(G.files[target], 'lua', recv)[name]
614
+ local n = require('codeoutline.analysis.foreign').exports(G.files[target], 'lua', recv)[name]
508
615
  if n then result[#result + 1] = G.id_of[target][n] end
509
616
  end
510
617
  return #result > 0 and result or nil
511
618
  end
512
619
  if hint == '?' then return {} end
620
+ local self_index = tonumber(hint:match('^lua%-self:(%d+)$'))
621
+ if self_index then
622
+ local rec = G.files[f]
623
+ local selves = rec.lua_self or ctx and ctx.ordinary and ctx.ordinary.data(f).lua_self or {}
624
+ local info = selves[self_index]
625
+ if not info then return {} end
626
+ local n = info.members[name]
627
+ if n then return { G.id_of[f][n] } end
628
+ local imp = (rec.lua_imports or EMPTY)[info.base_import]
629
+ local result = {}
630
+ if imp and not info.fields[name] then
631
+ for _, entry in ipairs(M.member(G, module_target(G, imp, ctx), name)) do
632
+ result[#result + 1] = G.id_of[entry.file][entry.index]
633
+ end
634
+ end
635
+ return result
636
+ end
513
637
  local local_index = tonumber(hint:match('^lua%-local:(%d+)$'))
514
638
  if local_index then
515
639
  local rec = G.files[f]
@@ -525,7 +649,7 @@ function M.resolve(G, f, name, hint, ctx, recv)
525
649
  local result = {}
526
650
  for _, target in ipairs(M.modules(G, imp, ctx)) do
527
651
  local rec = G.files[target]
528
- local exports = require('codeoutline.foreign').exports(rec, 'lua', imp.path) or rec.lua_exports
652
+ local exports = require('codeoutline.analysis.foreign').exports(rec, 'lua', imp.path) or rec.lua_exports
529
653
  local n = (exports or {})[name]
530
654
  if n then result[#result + 1] = G.id_of[target][n] end
531
655
  end
@@ -1,6 +1,6 @@
1
1
  -- Query-only traversal of a closed, same-file local callback collection.
2
2
  local M = { MAX_FILES = 128, MAX_LOOPS = 128, MAX_TARGETS = 64, MAX_LINKS = 512 }
3
- local control = require('codeoutline.control')
3
+ local control = require('codeoutline.shared.control')
4
4
  local iterators = { pairs = true, ipairs = true }
5
5
  local function loop_header(T, i)
6
6
  return T:text(i) == 'for' and T.k[i + 1] == 'id' and T:text(i + 2) == ',' and T.k[i + 3] == 'id'