@codua/codeoutline-win32-x64 0.1.8 → 0.2.0

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 (38) hide show
  1. package/README.md +32 -5
  2. package/README.zh-CN.md +32 -5
  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 +36 -5
  10. package/scripts/codeoutline/completion.lua +913 -0
  11. package/scripts/codeoutline/control.lua +5 -1
  12. package/scripts/codeoutline/daemon.lua +4 -2
  13. package/scripts/codeoutline/documents.lua +154 -0
  14. package/scripts/codeoutline/explore.lua +32 -7
  15. package/scripts/codeoutline/graph.lua +264 -68
  16. package/scripts/codeoutline/index.lua +168 -48
  17. package/scripts/codeoutline/index_worker.lua +108 -17
  18. package/scripts/codeoutline/lang/c.lua +22 -12
  19. package/scripts/codeoutline/lang/cpp.lua +13 -12
  20. package/scripts/codeoutline/lang/csharp.lua +21 -21
  21. package/scripts/codeoutline/lang/go.lua +10 -10
  22. package/scripts/codeoutline/lang/java.lua +9 -9
  23. package/scripts/codeoutline/lang/js.lua +15 -14
  24. package/scripts/codeoutline/lang/lua.lua +9 -6
  25. package/scripts/codeoutline/lang/python.lua +6 -6
  26. package/scripts/codeoutline/lang/rust.lua +23 -15
  27. package/scripts/codeoutline/lsp.lua +574 -0
  28. package/scripts/codeoutline/main.lua +28 -5
  29. package/scripts/codeoutline/navigation.lua +934 -0
  30. package/scripts/codeoutline/parse.lua +8 -2
  31. package/scripts/codeoutline/parse_pool.lua +189 -0
  32. package/scripts/codeoutline/parse_worker.lua +24 -0
  33. package/scripts/codeoutline/service.lua +82 -31
  34. package/scripts/codeoutline/update_sequence.lua +1 -1
  35. package/scripts/codeoutline/updater.lua +1 -1
  36. package/scripts/codeoutline/version.lua +1 -1
  37. package/scripts/xupgate/client.lua +8 -0
  38. 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
@@ -66,6 +74,16 @@ local function resolve_deps(G, f)
66
74
  for _, imp in ipairs(rec.imports) do
67
75
  local path = imp.path
68
76
  if C_FAMILY[rec.language] then
77
+ path = path:gsub('\\', '/')
78
+ if path:find('^%.%.?/') then
79
+ -- "../dir/x.h": relative to the including file first
80
+ local parts = {}
81
+ for segment in ((here ~= '' and here .. '/' or '') .. path):gmatch('[^/]+') do
82
+ if segment == '..' then parts[#parts] = nil
83
+ elseif segment ~= '.' then parts[#parts + 1] = segment end
84
+ end
85
+ add(G.file_index[table.concat(parts, '/')])
86
+ end
69
87
  -- "dir/x.h": files whose path ends with it, preferring the closest
70
88
  for _, g in ipairs(G.by_base[basename(path)] or {}) do
71
89
  local p = G.files[g].path
@@ -241,7 +259,11 @@ end
241
259
  -- unrelated, nil when invisible (a C static of another file).
242
260
  local function locality(G, f, cf, c, deps, paired)
243
261
  if cf == f then return 100 end
244
- if c.static then return nil end
262
+ if c.static then
263
+ -- `static inline` helpers in an included header serve every includer.
264
+ if deps[cf] and HEADER_EXT[G.files[cf].path:match('%.(%w+)$') or ''] then return 50 end
265
+ return nil
266
+ end
245
267
  if deps[cf] then return 50 end
246
268
  if paired[cf] then return 40 end
247
269
  if G.file_dir[cf] == G.file_dir[f] then return 20 end
@@ -282,10 +304,10 @@ local function is_decl(node) return node.kind == 'prototype' or node.decl end
282
304
  -- keep the hot loop allocation-free; only the first n entries are live.
283
305
  local scored_ids, scored_vals = {}, {}
284
306
 
285
- local function resolve_ref(G, f, src_id, name, kind, recv, deps, paired)
307
+ -- accept overrides the node kinds the ref kind may bind to (navigation only).
308
+ local function resolve_ref(G, f, src_id, name, kind, recv, deps, paired, accept)
286
309
  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
310
+ accept = accept or (kind == 'new' and NEWABLE) or (kind == 'ref' and VALUE) or CALLABLE
289
311
  local cands = G.by_name[name]
290
312
  if not cands then return nil end
291
313
  -- Score first: score() rejects other languages and statics of other
@@ -332,81 +354,255 @@ local function resolve_ref(G, f, src_id, name, kind, recv, deps, paired)
332
354
  return ties
333
355
  end
334
356
 
357
+ -- Files compare by path; nodes by file path, then node order (ids ascend
358
+ -- within a file). Both are strict total orders over live entries.
359
+ local function file_before(G, a, b) return G.files[a].path < G.files[b].path end
360
+ local function node_before(G, a, b)
361
+ local fa, fb = G.node_file[a], G.node_file[b]
362
+ if fa == fb then return a < b end
363
+ return G.files[fa].path < G.files[fb].path
364
+ end
365
+ local function string_before(_, a, b) return a < b end
366
+ M.before = node_before
367
+
368
+ -- Position of v (or where it belongs) in an ordered list.
369
+ local function search(G, list, v, before)
370
+ local lo, hi = 1, #list + 1
371
+ while lo < hi do
372
+ local mid = math.floor((lo + hi) / 2)
373
+ if before(G, list[mid], v) then lo = mid + 1 else hi = mid end
374
+ end
375
+ return lo
376
+ end
377
+
378
+ -- Ordered insert; a build in path order appends after one comparison.
379
+ local function insert(G, t, key, v, before)
380
+ local list = t[key]
381
+ if not list then t[key] = { v }; return end
382
+ local n = #list
383
+ if before(G, list[n], v) then list[n + 1] = v; return end
384
+ table.insert(list, search(G, list, v, before), v)
385
+ end
386
+
387
+ local function remove(G, t, key, v, before)
388
+ local list = t[key]
389
+ if not list then return end
390
+ local i = search(G, list, v, before)
391
+ if list[i] ~= v then return end
392
+ table.remove(list, i)
393
+ if #list == 0 then t[key] = nil end
394
+ end
395
+
396
+ function M.new()
397
+ return { files = {}, file_index = {}, file_order = {}, file_dir = {}, dir_ids = {}, nodes = {}, node_file = {},
398
+ id_of = {}, by_name = {}, by_lname = {}, by_qualified = {}, by_owner = {}, by_base = {}, by_stem = {}, pkg_files = {},
399
+ children = {}, dir_files = {}, dir_by_base = {}, ns_files = {},
400
+ next_file = 0, next_node = 0, next_dir = 0, file_count = 0, node_count = 0 }
401
+ end
402
+
403
+ local function namespaces(rec)
404
+ local seen = {}
405
+ if rec.language == 'csharp' then
406
+ for _, node in ipairs(rec.nodes) do
407
+ if node.kind == 'namespace' then seen[node.qualified] = true end
408
+ end
409
+ end
410
+ return seen
411
+ end
412
+
413
+ -- Qualifier of a qualified name: `Box` for `Box::area`, `M` for `M:split` or `M.trim`.
414
+ -- by_owner lists members wherever they are defined (out-of-line, other files).
415
+ function M.owner(qualified)
416
+ return qualified:match('^(.+)::[^:]+$') or qualified:match('^(.+)[%.:][^%.:]+$')
417
+ end
418
+
419
+ -- Add a record under rel. No cancellation checkpoints: index commits call
420
+ -- this and must not stop halfway.
421
+ function M.add_file(G, rel, rec)
422
+ assert(not G.file_index[rel], 'file already in symbol tables: ' .. rel)
423
+ local f = G.next_file + 1
424
+ G.next_file = f
425
+ G.files[f], G.file_index[rel] = rec, f
426
+ G.file_order[#G.file_order + 1] = f
427
+ local order = G.file_order
428
+ if #order > 1 and not file_before(G, order[#order - 1], f) then
429
+ table.remove(order)
430
+ table.insert(order, search(G, order, f, file_before), f)
431
+ end
432
+ local dir = dirname(rel)
433
+ local did = G.dir_ids[dir]
434
+ if not did then G.next_dir = G.next_dir + 1; did = G.next_dir; G.dir_ids[dir] = did end
435
+ G.file_dir[f] = did
436
+ insert(G, G.by_base, basename(rel), f, file_before)
437
+ insert(G, G.by_stem, stem(rel), f, file_before)
438
+ if not G.dir_files[dir] then insert(G, G.dir_by_base, basename(dir), dir, string_before) end
439
+ insert(G, G.dir_files, dir, f, file_before)
440
+ if rec.package then insert(G, G.pkg_files, rec.package, f, file_before) end
441
+ for qualified in pairs(namespaces(rec)) do insert(G, G.ns_files, qualified, f, file_before) end
442
+ local ids = {}
443
+ G.id_of[f] = ids
444
+ for n, node in ipairs(rec.nodes) do
445
+ local id = G.next_node + 1
446
+ G.next_node = id
447
+ G.nodes[id], G.node_file[id] = node, f
448
+ ids[n] = id
449
+ insert(G, G.by_name, node.name, id, node_before)
450
+ insert(G, G.by_lname, node.name:lower(), id, node_before)
451
+ insert(G, G.by_qualified, node.qualified, id, node_before)
452
+ local owner = M.owner(node.qualified)
453
+ if owner then insert(G, G.by_owner, owner, id, node_before) end
454
+ if node.parent then push(G.children, ids[node.parent], id) end
455
+ end
456
+ G.file_count, G.node_count = G.file_count + 1, G.node_count + #rec.nodes
457
+ return f
458
+ end
459
+
460
+ function M.remove_file(G, rel)
461
+ local f = G.file_index[rel]
462
+ if not f then return end
463
+ local rec, ids = G.files[f], G.id_of[f]
464
+ for _, id in ipairs(ids) do
465
+ local node = G.nodes[id]
466
+ remove(G, G.by_name, node.name, id, node_before)
467
+ remove(G, G.by_lname, node.name:lower(), id, node_before)
468
+ remove(G, G.by_qualified, node.qualified, id, node_before)
469
+ local owner = M.owner(node.qualified)
470
+ if owner then remove(G, G.by_owner, owner, id, node_before) end
471
+ G.children[id] = nil
472
+ end
473
+ for _, id in ipairs(ids) do G.nodes[id], G.node_file[id] = nil, nil end
474
+ local dir = dirname(rel)
475
+ remove(G, G.by_base, basename(rel), f, file_before)
476
+ remove(G, G.by_stem, stem(rel), f, file_before)
477
+ remove(G, G.dir_files, dir, f, file_before)
478
+ if not G.dir_files[dir] then remove(G, G.dir_by_base, basename(dir), dir, string_before) end
479
+ if rec.package then remove(G, G.pkg_files, rec.package, f, file_before) end
480
+ for qualified in pairs(namespaces(rec)) do remove(G, G.ns_files, qualified, f, file_before) end
481
+ local order = G.file_order
482
+ table.remove(order, search(G, order, f, file_before))
483
+ G.files[f], G.file_index[rel], G.id_of[f], G.file_dir[f] = nil, nil, nil, nil
484
+ G.file_count, G.node_count = G.file_count - 1, G.node_count - #ids
485
+ end
486
+
487
+ -- Symbol tables for every record of idx. Checkpoints per file: a cancelled
488
+ -- build is simply discarded.
335
489
  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
- }
490
+ local G = M.new()
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 function deps(f)
513
+ local entry = dependencies[f]
514
+ if not entry then
515
+ local direct, paired = resolve_deps(symbols, f)
516
+ entry = { direct, paired }; dependencies[f] = entry
377
517
  end
518
+ return entry[1], entry[2]
519
+ end
520
+ local function targets(f, i)
521
+ local rec, ids = symbols.files[f], symbols.id_of[f]
522
+ local refs = rec.refs
523
+ local direct, paired = deps(f)
524
+ Q.stats.resolved_refs = Q.stats.resolved_refs + 1
525
+ return resolve_ref(symbols, f, ids[refs.from[i]], refs.name[i], refs.kind[i],
526
+ refs.recv[i] or nil, direct, paired)
378
527
  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
528
+ setmetatable(Q.out, { __index = function(cache, id)
386
529
  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
530
+ if Q.stats.expanded >= limit then Q.incomplete = true; return nil end
531
+ Q.stats.expanded = Q.stats.expanded + 1
532
+ local f = assert(symbols.node_file[id], 'unknown symbol')
533
+ local rec, ids = symbols.files[f], symbols.id_of[f]
534
+ local grouped = references[f]
535
+ if not grouped then
536
+ grouped = {}
537
+ for i, from in ipairs(rec.refs.from) do
538
+ if i % 128 == 0 then control.check() end
539
+ if from > 0 then push(grouped, ids[from], i) end
540
+ end
541
+ references[f] = grouped
542
+ end
543
+ local edges = {}
544
+ for _, i in ipairs(grouped[id] or {}) do
545
+ control.check()
546
+ for _, dst in ipairs(targets(f, i) or {}) do
547
+ edges[#edges + 1] = dst
548
+ edges[#edges + 1] = rec.refs.line[i]
549
+ edges[#edges + 1] = rec.refs.kind[i]
550
+ end
551
+ end
552
+ rawset(cache, id, edges)
553
+ return edges
554
+ end })
555
+ -- Resolve all requested callers with a single ordered multi-name scan.
556
+ function Q:load_incoming(ids)
557
+ local wanted, names, found = {}, {}, false
558
+ for _, id in ipairs(ids) do
559
+ if rawget(self.inn, id) == nil then
560
+ wanted[id], names[symbols.nodes[id].name], found = true, true, true
561
+ end
562
+ end
563
+ if not found then return end
564
+ local incoming = {}
565
+ for id in pairs(wanted) do incoming[id] = {} end
566
+ self.stats.incoming_scans = self.stats.incoming_scans + 1
567
+ -- Hot loop over every reference: numeric loops, hoisted fields, and the
568
+ -- selective name test first. Checkpoints run per file and per chunk.
569
+ local files = symbols.files
570
+ for _, f in ipairs(symbols.file_order) do
571
+ control.check()
572
+ local refs = files[f].refs
573
+ local ref_names, froms = refs.name, refs.from
574
+ local count = #ref_names
575
+ for first = 1, count, 4096 do
576
+ if first > 1 then control.check() end
577
+ for i = first, math.min(count, first + 4095) do
578
+ if names[ref_names[i]] and froms[i] > 0 then
579
+ for _, dst in ipairs(targets(f, i) or {}) do
580
+ if wanted[dst] then
581
+ push3(incoming, dst, symbols.id_of[f][froms[i]], refs.line[i], refs.kind[i])
582
+ end
583
+ end
401
584
  end
402
585
  end
403
586
  end
404
587
  end
588
+ -- Interrupted scans never publish partial caller lists.
589
+ for id, edges in pairs(incoming) do rawset(self.inn, id, edges) end
405
590
  end
406
- G.edge_count = edges
407
- return G
591
+ setmetatable(Q.inn, { __index = function(cache, id)
592
+ Q:load_incoming({ id })
593
+ return rawget(cache, id)
594
+ end })
595
+ return Q
408
596
  end
409
597
 
598
+ -- Navigation reuses the resolver over symbol tables or overlays of them.
599
+ M.CALLABLE = CALLABLE
600
+ M.dependencies = resolve_deps
601
+ M.resolve = resolve_ref
602
+ M.placement = locality
603
+ M.is_decl = is_decl
604
+ M.family = family
605
+
410
606
  -- Location string for a node: "path:line".
411
607
  function M.where(G, id)
412
608
  return G.files[G.node_file[id]].path .. ':' .. G.nodes[id].line