@codua/codeoutline-win32-x64 0.3.2 → 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 (103) hide show
  1. package/DISTRIBUTION.md +26 -1
  2. package/README.md +39 -4
  3. package/README.zh-CN.md +30 -3
  4. package/bin/xnet.exe +0 -0
  5. package/build-info.json +1 -1
  6. package/codeoutline +1 -1
  7. package/codeoutline.cmd +1 -0
  8. package/editors/codeoutline.vsix +0 -0
  9. package/editors/zed/extension.wasm +0 -0
  10. package/package.json +1 -1
  11. package/scripts/codeoutline/{automatic_events.lua → analysis/automatic_events.lua} +4 -4
  12. package/scripts/codeoutline/{cpp_bindings.lua → analysis/cpp/cpp_bindings.lua} +7 -7
  13. package/scripts/codeoutline/{cpp_implementations.lua → analysis/cpp/cpp_implementations.lua} +3 -3
  14. package/scripts/codeoutline/{cpp_includes.lua → analysis/cpp/cpp_includes.lua} +3 -3
  15. package/scripts/codeoutline/{cpp_macros.lua → analysis/cpp/cpp_macros.lua} +3 -3
  16. package/scripts/codeoutline/{cpp_receivers.lua → analysis/cpp/cpp_receivers.lua} +7 -7
  17. package/scripts/codeoutline/{cpp_types.lua → analysis/cpp/cpp_types.lua} +5 -5
  18. package/scripts/codeoutline/{csharp_bindings.lua → analysis/csharp/csharp_bindings.lua} +1 -1
  19. package/scripts/codeoutline/{dispatch_aliases.lua → analysis/dispatch_aliases.lua} +3 -3
  20. package/scripts/codeoutline/{foreign.lua → analysis/foreign.lua} +2 -2
  21. package/scripts/codeoutline/{function_values.lua → analysis/function_values.lua} +2 -2
  22. package/scripts/codeoutline/analysis/go/go_frameworks.lua +327 -0
  23. package/scripts/codeoutline/{go_methods.lua → analysis/go/go_methods.lua} +2 -2
  24. package/scripts/codeoutline/{go_modules.lua → analysis/go/go_modules.lua} +2 -2
  25. package/scripts/codeoutline/{graph.lua → analysis/graph.lua} +53 -47
  26. package/scripts/codeoutline/{implementations.lua → analysis/implementations.lua} +16 -9
  27. package/scripts/codeoutline/{indirect.lua → analysis/indirect.lua} +71 -13
  28. package/scripts/codeoutline/{js_evidence.lua → analysis/js/js_evidence.lua} +4 -3
  29. package/scripts/codeoutline/{js_resolution.lua → analysis/js/js_resolution.lua} +2 -2
  30. package/scripts/codeoutline/{js_workspace.lua → analysis/js/js_workspace.lua} +2 -2
  31. package/scripts/codeoutline/{ts_implementations.lua → analysis/js/ts_implementations.lua} +3 -3
  32. package/scripts/codeoutline/{foreign_lua.lua → analysis/lua/foreign_lua.lua} +3 -3
  33. package/scripts/codeoutline/{lua_bindings.lua → analysis/lua/lua_bindings.lua} +97 -11
  34. package/scripts/codeoutline/{lua_callback_loops.lua → analysis/lua/lua_callback_loops.lua} +1 -1
  35. package/scripts/codeoutline/{ordinary_bindings.lua → analysis/ordinary_bindings.lua} +45 -21
  36. package/scripts/codeoutline/{python_bindings.lua → analysis/python/python_bindings.lua} +2 -2
  37. package/scripts/codeoutline/analysis/receivers.lua +547 -0
  38. package/scripts/codeoutline/{rust_packages.lua → analysis/rust/rust_packages.lua} +2 -2
  39. package/scripts/codeoutline/analysis/rust/rust_resolution.lua +609 -0
  40. package/scripts/codeoutline/{shared_events.lua → analysis/shared_events.lua} +3 -3
  41. package/scripts/codeoutline/{static_dispatch.lua → analysis/static_dispatch.lua} +5 -5
  42. package/scripts/codeoutline/{type_uses.lua → analysis/type_uses.lua} +1 -1
  43. package/scripts/codeoutline/cli.lua +1 -1
  44. package/scripts/codeoutline/command.lua +236 -19
  45. package/scripts/codeoutline/{cpp_fragments.lua → indexing/cpp_fragments.lua} +4 -4
  46. package/scripts/codeoutline/{index.lua → indexing/index.lua} +12 -12
  47. package/scripts/codeoutline/{parse_pool.lua → indexing/parse_pool.lua} +1 -1
  48. package/scripts/codeoutline/{agent_config.lua → install/agent_config.lua} +21 -1
  49. package/scripts/codeoutline/{agent_install.lua → install/agent_install.lua} +105 -10
  50. package/scripts/codeoutline/{editor_install.lua → install/editor_install.lua} +36 -6
  51. package/scripts/codeoutline/lang/c.lua +2 -2
  52. package/scripts/codeoutline/lang/cpp.lua +2 -2
  53. package/scripts/codeoutline/lang/csharp.lua +2 -2
  54. package/scripts/codeoutline/lang/go.lua +2 -2
  55. package/scripts/codeoutline/lang/java.lua +2 -2
  56. package/scripts/codeoutline/lang/js.lua +2 -2
  57. package/scripts/codeoutline/lang/kotlin.lua +4 -2
  58. package/scripts/codeoutline/lang/lua.lua +3 -3
  59. package/scripts/codeoutline/lang/python.lua +2 -2
  60. package/scripts/codeoutline/lang/rust.lua +3 -3
  61. package/scripts/codeoutline/main.lua +9 -9
  62. package/scripts/codeoutline/{common.lua → parsing/common.lua} +22 -17
  63. package/scripts/codeoutline/{language_detect.lua → parsing/language_detect.lua} +1 -1
  64. package/scripts/codeoutline/{parse.lua → parsing/parse.lua} +4 -4
  65. package/scripts/codeoutline/{http.lua → protocol/http.lua} +1 -1
  66. package/scripts/codeoutline/{lsp.lua → protocol/lsp.lua} +4 -4
  67. package/scripts/codeoutline/{mcp.lua → protocol/mcp.lua} +9 -9
  68. package/scripts/codeoutline/{affected.lua → query/affected.lua} +6 -6
  69. package/scripts/codeoutline/{callers.lua → query/callers.lua} +9 -9
  70. package/scripts/codeoutline/{completion.lua → query/completion.lua} +37 -49
  71. package/scripts/codeoutline/{definition_candidates.lua → query/definition_candidates.lua} +6 -6
  72. package/scripts/codeoutline/{documents.lua → query/documents.lua} +4 -4
  73. package/scripts/codeoutline/{explore.lua → query/explore.lua} +85 -25
  74. package/scripts/codeoutline/{external_headers.lua → query/external_headers.lua} +6 -6
  75. package/scripts/codeoutline/{navigation.lua → query/navigation.lua} +53 -54
  76. package/scripts/codeoutline/{on_demand.lua → query/on_demand.lua} +6 -6
  77. package/scripts/codeoutline/{query_report.lua → query/query_report.lua} +9 -5
  78. package/scripts/codeoutline/{search_ranking.lua → query/search_ranking.lua} +10 -7
  79. package/scripts/codeoutline/{type_hierarchy.lua → query/type_hierarchy.lua} +11 -11
  80. package/scripts/codeoutline/{type_references.lua → query/type_references.lua} +17 -17
  81. package/scripts/codeoutline/{index_worker.lua → runtime/index_worker.lua} +10 -10
  82. package/scripts/codeoutline/{parse_worker.lua → runtime/parse_worker.lua} +2 -2
  83. package/scripts/codeoutline/{update_worker.lua → runtime/update_worker.lua} +1 -1
  84. package/scripts/codeoutline/service.lua +11 -11
  85. package/scripts/codeoutline/update_sequence.lua +1 -1
  86. package/scripts/codeoutline/version.lua +1 -1
  87. package/scripts/codeoutline/rust_resolution.lua +0 -301
  88. /package/scripts/codeoutline/{lua_literal.lua → analysis/lua/lua_literal.lua} +0 -0
  89. /package/scripts/codeoutline/{resolution.lua → analysis/resolution.lua} +0 -0
  90. /package/scripts/codeoutline/{cargo_toml.lua → analysis/rust/cargo_toml.lua} +0 -0
  91. /package/scripts/codeoutline/{type_bases.lua → analysis/type_bases.lua} +0 -0
  92. /package/scripts/codeoutline/{cache_repairs.lua → indexing/cache_repairs.lua} +0 -0
  93. /package/scripts/codeoutline/{daemon.lua → install/daemon.lua} +0 -0
  94. /package/scripts/codeoutline/{install_prompt.lua → install/install_prompt.lua} +0 -0
  95. /package/scripts/codeoutline/{xscan.lua → parsing/xscan.lua} +0 -0
  96. /package/scripts/codeoutline/{lsp_trace.lua → protocol/lsp_trace.lua} +0 -0
  97. /package/scripts/codeoutline/{coverage.lua → query/coverage.lua} +0 -0
  98. /package/scripts/codeoutline/{query_filters.lua → query/query_filters.lua} +0 -0
  99. /package/scripts/codeoutline/{idle_gc.lua → runtime/idle_gc.lua} +0 -0
  100. /package/scripts/codeoutline/{control.lua → shared/control.lua} +0 -0
  101. /package/scripts/codeoutline/{path.lua → shared/path.lua} +0 -0
  102. /package/scripts/codeoutline/{rules.lua → shared/rules.lua} +0 -0
  103. /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
@@ -152,10 +159,10 @@ end
152
159
 
153
160
  function M.types(G, f, written, ctx, scope, at)
154
161
  if G.files[f].language == 'typescript' then
155
- return require('codeoutline.ts_implementations').types(G, f, written, ctx)
162
+ return require('codeoutline.analysis.js.ts_implementations').types(G, f, written, ctx)
156
163
  end
157
164
  if G.files[f].language == 'csharp' then
158
- return require('codeoutline.csharp_bindings').types(G, f, written, at or 0, ctx, { scope = scope })
165
+ return require('codeoutline.analysis.csharp.csharp_bindings').types(G, f, written, at or 0, ctx, { scope = scope })
159
166
  end
160
167
  written = name(written)
161
168
  if not written then return {} end
@@ -237,11 +244,11 @@ function M.context(G, ctx, report)
237
244
  local cpp
238
245
  local go
239
246
  local function go_context()
240
- if not go then go = require('codeoutline.go_methods').context(G, ctx, report); C.stats.go = go.stats end
247
+ if not go then go = require('codeoutline.analysis.go.go_methods').context(G, ctx, report); C.stats.go = go.stats end
241
248
  return go
242
249
  end
243
250
  local function cpp_context()
244
- if not cpp then cpp = require('codeoutline.cpp_implementations').context(G, ctx, report, M, C) end
251
+ if not cpp then cpp = require('codeoutline.analysis.cpp.cpp_implementations').context(G, ctx, report, M, C) end
245
252
  return cpp
246
253
  end
247
254
  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,15 @@ 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
+
35
44
  -- Shared lexical table-member lookup for normal references and query-only
36
45
  -- configured callback aliases. Results are local parser node indices.
37
46
  function M.local_members(nodes, scopes, name, token, scope, finish)
@@ -129,17 +138,85 @@ function M.collect(r, T, bm)
129
138
  end
130
139
  end
131
140
  end
141
+ -- Derive method receivers only in query parses. Closures capture this
142
+ -- binding; a later local or parameter named self hides it normally.
143
+ r.lua_self = {}
144
+ local by_close, owners, receiver_tables = {}, {}, {}
145
+ for n, node in ipairs(r.nodes) do by_close[node.tj] = n end
146
+ for i = 1, T.n do
147
+ if T:text(i) == 'function' and T.k[i] == 'kw' then
148
+ local n = by_close[bm[i]]
149
+ local node = n and r.nodes[n]
150
+ local p = i + 1
151
+ while p < (bm[i] or i) and T:text(p) ~= '(' do p = p + 1 end
152
+ local implicit = T:text(p - 2) == ':'
153
+ local explicit = not implicit and T:text(p + 1) == 'self'
154
+ local owner = node and node.qualified:match('^(.*)[.:][%w_]+$')
155
+ if node and node.parent and T:text(i + 2) == '(' then owner = nil end
156
+ if implicit then
157
+ for j = p + 1, (T.m[p] or p) - 1 do
158
+ if T:text(j) == 'self' then implicit = false; break end
159
+ end
160
+ end
161
+ if owner and (implicit or explicit) then
162
+ local bound = binding_at(bindings, owner, i)
163
+ local scope = bound and bound.a or scopes[i]
164
+ local key = bound or owner .. '\0' .. scope
165
+ local info = owners[key]
166
+ if not info then
167
+ local first, finish = bound and bound.token or 0, bound and bound.b or bm[scope] or T.n
168
+ for _, later in ipairs(bindings[owner] or {}) do
169
+ if later.a == scope and later.token > first then finish = math.min(finish, later.token - 1) end
170
+ end
171
+ info = { members = M.local_members(r.nodes, scopes, owner, first, scope, finish), fields = {} }
172
+ owners[key] = info
173
+ if bound then receiver_tables[bound] = info end
174
+ end
175
+ r.lua_self[n] = info
176
+ local b
177
+ if implicit then
178
+ add('self', i, i, 'lua-self:' .. n)
179
+ b = bindings.self[#bindings.self]
180
+ else b = binding_at(bindings, 'self', p + 1) end
181
+ b.hint, b.imported, b.self_info = 'lua-self:' .. n, false, info
182
+ receiver_tables[b] = info
183
+ end
184
+ end
185
+ end
186
+ -- A shadowing self may itself be a literal table or an unknown
187
+ -- parameter. Keep its assigned fields separate from method receivers.
188
+ for _, b in ipairs(bindings.self or {}) do
189
+ local index = tonumber(b.hint:match('^lua%-local:(%d+)$'))
190
+ if not b.self_info and (index or b.hint == '?') and not b.imported then
191
+ b.self_info = { members = index and r.lua_locals[index] or {}, fields = {} }
192
+ receiver_tables[b] = b.self_info
193
+ end
194
+ end
195
+ for i = 1, T.n - 3 do
196
+ if i % 4096 == 0 then control.check() end
197
+ if T.k[i] == 'id' then
198
+ local info = receiver_tables[binding_at(bindings, T:text(i), i)]
199
+ if info and T:text(i + 1) == '.' and T.k[i + 2] == 'id' and T:text(i + 3) == '=' then
200
+ info.fields[T:text(i + 2)] = true
201
+ elseif info and T:text(i + 1) == '=' and T:text(i + 2) == '{' then
202
+ local j, close = i + 3, T.m[i + 2] or i + 2
203
+ while j < close do
204
+ if T.k[j] == 'id' and T:text(j + 1) == '=' then info.fields[T:text(j)] = true end
205
+ if T.m[j] and T.m[j] > j then j = T.m[j]
206
+ elseif bm[j] and bm[j] > j then j = bm[j] end
207
+ j = j + 1
208
+ end
209
+ end
210
+ end
211
+ end
132
212
  for _, ref in ipairs(r.refs) do
133
213
  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
214
+ local best = binding_at(bindings, ref.recv or ref.name, ref.tok)
139
215
  if best and (ref.recv or best.imported) then
140
216
  local value = best.hint:match('^lua%-value:')
141
217
  ref.lua_binding = value and (not ref.recv and best.hint or '?') or (ref.recv and best.hint or '?')
142
218
  end
219
+ if ref.recv == 'self' and not best then ref.lua_binding = '?' end
143
220
  if ref.recv and (T:text(ref.tok - 3) == '.' or T:text(ref.tok - 3) == ':') then ref.lua_binding = '?' end
144
221
  end
145
222
  end
@@ -437,7 +514,7 @@ function M.modules(G, imp, ctx)
437
514
  return result
438
515
  end
439
516
  function M.native_modules(G, name, ctx)
440
- return require('codeoutline.foreign').modules(G, 'lua', name, ctx)
517
+ return require('codeoutline.analysis.foreign').modules(G, 'lua', name, ctx)
441
518
  end
442
519
 
443
520
  -- Shared query-time receiver resolution for completion and navigation. Reuse
@@ -446,7 +523,7 @@ function M.member(G, target, name)
446
523
  local result = {}
447
524
  for _, f in ipairs(target and target.modules or {}) do
448
525
  local rec = G.files[f]
449
- local exports = require('codeoutline.foreign').exports(rec, 'lua', target.module_name) or rec.lua_exports
526
+ local exports = require('codeoutline.analysis.foreign').exports(rec, 'lua', target.module_name) or rec.lua_exports
450
527
  local n = exports and exports[name]
451
528
  if n then result[#result + 1] = { node = rec.nodes[n], file = f, index = n } end
452
529
  end
@@ -454,7 +531,7 @@ function M.member(G, target, name)
454
531
  end
455
532
 
456
533
  function M.return_target(G, node, ctx)
457
- local name = require('codeoutline.foreign').returns(node, 'lua')
534
+ local name = require('codeoutline.analysis.foreign').returns(node, 'lua')
458
535
  local files = name and M.native_modules(G, name, ctx)
459
536
  if files and #files > 0 then return { modules = files, module_name = name } end
460
537
  end
@@ -469,9 +546,11 @@ function M.receiver(G, rec, T, name, offset, ctx, depth)
469
546
  and (not best or b.a > best.a or b.a == best.a and b.token > best.token) then best = b end
470
547
  end
471
548
  if not best then
549
+ if name == 'self' then return nil, true end
472
550
  local files = M.native_modules(G, name, ctx)
473
551
  return #files > 0 and { modules = files, module_name = name } or nil, (T.lua_bindings or {})[name] ~= nil
474
552
  end
553
+ if best.self_info then return { lua_self = best.self_info }, true end
475
554
  local imported = tonumber(best.hint:match('^lua:(%d+)$'))
476
555
  if imported then
477
556
  local imp = rec.lua_imports[imported]
@@ -504,12 +583,19 @@ function M.resolve(G, f, name, hint, ctx, recv)
504
583
  if not hint or hint == '' then
505
584
  local result = {}
506
585
  for _, target in ipairs(M.native_modules(G, recv, ctx)) do
507
- local n = require('codeoutline.foreign').exports(G.files[target], 'lua', recv)[name]
586
+ local n = require('codeoutline.analysis.foreign').exports(G.files[target], 'lua', recv)[name]
508
587
  if n then result[#result + 1] = G.id_of[target][n] end
509
588
  end
510
589
  return #result > 0 and result or nil
511
590
  end
512
591
  if hint == '?' then return {} end
592
+ local self_index = tonumber(hint:match('^lua%-self:(%d+)$'))
593
+ if self_index then
594
+ local rec = G.files[f]
595
+ local selves = rec.lua_self or ctx and ctx.ordinary and ctx.ordinary.data(f).lua_self or {}
596
+ local n = selves[self_index] and selves[self_index].members[name]
597
+ return n and { G.id_of[f][n] } or {}
598
+ end
513
599
  local local_index = tonumber(hint:match('^lua%-local:(%d+)$'))
514
600
  if local_index then
515
601
  local rec = G.files[f]
@@ -525,7 +611,7 @@ function M.resolve(G, f, name, hint, ctx, recv)
525
611
  local result = {}
526
612
  for _, target in ipairs(M.modules(G, imp, ctx)) do
527
613
  local rec = G.files[target]
528
- local exports = require('codeoutline.foreign').exports(rec, 'lua', imp.path) or rec.lua_exports
614
+ local exports = require('codeoutline.analysis.foreign').exports(rec, 'lua', imp.path) or rec.lua_exports
529
615
  local n = (exports or {})[name]
530
616
  if n then result[#result + 1] = G.id_of[target][n] end
531
617
  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'