@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,342 @@
1
+ -- Query-owned C/C++ call-result receivers. Never infer a type from a member name.
2
+ local control = require('codeoutline.control')
3
+ local M = { MAX_FILES = 16, MAX_BYTES = 8388608, MAX_DEPTH = 12, MAX_CANDIDATES = 256, MAX_TIME_MS = 400 }
4
+ local family = { c = true, cpp = true }
5
+ local aggregates = { class = true, struct = true, union = true }
6
+ local callable = { ['function'] = true, method = true, prototype = true }
7
+ local modifiers = { static = true, inline = true, virtual = true, constexpr = true, extern = true,
8
+ friend = true, __inline = true, __inline__ = true, register = true, typedef = true }
9
+ local cv = { const = true, volatile = true, restrict = true, __restrict = true }
10
+
11
+ local function declared(T, a, b)
12
+ while modifiers[T:text(a)] do a = a + 1 end
13
+ local names, pointer, reference, tag, is_const = {}, 0, false, nil, false
14
+ for i = a, b do
15
+ local s = T:text(i)
16
+ if cv[s] then if s == 'const' and pointer == 0 then is_const = true end
17
+ elseif aggregates[s] then if #names > 0 then return nil end; tag = s
18
+ elseif s == '*' then pointer = pointer + 1
19
+ elseif s == '&' or s == '&&' then reference = true
20
+ elseif s == '::' and pointer == 0 and not reference then names[#names + 1] = s
21
+ elseif T.k[i] == 'id' and pointer == 0 and not reference then
22
+ if #names > 0 and names[#names] ~= '::' then return nil end
23
+ names[#names + 1] = s
24
+ else return nil end
25
+ end
26
+ local name = table.concat(names)
27
+ if name == '' or name == 'auto' or name == 'decltype' or name:sub(-2) == '::' then return nil end
28
+ return { name = name, pointer = pointer, reference = reference, const = is_const, tag = tag, at = T.s[a] - 1 }
29
+ end
30
+
31
+ local expression
32
+ expression = function(T, last, depth)
33
+ depth = (depth or 0) + 1
34
+ if depth > M.MAX_DEPTH then return nil end
35
+ if T.k[last] == 'id' then
36
+ local op = T:text(last - 1)
37
+ if op == '.' or op == '->' then
38
+ local receiver, first, size, call = expression(T, last - 2, depth)
39
+ if receiver then return { kind = 'field', receiver = receiver, name = T:text(last), op = op }, first, size + 1, call end
40
+ return nil
41
+ end
42
+ local first = last
43
+ while T:text(first - 1) == '::' and T.k[first - 2] == 'id' do first = first - 2 end
44
+ if T:text(first - 1) == '::' then first = first - 1 end
45
+ return { kind = 'name', name = T.src:sub(T.s[first], T.e[last]):gsub('%s+', ''),
46
+ at = T.s[last] - 1 }, first, 1, false
47
+ end
48
+ if T:text(last) ~= ')' or not T.m[last] then return nil end
49
+ local open = T.m[last]
50
+ if T.k[open - 1] == 'id' then
51
+ local target, first, size = expression(T, open - 1, depth)
52
+ if target then return { kind = 'call', target = target }, first, size + 1, true end
53
+ else
54
+ local previous = T:text(open - 1)
55
+ if previous == '>' or previous == '>>' or previous == ']' or previous == ')' then return nil end
56
+ local value, first, size, call = expression(T, last - 1, depth)
57
+ if first == open + 1 then return value, open, size, call end
58
+ end
59
+ end
60
+ M.expression = expression
61
+
62
+ function M.evidence(T, t)
63
+ local op = T:text(t - 1)
64
+ if op ~= '.' and op ~= '->' then return nil end
65
+ local e, _, _, call = expression(T, t - 2)
66
+ if call or not e and (T:text(t - 2) == ')' or T:text(t - 2) == ']') then return 'cxx:expr:' .. (T.s[t] - 1) end
67
+ end
68
+
69
+ function M.collect(r, T)
70
+ if not family[r.language] then return end
71
+ local d = { nodes = {}, expressions = {}, bindings = {}, calls = {}, weight = 0 }
72
+ r.cpp_receivers = d
73
+ local wanted = {}
74
+ local function roots(e)
75
+ if e.kind == 'name' then wanted[e.name] = true
76
+ elseif e.target then roots(e.target)
77
+ elseif e.receiver then roots(e.receiver) end
78
+ end
79
+ for t = 1, T.n do
80
+ if t % 4096 == 0 then control.check() end
81
+ local op = T:text(t - 1)
82
+ if T.k[t] == 'id' and (op == '.' or op == '->') then
83
+ local e, _, size, call = expression(T, t - 2)
84
+ if call or not e and (T:text(t - 2) == ')' or T:text(t - 2) == ']') then
85
+ local at = T.s[t] - 1
86
+ d.expressions[at] = { receiver = e or false, op = op }
87
+ d.weight = d.weight + (size or 1) * 192
88
+ if e then roots(e) end
89
+ end
90
+ end
91
+ end
92
+ local function prefix(ni)
93
+ local a = ni - 1
94
+ while a > 0 do
95
+ local s = T:text(a)
96
+ if T.k[a] ~= 'id' and T.k[a] ~= 'kw' and s ~= '*' and s ~= '&' and s ~= '&&' and s ~= '::' then break end
97
+ a = a - 1
98
+ end
99
+ return a + 1
100
+ end
101
+ local functions = {}
102
+ for id, n in ipairs(r.nodes) do
103
+ if id % 128 == 0 then control.check() end
104
+ local ni, a, b = r.cpp_declaration_tokens and r.cpp_declaration_tokens[id], n.ti, nil
105
+ local const_method = false
106
+ if callable[n.kind] and ni then
107
+ functions[#functions + 1] = n
108
+ local first = ni
109
+ while T:text(first - 1) == '::' and T.k[first - 2] == 'id' do first = first - 2 end
110
+ if T:text(first - 1) == '::' then first = first - 1 end
111
+ b = first - 1
112
+ local open = ni + 1
113
+ if T:text(open) == ')' and T.m[open] == ni - 1 then open, b = ni + 2, ni - 2 end
114
+ if T:text(open) == '(' and T.m[open] then
115
+ local after = T.m[open] + 1
116
+ const_method = T:text(after) == 'const'
117
+ while cv[T:text(after)] or T:text(after) == 'noexcept' do
118
+ after = after + 1
119
+ if T:text(after) == '(' and T.m[after] then after = T.m[after] + 1 end
120
+ end
121
+ if T:text(after) == '->' then
122
+ a, b = after + 1, after + 1
123
+ while b <= n.tj and T:text(b) ~= '{' and T:text(b) ~= ';' and T:text(b) ~= '=' do b = b + 1 end
124
+ b = b - 1
125
+ end
126
+ end
127
+ elseif n.kind == 'field' and ni then
128
+ a, b = prefix(ni), ni - 1
129
+ if T:text(ni + 1) == '[' or T:text(ni + 1) == ')' then b = a - 1 end
130
+ elseif n.kind == 'typedef' and ni then
131
+ if T:text(ni + 1) == '=' then a, b = ni + 2, n.tj - 1
132
+ elseif T:text(n.ti) == 'typedef' then a, b = n.ti + 1, ni - 1 end
133
+ end
134
+ d.nodes[id] = { type = b and declared(T, a, b) or false, const_method = const_method }
135
+ end
136
+ local scopes, stack = {}, {}
137
+ for t = 1, T.n do
138
+ if T:text(t) == '{' and T.m[t] then stack[#stack + 1] = t end
139
+ scopes[t] = stack[#stack] or 0
140
+ if stack[#stack] and T.m[stack[#stack]] == t then stack[#stack] = nil end
141
+ end
142
+ for t = 1, T.n do
143
+ if wanted[T:text(t)] then
144
+ local after, a = T:text(t + 1), prefix(t)
145
+ local pointer_callable = T:text(t - 1) == '*' and T:text(t - 2) == '('
146
+ local ty = declared(T, a, t - 1)
147
+ if (ty or pointer_callable or T:text(a) == 'auto' or T:text(t - 1) == '>')
148
+ and (after == ')' or after == ',' or after == ';' or after == '=' or after == '[') then
149
+ local scope = scopes[t]
150
+ local first, last = scope > 0 and T.s[scope] - 1 or 0, scope > 0 and T.e[T.m[scope]] or #T.src
151
+ for _, fn in ipairs(functions) do
152
+ if fn.ti < t and t < fn.tj and T.s[fn.ti] - 1 > first then first, last = T.s[fn.ti] - 1, T.e[fn.tj] end
153
+ end
154
+ d.bindings[#d.bindings + 1] = { name = T:text(t), type = ty or false, at = T.s[t] - 1, first = first, last = last }
155
+ end
156
+ end
157
+ end
158
+ d.evidence = {}
159
+ for index, ref in ipairs(r.refs) do
160
+ local at = T.s[ref.tok] - 1
161
+ if ref.kind == 'call' then d.calls[at] = ref.binding == 'cpp:?' or false end
162
+ if d.expressions[at] then ref.binding = 'cxx:expr:' .. at; d.evidence[index] = ref.binding; r.has_bindings = true end
163
+ end
164
+ d.weight = d.weight + #r.nodes * 160 + #d.bindings * 192
165
+ r.cpp_declaration_tokens = nil
166
+ end
167
+
168
+ function M.context(G, ctx)
169
+ ctx = ctx or {}
170
+ if ctx.cpp_receivers then return ctx.cpp_receivers end
171
+ local C = { stats = { files = 0, bytes = 0, candidates = 0 }, incomplete = false }
172
+ ctx.cpp_receivers = C
173
+ local deadline, records, visibility = xtimer.now_ms() + M.MAX_TIME_MS, {}, {}
174
+ local function limited() C.incomplete, ctx.cpp_receivers_incomplete = true, true end
175
+ local function expired()
176
+ control.check()
177
+ if xtimer.now_ms() > deadline then limited(); return true end
178
+ return false
179
+ end
180
+ function C.data(f)
181
+ if records[f] ~= nil then return records[f] or nil end
182
+ local rec = G.files[f]
183
+ if not ctx.ordinary or not ctx.ordinary.available(f) then records[f] = false; return nil end
184
+ local size = ctx.ordinary.source_size(f) or rec.size or #rec.nodes * 128
185
+ if expired() or C.stats.files >= M.MAX_FILES or C.stats.bytes + size > M.MAX_BYTES then
186
+ limited(); records[f] = false; return nil
187
+ end
188
+ C.stats.files, C.stats.bytes = C.stats.files + 1, C.stats.bytes + size
189
+ records[f] = ctx.ordinary.data(f).cpp_receivers or false
190
+ return records[f] or nil
191
+ end
192
+ local function active(id)
193
+ local f = G.node_file[id]; local ids = f and G.id_of[f]
194
+ return ids and ids[1] and ids[1] <= id and id <= ids[#ids]
195
+ end
196
+ local function info(id)
197
+ if not active(id) then return nil end
198
+ local f = G.node_file[id]; local d = C.data(f)
199
+ return d and d.nodes[id - G.id_of[f][1] + 1]
200
+ end
201
+ local function visible(f, g)
202
+ if f == g then return true end
203
+ if not visibility[f] then visibility[f] = require('codeoutline.graph').visible_dependencies(G, f, ctx) end
204
+ return visibility[f][g]
205
+ end
206
+ local function bound(f, name, at)
207
+ local d, best = C.data(f), nil
208
+ for _, b in ipairs(d and d.bindings or {}) do
209
+ if b.name == name and b.at < at and b.first <= at and at <= b.last
210
+ and (not best or b.first > best.first or b.first == best.first and b.at > best.at) then best = b end
211
+ end
212
+ return best
213
+ end
214
+ local function scope(id)
215
+ return id and G.nodes[id].qualified:match('^(.*)::[^:]+$') or nil
216
+ end
217
+ local type_of
218
+ type_of = function(f, ty, owner, seen, depth)
219
+ depth, seen = (depth or 0) + 1, seen or {}
220
+ if not ty or depth > M.MAX_DEPTH or expired() then return nil end
221
+ local ids
222
+ if G.files[f].language == 'cpp' then
223
+ -- Decorated aliases must retain indirection. The namespace resolver
224
+ -- intentionally normalizes it away, so leave those aliases unknown.
225
+ for i, alias in ipairs(G.by_name[ty.name:match('([^:]+)$')] or {}) do
226
+ if i > M.MAX_CANDIDATES then limited(); return nil end
227
+ if active(alias) and G.nodes[alias].kind == 'typedef' and visible(f, G.node_file[alias]) then
228
+ for _, a in ipairs(require('codeoutline.cpp_types').aliases(G, G.node_file[alias], ctx)) do
229
+ if a.name == G.nodes[alias].name and a.decorated then return nil end
230
+ end
231
+ end
232
+ end
233
+ ids = require('codeoutline.cpp_types').resolve(G, f, ty.name, { context = ctx, scope = owner, at = ty.at })
234
+ else
235
+ ids = {}
236
+ for i, id in ipairs(G.by_name[ty.name] or {}) do
237
+ if i > M.MAX_CANDIDATES then limited(); return nil end
238
+ local n, g = G.nodes[id], G.node_file[id]
239
+ if active(id) and family[G.files[g].language] and visible(f, g) and not n.parent then
240
+ if aggregates[n.kind] then ids[#ids + 1] = id
241
+ elseif n.kind == 'typedef' and not ty.tag then
242
+ if seen[id] then return nil end
243
+ local d = info(id); seen[id] = true
244
+ local value = d and type_of(g, d.type, nil, seen, depth)
245
+ seen[id] = nil
246
+ if not value then return nil end
247
+ return { id = value.id, pointer = value.pointer + ty.pointer, const = value.const or ty.const }
248
+ end
249
+ end
250
+ end
251
+ end
252
+ if #ids ~= 1 then return nil end
253
+ return { id = ids[1], pointer = ty.pointer, const = ty.const }
254
+ end
255
+ local function members(receiver, name, op, declarations)
256
+ if not receiver or (op == '->' and receiver.pointer ~= 1 or op == '.' and receiver.pointer ~= 0) then return {} end
257
+ local id, result = receiver.id, {}
258
+ if G.files[G.node_file[id]].language == 'cpp' then
259
+ local candidates
260
+ if declarations then
261
+ local known
262
+ candidates, known = require('codeoutline.cpp_types').resolve(G, G.node_file[id], '::' .. G.nodes[id].qualified .. '::' .. name,
263
+ { context = ctx, accept = { ['function'] = true, method = true, prototype = true, field = true } })
264
+ if known and #candidates == 0 then return {} end
265
+ end
266
+ if not candidates or #candidates == 0 then
267
+ candidates = require('codeoutline.cpp_bindings').resolve(G, G.node_file[id], nil, name,
268
+ 'cpp:type:::' .. G.nodes[id].qualified, nil, ctx) or {}
269
+ end
270
+ for _, mid in ipairs(candidates) do
271
+ local d = receiver.const and callable[G.nodes[mid].kind] and info(mid)
272
+ if not receiver.const or not callable[G.nodes[mid].kind] or d and d.const_method then result[#result + 1] = mid end
273
+ end
274
+ return result
275
+ end
276
+ for i, mid in ipairs(G.by_name[name] or {}) do
277
+ if i > M.MAX_CANDIDATES then limited(); break end
278
+ local n, g = G.nodes[mid], G.node_file[mid]
279
+ if active(mid) and g == G.node_file[id] and n.parent and G.id_of[g][n.parent] == id then result[#result + 1] = mid end
280
+ end
281
+ return result
282
+ end
283
+ C.members = members
284
+ local value
285
+ value = function(f, e, owner, depth)
286
+ depth = (depth or 0) + 1
287
+ if not e or depth > M.MAX_DEPTH or expired() then return nil end
288
+ if e.kind == 'name' then
289
+ local b = bound(f, e.name, e.at)
290
+ return b and type_of(f, b.type, scope(owner)) or nil
291
+ end
292
+ local candidates
293
+ local parent
294
+ if e.kind == 'field' then
295
+ parent = value(f, e.receiver, owner, depth)
296
+ candidates = members(parent, e.name, e.op, true)
297
+ elseif e.kind == 'call' then
298
+ local target = e.target
299
+ if target.kind == 'field' then
300
+ candidates = members(value(f, target.receiver, owner, depth), target.name, target.op, true)
301
+ elseif target.kind == 'name' then
302
+ local d = C.data(f)
303
+ if not d or d.calls[target.at] or bound(f, target.name, target.at) then return nil end
304
+ if G.files[f].language == 'cpp' then
305
+ candidates = require('codeoutline.cpp_types').resolve(G, f, target.name,
306
+ { context = ctx, scope = scope(owner), at = target.at, accept = callable })
307
+ else
308
+ candidates = {}
309
+ for i, id in ipairs(G.by_name[target.name] or {}) do
310
+ if i > M.MAX_CANDIDATES then limited(); return nil end
311
+ local n, g = G.nodes[id], G.node_file[id]
312
+ if active(id) and callable[n.kind] and not n.parent and visible(f, g)
313
+ and not (n.static and f ~= g) then candidates[#candidates + 1] = id end
314
+ end
315
+ end
316
+ end
317
+ end
318
+ local agreed
319
+ for i, id in ipairs(candidates or {}) do
320
+ if i > M.MAX_CANDIDATES then limited(); return nil end
321
+ C.stats.candidates = C.stats.candidates + 1
322
+ if e.kind == 'call' and not callable[G.nodes[id].kind] or e.kind == 'field' and G.nodes[id].kind ~= 'field' then return nil end
323
+ local d = info(id)
324
+ local actual = d and type_of(G.node_file[id], d.type, scope(id))
325
+ if actual and parent and parent.const and actual.pointer == 0 then actual.const = true end
326
+ if not actual or agreed and (agreed.id ~= actual.id or agreed.pointer ~= actual.pointer or agreed.const ~= actual.const) then return nil end
327
+ agreed = actual
328
+ end
329
+ return agreed
330
+ end
331
+ C.receiver = value
332
+ function C.resolve(f, src, name, evidence)
333
+ local at = evidence and tonumber(evidence:match('^cxx:expr:(%d+)$'))
334
+ if not at then return nil end
335
+ local d = C.data(f); local site = d and d.expressions[at]
336
+ if not site then return {}, 'missing C/C++ receiver evidence' end
337
+ return members(value(f, site.receiver, src), name, site.op), 'C/C++ declared call-result receiver'
338
+ end
339
+ return C
340
+ end
341
+
342
+ return M