@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,301 @@
|
|
|
1
|
+
-- Rust crate/module evidence is produced only for queries, never serialized.
|
|
2
|
+
local M = { MAX_DEPTH = 16, MAX_RESULTS = 128, MAX_ALIAS_FILES = 64, MAX_NODES = 8192 }
|
|
3
|
+
local cargo, control = require('codeoutline.rust_packages'), require('codeoutline.control')
|
|
4
|
+
local function join(a, b) return a == '' and b or b == '' and a or a .. '::' .. b end
|
|
5
|
+
local function text(T, i) return i >= 1 and i <= T.n and T:text(i) or '' end
|
|
6
|
+
|
|
7
|
+
function M.collect(r, T)
|
|
8
|
+
r.rust_imports, r.rust_public, r.has_bindings = {}, {}, true
|
|
9
|
+
for n, node in ipairs(r.nodes) do
|
|
10
|
+
r.rust_public[n] = text(T, node.ti) == 'pub' and text(T, node.ti + 1) ~= '('
|
|
11
|
+
end
|
|
12
|
+
for i = 1, T.n do
|
|
13
|
+
if text(T, i) == 'use' then
|
|
14
|
+
local parent, in_function, last, j = nil, false, i + 1, i + 1
|
|
15
|
+
for n, node in ipairs(r.nodes) do
|
|
16
|
+
if node.ti <= i and i <= node.tj then
|
|
17
|
+
if node.kind == 'namespace' then parent = n
|
|
18
|
+
elseif node.kind == 'function' or node.kind == 'method' then in_function = true end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
while j <= T.n and text(T, j) ~= ';' do
|
|
22
|
+
if T.m[j] and T.m[j] > j then j = T.m[j] end
|
|
23
|
+
j = j + 1
|
|
24
|
+
end
|
|
25
|
+
last = j - 1
|
|
26
|
+
local cursor, count = i + 1, 0
|
|
27
|
+
if text(T, cursor) == '::' then cursor = cursor + 1 end
|
|
28
|
+
local branch
|
|
29
|
+
branch = function(prefix, depth)
|
|
30
|
+
if depth > M.MAX_DEPTH then error('Rust use nesting limit reached', 0) end
|
|
31
|
+
local path = prefix
|
|
32
|
+
while cursor <= last do
|
|
33
|
+
local token = text(T, cursor)
|
|
34
|
+
if token == '{' then
|
|
35
|
+
cursor = cursor + 1
|
|
36
|
+
while cursor <= last and text(T, cursor) ~= '}' do
|
|
37
|
+
branch(path, depth + 1)
|
|
38
|
+
if text(T, cursor) == ',' then cursor = cursor + 1 else break end
|
|
39
|
+
end
|
|
40
|
+
if text(T, cursor) ~= '}' then error('unsupported Rust use group', 0) end
|
|
41
|
+
cursor = cursor + 1; return
|
|
42
|
+
end
|
|
43
|
+
if token == '' or token == ',' or token == '}' then break end
|
|
44
|
+
if token ~= 'self' or path == '' then path = join(path, token) end
|
|
45
|
+
cursor = cursor + 1
|
|
46
|
+
if text(T, cursor) == '::' then cursor = cursor + 1 else break end
|
|
47
|
+
end
|
|
48
|
+
local alias = path:match('([^:]+)$')
|
|
49
|
+
if text(T, cursor) == 'as' then alias = text(T, cursor + 1); cursor = cursor + 2 end
|
|
50
|
+
count = count + 1
|
|
51
|
+
if count > M.MAX_RESULTS then error('Rust use binding limit reached', 0) end
|
|
52
|
+
if not in_function then r.rust_imports[#r.rust_imports + 1] = { path = path, alias = alias,
|
|
53
|
+
parent = parent, public = text(T, i - 1) == 'pub', line = T:line(i) } end
|
|
54
|
+
end
|
|
55
|
+
branch('', 0)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
for _, ref in ipairs(r.refs) do
|
|
59
|
+
local i, path = ref.tok, ref.name
|
|
60
|
+
if text(T, i - 1) == '.' then ref.binding = 'rust:member'
|
|
61
|
+
else
|
|
62
|
+
while text(T, i - 1) == '::' and (T.k[i - 2] == 'id' or T.k[i - 2] == 'kw') do
|
|
63
|
+
path, i = text(T, i - 2) .. '::' .. path, i - 2
|
|
64
|
+
end
|
|
65
|
+
ref.binding = 'rust:path:' .. path
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
local function data(G, f, ctx)
|
|
71
|
+
local rec = G.files[f]
|
|
72
|
+
if rec.rust_imports then return rec end
|
|
73
|
+
return ctx.ordinary and cargo.guard(ctx, function() return ctx.ordinary.data(f) end) or rec
|
|
74
|
+
end
|
|
75
|
+
local function scope_of(G, f, src)
|
|
76
|
+
local node = src and G.nodes[src]
|
|
77
|
+
local p = node and node.parent
|
|
78
|
+
while p do
|
|
79
|
+
local owner = G.files[f].nodes[p]
|
|
80
|
+
if owner.kind == 'namespace' then return owner.qualified end
|
|
81
|
+
p = owner.parent
|
|
82
|
+
end
|
|
83
|
+
return ''
|
|
84
|
+
end
|
|
85
|
+
local function parent_scope(G, f, p) return p and G.files[f].nodes[p].qualified or '' end
|
|
86
|
+
local function nodes(G, f, ctx)
|
|
87
|
+
local list = G.files[f].nodes
|
|
88
|
+
if #list > M.MAX_NODES then
|
|
89
|
+
ctx.rust_incomplete, ctx.rust_error = true, 'Rust module node limit reached'
|
|
90
|
+
return {}
|
|
91
|
+
end
|
|
92
|
+
return list
|
|
93
|
+
end
|
|
94
|
+
local function child(G, entry, name, ctx)
|
|
95
|
+
local wanted, found = join(entry.scope, name), nil
|
|
96
|
+
local rec, detail = G.files[entry.file], data(G, entry.file, ctx)
|
|
97
|
+
for n, node in ipairs(nodes(G, entry.file, ctx)) do
|
|
98
|
+
if node.kind == 'namespace' and node.qualified == wanted then
|
|
99
|
+
if entry.external and not (detail.rust_public or {})[n] then return nil end
|
|
100
|
+
local external = false
|
|
101
|
+
for _, imp in ipairs(rec.imports) do if imp.kind == 'mod' and imp.path == name then external = true; break end end
|
|
102
|
+
if not external then return { file = entry.file, scope = wanted, external = entry.external, root = entry.root } end
|
|
103
|
+
local path = rec.path
|
|
104
|
+
local directory, stem = cargo.dir(path), path:match('([^/]+)%.rs$')
|
|
105
|
+
if not entry.root and stem ~= 'lib' and stem ~= 'main' and stem ~= 'mod' then directory = cargo.join(directory, stem) end
|
|
106
|
+
if entry.scope ~= '' then directory = cargo.join(directory, entry.scope:gsub('::', '/')) end
|
|
107
|
+
for _, candidate in ipairs({ cargo.join(directory, name .. '.rs'), cargo.join(directory, name .. '/mod.rs') }) do
|
|
108
|
+
local id = G.file_index[candidate]
|
|
109
|
+
if id then
|
|
110
|
+
if found then return nil end
|
|
111
|
+
if cargo.owner(G, id, ctx) ~= cargo.owner(G, entry.file, ctx) then return nil end
|
|
112
|
+
found = { file = id, scope = '', external = entry.external }
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
return found
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
local walk
|
|
121
|
+
local function terminal(G, entry, name, ctx, seen, depth)
|
|
122
|
+
local result, rec, detail = {}, G.files[entry.file], data(G, entry.file, ctx)
|
|
123
|
+
local wanted = join(entry.scope, name)
|
|
124
|
+
for n, node in ipairs(nodes(G, entry.file, ctx)) do
|
|
125
|
+
if node.qualified == wanted and node.kind ~= 'namespace'
|
|
126
|
+
and (not entry.external or (detail.rust_public or {})[n]) then
|
|
127
|
+
result[#result + 1] = G.id_of[entry.file][n]
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
if #result > 0 then return { ids = result } end
|
|
131
|
+
for _, imp in ipairs(detail.rust_imports or {}) do
|
|
132
|
+
if imp.alias == name and parent_scope(G, entry.file, imp.parent) == entry.scope
|
|
133
|
+
and (not entry.external or imp.public) then
|
|
134
|
+
local found = walk(G, entry.file, imp.path, ctx, entry.scope, seen, depth + 1)
|
|
135
|
+
if entry.external and found and found.ids then
|
|
136
|
+
local visible = {}
|
|
137
|
+
for _, id in ipairs(found.ids) do
|
|
138
|
+
local f = G.node_file[id]
|
|
139
|
+
for n, local_id in ipairs(G.id_of[f]) do
|
|
140
|
+
if local_id == id and (data(G, f, ctx).rust_public or {})[n] then visible[#visible + 1] = id end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
found.ids = visible
|
|
144
|
+
end
|
|
145
|
+
return found
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
walk = function(G, f, path, ctx, scope, seen, depth)
|
|
150
|
+
control.check()
|
|
151
|
+
if depth > M.MAX_DEPTH then error('Rust module resolution depth limit reached', 0) end
|
|
152
|
+
local key = G.files[f].path .. '\0' .. scope .. '\0' .. path
|
|
153
|
+
if seen[key] then return nil end
|
|
154
|
+
seen[key] = true
|
|
155
|
+
local parts = {}; for name in path:gmatch('[^:]+') do parts[#parts + 1] = name end
|
|
156
|
+
if #parts == 0 then return nil end
|
|
157
|
+
local owner = cargo.owner(G, f, ctx)
|
|
158
|
+
if not owner then return nil end
|
|
159
|
+
local first, index, entry = parts[1], 2, nil
|
|
160
|
+
if first == 'crate' then
|
|
161
|
+
local id = cargo.entry(G, owner, ctx, f)
|
|
162
|
+
if id then entry = { file = id, scope = '', root = true } end
|
|
163
|
+
elseif first == 'self' then entry = { file = f, scope = scope, root = cargo.entry(G, owner, ctx, f) == f }
|
|
164
|
+
elseif first == 'super' then
|
|
165
|
+
if scope ~= '' then entry = { file = f, scope = scope:match('^(.*)::[^:]+$') or '', root = cargo.entry(G, owner, ctx, f) == f }
|
|
166
|
+
else
|
|
167
|
+
local root = cargo.entry(G, owner, ctx, f)
|
|
168
|
+
if root and root ~= f then
|
|
169
|
+
local directory = cargo.dir(G.files[f].path)
|
|
170
|
+
if G.files[f].path:match('/mod%.rs$') then directory = cargo.dir(directory) end
|
|
171
|
+
local candidates = directory == cargo.dir(G.files[root].path) and { G.files[root].path }
|
|
172
|
+
or { directory .. '.rs', cargo.join(directory, 'mod.rs') }
|
|
173
|
+
for _, candidate in ipairs(candidates) do
|
|
174
|
+
local id = G.file_index[candidate]
|
|
175
|
+
if id and cargo.owner(G, id, ctx) == owner then
|
|
176
|
+
if entry then return nil end
|
|
177
|
+
entry = { file = id, scope = '', root = id == root }
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
else
|
|
183
|
+
for _, imp in ipairs(data(G, f, ctx).rust_imports or {}) do
|
|
184
|
+
if imp.alias == first and parent_scope(G, f, imp.parent) == scope then
|
|
185
|
+
local replacement = imp.path
|
|
186
|
+
if #parts > 1 then replacement = replacement .. '::' .. table.concat(parts, '::', 2) end
|
|
187
|
+
if replacement ~= path then return walk(G, f, replacement, ctx, scope, seen, depth + 1) end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
local id = cargo.crates(G, f, ctx)[first]
|
|
191
|
+
if id then entry = { file = id, scope = '', external = cargo.owner(G, id, ctx) ~= owner, root = true }
|
|
192
|
+
else entry, index = { file = f, scope = scope }, 1 end
|
|
193
|
+
end
|
|
194
|
+
if not entry then return nil end
|
|
195
|
+
if first == 'super' and parts[2] == 'super' then
|
|
196
|
+
return walk(G, entry.file, table.concat(parts, '::', 2), ctx, entry.scope, seen, depth + 1)
|
|
197
|
+
end
|
|
198
|
+
while index <= #parts do
|
|
199
|
+
local next_entry = child(G, entry, parts[index], ctx)
|
|
200
|
+
if next_entry then entry = next_entry
|
|
201
|
+
else
|
|
202
|
+
local found = terminal(G, entry, parts[index], ctx, seen, depth)
|
|
203
|
+
if index == #parts then return found end
|
|
204
|
+
if found and found.module then
|
|
205
|
+
found.module.external = entry.external; entry = found.module
|
|
206
|
+
elseif found and found.ids and index + 1 == #parts then
|
|
207
|
+
local ids = {}
|
|
208
|
+
for _, type_id in ipairs(found.ids) do
|
|
209
|
+
local ty, tf = G.nodes[type_id], G.node_file[type_id]
|
|
210
|
+
for _, id in ipairs(G.by_name[parts[index + 1]] or {}) do
|
|
211
|
+
local method, mf = G.nodes[id], G.node_file[id]
|
|
212
|
+
if mf == tf and method.kind == 'method' and method.qualified == ty.qualified .. '::' .. parts[index + 1] then
|
|
213
|
+
for n, local_id in ipairs(G.id_of[mf]) do
|
|
214
|
+
if local_id == id and (not entry.external or (data(G, mf, ctx).rust_public or {})[n]) then ids[#ids + 1] = id end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
return { ids = ids }
|
|
220
|
+
else return nil end
|
|
221
|
+
end
|
|
222
|
+
index = index + 1
|
|
223
|
+
end
|
|
224
|
+
return { module = entry }
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
function M.path(G, f, path, ctx, scope)
|
|
228
|
+
return cargo.guard(ctx, walk, G, f, path, ctx, scope or '', {}, 0)
|
|
229
|
+
end
|
|
230
|
+
function M.resolve(G, f, src, name, recv, evidence, ctx)
|
|
231
|
+
if not cargo.owner(G, f, ctx) then return ctx.rust_incomplete and {} or nil, ctx.rust_error end
|
|
232
|
+
if evidence == 'rust:member' then return nil end
|
|
233
|
+
local path = evidence and evidence:match('^rust:path:(.*)$') or (recv and recv .. '::' .. name or name)
|
|
234
|
+
local found, reason = M.path(G, f, path, ctx, scope_of(G, f, src))
|
|
235
|
+
return found and found.ids or {}, reason or 'Cargo crate/module target is not indexed or visible'
|
|
236
|
+
end
|
|
237
|
+
function M.imports(G, f, imp, ctx)
|
|
238
|
+
if not cargo.owner(G, f, ctx) then return ctx.rust_incomplete and {} or nil end
|
|
239
|
+
local result, seen = {}, {}
|
|
240
|
+
local function add(id) if id and not seen[id] then seen[id] = true; result[#result + 1] = id end end
|
|
241
|
+
if imp.kind == 'mod' then
|
|
242
|
+
local entry = child(G, { file = f, scope = '' }, imp.path, ctx)
|
|
243
|
+
if entry then add(entry.file) end
|
|
244
|
+
else
|
|
245
|
+
for _, binding in ipairs(data(G, f, ctx).rust_imports or {}) do
|
|
246
|
+
if binding.line == imp.line then
|
|
247
|
+
local found = M.path(G, f, binding.path, ctx, parent_scope(G, f, binding.parent))
|
|
248
|
+
if found then
|
|
249
|
+
if found.module then add(found.module.file) end
|
|
250
|
+
for _, id in ipairs(found.ids or {}) do add(G.node_file[id]) end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
return result
|
|
256
|
+
end
|
|
257
|
+
function M.members(G, entry, ctx)
|
|
258
|
+
return cargo.guard(ctx, function()
|
|
259
|
+
local result, names, detail = {}, {}, data(G, entry.file, ctx)
|
|
260
|
+
for n, node in ipairs(nodes(G, entry.file, ctx)) do
|
|
261
|
+
if node.kind ~= 'impl' and parent_scope(G, entry.file, node.parent) == entry.scope
|
|
262
|
+
and (not entry.external or (detail.rust_public or {})[n]) then
|
|
263
|
+
names[node.name] = true
|
|
264
|
+
result[#result + 1] = { name = node.name, node = node, file = entry.file, kind = node.kind }
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
for _, imp in ipairs(detail.rust_imports or {}) do
|
|
268
|
+
if imp.public and imp.alias ~= '*' and not names[imp.alias]
|
|
269
|
+
and parent_scope(G, entry.file, imp.parent) == entry.scope then
|
|
270
|
+
local found = M.path(G, entry.file, imp.path, ctx, entry.scope)
|
|
271
|
+
for _, id in ipairs(found and found.ids or {}) do
|
|
272
|
+
result[#result + 1] = { name = imp.alias, node = G.nodes[id], file = G.node_file[id], kind = G.nodes[id].kind }
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
if #result > M.MAX_RESULTS then error('Rust module member limit reached', 0) end
|
|
277
|
+
return result
|
|
278
|
+
end) or {}
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
function M.alias_refs(G, f, wanted, ctx)
|
|
282
|
+
local rec = G.files[f]
|
|
283
|
+
if rec.language ~= 'rust' or #rec.imports == 0 or not cargo.owner(G, f, ctx) then return {} end
|
|
284
|
+
local relevant = false
|
|
285
|
+
for id in pairs(wanted) do
|
|
286
|
+
local target = cargo.owner(G, G.node_file[id], ctx)
|
|
287
|
+
if cargo.reaches(G, f, target, ctx) then relevant = true end
|
|
288
|
+
end
|
|
289
|
+
if not relevant then return {} end
|
|
290
|
+
ctx.rust_alias_files = ctx.rust_alias_files or {}
|
|
291
|
+
if not ctx.rust_alias_files[f] then
|
|
292
|
+
ctx.rust_alias_count = (ctx.rust_alias_count or 0) + 1
|
|
293
|
+
if ctx.rust_alias_count > M.MAX_ALIAS_FILES then ctx.rust_incomplete = true; return {} end
|
|
294
|
+
ctx.rust_alias_files[f] = true
|
|
295
|
+
end
|
|
296
|
+
local refs, result = data(G, f, ctx).refs, {}
|
|
297
|
+
for i, binding in ipairs(refs.binding or {}) do if binding:match('^rust:path:') then result[i] = true end end
|
|
298
|
+
return result
|
|
299
|
+
end
|
|
300
|
+
M.scope = scope_of
|
|
301
|
+
return M
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
-- Per-query search policy. Directory penalties never change graph visibility.
|
|
2
|
+
local rules = require('codeoutline.rules')
|
|
3
|
+
local text = require('codeoutline.text')
|
|
4
|
+
local M = { MAX_DIRECTORIES = 32, MAX_PATH_BYTES = 1024, PENALTY = 6 }
|
|
5
|
+
local defaults = { '/3rd/', '^3rd/', '/third_party/', '^third_party/', '/thirdparty/',
|
|
6
|
+
'/vendor/', '^vendor/', '/node_modules/', '/external/', '^external/', '/deps/', '^deps/' }
|
|
7
|
+
|
|
8
|
+
local function directory(value)
|
|
9
|
+
assert(type(value) == 'string' and value:find('%S') and #value <= M.MAX_PATH_BYTES
|
|
10
|
+
and not value:find('[%z\r\n]') and text.valid(value) == value,
|
|
11
|
+
'deprioritize must contain non-empty UTF-8 directory paths up to 1024 bytes without NUL or newlines')
|
|
12
|
+
value = value:gsub('\\', '/')
|
|
13
|
+
assert(value:sub(1, 1) ~= '/' and not value:find(':', 1, true) and not value:find('[%*%?]'),
|
|
14
|
+
'deprioritize requires project-relative directory prefixes, not absolute paths or globs')
|
|
15
|
+
local parts = {}
|
|
16
|
+
for part in value:gmatch('[^/]+') do
|
|
17
|
+
assert(part ~= '..', 'deprioritize directories must stay inside the project')
|
|
18
|
+
if part ~= '.' then parts[#parts + 1] = part end
|
|
19
|
+
end
|
|
20
|
+
assert(#parts > 0, 'deprioritize must name a directory, not the project root')
|
|
21
|
+
return table.concat(parts, '/') .. '/'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
function M.policy(root)
|
|
25
|
+
local value = rules.read(root).deprioritize
|
|
26
|
+
local prefixes, seen = {}, {}
|
|
27
|
+
local configured = value ~= nil
|
|
28
|
+
if configured then
|
|
29
|
+
assert(type(value) == 'table' and #value <= M.MAX_DIRECTORIES,
|
|
30
|
+
'deprioritize must be an array of at most 32 directory paths')
|
|
31
|
+
local count = 0
|
|
32
|
+
for k in pairs(value) do
|
|
33
|
+
assert(type(k) == 'number' and k % 1 == 0 and k >= 1 and k <= #value, 'deprioritize must be an array')
|
|
34
|
+
count = count + 1
|
|
35
|
+
end
|
|
36
|
+
assert(count == #value, 'deprioritize must be an array')
|
|
37
|
+
for _, path in ipairs(value) do
|
|
38
|
+
local prefix = directory(path)
|
|
39
|
+
if not seen[prefix] then prefixes[#prefixes + 1] = prefix; seen[prefix] = true end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
local cache = {}
|
|
43
|
+
local P = { configured = configured, stats = { configured = configured,
|
|
44
|
+
rules = configured and #prefixes or #defaults, checked_files = 0, matched_files = 0 } }
|
|
45
|
+
function P.penalty(path, explicit)
|
|
46
|
+
-- Keep legacy scores unchanged without configuration. A configured
|
|
47
|
+
-- directory never penalizes an explicitly qualified symbol request.
|
|
48
|
+
if configured and explicit then return 0 end
|
|
49
|
+
local amount = cache[path]
|
|
50
|
+
if amount == nil then
|
|
51
|
+
amount = 0
|
|
52
|
+
if configured then
|
|
53
|
+
for _, prefix in ipairs(prefixes) do
|
|
54
|
+
if path:sub(1, #prefix) == prefix then amount = M.PENALTY; break end
|
|
55
|
+
end
|
|
56
|
+
else
|
|
57
|
+
for _, pattern in ipairs(defaults) do
|
|
58
|
+
if path:find(pattern) then amount = M.PENALTY; break end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
cache[path] = amount
|
|
62
|
+
P.stats.checked_files = P.stats.checked_files + 1
|
|
63
|
+
if amount > 0 then P.stats.matched_files = P.stats.matched_files + 1 end
|
|
64
|
+
end
|
|
65
|
+
return amount
|
|
66
|
+
end
|
|
67
|
+
return P
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
return M
|
|
@@ -14,14 +14,21 @@ local watch = false
|
|
|
14
14
|
-- last one. A resident index makes the heap large, so the garbage of polls
|
|
15
15
|
-- and requests (and a dropped project's whole index) would build up toward
|
|
16
16
|
-- the index's own size; hosts collect it on idle ticks with M.collect.
|
|
17
|
-
local gc = { live = collectgarbage('count'), running = false }
|
|
18
|
-
--
|
|
17
|
+
local gc = { live = collectgarbage('count'), running = false, again = false }
|
|
18
|
+
-- Limit incremental work per idle tick. The collector's atomic phase can take
|
|
19
|
+
-- longer than an ordinary step, so this is not a hard wall-time bound.
|
|
19
20
|
M.GC_MIN_KB, M.GC_STEP_KB = 16384, 512
|
|
20
21
|
|
|
22
|
+
local function reclaim_later()
|
|
23
|
+
-- A cycle already in progress may have marked the index we just dropped.
|
|
24
|
+
-- Finish it, then run a complete new cycle after the owner's stack unwinds.
|
|
25
|
+
gc.running, gc.again = true, true
|
|
26
|
+
end
|
|
27
|
+
|
|
21
28
|
local function drop(key)
|
|
22
29
|
local p = projects[key]
|
|
23
30
|
projects[key] = nil
|
|
24
|
-
if p then p.idx:close();
|
|
31
|
+
if p then p.idx:close(); reclaim_later() end
|
|
25
32
|
end
|
|
26
33
|
|
|
27
34
|
function M.configure(opts)
|
|
@@ -64,13 +71,17 @@ end
|
|
|
64
71
|
-- Run one bounded incremental GC step on an idle tick; returns whether a cycle
|
|
65
72
|
-- is still in progress. A cycle starts once the garbage since the last one
|
|
66
73
|
-- reaches a sixteenth of the live heap (at least GC_MIN_KB), or a project is
|
|
67
|
-
-- dropped, and then advances one step per call until it completes.
|
|
74
|
+
-- dropped/replaced, and then advances one step per call until it completes.
|
|
75
|
+
-- Dropped indexes also need a follow-up cycle to reclaim already-marked objects.
|
|
68
76
|
function M.collect()
|
|
69
77
|
if not gc.running then
|
|
70
78
|
if collectgarbage('count') - gc.live < math.max(M.GC_MIN_KB, gc.live / 16) then return false end
|
|
71
79
|
gc.running = true
|
|
72
80
|
end
|
|
73
|
-
if collectgarbage('step', M.GC_STEP_KB) then
|
|
81
|
+
if collectgarbage('step', M.GC_STEP_KB) then
|
|
82
|
+
if gc.again then gc.again = false
|
|
83
|
+
else gc.running, gc.live = false, collectgarbage('count') end
|
|
84
|
+
end
|
|
74
85
|
return gc.running
|
|
75
86
|
end
|
|
76
87
|
|
|
@@ -151,7 +162,20 @@ local function run_query(engine, root, query, opts)
|
|
|
151
162
|
local ok, result = pcall(function()
|
|
152
163
|
while true do
|
|
153
164
|
-- A GBK repair commits the decoded file, which renumbers its nodes.
|
|
154
|
-
local
|
|
165
|
+
local symbols, source_index, dynamic = idx:symbols(), idx, nil
|
|
166
|
+
if engine == explore then symbols, source_index, dynamic = require('codeoutline.on_demand').open(symbols, idx, query) end
|
|
167
|
+
local output, details = engine.run(symbols, source_index, query, opts)
|
|
168
|
+
if dynamic then
|
|
169
|
+
details.on_demand_files, details.on_demand_rejected, details.on_demand_truncated = dynamic.files, dynamic.rejected, dynamic.truncated
|
|
170
|
+
if output and #dynamic.files > 0 then
|
|
171
|
+
local notices = {}
|
|
172
|
+
for _, file in ipairs(dynamic.files) do
|
|
173
|
+
notices[#notices + 1] = string.format('On-demand source: %s (%s, %s); not stored in the index.', file.path, file.language, file.basis)
|
|
174
|
+
end
|
|
175
|
+
output, details.truncated = require('codeoutline.text').limit(table.concat(notices, '\n') .. '\n' .. output,
|
|
176
|
+
opts and opts.budget or explore.DEFAULT_BUDGET, details.truncated or dynamic.truncated)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
155
179
|
control.check()
|
|
156
180
|
if not details.encoding_retry then return { text = output, info = details } end
|
|
157
181
|
end
|
|
@@ -163,6 +187,10 @@ local function run_query(engine, root, query, opts)
|
|
|
163
187
|
stats.cache_saved, stats.cache_error = saved, err
|
|
164
188
|
end
|
|
165
189
|
result.info.refresh = stats
|
|
190
|
+
result.info.coverage = require('codeoutline.coverage').summarize(result.info)
|
|
191
|
+
result.info.resolution = result.info.query_stats and result.info.query_stats.resolution
|
|
192
|
+
result.info.generation = idx.generation
|
|
193
|
+
result.info.projectPath = idx.root
|
|
166
194
|
return result.text, result.info
|
|
167
195
|
end
|
|
168
196
|
|
|
@@ -174,6 +202,18 @@ function M.callers(root, query, opts)
|
|
|
174
202
|
return run_query(require('codeoutline.callers'), root, query, opts)
|
|
175
203
|
end
|
|
176
204
|
|
|
205
|
+
function M.affected(root, files, opts)
|
|
206
|
+
return run_query(require('codeoutline.affected'), root, files, opts)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
function M.type_hierarchy(root, query, opts)
|
|
210
|
+
return run_query(require('codeoutline.type_hierarchy'), root, query, opts)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
function M.type_references(root, query, opts)
|
|
214
|
+
return run_query(require('codeoutline.type_references'), root, query, opts)
|
|
215
|
+
end
|
|
216
|
+
|
|
177
217
|
function M.status(root, opts)
|
|
178
218
|
local idx, G, stats = M.get(root, opts)
|
|
179
219
|
local languages = {}
|
|
@@ -208,7 +248,7 @@ function M.rebuild(root, opts)
|
|
|
208
248
|
projects[key] = previous
|
|
209
249
|
error(result, 2)
|
|
210
250
|
end
|
|
211
|
-
if previous then previous.idx:close() end
|
|
251
|
+
if previous then previous.idx:close(); reclaim_later() end
|
|
212
252
|
return result
|
|
213
253
|
end
|
|
214
254
|
|