@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.
- package/README.md +205 -3
- package/README.zh-CN.md +40 -2
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/package.json +1 -1
- package/scripts/codeoutline/affected.lua +145 -0
- package/scripts/codeoutline/automatic_events.lua +202 -0
- package/scripts/codeoutline/cache_repairs.lua +47 -0
- package/scripts/codeoutline/callers.lua +56 -16
- package/scripts/codeoutline/cargo_toml.lua +125 -0
- package/scripts/codeoutline/command.lua +26 -4
- package/scripts/codeoutline/common.lua +65 -9
- package/scripts/codeoutline/completion.lua +221 -65
- package/scripts/codeoutline/coverage.lua +63 -0
- package/scripts/codeoutline/cpp_bindings.lua +151 -0
- package/scripts/codeoutline/cpp_fragments.lua +143 -0
- package/scripts/codeoutline/cpp_implementations.lua +340 -0
- package/scripts/codeoutline/cpp_includes.lua +156 -0
- package/scripts/codeoutline/cpp_macros.lua +279 -0
- package/scripts/codeoutline/cpp_receivers.lua +342 -0
- package/scripts/codeoutline/cpp_types.lua +456 -0
- package/scripts/codeoutline/csharp_bindings.lua +498 -0
- package/scripts/codeoutline/definition_candidates.lua +180 -0
- package/scripts/codeoutline/dispatch_aliases.lua +479 -0
- package/scripts/codeoutline/documents.lua +32 -9
- package/scripts/codeoutline/explore.lua +274 -119
- package/scripts/codeoutline/external_headers.lua +171 -0
- package/scripts/codeoutline/foreign.lua +79 -14
- package/scripts/codeoutline/foreign_lua.lua +146 -19
- package/scripts/codeoutline/function_values.lua +69 -0
- package/scripts/codeoutline/go_methods.lua +931 -0
- package/scripts/codeoutline/go_modules.lua +329 -0
- package/scripts/codeoutline/graph.lua +346 -63
- package/scripts/codeoutline/implementations.lua +403 -0
- package/scripts/codeoutline/index.lua +165 -27
- package/scripts/codeoutline/index_worker.lua +11 -4
- package/scripts/codeoutline/indirect.lua +116 -40
- package/scripts/codeoutline/js_evidence.lua +32 -3
- package/scripts/codeoutline/js_resolution.lua +72 -10
- package/scripts/codeoutline/js_workspace.lua +325 -0
- package/scripts/codeoutline/lang/c.lua +15 -2
- package/scripts/codeoutline/lang/cpp.lua +7 -4
- package/scripts/codeoutline/lang/csharp.lua +15 -3
- package/scripts/codeoutline/lang/js.lua +56 -20
- package/scripts/codeoutline/lang/rust.lua +9 -1
- package/scripts/codeoutline/language_detect.lua +100 -0
- package/scripts/codeoutline/lsp.lua +173 -23
- package/scripts/codeoutline/lua_bindings.lua +228 -54
- package/scripts/codeoutline/lua_callback_loops.lua +210 -0
- package/scripts/codeoutline/lua_literal.lua +38 -0
- package/scripts/codeoutline/main.lua +32 -7
- package/scripts/codeoutline/mcp.lua +52 -9
- package/scripts/codeoutline/navigation.lua +593 -147
- package/scripts/codeoutline/on_demand.lua +93 -0
- package/scripts/codeoutline/ordinary_bindings.lua +396 -0
- package/scripts/codeoutline/parse.lua +18 -2
- package/scripts/codeoutline/parse_pool.lua +1 -1
- package/scripts/codeoutline/parse_worker.lua +1 -1
- package/scripts/codeoutline/python_bindings.lua +112 -0
- package/scripts/codeoutline/query_filters.lua +65 -0
- package/scripts/codeoutline/query_report.lua +135 -8
- package/scripts/codeoutline/resolution.lua +23 -0
- package/scripts/codeoutline/rules.lua +127 -0
- package/scripts/codeoutline/rust_packages.lua +203 -0
- package/scripts/codeoutline/rust_resolution.lua +301 -0
- package/scripts/codeoutline/search_ranking.lua +70 -0
- package/scripts/codeoutline/service.lua +47 -7
- package/scripts/codeoutline/shared_events.lua +369 -0
- package/scripts/codeoutline/static_dispatch.lua +569 -0
- package/scripts/codeoutline/text.lua +3 -2
- package/scripts/codeoutline/ts_implementations.lua +81 -0
- package/scripts/codeoutline/type_bases.lua +61 -0
- package/scripts/codeoutline/type_hierarchy.lua +324 -0
- package/scripts/codeoutline/type_references.lua +290 -0
- package/scripts/codeoutline/type_uses.lua +260 -0
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
-- Query explicit type sites without a separate resident type-use graph.
|
|
2
|
+
local graph, control = require('codeoutline.graph'), require('codeoutline.control')
|
|
3
|
+
local M = { MAX_FILES = 64, MAX_BYTES = 8 * 1024 * 1024, MAX_NAMES = 32, MAX_SITES = 4096,
|
|
4
|
+
MAX_SCAN_FILES = 20000, MAX_SCAN_BYTES = 256 * 1024 * 1024, TIME_MS = 5000 }
|
|
5
|
+
M.kinds = { class = true, struct = true, union = true, interface = true, enum = true, record = true, typedef = true, annotation_type = true, trait = true }
|
|
6
|
+
local languages = require('codeoutline.type_uses').languages
|
|
7
|
+
function M.validate(query, opts)
|
|
8
|
+
local budget = require('codeoutline.explore').validate(query, opts)
|
|
9
|
+
assert(require('codeoutline.query_filters').parse(query).text ~= '', 'type references require an exact type name')
|
|
10
|
+
local cap = opts and opts.max_nodes or 200
|
|
11
|
+
assert(type(cap) == 'number' and cap % 1 == 0 and cap >= 1 and cap <= 2000, 'max_nodes must be an integer between 1 and 2000')
|
|
12
|
+
return budget
|
|
13
|
+
end
|
|
14
|
+
function M.resolve(G, f, from, site, ctx, details)
|
|
15
|
+
if site.value_shadowed and not site.elaborated then return {}, 'value binding' end
|
|
16
|
+
local language, written = G.files[f].language, site.written
|
|
17
|
+
local data, head = details or ctx.ordinary.data(f), written:match('^([%w_$]+)')
|
|
18
|
+
for _, p in ipairs(data.type_parameters or {}) do
|
|
19
|
+
if p.name == head and p.first <= site.at and site.at <= p.last then return {}, 'type parameter' end
|
|
20
|
+
end
|
|
21
|
+
local scope = from and from > 0 and G.nodes[from] and G.nodes[from].qualified or ''
|
|
22
|
+
local ids
|
|
23
|
+
if language == 'cpp' then
|
|
24
|
+
ids = require('codeoutline.cpp_types').resolve(G, f, written, { context = ctx, scope = scope, at = site.at, accept = M.kinds, definitions = true })
|
|
25
|
+
elseif language == 'c' then
|
|
26
|
+
local visible = graph.visible_dependencies(G, f, ctx); ids = {}
|
|
27
|
+
local own = {}
|
|
28
|
+
for _, id in ipairs(G.by_name[written] or {}) do
|
|
29
|
+
local cf = G.node_file[id]
|
|
30
|
+
local kind = G.nodes[id].kind
|
|
31
|
+
if (cf == f or visible[cf]) and (site.elaborated and kind == site.elaborated or not site.elaborated and kind == 'typedef')
|
|
32
|
+
and (G.files[cf].language == 'c' or G.files[cf].language == 'cpp') then
|
|
33
|
+
if cf == f and G.nodes[id].line <= site.line then own[#own + 1] = id
|
|
34
|
+
elseif cf ~= f then ids[#ids + 1] = id end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
if #own > 0 then ids = own end
|
|
38
|
+
elseif language == 'go' then ids = require('codeoutline.go_methods').context(G, ctx).types(f, written)
|
|
39
|
+
elseif language == 'rust' then
|
|
40
|
+
local resolver = require('codeoutline.rust_resolution')
|
|
41
|
+
local entry = resolver.path(G, f, written, ctx, resolver.scope(G, f, from)); ids = entry and entry.ids or {}
|
|
42
|
+
if not entry and not require('codeoutline.rust_packages').owner(G, f, ctx) then
|
|
43
|
+
for _, id in ipairs(G.by_name[written] or {}) do
|
|
44
|
+
if G.node_file[id] == f and G.nodes[id].qualified == written then ids[#ids + 1] = id end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
elseif language == 'typescript' or language == 'arkts' then
|
|
48
|
+
ids = require('codeoutline.ts_implementations').types(G, f, written, ctx)
|
|
49
|
+
if #ids == 0 then
|
|
50
|
+
for _, imp in ipairs(G.files[f].js_imports or {}) do
|
|
51
|
+
if imp.local_name == written and imp.imported ~= '*' then ids = require('codeoutline.js_resolution').imported(G, f, imp.path, imp.imported, ctx); break end
|
|
52
|
+
end
|
|
53
|
+
if #ids == 0 then
|
|
54
|
+
for _, id in ipairs(G.by_name[written] or {}) do if G.node_file[id] == f and not G.nodes[id].parent then ids[#ids + 1] = id end end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
else ids = require('codeoutline.implementations').types(G, f, written, ctx, scope, site.at) end
|
|
58
|
+
local result = {}
|
|
59
|
+
for _, id in ipairs(ids or {}) do if M.kinds[G.nodes[id].kind] then result[#result + 1] = id end end
|
|
60
|
+
return result, #result > 1 and 'ambiguous type' or #result == 0 and 'unresolved type' or nil
|
|
61
|
+
end
|
|
62
|
+
local function describe(G, id)
|
|
63
|
+
return { id = id, name = G.nodes[id].qualified, file = G.files[G.node_file[id]].path, line = G.nodes[id].line }
|
|
64
|
+
end
|
|
65
|
+
function M.query(G, idx, targets, opts)
|
|
66
|
+
opts = opts or {}
|
|
67
|
+
local result = { targets = {}, references = {}, unresolved_sites = 0, ambiguous_sites = 0,
|
|
68
|
+
query_stats = { scanned_files = 0, scanned_sites = 0, source_files = 0, source_bytes = 0, incomplete_reasons = {} } }
|
|
69
|
+
local stats, deadline, stop = result.query_stats, xtimer.now_ms() + (opts.time_limit_ms or M.TIME_MS), {}
|
|
70
|
+
if #targets > (opts.max_nodes or 200) then
|
|
71
|
+
local selected = {}
|
|
72
|
+
for i = 1, opts.max_nodes or 200 do selected[i] = targets[i] end
|
|
73
|
+
targets = selected
|
|
74
|
+
result.seed_limit_reached, result.relationships_incomplete = true, true
|
|
75
|
+
stats.incomplete_reasons.type_reference_target_limit = true
|
|
76
|
+
end
|
|
77
|
+
local roots, root_files, names, name_count, loaded, positions = {}, {}, {}, 0, {}, {}
|
|
78
|
+
local function limited(reason) stats.incomplete_reasons[reason], result.relationships_incomplete = true, true; error(stop, 0) end
|
|
79
|
+
local function check()
|
|
80
|
+
control.check()
|
|
81
|
+
if xtimer.now_ms() >= deadline then result.time_limit_reached = true; limited('type_reference_time_limit') end
|
|
82
|
+
end
|
|
83
|
+
local function add_name(name)
|
|
84
|
+
if names[name] then return end
|
|
85
|
+
if name_count >= M.MAX_NAMES then limited('type_reference_alias_limit') end
|
|
86
|
+
names[name], name_count = true, name_count + 1
|
|
87
|
+
end
|
|
88
|
+
if #targets == 0 then return result end
|
|
89
|
+
local ctx = require('codeoutline.js_resolution').context(G); ctx.include_paths = opts.include_paths
|
|
90
|
+
local function source(f)
|
|
91
|
+
if not loaded[f] then
|
|
92
|
+
if stats.source_files >= (opts.max_files or M.MAX_FILES) then limited('type_reference_file_limit') end
|
|
93
|
+
if stats.source_bytes + (G.files[f].size or 0) > M.MAX_BYTES then limited('type_reference_source_limit') end
|
|
94
|
+
loaded[f] = true; stats.source_files = stats.source_files + 1; stats.source_bytes = stats.source_bytes + (G.files[f].size or 0)
|
|
95
|
+
end
|
|
96
|
+
if idx then
|
|
97
|
+
local raw, repaired = idx:query_source(G.files[f].path)
|
|
98
|
+
if repaired then error(opts.retry, 0) end
|
|
99
|
+
return assert(raw, 'cannot read type reference source')
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
ctx.ordinary = require('codeoutline.ordinary_bindings').context(G, ctx,
|
|
103
|
+
(idx or G.root) and function(f) return source(f) end or nil, opts.cache and { cache = opts.cache } or nil)
|
|
104
|
+
stats.ordinary = ctx.ordinary.stats
|
|
105
|
+
local summaries, summary_bytes = {}, 0
|
|
106
|
+
local function data(f)
|
|
107
|
+
check()
|
|
108
|
+
if summaries[f] then return summaries[f] end
|
|
109
|
+
if not loaded[f] then source(f) end
|
|
110
|
+
local full = ctx.ordinary.data(f)
|
|
111
|
+
local count = 0; for _ in pairs(full.type_sites or {}) do count = count + 1 end
|
|
112
|
+
local weight = count * 256 + #(full.type_parameters or {}) * 96
|
|
113
|
+
if summary_bytes + weight > M.MAX_BYTES then limited('type_reference_evidence_limit') end
|
|
114
|
+
summary_bytes = summary_bytes + weight; stats.evidence_bytes = summary_bytes
|
|
115
|
+
summaries[f] = { type_sites = full.type_sites, type_parameters = full.type_parameters }
|
|
116
|
+
return summaries[f]
|
|
117
|
+
end
|
|
118
|
+
local function matches(ids) for _, id in ipairs(ids) do if roots[id] then return roots[id] end end end
|
|
119
|
+
-- Type occurrences are not in the persistent graph. Scan candidate text,
|
|
120
|
+
-- then parse only relevant files through the validated shared FIFO.
|
|
121
|
+
local function candidate(f)
|
|
122
|
+
check()
|
|
123
|
+
local rec = G.files[f]
|
|
124
|
+
local cached = summaries[f] or rec
|
|
125
|
+
if cached.type_sites then
|
|
126
|
+
for _, site in ipairs(cached.type_sites) do if names[site.name] then return true end end
|
|
127
|
+
return false
|
|
128
|
+
end
|
|
129
|
+
if (stats.candidate_files or 0) >= M.MAX_SCAN_FILES then limited('type_reference_scan_file_limit') end
|
|
130
|
+
if (stats.candidate_bytes or 0) + (rec.size or 0) > M.MAX_SCAN_BYTES then limited('type_reference_scan_byte_limit') end
|
|
131
|
+
local raw, repaired
|
|
132
|
+
if idx and idx.abs then
|
|
133
|
+
local file = assert(io.open(idx:abs(rec.path), 'rb'), 'cannot read type candidate: ' .. rec.path)
|
|
134
|
+
raw = file:read(M.MAX_SCAN_BYTES - (stats.candidate_bytes or 0) + 1); file:close()
|
|
135
|
+
local crc = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
|
|
136
|
+
assert(#raw == rec.size and crc == rec.crc, 'source snapshot changed during type query: ' .. rec.path)
|
|
137
|
+
elseif idx then raw, repaired = idx:query_source(rec.path)
|
|
138
|
+
elseif G.root then
|
|
139
|
+
local file = assert(io.open(G.root .. '/' .. rec.path, 'rb')); raw = file:read('a'); file:close()
|
|
140
|
+
local crc = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
|
|
141
|
+
assert(#raw == rec.size and crc == rec.crc, 'source snapshot changed during type query: ' .. rec.path)
|
|
142
|
+
else
|
|
143
|
+
for _, site in ipairs(data(f).type_sites or {}) do if names[site.name] then return true end end
|
|
144
|
+
return false
|
|
145
|
+
end
|
|
146
|
+
if repaired then error(opts.retry, 0) end
|
|
147
|
+
assert(raw, 'cannot read type candidate: ' .. rec.path)
|
|
148
|
+
stats.candidate_files, stats.candidate_bytes = (stats.candidate_files or 0) + 1, (stats.candidate_bytes or 0) + #raw
|
|
149
|
+
if stats.candidate_bytes > M.MAX_SCAN_BYTES then limited('type_reference_scan_byte_limit') end
|
|
150
|
+
for name in pairs(names) do
|
|
151
|
+
local escaped = name:gsub('([^%w])', '%%%1')
|
|
152
|
+
if raw:find('%f[%w_$]' .. escaped .. '%f[^%w_$]') then return true end
|
|
153
|
+
end
|
|
154
|
+
return false
|
|
155
|
+
end
|
|
156
|
+
local ok, err = pcall(function()
|
|
157
|
+
for _, id in ipairs(targets) do roots[id] = id; root_files[G.node_file[id]] = true; add_name(G.nodes[id].name) end
|
|
158
|
+
for _, id in ipairs(targets) do
|
|
159
|
+
data(G.node_file[id])
|
|
160
|
+
result.targets[#result.targets + 1] = describe(G, id)
|
|
161
|
+
end
|
|
162
|
+
for _, id in ipairs(targets) do
|
|
163
|
+
if G.nodes[id].kind == 'typedef' then
|
|
164
|
+
local f, n = G.node_file[id], id - G.id_of[G.node_file[id]][1] + 1
|
|
165
|
+
for i, site in pairs(data(f).type_sites or {}) do
|
|
166
|
+
if site.from == n and site.role == 'alias' and site.alias_name then
|
|
167
|
+
local resolved = M.resolve(G, f, id, site, ctx, data(f))
|
|
168
|
+
if #resolved == 1 then roots[resolved[1]] = id; root_files[G.node_file[resolved[1]]] = true end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
for round = 1, M.MAX_NAMES do
|
|
174
|
+
local before = name_count
|
|
175
|
+
for number, f in ipairs(G.file_order) do
|
|
176
|
+
if number % 128 == 0 then check() end
|
|
177
|
+
local rec = G.files[f]
|
|
178
|
+
if languages[rec.language] then
|
|
179
|
+
for _, export in ipairs(rec.js_exports or {}) do
|
|
180
|
+
if export.local_name and names[export.local_name] and export.name ~= 'default' then add_name(export.name) end
|
|
181
|
+
end
|
|
182
|
+
for _, imp in ipairs(rec.js_imports or rec.imports or {}) do
|
|
183
|
+
local tail = (imp.imported or imp.path or ''):match('([%w_$]+)$')
|
|
184
|
+
local alias = imp.local_name or imp.alias
|
|
185
|
+
if alias and names[tail] then add_name(alias) end
|
|
186
|
+
for _, hint in ipairs(imp.type_aliases or {}) do if names[hint.name] then add_name(hint.alias) end end
|
|
187
|
+
if imp.imported == 'default' and alias then
|
|
188
|
+
local imported = require('codeoutline.js_resolution').imported(G, f, imp.path, imp.imported, ctx)
|
|
189
|
+
if matches(imported) then add_name(alias) end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
if before == name_count then break end
|
|
195
|
+
end
|
|
196
|
+
for pass = 1, M.MAX_NAMES do
|
|
197
|
+
local before = name_count
|
|
198
|
+
local eligible = {}
|
|
199
|
+
local dirs, ordered, near, far = {}, {}, {}, {}
|
|
200
|
+
for f in pairs(root_files) do dirs[G.file_dir[f]] = true end
|
|
201
|
+
for _, f in ipairs(G.file_order) do
|
|
202
|
+
if languages[G.files[f].language] then
|
|
203
|
+
local bucket = root_files[f] and ordered or dirs[G.file_dir[f]] and near or far
|
|
204
|
+
bucket[#bucket + 1] = f
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
for _, f in ipairs(near) do ordered[#ordered + 1] = f end
|
|
208
|
+
for _, f in ipairs(far) do ordered[#ordered + 1] = f end
|
|
209
|
+
for _, f in ipairs(ordered) do
|
|
210
|
+
if languages[G.files[f].language] then
|
|
211
|
+
stats.scanned_files = stats.scanned_files + 1
|
|
212
|
+
if stats.scanned_files % 128 == 0 then check() end
|
|
213
|
+
local rec = G.files[f]
|
|
214
|
+
if candidate(f) then
|
|
215
|
+
if rec.language == 'c' or rec.language == 'cpp' then
|
|
216
|
+
eligible[f] = root_files[f] or false
|
|
217
|
+
if not eligible[f] then
|
|
218
|
+
local visible, paired = graph.visible_dependencies(G, f, ctx)
|
|
219
|
+
for root in pairs(root_files) do if visible[root] or paired[root] then eligible[f] = true; break end end
|
|
220
|
+
end
|
|
221
|
+
else eligible[f] = true end
|
|
222
|
+
if eligible[f] then
|
|
223
|
+
for i, site in ipairs(data(f).type_sites or {}) do
|
|
224
|
+
if i % 1024 == 0 then check() end
|
|
225
|
+
local key = f .. ':' .. i
|
|
226
|
+
if names[site.name] and not positions[key] then
|
|
227
|
+
if stats.scanned_sites >= M.MAX_SITES then limited('type_reference_site_limit') end
|
|
228
|
+
positions[key] = true; stats.scanned_sites = stats.scanned_sites + 1
|
|
229
|
+
local from = site.from > 0 and G.id_of[f][site.from] or nil
|
|
230
|
+
local ids, reason = M.resolve(G, f, from, site, ctx, data(f))
|
|
231
|
+
if ctx.include_incomplete or ctx.workspace_incomplete or ctx.go_incomplete or ctx.go_methods_incomplete or ctx.rust_incomplete then limited('type_reference_binding_incomplete') end
|
|
232
|
+
local target = matches(ids)
|
|
233
|
+
if #ids == 1 and target then
|
|
234
|
+
if #result.references >= (opts.max_nodes or 200) then result.node_limit_reached = true; limited('type_reference_result_limit') end
|
|
235
|
+
result.references[#result.references + 1] = { file = rec.path, line = site.line, first = site.first, last = site.last,
|
|
236
|
+
role = site.role, written = site.written, target = target, source = from }
|
|
237
|
+
local node = site.from > 0 and rec.nodes[site.from]
|
|
238
|
+
if site.role == 'alias' and site.alias_name and node and node.kind == 'typedef' then
|
|
239
|
+
roots[from] = target; root_files[f] = true; add_name(node.name)
|
|
240
|
+
end
|
|
241
|
+
elseif #ids > 1 then result.ambiguous_sites = result.ambiguous_sites + 1
|
|
242
|
+
elseif reason ~= 'type parameter' and reason ~= 'value binding' then result.unresolved_sites = result.unresolved_sites + 1 end
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
if before == name_count then break end
|
|
250
|
+
end
|
|
251
|
+
end)
|
|
252
|
+
if not ok and err ~= stop then error(err, 0) end
|
|
253
|
+
if ctx.include_incomplete or ctx.workspace_incomplete or ctx.go_incomplete or ctx.go_methods_incomplete or ctx.rust_incomplete then
|
|
254
|
+
result.relationships_incomplete = true; stats.incomplete_reasons.type_reference_binding_incomplete = true
|
|
255
|
+
end
|
|
256
|
+
result.incomplete = result.relationships_incomplete or result.unresolved_sites > 0 or result.ambiguous_sites > 0
|
|
257
|
+
table.sort(result.references, function(a, b) return a.file < b.file or a.file == b.file and a.first < b.first end)
|
|
258
|
+
return result
|
|
259
|
+
end
|
|
260
|
+
local function run(G, idx, query, opts, retry)
|
|
261
|
+
local budget = M.validate(query, opts)
|
|
262
|
+
local filters = require('codeoutline.query_filters').parse(query)
|
|
263
|
+
local ids = {}
|
|
264
|
+
for number, id in ipairs(G.by_qualified[filters.text] or G.by_name[filters.text] or {}) do
|
|
265
|
+
if number % 256 == 0 then control.check() end
|
|
266
|
+
if M.kinds[G.nodes[id].kind] and languages[G.files[G.node_file[id]].language] and require('codeoutline.query_filters').id(filters, G, id) then
|
|
267
|
+
ids[#ids + 1] = id
|
|
268
|
+
if #ids > (opts.max_nodes or 200) then break end
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
table.sort(ids, function(a, b) return graph.before(G, a, b) end)
|
|
272
|
+
local options = {}; for key, value in pairs(opts or {}) do options[key] = value end; options.retry = retry
|
|
273
|
+
local result = M.query(G, idx, ids, options)
|
|
274
|
+
local lines = { string.format('Matched %d type(s); %d explicit type references.', #result.targets, #result.references),
|
|
275
|
+
'Scope: explicit type positions parsed on demand in indexed files; no inference, runtime reflection or complete build coverage is claimed.' }
|
|
276
|
+
for _, target in ipairs(result.targets) do lines[#lines + 1] = string.format('Target: %s (%s:%d)', target.name, target.file, target.line) end
|
|
277
|
+
for _, ref in ipairs(result.references) do lines[#lines + 1] = string.format('- %s:%d [%s] %s', ref.file, ref.line, ref.role, ref.written) end
|
|
278
|
+
if #ids == 0 then lines[#lines + 1] = 'No supported type matched; use an exact type name or qualified name.' end
|
|
279
|
+
if result.incomplete then lines[#lines + 1] = string.format('Coverage incomplete; %d unresolved and %d ambiguous candidate sites.', result.unresolved_sites, result.ambiguous_sites) end
|
|
280
|
+
local output, cut = require('codeoutline.text').limit(table.concat(lines, '\n'), budget, result.node_limit_reached)
|
|
281
|
+
result.truncated = cut; return output, result
|
|
282
|
+
end
|
|
283
|
+
function M.run(G, idx, query, opts)
|
|
284
|
+
local retry = {}
|
|
285
|
+
local ok, output, info = pcall(run, G, idx, query, opts or {}, retry)
|
|
286
|
+
if not ok and output == retry then return nil, { encoding_retry = true } end
|
|
287
|
+
if not ok then error(output, 0) end
|
|
288
|
+
return output, info
|
|
289
|
+
end
|
|
290
|
+
return M
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
-- Explicit type sites; detailed binding and ranges belong to queries only.
|
|
2
|
+
local M = { languages = { c = true, cpp = true, csharp = true, java = true,
|
|
3
|
+
kotlin = true, typescript = true, arkts = true, go = true, rust = true } }
|
|
4
|
+
local builtin = {}
|
|
5
|
+
for word in ([[void bool boolean byte sbyte char wchar_t char16_t char32_t short int long float double decimal
|
|
6
|
+
signed unsigned const volatile static extern inline virtual public private protected internal abstract override
|
|
7
|
+
final sealed readonly ref out in params mut dyn impl auto var val let new class struct union enum interface
|
|
8
|
+
record typename template typedef using extends implements throws where async await return yield get set
|
|
9
|
+
string object any unknown never number symbol bigint undefined null true false self Self super this
|
|
10
|
+
int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr float32 float64 complex64 complex128
|
|
11
|
+
rune error chan map func type pub fn trait i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize f32 f64
|
|
12
|
+
Unit Nothing Any Boolean Byte Short Int Long Float Double Char String dynamic]]):gmatch('%S+') do builtin[word] = true end
|
|
13
|
+
local callable = { ['function'] = true, method = true, prototype = true, constructor = true, destructor = true }
|
|
14
|
+
local containers = { class = true, struct = true, union = true, interface = true, record = true, enum = true }
|
|
15
|
+
|
|
16
|
+
function M.collect(r, T)
|
|
17
|
+
if not M.languages[r.language] or r.cpp_aliases_only or r.dispatch_only or r.collect_type_uses == false
|
|
18
|
+
or not (r.ordinary_bindings or r.ranges) then return end
|
|
19
|
+
local language, sites, names, seen = r.language, {}, {}, {}
|
|
20
|
+
local details = r.ordinary_bindings or r.ranges
|
|
21
|
+
local suffix = language == 'typescript' or language == 'arkts' or language == 'kotlin' or language == 'rust'
|
|
22
|
+
local prefix = language == 'c' or language == 'cpp' or language == 'java' or language == 'csharp'
|
|
23
|
+
local separator = (language == 'c' or language == 'cpp' or language == 'rust') and '::' or '.'
|
|
24
|
+
for _, n in ipairs(r.nodes) do if n.type_token then names[n.type_token] = true end end
|
|
25
|
+
local function add(t, role, first, last)
|
|
26
|
+
local name = T:text(t)
|
|
27
|
+
if seen[t] or names[t] or T.k[t] ~= 'id' or not name:match('^[%a_$][%w_$]*$') then return end
|
|
28
|
+
seen[t] = true
|
|
29
|
+
local a = t
|
|
30
|
+
while a > (first or 1) and T:text(a - 1) == separator and T.k[a - 2] == 'id' do a = a - 2 end
|
|
31
|
+
if T:text(t + 1) == separator and t + 1 <= (last or T.n) then return end
|
|
32
|
+
local written = T.src:sub(T.s[a], T.e[t]):gsub('%s+', '')
|
|
33
|
+
local site = { tok = t, name = name, kind = 'type', line = T:line(t), type_role = role,
|
|
34
|
+
recv = a < t and written:sub(1, #written - #name - #separator) or nil }
|
|
35
|
+
sites[#sites + 1] = site
|
|
36
|
+
if details then
|
|
37
|
+
site.type_use = { role = role, written = written, line = site.line, first = T.s[t] - 1, last = T.e[t], at = T.s[a] - 1 }
|
|
38
|
+
local tag = T:text(a - 1)
|
|
39
|
+
if tag == 'struct' or tag == 'union' or tag == 'enum' or tag == 'class' then site.type_use.elaborated = tag end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
local function range(a, b, role, exclude)
|
|
43
|
+
if not a or not b or a > b then return end
|
|
44
|
+
for _, t in ipairs(T:idents(a, b)) do if t ~= exclude then add(t, role, a, b) end end
|
|
45
|
+
end
|
|
46
|
+
local function cut(a, b)
|
|
47
|
+
local depth = 0
|
|
48
|
+
for i = a, b do
|
|
49
|
+
local s = T:text(i)
|
|
50
|
+
if s == '<' then depth = depth + 1 elseif s == '>' then depth = math.max(0, depth - 1) end
|
|
51
|
+
if depth == 0 and (s == '=' or s == '{' or s == 'where') then return i - 1 end
|
|
52
|
+
end
|
|
53
|
+
return b
|
|
54
|
+
end
|
|
55
|
+
local function angle(a, b, owner)
|
|
56
|
+
if T:text(a) ~= '<' and not (language == 'go' and T:text(a) == '[') then return a end
|
|
57
|
+
local open, close = T:text(a), T:text(a) == '[' and ']' or '>'
|
|
58
|
+
local depth, expect = 1, true
|
|
59
|
+
for i = a + 1, math.min(b, a + 256) do
|
|
60
|
+
local s = T:text(i)
|
|
61
|
+
if s == open then depth = depth + 1 elseif s == close then depth = depth - 1 end
|
|
62
|
+
if depth == 0 then return i + 1 end
|
|
63
|
+
if depth == 1 then
|
|
64
|
+
if s == ',' then expect = true
|
|
65
|
+
elseif T.k[i] == 'id' and expect then
|
|
66
|
+
names[i], expect = true, false
|
|
67
|
+
if r.ordinary_bindings or r.ranges then
|
|
68
|
+
r.type_parameters = r.type_parameters or {}
|
|
69
|
+
r.type_parameters[#r.type_parameters + 1] = { name = s, first = T.s[owner.ti] - 1, last = T.e[owner.tj] }
|
|
70
|
+
end
|
|
71
|
+
elseif s == 'extends' or s == ':' then
|
|
72
|
+
local j = i + 1
|
|
73
|
+
while j <= b and T:text(j) ~= ',' and T:text(j) ~= close do j = j + 1 end
|
|
74
|
+
range(i + 1, j - 1, 'constraint')
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
return b + 1
|
|
79
|
+
end
|
|
80
|
+
local function parameter(a, b, role)
|
|
81
|
+
b = cut(a, b)
|
|
82
|
+
if a > b then return end
|
|
83
|
+
if suffix then
|
|
84
|
+
for i = a, b do if T:text(i) == ':' then range(i + 1, b, role); return end end
|
|
85
|
+
return
|
|
86
|
+
end
|
|
87
|
+
if language == 'go' then
|
|
88
|
+
if T.k[a] == 'id' and T:text(a + 1) ~= '.' and a < b then
|
|
89
|
+
local i = a + 1
|
|
90
|
+
while T:text(i) == ',' and T.k[i + 1] == 'id' do i = i + 2 end
|
|
91
|
+
range(i, b, role)
|
|
92
|
+
else range(a, b, role) end
|
|
93
|
+
return
|
|
94
|
+
end
|
|
95
|
+
local last, count, depth, primitive = nil, 0, 0, false
|
|
96
|
+
for i = a, b do
|
|
97
|
+
local s = T:text(i)
|
|
98
|
+
if s == '<' then depth = depth + 1 elseif s == '>' then depth = math.max(0, depth - 1) end
|
|
99
|
+
if depth == 0 then
|
|
100
|
+
if T.k[i] == 'id' then last, count = i, count + 1 end
|
|
101
|
+
if s == 'int' or s == 'char' or s == 'void' or s == 'string' or s == 'bool' then primitive = true end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
local exclude = last and (count > 1 or primitive) and T:text(last - 1) ~= separator
|
|
105
|
+
and T:text(last + 1) ~= '<' and last or nil
|
|
106
|
+
range(a, b, role, exclude)
|
|
107
|
+
end
|
|
108
|
+
local function parameters(a, b, role)
|
|
109
|
+
local start, i, depth = a, a, 0
|
|
110
|
+
while i <= b + 1 do
|
|
111
|
+
local s = T:text(i)
|
|
112
|
+
if i == b + 1 or s == ',' and depth == 0 then parameter(start, i - 1, role); start = i + 1
|
|
113
|
+
elseif s == '<' then depth = depth + 1
|
|
114
|
+
elseif s == '>' then depth = math.max(0, depth - 1)
|
|
115
|
+
elseif T.m[i] and T.m[i] > i then i = T.m[i] end
|
|
116
|
+
i = i + 1
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
local declaration_prefixes = {}
|
|
120
|
+
for index, n in ipairs(r.nodes) do
|
|
121
|
+
if index % 128 == 0 then require('codeoutline.control').check() end
|
|
122
|
+
local ni = n.type_token
|
|
123
|
+
if ni and (callable[n.kind] or containers[n.kind] or n.kind == 'typedef') then
|
|
124
|
+
local a = n.ti
|
|
125
|
+
while builtin[T:text(a)] and T:text(a) ~= 'template' and T:text(a) ~= 'void' do a = a + 1 end
|
|
126
|
+
if language == 'java' and T:text(a) == '<' then angle(a, n.tj, n) end
|
|
127
|
+
if language == 'cpp' then
|
|
128
|
+
for j = n.ti, math.max(1, n.ti - 256), -1 do
|
|
129
|
+
local s = T:text(j)
|
|
130
|
+
if s == 'template' and T:text(j + 1) == '<' then angle(j + 1, n.tj, { ti = j, tj = n.tj }); break end
|
|
131
|
+
if j < n.ti and (s == ';' or s == '{' or s == '}') then break end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
if ni and callable[n.kind] then
|
|
136
|
+
local p = angle(ni + 1, n.tj, n)
|
|
137
|
+
if T:text(p) == '(' and T.m[p] then
|
|
138
|
+
local ending = T.m[p]
|
|
139
|
+
parameters(p + 1, ending - 1, 'parameter')
|
|
140
|
+
if prefix then range(n.ti, ni - 1, 'return') end
|
|
141
|
+
local a = ending + 1
|
|
142
|
+
if language == 'go' then
|
|
143
|
+
local b = a
|
|
144
|
+
while b <= n.tj and T:text(b) ~= '{' and T:text(b) ~= ';' and T.k[b] ~= 'nl' do b = b + 1 end
|
|
145
|
+
if T:text(a) == '(' and T.m[a] then parameters(a + 1, T.m[a] - 1, 'return') else range(a, b - 1, 'return') end
|
|
146
|
+
if T:text(n.ti + 1) == '(' and T.m[n.ti + 1] then parameters(n.ti + 2, T.m[n.ti + 1] - 1, 'receiver') end
|
|
147
|
+
elseif T:text(a) == ':' or T:text(a) == '->' then range(a + 1, cut(a + 1, n.tj), 'return') end
|
|
148
|
+
end
|
|
149
|
+
elseif ni and containers[n.kind] then
|
|
150
|
+
local a, mode = angle(ni + 1, n.tj, n), nil
|
|
151
|
+
if T:text(a) == '(' and T.m[a] then parameters(a + 1, T.m[a] - 1, 'parameter'); a = T.m[a] + 1 end
|
|
152
|
+
for i = a, n.tj do
|
|
153
|
+
local s = T:text(i)
|
|
154
|
+
if s == '{' then break end
|
|
155
|
+
if s == ':' or s == 'extends' or s == 'implements' then mode = i + 1 end
|
|
156
|
+
if mode and T.k[i] == 'id' then add(i, 'inheritance', mode, n.tj) end
|
|
157
|
+
end
|
|
158
|
+
elseif ni and (n.kind == 'field' or n.kind == 'property' or n.kind == 'variable' or n.kind == 'constant') then
|
|
159
|
+
if prefix then
|
|
160
|
+
local span = declaration_prefixes[n.tj]
|
|
161
|
+
if not span then
|
|
162
|
+
local a = n.ti
|
|
163
|
+
if a >= ni then
|
|
164
|
+
a = ni - 1
|
|
165
|
+
while a > 0 and T:text(a) ~= ';' and T:text(a) ~= '{' and T:text(a) ~= '}' do a = a - 1 end
|
|
166
|
+
a = a + 1
|
|
167
|
+
end
|
|
168
|
+
span = { a, ni - 1 }; declaration_prefixes[n.tj] = span
|
|
169
|
+
end
|
|
170
|
+
range(span[1], span[2], n.kind == 'field' and 'field' or 'variable')
|
|
171
|
+
elseif suffix and T:text(ni + 1) == ':' then range(ni + 2, cut(ni + 2, n.tj), (n.kind == 'field' or n.kind == 'property') and 'field' or 'variable')
|
|
172
|
+
elseif language == 'go' then
|
|
173
|
+
if n.embedded then range(n.ti, n.tj, 'inheritance') else range(ni + 1, cut(ni + 1, n.tj), n.kind == 'field' and 'field' or 'variable') end
|
|
174
|
+
end
|
|
175
|
+
elseif ni and n.kind == 'typedef' then
|
|
176
|
+
local first_site, a, b = #sites + 1
|
|
177
|
+
if prefix then
|
|
178
|
+
if T:text(n.ti) == 'using' then a, b = ni + 2, n.tj - 1 else a, b = n.ti + 1, ni - 1 end
|
|
179
|
+
else
|
|
180
|
+
a = angle(ni + 1, n.tj, n); if T:text(a) == '=' then a = a + 1 end
|
|
181
|
+
b = cut(a, n.tj)
|
|
182
|
+
end
|
|
183
|
+
range(a, b, 'alias')
|
|
184
|
+
if details then
|
|
185
|
+
local first, last = a, b
|
|
186
|
+
if T:text(last) == ';' then last = last - 1 end
|
|
187
|
+
local tag = T:text(first)
|
|
188
|
+
if tag == 'struct' or tag == 'class' or tag == 'union' or tag == 'enum' then first = first + 1 end
|
|
189
|
+
local plain, identifier = first <= last, true
|
|
190
|
+
for j = first, last do
|
|
191
|
+
if identifier then plain = plain and T.k[j] == 'id'
|
|
192
|
+
else plain = plain and (T:text(j) == '.' or T:text(j) == '::') end
|
|
193
|
+
identifier = not identifier
|
|
194
|
+
end
|
|
195
|
+
-- Containers, unions, function types and pointer decoration are
|
|
196
|
+
-- type uses, but do not make the alias identical to an element type.
|
|
197
|
+
if plain and not identifier and (language ~= 'go' or T:text(ni + 1) == '=') then
|
|
198
|
+
for j = first_site, #sites do sites[j].type_use.alias_name = n.name end
|
|
199
|
+
elseif language == 'go' and T:text(ni + 1) ~= '=' then
|
|
200
|
+
for j = first_site, #sites do sites[j].type_use.role = 'underlying' end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
local function import_alias(t)
|
|
206
|
+
for i = t - 2, math.max(1, t - 128), -1 do
|
|
207
|
+
local s = T:text(i)
|
|
208
|
+
if s == 'import' or s == 'use' then return true end
|
|
209
|
+
if s == ';' or s == '=' or s == 'return' or s == 'function' or s == 'fn' then return false end
|
|
210
|
+
if s == '{' then
|
|
211
|
+
for j = i - 1, math.max(1, i - 4), -1 do if T:text(j) == 'import' or T:text(j) == 'use' then return true end end
|
|
212
|
+
return false
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
return false
|
|
216
|
+
end
|
|
217
|
+
for _, i in ipairs(T:idents(1, T.n)) do
|
|
218
|
+
local prev = T:text(i - 1)
|
|
219
|
+
if prev == 'new' or prev == 'as' or prev == 'is' or prev == 'instanceof' then
|
|
220
|
+
local j = i
|
|
221
|
+
while T:text(j + 1) == separator and T.k[j + 2] == 'id' do j = j + 2 end
|
|
222
|
+
if prev ~= 'as' or not import_alias(i) then range(i, j, prev == 'new' and 'construction' or 'cast') end
|
|
223
|
+
elseif prev == '<' and (T:text(i - 2) == 'static_cast' or T:text(i - 2) == 'dynamic_cast'
|
|
224
|
+
or T:text(i - 2) == 'const_cast' or T:text(i - 2) == 'reinterpret_cast') then
|
|
225
|
+
local j = i; while j <= math.min(T.n, i + 128) and T:text(j) ~= '>' do j = j + 1 end
|
|
226
|
+
if T:text(j) == '>' then range(i, j - 1, 'cast') end
|
|
227
|
+
elseif (language == 'go' or language == 'rust') and T:text(i + 1) == '{'
|
|
228
|
+
and (prev == '=' or prev == ':=' or prev == 'return' or prev == '&') then add(i, 'construction')
|
|
229
|
+
elseif prefix and (prev == 'struct' or prev == 'class' or prev == 'union' or prev == 'enum') then add(i, 'variable')
|
|
230
|
+
elseif prefix and (prev == ';' or prev == '{' or prev == '}' or prev == 'const' or prev == 'static') then
|
|
231
|
+
local j = i
|
|
232
|
+
while T:text(j + 1) == separator and T.k[j + 2] == 'id' do j = j + 2 end
|
|
233
|
+
local p = j + 1
|
|
234
|
+
if T:text(p) == '<' then
|
|
235
|
+
local depth = 1; p = p + 1
|
|
236
|
+
while p <= math.min(T.n, j + 128) and depth > 0 do
|
|
237
|
+
if T:text(p) == '<' then depth = depth + 1 elseif T:text(p) == '>' then depth = depth - 1 end
|
|
238
|
+
p = p + 1
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
while T:text(p) == '*' or T:text(p) == '&' or T:text(p) == '&&' or T:text(p) == 'const' do p = p + 1 end
|
|
242
|
+
if T.k[p] == 'id' and (T:text(p + 1) == '=' or T:text(p + 1) == ';' or T:text(p + 1) == ','
|
|
243
|
+
or T:text(p + 1) == '[' or T:text(p + 1) == '{') then range(i, p - 1, 'variable') end
|
|
244
|
+
elseif (suffix or language == 'go') and (prev == 'let' or prev == 'var' or prev == 'val' or prev == 'const') then
|
|
245
|
+
local p = i + 1
|
|
246
|
+
if suffix and T:text(p) == ':' then p = p + 1 elseif suffix then p = T.n + 1 end
|
|
247
|
+
local b = p
|
|
248
|
+
while b <= T.n and T:text(b) ~= '=' and T:text(b) ~= ';' and T:text(b) ~= '{'
|
|
249
|
+
and T.k[b] ~= 'nl' and T:line(b) == T:line(i) do b = b + 1 end
|
|
250
|
+
range(p, b - 1, 'variable')
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
for _, i in ipairs(T:calls(1, T.n)) do
|
|
254
|
+
local a = i
|
|
255
|
+
while T:text(a - 1) == separator and T.k[a - 2] == 'id' do a = a - 2 end
|
|
256
|
+
if T:text(a - 1) == 'new' then add(i, 'construction', a, i) end
|
|
257
|
+
end
|
|
258
|
+
r.type_use_refs = sites
|
|
259
|
+
end
|
|
260
|
+
return M
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return
|
|
1
|
+
return 18
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return '0.2.
|
|
1
|
+
return '0.2.9'
|