@codua/codeoutline-win32-x64 0.2.4 → 0.2.9

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 (77) 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 +65 -9
  13. package/scripts/codeoutline/completion.lua +221 -65
  14. package/scripts/codeoutline/coverage.lua +63 -0
  15. package/scripts/codeoutline/cpp_bindings.lua +151 -0
  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 +456 -0
  22. package/scripts/codeoutline/csharp_bindings.lua +498 -0
  23. package/scripts/codeoutline/definition_candidates.lua +180 -0
  24. package/scripts/codeoutline/dispatch_aliases.lua +479 -0
  25. package/scripts/codeoutline/documents.lua +32 -9
  26. package/scripts/codeoutline/explore.lua +274 -119
  27. package/scripts/codeoutline/external_headers.lua +171 -0
  28. package/scripts/codeoutline/foreign.lua +79 -14
  29. package/scripts/codeoutline/foreign_lua.lua +146 -19
  30. package/scripts/codeoutline/function_values.lua +69 -0
  31. package/scripts/codeoutline/go_methods.lua +931 -0
  32. package/scripts/codeoutline/go_modules.lua +329 -0
  33. package/scripts/codeoutline/graph.lua +346 -63
  34. package/scripts/codeoutline/implementations.lua +403 -0
  35. package/scripts/codeoutline/index.lua +165 -27
  36. package/scripts/codeoutline/index_worker.lua +11 -4
  37. package/scripts/codeoutline/indirect.lua +116 -40
  38. package/scripts/codeoutline/js_evidence.lua +32 -3
  39. package/scripts/codeoutline/js_resolution.lua +72 -10
  40. package/scripts/codeoutline/js_workspace.lua +325 -0
  41. package/scripts/codeoutline/lang/c.lua +15 -2
  42. package/scripts/codeoutline/lang/cpp.lua +7 -4
  43. package/scripts/codeoutline/lang/csharp.lua +15 -3
  44. package/scripts/codeoutline/lang/js.lua +56 -20
  45. package/scripts/codeoutline/lang/rust.lua +9 -1
  46. package/scripts/codeoutline/language_detect.lua +100 -0
  47. package/scripts/codeoutline/lsp.lua +173 -23
  48. package/scripts/codeoutline/lua_bindings.lua +228 -54
  49. package/scripts/codeoutline/lua_callback_loops.lua +210 -0
  50. package/scripts/codeoutline/lua_literal.lua +38 -0
  51. package/scripts/codeoutline/main.lua +32 -7
  52. package/scripts/codeoutline/mcp.lua +52 -9
  53. package/scripts/codeoutline/navigation.lua +593 -147
  54. package/scripts/codeoutline/on_demand.lua +93 -0
  55. package/scripts/codeoutline/ordinary_bindings.lua +396 -0
  56. package/scripts/codeoutline/parse.lua +18 -2
  57. package/scripts/codeoutline/parse_pool.lua +1 -1
  58. package/scripts/codeoutline/parse_worker.lua +1 -1
  59. package/scripts/codeoutline/python_bindings.lua +112 -0
  60. package/scripts/codeoutline/query_filters.lua +65 -0
  61. package/scripts/codeoutline/query_report.lua +135 -8
  62. package/scripts/codeoutline/resolution.lua +23 -0
  63. package/scripts/codeoutline/rules.lua +127 -0
  64. package/scripts/codeoutline/rust_packages.lua +203 -0
  65. package/scripts/codeoutline/rust_resolution.lua +301 -0
  66. package/scripts/codeoutline/search_ranking.lua +70 -0
  67. package/scripts/codeoutline/service.lua +47 -7
  68. package/scripts/codeoutline/shared_events.lua +369 -0
  69. package/scripts/codeoutline/static_dispatch.lua +569 -0
  70. package/scripts/codeoutline/text.lua +3 -2
  71. package/scripts/codeoutline/ts_implementations.lua +81 -0
  72. package/scripts/codeoutline/type_bases.lua +61 -0
  73. package/scripts/codeoutline/type_hierarchy.lua +324 -0
  74. package/scripts/codeoutline/type_references.lua +290 -0
  75. package/scripts/codeoutline/type_uses.lua +260 -0
  76. package/scripts/codeoutline/update_sequence.lua +1 -1
  77. package/scripts/codeoutline/version.lua +1 -1
@@ -11,10 +11,9 @@
11
11
  -- files are reparsed on demand within a time budget; running out of it, or
12
12
  -- of items, marks the list incomplete.
13
13
  local graph = require('codeoutline.graph')
14
- local parse = require('codeoutline.parse')
15
14
  local navigation = require('codeoutline.navigation')
16
15
  local control = require('codeoutline.control')
17
- local M = { MAX_ITEMS = 500, BUDGET_SECONDS = 0.3, MAX_FILE_BYTES = 524288, MAX_DEPTH = 6, CACHE_FILES = 64 }
16
+ local M = { MAX_ITEMS = 500, BUDGET_SECONDS = 0.3, MAX_DEPTH = 6 }
18
17
 
19
18
  local ITEM = { ['function'] = 3, method = 2, constructor = 4, destructor = 4, field = 5, variable = 6,
20
19
  property = 10, class = 7, struct = 22, union = 22, record = 22, interface = 8, enum = 13, enum_member = 20,
@@ -38,11 +37,8 @@ end
38
37
  local WRAPPERS = {}
39
38
  for word in ([[Option Box Rc Arc RefCell Cell Mutex RwLock Weak unique_ptr shared_ptr weak_ptr Ptr Ref
40
39
  Optional Nullable Promise Future Lazy]]):gmatch('%S+') do WRAPPERS[word] = true end
41
- local TYPE_AFTER = { go = true, rust = true, typescript = true, javascript = true, python = true, kotlin = true }
42
- local DYNAMIC = { lua = true, python = true, javascript = true, typescript = true }
43
-
44
- -- Full parses of type files, keyed by the index record they correspond to.
45
- local cache, cache_order = setmetatable({}, { __mode = 'k' }), {}
40
+ local TYPE_AFTER = { go = true, rust = true, typescript = true, arkts = true, javascript = true, python = true, kotlin = true }
41
+ local DYNAMIC = { lua = true, python = true, javascript = true, typescript = true, arkts = true }
46
42
 
47
43
  local function text_of(T, i) return T.s[i] and T:text(i) or '' end
48
44
  local function is(T, i, s) return T.k[i] == 'op' and text_of(T, i) == s end
@@ -57,13 +53,21 @@ end
57
53
 
58
54
  -- Type name for a declared type text: modifiers, pointers, references,
59
55
  -- arrays, namespaces and well-known wrappers removed.
60
- local function normalize(text)
56
+ local function normalize(text, language)
61
57
  if type(text) ~= 'string' then return nil end
58
+ if language == 'cpp' then
59
+ local named = require('codeoutline.cpp_types').normalize(text)
60
+ if named then return named end
61
+ end
62
62
  text = text:gsub('^%s+', ''):gsub('%s+$', '')
63
63
  for _ = 1, 8 do
64
64
  local first, rest = text:match('^([%a_]+)%s+(.+)$')
65
65
  if first and MODIFIERS[first] then text = rest else break end
66
66
  end
67
+ if language == 'csharp' then
68
+ local named = require('codeoutline.csharp_bindings').name(text)
69
+ if named then return named end
70
+ end
67
71
  text = text:gsub('^[%*&%[%]]+', ''):gsub('[%*&%?!%s]+$', ''):gsub('%[%]$', '')
68
72
  text = text:gsub('^%[%d*%]', ''):gsub('^map%b[]', '')
69
73
  local outer, inner = text:match('^([%w_:%.]+)%s*<(.*)>$')
@@ -91,7 +95,7 @@ end
91
95
 
92
96
  -- Declared type of a node from its signature (or the full-parse `type`).
93
97
  local function declared(node, language)
94
- if node.type then return normalize(node.type) end
98
+ if node.type then return normalize(node.type, language) end
95
99
  local sig, name = node.sig, node.name
96
100
  if not sig then return nil end
97
101
  if node.kind == 'constructor' then return nil end
@@ -109,7 +113,7 @@ local function declared(node, language)
109
113
  rest = rest:sub(#params + 1):gsub('^%s+', '')
110
114
  if rest:sub(1, 1) == '(' then rest = rest:match('^%((.-)[,%)]') or '' end
111
115
  return normalize(rest)
112
- elseif language == 'typescript' or language == 'javascript' or language == 'kotlin' then
116
+ elseif language == 'typescript' or language == 'arkts' or language == 'javascript' or language == 'kotlin' then
113
117
  local after = sig:match('%)%s*:%s*([^{=]+)$')
114
118
  return after and normalize(after)
115
119
  elseif language == 'lua' then
@@ -117,7 +121,7 @@ local function declared(node, language)
117
121
  end
118
122
  local at = sig:find('[%w_]*' .. name .. '%s*%(')
119
123
  if not at then return nil end
120
- return normalize(strip_name(sig:sub(1, at - 1), name))
124
+ return normalize(strip_name(sig:sub(1, at - 1), name), language)
121
125
  end
122
126
  if language == 'go' then
123
127
  return normalize(sig:match('^%s*' .. name .. '%s+(.+)$'))
@@ -130,36 +134,12 @@ local function declared(node, language)
130
134
  local at
131
135
  for position in sig:gmatch('()' .. name .. '%f[^%w_]') do at = position end
132
136
  if not at or at == 1 then return nil end
133
- return normalize(sig:sub(1, at - 1))
137
+ return normalize(sig:sub(1, at - 1), language)
134
138
  end
135
139
 
136
140
  -- Full record and tokens of file f: the overlay document, else a cached
137
141
  -- reparse of the indexed file (nil when too large or unreadable).
138
- local function full(V, f)
139
- local draft = V.drafts[f]
140
- if draft then
141
- draft.completion = draft.completion or {}
142
- local entry = draft.completion
143
- if not entry.rec then entry.rec, entry.tokens = parse.parse_tokens(draft.path or V.files[f].path, draft.source) end
144
- return entry.rec, entry.tokens, draft
145
- end
146
- local key = V.files[f]
147
- local entry = cache[key]
148
- if entry == nil then
149
- if (key.size or 0) > M.MAX_FILE_BYTES then cache[key] = false; return nil end
150
- local doc = navigation.source_doc(V, f)
151
- entry = false
152
- if doc then
153
- local rec, tokens = parse.parse_tokens(key.path, doc.source)
154
- entry = rec and { rec = rec, tokens = tokens } or false
155
- end
156
- cache[key] = entry
157
- cache_order[#cache_order + 1] = key
158
- if #cache_order > M.CACHE_FILES then cache[table.remove(cache_order, 1)] = nil end
159
- end
160
- if not entry then return nil end
161
- return entry.rec, entry.tokens
162
- end
142
+ local full = navigation.full
163
143
 
164
144
  -- Parameters inside parentheses [a, b] of a function header.
165
145
  local function parameters(T, a, b, language, out)
@@ -204,7 +184,7 @@ local function parameters(T, a, b, language, out)
204
184
  else
205
185
  local name
206
186
  for k = y, x, -1 do if T.k[k] == 'id' then name = k; break end end
207
- if name and name > x then out[#out + 1] = { name = text_of(T, name), type = normalize(span(T, x, name - 1)) } end
187
+ if name and name > x then out[#out + 1] = { name = text_of(T, name), type = normalize(span(T, x, name - 1), language), at = name } end
208
188
  end
209
189
  end
210
190
  for _, name in ipairs(pending) do out[#out + 1] = { name = name } end
@@ -274,7 +254,7 @@ local function declarations(T, a, b, language, skip, out)
274
254
  return b
275
255
  end
276
256
  local function add(name_tok, type, init)
277
- local entry = { name = text_of(T, name_tok), type = normalize(type), at = name_tok }
257
+ local entry = { name = text_of(T, name_tok), type = normalize(type, language), at = name_tok }
278
258
  if init then
279
259
  local stop = statement_end(init)
280
260
  local value = initializer(T, init, stop, language)
@@ -327,7 +307,7 @@ local function declarations(T, a, b, language, skip, out)
327
307
  local k = i + 1
328
308
  while T.k[k] == 'id' do add(k); if is(T, k + 1, ',') then k = k + 2 else break end end
329
309
  elseif kw(T, i, 'as') and T.k[i + 1] == 'id' then add(i + 1) end
330
- elseif language == 'javascript' or language == 'typescript' or language == 'kotlin' then
310
+ elseif language == 'javascript' or language == 'typescript' or language == 'arkts' or language == 'kotlin' then
331
311
  if (kw(T, i, 'let') or kw(T, i, 'const') or kw(T, i, 'var') or kw(T, i, 'val')) and T.k[i + 1] == 'id' then
332
312
  local k, type = i + 2, nil
333
313
  if is(T, k, ':') then
@@ -419,14 +399,14 @@ local function module_aliases(T, language)
419
399
  end
420
400
  j = j + 1
421
401
  end
422
- elseif (language == 'javascript' or language == 'typescript') then
402
+ elseif (language == 'javascript' or language == 'typescript' or language == 'arkts') then
423
403
  if kw(T, i, 'import') and is(T, i + 1, '*') and T.k[i + 3] == 'id' and T.k[i + 5] == 'str' then
424
404
  out[text_of(T, i + 3)] = { kind = 'import', path = text_of(T, i + 5):sub(2, -2) }
425
405
  elseif kw(T, i, 'import') and T.k[i + 1] == 'id' and T.k[i + 3] == 'str' then
426
406
  out[text_of(T, i + 1)] = { kind = 'import', path = text_of(T, i + 3):sub(2, -2) }
427
407
  elseif (kw(T, i, 'const') or kw(T, i, 'let') or kw(T, i, 'var')) and T.k[i + 1] == 'id' and is(T, i + 2, '=') then
428
408
  local value = initializer(T, i + 3, math.min(T.n, i + 6))
429
- if value.module then out[text_of(T, i + 1)] = { kind = 'import', path = value.module } end
409
+ if value.module then out[text_of(T, i + 1)] = { kind = 'require', path = value.module } end
430
410
  end
431
411
  elseif language == 'go' and kw(T, i, 'import') then
432
412
  local first, last = i + 1, i + 2
@@ -468,11 +448,32 @@ local Completion = {}
468
448
  Completion.__index = Completion
469
449
 
470
450
  -- Type nodes named name, as seen from file f.
471
- function Completion:types(name, f)
451
+ function Completion:types(name, f, scope, at)
472
452
  if not name then return {} end
473
453
  f = f or self.f
454
+ if self.V.files[f].language == 'go' then return require('codeoutline.go_methods').context(self.V, self.V.js_context).types(f, name) end
474
455
  local accept = self.language == 'lua' and LUA_TYPES or TYPES
475
456
  local direct, paired = navigation.deps(self.V, f)
457
+ if self.V.files[f].language == 'csharp' then
458
+ local ids = require('codeoutline.csharp_bindings').types(self.V, f, name,
459
+ at or (f == self.f and self.offset) or 0, self.V.js_context, { scope = scope })
460
+ return ids
461
+ end
462
+ if self.V.files[f].language == 'java' or self.V.files[f].language == 'kotlin' then
463
+ local owner = self.fn and self.rec.nodes[self.fn] or self.owner and self.rec.nodes[self.owner]
464
+ scope = scope or owner and owner.qualified
465
+ return require('codeoutline.implementations').types(self.V, f, name, self.V.js_context, scope, at)
466
+ end
467
+ if self.V.files[f].language == 'cpp' then
468
+ if not scope and f == self.f then
469
+ local owner = self.fn and self.rec.nodes[self.fn] or self.owner and self.rec.nodes[self.owner]
470
+ scope = owner and (CALLABLE[owner.kind] and owner.qualified:match('^(.*)::[^:]+$') or owner.qualified)
471
+ end
472
+ if at == nil and f == self.f then at = self.offset end
473
+ local ids = require('codeoutline.cpp_types').resolve(self.V, f, name,
474
+ { scope = scope, at = at or nil, context = self.V.js_context, accept = TYPES, forward = true })
475
+ return ids
476
+ end
476
477
  local found = graph.resolve(self.V, f, nil, name, 'call', nil, direct, paired, accept) or {}
477
478
  if #found == 0 then
478
479
  local family = graph.family(self.V.files[f].language)
@@ -501,7 +502,7 @@ function Completion:types(name, f)
501
502
  end
502
503
 
503
504
  function Completion:expired()
504
- if os.clock() > self.deadline then self.incomplete = true; return true end
505
+ if xtimer.now_ms() > self.deadline then self.incomplete = true; return true end
505
506
  return false
506
507
  end
507
508
 
@@ -509,6 +510,13 @@ end
509
510
  function Completion:members(ids, depth, seen)
510
511
  depth, seen = depth or 0, seen or {}
511
512
  local V, out = self.V, {}
513
+ if self.language == 'go' then
514
+ local methods = require('codeoutline.go_methods').context(V, V.js_context)
515
+ for _, id in ipairs(ids) do
516
+ for _, entry in ipairs(methods.members({ id = id, pointer = false, addressable = true }, self.f)) do out[#out + 1] = entry end
517
+ end
518
+ return out
519
+ end
512
520
  local function add(name, kind, node, f)
513
521
  out[#out + 1] = { name = name, kind = kind, node = node, file = f }
514
522
  end
@@ -528,9 +536,18 @@ function Completion:members(ids, depth, seen)
528
536
  if c.parent == n then add(c.name, c.kind, c, f) end
529
537
  end
530
538
  -- Out-of-line members anywhere: `Box::area`, Go methods, Lua `M.f` / `M:f`.
531
- for _, entry in ipairs(self:owned(node.qualified, graph.family(language))) do out[#out + 1] = entry end
539
+ for _, entry in ipairs(self:owned(node.qualified, graph.family(language))) do
540
+ if self:expired() then break end
541
+ local owner = language == 'cpp' and require('codeoutline.cpp_types').owner(V, entry.file, entry.node, V.js_context)
542
+ local parent = entry.node.parent and V.files[entry.file].nodes[entry.node.parent]
543
+ local legacy = language == 'cpp' and not owner and (not parent or not TYPES[parent.kind])
544
+ and not require('codeoutline.cpp_includes').policy(V, self.f, V.js_context).configured
545
+ if language ~= 'cpp' or owner == id or legacy then
546
+ out[#out + 1] = entry
547
+ end
548
+ end
532
549
  -- Attributes assigned in methods (Python, JS) or on Lua tables.
533
- if T and (language == 'python' or language == 'javascript' or language == 'typescript' or language == 'lua') then
550
+ if T and (language == 'python' or language == 'javascript' or language == 'typescript' or language == 'arkts' or language == 'lua') then
534
551
  local first, last = 1, T.n
535
552
  if target.start_byte and language ~= 'lua' then
536
553
  first, last = nil, nil
@@ -552,7 +569,7 @@ function Completion:members(ids, depth, seen)
552
569
  -- Base classes.
553
570
  if depth < 3 and node.bases then
554
571
  for _, base in ipairs(node.bases) do
555
- local base_ids = self:types(normalize(base), f)
572
+ local base_ids = self:types(normalize(base, self.language), f, node.qualified:match('^(.*)::[^:]+$'), false)
556
573
  for _, entry in ipairs(self:members(base_ids, depth + 1, seen)) do out[#out + 1] = entry end
557
574
  end
558
575
  end
@@ -615,9 +632,9 @@ function Completion:module_members(files, module_name)
615
632
  if self:expired() then break end
616
633
  local rec = self.V.files[g]
617
634
  local language = rec.language
618
- local native = rec.foreign_exports and rec.foreign_exports[self.language]
635
+ local native = require('codeoutline.foreign').exports(rec, self.language, module_name)
619
636
  if native then
620
- for name, n in pairs(native[module_name] or {}) do
637
+ for name, n in pairs(native) do
621
638
  local node = rec.nodes[n]
622
639
  out[#out + 1] = { name = name, kind = node.kind, node = node, file = g }
623
640
  end
@@ -765,6 +782,17 @@ end
765
782
  -- A receiver: { types = ids } or { modules = files }.
766
783
  function Completion:receiver(item, depth)
767
784
  local name = item.name
785
+ if self.language == 'go' then
786
+ local receiver = require('codeoutline.go_methods').context(self.V, self.V.js_context).receiver(self.f, name, self.offset)
787
+ if receiver == false then return { go_blocked = true } end
788
+ if receiver then return { go_receiver = receiver } end
789
+ end
790
+ if self.language == 'lua' then
791
+ local target, bound = require('codeoutline.lua_bindings').receiver(
792
+ self.V, self.rec, self.T, name, self.offset, self.V.js_context.lua)
793
+ if target then return target end
794
+ if bound then return { owner = name, local_only = true } end
795
+ end
768
796
  if SELF[name] or (self.language == 'rust' and name == 'self') then
769
797
  local ids = self:self_types()
770
798
  if #ids > 0 then return { types = ids } end
@@ -774,7 +802,7 @@ function Completion:receiver(item, depth)
774
802
  if entry.module then
775
803
  return { modules = import_files(self.V, self.f, { kind = entry.module_kind or 'require', path = entry.module }), module_name = entry.module }
776
804
  elseif entry.type then
777
- local ids = self:types(entry.type)
805
+ local ids = self:types(entry.type, nil, nil, entry.at and self.T.s[entry.at] - 1)
778
806
  if #ids > 0 then return { types = ids } end
779
807
  elseif entry.chain and depth < M.MAX_DEPTH then
780
808
  return self:chain(entry.chain, depth + 1)
@@ -792,6 +820,18 @@ function Completion:receiver(item, depth)
792
820
  local files = require('codeoutline.lua_bindings').native_modules(self.V, name, self.V.js_context.lua)
793
821
  if #files > 0 then return { modules = files, module_name = name } end
794
822
  end
823
+ if self.language == 'csharp' then
824
+ if name == 'global' then return { csharp_namespace = '' } end
825
+ local ids, namespace, known = require('codeoutline.csharp_bindings').types(self.V, self.f, name, self.offset, self.V.js_context)
826
+ if namespace then return { csharp_namespace = namespace } end
827
+ if known then return #ids > 0 and { types = ids, static = not item.call } or nil end
828
+ end
829
+ if self.language == 'cpp' then
830
+ local ids = self:types(name)
831
+ if #ids == 0 then return nil end
832
+ if self.V.nodes[ids[1]].kind == 'namespace' then return { cpp_namespace = self.V.nodes[ids[1]].qualified } end
833
+ return { types = ids, static = true }
834
+ end
795
835
  local ids = self:types(name)
796
836
  if #ids > 0 then return { types = ids, static = true } end
797
837
  -- Dynamic languages: a global table with members defined elsewhere, or a
@@ -802,38 +842,109 @@ end
802
842
 
803
843
  function Completion:entries(target)
804
844
  if not target then return {} end
845
+ if target.go_blocked or target.cxx_blocked then return {} end
846
+ if target.go_receiver then return require('codeoutline.go_methods').context(self.V, self.V.js_context).members(target.go_receiver, self.f) end
847
+ if target.cxx_receiver then
848
+ local receivers = require('codeoutline.cpp_receivers').context(self.V, self.V.js_context)
849
+ local out, names = {}, {}
850
+ for _, entry in ipairs(self:members({ target.cxx_receiver.id })) do
851
+ if self:expired() then break end
852
+ if not names[entry.name] then
853
+ names[entry.name] = true
854
+ for _, id in ipairs(receivers.members(target.cxx_receiver, entry.name, target.cxx_op)) do
855
+ out[#out + 1] = { name = self.V.nodes[id].name, kind = self.V.nodes[id].kind,
856
+ node = self.V.nodes[id], file = self.V.node_file[id] }
857
+ end
858
+ end
859
+ end
860
+ return out
861
+ end
862
+ if target.rust_module then return require('codeoutline.rust_resolution').members(self.V, target.rust_module, self.V.js_context) end
863
+ if target.cpp_namespace then
864
+ local bindings, result = require('codeoutline.cpp_types'), {}
865
+ local any = setmetatable({}, { __index = function() return true end })
866
+ for _, entry in ipairs(bindings.namespace_members(self.V, self.f, target.cpp_namespace, self.V.js_context, self.offset,
867
+ nil, nil, function() return self:expired() end)) do
868
+ if self:expired() then break end
869
+ local ids = bindings.resolve(self.V, self.f, '::' .. target.cpp_namespace .. '::' .. entry.name,
870
+ { context = self.V.js_context, at = self.offset, accept = any })
871
+ if #ids > 0 then result[#result + 1] = entry end
872
+ end
873
+ return result
874
+ end
875
+ if target.csharp_namespace ~= nil then
876
+ return require('codeoutline.csharp_bindings').namespace_members(self.V, self.f, target.csharp_namespace, self.V.js_context)
877
+ end
805
878
  if target.modules then return self:module_members(target.modules, target.module_name) end
806
879
  if target.owner then
807
880
  local out = target.local_only and {} or self:owned(target.owner, graph.family(self.language))
808
881
  for _, entry in ipairs(self:assigned(target.owner)) do out[#out + 1] = entry end
809
882
  return out
810
883
  end
811
- return self:members(target.types)
884
+ local entries = self:members(target.types)
885
+ if self.language == 'csharp' then
886
+ local kept = {}
887
+ for _, entry in ipairs(entries) do
888
+ local n = entry.node
889
+ local bindings = require('codeoutline.csharp_bindings')
890
+ if not n or TYPES[n.kind] or (bindings.static_node(self.V, entry.file, n, self.V.js_context) == (target.static or false)
891
+ and bindings.visible_node(self.V, self.f, entry.file, n, self.offset, self.V.js_context)) then kept[#kept + 1] = entry end
892
+ end
893
+ return kept
894
+ end
895
+ return entries
812
896
  end
813
897
 
814
898
  -- Type of a receiver chain, element by element.
815
899
  function Completion:chain(chain, depth)
816
900
  depth = depth or 0
901
+ if self.rust_static and require('codeoutline.rust_packages').owner(self.V, self.f, self.V.js_context) then
902
+ local names, plain = {}, true
903
+ for _, element in ipairs(chain) do names[#names + 1] = element.name; if element.call then plain = false end end
904
+ if plain then
905
+ local scope = require('codeoutline.rust_resolution').scope(self.V, self.f, self.fn and self.V.id_of[self.f][self.fn])
906
+ local found = require('codeoutline.rust_resolution').path(self.V, self.f, table.concat(names, '::'), self.V.js_context, scope)
907
+ if found and found.module then return { rust_module = found.module } end
908
+ end
909
+ end
817
910
  local target = self:receiver(chain[1], depth)
818
911
  for k = 2, #chain do
819
912
  if not target or self:expired() then return nil end
820
- local element, next_ids = chain[k], {}
913
+ local element, next_ids, next_files, next_module, next_namespace, next_static, next_cpp = chain[k], {}, nil, nil, nil, nil, nil
821
914
  for _, entry in ipairs(self:entries(target)) do
822
915
  if entry.name == element.name then
823
916
  local node = entry.node
824
- if TYPES[node.kind] then
917
+ if self.language == 'cpp' and node.kind == 'namespace' then next_cpp = node.qualified
918
+ elseif self.language == 'cpp' and TYPES[node.kind] then
919
+ for _, id in ipairs(self:types('::' .. node.qualified)) do next_ids[#next_ids + 1] = id end
920
+ elseif self.language == 'csharp' and node.kind == 'namespace' then next_namespace = node.qualified
921
+ elseif self.language == 'csharp' and TYPES[node.kind] then
922
+ next_static = not element.call
923
+ local ids = require('codeoutline.csharp_bindings').types(self.V, self.f, 'global::' .. node.qualified, self.offset, self.V.js_context)
924
+ for _, id in ipairs(ids) do next_ids[#next_ids + 1] = id end
925
+ elseif TYPES[node.kind] then
825
926
  for _, id in ipairs(self:types(node.name, entry.file)) do next_ids[#next_ids + 1] = id end
826
927
  else
827
- local type = declared(node, self.V.files[entry.file].language)
928
+ local detail = navigation.detail(self.V, entry.file, node)
929
+ local type = declared(detail, self.V.files[entry.file].language)
828
930
  if not type and element.call and FACTORY[element.name] and target.types then
829
931
  for _, id in ipairs(target.types) do next_ids[#next_ids + 1] = id end
830
932
  elseif type then
831
- for _, id in ipairs(self:types(type, entry.file)) do next_ids[#next_ids + 1] = id end
933
+ local scope = node.qualified:match('^(.*)::[^:]+$')
934
+ or self.language == 'csharp' and node.qualified:match('^(.*)%.[^.]+$')
935
+ for _, id in ipairs(self:types(type, entry.file, scope, self.language == 'csharp' and detail.name_start or false)) do next_ids[#next_ids + 1] = id end
936
+ end
937
+ if #next_ids == 0 and element.call and self.language == 'lua' then
938
+ -- A native object: the C implementation names the metatable
939
+ -- it returns, which is the type the guest sees.
940
+ local value = require('codeoutline.lua_bindings').return_target(self.V, node, self.V.js_context.lua)
941
+ if value then next_files, next_module = value.modules, value.module_name end
832
942
  end
833
943
  end
834
944
  end
835
945
  end
836
- target = #next_ids > 0 and { types = next_ids } or nil
946
+ target = next_cpp and { cpp_namespace = next_cpp } or next_namespace and { csharp_namespace = next_namespace } or #next_ids > 0 and { types = next_ids, static = next_static }
947
+ or (next_module and { modules = next_files, module_name = next_module } or nil)
837
948
  end
838
949
  return target
839
950
  end
@@ -845,7 +956,7 @@ local function receiver_chain(T, op, member)
845
956
  local call = false
846
957
  if is(T, i, ')') and T.m[i] then call = true; i = T.m[i] - 1 end
847
958
  if is(T, i, '>') and T.m[i] then i = T.m[i] - 1 end
848
- if not (T.k[i] == 'id' or (T.k[i] == 'kw' and SELF[text_of(T, i)])) then
959
+ if not (T.k[i] == 'id' or (T.k[i] == 'kw' and (SELF[text_of(T, i)] or text_of(T, i) == 'crate' or text_of(T, i) == 'super'))) then
849
960
  if call or #chain == 0 then return nil end
850
961
  break
851
962
  end
@@ -856,9 +967,10 @@ local function receiver_chain(T, op, member)
856
967
  return #chain > 0 and chain or nil
857
968
  end
858
969
 
859
- local function item_for(entry, language)
970
+ local function item_for(entry, language, V, details)
860
971
  local node = entry.node
861
972
  local foreign = node and require('codeoutline.foreign').signature(node, language, entry.name)
973
+ if details and node and entry.file and not foreign then node = navigation.detail(V, entry.file, node) end
862
974
  return { label = entry.name, kind = ITEM[entry.kind] or 6,
863
975
  detail = foreign and foreign.label or (node and (node.sig or (node.type and (node.type .. ' ' .. entry.name))) or entry.detail) }
864
976
  end
@@ -867,10 +979,10 @@ end
867
979
  function M.complete(req)
868
980
  local doc = navigation.request_doc(req)
869
981
  if not doc then return { items = {} } end
870
- local V = navigation.view(req.session, req.root)
982
+ local V = navigation.view(req.session, req.root, req.includePaths)
871
983
  local f = V.add(doc)
872
984
  if not f then return { items = {} } end
873
- local self = setmetatable({ V = V, f = f, doc = doc, deadline = os.clock() + M.BUDGET_SECONDS,
985
+ local self = setmetatable({ V = V, f = f, doc = doc, deadline = xtimer.now_ms() + M.BUDGET_SECONDS * 1000,
874
986
  incomplete = false }, Completion)
875
987
  self.rec, self.T = full(V, f)
876
988
  if not self.rec or not self.T then return { items = {} } end
@@ -884,13 +996,36 @@ function M.complete(req)
884
996
  local op = t
885
997
  if t and (T.k[t] == 'id' or T.k[t] == 'kw') and T.e[t] >= offset then op = t - 1 end
886
998
  local is_member = op and op >= 1 and T.k[op] == 'op' and member[text_of(T, op)] and T.e[op] <= offset
999
+ self.rust_static = self.language == 'rust' and is_member and text_of(T, op) == '::'
887
1000
  if req.trigger and not is_member then return { items = {} } end
888
1001
  self.fn, self.owner = self:scope()
1002
+ local prefix = t and T.k[t] == 'id' and T.e[t] >= offset
1003
+ and doc.source:sub(T.s[t], offset):lower() or ''
889
1004
  self.aliases = module_aliases(T, self.language)
1005
+ if self.language == 'go' then self.aliases = require('codeoutline.go_modules').aliases(V, f, V.js_context) end
890
1006
  local entries = {}
891
1007
  if is_member then
892
1008
  local chain = receiver_chain(T, op, member)
893
- local target = chain and self:chain(chain)
1009
+ local target
1010
+ if self.language == 'go' then
1011
+ local methods = require('codeoutline.go_methods')
1012
+ local expression = methods.expression(T, op - 1)
1013
+ if expression and expression.kind ~= 'binding_value' then
1014
+ local receiver = methods.context(V, V.js_context).expression_receiver(f, expression)
1015
+ target = receiver and { go_receiver = receiver } or { go_blocked = true }
1016
+ end
1017
+ elseif self.language == 'c' or self.language == 'cpp' then
1018
+ local receivers = require('codeoutline.cpp_receivers')
1019
+ local expression, _, _, call = receivers.expression(T, op - 1)
1020
+ if call then
1021
+ local source = self.fn and V.id_of[f][self.fn]
1022
+ local receiver = receivers.context(V, V.js_context).receiver(f, expression, source)
1023
+ local valid = receiver and (text_of(T, op) == '->' and receiver.pointer == 1
1024
+ or text_of(T, op) == '.' and receiver.pointer == 0)
1025
+ target = valid and { cxx_receiver = receiver, cxx_op = text_of(T, op) } or { cxx_blocked = true }
1026
+ end
1027
+ end
1028
+ target = target or chain and self:chain(chain)
894
1029
  entries = self:entries(target)
895
1030
  if self.language == 'lua' and text_of(T, op) == ':' then
896
1031
  local methods = {}
@@ -903,6 +1038,21 @@ function M.complete(req)
903
1038
  detail = entry.type and (entry.type .. ' ' .. entry.name) or nil }
904
1039
  end
905
1040
  for alias in pairs(self.aliases) do entries[#entries + 1] = { name = alias, kind = 'namespace', detail = 'module' } end
1041
+ if self.language == 'csharp' then
1042
+ local bindings = require('codeoutline.csharp_bindings')
1043
+ for _, entry in ipairs(bindings.usings(V, f, self.offset, V.js_context)) do
1044
+ local d = entry.directive
1045
+ if d.alias then entries[#entries + 1] = { name = d.alias:gsub('^@', ''), kind = 'class', detail = d.path }
1046
+ elseif d.static then
1047
+ local ids = bindings.types(V, entry.file, d.path, d.first, V.js_context,
1048
+ { exclude = d.first, no_global = true, scope = d.scope })
1049
+ for _, member in ipairs(self:members(ids)) do
1050
+ if TYPES[member.kind] or bindings.static_node(V, member.file, member.node, V.js_context)
1051
+ and bindings.visible_node(V, f, member.file, member.node, self.offset, V.js_context) then entries[#entries + 1] = member end
1052
+ end
1053
+ end
1054
+ end
1055
+ end
906
1056
  for _, node in ipairs(self.rec.nodes) do
907
1057
  if not node.parent and (self.language == 'kotlin' or not node.qualified:find('[%.:]')) then
908
1058
  entries[#entries + 1] = { name = node.name, kind = node.kind, node = node, file = f }
@@ -945,6 +1095,12 @@ function M.complete(req)
945
1095
  end
946
1096
  end
947
1097
  end
1098
+ if self.language == 'cpp' and not self:expired() then
1099
+ local owner = self.fn and self.rec.nodes[self.fn] or self.owner and self.rec.nodes[self.owner]
1100
+ local scope = owner and (CALLABLE[owner.kind] and owner.qualified:match('^(.*)::[^:]+$') or owner.qualified)
1101
+ for _, entry in ipairs(require('codeoutline.cpp_types').imported_members(V, f, scope, offset, V.js_context,
1102
+ function() return self:expired() end, prefix)) do entries[#entries + 1] = entry end
1103
+ end
948
1104
  if self.owner or self.fn then
949
1105
  local ids = self:self_types()
950
1106
  for _, entry in ipairs(self:members(ids)) do entries[#entries + 1] = entry end
@@ -952,8 +1108,6 @@ function M.complete(req)
952
1108
  end
953
1109
  -- Preserve editor-side fuzzy filtering, but keep prefix matches ahead of
954
1110
  -- unrelated items when a large include tree exceeds the response limit.
955
- local prefix = t and T.k[t] == 'id' and T.e[t] >= offset
956
- and doc.source:sub(T.s[t], offset):lower() or ''
957
1111
  if prefix ~= '' and #entries > M.MAX_ITEMS then
958
1112
  local ordered = {}
959
1113
  for _, entry in ipairs(entries) do
@@ -969,10 +1123,12 @@ function M.complete(req)
969
1123
  if not seen[entry.name] then
970
1124
  seen[entry.name] = true
971
1125
  if #items >= M.MAX_ITEMS then self.incomplete = true; break end
972
- items[#items + 1] = item_for(entry, self.language)
1126
+ items[#items + 1] = item_for(entry, self.language, V, not self:expired())
973
1127
  end
974
1128
  end
975
- return { items = items, incomplete = self.incomplete }
1129
+ return { items = items, incomplete = self.incomplete or V.js_context.include_incomplete
1130
+ or V.js_context.workspace_incomplete or V.js_context.go_incomplete or V.js_context.go_methods_incomplete
1131
+ or V.js_context.cpp_receivers_incomplete or V.js_context.rust_incomplete }
976
1132
  end
977
1133
 
978
1134
  navigation.register('lsp_completion', function(req)
@@ -0,0 +1,63 @@
1
+ -- Small agent-facing status, independent of source text and temporary node IDs.
2
+ local M = {}
3
+
4
+ function M.relations(info)
5
+ local result = {}
6
+ local stats = info.query_stats or {}
7
+ for reason in pairs(stats.incomplete_reasons or {}) do result[#result + 1] = reason end
8
+ local shared = stats.events and stats.events.shared
9
+ for reason in pairs(shared and shared.incomplete_reasons or {}) do
10
+ result[#result + 1] = 'shared_events.' .. reason
11
+ end
12
+ if info.relationships_incomplete and #result == 0 then result[1] = 'relationship_analysis_incomplete' end
13
+ table.sort(result); return result
14
+ end
15
+
16
+ function M.summarize(info)
17
+ info = info or {}
18
+ local reasons, seen = {}, {}
19
+ local function add(reason)
20
+ if not seen[reason] then seen[reason] = true; reasons[#reasons + 1] = reason end
21
+ end
22
+ for _, reason in ipairs(M.relations(info)) do add(reason) end
23
+ local flags = {
24
+ truncated = 'output_truncated', seed_selection_limited = 'seed_selection_limited',
25
+ seed_limit_reached = 'seed_candidate_limit', path_search_limited = 'path_search_limit',
26
+ depth_limit_reached = 'depth_limit', node_limit_reached = 'node_limit', time_limit_reached = 'time_limit',
27
+ candidate_limit_reached = 'candidate_limit', cycle_detected = 'inheritance_cycle',
28
+ evidence_truncated = 'evidence_omitted', unresolved_candidates_truncated = 'definition_candidates_omitted',
29
+ path_breakpoints_truncated = 'path_breakpoints_omitted', on_demand_truncated = 'on_demand_limit',
30
+ }
31
+ for flag, reason in pairs(flags) do if info[flag] then add(reason) end end
32
+ if info.unresolved_files and #info.unresolved_files > 0 then add('unresolved_files') end
33
+ if info.files_without_symbols and #info.files_without_symbols > 0 then add('files_without_symbols') end
34
+ if info.on_demand_rejected and #info.on_demand_rejected > 0 then add('on_demand_rejected') end
35
+ if info.unresolved and #info.unresolved > 0 then add('unresolved_types') end
36
+ if (info.unresolved_sites or 0) > 0 then add('unresolved_type_sites') end
37
+ if (info.ambiguous_sites or 0) > 0 then add('ambiguous_type_sites') end
38
+ if info.query_stats and (info.query_stats.reverse_unresolved or 0) > 0 then add('unresolved_reverse_types') end
39
+ local resolution = info.query_stats and info.query_stats.resolution
40
+ if resolution then
41
+ if resolution.unresolved_sites > 0 then add('unresolved_calls') end
42
+ if resolution.ambiguous_sites > 0 then add('ambiguous_calls') end
43
+ if resolution.counts_limited then add('resolution_count_limit') end
44
+ end
45
+ if info.incomplete and #reasons == 0 then add('analysis_incomplete') end
46
+ table.sort(reasons)
47
+ return { scope = 'indexed_static_analysis', partial = #reasons > 0, reasons = reasons,
48
+ output_truncated = info.truncated == true, relationships_incomplete = info.relationships_incomplete == true,
49
+ selection_limited = info.seed_selection_limited == true or info.seed_limit_reached == true }
50
+ end
51
+
52
+ function M.error(message)
53
+ message = tostring(message or '')
54
+ local code, retryable = 'query_failed', false
55
+ if message:find('source changed', 1, true) or message:find('source snapshot changed', 1, true) then
56
+ code, retryable = 'source_changed', true
57
+ elseif message:find('deadline exceeded', 1, true) then code, retryable = 'deadline_exceeded', true
58
+ elseif message:find('queue is full', 1, true) or message:find('queue wait exceeded', 1, true) then code, retryable = 'busy', true
59
+ elseif message:lower():find('cancelled', 1, true) then code = 'cancelled' end
60
+ return { code = code, retryable = retryable, retryAfterMs = code == 'busy' and 250 or nil }
61
+ end
62
+
63
+ return M