@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
@@ -0,0 +1,456 @@
1
+ -- Shared C++ name lookup. Alias/import bodies and lexical ranges are query-only.
2
+ local M = {}
3
+ local control = require('codeoutline.control')
4
+ local classes = { class = true, struct = true, union = 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 }
7
+ local callable = { ['function'] = true, method = true, constructor = true, destructor = true }
8
+ local qualifiers = { const = true, volatile = true, struct = true, class = true, union = true }
9
+
10
+ -- Only named types with cv/pointer/reference decoration. Never erase template
11
+ -- arguments or dependent expressions and then guess an unrelated class.
12
+ function M.normalize(text)
13
+ if type(text) ~= 'string' then return nil end
14
+ text = text:gsub('^%s+', ''):gsub('%s+$', '')
15
+ for _ = 1, 8 do
16
+ local word, rest = text:match('^(%w+)%s+(.+)$')
17
+ if qualifiers[word] then text = rest else break end
18
+ end
19
+ for _ = 1, 8 do
20
+ local before, word = text:match('^(.-)%s+(%w+)$')
21
+ if word == 'const' or word == 'volatile' then text = before
22
+ else
23
+ local stripped = text:gsub('[%*&%s]+$', '')
24
+ if stripped == text then break end
25
+ text = stripped
26
+ end
27
+ end
28
+ text = text:gsub('%s*::%s*', '::')
29
+ local rest = text:gsub('^::', '')
30
+ local parts = {}
31
+ for part in rest:gmatch('[^:]+') do
32
+ if not part:match('^[%a_][%w_]*$') then return nil end
33
+ parts[#parts + 1] = part
34
+ end
35
+ if #parts == 0 or table.concat(parts, '::') ~= rest then return nil end
36
+ if rest == 'auto' or rest == 'decltype' then return nil end
37
+ return text
38
+ end
39
+
40
+ function M.collect(r, T)
41
+ if r.language ~= 'cpp' then return end
42
+ local result, scopes, stack = {}, {}, {}
43
+ for i = 1, T.n do
44
+ if T:text(i) == '{' and T.m[i] then stack[#stack + 1] = i end
45
+ scopes[i] = stack[#stack] or 0
46
+ if stack[#stack] and T.m[stack[#stack]] == i then stack[#stack] = nil end
47
+ end
48
+ for i = 1, T.n do
49
+ if i % 4096 == 0 then control.check() end
50
+ local word = T:text(i)
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
54
+ local stop = i + 1
55
+ while stop <= T.n and T:text(stop) ~= ';' do
56
+ if T.m[stop] and T.m[stop] > stop then stop = T.m[stop] end
57
+ stop = stop + 1
58
+ end
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'
67
+ elseif T.k[stop - 1] == 'id' then name, first, last = stop - 1, i + 1, stop - 2 end
68
+ -- Unsupported function-pointer typedefs still introduce a name barrier.
69
+ if not name then
70
+ for j = i + 1, stop - 1 do
71
+ if T:text(j) == '*' and T.k[j + 1] == 'id' and T:text(j + 2) == ')' then name = j + 1; break end
72
+ end
73
+ end
74
+ if name and stop <= T.n then
75
+ local owner, templated
76
+ for _, n in ipairs(r.nodes) do
77
+ if (classes[n.kind] or n.kind == 'namespace' or callable[n.kind]) and n.ti < i and i < n.tj then
78
+ if not owner or n.ti > owner.ti then owner = n end
79
+ if T:text(n.ti) == 'template' then templated = true end
80
+ end
81
+ end
82
+ for j = i - 1, 1, -1 do
83
+ local s = T:text(j)
84
+ if s == ';' or s == '{' or s == '}' then break end
85
+ if s == 'template' then templated = true; break end
86
+ end
87
+ local scope = owner and owner.qualified or ''
88
+ local local_alias = owner and callable[owner.kind] or false
89
+ if local_alias then scope = scope:match('^(.*)::[^:]+$') or '' end
90
+ local text = first and T.src:sub(T.s[first], T.e[last])
91
+ local open = scopes[i]
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,
96
+ scope = scope, local_alias = local_alias, at = T.s[name] - 1,
97
+ first = open > 0 and T.s[open] - 1 or 0,
98
+ last = open > 0 and T.e[T.m[open]] or #T.src }
99
+ end
100
+ end
101
+ end
102
+ if #result > 0 then r.cpp_aliases = result end
103
+ end
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
+
118
+ -- opts.at is a byte position in file f, normally the receiver declaration.
119
+ -- The boolean result distinguishes an unknown name from a known but unresolved
120
+ -- declaration, so completion cannot revive a hidden outer type on failure.
121
+ function M.resolve(G, f, written, opts)
122
+ opts = opts or {}
123
+ written = M.normalize(written)
124
+ if not written then return {}, true end
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
131
+ local function visible(file, target)
132
+ if file == target then return true end
133
+ return dependencies(file)[target]
134
+ end
135
+ local function aliases(file)
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
165
+ end
166
+ local seen = {}
167
+ local resolve
168
+ local function follow(alias, file, depth)
169
+ if opts.undecorated and alias.decorated then return {}, true end
170
+ if not alias.target then return {} end
171
+ local key = file .. ':' .. alias.at
172
+ if seen[key] or depth >= 8 then return {}, true end
173
+ seen[key] = true
174
+ local ids = resolve(file, alias.target, alias.scope, alias.at, depth + 1)
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
181
+ return ids
182
+ end
183
+ local function named(file, qualified, at, depth)
184
+ local tail = qualified:match('([^:]+)$')
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
188
+ local n, g = G.nodes[id], G.node_file[id]
189
+ if n.qualified == qualified and declaring[n.kind] and visible(file, g) then
190
+ if n.kind == 'typedef' then
191
+ local matched = false
192
+ for _, alias in ipairs(aliases(g)) do
193
+ if not alias.kind and not alias.local_alias and (alias.scope ~= '' and alias.scope .. '::' or '') .. alias.name == qualified then
194
+ matched = true
195
+ if g ~= file or not at or alias.at <= at then found = true; add(ids, follow(alias, g, depth)) end
196
+ end
197
+ end
198
+ if not matched then found = true end -- unsupported alias is a barrier
199
+ else
200
+ found = true
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
240
+ end
241
+ end
242
+ end
243
+ return ids, found
244
+ end
245
+ local function qualified(file, name, at, depth)
246
+ local ids, found = named(file, name, at, depth)
247
+ if found then return ids, true end
248
+ -- A class alias may qualify a nested type, e.g. Alias::Inner.
249
+ local prefix, suffix = name:match('^(.*)::([^:]+)$')
250
+ if prefix and depth < 8 then
251
+ local owners, known = qualified(file, prefix, at, depth + 1)
252
+ if known then
253
+ local result = {}
254
+ for _, owner in ipairs(owners) do
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)
260
+ end
261
+ if #owners > 0 then return result, true end
262
+ end
263
+ end
264
+ return {}, false
265
+ end
266
+ resolve = function(file, name, scope, at, depth, only_scope)
267
+ control.check()
268
+ if depth > 8 then return {}, true end
269
+ if name:sub(1, 2) == '::' then return qualified(file, name:sub(3), at, depth) end
270
+ local head, tail = name:match('^([^:]+)::(.*)$')
271
+ head = head or name
272
+ if at then
273
+ local best
274
+ for _, alias in ipairs(aliases(file)) do
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
276
+ and (not best or alias.first > best.first or alias.first == best.first and alias.at > best.at) then best = alias end
277
+ end
278
+ if best then
279
+ local ids = follow(best, file, depth)
280
+ if not tail then return ids, true end
281
+ local result = {}
282
+ for _, id in ipairs(ids) do
283
+ local more = qualified(file, G.nodes[id].qualified .. '::' .. tail, nil, depth + 1)
284
+ add(result, more)
285
+ end
286
+ return result, true
287
+ end
288
+ end
289
+ while true do
290
+ local prefix = scope and scope ~= '' and scope .. '::' or ''
291
+ local ids, found
292
+ if not tail then ids, found = named(file, prefix .. name, at, depth)
293
+ else
294
+ ids, found = qualified(file, prefix .. name, at, depth)
295
+ if not found then
296
+ local _, declared = named(file, prefix .. head, at, depth)
297
+ found = declared
298
+ end
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
322
+ if found then return ids, true end
323
+ if only_scope or not scope or scope == '' then break end
324
+ scope = scope:match('^(.*)::[^:]+$') or ''
325
+ end
326
+ return {}, false
327
+ end
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
454
+ end
455
+
456
+ return M