@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
@@ -1,8 +1,9 @@
1
- -- Shared C++ named-type lookup. Alias bodies and lexical ranges are query-only.
1
+ -- Shared C++ name lookup. Alias/import bodies and lexical ranges are query-only.
2
2
  local M = {}
3
3
  local control = require('codeoutline.control')
4
4
  local classes = { class = true, struct = true, union = true }
5
- local declaring = { class = true, struct = true, union = true, enum = true, namespace = true, typedef = true }
5
+ local declaring = { class = true, struct = true, union = true, enum = true, namespace = true, typedef = true,
6
+ ['function'] = true, method = true, prototype = true, variable = true, field = true, constant = true, macro = true }
6
7
  local callable = { ['function'] = true, method = true, constructor = true, destructor = true }
7
8
  local qualifiers = { const = true, volatile = true, struct = true, class = true, union = true }
8
9
 
@@ -47,14 +48,22 @@ function M.collect(r, T)
47
48
  for i = 1, T.n do
48
49
  if i % 4096 == 0 then control.check() end
49
50
  local word = T:text(i)
50
- if word == 'using' and T.k[i + 1] == 'id' and T:text(i + 2) == '=' or word == 'typedef' then
51
+ local ns_alias = word == 'namespace' and T.k[i + 1] == 'id' and T:text(i + 2) == '='
52
+ local forward = classes[word] and T.k[i + 1] == 'id' and T:text(i + 2) == ';'
53
+ if word == 'using' or word == 'typedef' or ns_alias or forward then
51
54
  local stop = i + 1
52
55
  while stop <= T.n and T:text(stop) ~= ';' do
53
56
  if T.m[stop] and T.m[stop] > stop then stop = T.m[stop] end
54
57
  stop = stop + 1
55
58
  end
56
- local name, first, last
57
- if word == 'using' then name, first, last = i + 1, i + 3, stop - 1
59
+ local name, first, last, kind
60
+ if forward then name, first, last, kind = i + 1, i + 1, i + 1, 'forward'
61
+ elseif ns_alias then name, first, last, kind = i + 1, i + 3, stop - 1, 'namespace'
62
+ elseif word == 'using' and T:text(i + 1) == 'namespace' then
63
+ name, first, last, kind = i + 1, i + 2, stop - 1, 'directive'
64
+ elseif word == 'using' and T:text(i + 2) == '=' then name, first, last = i + 1, i + 3, stop - 1
65
+ elseif word == 'using' and T.k[stop - 1] == 'id' then
66
+ name, first, last, kind = stop - 1, i + 1, stop - 1, 'using'
58
67
  elseif T.k[stop - 1] == 'id' then name, first, last = stop - 1, i + 1, stop - 2 end
59
68
  -- Unsupported function-pointer typedefs still introduce a name barrier.
60
69
  if not name then
@@ -80,7 +89,10 @@ function M.collect(r, T)
80
89
  if local_alias then scope = scope:match('^(.*)::[^:]+$') or '' end
81
90
  local text = first and T.src:sub(T.s[first], T.e[last])
82
91
  local open = scopes[i]
83
- result[#result + 1] = { name = T:text(name), target = not templated and M.normalize(text) or false,
92
+ result[#result + 1] = { name = kind == 'directive' and '*' or T:text(name), kind = kind,
93
+ target = not templated and M.normalize(text) or false,
94
+ decorated = not kind and text and (text:find('[*&]') ~= nil or text:match('%f[%w]const%f[%W]') ~= nil
95
+ or text:match('%f[%w]volatile%f[%W]') ~= nil) or nil,
84
96
  scope = scope, local_alias = local_alias, at = T.s[name] - 1,
85
97
  first = open > 0 and T.s[open] - 1 or 0,
86
98
  last = open > 0 and T.e[T.m[open]] or #T.src }
@@ -90,6 +102,19 @@ function M.collect(r, T)
90
102
  if #result > 0 then r.cpp_aliases = result end
91
103
  end
92
104
 
105
+ -- Preserve the whole written qualifier, not just the receiver's final token.
106
+ function M.evidence(T, t)
107
+ local first = t
108
+ while T:text(first - 1) == '::' and T.k[first - 2] == 'id' do first = first - 2 end
109
+ if T:text(first - 1) == '::' then first = first - 1 end
110
+ return 'cpp:name:' .. T.src:sub(T.s[first], T.e[t]):gsub('%s+', '') .. '\0' .. (T.s[t] - 1)
111
+ end
112
+
113
+ function M.aliases(G, f, ctx)
114
+ if ctx and ctx.ordinary and ctx.ordinary.cpp_aliases then return ctx.ordinary.cpp_aliases(f) end
115
+ return (ctx and ctx.ordinary and ctx.ordinary.data(f) or G.files[f]).cpp_aliases or {}
116
+ end
117
+
93
118
  -- opts.at is a byte position in file f, normally the receiver declaration.
94
119
  -- The boolean result distinguishes an unknown name from a known but unresolved
95
120
  -- declaration, so completion cannot revive a hidden outer type on failure.
@@ -97,50 +122,133 @@ function M.resolve(G, f, written, opts)
97
122
  opts = opts or {}
98
123
  written = M.normalize(written)
99
124
  if not written then return {}, true end
100
- local deps, ctx, accept = opts.deps or {}, opts.context, opts.accept or classes
101
- local visibility = { [f] = deps }
125
+ local ctx, accept = opts.context, opts.accept or classes
126
+ local visibility, records = {}, {}
127
+ local function dependencies(file)
128
+ if not visibility[file] then visibility[file] = require('codeoutline.graph').visible_dependencies(G, file, ctx) end
129
+ return visibility[file]
130
+ end
102
131
  local function visible(file, target)
103
132
  if file == target then return true end
104
- if not visibility[file] then visibility[file] = require('codeoutline.graph').dependencies(G, file, ctx) end
105
- return visibility[file][target]
133
+ return dependencies(file)[target]
106
134
  end
107
135
  local function aliases(file)
108
- local rec = G.files[file]
109
- return (ctx and ctx.ordinary and ctx.ordinary.data(file) or rec).cpp_aliases or {}
136
+ if not records[file] then records[file] = opts.aliases and opts.aliases(file) or M.aliases(G, file, ctx) end
137
+ return records[file]
138
+ end
139
+ local lists = {}
140
+ local function files(file)
141
+ if not lists[file] then
142
+ local list = { file }
143
+ -- A resident boolean says whether a header can change lookup without
144
+ -- introducing an indexed name. Detailed evidence remains query-only.
145
+ for g in pairs(dependencies(file)) do if G.files[g].cpp_imports then list[#list + 1] = g end end
146
+ table.sort(list, function(a, b) return G.files[a].path < G.files[b].path end)
147
+ lists[file] = list
148
+ end
149
+ return lists[file]
150
+ end
151
+ local directive_lists = {}
152
+ local function directive_files(file)
153
+ if not directive_lists[file] then
154
+ local list = { file }
155
+ for _, g in ipairs(files(file)) do
156
+ if g ~= file and (G.files[g].cpp_using_directives or opts.aliases) then list[#list + 1] = g end
157
+ end
158
+ directive_lists[file] = list
159
+ end
160
+ return directive_lists[file]
161
+ end
162
+ local function add(ids, more)
163
+ local seen = {}; for _, id in ipairs(ids) do seen[id] = true end
164
+ for _, id in ipairs(more) do if not seen[id] then seen[id] = true; ids[#ids + 1] = id end end
110
165
  end
111
166
  local seen = {}
112
167
  local resolve
113
168
  local function follow(alias, file, depth)
169
+ if opts.undecorated and alias.decorated then return {}, true end
114
170
  if not alias.target then return {} end
115
171
  local key = file .. ':' .. alias.at
116
- if seen[key] or depth >= 8 then return {} end
172
+ if seen[key] or depth >= 8 then return {}, true end
117
173
  seen[key] = true
118
174
  local ids = resolve(file, alias.target, alias.scope, alias.at, depth + 1)
119
175
  seen[key] = nil
176
+ if alias.kind == 'namespace' or alias.kind == 'directive' then
177
+ local kept = {}
178
+ for _, id in ipairs(ids) do if G.nodes[id].kind == 'namespace' then kept[#kept + 1] = id end end
179
+ ids = kept
180
+ end
120
181
  return ids
121
182
  end
122
183
  local function named(file, qualified, at, depth)
123
184
  local tail = qualified:match('([^:]+)$')
124
- local found, ids, unique = false, {}, {}
125
- local function add(more) for _, id in ipairs(more) do if not unique[id] then unique[id] = true; ids[#ids + 1] = id end end end
126
- for _, id in ipairs(G.by_name[tail] or {}) do
185
+ local found, ids, alias_declarations = false, {}, {}
186
+ for index, id in ipairs(G.by_name[tail] or {}) do
187
+ if index % 128 == 0 then control.check() end
127
188
  local n, g = G.nodes[id], G.node_file[id]
128
189
  if n.qualified == qualified and declaring[n.kind] and visible(file, g) then
129
190
  if n.kind == 'typedef' then
130
191
  local matched = false
131
192
  for _, alias in ipairs(aliases(g)) do
132
- if not alias.local_alias and (alias.scope ~= '' and alias.scope .. '::' or '') .. alias.name == qualified then
193
+ if not alias.kind and not alias.local_alias and (alias.scope ~= '' and alias.scope .. '::' or '') .. alias.name == qualified then
133
194
  matched = true
134
- if g ~= file or not at or alias.at <= at then found = true; add(follow(alias, g, depth)) end
195
+ if g ~= file or not at or alias.at <= at then
196
+ found = true; add(ids, follow(alias, g, depth))
197
+ if opts.navigation_alias and depth == 0 then add(alias_declarations, { id }) end
198
+ end
199
+ end
200
+ end
201
+ if not matched then
202
+ found = true -- unsupported alias is a barrier
203
+ if opts.navigation_alias and depth == 0 and (g ~= file or not at) then
204
+ add(alias_declarations, { id })
135
205
  end
136
206
  end
137
- if not matched then found = true end -- unsupported alias is a barrier
138
207
  else
139
208
  found = true
140
- if accept[n.kind] then add({ id }) end
209
+ add(ids, { id })
141
210
  end
142
211
  end
143
212
  end
213
+ -- A visible class declaration cannot be changed by an alias elsewhere.
214
+ -- Class-scope using declarations can only occur in that class's source;
215
+ -- do not fully inspect every transitive header to look up A::member.
216
+ local class_only = #ids > 0
217
+ for _, id in ipairs(ids) do if not classes[G.nodes[id].kind] then class_only = false; break end end
218
+ if class_only then return ids, true end
219
+ local alias_files, seen_files = {}, {}
220
+ local owner = qualified:match('^(.*)::[^:]+$')
221
+ while owner and #alias_files == 0 do
222
+ for _, id in ipairs(G.by_name[owner:match('([^:]+)$')] or {}) do
223
+ local n, g = G.nodes[id], G.node_file[id]
224
+ if classes[n.kind] and n.qualified == owner and visible(file, g) and not seen_files[g] then
225
+ seen_files[g] = true; alias_files[#alias_files + 1] = g
226
+ end
227
+ end
228
+ owner = owner:match('^(.*)::[^:]+$')
229
+ end
230
+ if #alias_files == 0 then alias_files = files(file) end
231
+ for _, g in ipairs(alias_files) do
232
+ control.check()
233
+ for _, alias in ipairs(aliases(g)) do
234
+ if alias.kind and alias.kind ~= 'directive' and not alias.local_alias
235
+ and (alias.scope ~= '' and alias.scope .. '::' or '') .. alias.name == qualified
236
+ and (g ~= file or not at or alias.at <= at) then
237
+ found = true
238
+ if alias.kind == 'forward' then
239
+ -- Preserve completion's existing incomplete-type aid,
240
+ -- but require an explicit forward declaration first.
241
+ if opts.forward then
242
+ for _, id in ipairs(G.by_name[tail] or {}) do
243
+ local n = G.nodes[id]
244
+ if n.qualified == qualified and classes[n.kind] then add(ids, { id }) end
245
+ end
246
+ end
247
+ else add(ids, follow(alias, g, depth)) end
248
+ end
249
+ end
250
+ end
251
+ if #ids == 0 and opts.navigation_alias then add(ids, alias_declarations) end
144
252
  return ids, found
145
253
  end
146
254
  local function qualified(file, name, at, depth)
@@ -153,17 +261,18 @@ function M.resolve(G, f, written, opts)
153
261
  if known then
154
262
  local result = {}
155
263
  for _, owner in ipairs(owners) do
156
- local more = named(file, G.nodes[owner].qualified .. '::' .. suffix, nil, depth + 1)
157
- for _, id in ipairs(more) do result[#result + 1] = id end
264
+ local node = G.nodes[owner]
265
+ local more
266
+ if node.kind == 'namespace' then more = resolve(file, suffix, node.qualified, at, depth + 1, true)
267
+ else more = named(file, node.qualified .. '::' .. suffix, nil, depth + 1) end
268
+ add(result, more)
158
269
  end
159
- -- Namespace nodes are not class results, so do not stop lexical
160
- -- lookup merely because a namespace prefix exists.
161
270
  if #owners > 0 then return result, true end
162
271
  end
163
272
  end
164
273
  return {}, false
165
274
  end
166
- resolve = function(file, name, scope, at, depth)
275
+ resolve = function(file, name, scope, at, depth, only_scope)
167
276
  control.check()
168
277
  if depth > 8 then return {}, true end
169
278
  if name:sub(1, 2) == '::' then return qualified(file, name:sub(3), at, depth) end
@@ -172,7 +281,7 @@ function M.resolve(G, f, written, opts)
172
281
  if at then
173
282
  local best
174
283
  for _, alias in ipairs(aliases(file)) do
175
- if alias.local_alias and alias.name == head and alias.at <= at and alias.first <= at and at <= alias.last
284
+ if alias.kind ~= 'directive' and alias.local_alias and alias.name == head and alias.at <= at and alias.first <= at and at <= alias.last
176
285
  and (not best or alias.first > best.first or alias.first == best.first and alias.at > best.at) then best = alias end
177
286
  end
178
287
  if best then
@@ -181,7 +290,7 @@ function M.resolve(G, f, written, opts)
181
290
  local result = {}
182
291
  for _, id in ipairs(ids) do
183
292
  local more = qualified(file, G.nodes[id].qualified .. '::' .. tail, nil, depth + 1)
184
- for _, target in ipairs(more) do result[#result + 1] = target end
293
+ add(result, more)
185
294
  end
186
295
  return result, true
187
296
  end
@@ -197,13 +306,160 @@ function M.resolve(G, f, written, opts)
197
306
  found = declared
198
307
  end
199
308
  end
309
+ -- using-directives contribute candidates only in their lexical
310
+ -- scope. Imported headers contribute namespace/file scope, never locals.
311
+ for _, g in ipairs(directive_files(file)) do
312
+ for _, alias in ipairs(aliases(g)) do
313
+ if alias.kind == 'directive' and alias.scope == (scope or '')
314
+ and not (g == f and alias.at == opts.exclude)
315
+ and (not alias.local_alias or g == file and at and alias.first <= at and at <= alias.last)
316
+ and (g ~= file or not at or alias.at <= at) then
317
+ local namespaces = follow(alias, g, depth)
318
+ for _, id in ipairs(namespaces) do
319
+ local q = G.nodes[id].qualified
320
+ local key = file .. ':' .. q .. ':' .. name
321
+ if not seen[key] then
322
+ seen[key] = true
323
+ local more, known = resolve(file, '::' .. q .. '::' .. name, '', at, depth + 1)
324
+ seen[key] = nil
325
+ if known then found = true; add(ids, more) end
326
+ end
327
+ end
328
+ end
329
+ end
330
+ end
200
331
  if found then return ids, true end
201
- if not scope or scope == '' then break end
332
+ if only_scope or not scope or scope == '' then break end
202
333
  scope = scope:match('^(.*)::[^:]+$') or ''
203
334
  end
204
335
  return {}, false
205
336
  end
206
- return resolve(f, written, opts.scope, opts.at, 0)
337
+ local ids, known = resolve(f, written, opts.scope, opts.at, 0)
338
+ local result, qualified = {}, nil
339
+ for _, id in ipairs(ids) do
340
+ local n = G.nodes[id]
341
+ -- Distinct qualified names are an ambiguity, not a locality contest.
342
+ if qualified and qualified ~= n.qualified then return {}, true end
343
+ qualified = n.qualified
344
+ if accept[n.kind] then result[#result + 1] = id end
345
+ end
346
+ if opts.definitions and #result > 0 then
347
+ local _, paired = require('codeoutline.graph').visible_dependencies(G, f, ctx)
348
+ local definitions = {}
349
+ for _, id in ipairs(G.by_name[G.nodes[result[1]].name] or {}) do
350
+ local n, g = G.nodes[id], G.node_file[id]
351
+ if n.qualified == qualified and accept[n.kind] and not n.decl and n.kind ~= 'prototype'
352
+ and (g == f or visible(f, g) or paired[g]) and not (n.static and g ~= f and paired[g]) then
353
+ definitions[#definitions + 1] = id
354
+ end
355
+ end
356
+ if #definitions > 0 then result = definitions end
357
+ end
358
+ return result, known
359
+ end
360
+
361
+ -- Class-outside members belong to the class visible in their own source file,
362
+ -- not every class elsewhere with the same spelling.
363
+ function M.owner(G, f, node, ctx)
364
+ local parent = node.parent and G.id_of[f][node.parent]
365
+ if parent and classes[G.nodes[parent].kind] then return parent end
366
+ local prefix = node.qualified:match('^(.*)::[^:]+$')
367
+ if not prefix then return nil end
368
+ local ids = M.resolve(G, f, prefix, { context = ctx, at = node.start_byte, undecorated = true })
369
+ return #ids == 1 and ids[1] or nil
370
+ end
371
+
372
+ -- Namespace members are restricted to declarations visible to the requester.
373
+ -- Overlay nodes replace the resident by_owner entries just as by_name does.
374
+ function M.namespace_members(G, f, namespace, ctx, at, seen, depth, expired)
375
+ seen, depth = seen or {}, depth or 0
376
+ if seen[namespace] or depth > 8 then return {} end
377
+ seen[namespace] = true
378
+ local deps = require('codeoutline.graph').visible_dependencies(G, f, ctx)
379
+ local result = {}
380
+ local function add(id)
381
+ local n, g = G.nodes[id], G.node_file[id]
382
+ if (g == f or deps[g]) and n.qualified:match('^(.*)::[^:]+$') == namespace then
383
+ result[#result + 1] = { name = n.name, kind = n.kind, node = n, file = g }
384
+ end
385
+ end
386
+ for _, id in ipairs(G.by_owner[namespace] or {}) do
387
+ if not (G.drafts and G.drafts[G.node_file[id]]) then add(id) end
388
+ end
389
+ for g in pairs(G.drafts or {}) do for _, id in ipairs(G.id_of[g]) do add(id) end end
390
+ local files = { f }; for g in pairs(deps) do if G.files[g].cpp_imports then files[#files + 1] = g end end
391
+ table.sort(files, function(a, b) return G.files[a].path < G.files[b].path end)
392
+ local any = setmetatable({}, { __index = function() return true end })
393
+ for _, g in ipairs(files) do
394
+ control.check()
395
+ if expired and expired() then return result end
396
+ for _, alias in ipairs(M.aliases(G, g, ctx)) do
397
+ if expired and expired() then return result end
398
+ if not alias.local_alias and alias.scope == namespace and (g ~= f or not at or alias.at <= at) then
399
+ if alias.kind == 'directive' and alias.target then
400
+ local ids = M.resolve(G, g, alias.target,
401
+ { scope = alias.scope, at = alias.at, exclude = alias.at, context = ctx, accept = { namespace = true } })
402
+ for _, id in ipairs(ids) do
403
+ for _, entry in ipairs(M.namespace_members(G, f, G.nodes[id].qualified, ctx, at, seen, depth + 1, expired)) do
404
+ result[#result + 1] = entry
405
+ end
406
+ end
407
+ elseif alias.kind ~= 'forward' then
408
+ local ids = M.resolve(G, f, '::' .. namespace .. '::' .. alias.name, { context = ctx, at = at, accept = any })
409
+ for _, id in ipairs(ids) do
410
+ local n = G.nodes[id]
411
+ result[#result + 1] = { name = alias.name, kind = n.kind, node = n, file = G.node_file[id] }
412
+ end
413
+ end
414
+ end
415
+ end
416
+ end
417
+ return result
418
+ end
419
+
420
+ function M.imported_members(G, f, scope, at, ctx, expired, prefix)
421
+ local deps = require('codeoutline.graph').visible_dependencies(G, f, ctx)
422
+ local result, names = {}, {}
423
+ local any = setmetatable({}, { __index = function() return true end })
424
+ local function active(alias, file)
425
+ if file == f and alias.at > at then return false end
426
+ if alias.local_alias then return file == f and alias.first <= at and at <= alias.last end
427
+ return alias.scope == '' or scope == alias.scope or (scope or ''):sub(1, #alias.scope + 2) == alias.scope .. '::'
428
+ end
429
+ local files = { f }; for g in pairs(deps) do if G.files[g].cpp_imports then files[#files + 1] = g end end
430
+ table.sort(files, function(a, b) return G.files[a].path < G.files[b].path end)
431
+ for _, g in ipairs(files) do
432
+ control.check()
433
+ if expired and expired() then break end
434
+ for _, alias in ipairs(M.aliases(G, g, ctx)) do
435
+ if expired and expired() then break end
436
+ if active(alias, g) then
437
+ if alias.kind == 'directive' and alias.target then
438
+ local ids = M.resolve(G, g, alias.target,
439
+ { scope = alias.scope, at = alias.at, exclude = alias.at, context = ctx, accept = { namespace = true } })
440
+ for _, id in ipairs(ids) do
441
+ for _, entry in ipairs(M.namespace_members(G, f, G.nodes[id].qualified, ctx, at, nil, nil, expired)) do names[entry.name] = true end
442
+ end
443
+ else names[alias.name] = true end
444
+ end
445
+ end
446
+ end
447
+ local ordered, rest = {}, {}
448
+ for name in pairs(names) do
449
+ local bucket = prefix and name:sub(1, #prefix):lower() == prefix and ordered or rest
450
+ bucket[#bucket + 1] = name
451
+ end
452
+ table.sort(ordered); table.sort(rest)
453
+ for _, name in ipairs(rest) do ordered[#ordered + 1] = name end
454
+ for _, name in ipairs(ordered) do
455
+ if expired and expired() then break end
456
+ local ids = M.resolve(G, f, name, { scope = scope, at = at, context = ctx, accept = any })
457
+ for _, id in ipairs(ids) do
458
+ local n = G.nodes[id]
459
+ result[#result + 1] = { name = name, kind = n.kind, node = n, file = G.node_file[id] }
460
+ end
461
+ end
462
+ return result
207
463
  end
208
464
 
209
465
  return M
@@ -0,0 +1,186 @@
1
+ -- Query-only navigation suggestions, never execution bindings or index data.
2
+ local M = { MAX_SCAN = 256, MAX_RESULTS = 8, MAX_SITES = 4, MAX_FILES = 4, MAX_BYTES = 2 * 1048576 }
3
+ local control = require('codeoutline.control')
4
+ local graph = require('codeoutline.graph')
5
+ local callable = { ['function'] = true, prototype = true, method = true, constructor = true }
6
+ local types = { class = true, struct = true, union = true, interface = true, record = true,
7
+ enum = true, typedef = true }
8
+ local values = { variable = true, constant = true, field = true, enum_member = true }
9
+ local reasons = { ['no indexed target'] = true, ['no eligible target'] = true,
10
+ ['unresolved c++ name'] = true, ['name/locality match'] = true,
11
+ ['multiple name/locality candidates'] = true }
12
+ local function normalized(name) return (name:gsub('::', '.'):gsub(':', '.'):gsub('^%.', '')) end
13
+
14
+ function M.allowed(site)
15
+ if not site or site.decl or not site.name or not site.name:match('^[%a_$][%w_$]*$') then return false end
16
+ -- Uncertain preprocessing may hide an ordinary function even when the only
17
+ -- same-name macro is in an unrelated header. Definition suggestions can
18
+ -- inspect ordinary tags after the macro declaration pass found nothing.
19
+ -- This does not establish a call edge or permit guessing macro definitions.
20
+ local macro_unknown = site.kind == 'call' and site.reason == 'unknown or unsupported macro visibility'
21
+ and (site.macro_state == 'uncertain' or site.macro_state == 'limited')
22
+ if not macro_unknown and not reasons[site.reason]
23
+ and not (site.reason or ''):match('^ambiguous name candidates') then return false end
24
+ -- A known binding that failed is a barrier, not permission to guess another
25
+ -- imported value, local, receiver type, package, or constructor.
26
+ if site.evidence ~= nil and site.evidence ~= ''
27
+ and not (type(site.evidence) == 'string' and site.evidence:match('^cpp:name:')) then return false end
28
+ return site.kind == 'call' or site.kind == 'ref' or site.kind == 'symbol' or site.kind == 'new'
29
+ or site.kind == 'member_call' or site.kind == 'member_symbol'
30
+ end
31
+
32
+ function M.find(G, f, site, ctx)
33
+ local info = { truncated = site and site.macro_state == 'limited' or false,
34
+ scanned = 0, reason = 'exact name; binding unconfirmed' }
35
+ if not M.allowed(site) then return {}, info end
36
+ local language = G.files[f].language
37
+ -- These languages have package/project visibility that a name-only search
38
+ -- cannot establish. Their existing resolvers retain authority.
39
+ if language == 'go' or language == 'rust' or language == 'csharp' then return {}, info end
40
+ local configured = (language == 'c' or language == 'cpp')
41
+ and require('codeoutline.cpp_includes').policy(G, f, ctx).configured
42
+ local qualified
43
+ if site.evidence and site.evidence ~= '' then qualified = site.evidence:match('^cpp:name:(.-)%z') end
44
+ qualified = qualified and normalized(qualified)
45
+ if qualified and not qualified:find('.', 1, true) then qualified = nil end
46
+ if site.recv then
47
+ if site.recv == 'self' or site.recv == 'this' or site.recv == 'cls' then return {}, info end
48
+ qualified = qualified or normalized(site.recv .. '.' .. site.name)
49
+ elseif site.kind == 'member_call' or site.kind == 'member_symbol' then return {}, info end
50
+ local list, hits, macro_hits = G.by_name[site.name] or {}, {}, {}
51
+ local source_dir = G.files[f].path:match('^(.*)/') or ''
52
+ for i = 1, math.min(#list, M.MAX_SCAN) do
53
+ if i % 16 == 0 then control.check() end
54
+ info.scanned = i
55
+ local id = list[i]
56
+ local node, g = G.nodes[id], G.node_file[id]
57
+ local rec = G.files[g]
58
+ local parent = node.parent and rec.nodes[node.parent]
59
+ local published = language == 'lua' and require('codeoutline.lua_bindings').exported(node, site.name, G.lua_global_export_tables)
60
+ local kind = site.kind == 'new' and types[node.kind]
61
+ or site.kind ~= 'new' and (callable[node.kind]
62
+ or (site.kind == 'symbol' or site.kind == 'member_symbol') and (types[node.kind] or values[node.kind]))
63
+ -- Unresolved macro visibility can still offer unconfirmed definition
64
+ -- tags for navigation, including when include paths are configured.
65
+ -- An explicit undef remains a barrier.
66
+ if node.kind == 'macro' then
67
+ kind = site.kind == 'call' and (site.macro_state == 'unseen'
68
+ or site.macro_state == 'uncertain' or site.macro_state == 'limited')
69
+ and (g ~= f or site.line and node.line < site.line)
70
+ end
71
+ local name_matches = (node.name == site.name or published) and (normalized(node.qualified) == site.name or published)
72
+ if qualified then
73
+ name_matches = normalized(node.qualified) == qualified
74
+ if not name_matches and language == 'lua' then
75
+ for _, alias in ipairs(require('codeoutline.lua_bindings').aliases(node, G.lua_global_export_tables)) do
76
+ if normalized(alias) == qualified then name_matches = true; break end
77
+ end
78
+ end
79
+ end
80
+ -- No call sites, private locals, nested functions or unrelated class methods.
81
+ -- Even same-file locals require lexical evidence from the strict resolver.
82
+ if kind and name_matches and graph.family(rec.language) == graph.family(language)
83
+ and (not node['local'] or published) and not (node.static and g ~= f)
84
+ and (not parent or parent.kind == 'namespace' or qualified and (types[parent.kind]))
85
+ and (qualified or node.kind ~= 'method' and node.kind ~= 'constructor') then
86
+ local score = g == f and 100 or (rec.path:match('^(.*)/') or '') == source_dir and 20 or 0
87
+ if node.kind ~= 'prototype' and not node.decl then score = score + 1 end
88
+ local bucket = node.kind == 'macro' and macro_hits or hits
89
+ bucket[#bucket + 1] = { id = id, score = score }
90
+ end
91
+ end
92
+ -- Ordinary definitions are more useful than unrelated proxy macros.
93
+ if #hits == 0 then hits = macro_hits
94
+ elseif configured then hits = {} end
95
+ info.truncated = info.truncated or #list > M.MAX_SCAN
96
+ -- Prefer implementations over repeated API declarations. A declaration is
97
+ -- still useful when the project has no matching implementation at all.
98
+ local defined = {}
99
+ for _, hit in ipairs(hits) do
100
+ local node = G.nodes[hit.id]
101
+ if not graph.is_decl(node) then defined[node.qualified] = true end
102
+ end
103
+ local kept = {}
104
+ for _, hit in ipairs(hits) do
105
+ local node = G.nodes[hit.id]
106
+ if not graph.is_decl(node) or not defined[node.qualified] then kept[#kept + 1] = hit end
107
+ end
108
+ hits = kept
109
+ table.sort(hits, function(a, b)
110
+ if a.score ~= b.score then return a.score > b.score end
111
+ return graph.before(G, a.id, b.id)
112
+ end)
113
+ local ids = {}
114
+ for i = 1, math.min(#hits, M.MAX_RESULTS) do ids[i] = hits[i].id end
115
+ info.truncated = info.truncated or #hits > M.MAX_RESULTS
116
+ return ids, info
117
+ end
118
+
119
+ -- Candidates for failures already encountered by an explore query. Reuse its
120
+ -- binding/macro context; never broaden graph traversal to hunt for failures.
121
+ function M.suggest(G, report, ctx)
122
+ local result = { entries = {}, truncated = report and report.truncated or false,
123
+ stats = { sites = 0, scanned = 0, files = 0, bytes = 0 } }
124
+ local files, macro_ctx = {}, nil
125
+ for _, entry in ipairs(report and report.entries or {}) do
126
+ if entry.reference and entry.reason and not entry.target then
127
+ local f = G.node_file[entry.source]
128
+ local refs = G.files[f].refs
129
+ local site = { name = entry.call, kind = refs.kind[entry.reference], recv = refs.recv[entry.reference],
130
+ evidence = entry.binding, reason = entry.reason, macro_state = entry.macro_state, line = entry.line }
131
+ local macro = entry.reason == 'unknown or unsupported macro visibility'
132
+ and (G.files[f].language == 'c' or G.files[f].language == 'cpp')
133
+ if macro or M.allowed(site) then
134
+ if result.stats.sites >= M.MAX_SITES then result.truncated = true; break end
135
+ result.stats.sites = result.stats.sites + 1
136
+ local ids, info
137
+ if macro then
138
+ -- A whole-function graph query may already have exhausted
139
+ -- its macro budget. Suggestions get a separate bounded
140
+ -- pass while sharing the existing source/binding caches.
141
+ if not macro_ctx then
142
+ macro_ctx = {}; for k, v in pairs(ctx) do macro_ctx[k] = v end
143
+ macro_ctx.cpp_macro_context = nil
144
+ end
145
+ local _, sites = require('codeoutline.cpp_macros').resolve(G, f, site.name, entry.line, macro_ctx, true)
146
+ ids = sites or {}
147
+ info = { reason = 'possible macro declaration; binding unconfirmed',
148
+ truncated = macro_ctx.cpp_macro_context and macro_ctx.cpp_macro_context.incomplete or false, scanned = 0 }
149
+ if #ids == 0 then
150
+ local truncated = info.truncated
151
+ ids, info = M.find(G, f, site, ctx)
152
+ info.truncated = info.truncated or truncated
153
+ end
154
+ else ids, info = M.find(G, f, site, ctx) end
155
+ result.stats.scanned = result.stats.scanned + info.scanned
156
+ result.truncated = result.truncated or info.truncated or #ids > M.MAX_RESULTS
157
+ local group = { source = entry.source, path = G.files[f].path, line = entry.line, call = entry.call,
158
+ resolution_reason = entry.reason, status = 'unconfirmed', candidates = {} }
159
+ for i = 1, math.min(#ids, M.MAX_RESULTS) do
160
+ control.check()
161
+ local id = ids[i]
162
+ local g, node = G.node_file[id], G.nodes[id]
163
+ local rec = G.files[g]
164
+ local size = rec.size or 0
165
+ local accepted = files[g]
166
+ if not accepted then
167
+ if result.stats.files < M.MAX_FILES and size <= 1048576 and result.stats.bytes + size <= M.MAX_BYTES then
168
+ files[g], accepted = true, true
169
+ result.stats.files, result.stats.bytes = result.stats.files + 1, result.stats.bytes + size
170
+ else result.truncated = true end
171
+ end
172
+ if accepted then
173
+ group.candidates[#group.candidates + 1] = { id = id, path = rec.path, line = node.line,
174
+ name = node.name, qualified = node.qualified, kind = node.kind,
175
+ status = 'unconfirmed', reason = info.reason }
176
+ end
177
+ end
178
+ if #group.candidates > 0 then result.entries[#result.entries + 1] = group end
179
+ end
180
+ end
181
+ end
182
+ if macro_ctx and macro_ctx.cpp_macro_context then result.stats.macros = macro_ctx.cpp_macro_context.stats end
183
+ return result
184
+ end
185
+
186
+ return M
@@ -3,7 +3,7 @@
3
3
  local M = {}
4
4
  local control = require('codeoutline.control')
5
5
  local member = { ['.'] = true, [':'] = true, ['::'] = true, ['->'] = true }
6
- local supported = { lua = true, javascript = true, typescript = true, python = true, c = true, cpp = true }
6
+ local supported = { lua = true, javascript = true, typescript = true, arkts = true, python = true, c = true, cpp = true }
7
7
  local callable = { ['function'] = true, method = true, constructor = true }
8
8
  local statements = { ['local'] = true, ['function'] = true, ['end'] = true, ['return'] = true,
9
9
  ['if'] = true, ['else'] = true, ['elseif'] = true, ['until'] = true, ['for'] = true,
@@ -90,7 +90,7 @@ end
90
90
  -- decide whether an import can actually be used at a query site.
91
91
  local function imports(r, T)
92
92
  local result = {}
93
- if r.language ~= 'lua' and r.language ~= 'javascript' and r.language ~= 'typescript'
93
+ if r.language ~= 'lua' and r.language ~= 'javascript' and r.language ~= 'typescript' and r.language ~= 'arkts'
94
94
  and r.language ~= 'python' then return result end
95
95
  local function add(local_name, path, imported, token)
96
96
  result[#result + 1] = { name = local_name, path = path, imported = imported, token = token }
@@ -105,7 +105,7 @@ local function imports(r, T)
105
105
  local path = quoted(T, i + 4, 'lua') or quoted(T, i + 5, 'lua')
106
106
  add(T:text(i + 1), path, '*', i + 1)
107
107
  result[#result].loader = T:text(i + 3)
108
- elseif (r.language == 'javascript' or r.language == 'typescript') and s == 'import'
108
+ elseif (r.language == 'javascript' or r.language == 'typescript' or r.language == 'arkts') and s == 'import'
109
109
  and T:text(i + 1) ~= '(' then
110
110
  local j, entries = i + 1, {}
111
111
  if T.k[j] == 'id' then entries[#entries + 1] = { T:text(j), 'default', j }; j = j + 1 end
@@ -219,7 +219,7 @@ end
219
219
  function M.prepare(r, T)
220
220
  if not supported[r.language] then return function(v) return v end end
221
221
  local lua, python = r.language == 'lua', r.language == 'python'
222
- local js = r.language == 'javascript' or r.language == 'typescript'
222
+ local js = r.language == 'javascript' or r.language == 'typescript' or r.language == 'arkts'
223
223
  local scopes, ends, stack = {}, { [0] = T.n }, {}
224
224
  local opens = { ['function'] = true, ['if'] = true, ['do'] = true, ['repeat'] = true }
225
225
  for i = 1, T.n do
@@ -468,7 +468,12 @@ function M.prepare(r, T)
468
468
  end
469
469
  return expand(target, b.token - 1, depth + 1)
470
470
  end
471
- return function(v, at) return expand(v, at, 0) end
471
+ -- Query collectors can identify an exact local object without pretending
472
+ -- its initializer is a function/literal alias. Do not expose binding tables.
473
+ return function(v, at) return expand(v, at, 0) end, function(n, at)
474
+ local b = binding(n, at)
475
+ if b and not b.invalid and b.token <= at then return b.token, b.scope, b.finish end
476
+ end
472
477
  end
473
478
 
474
479
  return M