@codua/codeoutline-win32-x64 0.1.9 → 0.2.1

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 (40) hide show
  1. package/README.md +38 -6
  2. package/README.zh-CN.md +36 -6
  3. package/THIRD_PARTY.md +3 -3
  4. package/bin/xnet.exe +0 -0
  5. package/build-info.json +1 -1
  6. package/package.json +1 -1
  7. package/scripts/codeoutline/cli.lua +2 -2
  8. package/scripts/codeoutline/command.lua +9 -1
  9. package/scripts/codeoutline/common.lua +45 -5
  10. package/scripts/codeoutline/completion.lua +936 -0
  11. package/scripts/codeoutline/control.lua +5 -1
  12. package/scripts/codeoutline/documents.lua +154 -0
  13. package/scripts/codeoutline/explore.lua +35 -8
  14. package/scripts/codeoutline/graph.lua +321 -102
  15. package/scripts/codeoutline/index.lua +170 -50
  16. package/scripts/codeoutline/index_worker.lua +108 -17
  17. package/scripts/codeoutline/indirect.lua +201 -0
  18. package/scripts/codeoutline/js_evidence.lua +175 -0
  19. package/scripts/codeoutline/js_resolution.lua +201 -0
  20. package/scripts/codeoutline/lang/c.lua +22 -12
  21. package/scripts/codeoutline/lang/cpp.lua +13 -12
  22. package/scripts/codeoutline/lang/csharp.lua +21 -21
  23. package/scripts/codeoutline/lang/go.lua +10 -10
  24. package/scripts/codeoutline/lang/java.lua +9 -9
  25. package/scripts/codeoutline/lang/js.lua +15 -14
  26. package/scripts/codeoutline/lang/kotlin.lua +384 -0
  27. package/scripts/codeoutline/lang/lua.lua +11 -6
  28. package/scripts/codeoutline/lang/python.lua +6 -6
  29. package/scripts/codeoutline/lang/rust.lua +23 -15
  30. package/scripts/codeoutline/lsp.lua +574 -0
  31. package/scripts/codeoutline/lua_bindings.lua +222 -0
  32. package/scripts/codeoutline/main.lua +28 -5
  33. package/scripts/codeoutline/navigation.lua +1046 -0
  34. package/scripts/codeoutline/parse.lua +9 -2
  35. package/scripts/codeoutline/parse_pool.lua +189 -0
  36. package/scripts/codeoutline/parse_worker.lua +24 -0
  37. package/scripts/codeoutline/service.lua +82 -31
  38. package/scripts/codeoutline/update_sequence.lua +1 -1
  39. package/scripts/codeoutline/version.lua +1 -1
  40. package/licenses/rpmalloc.txt +0 -12
@@ -1,12 +1,20 @@
1
1
  -- graph.lua — cross-file resolution over an index: global symbol tables,
2
- -- file dependencies (#include / import), and call edges between nodes.
2
+ -- file dependencies (#include / import), and call edges resolved per query.
3
3
  --
4
- -- local G = graph.build(idx)
4
+ -- local G = graph.build(idx) -- symbol and path tables, kept per file
5
5
  -- G.nodes[id] -> <node table> (shared with the file record)
6
6
  -- G.node_file[id] -> file index
7
7
  -- G.files[f] -> file record (path, language, nodes, refs, imports)
8
- -- G.by_name[name] -> { id, ... }
9
- -- G.out[id], G.inn[id] -> { other, line, kind, other, line, kind, ... }
8
+ -- G.file_order -> { f, ... } in path order
9
+ -- G.by_name[name] -> { id, ... } in path, then node order
10
+ -- G.by_owner[q] -> members of qualifier q (`Box` for `Box::area`)
11
+ -- local Q = graph.query(G)
12
+ -- Q.out[id], Q.inn[id] -> { other, line, kind, other, line, kind, ... }
13
+ --
14
+ -- Tables change one file at a time (add_file / remove_file). File and node
15
+ -- ids are never reused while the tables live, so removed files leave holes:
16
+ -- iterate file_order, and compare nodes with graph.before rather than by id.
17
+ -- Every ordered list matches what a fresh build of the same records gives.
10
18
  --
11
19
  -- Edge lists are flat, EDGE values per edge, and nodes carry no wrapper
12
20
  -- table: on large trees per-edge and per-node tables cost more than the
@@ -19,6 +27,8 @@
19
27
  -- to MAX_TIES targets instead of guessing.
20
28
 
21
29
  local control = require('codeoutline.control')
30
+ local js_resolution = require('codeoutline.js_resolution')
31
+ local lua_bindings = require('codeoutline.lua_bindings')
22
32
  local M = {}
23
33
 
24
34
  M.EDGE = 3
@@ -58,7 +68,7 @@ local function push3(t, k, a, b, c)
58
68
  end
59
69
 
60
70
  -- Files a file depends on, resolved from its #include / import records.
61
- local function resolve_deps(G, f)
71
+ local function resolve_deps(G, f, js_context)
62
72
  local rec = G.files[f]
63
73
  local deps = {}
64
74
  local function add(g) if g and g ~= f then deps[g] = true end end
@@ -66,6 +76,16 @@ local function resolve_deps(G, f)
66
76
  for _, imp in ipairs(rec.imports) do
67
77
  local path = imp.path
68
78
  if C_FAMILY[rec.language] then
79
+ path = path:gsub('\\', '/')
80
+ if path:find('^%.%.?/') then
81
+ -- "../dir/x.h": relative to the including file first
82
+ local parts = {}
83
+ for segment in ((here ~= '' and here .. '/' or '') .. path):gmatch('[^/]+') do
84
+ if segment == '..' then parts[#parts] = nil
85
+ elseif segment ~= '.' then parts[#parts + 1] = segment end
86
+ end
87
+ add(G.file_index[table.concat(parts, '/')])
88
+ end
69
89
  -- "dir/x.h": files whose path ends with it, preferring the closest
70
90
  for _, g in ipairs(G.by_base[basename(path)] or {}) do
71
91
  local p = G.files[g].path
@@ -107,19 +127,7 @@ local function resolve_deps(G, f)
107
127
  -- require 'a.b' -> a/b.lua or a/b/init.lua anywhere under the root
108
128
  -- (package.path prefixes like scripts/?.lua vary per project);
109
129
  -- dofile/loadfile take a path.
110
- local wants
111
- if imp.kind == 'require' then
112
- local sub = path:gsub('%.', '/')
113
- wants = { sub .. '.lua', sub .. '/init.lua' }
114
- else
115
- wants = { (path:gsub('\\', '/'):gsub('^%./', '')) }
116
- end
117
- for _, want in ipairs(wants) do
118
- for _, g in ipairs(G.by_base[basename(want)] or {}) do
119
- local p = G.files[g].path
120
- if p == want or p:sub(-(#want + 1)) == '/' .. want then add(g) end
121
- end
122
- end
130
+ for _, g in ipairs(lua_bindings.modules(G, imp, js_context and js_context.lua)) do add(g) end
123
131
  elseif rec.language == 'go' then
124
132
  -- import "github.com/org/repo/pkg/sub": the package is the directory
125
133
  -- whose path ends with the longest matching suffix of the import
@@ -137,22 +145,7 @@ local function resolve_deps(G, f)
137
145
  if hit then break end
138
146
  end
139
147
  elseif rec.language == 'javascript' or rec.language == 'typescript' then
140
- -- relative specifiers only; bare package names live in node_modules
141
- if path:sub(1, 1) == '.' then
142
- local base = here
143
- local rel = path
144
- while true do
145
- if rel:sub(1, 2) == './' then rel = rel:sub(3)
146
- elseif rel:sub(1, 3) == '../' then base = dirname(base); rel = rel:sub(4)
147
- else break end
148
- end
149
- local stemp = (base ~= '' and (base .. '/') or '') .. rel
150
- stemp = stemp:gsub('%.[mc]?js$', '') -- TS sources imported as ./x.js
151
- for _, ext in ipairs({ '', '.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.mts',
152
- '/index.ts', '/index.tsx', '/index.js', '/index.mjs' }) do
153
- add(G.file_index[stemp .. ext])
154
- end
155
- end
148
+ add(js_resolution.module(G, f, path, js_context))
156
149
  elseif rec.language == 'csharp' then
157
150
  for _, g in ipairs(G.ns_files[path] or {}) do add(g) end
158
151
  elseif rec.language == 'rust' then
@@ -184,9 +177,12 @@ local function resolve_deps(G, f)
184
177
  if found then break end
185
178
  end
186
179
  end
187
- elseif rec.language == 'java' then
180
+ elseif rec.language == 'java' or rec.language == 'kotlin' then
188
181
  if path:sub(-2) == '.*' then
189
182
  for _, g in ipairs(G.pkg_files[path:sub(1, -3)] or {}) do add(g) end
183
+ if rec.language == 'kotlin' then
184
+ for _, id in ipairs(G.by_owner[path:sub(1, -3)] or {}) do add(G.node_file[id]) end
185
+ end
190
186
  else
191
187
  for _, id in ipairs(G.by_qualified[path] or {}) do add(G.node_file[id]) end
192
188
  end
@@ -194,7 +190,7 @@ local function resolve_deps(G, f)
194
190
  end
195
191
  -- Java: the whole package is visible without imports; Go: the whole
196
192
  -- directory is one package; C#: the file's own namespaces.
197
- if rec.language == 'java' and rec.package then
193
+ if (rec.language == 'java' or rec.language == 'kotlin') and rec.package then
198
194
  for _, g in ipairs(G.pkg_files[rec.package] or {}) do add(g) end
199
195
  elseif rec.language == 'go' then
200
196
  for _, g in ipairs(G.dir_files[here] or {}) do add(g) end
@@ -241,7 +237,11 @@ end
241
237
  -- unrelated, nil when invisible (a C static of another file).
242
238
  local function locality(G, f, cf, c, deps, paired)
243
239
  if cf == f then return 100 end
244
- if c.static then return nil end
240
+ if c.static then
241
+ -- `static inline` helpers in an included header serve every includer.
242
+ if deps[cf] and HEADER_EXT[G.files[cf].path:match('%.(%w+)$') or ''] then return 50 end
243
+ return nil
244
+ end
245
245
  if deps[cf] then return 50 end
246
246
  if paired[cf] then return 40 end
247
247
  if G.file_dir[cf] == G.file_dir[f] then return 20 end
@@ -269,7 +269,7 @@ local function score(G, f, src_id, ref_kind, recv, cid, deps, paired, owner)
269
269
  -- method project-wide (str.format -> some format()) is mostly wrong,
270
270
  -- so only local candidates qualify.
271
271
  return nil
272
- elseif ref_kind == 'call' and G.files[f].language == 'java' and src_id then
272
+ elseif ref_kind == 'call' and (G.files[f].language == 'java' or G.files[f].language == 'kotlin') and src_id then
273
273
  -- unqualified call inside a class: implicit this
274
274
  if owner and c.parent and G.id_of[cf][c.parent] == owner then s = s + 30 end
275
275
  end
@@ -282,11 +282,32 @@ local function is_decl(node) return node.kind == 'prototype' or node.decl end
282
282
  -- keep the hot loop allocation-free; only the first n entries are live.
283
283
  local scored_ids, scored_vals = {}, {}
284
284
 
285
- local function resolve_ref(G, f, src_id, name, kind, recv, deps, paired)
285
+ -- accept overrides the node kinds the ref kind may bind to (navigation only).
286
+ local function resolve_ref(G, f, src_id, name, kind, recv, deps, paired, accept, evidence, js_context)
286
287
  if kind == 'annotation' then return nil end
287
- local accept = CALLABLE
288
- if kind == 'new' then accept = NEWABLE elseif kind == 'ref' then accept = VALUE end
288
+ accept = accept or (kind == 'new' and NEWABLE) or (kind == 'ref' and VALUE) or CALLABLE
289
+ if evidence == '' then evidence = nil end
290
+ local exact = js_resolution.resolve(G, f, name, kind, recv, evidence, js_context)
291
+ if exact == nil then exact = lua_bindings.resolve(G, f, name, evidence, js_context and js_context.lua) end
292
+ if exact ~= nil then
293
+ local result = {}
294
+ for _, id in ipairs(exact) do if accept[G.nodes[id].kind] then result[#result + 1] = id end end
295
+ return result
296
+ end
289
297
  local cands = G.by_name[name]
298
+ if G.files[f].language == 'kotlin' and not recv then
299
+ for _, imp in ipairs(G.files[f].imports) do
300
+ if (imp.alias or imp.path:match('([^.]+)$')) == name then
301
+ cands = {}
302
+ -- by_name also includes unsaved LSP overlays; by_qualified is
303
+ -- a resident index and may still name the masked disk nodes.
304
+ for _, id in ipairs(G.by_name[imp.path:match('([^.]+)$')] or {}) do
305
+ if G.nodes[id].qualified == imp.path then cands[#cands + 1] = id end
306
+ end
307
+ break
308
+ end
309
+ end
310
+ end
290
311
  if not cands then return nil end
291
312
  -- Score first: score() rejects other languages and statics of other
292
313
  -- files, so "is there a real definition?" is only asked among the
@@ -294,7 +315,7 @@ local function resolve_ref(G, f, src_id, name, kind, recv, deps, paired)
294
315
  -- same-named nodes let a Python `def work` hide the C prototype of
295
316
  -- `work`, after which the Python def was filtered out too.)
296
317
  local self_call = kind == 'member_call' and src_id and (recv == 'self' or recv == 'this' or recv == 'cls')
297
- local owner = (self_call or (kind == 'call' and src_id and G.files[f].language == 'java'))
318
+ local owner = (self_call or (kind == 'call' and src_id and (G.files[f].language == 'java' or G.files[f].language == 'kotlin')))
298
319
  and owner_class(G, src_id) or nil
299
320
  -- score() rejects an unknown-receiver member call to an unrelated file;
300
321
  -- checking placement first skips most candidates of common method names.
@@ -332,81 +353,279 @@ local function resolve_ref(G, f, src_id, name, kind, recv, deps, paired)
332
353
  return ties
333
354
  end
334
355
 
356
+ -- Files compare by path; nodes by file path, then node order (ids ascend
357
+ -- within a file). Both are strict total orders over live entries.
358
+ local function file_before(G, a, b) return G.files[a].path < G.files[b].path end
359
+ local function node_before(G, a, b)
360
+ local fa, fb = G.node_file[a], G.node_file[b]
361
+ if fa == fb then return a < b end
362
+ return G.files[fa].path < G.files[fb].path
363
+ end
364
+ local function string_before(_, a, b) return a < b end
365
+ M.before = node_before
366
+
367
+ -- Position of v (or where it belongs) in an ordered list.
368
+ local function search(G, list, v, before)
369
+ local lo, hi = 1, #list + 1
370
+ while lo < hi do
371
+ local mid = math.floor((lo + hi) / 2)
372
+ if before(G, list[mid], v) then lo = mid + 1 else hi = mid end
373
+ end
374
+ return lo
375
+ end
376
+
377
+ -- Ordered insert; a build in path order appends after one comparison.
378
+ local function insert(G, t, key, v, before)
379
+ local list = t[key]
380
+ if not list then t[key] = { v }; return end
381
+ local n = #list
382
+ if before(G, list[n], v) then list[n + 1] = v; return end
383
+ table.insert(list, search(G, list, v, before), v)
384
+ end
385
+
386
+ local function remove(G, t, key, v, before)
387
+ local list = t[key]
388
+ if not list then return end
389
+ local i = search(G, list, v, before)
390
+ if list[i] ~= v then return end
391
+ table.remove(list, i)
392
+ if #list == 0 then t[key] = nil end
393
+ end
394
+
395
+ function M.new()
396
+ return { files = {}, file_index = {}, file_order = {}, file_dir = {}, dir_ids = {}, nodes = {}, node_file = {},
397
+ id_of = {}, by_name = {}, by_lname = {}, by_qualified = {}, by_owner = {}, by_base = {}, by_stem = {}, pkg_files = {},
398
+ children = {}, dir_files = {}, dir_by_base = {}, ns_files = {},
399
+ next_file = 0, next_node = 0, next_dir = 0, file_count = 0, node_count = 0 }
400
+ end
401
+
402
+ local function namespaces(rec)
403
+ local seen = {}
404
+ if rec.language == 'csharp' then
405
+ for _, node in ipairs(rec.nodes) do
406
+ if node.kind == 'namespace' then seen[node.qualified] = true end
407
+ end
408
+ end
409
+ return seen
410
+ end
411
+
412
+ -- Qualifier of a qualified name: `Box` for `Box::area`, `M` for `M:split` or `M.trim`.
413
+ -- by_owner lists members wherever they are defined (out-of-line, other files).
414
+ function M.owner(qualified)
415
+ return qualified:match('^(.+)::[^:]+$') or qualified:match('^(.+)[%.:][^%.:]+$')
416
+ end
417
+
418
+ -- Add a record under rel. No cancellation checkpoints: index commits call
419
+ -- this and must not stop halfway.
420
+ function M.add_file(G, rel, rec)
421
+ assert(not G.file_index[rel], 'file already in symbol tables: ' .. rel)
422
+ local f = G.next_file + 1
423
+ G.next_file = f
424
+ G.files[f], G.file_index[rel] = rec, f
425
+ G.file_order[#G.file_order + 1] = f
426
+ local order = G.file_order
427
+ if #order > 1 and not file_before(G, order[#order - 1], f) then
428
+ table.remove(order)
429
+ table.insert(order, search(G, order, f, file_before), f)
430
+ end
431
+ local dir = dirname(rel)
432
+ local did = G.dir_ids[dir]
433
+ if not did then G.next_dir = G.next_dir + 1; did = G.next_dir; G.dir_ids[dir] = did end
434
+ G.file_dir[f] = did
435
+ insert(G, G.by_base, basename(rel), f, file_before)
436
+ insert(G, G.by_stem, stem(rel), f, file_before)
437
+ if not G.dir_files[dir] then insert(G, G.dir_by_base, basename(dir), dir, string_before) end
438
+ insert(G, G.dir_files, dir, f, file_before)
439
+ if rec.package then insert(G, G.pkg_files, rec.package, f, file_before) end
440
+ for qualified in pairs(namespaces(rec)) do insert(G, G.ns_files, qualified, f, file_before) end
441
+ local ids = {}
442
+ G.id_of[f] = ids
443
+ for n, node in ipairs(rec.nodes) do
444
+ local id = G.next_node + 1
445
+ G.next_node = id
446
+ G.nodes[id], G.node_file[id] = node, f
447
+ ids[n] = id
448
+ insert(G, G.by_name, node.name, id, node_before)
449
+ insert(G, G.by_lname, node.name:lower(), id, node_before)
450
+ insert(G, G.by_qualified, node.qualified, id, node_before)
451
+ local owner = M.owner(node.qualified)
452
+ if owner then insert(G, G.by_owner, owner, id, node_before) end
453
+ if node.parent then push(G.children, ids[node.parent], id) end
454
+ end
455
+ G.file_count, G.node_count = G.file_count + 1, G.node_count + #rec.nodes
456
+ return f
457
+ end
458
+
459
+ function M.remove_file(G, rel)
460
+ local f = G.file_index[rel]
461
+ if not f then return end
462
+ local rec, ids = G.files[f], G.id_of[f]
463
+ for _, id in ipairs(ids) do
464
+ local node = G.nodes[id]
465
+ remove(G, G.by_name, node.name, id, node_before)
466
+ remove(G, G.by_lname, node.name:lower(), id, node_before)
467
+ remove(G, G.by_qualified, node.qualified, id, node_before)
468
+ local owner = M.owner(node.qualified)
469
+ if owner then remove(G, G.by_owner, owner, id, node_before) end
470
+ G.children[id] = nil
471
+ end
472
+ for _, id in ipairs(ids) do G.nodes[id], G.node_file[id] = nil, nil end
473
+ local dir = dirname(rel)
474
+ remove(G, G.by_base, basename(rel), f, file_before)
475
+ remove(G, G.by_stem, stem(rel), f, file_before)
476
+ remove(G, G.dir_files, dir, f, file_before)
477
+ if not G.dir_files[dir] then remove(G, G.dir_by_base, basename(dir), dir, string_before) end
478
+ if rec.package then remove(G, G.pkg_files, rec.package, f, file_before) end
479
+ for qualified in pairs(namespaces(rec)) do remove(G, G.ns_files, qualified, f, file_before) end
480
+ local order = G.file_order
481
+ table.remove(order, search(G, order, f, file_before))
482
+ G.files[f], G.file_index[rel], G.id_of[f], G.file_dir[f] = nil, nil, nil, nil
483
+ G.file_count, G.node_count = G.file_count - 1, G.node_count - #ids
484
+ end
485
+
486
+ -- Symbol tables for every record of idx. Checkpoints per file: a cancelled
487
+ -- build is simply discarded.
335
488
  function M.build(idx)
336
- local G = {
337
- files = {}, file_index = {}, file_dir = {}, nodes = {}, node_file = {}, id_of = {},
338
- by_name = {}, by_lname = {}, by_qualified = {}, by_base = {}, by_stem = {},
339
- pkg_files = {}, children = {}, out = {}, inn = {}, deps = {}, dir_files = {}, ns_files = {},
340
- generation = idx.generation,
341
- }
489
+ local G = M.new()
490
+ G.root = idx.root
342
491
  local paths = {}
343
492
  for rel in pairs(idx.files) do paths[#paths + 1] = rel end
344
493
  table.sort(paths)
345
- -- Directory ids per file: placement scoring compares numbers instead of
346
- -- slicing two paths per candidate.
347
- local dir_ids = {}
348
- -- Checkpoints per file: LuaJIT does not run count hooks inside compiled
349
- -- loops, so cancellation relies on these (as in Index:refresh).
350
- for f, rel in ipairs(paths) do
494
+ for _, rel in ipairs(paths) do
351
495
  control.check()
352
- local rec = idx.files[rel]
353
- G.files[f] = rec
354
- G.file_index[rel] = f
355
- local dir = dirname(rel)
356
- local did = dir_ids[dir]
357
- if not did then did = f; dir_ids[dir] = did end
358
- G.file_dir[f] = did
359
- push(G.by_base, basename(rel), f)
360
- push(G.by_stem, stem(rel), f)
361
- push(G.dir_files, dirname(rel), f)
362
- if rec.package then push(G.pkg_files, rec.package, f) end
363
- local ids = {}
364
- G.id_of[f] = ids
365
- for n, node in ipairs(rec.nodes) do
366
- local id = #G.nodes + 1
367
- G.nodes[id], G.node_file[id] = node, f
368
- ids[n] = id
369
- push(G.by_name, node.name, id)
370
- push(G.by_lname, node.name:lower(), id)
371
- push(G.by_qualified, node.qualified, id)
372
- if node.kind == 'namespace' and rec.language == 'csharp' then
373
- local list = G.ns_files[node.qualified]
374
- if not list or list[#list] ~= f then push(G.ns_files, node.qualified, f) end
375
- end
376
- if node.parent then push(G.children, ids[node.parent], id) end
496
+ M.add_file(G, rel, idx.files[rel])
497
+ end
498
+ G.generation = idx.generation
499
+ return G
500
+ end
501
+
502
+ -- Query-owned edges: never attach these caches to the resident symbol tables.
503
+ M.MAX_EXPANDED = 20000
504
+ function M.query(symbols, opts)
505
+ opts = opts or {}
506
+ local limit = opts.max_expanded or M.MAX_EXPANDED
507
+ assert(type(limit) == 'number' and limit >= 1 and limit % 1 == 0 and limit < math.huge,
508
+ 'max_expanded must be a positive integer')
509
+ local Q = setmetatable({ out = {}, inn = {},
510
+ stats = { expanded = 0, incoming_scans = 0, resolved_refs = 0 }, incomplete = false }, { __index = symbols })
511
+ local dependencies, references = {}, {}
512
+ local js_context = js_resolution.context(symbols)
513
+ js_context.lua = lua_bindings.context(symbols)
514
+ local indirect = require('codeoutline.indirect').query(symbols, opts.dispatch_rules)
515
+ local function deps(f)
516
+ local entry = dependencies[f]
517
+ if not entry then
518
+ local direct, paired = resolve_deps(symbols, f, js_context)
519
+ entry = { direct, paired }; dependencies[f] = entry
377
520
  end
521
+ return entry[1], entry[2]
378
522
  end
379
- -- Directories indexed by their last path segment (Go import lookups).
380
- G.dir_by_base = {}
381
- for d in pairs(G.dir_files) do push(G.dir_by_base, basename(d), d) end
382
- for _, list in pairs(G.dir_by_base) do table.sort(list) end
383
- -- Edges.
384
- local edges = 0
385
- for f, rec in ipairs(G.files) do
523
+ local function targets(f, i)
524
+ local rec, ids = symbols.files[f], symbols.id_of[f]
525
+ local refs = rec.refs
526
+ local direct, paired = deps(f)
527
+ Q.stats.resolved_refs = Q.stats.resolved_refs + 1
528
+ return resolve_ref(symbols, f, ids[refs.from[i]], refs.name[i], refs.kind[i],
529
+ refs.recv[i] or nil, direct, paired, nil, refs.lua_binding and refs.lua_binding[i] or refs.js_receiver and refs.js_receiver[i], js_context)
530
+ end
531
+ setmetatable(Q.out, { __index = function(cache, id)
386
532
  control.check()
387
- local deps, paired = resolve_deps(G, f)
388
- G.deps[f] = deps
389
- local refs, ids = rec.refs, G.id_of[f]
390
- local names, froms, kinds, lines, recvs = refs.name, refs.from, refs.kind, refs.line, refs.recv
391
- for i = 1, #names do
392
- local from = froms[i]
393
- if from > 0 then
394
- local src, kind, line = ids[from], kinds[i], lines[i]
395
- local targets = resolve_ref(G, f, src, names[i], kind, recvs[i] or nil, deps, paired)
396
- if targets then
397
- for _, dst in ipairs(targets) do
398
- push3(G.out, src, dst, line, kind)
399
- push3(G.inn, dst, src, line, kind)
400
- edges = edges + 1
533
+ if Q.stats.expanded >= limit then Q.incomplete = true; return nil end
534
+ Q.stats.expanded = Q.stats.expanded + 1
535
+ local f = assert(symbols.node_file[id], 'unknown symbol')
536
+ local rec, ids = symbols.files[f], symbols.id_of[f]
537
+ local grouped = references[f]
538
+ if not grouped then
539
+ grouped = {}
540
+ for i, from in ipairs(rec.refs.from) do
541
+ if i % 128 == 0 then control.check() end
542
+ if from > 0 then push(grouped, ids[from], i) end
543
+ end
544
+ references[f] = grouped
545
+ end
546
+ local edges = {}
547
+ for _, edge in ipairs(indirect.outgoing(id)) do
548
+ edges[#edges + 1] = edge.target
549
+ edges[#edges + 1] = edge.line
550
+ edges[#edges + 1] = edge.kind
551
+ end
552
+ for _, i in ipairs(grouped[id] or {}) do
553
+ control.check()
554
+ for _, dst in ipairs(targets(f, i) or {}) do
555
+ edges[#edges + 1] = dst
556
+ edges[#edges + 1] = rec.refs.line[i]
557
+ edges[#edges + 1] = rec.refs.kind[i]
558
+ end
559
+ end
560
+ rawset(cache, id, edges)
561
+ return edges
562
+ end })
563
+ -- Resolve all requested callers with a single ordered multi-name scan.
564
+ function Q:load_incoming(ids)
565
+ local wanted, names, found = {}, {}, false
566
+ for _, id in ipairs(ids) do
567
+ if rawget(self.inn, id) == nil then
568
+ wanted[id], names[symbols.nodes[id].name], found = true, true, true
569
+ end
570
+ end
571
+ if not found then return end
572
+ local incoming = {}
573
+ for id in pairs(wanted) do incoming[id] = {} end
574
+ local indirect_incoming = indirect.incoming(wanted)
575
+ for _, f in ipairs(symbols.file_order) do
576
+ for _, src in ipairs(symbols.id_of[f]) do
577
+ for _, edge in ipairs(indirect_incoming[src] or {}) do
578
+ if wanted[edge.target] then push3(incoming, edge.target, src, edge.line, edge.kind) end
579
+ end
580
+ end
581
+ end
582
+ self.stats.incoming_scans = self.stats.incoming_scans + 1
583
+ -- Hot loop over every reference: numeric loops, hoisted fields, and the
584
+ -- selective name test first. Checkpoints run per file and per chunk.
585
+ local files = symbols.files
586
+ for _, f in ipairs(symbols.file_order) do
587
+ control.check()
588
+ local aliases = {}
589
+ for _, binding in ipairs(files[f].js_imports or {}) do aliases[binding.local_name] = true end
590
+ if files[f].language == 'kotlin' then
591
+ for _, imp in ipairs(files[f].imports) do
592
+ if imp.alias and names[imp.path:match('([^.]+)$')] then aliases[imp.alias] = true end
593
+ end
594
+ end
595
+ local refs = files[f].refs
596
+ local ref_names, froms = refs.name, refs.from
597
+ local count = #ref_names
598
+ for first = 1, count, 4096 do
599
+ if first > 1 then control.check() end
600
+ for i = first, math.min(count, first + 4095) do
601
+ if (names[ref_names[i]] or aliases[ref_names[i]] or aliases[refs.recv[i]] or (refs.lua_binding and refs.lua_binding[i] ~= '')) and froms[i] > 0 then
602
+ for _, dst in ipairs(targets(f, i) or {}) do
603
+ if wanted[dst] then
604
+ push3(incoming, dst, symbols.id_of[f][froms[i]], refs.line[i], refs.kind[i])
605
+ end
606
+ end
401
607
  end
402
608
  end
403
609
  end
404
610
  end
611
+ -- Interrupted scans never publish partial caller lists.
612
+ for id, edges in pairs(incoming) do rawset(self.inn, id, edges) end
405
613
  end
406
- G.edge_count = edges
407
- return G
614
+ setmetatable(Q.inn, { __index = function(cache, id)
615
+ Q:load_incoming({ id })
616
+ return rawget(cache, id)
617
+ end })
618
+ return Q
408
619
  end
409
620
 
621
+ -- Navigation reuses the resolver over symbol tables or overlays of them.
622
+ M.CALLABLE = CALLABLE
623
+ M.dependencies = resolve_deps
624
+ M.resolve = resolve_ref
625
+ M.placement = locality
626
+ M.is_decl = is_decl
627
+ M.family = family
628
+
410
629
  -- Location string for a node: "path:line".
411
630
  function M.where(G, id)
412
631
  return G.files[G.node_file[id]].path .. ':' .. G.nodes[id].line