@codua/codeoutline-win32-x64 0.2.6 → 0.3.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 (73) hide show
  1. package/README.md +205 -3
  2. package/README.zh-CN.md +40 -2
  3. package/bin/xnet.exe +0 -0
  4. package/build-info.json +1 -1
  5. package/package.json +1 -1
  6. package/scripts/codeoutline/affected.lua +145 -0
  7. package/scripts/codeoutline/automatic_events.lua +202 -0
  8. package/scripts/codeoutline/cache_repairs.lua +47 -0
  9. package/scripts/codeoutline/callers.lua +56 -16
  10. package/scripts/codeoutline/cargo_toml.lua +125 -0
  11. package/scripts/codeoutline/command.lua +26 -4
  12. package/scripts/codeoutline/common.lua +48 -7
  13. package/scripts/codeoutline/completion.lua +126 -22
  14. package/scripts/codeoutline/coverage.lua +63 -0
  15. package/scripts/codeoutline/cpp_bindings.lua +46 -11
  16. package/scripts/codeoutline/cpp_fragments.lua +143 -0
  17. package/scripts/codeoutline/cpp_implementations.lua +340 -0
  18. package/scripts/codeoutline/cpp_includes.lua +156 -0
  19. package/scripts/codeoutline/cpp_macros.lua +279 -0
  20. package/scripts/codeoutline/cpp_receivers.lua +342 -0
  21. package/scripts/codeoutline/cpp_types.lua +285 -29
  22. package/scripts/codeoutline/definition_candidates.lua +186 -0
  23. package/scripts/codeoutline/dispatch_aliases.lua +10 -5
  24. package/scripts/codeoutline/documents.lua +22 -9
  25. package/scripts/codeoutline/explore.lua +243 -122
  26. package/scripts/codeoutline/external_headers.lua +176 -0
  27. package/scripts/codeoutline/foreign.lua +23 -3
  28. package/scripts/codeoutline/function_values.lua +69 -0
  29. package/scripts/codeoutline/go_methods.lua +931 -0
  30. package/scripts/codeoutline/go_modules.lua +329 -0
  31. package/scripts/codeoutline/graph.lua +322 -67
  32. package/scripts/codeoutline/implementations.lua +403 -0
  33. package/scripts/codeoutline/index.lua +161 -28
  34. package/scripts/codeoutline/index_worker.lua +11 -4
  35. package/scripts/codeoutline/indirect.lua +4 -2
  36. package/scripts/codeoutline/js_evidence.lua +2 -1
  37. package/scripts/codeoutline/js_resolution.lua +40 -12
  38. package/scripts/codeoutline/js_workspace.lua +325 -0
  39. package/scripts/codeoutline/lang/c.lua +15 -2
  40. package/scripts/codeoutline/lang/cpp.lua +32 -18
  41. package/scripts/codeoutline/lang/csharp.lua +1 -1
  42. package/scripts/codeoutline/lang/js.lua +56 -20
  43. package/scripts/codeoutline/lang/rust.lua +9 -1
  44. package/scripts/codeoutline/language_detect.lua +100 -0
  45. package/scripts/codeoutline/lsp.lua +173 -23
  46. package/scripts/codeoutline/lua_bindings.lua +151 -47
  47. package/scripts/codeoutline/lua_callback_loops.lua +210 -0
  48. package/scripts/codeoutline/main.lua +32 -7
  49. package/scripts/codeoutline/mcp.lua +52 -9
  50. package/scripts/codeoutline/navigation.lua +351 -65
  51. package/scripts/codeoutline/on_demand.lua +93 -0
  52. package/scripts/codeoutline/ordinary_bindings.lua +210 -34
  53. package/scripts/codeoutline/parse.lua +18 -2
  54. package/scripts/codeoutline/parse_pool.lua +1 -1
  55. package/scripts/codeoutline/parse_worker.lua +1 -1
  56. package/scripts/codeoutline/python_bindings.lua +2 -2
  57. package/scripts/codeoutline/query_filters.lua +65 -0
  58. package/scripts/codeoutline/query_report.lua +56 -19
  59. package/scripts/codeoutline/resolution.lua +23 -0
  60. package/scripts/codeoutline/rust_packages.lua +203 -0
  61. package/scripts/codeoutline/rust_resolution.lua +301 -0
  62. package/scripts/codeoutline/search_ranking.lua +70 -0
  63. package/scripts/codeoutline/service.lua +47 -7
  64. package/scripts/codeoutline/shared_events.lua +369 -0
  65. package/scripts/codeoutline/static_dispatch.lua +46 -11
  66. package/scripts/codeoutline/text.lua +3 -2
  67. package/scripts/codeoutline/ts_implementations.lua +81 -0
  68. package/scripts/codeoutline/type_bases.lua +61 -0
  69. package/scripts/codeoutline/type_hierarchy.lua +324 -0
  70. package/scripts/codeoutline/type_references.lua +291 -0
  71. package/scripts/codeoutline/type_uses.lua +260 -0
  72. package/scripts/codeoutline/update_sequence.lua +1 -1
  73. package/scripts/codeoutline/version.lua +1 -1
@@ -19,21 +19,24 @@ local paths = require('codeoutline.path')
19
19
  local control = require('codeoutline.control')
20
20
  local graph = require('codeoutline.graph')
21
21
  local pool = require('codeoutline.parse_pool')
22
+ local fragments = require('codeoutline.cpp_fragments')
22
23
 
23
24
  local M = {}
24
25
  local INDEX_PARSE = { ranges = false, omit_signatures = true }
25
26
  local LARGE_PARSE = { ranges = false }
26
27
  -- Keep signatures for files beyond the shared query parser's 1 MiB limit.
27
- local function parse_options(source)
28
- return #source <= 1048576 and INDEX_PARSE or LARGE_PARSE
28
+ local function parse_options(source, language)
29
+ local options = #source <= 1048576 and INDEX_PARSE or LARGE_PARSE
30
+ if not language then return options end
31
+ return { ranges = false, omit_signatures = options.omit_signatures, language = language, cpp_fragment = language }
29
32
  end
30
33
 
31
34
  -- Cache version: a checksum of the parser sources, so any parser change
32
35
  -- rebuilds stale caches instead of silently reusing old parse results.
33
36
  M.VERSION = (function()
34
37
  local parts = {}
35
- for _, m in ipairs({ 'xscan', 'text', 'common', 'indirect', 'dispatch_aliases', 'static_dispatch', 'js_evidence', 'python_bindings', 'cpp_bindings', 'cpp_types', 'csharp_bindings', 'lua_bindings', 'foreign', 'foreign_lua', 'parse', 'lang.c', 'lang.cpp', 'lang.lua', 'lang.python',
36
- 'lang.java', 'lang.kotlin', 'lang.go', 'lang.js', 'lang.csharp', 'lang.rust' }) do
38
+ for _, m in ipairs({ 'xscan', 'text', 'common', 'type_uses', 'indirect', 'dispatch_aliases', 'static_dispatch', 'js_evidence', 'python_bindings', 'cpp_bindings', 'cpp_types', 'csharp_bindings', 'lua_bindings', 'foreign', 'foreign_lua', 'parse', 'lang.c', 'lang.cpp', 'lang.lua', 'lang.python',
39
+ 'cpp_receivers', 'cpp_macros', 'cpp_includes', 'cpp_fragments', 'language_detect', 'go_methods', 'function_values', 'implementations', 'cpp_implementations', 'ts_implementations', 'type_bases', 'automatic_events', 'shared_events', 'lua_callback_loops', 'lang.java', 'lang.kotlin', 'lang.go', 'lang.js', 'lang.csharp', 'lang.rust' }) do
37
40
  local file = package.searchpath and package.searchpath('codeoutline.' .. m, package.path)
38
41
  local h = file and io.open(file, 'rb')
39
42
  if h then parts[#parts + 1] = h:read('a'); h:close() end
@@ -137,13 +140,15 @@ function Index:load()
137
140
  local t = cmsgpack.unpack(payload)
138
141
  assert(t.version == M.VERSION and t.root == paths.key(self.root) and type(t.files) == 'table')
139
142
  local records = {}
140
- for _, rec in ipairs(t.files) do
143
+ local function validate(rec, destination)
141
144
  control.check()
142
145
  assert(type(rec) == 'table' and type(rec.path) == 'string')
143
146
  assert(not rec.path:find('[\\:%z]') and rec.path:sub(1, 1) ~= '/')
144
147
  for part in rec.path:gmatch('[^/]+') do assert(part ~= '..' and part ~= '.') end
145
148
  assert(type(rec.nodes) == 'table' and type(rec.refs) == 'table' and type(rec.imports) == 'table')
146
149
  assert(type(rec.size) == 'number' and type(rec.language) == 'string')
150
+ assert(rec.cpp_fragment == nil or rec.cpp_fragment == 'c' or rec.cpp_fragment == 'cpp')
151
+ assert(rec.cpp_fragment_cpp == nil or rec.cpp_fragment_cpp == true)
147
152
  assert(rec.encoding == nil or rec.encoding == 'utf-8' or rec.encoding == 'utf-8-bom' or rec.encoding == 'gbk')
148
153
  for i, n in ipairs(rec.nodes) do
149
154
  if i % 128 == 0 then control.check() end
@@ -163,8 +168,23 @@ function Index:load()
163
168
  assert(recv == false or type(recv) == 'string')
164
169
  end
165
170
  for _, imp in ipairs(rec.imports) do assert(type(imp.path) == 'string') end
166
- records[rec.path] = rec
171
+ destination[rec.path] = rec
167
172
  end
173
+ for _, rec in ipairs(t.files) do validate(rec, records) end
174
+ local patches = require('codeoutline.cache_repairs').load(self.cache_path, envelope.sha256, M.VERSION, paths.key(self.root))
175
+ local valid, applied = pcall(function()
176
+ local result = {}
177
+ for path, rec in pairs(patches) do
178
+ local base = assert(records[path])
179
+ assert(rec.crc == base.crc and rec.size == base.size and rec.language == base.language and rec.encoding == 'gbk')
180
+ validate(rec, result)
181
+ end
182
+ return result
183
+ end)
184
+ if not valid and control.is_interrupted(applied) then error(applied, 0) end
185
+ self.repair_records = valid and applied or {}
186
+ for path, rec in pairs(self.repair_records) do records[path] = rec end
187
+ self.cache_hash = envelope.sha256
168
188
  return records
169
189
  end)
170
190
  if not ok then
@@ -187,12 +207,21 @@ function Index:save()
187
207
  if not (cmsgpack and xcompress and xcompress.deflate and xutils.temp_file and xutils.replace_file) then
188
208
  return false, 'runtime requires cmsgpack, xcompress, temp_file and replace_file'
189
209
  end
210
+ if self.repair_only and self.cache_hash then
211
+ local ok, err = require('codeoutline.cache_repairs').save(self.cache_path, self.cache_hash,
212
+ M.VERSION, paths.key(self.root), self.repair_records)
213
+ if ok then
214
+ self.saved_generation, self.encoding_dirty, self.repair_only = self.generation, false, false
215
+ end
216
+ return ok, err
217
+ end
190
218
  local list = {}
191
219
  for _, rec in pairs(self.files) do list[#list + 1] = rec end
192
220
  table.sort(list, function(a, b) return a.path < b.path end)
193
221
  local payload = cmsgpack.pack({ version = M.VERSION, root = paths.key(self.root), files = list })
194
222
  local packed = xcompress.deflate(payload, M.CACHE_COMPRESSION_LEVEL)
195
- local blob = cmsgpack.pack({ codec = 'deflate', size = #payload, sha256 = xutils.sha256_hex(packed), payload = packed })
223
+ local hash = xutils.sha256_hex(packed)
224
+ local blob = cmsgpack.pack({ codec = 'deflate', size = #payload, sha256 = hash, payload = packed })
196
225
  local d = self.cache_path:match('^(.*)/[^/]*$') or '.'
197
226
  local made, err = xutils.mkdir_p(d)
198
227
  if not made then return false, err end
@@ -210,6 +239,8 @@ function Index:save()
210
239
  if not published then os.remove(tmp); return false, err end
211
240
  self.saved_generation = self.generation
212
241
  self.encoding_dirty = false
242
+ self.cache_hash, self.repair_records, self.repair_only = hash, {}, false
243
+ os.remove(self.cache_path .. '.repairs') -- a stale sidecar cannot match the new hash
213
244
  return true
214
245
  end
215
246
 
@@ -218,6 +249,7 @@ end
218
249
  -- so an interrupted refresh leaves every file either old or new. A failed
219
250
  -- table update drops the tables; the next symbols() call rebuilds them.
220
251
  function Index:commit(rel, rec)
252
+ self.repair_only = false
221
253
  local old = self.files[rel]
222
254
  self.files[rel] = rec
223
255
  self.generation = self.generation + 1
@@ -242,6 +274,24 @@ function Index:symbols()
242
274
  return self.symbol_tables
243
275
  end
244
276
 
277
+ -- Encoding confirmation need not replace a semantically identical parse.
278
+ local function same_value(a, b)
279
+ if type(a) ~= type(b) then return false end
280
+ if type(a) ~= 'table' then return a == b end
281
+ local count = 0
282
+ for key, value in pairs(a) do
283
+ count = count + 1
284
+ if count % 128 == 0 then control.check() end
285
+ if not same_value(value, b[key]) then return false end
286
+ end
287
+ for key in pairs(b) do
288
+ count = count + 1
289
+ if count % 128 == 0 then control.check() end
290
+ if a[key] == nil then return false end
291
+ end
292
+ return true
293
+ end
294
+
245
295
  -- Only query-selected files are decoded. This cache lasts for one query and
246
296
  -- holds the exact snapshot used for both reparsing and source rendering.
247
297
  function Index:query_source(rel)
@@ -271,16 +321,29 @@ function Index:query_source(rel)
271
321
  local changed = false
272
322
  if not rec.encoding then
273
323
  if encoding == 'gbk' then
274
- local parsed = assert(ci.parse(rel, src, parse_options(src)), 'cannot parse decoded source: ' .. rel)
324
+ local parsed = assert(ci.parse(rel, src, parse_options(src, rec.cpp_fragment)), 'cannot parse decoded source: ' .. rel)
275
325
  parsed.size, parsed.crc, parsed.mtime, parsed.checked = rec.size, rec.crc, rec.mtime, rec.checked
276
- parsed.encoding = encoding
277
- self:commit(rel, parsed)
278
- changed = true
326
+ local repair_only = not self:needs_save() or self.repair_only
327
+ if same_value(parsed, rec) then
328
+ -- GBK comments often leave every compact parse field intact.
329
+ -- Keep IDs and query evidence valid instead of restarting work.
330
+ rec.encoding = encoding
331
+ parsed = rec
332
+ else
333
+ parsed.encoding = encoding
334
+ self:commit(rel, parsed)
335
+ changed = true
336
+ end
337
+ self.repair_only = repair_only
338
+ self.repair_records = self.repair_records or {}
339
+ self.repair_records[rel] = parsed
340
+ self.encoding_dirty = true
279
341
  else
280
- -- Metadata only: names and positions are unchanged.
342
+ -- Metadata only: names and positions are unchanged. Keep this hint
343
+ -- resident and include it in the next normal save; confirming UTF-8
344
+ -- must not rewrite a large project cache on the query's hot path.
281
345
  rec.encoding = encoding
282
346
  end
283
- self.encoding_dirty = true
284
347
  end
285
348
  self.query_sources[rel] = src
286
349
  return src, changed
@@ -344,6 +407,7 @@ end
344
407
  -- Also returns each file's stat fields when the runtime lists them.
345
408
  function Index:walk_files()
346
409
  local out, meta = {}, {}
410
+ self.fragment_inventory = fragments.inventory(self.root)
347
411
  assert(xutils and xutils.list_dir, 'file enumeration unavailable: install rg or use a runtime with list_dir')
348
412
  local rules = load_ignore(self.root)
349
413
  local dirs = { '' }
@@ -364,9 +428,11 @@ function Index:walk_files()
364
428
  if st and st.type ~= 'link' and name:sub(1, 1) ~= '.' and not ignored(rules, rel, name, e.dir) then
365
429
  if e.dir then
366
430
  if not M.WALK_SKIP[name] then dirs[#dirs + 1] = rel end
367
- elseif ci.language(name) then
368
- out[#out + 1] = rel
369
- meta[rel] = st
431
+ else
432
+ if ci.language(name) then
433
+ out[#out + 1] = rel
434
+ meta[rel] = st
435
+ else fragments.add(self.fragment_inventory, rel) end
370
436
  end
371
437
  end
372
438
  end
@@ -390,6 +456,7 @@ function Index:list_files()
390
456
  local p = io.popen(cmd .. (package.config:sub(1, 1) == '\\' and ' 2>nul' or ' 2>/dev/null'))
391
457
  assert(p, 'cannot start rg file enumeration')
392
458
  local out = {}
459
+ self.fragment_inventory = fragments.inventory(self.root)
393
460
  local prefix = self.root:sub(-1) == '/' and self.root or self.root .. '/'
394
461
  local listing = p:read('a')
395
462
  local ok, _, code = p:close()
@@ -400,14 +467,15 @@ function Index:list_files()
400
467
  if ci.language(path) then
401
468
  out[#out + 1] = path
402
469
  assert(#out <= M.MAX_WALK_FILES, 'file enumeration limit exceeded')
470
+ else
471
+ fragments.add(self.fragment_inventory, path)
472
+ assert(self.fragment_inventory.count <= M.MAX_WALK_FILES, 'file enumeration limit exceeded')
403
473
  end
404
474
  end
405
475
  table.sort(out)
406
476
  return out
407
477
  end
408
478
 
409
- local MISSING = { exists = false }
410
-
411
479
  -- Stat fields for every listed file, read one directory at a time:
412
480
  -- list_dir reports them per entry, so a tree costs a call per directory
413
481
  -- rather than a stat per file. Older runtimes fall back to stat.
@@ -431,7 +499,9 @@ function Index:stat_listing(list)
431
499
  end
432
500
  for _, name in ipairs(names) do
433
501
  local rel = dir == '' and name or (dir .. '/' .. name)
434
- meta[rel] = by_name and (by_name[name] or MISSING) or xutils.stat(self:abs(rel))
502
+ -- rg and a native directory listing can disagree on filename
503
+ -- encoding. Check a listed path before treating it as deleted.
504
+ meta[rel] = by_name and by_name[name] or xutils.stat(self:abs(rel))
435
505
  end
436
506
  end
437
507
  return meta
@@ -444,7 +514,7 @@ end
444
514
  -- Read one file and parse it unless its size and checksum match the known
445
515
  -- record. Touches no index state, so a parse thread can run it too. `checked`
446
516
  -- is taken before the read: content read after that second is current.
447
- function M.load_file(abs, rel, max_bytes, old_size, old_crc)
517
+ function M.load_file(abs, rel, max_bytes, old_size, old_crc, language)
448
518
  local checked = os.time()
449
519
  local src = slurp(abs)
450
520
  if not src or #src > max_bytes then return { status = 'skipped' } end
@@ -452,7 +522,7 @@ function M.load_file(abs, rel, max_bytes, old_size, old_crc)
452
522
  if old_size == #src and old_crc == crc then
453
523
  return { status = 'unchanged', checked = checked }
454
524
  end
455
- local ok, r = pcall(ci.parse, rel, src, parse_options(src))
525
+ local ok, r = pcall(ci.parse, rel, src, parse_options(src, language))
456
526
  if not ok and control.is_interrupted(r) then error(r, 0) end
457
527
  -- A parser exception must not permanently hide a GBK file.
458
528
  -- Successful speculative parsing does not scan encoding here.
@@ -460,13 +530,13 @@ function M.load_file(abs, rel, max_bytes, old_size, old_crc)
460
530
  if xutils.to_utf8 then
461
531
  local decoded, encoding = xutils.to_utf8(src)
462
532
  if decoded then
463
- ok, r = pcall(ci.parse, rel, decoded, parse_options(src))
533
+ ok, r = pcall(ci.parse, rel, decoded, parse_options(src, language))
464
534
  if not ok and control.is_interrupted(r) then error(r, 0) end
465
535
  if ok and r then r.encoding = encoding end
466
536
  end
467
537
  end
468
538
  end
469
- if not (ok and r) then return { status = 'failed' } end
539
+ if not (ok and r) then return { status = language and ok and 'skipped' or 'failed' } end
470
540
  r.size, r.crc, r.checked = #src, crc, checked
471
541
  return { status = 'parsed', rec = r }
472
542
  end
@@ -513,13 +583,48 @@ function Index:apply_load(rel, st, res, stats)
513
583
  return true
514
584
  end
515
585
 
516
- function Index:read_file(rel, st, stats)
586
+ function Index:read_file(rel, st, stats, language)
517
587
  local rec = self.files[rel]
518
- local res = M.load_file(self:abs(rel), rel, self.max_bytes, rec and rec.size, rec and rec.crc)
588
+ language = language or rec and rec.cpp_fragment
589
+ local same = rec and rec.cpp_fragment == language
590
+ local res = M.load_file(self:abs(rel), rel, self.max_bytes, same and rec.size, same and rec.crc, language)
519
591
  control.check()
520
592
  return self:apply_load(rel, st, res, stats)
521
593
  end
522
594
 
595
+ function Index:refresh_fragments(stats, seen, changed)
596
+ fragments.refresh(self, stats, seen, function(batch)
597
+ local frontier, reads, meta = {}, {}, {}
598
+ for _, candidate in ipairs(batch) do
599
+ local rel, language, st = candidate.rel, candidate.language, candidate.stat
600
+ local rec = self.files[rel]
601
+ local settled
602
+ if not (changed and changed[rel]) and rec and rec.cpp_fragment == language then
603
+ settled = self:check_stat(rel, st, stats)
604
+ end
605
+ if settled then seen[rel] = true; frontier[#frontier + 1] = rel
606
+ elseif settled == nil then
607
+ local same = rec and rec.cpp_fragment == language
608
+ reads[#reads + 1] = { rel = rel, abs = self:abs(rel), language = language,
609
+ size = same and rec.size, crc = same and rec.crc, weight = st.size + M.FILE_WEIGHT }
610
+ meta[rel] = st
611
+ end
612
+ end
613
+ local function apply(rel, response)
614
+ control.check()
615
+ if self:apply_load(rel, meta[rel], response, stats) then seen[rel] = true; frontier[#frontier + 1] = rel end
616
+ end
617
+ if #reads >= M.PARALLEL_MIN_FILES and pool.ready() then pool.run(reads, self.max_bytes, apply)
618
+ else
619
+ for _, job in ipairs(reads) do
620
+ control.check()
621
+ apply(job.rel, M.load_file(job.abs, job.rel, self.max_bytes, job.size, job.crc, job.language))
622
+ end
623
+ end
624
+ return frontier
625
+ end, changed)
626
+ end
627
+
523
628
  -- Bring one listed file in line with the tree, given its stat fields (nil
524
629
  -- when the runtime has no stat). Returns false when it no longer belongs in
525
630
  -- the index: gone, too large, unreadable or unparsable.
@@ -563,7 +668,7 @@ local IGNORE_FILES = { ['.gitignore'] = true, ['.ignore'] = true, ['.rgignore']
563
668
  local function relevant(paths)
564
669
  local changed = {}
565
670
  for _, rel in ipairs(paths) do
566
- if IGNORE_FILES[rel:match('[^/]*$')] then return nil end
671
+ if IGNORE_FILES[rel:match('[^/]*$')] or rel == '.codeoutline.json' then return nil end
567
672
  if rel:sub(1, 1) ~= '.' and not rel:find('/.', 1, true) then changed[rel] = true end
568
673
  end
569
674
  return changed
@@ -574,6 +679,13 @@ end
574
679
  -- files that differ from the index.
575
680
  function Index:refresh_changed(changed, structural)
576
681
  local stats = new_stats('changes')
682
+ local refresh_fragments = structural or false
683
+ for rel in pairs(changed) do
684
+ local rec, language = self.files[rel], ci.language(rel)
685
+ if (rec and (rec.cpp_fragment or rec.language == 'c' or rec.language == 'cpp'))
686
+ or language == 'c' or language == 'cpp' or not language then refresh_fragments = true end
687
+ end
688
+ if refresh_fragments and not self.fragment_inventory then structural = true end
577
689
  if not structural then
578
690
  -- A supported file the index lacks may have shrunk under the size
579
691
  -- limit or been fixed after a failed parse: let the listing decide.
@@ -583,6 +695,7 @@ function Index:refresh_changed(changed, structural)
583
695
  end
584
696
  local listed
585
697
  if structural then
698
+ refresh_fragments = true
586
699
  stats.mode = 'relisted'
587
700
  listed = {}
588
701
  for _, rel in ipairs(self:list_files()) do
@@ -590,14 +703,16 @@ function Index:refresh_changed(changed, structural)
590
703
  if not self.files[rel] then changed[rel] = true end
591
704
  end
592
705
  for rel in pairs(self.files) do
593
- if not listed[rel] then changed[rel] = true end
706
+ if not listed[rel] and not self.files[rel].cpp_fragment then changed[rel] = true end
594
707
  end
595
708
  end
596
709
  local has_stat = xutils and xutils.stat
597
710
  for rel in pairs(changed) do
598
711
  control.check()
599
712
  local known = self.files[rel] ~= nil
600
- if listed and listed[rel] or (not listed and known) then
713
+ if known and self.files[rel].cpp_fragment then
714
+ -- Recheck through the reachable include closure below.
715
+ elseif listed and listed[rel] or (not listed and known) then
601
716
  if not self:sync_file(rel, has_stat and xutils.stat(self:abs(rel)) or nil, stats) and known then
602
717
  self:commit(rel, nil)
603
718
  stats.removed = stats.removed + 1
@@ -607,6 +722,14 @@ function Index:refresh_changed(changed, structural)
607
722
  stats.removed = stats.removed + 1
608
723
  end
609
724
  end
725
+ if refresh_fragments then
726
+ local seen = {}
727
+ for rel, rec in pairs(self.files) do if not rec.cpp_fragment then seen[rel] = true end end
728
+ self:refresh_fragments(stats, seen, changed)
729
+ local gone = {}
730
+ for rel, rec in pairs(self.files) do if rec.cpp_fragment and not seen[rel] then gone[#gone + 1] = rel end end
731
+ for _, rel in ipairs(gone) do self:commit(rel, nil); stats.removed = stats.removed + 1 end
732
+ end
610
733
  local total = 0
611
734
  for _ in pairs(self.files) do total = total + 1 end
612
735
  stats.unchanged = total - stats.parsed
@@ -619,12 +742,20 @@ end
619
742
  -- watcher is reopened before one.
620
743
  function Index:refresh(opts)
621
744
  opts = opts or {}
745
+ local policy = fragments.policy_key(self.root)
746
+ if self.fragment_policy and self.fragment_policy ~= policy then
747
+ self.watch_ready = false
748
+ local stats = self:refresh_all()
749
+ if self.watcher then self.watch_ready = true end
750
+ return stats
751
+ end
622
752
  if opts.paths then
623
753
  local changed = {}
624
754
  for _, path in ipairs(opts.paths) do
625
755
  if paths.contains(self.root, path) then
626
756
  local prefix = self.root:sub(-1) == '/' and self.root or self.root .. '/'
627
757
  local rel = path:sub(#prefix + 1)
758
+ if rel == '.codeoutline.json' then return self:refresh_all() end
628
759
  -- Unindexed/ignored files are admitted by watcher enumeration.
629
760
  if self.files[rel] then changed[rel] = true end
630
761
  end
@@ -667,6 +798,7 @@ end
667
798
  function Index:refresh_all()
668
799
  local stats = new_stats('full')
669
800
  self.next_full = nil
801
+ self.fragment_policy = fragments.policy_key(self.root)
670
802
  local seen = {}
671
803
  local list, meta = self:list_files()
672
804
  if not meta and xutils and xutils.stat then meta = self:stat_listing(list) end
@@ -694,6 +826,7 @@ function Index:refresh_all()
694
826
  if self:read_file(rel, meta and meta[rel], stats) then seen[rel] = true end
695
827
  end
696
828
  end
829
+ self:refresh_fragments(stats, seen)
697
830
  local gone = {}
698
831
  for rel in pairs(self.files) do
699
832
  if not seen[rel] then gone[#gone + 1] = rel end
@@ -55,11 +55,16 @@ local function execute(req)
55
55
  assert(paths.allowed(req.allowedRoots, root), 'project path is outside allowed roots')
56
56
  if req.method == 'lsp_refresh' then
57
57
  service.configure({ max_projects = lsp.MAX_ROOTS })
58
- service.refresh(root, { full_interval = 45, paths = req.paths })
58
+ local idx = service.refresh(root, { full_interval = 45, paths = req.paths })
59
+ -- Ready navigation must not leave a whole-project symbol-table build
60
+ -- on the first definition request. Symbol-only clients retain lazy data.
61
+ if req.prepare_navigation then idx:symbols() end
59
62
  return true
60
- elseif req.method == 'explore' or req.method == 'callers' then
61
- local text, info = service[req.method](root, req.query, { budget = req.budget, depth = req.depth, max_nodes = req.max_nodes })
62
- return { text = text, truncated = info.truncated or false, refresh = info.refresh }
63
+ elseif req.method == 'explore' or req.method == 'callers' or req.method == 'type_hierarchy' or req.method == 'type_references' or req.method == 'affected' then
64
+ local text, info = service[req.method](root, req.method == 'affected' and req.files or req.query, { budget = req.budget, depth = req.depth,
65
+ max_nodes = req.max_nodes, direction = req.direction })
66
+ return { text = text, truncated = info.truncated or false, coverage = info.coverage,
67
+ resolution = info.resolution, generation = info.generation, refresh = info.refresh }
63
68
  elseif req.method == 'status' then return service.status(root)
64
69
  elseif req.method == 'rebuild' then return service.rebuild(root)
65
70
  else error('unknown operation') end
@@ -71,11 +76,13 @@ end
71
76
  local queue, active = {}, nil
72
77
 
73
78
  local function run(id, req, reply)
79
+ if req.queue_until then assert(xthread.post(1, 'worker_started', id)) end
74
80
  -- Draft text applies even to a cancelled request: the session counts it as sent.
75
81
  if req.session and req.open then
76
82
  local synced, err = pcall(navigation.sync, req)
77
83
  if not synced then io.stderr:write('[codeoutline lsp] ', tostring(err), '\n') end
78
84
  end
85
+ if req.method == 'lsp_warm' then req.deadline = math.min(req.deadline, xtimer.now_ms() + 5000) end
79
86
  control.callback = function()
80
87
  if shared:get('shutdown') or shared:get('cancel:' .. id) then error(control.cancelled(), 0) end
81
88
  if xtimer.now_ms() > req.deadline then error(control.deadline(), 0) end
@@ -75,6 +75,8 @@ 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)
79
+ if roles ~= 0 then r.event_roles = roles end
78
80
  if r.collect_dispatch then r.dispatch_sites = sites end
79
81
  end
80
82
 
@@ -138,7 +140,7 @@ function M.query(G, rules, report)
138
140
  if not relevant then return {} end
139
141
  end
140
142
  local parsed = assert(require('codeoutline.parse').parse(rec.path, source,
141
- { ranges = false, dispatch = names, dispatch_only = true }))
143
+ { ranges = false, dispatch = names, dispatch_only = true, language = rec.language }))
142
144
  assert(#parsed.nodes == #rec.nodes, 'source encoding changed; refresh index before indirect query: ' .. rec.path)
143
145
  for i, n in ipairs(parsed.nodes) do
144
146
  assert(n.qualified == rec.nodes[i].qualified and n.line == rec.nodes[i].line,
@@ -160,7 +162,7 @@ function M.query(G, rules, report)
160
162
  if arg and not literal and arg.import then
161
163
  local imp = arg.import
162
164
  local rec = G.files[f]
163
- if rec.language == 'javascript' or rec.language == 'typescript' then
165
+ if rec.language == 'javascript' or rec.language == 'typescript' or rec.language == 'arkts' then
164
166
  local js = require('codeoutline.js_resolution')
165
167
  dependencies.js = dependencies.js or js.context(G)
166
168
  return js.imported(G, f, imp.path, arg.member, dependencies.js) or {}
@@ -16,7 +16,7 @@ local function type_name(T, i)
16
16
  end
17
17
 
18
18
  function M.collect(r, T)
19
- if r.language ~= 'javascript' and r.language ~= 'typescript' then return end
19
+ if r.language ~= 'javascript' and r.language ~= 'typescript' and r.language ~= 'arkts' then return end
20
20
  r.js_imports, r.js_exports = {}, {}
21
21
  local skip = {}
22
22
  local function export(name, local_name, path)
@@ -75,6 +75,7 @@ function M.collect(r, T)
75
75
  end
76
76
  end
77
77
 
78
+ if r.defer_analysis or not r.ordinary_bindings and not r.ranges then return end
78
79
  -- Braces provide block lifetime; node ranges extend parameter bindings to bodies.
79
80
  local scopes, stack = {}, {}
80
81
  for i = 1, T.n do
@@ -1,7 +1,7 @@
1
1
  -- JS/TS module and receiver evidence; deliberately not a type checker.
2
2
  local M = {}
3
3
  local control = require('codeoutline.control')
4
- local function js(rec) return rec and (rec.language == 'javascript' or rec.language == 'typescript') end
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)
7
7
  local parts = {}
@@ -43,7 +43,9 @@ local function config(path, seen, depth)
43
43
  end
44
44
 
45
45
  function M.context(G)
46
- local ctx = { modules = {}, exports = {} }
46
+ local ctx = { modules = {}, exports = {}, module_reasons = {},
47
+ workspace_stats = { reads = 0, bytes = 0, directories = 0, packages = 0 },
48
+ go_stats = { reads = 0, bytes = 0, modules = 0 }, rust_stats = { reads = 0, bytes = 0, packages = 0 } }
47
49
  if G.root then
48
50
  for _, name in ipairs({ 'tsconfig.json', 'jsconfig.json', 'tsconfig.base.json' }) do
49
51
  local opts = config(G.root .. '/' .. name, {}, 0)
@@ -70,10 +72,11 @@ end
70
72
 
71
73
  local extensions = { '', '.ts', '.tsx', '.js', '.jsx', '.mts', '.cts', '.mjs', '.cjs',
72
74
  '/index.ts', '/index.tsx', '/index.js', '/index.jsx', '/index.mts', '/index.mjs' }
73
- function M.module(G, f, spec, ctx)
75
+ function M.module(G, f, spec, ctx, mode)
74
76
  ctx = ctx or M.context(G)
75
- local key = f .. '\0' .. spec
76
- if ctx.modules[key] ~= nil then return ctx.modules[key] or nil end
77
+ mode = mode or 'import'
78
+ local key = G.files[f].path .. '\0' .. spec .. '\0' .. mode
79
+ if ctx.modules[key] ~= nil then return ctx.modules[key] or nil, ctx.module_reasons[key] end
77
80
  local bases = {}
78
81
  if spec:sub(1, 1) == '.' then bases[1] = norm(dir(G.files[f].path) .. '/' .. spec):gsub('^/', '')
79
82
  else
@@ -94,16 +97,41 @@ function M.module(G, f, spec, ctx)
94
97
  end
95
98
  end
96
99
  end
97
- for _, base in ipairs(bases) do
100
+ local function find(base)
98
101
  local candidates = { base }
99
- if base:match('%.js$') then candidates[#candidates + 1] = base:gsub('%.js$', '.ts'); candidates[#candidates + 1] = base:gsub('%.js$', '.tsx') end
102
+ if G.files[f].language == 'arkts' then
103
+ candidates[#candidates + 1] = base .. '.ets'
104
+ candidates[#candidates + 1] = base .. '/index.ets'
105
+ end
106
+ if base:match('%.js$') then candidates[#candidates + 1] = base:gsub('%.js$', '.ts'); candidates[#candidates + 1] = base:gsub('%.js$', '.tsx')
107
+ elseif base:match('%.mjs$') then candidates[#candidates + 1] = base:gsub('%.mjs$', '.mts')
108
+ elseif base:match('%.cjs$') then candidates[#candidates + 1] = base:gsub('%.cjs$', '.cts') end
100
109
  for _, ext in ipairs(extensions) do candidates[#candidates + 1] = base .. ext end
101
110
  for _, candidate in ipairs(candidates) do
102
111
  local target = G.file_index[candidate]
103
- if target and js(G.files[target]) then ctx.modules[key] = target; return target end
112
+ if target and js(G.files[target]) then return target end
113
+ end
114
+ end
115
+ for _, base in ipairs(bases) do
116
+ local target = find(base)
117
+ if target then ctx.modules[key] = target; return target end
118
+ end
119
+ if spec:sub(1, 1) ~= '.' then
120
+ if ctx.workspace_error then
121
+ ctx.modules[key], ctx.module_reasons[key] = false, ctx.workspace_error
122
+ return nil, ctx.workspace_error
123
+ end
124
+ local ok, target, reason = pcall(require('codeoutline.js_workspace').resolve, G, f, spec, ctx, mode, find)
125
+ if not ok then
126
+ if control.is_interrupted(target) then error(target, 0) end
127
+ ctx.workspace_incomplete = true; reason, target = tostring(target), nil
128
+ ctx.workspace_error = reason
104
129
  end
130
+ if target then ctx.modules[key] = target; return target end
131
+ ctx.module_reasons[key] = reason
105
132
  end
106
133
  ctx.modules[key] = false
134
+ return nil, ctx.module_reasons[key]
107
135
  end
108
136
 
109
137
  local function exported(G, f, name, ctx, seen, depth)
@@ -171,8 +199,8 @@ end
171
199
  -- Shared named/namespace import lookup for query-owned callback aliases.
172
200
  function M.imported(G, f, path, name, ctx)
173
201
  ctx = ctx or M.context(G)
174
- local target = M.module(G, f, path, ctx)
175
- return target and name ~= '' and exported(G, target, name, ctx, {}, 0) or {}
202
+ local target, reason = M.module(G, f, path, ctx)
203
+ return target and name ~= '' and exported(G, target, name, ctx, {}, 0) or {}, reason
176
204
  end
177
205
 
178
206
  function M.resolve(G, f, name, kind, recv, evidence, ctx)
@@ -182,8 +210,8 @@ function M.resolve(G, f, name, kind, recv, evidence, ctx)
182
210
  local function binding(local_name, member)
183
211
  for _, b in ipairs(rec.js_imports or {}) do
184
212
  if b.local_name == local_name then
185
- local target = M.module(G, f, b.path, ctx)
186
- if not target then return {} end
213
+ local target, reason = M.module(G, f, b.path, ctx)
214
+ if not target then return {}, reason end
187
215
  if b.imported == '*' then return member and exported(G, target, member, ctx, {}, 0) or {} end
188
216
  return exported(G, target, b.imported, ctx, {}, 0)
189
217
  end