@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,479 @@
1
+ -- Query-owned, bounded lexical aliases for explicit dispatch contracts.
2
+ -- No execution, basename guesses or persistent binding graph.
3
+ local M = {}
4
+ local control = require('codeoutline.control')
5
+ local member = { ['.'] = true, [':'] = true, ['::'] = true, ['->'] = true }
6
+ local supported = { lua = true, javascript = true, typescript = true, arkts = true, python = true, c = true, cpp = true }
7
+ local callable = { ['function'] = true, method = true, constructor = true }
8
+ local statements = { ['local'] = true, ['function'] = true, ['end'] = true, ['return'] = true,
9
+ ['if'] = true, ['else'] = true, ['elseif'] = true, ['until'] = true, ['for'] = true,
10
+ ['while'] = true, ['do'] = true, ['repeat'] = true, ['break'] = true }
11
+
12
+ local function quoted(T, i, language)
13
+ local s = T:text(i)
14
+ if T.k[i] == 'str' and language == 'lua' then return require('codeoutline.lua_literal').decode(s) end
15
+ if T.k[i] == 'str' and (s:sub(1, 1) == '"' or s:sub(1, 1) == "'")
16
+ and s:sub(-1) == s:sub(1, 1) and not s:find('[\\$]') then return s:sub(2, -2) end
17
+ end
18
+
19
+ local function name(T, i)
20
+ if T.k[i] ~= 'id' then return nil, i end
21
+ local result = T:text(i)
22
+ i = i + 1
23
+ while member[T:text(i)] and T.k[i + 1] == 'id' do
24
+ result = result .. T:text(i) .. T:text(i + 1); i = i + 2
25
+ end
26
+ return result, i
27
+ end
28
+
29
+ local function simple(T, i, language, symbols_only)
30
+ local start = i
31
+ if T:text(i) == '&' then i = i + 1 end
32
+ local symbol, ending = name(T, i)
33
+ local literal = not symbols_only and quoted(T, i, language)
34
+ if literal then ending = i + 1 end
35
+ if not symbol and not literal then return false end
36
+ local next = T:text(ending)
37
+ local boundary = next == '' or next == ';' or next == '}' or T.k[ending] == 'nl'
38
+ or language == 'lua' and statements[next]
39
+ or T.l[ending] and T.l[ending] > T.l[ending - 1]
40
+ and (T.k[ending] == 'id' or T.k[ending] == 'kw' and next ~= 'and' and next ~= 'or')
41
+ if not boundary then return false end
42
+ return { symbol = symbol, literal = literal, token = start }, ending
43
+ end
44
+ M.simple = simple
45
+
46
+ -- Only remember literal service constructors; validate the factory's lexical
47
+ -- identity during expansion, after imports, shadowing and writes are known.
48
+ local function service_initializer(T, i)
49
+ local factory, open = name(T, i)
50
+ if not factory or T:text(open) ~= '(' or not T.m[open] then return nil end
51
+ local service = quoted(T, open + 1, 'lua')
52
+ if not service or (T:text(open + 2) ~= ',' and open + 2 ~= T.m[open]) then return nil end
53
+ local ending = T.m[open] + 1
54
+ local next = T:text(ending)
55
+ if next ~= '' and next ~= ';' and not statements[next]
56
+ and not (T.l[ending] and T.l[ending] > T.l[ending - 1]
57
+ and (T.k[ending] == 'id' or T.k[ending] == 'kw' and next ~= 'and' and next ~= 'or')) then return nil end
58
+ return { service = service, factory = { symbol = factory }, token = i }
59
+ end
60
+
61
+ local function is_service_factory(value)
62
+ return value and not value.node and (not value.import or value.import.path == 'skynet')
63
+ and (value.symbol == 'skynet.uniqueservice' or value.symbol == 'skynet.newservice')
64
+ end
65
+
66
+ local function initializer(T, i, typed)
67
+ if T:text(i + 1) == '=' then return i + 1 end
68
+ -- C/C++ inline function-pointer declarators, not a call-result expression.
69
+ if T:text(i - 2) == '(' and T:text(i - 1) == '*' and T:text(i + 1) == ')'
70
+ and T:text(i + 2) == '(' and T.m[i + 2] and T:text(T.m[i + 2] + 1) == '=' then
71
+ return T.m[i + 2] + 1
72
+ end
73
+ if typed and T:text(i + 1) == ':' then
74
+ local _, j = name(T, i + 2)
75
+ if T:text(j) == '=' then return j end
76
+ end
77
+ end
78
+
79
+ local function lvalue_end(T, i)
80
+ if T.k[i] ~= 'id' then return nil end
81
+ i = i + 1
82
+ while true do
83
+ if member[T:text(i)] and T.k[i + 1] == 'id' then i = i + 2
84
+ elseif T:text(i) == '[' and T.m[i] then i = T.m[i] + 1
85
+ else return i end
86
+ end
87
+ end
88
+
89
+ -- Import descriptors are syntax only. Lexical declarations and writes below
90
+ -- decide whether an import can actually be used at a query site.
91
+ local function imports(r, T)
92
+ local result = {}
93
+ if r.language ~= 'lua' and r.language ~= 'javascript' and r.language ~= 'typescript' and r.language ~= 'arkts'
94
+ and r.language ~= 'python' then return result end
95
+ local function add(local_name, path, imported, token)
96
+ result[#result + 1] = { name = local_name, path = path, imported = imported, token = token }
97
+ end
98
+ for i = 1, T.n do
99
+ if i % 4096 == 0 then control.check() end
100
+ local s = T.k[i] == 'kw' and T:text(i)
101
+ if r.language == 'lua' and s == 'local' and T.k[i + 1] == 'id' and T:text(i + 2) == '='
102
+ and (T:text(i + 3) == 'require' or T:text(i + 3) == 'dofile')
103
+ and (T:text(i + 4) == '(' and T.m[i + 4] == i + 6 and quoted(T, i + 5, 'lua')
104
+ or quoted(T, i + 4, 'lua')) then
105
+ local path = quoted(T, i + 4, 'lua') or quoted(T, i + 5, 'lua')
106
+ add(T:text(i + 1), path, '*', i + 1)
107
+ result[#result].loader = T:text(i + 3)
108
+ elseif (r.language == 'javascript' or r.language == 'typescript' or r.language == 'arkts') and s == 'import'
109
+ and T:text(i + 1) ~= '(' then
110
+ local j, entries = i + 1, {}
111
+ if T.k[j] == 'id' then entries[#entries + 1] = { T:text(j), 'default', j }; j = j + 1 end
112
+ if T:text(j) == ',' then j = j + 1 end
113
+ if T:text(j) == '*' and T:text(j + 1) == 'as' and T.k[j + 2] == 'id' then
114
+ entries[#entries + 1] = { T:text(j + 2), '*', j + 2 }; j = j + 3
115
+ elseif T:text(j) == '{' and T.m[j] then
116
+ local close = T.m[j]; j = j + 1
117
+ while j < close do
118
+ if T.k[j] == 'id' then
119
+ local original, alias, tok = T:text(j), T:text(j), j; j = j + 1
120
+ if T:text(j) == 'as' and T.k[j + 1] == 'id' then alias, tok, j = T:text(j + 1), j + 1, j + 2 end
121
+ entries[#entries + 1] = { alias, original, tok }
122
+ else j = j + 1 end
123
+ end
124
+ j = close + 1
125
+ end
126
+ if T:text(j) == 'from' and quoted(T, j + 1) then
127
+ for _, e in ipairs(entries) do add(e[1], quoted(T, j + 1), e[2], e[3]) end
128
+ end
129
+ elseif r.language == 'python' and s == 'import' and T:text(i - 1) ~= '.' then
130
+ -- A from-import is handled at its `from` token.
131
+ local first = i
132
+ while first > 1 and T.k[first - 1] ~= 'nl' do first = first - 1 end
133
+ if T:text(first) ~= 'from' then
134
+ local j = i + 1
135
+ while T.k[j] == 'id' do
136
+ local path
137
+ path, j = name(T, j)
138
+ if T:text(j) == 'as' and T.k[j + 1] == 'id' then add(T:text(j + 1), path, '*', j + 1)
139
+ j = j + 2
140
+ else add(path:match('^[^.]+'), path:match('^[^.]+'), '*', j - 1) end
141
+ if T:text(j) ~= ',' then break end
142
+ j = j + 1
143
+ end
144
+ end
145
+ elseif r.language == 'python' and s == 'from' then
146
+ local prefix, j = '', i + 1
147
+ while T:text(j) == '.' or T:text(j) == '...' do prefix = prefix .. T:text(j); j = j + 1 end
148
+ local path
149
+ path, j = name(T, j)
150
+ path = prefix .. (path or '')
151
+ if path == '' then path = nil end
152
+ if path and T:text(j) == 'import' then
153
+ j = j + 1
154
+ if T:text(j) == '(' then j = j + 1 end
155
+ while T.k[j] == 'id' do
156
+ local original, alias, tok = T:text(j), T:text(j), j; j = j + 1
157
+ if T:text(j) == 'as' and T.k[j + 1] == 'id' then alias, tok, j = T:text(j + 1), j + 1, j + 2 end
158
+ add(alias, path, original, tok)
159
+ if T:text(j) ~= ',' then break end
160
+ j = j + 1
161
+ end
162
+ end
163
+ end
164
+ end
165
+ return result
166
+ end
167
+ M.imports = imports
168
+
169
+ -- Cheap, conservative roots let aliases reach the query parser without
170
+ -- performing scope analysis at index time. Existing dispatch_calls stores them.
171
+ function M.hints(r, T, calls)
172
+ if not supported[r.language] then return end
173
+ local roots, values = {}, {}
174
+ for call in pairs(calls) do roots[call:match('^([%w_$]+)')] = true end
175
+ local function add(n, v)
176
+ values[n] = values[n] or {}; values[n][#values[n] + 1] = v
177
+ end
178
+ for i = 1, T.n do
179
+ if i % 4096 == 0 then control.check() end
180
+ if T.k[i] == 'op' and T:text(i) == '=' then
181
+ local lhs = T.k[i - 1] == 'id' and i - 1
182
+ -- A type annotation may separate the local name from `=`. All
183
+ -- identifier components are conservative roots, not proven bindings.
184
+ if lhs then
185
+ local v = simple(T, i + 1, r.language, true)
186
+ if v and v.symbol then
187
+ add(T:text(lhs), v.symbol)
188
+ local j = lhs
189
+ while j > 2 and T:text(j - 1) == '.' and T.k[j - 2] == 'id' do j = j - 2 end
190
+ if T:text(j - 1) == ':' and T.k[j - 2] == 'id' then add(T:text(j - 2), v.symbol) end
191
+ end
192
+ elseif T:text(i - 1) == ')' and T.m[i - 1] then
193
+ local p = T.m[i - 1]
194
+ if T:text(p - 1) == ')' and T.k[p - 2] == 'id' and T:text(p - 3) == '*'
195
+ and T:text(p - 4) == '(' then
196
+ local v = simple(T, i + 1, r.language, true)
197
+ if v and v.symbol then add(T:text(p - 2), v.symbol) end
198
+ end
199
+ end
200
+ end
201
+ end
202
+ for _, imp in ipairs(imports(r, T)) do
203
+ if imp.path:match('^[%a_][%w_%.]*$') and not (imp.imported == '*' and imp.name == imp.path) then
204
+ add(imp.name, imp.path .. (imp.imported ~= '*' and '.' .. imp.imported or ''))
205
+ end
206
+ end
207
+ local seen = {}
208
+ local function visit(n, depth)
209
+ if seen[n] and seen[n] <= depth or depth > 8 then return end
210
+ seen[n] = depth
211
+ for _, v in ipairs(values[n] or {}) do
212
+ calls['@' .. v] = true
213
+ visit(v:match('^([%w_$]+)'), depth + 1)
214
+ end
215
+ end
216
+ for n in pairs(roots) do visit(n, 0) end
217
+ end
218
+
219
+ function M.prepare(r, T)
220
+ if not supported[r.language] then return function(v) return v end end
221
+ local lua, python = r.language == 'lua', r.language == 'python'
222
+ local js = r.language == 'javascript' or r.language == 'typescript' or r.language == 'arkts'
223
+ local scopes, ends, stack = {}, { [0] = T.n }, {}
224
+ local opens = { ['function'] = true, ['if'] = true, ['do'] = true, ['repeat'] = true }
225
+ for i = 1, T.n do
226
+ local s = T:text(i)
227
+ if lua and T.k[i] == 'kw' and (s == 'end' or s == 'until') then
228
+ local top = table.remove(stack); if top then ends[top] = i end
229
+ elseif not lua and (python and T.k[i] == 'dedent' or not python and s == '}') then table.remove(stack) end
230
+ scopes[i] = stack[#stack] or 0
231
+ if lua and T.k[i] == 'kw' and opens[s] or python and T.k[i] == 'indent'
232
+ or not lua and not python and s == '{' then
233
+ stack[#stack + 1] = i
234
+ if not lua then ends[i] = T.m[i] or T.n end
235
+ end
236
+ end
237
+ local bindings, imported, callable_declarations = {}, {}, {}
238
+ local function function_scope(at)
239
+ local owner
240
+ for _, n in ipairs(r.nodes) do
241
+ if callable[n.kind] and n.ti <= at and at <= n.tj and (not owner or n.ti > owner.ti) then owner = n end
242
+ end
243
+ return owner and owner.ti or 0, owner and owner.tj or T.n
244
+ end
245
+ local function add(n, token, scope, v, finish)
246
+ local b = { name = n, token = token, scope = scope, finish = finish or ends[scope] or T.n, value = v }
247
+ bindings[n] = bindings[n] or {}; bindings[n][#bindings[n] + 1] = b
248
+ return b
249
+ end
250
+ local function binding(n, at)
251
+ local best
252
+ for _, b in ipairs(bindings[n] or {}) do
253
+ if b.scope <= at and at <= b.finish and (b.token <= at or js or python)
254
+ and (not best or b.scope > best.scope or b.scope == best.scope and b.token > best.token) then best = b end
255
+ end
256
+ return best
257
+ end
258
+ for _, imp in ipairs(imports(r, T)) do
259
+ imported[imp.token] = true
260
+ local scope, finish = scopes[imp.token], nil
261
+ if js then scope = 0 elseif python then scope, finish = function_scope(imp.token) end
262
+ add(imp.name, imp.token, scope, { import = imp, symbol = imp.name }, finish)
263
+ end
264
+ -- Function declarations and all header identifiers provide lexical barriers
265
+ -- for parameters, including unsupported typed/destructured parameter forms.
266
+ for id, n in ipairs(r.nodes) do
267
+ if callable[n.kind] then
268
+ if js and n.kind == 'function' then
269
+ for j = n.ti, math.min(n.tj, n.ti + 4) do
270
+ local prev = T:text(j - 1)
271
+ if T:text(j) == n.name and (prev == 'const' or prev == 'let' or prev == 'var') then
272
+ callable_declarations[j] = id; break
273
+ end
274
+ end
275
+ end
276
+ local p = n.ti
277
+ while p <= n.tj and T:text(p) ~= '(' and T:text(p) ~= '{' and T:text(p) ~= '=>' do p = p + 1 end
278
+ if T:text(p) == '(' and T.m[p] then
279
+ for j = p + 1, T.m[p] - 1 do if T.k[j] == 'id' then add(T:text(j), j, n.ti, false, n.tj) end end
280
+ if lua then
281
+ for j = n.ti, p - 1 do
282
+ if T:text(j) == ':' then add('self', p, n.ti, false, n.tj); break end
283
+ end
284
+ end
285
+ elseif T:text(p) == '=>' and T.k[p - 1] == 'id' then add(T:text(p - 1), p - 1, n.ti, false, n.tj) end
286
+ -- Locally declared named functions are exact targets, not a global
287
+ -- name-only guess. Lua local functions start at the `local` token.
288
+ if n.qualified == n.name or n.parent and (lua or python) then
289
+ add(n.name, n.ti, scopes[n.ti], { node = id, symbol = n.name })
290
+ end
291
+ end
292
+ end
293
+ local declaration = {}
294
+ for i = 1, T.n do
295
+ if i % 4096 == 0 then control.check() end
296
+ local word = T:text(i)
297
+ if js and (word == 'const' or word == 'let' or word == 'var')
298
+ and (T:text(i + 1) == '{' or T:text(i + 1) == '[') and T.m[i + 1] then
299
+ for j = i + 2, T.m[i + 1] - 1 do
300
+ if T.k[j] == 'id' then add(T:text(j), j, scopes[i], false) end
301
+ end
302
+ elseif lua and word == 'local' and T.k[i + 1] == 'id' and T:text(i + 2) == ',' then
303
+ local j = i + 1
304
+ while T.k[j] == 'id' do
305
+ add(T:text(j), j, scopes[i], false)
306
+ if T:text(j + 1) ~= ',' then break end
307
+ j = j + 2
308
+ end
309
+ elseif (lua or python) and word == 'for' then
310
+ local scope, finish
311
+ if lua then
312
+ scope = i + 1
313
+ while scope <= T.n and T:text(scope) ~= 'do' do
314
+ if T.m[scope] and T.m[scope] > scope then scope = T.m[scope] end
315
+ scope = scope + 1
316
+ end
317
+ finish = ends[scope]
318
+ else scope, finish = function_scope(i) end
319
+ local j = i + 1
320
+ while T.k[j] == 'id' do
321
+ add(T:text(j), j, scope, false, finish)
322
+ if T:text(j + 1) ~= ',' then break end
323
+ j = j + 2
324
+ end
325
+ elseif python and word == 'as' and T.k[i + 1] == 'id' and not imported[i + 1] then
326
+ local scope, finish = function_scope(i)
327
+ add(T:text(i + 1), i + 1, scope, false, finish)
328
+ elseif not lua and not python and word == 'catch' and T:text(i + 1) == '(' and T.m[i + 1] then
329
+ local close = T.m[i + 1]
330
+ local scope = T:text(close + 1) == '{' and close + 1 or scopes[i]
331
+ for j = i + 2, close - 1 do
332
+ if T.k[j] == 'id' then add(T:text(j), j, scope, false) end
333
+ end
334
+ elseif python and (word == 'global' or word == 'nonlocal' or word == 'del') then
335
+ local j, scope, finish = i + 1, function_scope(i)
336
+ while T.k[j] == 'id' do
337
+ add(T:text(j), j, scope, false, finish)
338
+ if T:text(j + 1) ~= ',' then break end
339
+ j = j + 2
340
+ end
341
+ end
342
+ if T.k[i] == 'id' and not imported[i] then
343
+ local prev, next = T:text(i - 1), T:text(i + 1)
344
+ local eq = initializer(T, i, js)
345
+ local local_decl = lua and prev == 'local' or js and (prev == 'const' or prev == 'let' or prev == 'var')
346
+ if python and (next == '=' or next == ':') and not member[prev] then local_decl = true end
347
+ if (r.language == 'c' or r.language == 'cpp') and eq
348
+ and (T.k[i - 1] == 'id' or T.k[i - 1] == 'kw' or prev == '*') then local_decl = true end
349
+ if (r.language == 'c' or r.language == 'cpp') and (next == ';' or next == ',')
350
+ and (T.k[i - 1] == 'id' or prev == '*') then local_decl = true end
351
+ if local_decl then
352
+ declaration[i] = true
353
+ local scope, finish = scopes[i], nil
354
+ if python or js and prev == 'var' then scope, finish = function_scope(i) end
355
+ local v = eq and simple(T, eq + 1, r.language) or false
356
+ if callable_declarations[i] then v = { node = callable_declarations[i], symbol = T:text(i) } end
357
+ if lua and eq and not v then v = service_initializer(T, eq + 1) or false end
358
+ if lua and eq and T:text(eq + 1) == '{' then v = { namespace = true } end
359
+ local b = add(T:text(i), i, scope, v, finish)
360
+ if python or js and prev == 'var' then
361
+ for _, other in ipairs(bindings[b.name]) do
362
+ if other ~= b and other.scope == b.scope then other.invalid, b.invalid = true, true end
363
+ end
364
+ end
365
+ end
366
+ end
367
+ end
368
+ local service_writes = {}
369
+ -- Any later write poisons that lexical binding for this whole query. This
370
+ -- deliberately avoids inventing execution order across functions/branches.
371
+ for i = 1, T.n do
372
+ if js and (T:text(i) == '{' or T:text(i) == '[') and T.m[i] and T:text(T.m[i] + 1) == '=' then
373
+ for j = i + 1, T.m[i] - 1 do
374
+ local b = T.k[j] == 'id' and binding(T:text(j), i)
375
+ if b then b.invalid = true end
376
+ end
377
+ end
378
+ if T.k[i] == 'id' and not declaration[i] and not imported[i] and not member[T:text(i - 1)] then
379
+ local tail = lvalue_end(T, i)
380
+ local next = T:text(tail)
381
+ local last = tail
382
+ if lua or python then
383
+ while last and T:text(last) == ',' do last = lvalue_end(T, last + 1) end
384
+ end
385
+ if next == '=' or next:match('^[+%-%*/%%&|%^]=') or next == '++' or next == '--'
386
+ or last and T:text(last) == '=' or T:text(i - 1) == '++' or T:text(i - 1) == '--' then
387
+ local b = binding(T:text(i), i)
388
+ if b then b.invalid = true end
389
+ if lua then
390
+ local name = T:text(i)
391
+ local value = next == '=' and tail == i + 1 and T:text(i - 1) ~= ','
392
+ and (service_initializer(T, i + 2) or simple(T, i + 2, 'lua')) or false
393
+ service_writes[name] = service_writes[name] or {}
394
+ service_writes[name][#service_writes[name] + 1] = {
395
+ binding = b, token = i, scope = scopes[i], value = value,
396
+ }
397
+ end
398
+ end
399
+ end
400
+ end
401
+ local expand
402
+ expand = function(v, at, depth)
403
+ if not v or not v.symbol then return v end
404
+ depth = depth or 0
405
+ if depth > 8 then return false end
406
+ local head, suffix = v.symbol:match('^([%w_$]+)(.*)$')
407
+ local b = binding(head, at)
408
+ -- A single later initialization of a nil/uninitialized handle is useful
409
+ -- for navigation. Keep ordinary aliases poisoned, and require assignment
410
+ -- and use in the same block; no branch or cross-function ordering guesses.
411
+ if suffix == '' and (not b or not b.value) then
412
+ local write
413
+ for _, candidate in ipairs(service_writes[head] or {}) do
414
+ if candidate.binding == b then
415
+ if write then write = false; break end
416
+ write = candidate
417
+ end
418
+ end
419
+ if write and write.token < at and write.scope == scopes[at] and write.value then
420
+ local value = write.value
421
+ if value.factory then
422
+ local factory = expand(value.factory, value.token, depth + 1)
423
+ if is_service_factory(factory) then
424
+ return { service = value.service, token = write.token }
425
+ end
426
+ else
427
+ local resolved = expand(value, write.token, depth + 1)
428
+ if resolved and resolved.service then return resolved end
429
+ end
430
+ end
431
+ end
432
+ if not b then return v end
433
+ if b.invalid or not b.value or b.token > at and not b.value.node then return false end
434
+ local target = b.value
435
+ if target.factory then
436
+ if suffix ~= '' then return false end
437
+ local factory = expand(target.factory, target.token, depth + 1)
438
+ if is_service_factory(factory) then
439
+ return { service = target.service, token = b.token }
440
+ end
441
+ return false
442
+ end
443
+ if target.namespace then
444
+ local short = suffix:match('^[%.:]([%w_]+)$')
445
+ if not short then return false end
446
+ b.members = b.members or require('codeoutline.lua_bindings').local_members(r.nodes, scopes,
447
+ b.name, b.token, b.scope, b.finish)
448
+ local id = b.members[short]
449
+ return id and { node = id, symbol = r.nodes[id].qualified } or false
450
+ end
451
+ if target.import then
452
+ local imp = target.import
453
+ if imp.loader and binding(imp.loader, imp.token) then return false end
454
+ if imp.imported == 'default' and suffix ~= '' then return false end
455
+ local part = imp.imported ~= '*' and imp.imported ~= 'default' and imp.imported or ''
456
+ if imp.imported == 'default' then part = 'default' end
457
+ if suffix ~= '' then part = part .. (part == '' and suffix:sub(2) or suffix) end
458
+ local canonical = imp.path:match('^[%a_][%w_%.]*$') and imp.path .. (part ~= '' and '.' .. part or '')
459
+ return { symbol = canonical or v.symbol, import = imp, member = part, token = imp.token }
460
+ end
461
+ if target.node then
462
+ if suffix ~= '' then return false end
463
+ return { symbol = target.symbol, node = target.node, token = b.token }
464
+ end
465
+ if suffix ~= '' then
466
+ if not target.symbol or target.literal then return false end
467
+ return expand({ symbol = target.symbol .. suffix }, b.token - 1, depth + 1)
468
+ end
469
+ return expand(target, b.token - 1, depth + 1)
470
+ 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
477
+ end
478
+
479
+ return M
@@ -2,6 +2,7 @@ local parse = require('codeoutline.parse')
2
2
  local paths = require('codeoutline.path')
3
3
  local text = require('codeoutline.text')
4
4
  local M = { MAX_BYTES = 1500000 }
5
+ local branch_scanners = {}
5
6
  local Doc = {}
6
7
  Doc.__index = Doc
7
8
 
@@ -122,33 +123,55 @@ function Doc:offset(position)
122
123
  return p
123
124
  end
124
125
 
125
- local extensions = { javascript = 'js', typescript = 'ts', python = 'py', csharp = 'cs', rust = 'rs', cpp = 'cpp', kotlin = 'kt' }
126
126
  local function parser_name(doc)
127
- local name = doc.path or ('document.' .. (extensions[doc.language] or doc.language or 'txt'))
128
- if not parse.language(name) and doc.language then name = 'document.' .. (extensions[doc.language] or doc.language) end
129
- return name
127
+ return doc.path or 'document'
130
128
  end
131
129
 
132
130
  function Doc:parse()
133
131
  if self.parsed then return self.parsed end
134
- self.parsed = parse.parse(parser_name(self), self.source) or { nodes = {} }
132
+ self.parsed = parse.parse(parser_name(self), self.source,
133
+ { language = self.indexed_language or self.language, detect = true, type_uses = false, analysis = false }) or { nodes = {} }
135
134
  return self.parsed
136
135
  end
137
136
 
138
137
  -- Tokens are not retained: only cursor lookups outside indexed refs need them.
139
- function Doc:tokens()
140
- local _, tokens = parse.parse_tokens(parser_name(self), self.source)
138
+ function Doc:tokens(all_branches)
139
+ local language = self:parse().language
140
+ if all_branches and (language == 'c' or language == 'cpp') then
141
+ if not self.branch_tokens then
142
+ local scanner = branch_scanners[language]
143
+ if not scanner then
144
+ local config = {}
145
+ for k, v in pairs(require('codeoutline.lang.' .. language).config) do config[k] = v end
146
+ config.pp_first_branch = false
147
+ scanner = require('codeoutline.xscan').lang(config); branch_scanners[language] = scanner
148
+ end
149
+ self.branch_tokens = scanner:tokenize(self.source)
150
+ end
151
+ return self.branch_tokens
152
+ end
153
+ local _, tokens = parse.parse_tokens(parser_name(self), self.source, { language = self:parse().language })
141
154
  return tokens
142
155
  end
143
156
 
144
- function M.read(path)
157
+ -- Transient sites use the same alias/literal resolver as relationship queries.
158
+ function Doc:dispatch(names)
159
+ return parse.parse(parser_name(self), self.source, { dispatch = names, dispatch_only = true, language = self:parse().language })
160
+ end
161
+
162
+ -- An indexed target must still match its raw on-disk snapshot before decoding.
163
+ function M.read(path, indexed)
145
164
  local f = io.open(path, 'rb')
146
165
  if not f then return nil end
147
166
  local raw = f:read(M.MAX_BYTES + 1); f:close()
148
167
  if not raw or #raw > M.MAX_BYTES then return nil end
168
+ if indexed then
169
+ local crc = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
170
+ assert(#raw == indexed.size and crc == indexed.crc, 'source changed during query; retry: ' .. indexed.path)
171
+ end
149
172
  local source = xutils.to_utf8(raw)
150
173
  if not source then return nil end
151
- return M.new(M.uri(path), source)
174
+ return M.new(M.uri(path), source, nil, indexed and indexed.language)
152
175
  end
153
176
 
154
177
  return M