@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,498 @@
1
+ -- C# using/receiver evidence shared by LSP and graph queries. No compiler execution.
2
+ local M = {}
3
+ local control = require('codeoutline.control')
4
+ local types = { class = true, struct = true, interface = true, record = true, enum = true }
5
+ local callable = { method = true, constructor = true, ['function'] = true, prototype = true }
6
+ local function clean(s) return s and s:gsub('^@', '') end
7
+
8
+ function M.name(text)
9
+ if type(text) ~= 'string' then return nil end
10
+ text = text:gsub('%s+', ''):gsub('@([%a_][%w_]*)', '%1')
11
+ local prefix, rest = text:match('^([%w_]+)::(.*)$')
12
+ rest = rest or text
13
+ local parts = {}
14
+ for part in rest:gmatch('[^.]+') do
15
+ if not part:match('^[%a_][%w_]*$') then return nil end
16
+ parts[#parts + 1] = part
17
+ end
18
+ if #parts == 0 or table.concat(parts, '.') ~= rest then return nil end
19
+ return (prefix and prefix .. '::' or '') .. rest
20
+ end
21
+
22
+ local function token_name(T, first, last)
23
+ if first > last then return nil end
24
+ return M.name(T.src:sub(T.s[first], T.e[last]))
25
+ end
26
+
27
+ function M.collect(r, T)
28
+ r.csharp_usings = r.csharp_usings or {}
29
+ r.csharp_scopes, r.csharp_statics, r.csharp_access, r.has_bindings = {}, {}, {}, true
30
+ r.csharp_parameters = {}
31
+ for index, n in ipairs(r.nodes) do
32
+ if types[n.kind] or n.kind == 'namespace' then
33
+ r.csharp_scopes[#r.csharp_scopes + 1] = { scope = n.qualified, first = T.s[n.ti] - 1, last = T.e[n.tj] }
34
+ end
35
+ local header = (n.sig or ''):match('^(.-)%(') or n.sig or ''
36
+ if header:find('%f[%w]static%f[^%w]') then r.csharp_statics[index] = true end
37
+ local access = header:match('%f[%w](public)%f[^%w]') or header:match('%f[%w](internal)%f[^%w]')
38
+ or header:match('%f[%w](protected)%f[^%w]') or header:match('%f[%w](private)%f[^%w]')
39
+ r.csharp_access[index] = access or (n.parent and r.nodes[n.parent].kind == 'interface' and 'public') or 'private'
40
+ if types[n.kind] or callable[n.kind] then
41
+ for i = n.ti, n.tj do
42
+ local word = T:text(i)
43
+ if word == '(' or word == '{' then break end
44
+ if clean(word) == clean(n.name) and T:text(i + 1) == '<' then
45
+ local j, depth = i + 2, 1
46
+ while j <= n.tj and depth > 0 do
47
+ local s = T:text(j)
48
+ if depth == 1 and T.k[j] == 'id' and (T:text(j - 1) == '<' or T:text(j - 1) == ',') then
49
+ r.csharp_parameters[#r.csharp_parameters + 1] = { name = clean(s), first = T.s[n.ti] - 1, last = T.e[n.tj] }
50
+ end
51
+ if s == '<' then depth = depth + 1 elseif s == '>' then depth = depth - 1 elseif s == '>>' then depth = depth - 2 end
52
+ j = j + 1
53
+ end
54
+ break
55
+ end
56
+ end
57
+ end
58
+ end
59
+ local wanted, scopes, stack = {}, {}, {}
60
+ for _, ref in ipairs(r.refs) do if ref.recv then wanted[clean(ref.recv)] = true end end
61
+ for i = 1, T.n do
62
+ if T:text(i) == '{' and T.m[i] then stack[#stack + 1] = i end
63
+ scopes[i] = stack[#stack] or 0
64
+ if stack[#stack] and T.m[stack[#stack]] == i then stack[#stack] = nil end
65
+ end
66
+ local bindings = {}
67
+ local endings = { [')'] = true, [','] = true, [';'] = true, ['='] = true, ['{'] = true }
68
+ local forbidden = { ['return'] = true, ['new'] = true, ['throw'] = true, ['using'] = true, ['namespace'] = true }
69
+ for i = 2, T.n do
70
+ if i % 4096 == 0 then control.check() end
71
+ local name, prev = clean(T:text(i)), T:text(i - 1)
72
+ if T.k[i] == 'id' and wanted[name] and endings[T:text(i + 1)] and not forbidden[prev]
73
+ and (T.k[i - 1] == 'id' or T.k[i - 1] == 'kw' or prev == '>' or prev == '>>' or prev == ']' or prev == '?') then
74
+ local first = i - 1
75
+ while (T:text(first - 1) == '.' or T:text(first - 1) == '::') and T.k[first - 2] == 'id' do first = first - 2 end
76
+ local ty = token_name(T, first, i - 1)
77
+ if ty == 'var' then
78
+ ty = nil
79
+ if T:text(i + 1) == '=' and T:text(i + 2) == 'new' then
80
+ local last = i + 3
81
+ while T:text(last + 1) == '.' or T:text(last + 1) == '::' do last = last + 2 end
82
+ if T:text(last + 1) == '(' then ty = token_name(T, i + 3, last) end
83
+ end
84
+ end
85
+ local a = scopes[i]
86
+ local b = a > 0 and T.m[a] or T.n
87
+ for _, n in ipairs(r.nodes) do
88
+ if callable[n.kind] and n.ti <= i and i <= n.tj and n.ti > a then a, b = n.ti, n.tj end
89
+ end
90
+ bindings[name] = bindings[name] or {}
91
+ bindings[name][#bindings[name] + 1] = { type = ty or false, token = i, first = a, last = b }
92
+ end
93
+ end
94
+ for _, ref in ipairs(r.refs) do
95
+ local first = ref.tok
96
+ while (T:text(first - 1) == '.' or T:text(first - 1) == '?.' or T:text(first - 1) == '::')
97
+ and (T.k[first - 2] == 'id' or T.k[first - 2] == 'kw') do first = first - 2 end
98
+ if T:text(first - 1) == 'new' then
99
+ ref.binding = 'cs:new:' .. (token_name(T, first, ref.tok) or '?') .. '\0' .. (T.s[first] - 1)
100
+ elseif ref.kind == 'member_call' then
101
+ local root, best = clean(T:text(first))
102
+ for _, b in ipairs(bindings[root] or {}) do
103
+ if b.first <= ref.tok and ref.tok <= b.last and b.token <= ref.tok
104
+ and (not best or b.first > best.first or b.first == best.first and b.token > best.token) then best = b end
105
+ end
106
+ if best then
107
+ ref.binding = best.type and first == ref.tok - 2 and 'cs:type:' .. best.type .. '\0' .. (T.s[best.token] - 1) or 'cs:?'
108
+ elseif root == 'this' or root == 'base' then ref.binding = 'cs:self:' .. root .. '\0' .. (T.s[first] - 1)
109
+ else ref.binding = 'cs:owner:' .. (token_name(T, first, ref.tok - 2) or '?') .. '\0' .. (T.s[first] - 1) end
110
+ elseif ref.kind == 'call' then ref.binding = 'cs:call:\0' .. (T.s[ref.tok] - 1) end
111
+ end
112
+ end
113
+
114
+ local function context(G, ctx)
115
+ ctx = ctx or {}
116
+ if ctx.csharp then return ctx.csharp end
117
+ local C = {}
118
+ ctx.csharp = C
119
+ function C.data(f) return ctx.ordinary and ctx.ordinary.data(f) or G.files[f] end
120
+ local directories, groups = {}, {}
121
+ local function directory_group(dir)
122
+ if directories[dir] ~= nil then return directories[dir] end
123
+ local found
124
+ if G.root then
125
+ local entries, truncated = xutils.list_dir(G.root .. (dir ~= '' and '/' .. dir or ''), 8192, true)
126
+ if truncated then directories[dir] = '!'; return '!' end
127
+ for _, entry in ipairs(entries or {}) do
128
+ if not entry.dir and entry.name:lower():match('%.csproj$') then
129
+ if found then directories[dir] = '!'; return '!' end
130
+ found = dir .. '/' .. entry.name
131
+ end
132
+ end
133
+ end
134
+ if not found and dir ~= '' then found = directory_group(dir:match('^(.*)/[^/]+$') or '') end
135
+ directories[dir] = found or '@workspace'
136
+ return directories[dir]
137
+ end
138
+ function C.group(f)
139
+ if not groups[f] then
140
+ local group = directory_group(G.files[f].path:match('^(.*)/[^/]+$') or '')
141
+ groups[f] = group == '!' and '!file:' .. f or group
142
+ end
143
+ return groups[f]
144
+ end
145
+ function C.same(f, g) return C.group(f) == C.group(g) end
146
+ local files = {}
147
+ for _, f in ipairs(G.file_order) do files[#files + 1] = f end
148
+ for _, f in ipairs(G.new_files or {}) do files[#files + 1] = f end
149
+ local global_candidates, namespaces = {}, {}
150
+ for _, f in ipairs(files) do
151
+ local rec = G.files[f]
152
+ if rec.language == 'csharp' then
153
+ control.check()
154
+ local group = C.group(f)
155
+ namespaces[group] = namespaces[group] or {}
156
+ for _, n in ipairs(rec.nodes) do
157
+ if n.kind == 'namespace' then
158
+ local scope = n.qualified
159
+ while scope and scope ~= '' do
160
+ namespaces[group][scope] = true; scope = scope:match('^(.*)%.[^.]+$')
161
+ end
162
+ end
163
+ end
164
+ local candidate = rec.ordinary_bindings
165
+ for _, imp in ipairs(rec.imports) do if imp.global then candidate = true; break end end
166
+ if candidate then
167
+ global_candidates[group] = global_candidates[group] or {}
168
+ global_candidates[group][#global_candidates[group] + 1] = f
169
+ end
170
+ end
171
+ end
172
+ function C.scope(f, at)
173
+ local scope, first = '', -1
174
+ for _, n in ipairs(C.data(f).csharp_scopes or {}) do
175
+ if n.first <= at and at <= n.last and n.first > first then scope, first = n.scope, n.first end
176
+ end
177
+ return scope
178
+ end
179
+ function C.active(f, at, exclude, no_global)
180
+ local out = {}
181
+ for _, d in ipairs(C.data(f).csharp_usings or {}) do
182
+ if not d.global and d.first <= at and at <= d.last and d.first ~= exclude then out[#out + 1] = { file = f, directive = d } end
183
+ end
184
+ if not no_global then
185
+ for _, g in ipairs(global_candidates[C.group(f)] or {}) do
186
+ for _, d in ipairs(C.data(g).csharp_usings or {}) do
187
+ if d.global and d.scope == '' then out[#out + 1] = { file = g, directive = d } end
188
+ end
189
+ end
190
+ end
191
+ return out
192
+ end
193
+ function C.exact(f, name)
194
+ local ids = {}
195
+ for _, id in ipairs(G.by_name[name:match('([^.]+)$')] or {}) do
196
+ local n, g = G.nodes[id], G.node_file[id]
197
+ if n.qualified == name and types[n.kind] and G.files[g].language == 'csharp' and C.same(f, g) then ids[#ids + 1] = id end
198
+ end
199
+ return ids
200
+ end
201
+ function C.namespace(f, name)
202
+ return namespaces[C.group(f)] and namespaces[C.group(f)][name] or false
203
+ end
204
+ function C.namespace_children(f, namespace)
205
+ local result = {}
206
+ local prefix = namespace ~= '' and namespace .. '.' or ''
207
+ for name in pairs(namespaces[C.group(f)] or {}) do
208
+ if name:sub(1, #prefix) == prefix then
209
+ local suffix = name:sub(#prefix + 1)
210
+ if not suffix:find('.', 1, true) and suffix ~= '' then result[#result + 1] = suffix end
211
+ end
212
+ end
213
+ table.sort(result)
214
+ return result
215
+ end
216
+ return C
217
+ end
218
+
219
+ -- Result: type ids, resolved namespace (if any), and whether a binding was known.
220
+ function M.types(G, f, name, at, ctx, options)
221
+ local C = context(G, ctx)
222
+ options = options or {}
223
+ name = M.name(name)
224
+ if not name then return {}, nil, true end
225
+ at = at or 0
226
+ local active = C.active(f, at, options.exclude, options.no_global)
227
+ local qualifier, rest = name:match('^([%w_]+)::(.*)$')
228
+ if qualifier == 'global' then
229
+ return C.exact(f, rest), C.namespace(f, rest) and rest or nil, true
230
+ end
231
+ local head, tail = (rest or name):match('^([^.]+)%.(.*)$')
232
+ head = qualifier or head or name
233
+ if qualifier then tail = rest end
234
+ if not qualifier then
235
+ for _, parameter in ipairs(C.data(f).csharp_parameters or {}) do
236
+ if parameter.name == head and parameter.first <= at and at <= parameter.last then return {}, nil, true end
237
+ end
238
+ end
239
+ local aliases, priority = {}, -2
240
+ for _, entry in ipairs(active) do
241
+ local d = entry.directive
242
+ if clean(d.alias) == head then
243
+ local rank = d.global and -1 or d.first
244
+ if rank > priority then aliases, priority = {}, rank end
245
+ if rank == priority then aliases[#aliases + 1] = entry end
246
+ end
247
+ end
248
+ if #aliases > 0 then
249
+ if #aliases ~= 1 or (options.depth or 0) >= 8 then return {}, nil, true end
250
+ local entry = aliases[1]
251
+ local d = entry.directive
252
+ if not d.global and d.scope == '' then
253
+ for _, other in ipairs(active) do
254
+ if other.directive.global and clean(other.directive.alias) == head then return {}, nil, true end
255
+ end
256
+ end
257
+ -- A nested type is looked up before a using alias from an enclosing
258
+ -- namespace/file. The explicit alias:: form still selects the alias.
259
+ if not qualifier then
260
+ local scope = options.scope or C.scope(f, at)
261
+ while scope ~= '' and scope ~= d.scope do
262
+ local q = scope .. '.' .. name
263
+ local ids, namespace = C.exact(f, q), C.namespace(f, q)
264
+ if #ids > 0 or namespace then return ids, namespace and q or nil, true end
265
+ if #C.exact(f, scope .. '.' .. head) > 0 then return {}, nil, true end
266
+ scope = scope:match('^(.*)%.[^.]+$') or ''
267
+ end
268
+ end
269
+ local ids, namespace = M.types(G, entry.file, d.path, d.first, ctx,
270
+ { exclude = d.first, no_global = true, scope = d.scope, depth = (options.depth or 0) + 1 })
271
+ local target = namespace or (#ids > 0 and G.nodes[ids[1]].qualified)
272
+ if not target or qualifier and not namespace then return {}, nil, true end
273
+ if tail then target = target .. '.' .. tail end
274
+ return C.exact(f, target), C.namespace(f, target) and target or nil, true
275
+ end
276
+ if qualifier then return {}, nil, true end -- extern aliases require assembly identity
277
+ local scope = options.scope or C.scope(f, at)
278
+ while true do
279
+ local q = (scope ~= '' and scope .. '.' or '') .. name
280
+ local ids = C.exact(f, q)
281
+ if #ids > 0 or C.namespace(f, q) then return ids, C.namespace(f, q) and q or nil, true end
282
+ if scope == '' then break end
283
+ scope = scope:match('^(.*)%.[^.]+$') or ''
284
+ end
285
+ local ids, seen = {}, {}
286
+ for _, entry in ipairs(active) do
287
+ local d = entry.directive
288
+ if not d.alias then
289
+ if (options.depth or 0) < 8 then
290
+ local owners, path = M.types(G, entry.file, d.path, d.first, ctx,
291
+ { exclude = d.first, no_global = true, scope = d.scope, depth = (options.depth or 0) + 1 })
292
+ if d.static then
293
+ for _, owner in ipairs(owners) do
294
+ for _, id in ipairs(C.exact(f, G.nodes[owner].qualified .. '.' .. name)) do
295
+ if not seen[id] then seen[id] = true; ids[#ids + 1] = id end
296
+ end
297
+ end
298
+ elseif path then
299
+ for _, id in ipairs(C.exact(f, path .. '.' .. name)) do if not seen[id] then seen[id] = true; ids[#ids + 1] = id end end
300
+ end
301
+ end
302
+ end
303
+ end
304
+ return ids, nil, #ids > 0
305
+ end
306
+
307
+ function M.members(G, f, ids, name, static, ctx, depth, seen, access_scope)
308
+ depth, seen = depth or 0, seen or {}
309
+ local C, out, emitted = context(G, ctx), {}, {}
310
+ for _, cls in ipairs(ids) do
311
+ if not seen[cls] and depth <= 8 then
312
+ seen[cls] = true
313
+ local found = false
314
+ for _, id in ipairs(G.by_name[name] or {}) do
315
+ local n, g = G.nodes[id], G.node_file[id]
316
+ if callable[n.kind] and n.qualified == G.nodes[cls].qualified .. '.' .. name
317
+ and G.files[g].language == 'csharp' and C.same(f, g) then
318
+ local data, index = C.data(g), id - G.id_of[g][1] + 1
319
+ local is_static, access = (data.csharp_statics or {})[index] or false, (data.csharp_access or {})[index]
320
+ local owner = G.nodes[cls].qualified
321
+ local own = access_scope and (access_scope == owner or access_scope:sub(1, #owner + 1) == owner .. '.')
322
+ if (static == nil or is_static == static) and (access == 'public' or access == 'internal' or own) then
323
+ if not emitted[id] then emitted[id] = true; out[#out + 1] = id end
324
+ found = true
325
+ end
326
+ end
327
+ end
328
+ if not found and static ~= true then
329
+ for _, base in ipairs(G.nodes[cls].bases or {}) do
330
+ local g = G.node_file[cls]
331
+ local at = 0
332
+ for _, scope in ipairs(C.data(g).csharp_scopes or {}) do if scope.scope == G.nodes[cls].qualified then at = scope.first; break end end
333
+ local more = M.types(G, g, base, at, ctx, { scope = G.nodes[cls].qualified:match('^(.*)%.[^.]+$') or '' })
334
+ for _, id in ipairs(M.members(G, f, more, name, static, ctx, depth + 1, seen, access_scope)) do
335
+ if not emitted[id] then emitted[id] = true; out[#out + 1] = id end
336
+ end
337
+ end
338
+ end
339
+ end
340
+ end
341
+ return out
342
+ end
343
+
344
+ function M.resolve(G, f, src, name, kind, recv, evidence, ctx)
345
+ if not evidence or evidence:sub(1, 3) ~= 'cs:' then return nil end
346
+ local tag, value, offset = evidence:match('^cs:(%w+):(.-)%z(%d+)$')
347
+ if not tag then return {} end
348
+ local at, C = tonumber(offset), context(G, ctx)
349
+ local access_scope = C.scope(f, at)
350
+ if tag == 'new' then
351
+ local result = {}
352
+ for _, cls in ipairs(M.types(G, f, value, at, ctx)) do
353
+ local n, explicit = G.nodes[cls], false
354
+ for _, id in ipairs(G.by_name[n.name] or {}) do
355
+ if G.nodes[id].kind == 'constructor' and G.nodes[id].qualified == n.qualified .. '.' .. n.name
356
+ and C.same(f, G.node_file[id]) then explicit = true; break end
357
+ end
358
+ if explicit then
359
+ for _, id in ipairs(M.members(G, f, { cls }, n.name, false, ctx, nil, nil, access_scope)) do result[#result + 1] = id end
360
+ else result[#result + 1] = cls end
361
+ end
362
+ return result
363
+ end
364
+ if tag == 'name' then
365
+ local ids, namespace, known = M.types(G, f, value, at, ctx)
366
+ if namespace then
367
+ for _, id in ipairs(G.by_name[namespace:match('([^.]+)$')] or {}) do
368
+ if G.nodes[id].kind == 'namespace' and G.nodes[id].qualified == namespace and C.same(f, G.node_file[id]) then ids[#ids + 1] = id end
369
+ end
370
+ end
371
+ if known then return ids end
372
+ return nil
373
+ end
374
+ if tag == 'self' then
375
+ local scope = src and G.nodes[src].qualified:match('^(.*)%.[^.]+$') or C.scope(f, at)
376
+ local owners = C.exact(f, scope)
377
+ if value == 'base' then
378
+ local bases = {}
379
+ for _, id in ipairs(owners) do
380
+ for _, base in ipairs(G.nodes[id].bases or {}) do
381
+ for _, target in ipairs(M.types(G, f, base, at, ctx)) do bases[#bases + 1] = target end
382
+ end
383
+ end
384
+ owners = bases
385
+ end
386
+ return M.members(G, f, owners, name, false, ctx, nil, nil, access_scope)
387
+ end
388
+ if tag == 'type' or tag == 'owner' then
389
+ local ids, _, known = M.types(G, f, value, at, ctx)
390
+ if tag == 'type' or known then return M.members(G, f, ids, name, tag == 'owner', ctx, nil, nil, access_scope) end
391
+ return nil
392
+ end
393
+ if tag == 'call' then
394
+ local owner = src and G.nodes[src].qualified:match('^(.*)%.[^.]+$')
395
+ if owner then
396
+ local own = M.members(G, f, C.exact(f, owner), name, nil, ctx, nil, nil, access_scope)
397
+ if #own > 0 then return own end
398
+ end
399
+ local out, known, seen = {}, false, {}
400
+ for _, entry in ipairs(C.active(f, at)) do
401
+ local d = entry.directive
402
+ if d.static then
403
+ known = true
404
+ local ids = M.types(G, entry.file, d.path, d.first, ctx, { exclude = d.first, no_global = true, scope = d.scope })
405
+ for _, id in ipairs(M.members(G, f, ids, name, true, ctx, nil, nil, access_scope)) do
406
+ if not seen[id] then seen[id] = true; out[#out + 1] = id end
407
+ end
408
+ end
409
+ end
410
+ if known then return out end
411
+ end
412
+ end
413
+
414
+ function M.incoming_aliases(G, f, wanted, ctx)
415
+ local hits, possible = {}, false
416
+ for id in pairs(wanted) do
417
+ if G.files[G.node_file[id]].language == 'csharp' and (types[G.nodes[id].kind] or G.nodes[id].kind == 'constructor') then possible = true; break end
418
+ end
419
+ if not possible then return hits end
420
+ local C, relevant = context(G, ctx), false
421
+ for id in pairs(wanted) do
422
+ local kind = G.nodes[id].kind
423
+ if G.files[G.node_file[id]].language == 'csharp' and (types[kind] or kind == 'constructor') and C.same(f, G.node_file[id]) then relevant = true; break end
424
+ end
425
+ if not relevant then return hits end
426
+ local refs = G.files[f].refs
427
+ for i, kind in ipairs(refs.kind) do
428
+ if kind == 'new' then
429
+ control.check()
430
+ local value = ctx.ordinary.evidence(f, i)
431
+ for _, id in ipairs(M.resolve(G, f, nil, refs.name[i], kind, refs.recv[i], value, ctx) or {}) do
432
+ if wanted[id] then hits[i] = true; break end
433
+ end
434
+ end
435
+ end
436
+ return hits
437
+ end
438
+
439
+ function M.usings(G, f, at, ctx)
440
+ return context(G, ctx).active(f, at)
441
+ end
442
+
443
+ function M.is_static(G, id, ctx)
444
+ local g, C = G.node_file[id], context(G, ctx)
445
+ return (C.data(g).csharp_statics or {})[id - G.id_of[g][1] + 1] or false
446
+ end
447
+
448
+ function M.static_node(G, f, node, ctx)
449
+ for _, id in ipairs(G.by_name[node.name] or {}) do
450
+ local n = G.nodes[id]
451
+ if G.node_file[id] == f and n.qualified == node.qualified and n.line == node.line and n.kind == node.kind then
452
+ return M.is_static(G, id, ctx)
453
+ end
454
+ end
455
+ return false
456
+ end
457
+
458
+ function M.visible_node(G, caller, f, node, at, ctx)
459
+ local C = context(G, ctx)
460
+ for _, id in ipairs(G.by_name[node.name] or {}) do
461
+ local n = G.nodes[id]
462
+ if G.node_file[id] == f and n.qualified == node.qualified and n.line == node.line and n.kind == node.kind then
463
+ local access = (C.data(f).csharp_access or {})[id - G.id_of[f][1] + 1]
464
+ local owner, scope = n.qualified:match('^(.*)%.[^.]+$'), C.scope(caller, at)
465
+ return access == 'public' or access == 'internal' or owner and (scope == owner or scope:sub(1, #owner + 1) == owner .. '.')
466
+ end
467
+ end
468
+ return false
469
+ end
470
+
471
+ -- Namespace alias completion uses the same type/namespace target as navigation.
472
+ function M.namespace_members(G, f, namespace, ctx)
473
+ local C, out, seen = context(G, ctx), {}, {}
474
+ local prefix = namespace ~= '' and namespace .. '.' or ''
475
+ -- A dotted namespace declaration need not contain a separate node for
476
+ -- each enclosing namespace (namespace A.B still exposes A then B).
477
+ for _, name in ipairs(C.namespace_children(f, namespace)) do
478
+ seen[name] = true
479
+ out[#out + 1] = { name = name, kind = 'namespace', node = { kind = 'namespace', name = name, qualified = prefix .. name } }
480
+ end
481
+ local files = {}
482
+ for _, g in ipairs(G.file_order) do files[#files + 1] = g end
483
+ for _, g in ipairs(G.new_files or {}) do files[#files + 1] = g end
484
+ for _, g in ipairs(files) do
485
+ if G.files[g].language == 'csharp' and C.same(f, g) then
486
+ for _, id in ipairs(G.id_of[g]) do
487
+ local n = G.nodes[id]
488
+ local suffix = n.qualified:sub(1, #prefix) == prefix and n.qualified:sub(#prefix + 1)
489
+ if suffix and not suffix:find('.', 1, true) and (types[n.kind] or n.kind == 'namespace') and not seen[suffix] then
490
+ seen[suffix] = true; out[#out + 1] = { name = suffix, kind = n.kind, node = n, file = g }
491
+ end
492
+ end
493
+ end
494
+ end
495
+ return out
496
+ end
497
+
498
+ 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