@codua/codeoutline-win32-x64 0.3.9 → 0.5.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.
- package/README.md +44 -0
- package/README.zh-CN.md +33 -0
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/editors/codeoutline.vsix +0 -0
- package/editors/zed/extension.wasm +0 -0
- package/package.json +1 -1
- package/scripts/codeoutline/analysis/indirect.lua +18 -12
- package/scripts/codeoutline/analysis/lua/lua_bindings.lua +28 -0
- package/scripts/codeoutline/bm25/automatic.lua +100 -0
- package/scripts/codeoutline/bm25/collect.lua +148 -0
- package/scripts/codeoutline/bm25/index.lua +548 -0
- package/scripts/codeoutline/bm25/snapshot.lua +45 -0
- package/scripts/codeoutline/indexing/parse_pool.lua +12 -6
- package/scripts/codeoutline/main.lua +5 -1
- package/scripts/codeoutline/protocol/lsp.lua +3 -1
- package/scripts/codeoutline/protocol/mcp.lua +5 -2
- package/scripts/codeoutline/query/coverage.lua +2 -0
- package/scripts/codeoutline/query/definition_candidates.lua +24 -4
- package/scripts/codeoutline/query/explore.lua +110 -18
- package/scripts/codeoutline/query/navigation.lua +189 -19
- package/scripts/codeoutline/query/query_filters.lua +5 -1
- package/scripts/codeoutline/runtime/bm25_worker.lua +86 -0
- package/scripts/codeoutline/runtime/index_worker.lua +18 -5
- package/scripts/codeoutline/runtime/parse_worker.lua +10 -3
- package/scripts/codeoutline/service.lua +6 -0
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
local source = assert(xutils.realpath(debug.getinfo(1, 'S').source:sub(2))):gsub('\\', '/')
|
|
2
|
+
local scripts = assert(source:match('^(.*)/codeoutline/runtime/[^/]+$'))
|
|
3
|
+
package.path = scripts .. '/?.lua;' .. package.path
|
|
4
|
+
local indexing = require('codeoutline.indexing.index')
|
|
5
|
+
local bm25 = require('codeoutline.bm25.index')
|
|
6
|
+
local snapshot = require('codeoutline.bm25.snapshot')
|
|
7
|
+
local control = require('codeoutline.shared.control')
|
|
8
|
+
local pool = require('codeoutline.indexing.parse_pool')
|
|
9
|
+
local shared = assert(xshared.dict('codeoutline_control'))
|
|
10
|
+
local job
|
|
11
|
+
|
|
12
|
+
local function build(item)
|
|
13
|
+
control.check()
|
|
14
|
+
local index = indexing.open(item.root, {cache_path = item.cache})
|
|
15
|
+
local ok, err = pcall(function()
|
|
16
|
+
assert(index.cache_loaded and snapshot.stamp(index) == item.stamp, 'base snapshot changed before BM25 build')
|
|
17
|
+
if item.repair or not snapshot.current(item.file, item.stamp) then bm25.build(index, item.file) end
|
|
18
|
+
end)
|
|
19
|
+
index:close()
|
|
20
|
+
if not ok then error(err, 0) end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
local function advance(...)
|
|
24
|
+
local ok, err = coroutine.resume(job, ...)
|
|
25
|
+
if not ok then
|
|
26
|
+
io.stderr:write('[codeoutline bm25] ', tostring(err), '\n')
|
|
27
|
+
job = nil
|
|
28
|
+
pool.bind(nil)
|
|
29
|
+
elseif coroutine.status(job) == 'dead' then
|
|
30
|
+
job = nil
|
|
31
|
+
pool.bind(nil)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
local function lookup(request)
|
|
36
|
+
local previous = control.callback
|
|
37
|
+
control.callback = function()
|
|
38
|
+
previous()
|
|
39
|
+
if xtimer.now_ms() >= request.deadline then error(control.deadline(), 0) end
|
|
40
|
+
end
|
|
41
|
+
local ok, result = pcall(function()
|
|
42
|
+
control.check()
|
|
43
|
+
local hits = bm25.search(snapshot.reader(request.root, request.stamp), request.file, request.query, {
|
|
44
|
+
match = 'all', limit = 20, prefix = request.prefix,
|
|
45
|
+
})
|
|
46
|
+
control.check()
|
|
47
|
+
return hits
|
|
48
|
+
end)
|
|
49
|
+
control.callback = previous
|
|
50
|
+
return ok, ok and result or tostring(result)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
__init = function()
|
|
55
|
+
assert(xnet.init())
|
|
56
|
+
-- Keep worker IDs separate from the foreground index's parse pool.
|
|
57
|
+
pool.FIRST_ID = 256
|
|
58
|
+
pool.configure(scripts .. '/codeoutline/runtime/parse_worker.lua', pool.configured_threads())
|
|
59
|
+
control.callback = function()
|
|
60
|
+
if shared:get('shutdown') then error(control.cancelled(), 0) end
|
|
61
|
+
end
|
|
62
|
+
end,
|
|
63
|
+
__thread_handle = function(_, op, owner_or_token, item_or_results, failure)
|
|
64
|
+
if op == 'bm25_lookup' then
|
|
65
|
+
local ok, result = false, 'BM25 builder is busy'
|
|
66
|
+
if not job then ok, result = lookup(failure) end
|
|
67
|
+
xthread.post(owner_or_token, 'bm25_lookup_done', item_or_results, ok, result)
|
|
68
|
+
elseif op == 'bm25_build' then
|
|
69
|
+
local owner, item = owner_or_token, item_or_results
|
|
70
|
+
job = coroutine.create(function()
|
|
71
|
+
local ok, err = pcall(build, item)
|
|
72
|
+
if not ok and not control.is_interrupted(err) then
|
|
73
|
+
io.stderr:write('[codeoutline bm25] ', tostring(err), '\n')
|
|
74
|
+
end
|
|
75
|
+
pool.stop('BM25 snapshot complete')
|
|
76
|
+
collectgarbage('collect')
|
|
77
|
+
xthread.post(owner, 'bm25_done', item.file, item.stamp, ok)
|
|
78
|
+
end)
|
|
79
|
+
pool.bind(job)
|
|
80
|
+
advance()
|
|
81
|
+
elseif op == 'parsed' and pool.receive(owner_or_token) and job and pool.waiting() then
|
|
82
|
+
advance(owner_or_token, item_or_results, failure)
|
|
83
|
+
end
|
|
84
|
+
end,
|
|
85
|
+
__uninit = function() pool.stop(); xnet.uninit() end,
|
|
86
|
+
}
|
|
@@ -11,9 +11,13 @@ local pool = require('codeoutline.indexing.parse_pool')
|
|
|
11
11
|
require('codeoutline.query.completion') -- registers lsp_completion
|
|
12
12
|
service.configure({ watch = true })
|
|
13
13
|
local shared = assert(xshared.dict('codeoutline_control'))
|
|
14
|
+
local bm25 = shared:get('bm25_worker') and require('codeoutline.bm25.automatic')
|
|
14
15
|
|
|
15
16
|
local function execute(req)
|
|
16
|
-
if navigation.handles(req.method) then
|
|
17
|
+
if navigation.handles(req.method) then
|
|
18
|
+
if bm25 and req.method == 'lsp_definition' then req.bm25_definition = bm25.definition end
|
|
19
|
+
return navigation.execute(req)
|
|
20
|
+
end
|
|
17
21
|
if req.method == 'lsp_close' then navigation.close(req.session); return true end
|
|
18
22
|
if req.method == 'lsp_symbols' then
|
|
19
23
|
local result = {}
|
|
@@ -62,9 +66,10 @@ local function execute(req)
|
|
|
62
66
|
return true
|
|
63
67
|
elseif req.method == 'explore' or req.method == 'callers' or req.method == 'type_hierarchy' or req.method == 'type_references' or req.method == 'affected' then
|
|
64
68
|
local text, info = service[req.method](root, req.method == 'affected' and req.files or req.query, { budget = req.budget, depth = req.depth,
|
|
65
|
-
max_nodes = req.max_nodes, direction = req.direction
|
|
69
|
+
max_nodes = req.max_nodes, direction = req.direction, bm25_match = req.bm25_match,
|
|
70
|
+
prepare_bm25 = req.method == 'explore' and bm25 and bm25.prepare or nil })
|
|
66
71
|
return { text = text, truncated = info.truncated or false, coverage = info.coverage,
|
|
67
|
-
resolution = info.resolution, generation = info.generation, refresh = info.refresh }
|
|
72
|
+
resolution = info.resolution, generation = info.generation, refresh = info.refresh, bm25 = info.bm25 }
|
|
68
73
|
elseif req.method == 'status' then return service.status(root)
|
|
69
74
|
elseif req.method == 'rebuild' then return service.rebuild(root)
|
|
70
75
|
else error('unknown operation') end
|
|
@@ -140,15 +145,16 @@ return {
|
|
|
140
145
|
__init = function()
|
|
141
146
|
assert(xnet.init())
|
|
142
147
|
xtimer.init()
|
|
143
|
-
|
|
144
|
-
pool.configure(scripts .. '/codeoutline/runtime/parse_worker.lua', math.max(0, math.floor(threads)))
|
|
148
|
+
pool.configure(scripts .. '/codeoutline/runtime/parse_worker.lua', pool.configured_threads())
|
|
145
149
|
assert(xthread.post(1, 'worker_ready'))
|
|
146
150
|
end,
|
|
147
151
|
-- A suspended job still holds its project: sweeping waits for it. Idle
|
|
148
152
|
-- ticks also collect garbage, a step at a time (see service.collect).
|
|
149
153
|
__update = function()
|
|
154
|
+
if bm25 and bm25.expire_lookup() and active then resume(false); pump() end
|
|
150
155
|
pool.sweep()
|
|
151
156
|
if not active and #queue == 0 then
|
|
157
|
+
if bm25 then bm25.pump() end
|
|
152
158
|
service.sweep()
|
|
153
159
|
-- Timer callbacks own pending cycles. Retain idle collection for
|
|
154
160
|
-- allocations/dropped projects that happen after a timer finishes.
|
|
@@ -170,7 +176,14 @@ return {
|
|
|
170
176
|
elseif op == 'parsed' then
|
|
171
177
|
-- (token, results, failure); stale tokens are dropped by the pool.
|
|
172
178
|
if pool.receive(id) and active and pool.waiting() then resume(id, req, failure); pump() end
|
|
179
|
+
elseif op == 'bm25_done' and bm25 then
|
|
180
|
+
bm25.finish(id, req, failure)
|
|
181
|
+
elseif op == 'bm25_lookup_done' and bm25 then
|
|
182
|
+
if bm25.receive_lookup(id) and active then resume(req, failure); pump() end
|
|
173
183
|
end
|
|
184
|
+
-- Dispatch after foreground processing, even when a project is queried
|
|
185
|
+
-- by name and will never consult the lexical index in this request.
|
|
186
|
+
if bm25 and not active and #queue == 0 then bm25.pump() end
|
|
174
187
|
end,
|
|
175
188
|
__uninit = function()
|
|
176
189
|
timer_gc.close()
|
|
@@ -8,13 +8,20 @@ local shared = assert(xshared.dict('codeoutline_control'))
|
|
|
8
8
|
|
|
9
9
|
return {
|
|
10
10
|
__thread_handle = function(_, op, owner, token, max_bytes, files)
|
|
11
|
-
if op ~= 'parse' then return end
|
|
11
|
+
if op ~= 'parse' and op ~= 'bm25_collect' then return end
|
|
12
12
|
local results = {}
|
|
13
|
+
local abort_key = 'parse_abort:' .. owner
|
|
13
14
|
local ok, err = pcall(function()
|
|
15
|
+
local load = op == 'parse' and index.load_file or require('codeoutline.bm25.collect').file
|
|
14
16
|
for i, f in ipairs(files) do
|
|
15
17
|
-- An abandoned pass (cancelled, failed, shutting down) skips its rest.
|
|
16
|
-
if shared:get('shutdown') or (shared:get(
|
|
17
|
-
local res
|
|
18
|
+
if shared:get('shutdown') or (shared:get(abort_key) or 0) >= token then return end
|
|
19
|
+
local res
|
|
20
|
+
if op == 'parse' then
|
|
21
|
+
res = load(f[2], f[1], max_bytes, f[3] or nil, f[4] or nil, f[5] or nil)
|
|
22
|
+
else
|
|
23
|
+
res = load(f[2], f[1], f[3], f[4], f[5], f[6])
|
|
24
|
+
end
|
|
18
25
|
res.rel = f[1]
|
|
19
26
|
results[i] = res
|
|
20
27
|
end
|
|
@@ -182,6 +182,12 @@ end
|
|
|
182
182
|
local function execute_query(engine, root, query, opts)
|
|
183
183
|
engine.validate(query, opts)
|
|
184
184
|
local idx, _, stats = refresh(root, opts, true)
|
|
185
|
+
if engine == explore and opts and opts.prepare_bm25 then
|
|
186
|
+
local query_opts = {}
|
|
187
|
+
for key, value in pairs(opts) do query_opts[key] = value end
|
|
188
|
+
query_opts.bm25_fallback = opts.prepare_bm25(idx)
|
|
189
|
+
opts = query_opts
|
|
190
|
+
end
|
|
185
191
|
idx.query_sources = {}
|
|
186
192
|
local ok, result = pcall(function()
|
|
187
193
|
while true do
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return
|
|
1
|
+
return 29
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return '0.
|
|
1
|
+
return '0.5.0'
|