@codua/codeoutline-win32-x64 0.2.6 → 0.3.0

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 (73) hide show
  1. package/README.md +205 -3
  2. package/README.zh-CN.md +40 -2
  3. package/bin/xnet.exe +0 -0
  4. package/build-info.json +1 -1
  5. package/package.json +1 -1
  6. package/scripts/codeoutline/affected.lua +145 -0
  7. package/scripts/codeoutline/automatic_events.lua +202 -0
  8. package/scripts/codeoutline/cache_repairs.lua +47 -0
  9. package/scripts/codeoutline/callers.lua +56 -16
  10. package/scripts/codeoutline/cargo_toml.lua +125 -0
  11. package/scripts/codeoutline/command.lua +26 -4
  12. package/scripts/codeoutline/common.lua +48 -7
  13. package/scripts/codeoutline/completion.lua +126 -22
  14. package/scripts/codeoutline/coverage.lua +63 -0
  15. package/scripts/codeoutline/cpp_bindings.lua +46 -11
  16. package/scripts/codeoutline/cpp_fragments.lua +143 -0
  17. package/scripts/codeoutline/cpp_implementations.lua +340 -0
  18. package/scripts/codeoutline/cpp_includes.lua +156 -0
  19. package/scripts/codeoutline/cpp_macros.lua +279 -0
  20. package/scripts/codeoutline/cpp_receivers.lua +342 -0
  21. package/scripts/codeoutline/cpp_types.lua +285 -29
  22. package/scripts/codeoutline/definition_candidates.lua +186 -0
  23. package/scripts/codeoutline/dispatch_aliases.lua +10 -5
  24. package/scripts/codeoutline/documents.lua +22 -9
  25. package/scripts/codeoutline/explore.lua +243 -122
  26. package/scripts/codeoutline/external_headers.lua +176 -0
  27. package/scripts/codeoutline/foreign.lua +23 -3
  28. package/scripts/codeoutline/function_values.lua +69 -0
  29. package/scripts/codeoutline/go_methods.lua +931 -0
  30. package/scripts/codeoutline/go_modules.lua +329 -0
  31. package/scripts/codeoutline/graph.lua +322 -67
  32. package/scripts/codeoutline/implementations.lua +403 -0
  33. package/scripts/codeoutline/index.lua +161 -28
  34. package/scripts/codeoutline/index_worker.lua +11 -4
  35. package/scripts/codeoutline/indirect.lua +4 -2
  36. package/scripts/codeoutline/js_evidence.lua +2 -1
  37. package/scripts/codeoutline/js_resolution.lua +40 -12
  38. package/scripts/codeoutline/js_workspace.lua +325 -0
  39. package/scripts/codeoutline/lang/c.lua +15 -2
  40. package/scripts/codeoutline/lang/cpp.lua +32 -18
  41. package/scripts/codeoutline/lang/csharp.lua +1 -1
  42. package/scripts/codeoutline/lang/js.lua +56 -20
  43. package/scripts/codeoutline/lang/rust.lua +9 -1
  44. package/scripts/codeoutline/language_detect.lua +100 -0
  45. package/scripts/codeoutline/lsp.lua +173 -23
  46. package/scripts/codeoutline/lua_bindings.lua +151 -47
  47. package/scripts/codeoutline/lua_callback_loops.lua +210 -0
  48. package/scripts/codeoutline/main.lua +32 -7
  49. package/scripts/codeoutline/mcp.lua +52 -9
  50. package/scripts/codeoutline/navigation.lua +351 -65
  51. package/scripts/codeoutline/on_demand.lua +93 -0
  52. package/scripts/codeoutline/ordinary_bindings.lua +210 -34
  53. package/scripts/codeoutline/parse.lua +18 -2
  54. package/scripts/codeoutline/parse_pool.lua +1 -1
  55. package/scripts/codeoutline/parse_worker.lua +1 -1
  56. package/scripts/codeoutline/python_bindings.lua +2 -2
  57. package/scripts/codeoutline/query_filters.lua +65 -0
  58. package/scripts/codeoutline/query_report.lua +56 -19
  59. package/scripts/codeoutline/resolution.lua +23 -0
  60. package/scripts/codeoutline/rust_packages.lua +203 -0
  61. package/scripts/codeoutline/rust_resolution.lua +301 -0
  62. package/scripts/codeoutline/search_ranking.lua +70 -0
  63. package/scripts/codeoutline/service.lua +47 -7
  64. package/scripts/codeoutline/shared_events.lua +369 -0
  65. package/scripts/codeoutline/static_dispatch.lua +46 -11
  66. package/scripts/codeoutline/text.lua +3 -2
  67. package/scripts/codeoutline/ts_implementations.lua +81 -0
  68. package/scripts/codeoutline/type_bases.lua +61 -0
  69. package/scripts/codeoutline/type_hierarchy.lua +324 -0
  70. package/scripts/codeoutline/type_references.lua +291 -0
  71. package/scripts/codeoutline/type_uses.lua +260 -0
  72. package/scripts/codeoutline/update_sequence.lua +1 -1
  73. package/scripts/codeoutline/version.lua +1 -1
@@ -0,0 +1,93 @@
1
+ -- Explicit unknown-suffix files live in a bounded query overlay, never in idx.
2
+ local M = { MAX_FILES = 4, MAX_BYTES = 2 * 1048576, MAX_PROBES = 16 }
3
+ local graph = require('codeoutline.graph')
4
+ local parse = require('codeoutline.parse')
5
+ local documents = require('codeoutline.documents')
6
+ local paths = require('codeoutline.path')
7
+ local control = require('codeoutline.control')
8
+
9
+ local function fork(G)
10
+ local V = setmetatable({}, { __index = G })
11
+ for _, key in ipairs({ 'files', 'file_index', 'file_dir', 'dir_ids', 'nodes', 'node_file', 'id_of', 'children' }) do
12
+ V[key] = setmetatable({}, { __index = G[key] })
13
+ end
14
+ for _, key in ipairs({ 'by_name', 'by_lname', 'by_qualified', 'by_owner', 'by_base', 'by_stem',
15
+ 'pkg_files', 'dir_files', 'dir_by_base', 'ns_files' }) do
16
+ local base = G[key]
17
+ V[key] = setmetatable({}, { __index = function(t, name)
18
+ local old = base[name]
19
+ if not old then return nil end
20
+ local list = {}; for i, value in ipairs(old) do list[i] = value end
21
+ rawset(t, name, list); return list
22
+ end })
23
+ end
24
+ V.file_order = {}
25
+ for i, f in ipairs(G.file_order) do
26
+ if i % 4096 == 0 then control.check() end
27
+ V.file_order[i] = f
28
+ end
29
+ V.query_base_names = G.by_name
30
+ return V
31
+ end
32
+
33
+ function M.open(G, idx, query)
34
+ local result = { files = {}, rejected = {}, truncated = false }
35
+ local candidates, seen = {}, {}
36
+ local function add(value)
37
+ value = value:gsub('^path:', ''):gsub('[,;?]+$', ''):gsub('\\', '/')
38
+ if value:match('%.[%w_]+$') and not parse.language(value) and not seen[value] then
39
+ seen[value] = true; candidates[#candidates + 1] = value
40
+ end
41
+ end
42
+ for value in query:gmatch('"([^"]+)"') do add(value) end
43
+ for value in query:gsub('"[^"]+"', ''):gmatch('%S+') do add(value) end
44
+ local records, sources, V, bytes = {}, {}, nil, 0
45
+ for i, written in ipairs(candidates) do
46
+ if i > M.MAX_PROBES then result.truncated = true; break end
47
+ control.check()
48
+ local full = written:match('^%a:/') or written:sub(1, 1) == '/' and written
49
+ full = full and written or idx.root .. '/' .. written
50
+ local real = xutils.realpath(full)
51
+ real = real and paths.normalize(real)
52
+ if real and paths.contains(idx.root, real) then
53
+ local rel = real:sub(#idx.root + 2)
54
+ local stat = xutils.stat(real)
55
+ if not G.file_index[rel] and not records[rel] and stat and stat.type == 'file' then
56
+ if #result.files >= M.MAX_FILES or stat.size > 1048576 or bytes + stat.size > M.MAX_BYTES then
57
+ result.truncated = true
58
+ else
59
+ local doc = documents.read(real)
60
+ local filters = require('codeoutline.query_filters').parse(query)
61
+ local hint = #filters.languages == 1 and filters.languages[1] or nil
62
+ local rec = doc and parse.parse(rel, doc.source, { detect = true, language = hint, ordinary_bindings = true })
63
+ if rec then
64
+ -- Validate the raw file when the result is rendered too.
65
+ local file = assert(io.open(real, 'rb')); local raw = file:read(1048577); file:close()
66
+ assert(#raw <= 1048576 and bytes + #raw <= M.MAX_BYTES, 'source grew beyond query limits: ' .. rel)
67
+ local current = assert(documents.read(real))
68
+ assert(current.source == doc.source, 'source changed during query; retry: ' .. rel)
69
+ rec.size = #raw
70
+ if rec.language_source == 'editor' then rec.language_source = 'query' end
71
+ rec.crc = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
72
+ records[rel], sources[rel], bytes = rec, doc.source, bytes + #raw
73
+ V = V or fork(G)
74
+ graph.add_file(V, rel, rec)
75
+ result.files[#result.files + 1] = { path = rel, language = rec.language, basis = rec.language_source }
76
+ else result.rejected[#result.rejected + 1] = { path = rel, reason = 'language not confidently identified' } end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ if not V then return G, idx, result end
82
+ local transient = setmetatable({ root = idx.root }, { __index = idx })
83
+ function transient:query_source(rel)
84
+ if records[rel] then
85
+ assert(documents.read(idx.root .. '/' .. rel, records[rel]), 'cannot read source: ' .. rel)
86
+ return sources[rel], false
87
+ end
88
+ return idx:query_source(rel)
89
+ end
90
+ return V, transient, result
91
+ end
92
+
93
+ return M
@@ -1,7 +1,7 @@
1
1
  -- Ordinary binding evidence belongs to one query, never to the resident index.
2
2
  local M = {}
3
3
  local control = require('codeoutline.control')
4
- local function js(rec) return rec.language == 'javascript' or rec.language == 'typescript' end
4
+ local function js(rec) return rec.language == 'javascript' or rec.language == 'typescript' or rec.language == 'arkts' end
5
5
  local function evidence(rec, i)
6
6
  local refs = rec.refs
7
7
  return refs.binding and refs.binding[i] or refs.lua_binding and refs.lua_binding[i]
@@ -10,9 +10,41 @@ end
10
10
 
11
11
  function M.context(G, ctx, source, options)
12
12
  options = options or {}
13
- local cache, order, bytes = {}, {}, 0
13
+ local storage = options.cache or { entries = {}, order = {}, bytes = 0 }
14
+ local cache, order = storage.entries, storage.order
15
+ local validated = {}
14
16
  local max_files, max_bytes = options.max_files or 16, options.max_bytes or 8 * 1024 * 1024
15
- local C = { stats = { parses = 0, files = 0, bytes = 0 } }
17
+ while #order > 0 and (#order > max_files or storage.bytes > max_bytes) do
18
+ local old = table.remove(order, 1); storage.bytes = storage.bytes - cache[old].weight; cache[old] = nil
19
+ end
20
+ local C = { stats = { parses = 0, files = 0, bytes = 0, alias_files = 0, alias_bytes = 0 } }
21
+ -- A query may visit more headers than the shared full-evidence FIFO holds.
22
+ -- Retain only their small, validated alias lists for this query, so looking
23
+ -- up another name does not repeatedly parse the same evicted headers.
24
+ local query_aliases = {}
25
+ local max_alias_files, max_alias_bytes = options.max_alias_files or 256, options.max_alias_bytes or 1048576
26
+ local function alias_list(rec, list)
27
+ list = list or {}
28
+ if not query_aliases[rec.nodes] then
29
+ local weight = 64 + #list * 128
30
+ for _, alias in ipairs(list) do
31
+ weight = weight + #(alias.name or '') + #(alias.target or '') + #(alias.scope or '')
32
+ end
33
+ if C.stats.alias_files < max_alias_files and C.stats.alias_bytes + weight <= max_alias_bytes then
34
+ query_aliases[rec.nodes] = list
35
+ C.stats.alias_files, C.stats.alias_bytes = C.stats.alias_files + 1, C.stats.alias_bytes + weight
36
+ end
37
+ end
38
+ return list
39
+ end
40
+ function C.available(f)
41
+ local rec = G.files[f]
42
+ return rec.ordinary_bindings or rec.size ~= nil or source ~= nil
43
+ end
44
+ function C.source_size(f)
45
+ local draft = source and source(f)
46
+ return draft and #draft or G.files[f].size
47
+ end
16
48
  local hints = {}
17
49
  local function alias_hints(f)
18
50
  if hints[f] and hints[f].record == G.files[f] then return hints[f].roots end
@@ -23,11 +55,8 @@ function M.context(G, ctx, source, options)
23
55
  hints[f] = { record = G.files[f], roots = result }
24
56
  return result
25
57
  end
26
- function C.data(f)
58
+ local function read_source(f)
27
59
  local rec = G.files[f]
28
- if rec.ordinary_bindings then return rec end -- explicit in-memory parse
29
- if cache[f] and cache[f].record == rec then return cache[f].data end
30
- if not G.root and not source then return rec end
31
60
  control.check()
32
61
  local raw = source and source(f)
33
62
  if not raw then
@@ -39,8 +68,109 @@ function M.context(G, ctx, source, options)
39
68
  raw = assert(xutils.to_utf8(raw, rec.encoding == 'gbk' and 'gbk' or 'auto'))
40
69
  end
41
70
  end
71
+ return raw
72
+ end
73
+ local function cached_data(rec, raw)
74
+ local key, entry = rec.nodes, cache[rec.nodes]
75
+ if not entry then return nil end
76
+ if not validated[key] then
77
+ if not raw then return nil end
78
+ local checksum = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
79
+ if entry.checksum ~= checksum or entry.size ~= #raw or entry.language ~= rec.language then return nil end
80
+ validated[key] = true
81
+ end
82
+ C.stats.files, C.stats.bytes = #order, storage.bytes
83
+ return entry.data
84
+ end
85
+ local function remember(rec, raw, data, weight)
86
+ local key = rec.nodes
87
+ if cache[key] then
88
+ storage.bytes = storage.bytes - cache[key].weight; cache[key] = nil
89
+ for i, old in ipairs(order) do if old == key then table.remove(order, i); break end end
90
+ end
91
+ while #order > 0 and (#order >= max_files or storage.bytes + weight > max_bytes) do
92
+ local old = table.remove(order, 1); storage.bytes = storage.bytes - cache[old].weight; cache[old] = nil
93
+ end
94
+ if weight <= max_bytes then
95
+ local checksum = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
96
+ cache[key] = { data = data, weight = weight, checksum = checksum, size = #raw, language = rec.language }
97
+ order[#order + 1] = key; storage.bytes = storage.bytes + weight; validated[key] = true
98
+ end
99
+ C.stats.parses, C.stats.files, C.stats.bytes = C.stats.parses + 1, #order, storage.bytes
100
+ return data
101
+ end
102
+ function C.cpp_aliases(f)
103
+ local rec = G.files[f]
104
+ if rec.ordinary_bindings or not G.root and not source then return rec.cpp_aliases or {} end
105
+ local cached = cached_data(rec)
106
+ if cached then return alias_list(rec, cached.cpp_aliases) end
107
+ if query_aliases[rec.nodes] then return query_aliases[rec.nodes] end
108
+ local raw = read_source(f)
109
+ cached = cached_data(rec, raw)
110
+ if cached then return alias_list(rec, cached.cpp_aliases) end
42
111
  local parsed = assert(require('codeoutline.parse').parse(rec.path, raw,
43
- { ranges = false, ordinary_bindings = true }))
112
+ { ranges = false, omit_signatures = true, cpp_aliases_only = true, language = rec.language }))
113
+ assert(#parsed.nodes == #rec.nodes, 'source changed; refresh index before alias query: ' .. rec.path)
114
+ for i, n in ipairs(parsed.nodes) do
115
+ assert(n.qualified == rec.nodes[i].qualified and n.line == rec.nodes[i].line,
116
+ 'source changed; refresh index before alias query: ' .. rec.path)
117
+ end
118
+ local data = remember(rec, raw, { cpp_aliases = parsed.cpp_aliases, cpp_aliases_only = true },
119
+ #raw + #(parsed.cpp_aliases or {}) * 256)
120
+ return alias_list(rec, data.cpp_aliases)
121
+ end
122
+ function C.macros(f)
123
+ local rec = G.files[f]
124
+ if rec.cpp_macros then return rec.cpp_macros end
125
+ local cached = cached_data(rec)
126
+ if cached and not cached.cpp_aliases_only then return cached.cpp_macros end
127
+ if not G.root and not source then return nil end
128
+ local raw = read_source(f)
129
+ cached = cached_data(rec, raw)
130
+ if cached and not cached.cpp_aliases_only then return cached.cpp_macros end
131
+ -- Macro visibility needs directive events, not a second syntax tree,
132
+ -- receiver bindings or implementation evidence for the whole header.
133
+ return require('codeoutline.cpp_macros').summary(rec, raw)
134
+ end
135
+ -- Inheritance queries need class headers and aliases, not every call,
136
+ -- receiver, type-use site and method signature in the file.
137
+ function C.hierarchy(f)
138
+ local rec = G.files[f]
139
+ if rec.language ~= 'cpp' or rec.ordinary_bindings or not G.root and not source then return C.data(f) end
140
+ local cached = cached_data(rec)
141
+ if cached and (not cached.cpp_aliases_only or cached.implementation_evidence) then return cached end
142
+ local raw = read_source(f)
143
+ cached = cached_data(rec, raw)
144
+ if cached and (not cached.cpp_aliases_only or cached.implementation_evidence) then return cached end
145
+ local parsed, T = require('codeoutline.parse').parse_tokens(rec.path, raw,
146
+ { ranges = false, cpp_aliases_only = true, language = rec.language })
147
+ local function check(ok) assert(ok, 'source changed; refresh index before hierarchy query: ' .. rec.path) end
148
+ check(parsed and #parsed.nodes == #rec.nodes)
149
+ local evidence, count = {}, 0
150
+ for i, n in ipairs(parsed.nodes) do
151
+ if i % 128 == 0 then control.check() end
152
+ check(n.qualified == rec.nodes[i].qualified and n.line == rec.nodes[i].line)
153
+ if n.kind == 'class' or n.kind == 'struct' then
154
+ evidence[i] = { at = T.s[n.ti] - 1,
155
+ hierarchy_bases = require('codeoutline.type_bases').collect(T, n, rec.language) }
156
+ count = count + 1
157
+ end
158
+ end
159
+ return remember(rec, raw, { cpp_aliases = parsed.cpp_aliases, cpp_aliases_only = true,
160
+ implementation_evidence = evidence }, #raw + count * 256 + #(parsed.cpp_aliases or {}) * 256)
161
+ end
162
+ function C.data(f)
163
+ local rec = G.files[f]
164
+ if rec.ordinary_bindings then return rec end -- explicit in-memory parse
165
+ local cached = cached_data(rec)
166
+ if cached and not cached.cpp_aliases_only then return cached end
167
+ if not G.root and not source then return rec end
168
+ local raw = read_source(f)
169
+ cached = cached_data(rec, raw)
170
+ if cached and not cached.cpp_aliases_only then return cached end
171
+ local parsed = options.parsed and options.parsed(f)
172
+ parsed = parsed or assert(require('codeoutline.parse').parse(rec.path, raw,
173
+ { ranges = false, ordinary_bindings = true, language = rec.language }))
44
174
  local function check(ok) assert(ok, 'source changed; refresh index before binding query: ' .. rec.path) end
45
175
  check(#parsed.nodes == #rec.nodes and #parsed.refs.name == #rec.refs.name)
46
176
  for i, n in ipairs(parsed.nodes) do
@@ -51,41 +181,87 @@ function M.context(G, ctx, source, options)
51
181
  and parsed.refs.line[i] == rec.refs.line[i] and parsed.refs.kind[i] == rec.refs.kind[i])
52
182
  end
53
183
  -- Keep only compact query evidence; source, tokens, and duplicate symbols die here.
54
- local data = { refs = { binding = parsed.refs.binding, js_receiver = parsed.refs.js_receiver },
184
+ local data = { refs = { binding = parsed.refs.binding, js_receiver = parsed.refs.js_receiver, lua_binding = parsed.refs.lua_binding },
55
185
  js_exports = parsed.js_exports, python_imports = parsed.python_imports, cpp_aliases = parsed.cpp_aliases,
56
186
  csharp_usings = parsed.csharp_usings, csharp_statics = parsed.csharp_statics,
57
187
  csharp_scopes = parsed.csharp_scopes, csharp_parameters = parsed.csharp_parameters, csharp_access = parsed.csharp_access }
188
+ data.implementation_evidence = parsed.implementation_evidence
189
+ data.lua_locals = parsed.lua_locals
190
+ data.static_dispatch = parsed.static_dispatch
191
+ data.type_sites, data.type_parameters = parsed.type_sites, parsed.type_parameters
192
+ data.type_exclusions = parsed.type_exclusions
193
+ data.go_methods = parsed.go_methods
194
+ data.cpp_receivers = parsed.cpp_receivers
195
+ data.cpp_macros = parsed.cpp_macros
196
+ data.automatic_events = parsed.automatic_events
197
+ data.shared_events = parsed.shared_events
198
+ data.lua_callback_loops = parsed.lua_callback_loops
199
+ data.rust_imports, data.rust_public = parsed.rust_imports, parsed.rust_public
200
+ local type_count = 0; for _ in pairs(parsed.type_sites or {}) do type_count = type_count + 1 end
201
+ local static_count = 0
202
+ for _, site in ipairs(parsed.static_dispatch and parsed.static_dispatch.sites or {}) do
203
+ static_count = static_count + 1 + #site.registrations
204
+ end
58
205
  local weight = #raw + #parsed.refs.name * 128 + #(parsed.js_exports or {}) * 256
206
+ + type_count * 256 + #(parsed.type_parameters or {}) * 96
207
+ + static_count * 256
208
+ + #(parsed.lua_locals or {}) * 256
59
209
  + #(parsed.python_imports or {}) * 256 + #(parsed.cpp_aliases or {}) * 256
60
210
  + #(parsed.csharp_usings or {}) * 256 + #(parsed.csharp_scopes or {}) * 256
61
- + #(parsed.csharp_parameters or {}) * 128 + #parsed.nodes * (rec.language == 'csharp' and 32 or 0)
62
- if cache[f] then
63
- bytes = bytes - cache[f].weight; cache[f] = nil
64
- for i, old in ipairs(order) do if old == f then table.remove(order, i); break end end
65
- end
66
- while #order > 0 and (#order >= max_files or bytes + weight > max_bytes) do
67
- local old = table.remove(order, 1); bytes = bytes - cache[old].weight; cache[old] = nil
68
- end
69
- if weight <= max_bytes then
70
- cache[f] = { record = rec, data = data, weight = weight }
71
- order[#order + 1] = f; bytes = bytes + weight
72
- end
73
- C.stats.parses, C.stats.files, C.stats.bytes = C.stats.parses + 1, #order, bytes
74
- return data
211
+ + #(parsed.csharp_parameters or {}) * 128 + #parsed.nodes * (parsed.implementation_evidence and 256 or 0)
212
+ + #(parsed.rust_imports or {}) * 256 + #(parsed.rust_public or {}) * 32
213
+ + #(parsed.cpp_macros or {}) * 256
214
+ + (parsed.go_methods and (#parsed.nodes * 384 + #parsed.go_methods.bindings * 256
215
+ + (parsed.go_methods.receiver_weight or 0)) or 0)
216
+ + (parsed.cpp_receivers and parsed.cpp_receivers.weight or 0)
217
+ + #(parsed.automatic_events or {}) * 512
218
+ + (parsed.shared_events and parsed.shared_events.weight or 0)
219
+ + (parsed.lua_callback_loops and parsed.lua_callback_loops.weight or 0)
220
+ return remember(rec, raw, data, weight)
75
221
  end
76
222
  function C.evidence(f, i)
77
223
  local rec = G.files[f]
78
224
  local value = evidence(rec, i)
225
+ if rec.language == 'go' and not C.available(f) then return value end
226
+ if rec.language == 'go' then
227
+ local data = require('codeoutline.go_methods').context(G, ctx).data(f)
228
+ if not data then return 'go:?' end
229
+ return data.evidence[i] or value
230
+ end
79
231
  local kind = rec.refs.kind[i]
80
- if kind ~= 'call' and kind ~= 'member_call' and not (rec.language == 'csharp' and kind == 'new') then return value end
81
- -- JS already keeps receiver barriers. Only a bare blocked call can be
82
- -- a newly supported lexical alias; typed/member calls need no reparse.
83
- if js(rec) and (kind ~= 'call' or value ~= '?') then return value end
84
- if js(rec) and not next(alias_hints(f)) then return value end
232
+ if kind ~= 'call' and kind ~= 'member_call' and not (rec.language == 'csharp' and kind == 'new')
233
+ and kind ~= 'ref' then return value end
234
+ if rec.language == 'lua' then
235
+ if rec.refs.lua_binding then return value end
236
+ local wanted = rec.refs.recv[i] or rec.refs.name[i]
237
+ for _, imp in ipairs(rec.lua_imports or {}) do
238
+ if imp.member == rec.refs.name[i] then return evidence(C.data(f), i) or value end
239
+ end
240
+ for _, name in ipairs(rec.lua_binding_names or {}) do
241
+ if name == wanted then return evidence(C.data(f), i) or value end
242
+ end
243
+ return value
244
+ end
245
+ -- Explicit in-memory parses may already carry receiver evidence. Base
246
+ -- index records keep only imports/exports; their barriers are lazy.
247
+ if js(rec) and rec.refs.js_receiver then
248
+ if kind ~= 'ref' and (kind ~= 'call' or value ~= '?') then return value end
249
+ if kind ~= 'ref' and not next(alias_hints(f)) then return value end
250
+ end
85
251
  local recv = rec.refs.recv[i]
252
+ if (rec.language == 'c' or rec.language == 'cpp') and kind == 'member_call' and not recv then
253
+ local data = require('codeoutline.cpp_receivers').context(G, ctx).data(f)
254
+ if not data then return value end
255
+ return data.evidence[i] or value
256
+ end
257
+ if rec.language == 'c' and kind == 'member_call' then return evidence(C.data(f), i) or value end
86
258
  if rec.language == 'python' and (recv == 'self' or recv == 'cls') then return value end
87
- if rec.language == 'cpp' and (not recv or recv == 'this') then return value end
88
- if js(rec) or rec.language == 'python' or rec.language == 'csharp' or rec.language == 'cpp' and kind == 'member_call' then
259
+ if rec.language == 'cpp' and recv == 'this' then return value end
260
+ if rec.language == 'rust' and require('codeoutline.rust_packages').owner(G, f, ctx) then
261
+ return require('codeoutline.rust_packages').guard(ctx, function() return evidence(C.data(f), i) or value end) or value
262
+ end
263
+ if js(rec) or rec.language == 'python' or rec.language == 'csharp' or rec.language == 'cpp'
264
+ or (rec.language == 'java' or rec.language == 'kotlin') and (kind == 'member_call' or kind == 'ref') then
89
265
  return evidence(C.data(f), i) or value
90
266
  end
91
267
  return value
@@ -93,7 +269,7 @@ function M.context(G, ctx, source, options)
93
269
 
94
270
  -- Renamed calls can only originate in the target file or an import chain
95
271
  -- leading to it. Build this cheap reverse map from existing import records.
96
- -- No source is opened while constructing the candidate set.
272
+ -- No indexed source is opened; workspace lookup may read package manifests.
97
273
  local reverse
98
274
  function C.candidates(wanted)
99
275
  local found, queue = {}, {}
@@ -116,7 +292,7 @@ function M.context(G, ctx, source, options)
116
292
  local rec = G.files[f]
117
293
  control.check()
118
294
  if js(rec) then
119
- for _, imp in ipairs(rec.imports) do add(f, require('codeoutline.js_resolution').module(G, f, imp.path, ctx)) end
295
+ for _, imp in ipairs(rec.imports) do add(f, require('codeoutline.js_resolution').module(G, f, imp.path, ctx, imp.kind)) end
120
296
  elseif rec.language == 'python' then
121
297
  local module = require('codeoutline.python_bindings').module
122
298
  for _, imp in ipairs(rec.imports) do
@@ -188,8 +364,8 @@ function M.context(G, ctx, source, options)
188
364
  for name in pairs(imports) do if roots[name] then analyze = true; break end end
189
365
  end
190
366
  for i, kind in ipairs(rec.refs.kind) do
191
- if kind == 'call' or kind == 'member_call' or imports[rec.refs.name[i]] or imports[rec.refs.recv[i]] then
192
- local value = analyze and C.evidence(f, i) or evidence(rec, i)
367
+ if kind == 'call' or kind == 'member_call' or kind == 'ref' or imports[rec.refs.name[i]] or imports[rec.refs.recv[i]] then
368
+ local value = (analyze or kind == 'ref') and C.evidence(f, i) or evidence(rec, i)
193
369
  local path = value and (value:match('^import:(.-)%z') or value:match('^py:import:(.-)%z'))
194
370
  if path then
195
371
  local resolver = js(rec) and require('codeoutline.js_resolution') or require('codeoutline.python_bindings')
@@ -25,12 +25,13 @@ M.EXTENSIONS = {
25
25
  go = 'go',
26
26
  js = 'javascript', jsx = 'javascript', mjs = 'javascript', cjs = 'javascript',
27
27
  ts = 'typescript', tsx = 'typescript', mts = 'typescript', cts = 'typescript',
28
+ ets = 'arkts',
28
29
  cs = 'csharp',
29
30
  rs = 'rust',
30
31
  }
31
32
 
32
33
  -- Languages sharing one parser module; the language name is passed along.
33
- local MODULE = { javascript = 'js', typescript = 'js' }
34
+ local MODULE = { javascript = 'js', typescript = 'js', arkts = 'js' }
34
35
 
35
36
  function M.language(path)
36
37
  local ext = path:match('%.([%w]+)$')
@@ -40,12 +41,27 @@ end
40
41
  -- Returns the record and its tokens; positions in both exclude a UTF-8 BOM.
41
42
  function M.parse_tokens(path, src, opts)
42
43
  local lang = M.language(path)
44
+ local inferred, cpp_syntax
45
+ if not lang and opts and (opts.language or opts.detect) then
46
+ lang, inferred = require('codeoutline.language_detect').resolve(src, opts.language, opts.detect)
47
+ end
43
48
  if not lang then return nil end
49
+ if opts and opts.cpp_fragment then
50
+ assert(not M.language(path) and (opts.cpp_fragment == 'c' or opts.cpp_fragment == 'cpp'))
51
+ if src:find('\0', 1, true) then return nil end
52
+ local detected = require('codeoutline.language_detect').resolve(src, nil, true)
53
+ if detected and detected ~= 'c' and detected ~= 'cpp' then return nil end
54
+ cpp_syntax = not not parser('cpp').looks_cpp(src)
55
+ if lang == 'c' and cpp_syntax then lang = 'cpp' end
56
+ end
44
57
  -- Strip a UTF-8 BOM so it is not read as part of the first token.
45
58
  if src:sub(1, 3) == '\239\187\191' then src = src:sub(4) end
46
59
  -- .h is shared by C and C++: sniff for C++-only syntax.
47
60
  if lang == 'c' and path:match('%.[hH]$') and parser('cpp').looks_cpp(src) then lang = 'cpp' end
48
- return parser(MODULE[lang] or lang).parse(path, src, lang, opts)
61
+ local rec, tokens = parser(MODULE[lang] or lang).parse(path, src, lang, opts)
62
+ if opts and opts.cpp_fragment then rec.cpp_fragment, rec.cpp_fragment_cpp = opts.cpp_fragment, cpp_syntax or nil
63
+ elseif inferred then rec.on_demand, rec.language_source = true, inferred end
64
+ return rec, tokens
49
65
  end
50
66
 
51
67
  -- opts.ranges=false emits compact index nodes; default parsing retains positions.
@@ -149,7 +149,7 @@ function M.run(jobs, max_bytes, on_result)
149
149
  chunk, bytes = {}, 0
150
150
  end
151
151
  for _, j in ipairs(bucket) do
152
- chunk[#chunk + 1] = { j.rel, j.abs, j.size or false, j.crc or false }
152
+ chunk[#chunk + 1] = { j.rel, j.abs, j.size or false, j.crc or false, j.language or false }
153
153
  bytes = bytes + j.weight
154
154
  if #chunk >= M.CHUNK_FILES or bytes >= M.CHUNK_BYTES then flush() end
155
155
  end
@@ -14,7 +14,7 @@ return {
14
14
  for i, f in ipairs(files) do
15
15
  -- An abandoned pass (cancelled, failed, shutting down) skips its rest.
16
16
  if shared:get('shutdown') or (shared:get('parse_abort') or 0) >= token then return end
17
- local res = index.load_file(f[2], f[1], max_bytes, f[3] or nil, f[4] or nil)
17
+ local res = index.load_file(f[2], f[1], max_bytes, f[3] or nil, f[4] or nil, f[5] or nil)
18
18
  res.rel = f[1]
19
19
  results[i] = res
20
20
  end
@@ -24,13 +24,13 @@ function M.collect(r, T)
24
24
  end
25
25
  for i, ref in ipairs(r.refs) do
26
26
  if i % 128 == 0 then control.check() end
27
- if (ref.kind == 'call' or ref.kind == 'member_call') and ref.recv ~= 'self' and ref.recv ~= 'cls' then
27
+ if (ref.kind == 'call' or ref.kind == 'member_call' or ref.kind == 'ref') and ref.recv ~= 'self' and ref.recv ~= 'cls' then
28
28
  local symbol, first = ref.name, ref.tok
29
29
  while T:text(first - 1) == '.' and T.k[first - 2] == 'id' do
30
30
  symbol = T:text(first - 2) .. '.' .. symbol; first = first - 2
31
31
  end
32
32
  local value = expand({ symbol = symbol }, ref.tok)
33
- if value == false or ref.kind == 'member_call' and first == ref.tok then ref.binding = 'py:?'
33
+ if value == false or ref.recv and first == ref.tok then ref.binding = 'py:?'
34
34
  elseif value and value.import then
35
35
  ref.binding = 'py:import:' .. value.import.path .. '\0' .. value.member
36
36
  elseif value and value.node and not ref.recv then ref.binding = 'py:node:' .. value.node end
@@ -0,0 +1,65 @@
1
+ -- Seed selection only. These predicates never restrict graph expansion.
2
+ local M = {}
3
+ local fields = { kind = 'kinds', lang = 'languages', language = 'languages', path = 'paths', name = 'names' }
4
+ local aliases = { js = 'javascript', ts = 'typescript', py = 'python', ['c++'] = 'cpp', ['c#'] = 'csharp', cs = 'csharp', kt = 'kotlin', rs = 'rust' }
5
+ local languages = { c = true, cpp = true, csharp = true, javascript = true, typescript = true,
6
+ arkts = true, python = true, lua = true, kotlin = true, java = true, go = true, rust = true }
7
+
8
+ function M.parse(query)
9
+ local out = { text = '', kinds = {}, languages = {}, paths = {}, names = {}, count = 0 }
10
+ local words, at = {}, 1
11
+ while at <= #query do
12
+ local first = query:find('%S', at)
13
+ if not first then break end
14
+ local key, value_at = query:match('^([%a]+):()', first)
15
+ local field = key and fields[key:lower()]
16
+ if field then
17
+ local value, last
18
+ if query:sub(value_at, value_at) == '"' then
19
+ last = assert(query:find('"', value_at + 1, true), 'unterminated quoted query filter')
20
+ value = query:sub(value_at + 1, last - 1)
21
+ assert(last == #query or query:sub(last + 1, last + 1):match('%s'), 'query filter must end at whitespace')
22
+ else
23
+ last = (query:find('%s', value_at) or #query + 1) - 1
24
+ value = query:sub(value_at, last)
25
+ end
26
+ assert(value ~= '' and value:find('%S'), 'query filter value must not be empty')
27
+ value = value:lower()
28
+ if field == 'languages' then
29
+ value = aliases[value] or value
30
+ assert(languages[value], 'unsupported query language: ' .. value)
31
+ elseif field == 'paths' then value = value:gsub('\\', '/') end
32
+ out[field][#out[field] + 1] = value
33
+ out.count = out.count + 1
34
+ at = last + 1
35
+ else
36
+ local last = (query:find('%s', first) or #query + 1) - 1
37
+ words[#words + 1] = query:sub(first, last); at = last + 1
38
+ end
39
+ end
40
+ out.text = table.concat(words, ' ')
41
+ return out
42
+ end
43
+
44
+ local function matches(values, value, exact)
45
+ if #values == 0 then return true end
46
+ value = value:lower()
47
+ for _, wanted in ipairs(values) do
48
+ if exact and value == wanted or not exact and value:find(wanted, 1, true) then return true end
49
+ end
50
+ return false
51
+ end
52
+
53
+ function M.file(filters, rec)
54
+ return matches(filters.languages, rec.language, true) and matches(filters.paths, (rec.path:gsub('\\', '/')))
55
+ end
56
+
57
+ function M.node(filters, rec, node)
58
+ return M.file(filters, rec) and matches(filters.kinds, node.kind, true) and matches(filters.names, node.qualified)
59
+ end
60
+
61
+ function M.id(filters, G, id)
62
+ return filters.count == 0 or M.node(filters, G.files[G.node_file[id]], G.nodes[id])
63
+ end
64
+
65
+ return M