@codua/codeoutline-win32-x64 0.2.6 → 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 (72) 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 +275 -28
  22. package/scripts/codeoutline/definition_candidates.lua +180 -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 +171 -0
  27. package/scripts/codeoutline/function_values.lua +69 -0
  28. package/scripts/codeoutline/go_methods.lua +931 -0
  29. package/scripts/codeoutline/go_modules.lua +329 -0
  30. package/scripts/codeoutline/graph.lua +322 -67
  31. package/scripts/codeoutline/implementations.lua +403 -0
  32. package/scripts/codeoutline/index.lua +161 -28
  33. package/scripts/codeoutline/index_worker.lua +11 -4
  34. package/scripts/codeoutline/indirect.lua +4 -2
  35. package/scripts/codeoutline/js_evidence.lua +2 -1
  36. package/scripts/codeoutline/js_resolution.lua +40 -12
  37. package/scripts/codeoutline/js_workspace.lua +325 -0
  38. package/scripts/codeoutline/lang/c.lua +15 -2
  39. package/scripts/codeoutline/lang/cpp.lua +7 -4
  40. package/scripts/codeoutline/lang/csharp.lua +1 -1
  41. package/scripts/codeoutline/lang/js.lua +56 -20
  42. package/scripts/codeoutline/lang/rust.lua +9 -1
  43. package/scripts/codeoutline/language_detect.lua +100 -0
  44. package/scripts/codeoutline/lsp.lua +173 -23
  45. package/scripts/codeoutline/lua_bindings.lua +151 -47
  46. package/scripts/codeoutline/lua_callback_loops.lua +210 -0
  47. package/scripts/codeoutline/main.lua +32 -7
  48. package/scripts/codeoutline/mcp.lua +52 -9
  49. package/scripts/codeoutline/navigation.lua +284 -64
  50. package/scripts/codeoutline/on_demand.lua +93 -0
  51. package/scripts/codeoutline/ordinary_bindings.lua +210 -34
  52. package/scripts/codeoutline/parse.lua +18 -2
  53. package/scripts/codeoutline/parse_pool.lua +1 -1
  54. package/scripts/codeoutline/parse_worker.lua +1 -1
  55. package/scripts/codeoutline/python_bindings.lua +2 -2
  56. package/scripts/codeoutline/query_filters.lua +65 -0
  57. package/scripts/codeoutline/query_report.lua +56 -19
  58. package/scripts/codeoutline/resolution.lua +23 -0
  59. package/scripts/codeoutline/rust_packages.lua +203 -0
  60. package/scripts/codeoutline/rust_resolution.lua +301 -0
  61. package/scripts/codeoutline/search_ranking.lua +70 -0
  62. package/scripts/codeoutline/service.lua +47 -7
  63. package/scripts/codeoutline/shared_events.lua +369 -0
  64. package/scripts/codeoutline/static_dispatch.lua +46 -11
  65. package/scripts/codeoutline/text.lua +3 -2
  66. package/scripts/codeoutline/ts_implementations.lua +81 -0
  67. package/scripts/codeoutline/type_bases.lua +61 -0
  68. package/scripts/codeoutline/type_hierarchy.lua +324 -0
  69. package/scripts/codeoutline/type_references.lua +290 -0
  70. package/scripts/codeoutline/type_uses.lua +260 -0
  71. package/scripts/codeoutline/update_sequence.lua +1 -1
  72. 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,47 +122,121 @@ 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 = 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 found = true; add(ids, follow(alias, g, depth)) end
135
196
  end
136
197
  end
137
198
  if not matched then found = true end -- unsupported alias is a barrier
138
199
  else
139
200
  found = true
140
- if accept[n.kind] then add({ id }) end
201
+ add(ids, { id })
202
+ end
203
+ end
204
+ end
205
+ -- A visible class declaration cannot be changed by an alias elsewhere.
206
+ -- Class-scope using declarations can only occur in that class's source;
207
+ -- do not fully inspect every transitive header to look up A::member.
208
+ local class_only = #ids > 0
209
+ for _, id in ipairs(ids) do if not classes[G.nodes[id].kind] then class_only = false; break end end
210
+ if class_only then return ids, true end
211
+ local alias_files, seen_files = {}, {}
212
+ local owner = qualified:match('^(.*)::[^:]+$')
213
+ while owner and #alias_files == 0 do
214
+ for _, id in ipairs(G.by_name[owner:match('([^:]+)$')] or {}) do
215
+ local n, g = G.nodes[id], G.node_file[id]
216
+ if classes[n.kind] and n.qualified == owner and visible(file, g) and not seen_files[g] then
217
+ seen_files[g] = true; alias_files[#alias_files + 1] = g
218
+ end
219
+ end
220
+ owner = owner:match('^(.*)::[^:]+$')
221
+ end
222
+ if #alias_files == 0 then alias_files = files(file) end
223
+ for _, g in ipairs(alias_files) do
224
+ control.check()
225
+ for _, alias in ipairs(aliases(g)) do
226
+ if alias.kind and alias.kind ~= 'directive' and not alias.local_alias
227
+ and (alias.scope ~= '' and alias.scope .. '::' or '') .. alias.name == qualified
228
+ and (g ~= file or not at or alias.at <= at) then
229
+ found = true
230
+ if alias.kind == 'forward' then
231
+ -- Preserve completion's existing incomplete-type aid,
232
+ -- but require an explicit forward declaration first.
233
+ if opts.forward then
234
+ for _, id in ipairs(G.by_name[tail] or {}) do
235
+ local n = G.nodes[id]
236
+ if n.qualified == qualified and classes[n.kind] then add(ids, { id }) end
237
+ end
238
+ end
239
+ else add(ids, follow(alias, g, depth)) end
141
240
  end
142
241
  end
143
242
  end
@@ -153,17 +252,18 @@ function M.resolve(G, f, written, opts)
153
252
  if known then
154
253
  local result = {}
155
254
  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
255
+ local node = G.nodes[owner]
256
+ local more
257
+ if node.kind == 'namespace' then more = resolve(file, suffix, node.qualified, at, depth + 1, true)
258
+ else more = named(file, node.qualified .. '::' .. suffix, nil, depth + 1) end
259
+ add(result, more)
158
260
  end
159
- -- Namespace nodes are not class results, so do not stop lexical
160
- -- lookup merely because a namespace prefix exists.
161
261
  if #owners > 0 then return result, true end
162
262
  end
163
263
  end
164
264
  return {}, false
165
265
  end
166
- resolve = function(file, name, scope, at, depth)
266
+ resolve = function(file, name, scope, at, depth, only_scope)
167
267
  control.check()
168
268
  if depth > 8 then return {}, true end
169
269
  if name:sub(1, 2) == '::' then return qualified(file, name:sub(3), at, depth) end
@@ -172,7 +272,7 @@ function M.resolve(G, f, written, opts)
172
272
  if at then
173
273
  local best
174
274
  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
275
+ 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
276
  and (not best or alias.first > best.first or alias.first == best.first and alias.at > best.at) then best = alias end
177
277
  end
178
278
  if best then
@@ -181,7 +281,7 @@ function M.resolve(G, f, written, opts)
181
281
  local result = {}
182
282
  for _, id in ipairs(ids) do
183
283
  local more = qualified(file, G.nodes[id].qualified .. '::' .. tail, nil, depth + 1)
184
- for _, target in ipairs(more) do result[#result + 1] = target end
284
+ add(result, more)
185
285
  end
186
286
  return result, true
187
287
  end
@@ -197,13 +297,160 @@ function M.resolve(G, f, written, opts)
197
297
  found = declared
198
298
  end
199
299
  end
300
+ -- using-directives contribute candidates only in their lexical
301
+ -- scope. Imported headers contribute namespace/file scope, never locals.
302
+ for _, g in ipairs(directive_files(file)) do
303
+ for _, alias in ipairs(aliases(g)) do
304
+ if alias.kind == 'directive' and alias.scope == (scope or '')
305
+ and not (g == f and alias.at == opts.exclude)
306
+ and (not alias.local_alias or g == file and at and alias.first <= at and at <= alias.last)
307
+ and (g ~= file or not at or alias.at <= at) then
308
+ local namespaces = follow(alias, g, depth)
309
+ for _, id in ipairs(namespaces) do
310
+ local q = G.nodes[id].qualified
311
+ local key = file .. ':' .. q .. ':' .. name
312
+ if not seen[key] then
313
+ seen[key] = true
314
+ local more, known = resolve(file, '::' .. q .. '::' .. name, '', at, depth + 1)
315
+ seen[key] = nil
316
+ if known then found = true; add(ids, more) end
317
+ end
318
+ end
319
+ end
320
+ end
321
+ end
200
322
  if found then return ids, true end
201
- if not scope or scope == '' then break end
323
+ if only_scope or not scope or scope == '' then break end
202
324
  scope = scope:match('^(.*)::[^:]+$') or ''
203
325
  end
204
326
  return {}, false
205
327
  end
206
- return resolve(f, written, opts.scope, opts.at, 0)
328
+ local ids, known = resolve(f, written, opts.scope, opts.at, 0)
329
+ local result, qualified = {}, nil
330
+ for _, id in ipairs(ids) do
331
+ local n = G.nodes[id]
332
+ -- Distinct qualified names are an ambiguity, not a locality contest.
333
+ if qualified and qualified ~= n.qualified then return {}, true end
334
+ qualified = n.qualified
335
+ if accept[n.kind] then result[#result + 1] = id end
336
+ end
337
+ if opts.definitions and #result > 0 then
338
+ local _, paired = require('codeoutline.graph').visible_dependencies(G, f, ctx)
339
+ local definitions = {}
340
+ for _, id in ipairs(G.by_name[G.nodes[result[1]].name] or {}) do
341
+ local n, g = G.nodes[id], G.node_file[id]
342
+ if n.qualified == qualified and accept[n.kind] and not n.decl and n.kind ~= 'prototype'
343
+ and (g == f or visible(f, g) or paired[g]) and not (n.static and g ~= f and paired[g]) then
344
+ definitions[#definitions + 1] = id
345
+ end
346
+ end
347
+ if #definitions > 0 then result = definitions end
348
+ end
349
+ return result, known
350
+ end
351
+
352
+ -- Class-outside members belong to the class visible in their own source file,
353
+ -- not every class elsewhere with the same spelling.
354
+ function M.owner(G, f, node, ctx)
355
+ local parent = node.parent and G.id_of[f][node.parent]
356
+ if parent and classes[G.nodes[parent].kind] then return parent end
357
+ local prefix = node.qualified:match('^(.*)::[^:]+$')
358
+ if not prefix then return nil end
359
+ local ids = M.resolve(G, f, prefix, { context = ctx, at = node.start_byte, undecorated = true })
360
+ return #ids == 1 and ids[1] or nil
361
+ end
362
+
363
+ -- Namespace members are restricted to declarations visible to the requester.
364
+ -- Overlay nodes replace the resident by_owner entries just as by_name does.
365
+ function M.namespace_members(G, f, namespace, ctx, at, seen, depth, expired)
366
+ seen, depth = seen or {}, depth or 0
367
+ if seen[namespace] or depth > 8 then return {} end
368
+ seen[namespace] = true
369
+ local deps = require('codeoutline.graph').visible_dependencies(G, f, ctx)
370
+ local result = {}
371
+ local function add(id)
372
+ local n, g = G.nodes[id], G.node_file[id]
373
+ if (g == f or deps[g]) and n.qualified:match('^(.*)::[^:]+$') == namespace then
374
+ result[#result + 1] = { name = n.name, kind = n.kind, node = n, file = g }
375
+ end
376
+ end
377
+ for _, id in ipairs(G.by_owner[namespace] or {}) do
378
+ if not (G.drafts and G.drafts[G.node_file[id]]) then add(id) end
379
+ end
380
+ for g in pairs(G.drafts or {}) do for _, id in ipairs(G.id_of[g]) do add(id) end end
381
+ local files = { f }; for g in pairs(deps) do if G.files[g].cpp_imports then files[#files + 1] = g end end
382
+ table.sort(files, function(a, b) return G.files[a].path < G.files[b].path end)
383
+ local any = setmetatable({}, { __index = function() return true end })
384
+ for _, g in ipairs(files) do
385
+ control.check()
386
+ if expired and expired() then return result end
387
+ for _, alias in ipairs(M.aliases(G, g, ctx)) do
388
+ if expired and expired() then return result end
389
+ if not alias.local_alias and alias.scope == namespace and (g ~= f or not at or alias.at <= at) then
390
+ if alias.kind == 'directive' and alias.target then
391
+ local ids = M.resolve(G, g, alias.target,
392
+ { scope = alias.scope, at = alias.at, exclude = alias.at, context = ctx, accept = { namespace = true } })
393
+ for _, id in ipairs(ids) do
394
+ for _, entry in ipairs(M.namespace_members(G, f, G.nodes[id].qualified, ctx, at, seen, depth + 1, expired)) do
395
+ result[#result + 1] = entry
396
+ end
397
+ end
398
+ elseif alias.kind ~= 'forward' then
399
+ local ids = M.resolve(G, f, '::' .. namespace .. '::' .. alias.name, { context = ctx, at = at, accept = any })
400
+ for _, id in ipairs(ids) do
401
+ local n = G.nodes[id]
402
+ result[#result + 1] = { name = alias.name, kind = n.kind, node = n, file = G.node_file[id] }
403
+ end
404
+ end
405
+ end
406
+ end
407
+ end
408
+ return result
409
+ end
410
+
411
+ function M.imported_members(G, f, scope, at, ctx, expired, prefix)
412
+ local deps = require('codeoutline.graph').visible_dependencies(G, f, ctx)
413
+ local result, names = {}, {}
414
+ local any = setmetatable({}, { __index = function() return true end })
415
+ local function active(alias, file)
416
+ if file == f and alias.at > at then return false end
417
+ if alias.local_alias then return file == f and alias.first <= at and at <= alias.last end
418
+ return alias.scope == '' or scope == alias.scope or (scope or ''):sub(1, #alias.scope + 2) == alias.scope .. '::'
419
+ end
420
+ local files = { f }; for g in pairs(deps) do if G.files[g].cpp_imports then files[#files + 1] = g end end
421
+ table.sort(files, function(a, b) return G.files[a].path < G.files[b].path end)
422
+ for _, g in ipairs(files) do
423
+ control.check()
424
+ if expired and expired() then break end
425
+ for _, alias in ipairs(M.aliases(G, g, ctx)) do
426
+ if expired and expired() then break end
427
+ if active(alias, g) then
428
+ if alias.kind == 'directive' and alias.target then
429
+ local ids = M.resolve(G, g, alias.target,
430
+ { scope = alias.scope, at = alias.at, exclude = alias.at, context = ctx, accept = { namespace = true } })
431
+ for _, id in ipairs(ids) do
432
+ for _, entry in ipairs(M.namespace_members(G, f, G.nodes[id].qualified, ctx, at, nil, nil, expired)) do names[entry.name] = true end
433
+ end
434
+ else names[alias.name] = true end
435
+ end
436
+ end
437
+ end
438
+ local ordered, rest = {}, {}
439
+ for name in pairs(names) do
440
+ local bucket = prefix and name:sub(1, #prefix):lower() == prefix and ordered or rest
441
+ bucket[#bucket + 1] = name
442
+ end
443
+ table.sort(ordered); table.sort(rest)
444
+ for _, name in ipairs(rest) do ordered[#ordered + 1] = name end
445
+ for _, name in ipairs(ordered) do
446
+ if expired and expired() then break end
447
+ local ids = M.resolve(G, f, name, { scope = scope, at = at, context = ctx, accept = any })
448
+ for _, id in ipairs(ids) do
449
+ local n = G.nodes[id]
450
+ result[#result + 1] = { name = name, kind = n.kind, node = n, file = G.node_file[id] }
451
+ end
452
+ end
453
+ return result
207
454
  end
208
455
 
209
456
  return M
@@ -0,0 +1,180 @@
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
+ if (language == 'c' or language == 'cpp')
41
+ and require('codeoutline.cpp_includes').policy(G, f, ctx).configured then return {}, info end
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 = 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
+ -- An absent include context permits inspecting macro declarations.
64
+ -- An explicit undef, uncertain expansion, or budget failure does not.
65
+ if node.kind == 'macro' then
66
+ kind = site.kind == 'call' and site.macro_state == 'unseen'
67
+ and (g ~= f or site.line and node.line < site.line)
68
+ end
69
+ local name_matches = (node.name == site.name or published) and (normalized(node.qualified) == site.name or published)
70
+ if qualified then
71
+ name_matches = normalized(node.qualified) == qualified
72
+ if not name_matches and language == 'lua' then
73
+ for _, alias in ipairs(require('codeoutline.lua_bindings').aliases(node, G.lua_global_export_tables)) do
74
+ if normalized(alias) == qualified then name_matches = true; break end
75
+ end
76
+ end
77
+ end
78
+ -- No call sites, private locals, nested functions or unrelated class methods.
79
+ -- Even same-file locals require lexical evidence from the strict resolver.
80
+ if kind and name_matches and graph.family(rec.language) == graph.family(language)
81
+ and (not node['local'] or published) and not (node.static and g ~= f)
82
+ and (not parent or parent.kind == 'namespace' or qualified and (types[parent.kind]))
83
+ and (qualified or node.kind ~= 'method' and node.kind ~= 'constructor') then
84
+ local score = g == f and 100 or (rec.path:match('^(.*)/') or '') == source_dir and 20 or 0
85
+ if node.kind ~= 'prototype' and not node.decl then score = score + 1 end
86
+ hits[#hits + 1] = { id = id, score = score }
87
+ end
88
+ end
89
+ info.truncated = info.truncated or #list > M.MAX_SCAN
90
+ -- Prefer implementations over repeated API declarations. A declaration is
91
+ -- still useful when the project has no matching implementation at all.
92
+ local defined = {}
93
+ for _, hit in ipairs(hits) do
94
+ local node = G.nodes[hit.id]
95
+ if not graph.is_decl(node) then defined[node.qualified] = true end
96
+ end
97
+ local kept = {}
98
+ for _, hit in ipairs(hits) do
99
+ local node = G.nodes[hit.id]
100
+ if not graph.is_decl(node) or not defined[node.qualified] then kept[#kept + 1] = hit end
101
+ end
102
+ hits = kept
103
+ table.sort(hits, function(a, b)
104
+ if a.score ~= b.score then return a.score > b.score end
105
+ return graph.before(G, a.id, b.id)
106
+ end)
107
+ local ids = {}
108
+ for i = 1, math.min(#hits, M.MAX_RESULTS) do ids[i] = hits[i].id end
109
+ info.truncated = info.truncated or #hits > M.MAX_RESULTS
110
+ return ids, info
111
+ end
112
+
113
+ -- Candidates for failures already encountered by an explore query. Reuse its
114
+ -- binding/macro context; never broaden graph traversal to hunt for failures.
115
+ function M.suggest(G, report, ctx)
116
+ local result = { entries = {}, truncated = report and report.truncated or false,
117
+ stats = { sites = 0, scanned = 0, files = 0, bytes = 0 } }
118
+ local files, macro_ctx = {}, nil
119
+ for _, entry in ipairs(report and report.entries or {}) do
120
+ if entry.reference and entry.reason and not entry.target then
121
+ local f = G.node_file[entry.source]
122
+ local refs = G.files[f].refs
123
+ local site = { name = entry.call, kind = refs.kind[entry.reference], recv = refs.recv[entry.reference],
124
+ evidence = entry.binding, reason = entry.reason, macro_state = entry.macro_state, line = entry.line }
125
+ local macro = entry.reason == 'unknown or unsupported macro visibility'
126
+ and (G.files[f].language == 'c' or G.files[f].language == 'cpp')
127
+ if macro or M.allowed(site) then
128
+ if result.stats.sites >= M.MAX_SITES then result.truncated = true; break end
129
+ result.stats.sites = result.stats.sites + 1
130
+ local ids, info
131
+ if macro then
132
+ -- A whole-function graph query may already have exhausted
133
+ -- its macro budget. Suggestions get a separate bounded
134
+ -- pass while sharing the existing source/binding caches.
135
+ if not macro_ctx then
136
+ macro_ctx = {}; for k, v in pairs(ctx) do macro_ctx[k] = v end
137
+ macro_ctx.cpp_macro_context = nil
138
+ end
139
+ local _, sites = require('codeoutline.cpp_macros').resolve(G, f, site.name, entry.line, macro_ctx, true)
140
+ ids = sites or {}
141
+ info = { reason = 'possible macro declaration; binding unconfirmed',
142
+ truncated = macro_ctx.cpp_macro_context and macro_ctx.cpp_macro_context.incomplete or false, scanned = 0 }
143
+ if #ids == 0 then
144
+ local truncated = info.truncated
145
+ ids, info = M.find(G, f, site, ctx)
146
+ info.truncated = info.truncated or truncated
147
+ end
148
+ else ids, info = M.find(G, f, site, ctx) end
149
+ result.stats.scanned = result.stats.scanned + info.scanned
150
+ result.truncated = result.truncated or info.truncated or #ids > M.MAX_RESULTS
151
+ local group = { source = entry.source, path = G.files[f].path, line = entry.line, call = entry.call,
152
+ resolution_reason = entry.reason, status = 'unconfirmed', candidates = {} }
153
+ for i = 1, math.min(#ids, M.MAX_RESULTS) do
154
+ control.check()
155
+ local id = ids[i]
156
+ local g, node = G.node_file[id], G.nodes[id]
157
+ local rec = G.files[g]
158
+ local size = rec.size or 0
159
+ local accepted = files[g]
160
+ if not accepted then
161
+ if result.stats.files < M.MAX_FILES and size <= 1048576 and result.stats.bytes + size <= M.MAX_BYTES then
162
+ files[g], accepted = true, true
163
+ result.stats.files, result.stats.bytes = result.stats.files + 1, result.stats.bytes + size
164
+ else result.truncated = true end
165
+ end
166
+ if accepted then
167
+ group.candidates[#group.candidates + 1] = { id = id, path = rec.path, line = node.line,
168
+ name = node.name, qualified = node.qualified, kind = node.kind,
169
+ status = 'unconfirmed', reason = info.reason }
170
+ end
171
+ end
172
+ if #group.candidates > 0 then result.entries[#result.entries + 1] = group end
173
+ end
174
+ end
175
+ end
176
+ if macro_ctx and macro_ctx.cpp_macro_context then result.stats.macros = macro_ctx.cpp_macro_context.stats end
177
+ return result
178
+ end
179
+
180
+ 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