@codua/codeoutline-win32-x64 0.3.0 → 0.3.1
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/DISTRIBUTION.md +93 -8
- package/README.md +112 -2
- package/README.zh-CN.md +86 -2
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/editors/codeoutline.vsix +0 -0
- package/editors/zed/extension.toml +15 -0
- package/editors/zed/extension.wasm +0 -0
- package/package.json +1 -1
- package/scripts/codeoutline/agent_config.lua +291 -0
- package/scripts/codeoutline/agent_install.lua +195 -0
- package/scripts/codeoutline/command.lua +110 -9
- package/scripts/codeoutline/completion.lua +66 -20
- package/scripts/codeoutline/editor_install.lua +168 -0
- package/scripts/codeoutline/external_headers.lua +15 -7
- package/scripts/codeoutline/idle_gc.lua +45 -0
- package/scripts/codeoutline/index.lua +3 -1
- package/scripts/codeoutline/index_worker.lua +39 -5
- package/scripts/codeoutline/install_prompt.lua +15 -0
- package/scripts/codeoutline/lsp.lua +44 -4
- package/scripts/codeoutline/lsp_trace.lua +57 -0
- package/scripts/codeoutline/navigation.lua +38 -6
- package/scripts/codeoutline/service.lua +38 -5
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
- package/scripts/xupgate/client.lua +35 -18
- package/scripts/xupgate/common.lua +2 -2
- package/scripts/xupgate/http_client.lua +6 -1
|
@@ -55,10 +55,10 @@ local function execute(req)
|
|
|
55
55
|
assert(paths.allowed(req.allowedRoots, root), 'project path is outside allowed roots')
|
|
56
56
|
if req.method == 'lsp_refresh' then
|
|
57
57
|
service.configure({ max_projects = lsp.MAX_ROOTS })
|
|
58
|
-
|
|
59
|
-
--
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
-- Navigation startup includes symbol preparation in the same scoped GC
|
|
59
|
+
-- policy as cache loading. Symbol-only clients retain lazy preparation.
|
|
60
|
+
local refresh = req.prepare_navigation and service.get or service.refresh
|
|
61
|
+
refresh(root, { full_interval = 45, paths = req.paths })
|
|
62
62
|
return true
|
|
63
63
|
elseif req.method == 'explore' or req.method == 'callers' or req.method == 'type_hierarchy' or req.method == 'type_references' or req.method == 'affected' then
|
|
64
64
|
local text, info = service[req.method](root, req.method == 'affected' and req.files or req.query, { budget = req.budget, depth = req.depth,
|
|
@@ -74,6 +74,23 @@ end
|
|
|
74
74
|
-- Each job runs in a coroutine so a full refresh can wait for the parse
|
|
75
75
|
-- threads; jobs arriving meanwhile queue behind it.
|
|
76
76
|
local queue, active = {}, nil
|
|
77
|
+
-- Every external reply can release temporary analysis, including errors and
|
|
78
|
+
-- cancellation. Retain one pending timer and yield between collection steps.
|
|
79
|
+
local function gc_option(name, default, minimum)
|
|
80
|
+
local value = tonumber(os.getenv(name) or '')
|
|
81
|
+
if not value or value ~= value or math.abs(value) == math.huge then return default end
|
|
82
|
+
return math.max(minimum, math.floor(value))
|
|
83
|
+
end
|
|
84
|
+
local gc_every = gc_option('CODEOUTLINE_LSP_GC_EVERY', 1, 0)
|
|
85
|
+
local requests = 0
|
|
86
|
+
local gc_delay_ms = gc_option('CODEOUTLINE_LSP_GC_DELAY_MS', 1, 0)
|
|
87
|
+
local gc_step_kb = gc_option('CODEOUTLINE_LSP_GC_STEP_KB', 4096, 1)
|
|
88
|
+
local timer_gc = require('codeoutline.idle_gc').new({
|
|
89
|
+
delay_ms = gc_delay_ms,
|
|
90
|
+
busy = function() return active ~= nil or #queue > 0 end,
|
|
91
|
+
request = service.request_collection,
|
|
92
|
+
step = function() return service.collect(gc_step_kb) end,
|
|
93
|
+
})
|
|
77
94
|
|
|
78
95
|
local function run(id, req, reply)
|
|
79
96
|
if req.queue_until then assert(xthread.post(1, 'worker_started', id)) end
|
|
@@ -96,6 +113,12 @@ local function run(id, req, reply)
|
|
|
96
113
|
else
|
|
97
114
|
assert(xthread.post(1, 'worker_result', id, ok, result))
|
|
98
115
|
end
|
|
116
|
+
requests = requests + 1
|
|
117
|
+
if gc_every > 0 and requests % gc_every == 0 then
|
|
118
|
+
timer_gc.schedule()
|
|
119
|
+
elseif timer_gc.pending() then
|
|
120
|
+
timer_gc.schedule()
|
|
121
|
+
end
|
|
99
122
|
end
|
|
100
123
|
|
|
101
124
|
local function resume(...)
|
|
@@ -116,6 +139,7 @@ end
|
|
|
116
139
|
return {
|
|
117
140
|
__init = function()
|
|
118
141
|
assert(xnet.init())
|
|
142
|
+
xtimer.init()
|
|
119
143
|
local threads = tonumber(os.getenv('CODEOUTLINE_INDEX_THREADS') or '') or pool.THREADS
|
|
120
144
|
pool.configure(scripts .. '/codeoutline/parse_worker.lua', math.max(0, math.floor(threads)))
|
|
121
145
|
assert(xthread.post(1, 'worker_ready'))
|
|
@@ -124,14 +148,23 @@ return {
|
|
|
124
148
|
-- ticks also collect garbage, a step at a time (see service.collect).
|
|
125
149
|
__update = function()
|
|
126
150
|
pool.sweep()
|
|
127
|
-
if not active
|
|
151
|
+
if not active and #queue == 0 then
|
|
152
|
+
service.sweep()
|
|
153
|
+
-- Timer callbacks own pending cycles. Retain idle collection for
|
|
154
|
+
-- allocations/dropped projects that happen after a timer finishes.
|
|
155
|
+
if not timer_gc.pending() then
|
|
156
|
+
service.collect()
|
|
157
|
+
end
|
|
158
|
+
end
|
|
128
159
|
end,
|
|
129
160
|
__thread_handle = function(router, op, id, req, failure, rpc_request)
|
|
130
161
|
if type(router) == 'string' and req == 'run_rpc' then
|
|
131
162
|
-- RPC wire: router, coroutine id, session key, method, job id, request.
|
|
163
|
+
timer_gc.suspend()
|
|
132
164
|
queue[#queue + 1] = { failure, rpc_request, { router = router, co = op, sk = id } }
|
|
133
165
|
pump()
|
|
134
166
|
elseif op == 'run' then
|
|
167
|
+
timer_gc.suspend()
|
|
135
168
|
queue[#queue + 1] = { id, req }
|
|
136
169
|
pump()
|
|
137
170
|
elseif op == 'parsed' then
|
|
@@ -140,6 +173,7 @@ return {
|
|
|
140
173
|
end
|
|
141
174
|
end,
|
|
142
175
|
__uninit = function()
|
|
176
|
+
timer_gc.close()
|
|
143
177
|
pool.stop()
|
|
144
178
|
xnet.uninit()
|
|
145
179
|
end,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Shared terminal confirmation for optional integrations. EOF skips the rest.
|
|
2
|
+
local M = {}
|
|
3
|
+
function M.confirm(message, default)
|
|
4
|
+
while true do
|
|
5
|
+
io.write(message, default and ' [Y/n]\n' or ' [y/N]\n'); io.stdout:flush()
|
|
6
|
+
local answer = io.read('*l')
|
|
7
|
+
if answer == nil then return nil end
|
|
8
|
+
answer = answer:lower():gsub('^%s+', ''):gsub('%s+$', '')
|
|
9
|
+
if answer == '' then return default end
|
|
10
|
+
if answer == 'y' or answer == 'yes' then return true end
|
|
11
|
+
if answer == 'n' or answer == 'no' then return false end
|
|
12
|
+
io.write('Please enter y or n, or press Enter for the default.\n'); io.stdout:flush()
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
return M
|
|
@@ -3,7 +3,8 @@ local paths = require('codeoutline.path')
|
|
|
3
3
|
local text = require('codeoutline.text')
|
|
4
4
|
local M = { MAX_HEADER = 16384, MAX_MESSAGE = 4194304, MAX_ROOTS = 16,
|
|
5
5
|
MAX_DOCUMENTS = 128, MAX_DRAFT_BYTES = 33554432, MAX_PENDING = 64,
|
|
6
|
-
MAX_QUERY = 4096, MAX_SYMBOLS = 200, POLL_MS = 1000, WARM_DELAY_MS = 150
|
|
6
|
+
MAX_QUERY = 4096, MAX_SYMBOLS = 200, POLL_MS = 1000, WARM_DELAY_MS = 150,
|
|
7
|
+
LIMIT_WARNING_MS = 10000 }
|
|
7
8
|
local null = xutils.json_null
|
|
8
9
|
local function array(t) return setmetatable(t or {}, xutils.json_array_mt) end
|
|
9
10
|
local function object(t) return type(t) == 'table' and getmetatable(t) ~= xutils.json_array_mt end
|
|
@@ -95,8 +96,17 @@ function M.new(config, emit, submit, cancel, stop, await_worker)
|
|
|
95
96
|
local self = { state = 'new', documents = {}, roots = {}, pending = {}, scans = {}, ready = {},
|
|
96
97
|
document_bytes = 0, document_count = 0, session = config.session or ('lsp-' .. sessions),
|
|
97
98
|
synced = {}, features = {} }
|
|
99
|
+
local trace = require('codeoutline.lsp_trace').open(os.getenv('CODEOUTLINE_LSP_TRACE'), self.session)
|
|
100
|
+
if trace then
|
|
101
|
+
local transport_emit = emit
|
|
102
|
+
emit = function(msg) trace:message('send', msg); transport_emit(msg) end
|
|
103
|
+
trace:record('start', { source = debug.getinfo(1, 'S').source })
|
|
104
|
+
end
|
|
98
105
|
local progress, server_pending, next_id, next_poll = {}, {}, 0, 0
|
|
99
106
|
local navigation_flights, navigation_epoch = {}, 0
|
|
107
|
+
-- Clients also query definitions while restoring focus or showing links.
|
|
108
|
+
-- Preserve every incomplete report in the log without stacking popups.
|
|
109
|
+
local limit_warnings = {}
|
|
100
110
|
local warm_pending, warm_active, warm_done, warm_pump, focused_uri
|
|
101
111
|
local handlers = {}
|
|
102
112
|
local function error_response(id, code, message)
|
|
@@ -272,6 +282,7 @@ function M.new(config, emit, submit, cancel, stop, await_worker)
|
|
|
272
282
|
end
|
|
273
283
|
local function cancel_pending(id, silent)
|
|
274
284
|
local job = self.pending[id]
|
|
285
|
+
if trace then trace:record('cancel', { id = id, pending = job ~= nil, silent = silent or false }) end
|
|
275
286
|
if job then
|
|
276
287
|
self.pending[id] = nil
|
|
277
288
|
if job.flight then
|
|
@@ -285,6 +296,13 @@ function M.new(config, emit, submit, cancel, stop, await_worker)
|
|
|
285
296
|
if not silent then error_response(id, -32800, 'Request cancelled') end
|
|
286
297
|
end
|
|
287
298
|
end
|
|
299
|
+
local function cancel_completions(uri)
|
|
300
|
+
local ids = {}
|
|
301
|
+
for id, job in pairs(self.pending) do
|
|
302
|
+
if job.method == 'lsp_completion' and job.uri == uri then ids[#ids + 1] = id end
|
|
303
|
+
end
|
|
304
|
+
for _, id in ipairs(ids) do cancel_pending(id) end
|
|
305
|
+
end
|
|
288
306
|
function self:close()
|
|
289
307
|
if self.state == 'closed' then return end
|
|
290
308
|
self.state = 'closed'
|
|
@@ -296,6 +314,7 @@ function M.new(config, emit, submit, cancel, stop, await_worker)
|
|
|
296
314
|
if next(self.synced) or self.worker_session then submit({ method = 'lsp_close', session = self.session }, function() end) end
|
|
297
315
|
self.scans, self.documents, self.ready = {}, {}, {}
|
|
298
316
|
progress, server_pending = {}, {}
|
|
317
|
+
if trace then trace:record('close'); trace:close() end
|
|
299
318
|
end
|
|
300
319
|
handlers.initialize = function(id, params)
|
|
301
320
|
assert(self.state == 'new', 'server already initialized')
|
|
@@ -372,10 +391,12 @@ function M.new(config, emit, submit, cancel, stop, await_worker)
|
|
|
372
391
|
assert(self.document_bytes - #doc.source + #updated.source <= M.MAX_DRAFT_BYTES, 'open document limit reached')
|
|
373
392
|
self.documents[td.uri] = updated
|
|
374
393
|
self.document_bytes = self.document_bytes - #doc.source + #updated.source
|
|
394
|
+
cancel_completions(server_uri(td.uri))
|
|
375
395
|
schedule_warm(td.uri, false, 500)
|
|
376
396
|
end
|
|
377
397
|
handlers['textDocument/didClose'] = function(_, params)
|
|
378
398
|
local uri = params.textDocument.uri
|
|
399
|
+
cancel_completions(server_uri(uri))
|
|
379
400
|
if warm_pending and warm_pending.uri == uri then warm_pending = nil end
|
|
380
401
|
if warm_active and warm_active.uri == uri then cancel_warm() end
|
|
381
402
|
if focused_uri == uri then focused_uri = nil end
|
|
@@ -433,11 +454,15 @@ function M.new(config, emit, submit, cancel, stop, await_worker)
|
|
|
433
454
|
-- Each query owns a coroutine; cancelled/replaced requests discard replies.
|
|
434
455
|
local function request(id, req, started, key)
|
|
435
456
|
cancel_warm()
|
|
457
|
+
if req.method == 'lsp_completion' then cancel_completions(req.uri) end
|
|
436
458
|
if warm_pending and req.uri == server_uri(warm_pending.uri) then warm_pending = nil end
|
|
437
459
|
local count = 0
|
|
438
460
|
for _ in pairs(self.pending) do count = count + 1 end
|
|
439
461
|
assert(count < M.MAX_PENDING, 'too many pending requests')
|
|
440
|
-
local job = { coroutine = coroutine.running() }
|
|
462
|
+
local job = { coroutine = coroutine.running(), method = req.method, uri = req.uri }
|
|
463
|
+
local started_ms = trace and xtimer.now_ms()
|
|
464
|
+
if trace then trace:record('query', { id = id, method = req.method, uri = req.uri,
|
|
465
|
+
position = req.position, epoch = navigation_epoch, shared = key and navigation_flights[key] ~= nil or false }) end
|
|
441
466
|
self.pending[id] = job
|
|
442
467
|
local called, ok, result
|
|
443
468
|
local flight = key and navigation_flights[key]
|
|
@@ -477,6 +502,9 @@ function M.new(config, emit, submit, cancel, stop, await_worker)
|
|
|
477
502
|
if not ok and req.changed then self.synced = {} end
|
|
478
503
|
if self.pending[id] ~= job then return nil, false end
|
|
479
504
|
self.pending[id] = nil
|
|
505
|
+
if trace then trace:record('query_done', { id = id, method = req.method,
|
|
506
|
+
ms = xtimer.now_ms() - started_ms, ok = ok,
|
|
507
|
+
incomplete = type(result) == 'table' and result.incomplete or false }) end
|
|
480
508
|
if not ok then
|
|
481
509
|
error_response(id, -32603, tostring(result))
|
|
482
510
|
return nil, false
|
|
@@ -571,13 +599,24 @@ function M.new(config, emit, submit, cancel, stop, await_worker)
|
|
|
571
599
|
if not ok then return end
|
|
572
600
|
if value.error then error_response(id, -32803, value.error); return end
|
|
573
601
|
if value.incomplete then
|
|
602
|
+
if trace then trace:record('limit', { id = id, method = req.method, uri = req.uri,
|
|
603
|
+
position = req.position, epoch = navigation_epoch }) end
|
|
574
604
|
local message = req.method == 'lsp_definition'
|
|
575
605
|
and 'CodeOutline: definition lookup reached a candidate, source or visibility limit; some definitions may be omitted'
|
|
576
606
|
or req.method == 'lsp_references'
|
|
577
607
|
and 'CodeOutline: results were truncated; too many matching references'
|
|
578
608
|
or 'CodeOutline: lookup reached a query limit; some results may be omitted'
|
|
579
|
-
|
|
580
|
-
|
|
609
|
+
local now, previous = xtimer.now_ms(), limit_warnings[message]
|
|
610
|
+
local show = not previous or now - previous >= M.LIMIT_WARNING_MS
|
|
611
|
+
if show then limit_warnings[message] = now end
|
|
612
|
+
local detail = message
|
|
613
|
+
if not show then
|
|
614
|
+
local position = req.position or {}
|
|
615
|
+
detail = message .. ' [' .. req.method .. ' ' .. (req.uri or '')
|
|
616
|
+
.. ':' .. tostring(position.line or 0) .. ':' .. tostring(position.character or 0) .. ']'
|
|
617
|
+
end
|
|
618
|
+
emit({ jsonrpc = '2.0', method = show and 'window/showMessage' or 'window/logMessage',
|
|
619
|
+
params = { type = 2, message = detail } })
|
|
581
620
|
end
|
|
582
621
|
reply(id, to_client(finish(value.result)))
|
|
583
622
|
end
|
|
@@ -707,6 +746,7 @@ function M.new(config, emit, submit, cancel, stop, await_worker)
|
|
|
707
746
|
function self:accept(body)
|
|
708
747
|
local ok, msg = pcall(xutils.json_unpack, body)
|
|
709
748
|
if not ok or text.valid(body) ~= body then error_response(nil, -32700, 'Invalid JSON'); return end
|
|
749
|
+
if trace and object(msg) then trace:message('receive', msg) end
|
|
710
750
|
if object(msg) and msg.jsonrpc == '2.0' and msg.method == nil and valid_id(msg.id)
|
|
711
751
|
and ((msg.result ~= nil and msg.error == nil) or (msg.result == nil and object(msg.error))) then
|
|
712
752
|
local job = server_pending[msg.id]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
-- Opt-in local protocol metadata; document text and result bodies are omitted.
|
|
2
|
+
local M = {}
|
|
3
|
+
|
|
4
|
+
function M.open(path, session)
|
|
5
|
+
if not path or path == '' then return nil end
|
|
6
|
+
local file, err = io.open(path, 'ab')
|
|
7
|
+
if not file then
|
|
8
|
+
io.stderr:write('[codeoutline lsp trace] cannot open trace: ', tostring(err), '\n')
|
|
9
|
+
return nil
|
|
10
|
+
end
|
|
11
|
+
local self, sequence = {}, 0
|
|
12
|
+
function self:record(event, fields)
|
|
13
|
+
if not file then return end
|
|
14
|
+
sequence = sequence + 1
|
|
15
|
+
local row = { event = event, session = session, sequence = sequence,
|
|
16
|
+
utc = os.date('!%Y-%m-%dT%H:%M:%SZ'), ms = xtimer.now_ms(), fields = fields or {} }
|
|
17
|
+
local ok, failure = file:write(xutils.json_pack(row), '\n')
|
|
18
|
+
if ok then ok, failure = file:flush() end
|
|
19
|
+
if not ok then
|
|
20
|
+
io.stderr:write('[codeoutline lsp trace] write failed: ', tostring(failure), '\n')
|
|
21
|
+
file:close(); file = nil
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
function self:message(direction, msg)
|
|
25
|
+
local fields = { id = msg.id, method = msg.method }
|
|
26
|
+
local params = type(msg.params) == 'table' and msg.params or {}
|
|
27
|
+
local doc = type(params.textDocument) == 'table' and params.textDocument or {}
|
|
28
|
+
fields.uri, fields.version, fields.language = doc.uri, doc.version, doc.languageId
|
|
29
|
+
if type(params.position) == 'table' then
|
|
30
|
+
fields.position = { line = params.position.line, character = params.position.character }
|
|
31
|
+
end
|
|
32
|
+
if type(doc.text) == 'string' then fields.text_bytes = #doc.text end
|
|
33
|
+
if type(params.contentChanges) == 'table' then fields.changes = #params.contentChanges end
|
|
34
|
+
if msg.method == '$/cancelRequest' then fields.cancel_id = params.id end
|
|
35
|
+
if msg.method == 'initialize' then
|
|
36
|
+
fields.client = type(params.clientInfo) == 'table' and params.clientInfo.name or nil
|
|
37
|
+
fields.root_uri = params.rootUri
|
|
38
|
+
end
|
|
39
|
+
if msg.method == 'window/showMessage' or msg.method == 'window/logMessage' then
|
|
40
|
+
fields.message, fields.type = params.message, params.type
|
|
41
|
+
end
|
|
42
|
+
if type(msg.error) == 'table' then fields.error_code = msg.error.code end
|
|
43
|
+
if type(msg.result) == 'table' then
|
|
44
|
+
fields.result_count = #msg.result
|
|
45
|
+
fields.incomplete = msg.result.isIncomplete
|
|
46
|
+
local first = msg.result[1]
|
|
47
|
+
if type(first) == 'table' then fields.target_uri = first.uri or first.targetUri end
|
|
48
|
+
end
|
|
49
|
+
self:record(direction, fields)
|
|
50
|
+
end
|
|
51
|
+
function self:close()
|
|
52
|
+
if file then file:close(); file = nil end
|
|
53
|
+
end
|
|
54
|
+
return self
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
return M
|
|
@@ -752,6 +752,12 @@ local function probe_includes()
|
|
|
752
752
|
return unique
|
|
753
753
|
end
|
|
754
754
|
|
|
755
|
+
function M.external_completions(V, f, prefix, line, expired, limit)
|
|
756
|
+
return require('codeoutline.external_headers').find(V, f,
|
|
757
|
+
{ name = prefix, kind = 'call', reason = 'no indexed target', line = line },
|
|
758
|
+
V.js_context, probe_includes, { expired = expired, limit = limit })
|
|
759
|
+
end
|
|
760
|
+
|
|
755
761
|
-- Locations of the files an import on this line names: project files by the
|
|
756
762
|
-- dependency rules, and C/C++ headers found in the include directories.
|
|
757
763
|
local function import_targets(V, f, line)
|
|
@@ -1320,6 +1326,21 @@ function handlers.lsp_definition(req)
|
|
|
1320
1326
|
return result, V.js_context.include_incomplete or V.js_context.workspace_incomplete or V.js_context.go_incomplete or V.js_context.go_methods_incomplete or V.js_context.cpp_receivers_incomplete or V.js_context.rust_incomplete
|
|
1321
1327
|
end
|
|
1322
1328
|
|
|
1329
|
+
-- Display tags may be truncated before a heavily annotated SDK declaration's
|
|
1330
|
+
-- argument list. Recover only the selected function's bounded source span.
|
|
1331
|
+
local function external_signature(entry)
|
|
1332
|
+
local label, node = entry.node.sig, entry.node
|
|
1333
|
+
if label and not label:match('%.%.%.$') then return label end
|
|
1334
|
+
if not node.name_start then return label end
|
|
1335
|
+
local source = entry.source:sub(node.name_start + 1, node.name_start + 4096)
|
|
1336
|
+
local doc = documents.new(documents.uri(entry.file), source, 0)
|
|
1337
|
+
local T = doc:tokens()
|
|
1338
|
+
if T and T:text(1) == node.name and T:text(2) == '(' and T.m[2] then
|
|
1339
|
+
return source:sub(1, T.e[T.m[2]]):gsub('%s+', ' ')
|
|
1340
|
+
end
|
|
1341
|
+
return label
|
|
1342
|
+
end
|
|
1343
|
+
|
|
1323
1344
|
-- Follow unmatched delimiters up to the cursor. Commas in nested calls,
|
|
1324
1345
|
-- literals and indexing expressions do not advance the enclosing argument.
|
|
1325
1346
|
function handlers.lsp_signature(req)
|
|
@@ -1378,19 +1399,16 @@ function handlers.lsp_signature(req)
|
|
|
1378
1399
|
local query = {}
|
|
1379
1400
|
for key, value in pairs(req) do query[key] = value end
|
|
1380
1401
|
query.position = doc:position(T.s[name_token] - 1)
|
|
1381
|
-
local V, _, c, targets = at(query)
|
|
1402
|
+
local V, _, c, targets, f = at(query)
|
|
1382
1403
|
if not V or not c or c.decl then return false end
|
|
1383
1404
|
local signatures, seen = {}, {}
|
|
1384
|
-
|
|
1385
|
-
local node = V.nodes[id]
|
|
1386
|
-
local foreign = require('codeoutline.foreign').signature(node, doc:parse().language, T:text(name_token))
|
|
1387
|
-
local label = M.detail(V, V.node_file[id], node).sig
|
|
1405
|
+
local function add_signature(node, label, uri, foreign)
|
|
1388
1406
|
if foreign and not seen[foreign.label] then
|
|
1389
1407
|
foreign.activeParameter = #foreign.parameters > 0 and math.min(call.argument, #foreign.parameters - 1) or nil
|
|
1390
1408
|
signatures[#signatures + 1] = foreign
|
|
1391
1409
|
seen[foreign.label] = true
|
|
1392
1410
|
elseif not foreign and REFERENCE[node.kind] and label and not seen[label] then
|
|
1393
|
-
local sig_doc = documents.new(
|
|
1411
|
+
local sig_doc = documents.new(uri, label, 0)
|
|
1394
1412
|
local S = sig_doc:tokens()
|
|
1395
1413
|
local opening
|
|
1396
1414
|
for i = 1, S and S.n - 1 or 0 do
|
|
@@ -1418,6 +1436,20 @@ function handlers.lsp_signature(req)
|
|
|
1418
1436
|
end
|
|
1419
1437
|
end
|
|
1420
1438
|
end
|
|
1439
|
+
for _, id in ipairs(targets) do
|
|
1440
|
+
local node = V.nodes[id]
|
|
1441
|
+
add_signature(node, M.detail(V, V.node_file[id], node).sig, uri_of(V, V.node_file[id]),
|
|
1442
|
+
require('codeoutline.foreign').signature(node, doc:parse().language, T:text(name_token)))
|
|
1443
|
+
end
|
|
1444
|
+
if #targets == 0 and C_FAMILY[doc:parse().language] then
|
|
1445
|
+
-- Share definition lookup's bounded, source-validated external-header
|
|
1446
|
+
-- cache. SDK declarations stay query-local and never enter the index.
|
|
1447
|
+
local entries = require('codeoutline.external_headers').find(V, f,
|
|
1448
|
+
c, V.js_context, probe_includes)
|
|
1449
|
+
for _, entry in ipairs(entries) do
|
|
1450
|
+
add_signature(entry.node, external_signature(entry), documents.uri(entry.file))
|
|
1451
|
+
end
|
|
1452
|
+
end
|
|
1421
1453
|
if #signatures == 0 then return false end
|
|
1422
1454
|
return { signatures = signatures, activeSignature = 0, activeParameter = signatures[1].activeParameter }
|
|
1423
1455
|
end
|
|
@@ -4,6 +4,8 @@ local explore = require('codeoutline.explore')
|
|
|
4
4
|
local paths = require('codeoutline.path')
|
|
5
5
|
local control = require('codeoutline.control')
|
|
6
6
|
local M = {}
|
|
7
|
+
-- Loading uses tighter GC thresholds; queries retain the caller's settings.
|
|
8
|
+
local startup_gc = os.getenv('CODEOUTLINE_MEMORY_POLICY') ~= 'default'
|
|
7
9
|
local projects = {}
|
|
8
10
|
local sequence = 0
|
|
9
11
|
local limits = { max_projects = 8, idle_seconds = 900 }
|
|
@@ -73,12 +75,17 @@ end
|
|
|
73
75
|
-- reaches a sixteenth of the live heap (at least GC_MIN_KB), or a project is
|
|
74
76
|
-- dropped/replaced, and then advances one step per call until it completes.
|
|
75
77
|
-- Dropped indexes also need a follow-up cycle to reclaim already-marked objects.
|
|
76
|
-
|
|
78
|
+
-- Request a cycle without doing marking work on the foreground request.
|
|
79
|
+
function M.request_collection()
|
|
80
|
+
gc.running = true
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
function M.collect(step_kb)
|
|
77
84
|
if not gc.running then
|
|
78
85
|
if collectgarbage('count') - gc.live < math.max(M.GC_MIN_KB, gc.live / 16) then return false end
|
|
79
86
|
gc.running = true
|
|
80
87
|
end
|
|
81
|
-
if collectgarbage('step', M.GC_STEP_KB) then
|
|
88
|
+
if collectgarbage('step', step_kb or M.GC_STEP_KB) then
|
|
82
89
|
if gc.again then gc.again = false
|
|
83
90
|
else gc.running, gc.live = false, collectgarbage('count') end
|
|
84
91
|
end
|
|
@@ -93,10 +100,9 @@ end
|
|
|
93
100
|
|
|
94
101
|
-- Files commit one at a time, so an interrupted refresh needs no rollback:
|
|
95
102
|
-- the index stays consistent and the next refresh resumes with a full pass.
|
|
96
|
-
local function
|
|
103
|
+
local function refresh_project(root, opts, with_symbols)
|
|
97
104
|
opts = opts or {}
|
|
98
105
|
local key, canonical = key_for(root)
|
|
99
|
-
M.sweep()
|
|
100
106
|
local p = projects[key]
|
|
101
107
|
if p then
|
|
102
108
|
for _, name in ipairs({ 'cache_path', 'max_file_bytes', 'lister' }) do
|
|
@@ -135,6 +141,24 @@ local function refresh(root, opts, with_symbols)
|
|
|
135
141
|
return p.idx, with_symbols and p.idx:symbols() or nil, stats
|
|
136
142
|
end
|
|
137
143
|
|
|
144
|
+
-- Keep transient cache decoding/building allocations below the resident heap's
|
|
145
|
+
-- normal GC threshold. Restore the caller's settings before serving queries,
|
|
146
|
+
-- including when opening, indexing, saving or cancellation raises an error.
|
|
147
|
+
local function refresh(root, opts, with_symbols)
|
|
148
|
+
local key = key_for(root)
|
|
149
|
+
M.sweep()
|
|
150
|
+
if not startup_gc or projects[key] then
|
|
151
|
+
return refresh_project(root, opts, with_symbols)
|
|
152
|
+
end
|
|
153
|
+
local pause = collectgarbage('setpause', 100)
|
|
154
|
+
local stepmul = collectgarbage('setstepmul', 500)
|
|
155
|
+
local ok, idx, symbols, stats = pcall(refresh_project, root, opts, with_symbols)
|
|
156
|
+
collectgarbage('setpause', pause)
|
|
157
|
+
collectgarbage('setstepmul', stepmul)
|
|
158
|
+
if not ok then error(idx, 0) end
|
|
159
|
+
return idx, symbols, stats
|
|
160
|
+
end
|
|
161
|
+
|
|
138
162
|
-- LSP refreshes records; symbol tables are kept current only once built.
|
|
139
163
|
function M.refresh(root, opts)
|
|
140
164
|
local idx, _, stats = refresh(root, opts, false)
|
|
@@ -155,7 +179,7 @@ function M.resident(root)
|
|
|
155
179
|
return p.idx, p.idx.symbol_tables
|
|
156
180
|
end
|
|
157
181
|
|
|
158
|
-
local function
|
|
182
|
+
local function execute_query(engine, root, query, opts)
|
|
159
183
|
engine.validate(query, opts)
|
|
160
184
|
local idx, _, stats = refresh(root, opts, true)
|
|
161
185
|
idx.query_sources = {}
|
|
@@ -194,6 +218,15 @@ local function run_query(engine, root, query, opts)
|
|
|
194
218
|
return result.text, result.info
|
|
195
219
|
end
|
|
196
220
|
|
|
221
|
+
-- Agent work can spend longer reclaiming its temporary analysis. Keep this
|
|
222
|
+
-- outside execute_query's stack and leave LSP navigation on its idle GC path.
|
|
223
|
+
local function run_query(engine, root, query, opts)
|
|
224
|
+
local ok, text, info = pcall(execute_query, engine, root, query, opts)
|
|
225
|
+
if os.getenv('CODEOUTLINE_AGENT_GC') ~= '0' then collectgarbage('collect') end
|
|
226
|
+
if not ok then error(text, 0) end
|
|
227
|
+
return text, info
|
|
228
|
+
end
|
|
229
|
+
|
|
197
230
|
function M.explore(root, query, opts)
|
|
198
231
|
return run_query(explore, root, query, opts)
|
|
199
232
|
end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return
|
|
1
|
+
return 20
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return '0.3.
|
|
1
|
+
return '0.3.1'
|
|
@@ -34,9 +34,9 @@ end
|
|
|
34
34
|
local leases={}
|
|
35
35
|
-- Returns nil outside an update directory (the initial installation is never pruned).
|
|
36
36
|
function M.lease(files_root)
|
|
37
|
-
local root,
|
|
38
|
-
if not root or
|
|
39
|
-
local path=root .. '/leases/' ..
|
|
37
|
+
local root,version=files_root:gsub('\\','/'):match('^(.*)/versions/([^/]+)/files/?$')
|
|
38
|
+
if not root or not c.version(version) or not u.mkdir_p(root .. '/leases') then return nil end
|
|
39
|
+
local path=root .. '/leases/' .. version .. '-' .. token()
|
|
40
40
|
local handle
|
|
41
41
|
if windows then
|
|
42
42
|
handle=io.open(path,'wb');if not handle then return nil end
|
|
@@ -67,13 +67,18 @@ function M.open(config)
|
|
|
67
67
|
local data=c.read(root .. '/current.json',1048576)
|
|
68
68
|
if not data then
|
|
69
69
|
assert(not u.stat(root .. '/current.json').exists,'local state unreadable')
|
|
70
|
-
return {schema=
|
|
70
|
+
return {schema=2,highSequence=config.minimumSequence or 0}
|
|
71
71
|
end
|
|
72
72
|
local value=assert(c.decode_json(data),'corrupt local state')
|
|
73
|
-
assert(value.schema==
|
|
73
|
+
assert(value.schema==2, 'unsupported update state; stop old processes, remove the old update cache and reinstall CodeOutline')
|
|
74
|
+
assert(type(value.highSequence)=='number' and value.highSequence>=0 and value.highSequence%1==0,'invalid local state')
|
|
74
75
|
value.highSequence=math.max(value.highSequence,config.minimumSequence or 0)
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
for _, key in ipairs({ 'current', 'previous' }) do
|
|
77
|
+
local version, identity = value[key], value[key .. 'Identity']
|
|
78
|
+
assert(not version or c.version(version), 'invalid ' .. key .. ' version')
|
|
79
|
+
assert(not version and not identity or version and type(identity)=='string'
|
|
80
|
+
and #identity==64 and identity:match('^[0-9a-f]+$'), 'invalid ' .. key .. ' identity')
|
|
81
|
+
end
|
|
77
82
|
return value
|
|
78
83
|
end
|
|
79
84
|
local function save(value)c.atomic(root .. '/current.json',assert(u.json_pack(value)))end
|
|
@@ -93,9 +98,9 @@ function M.open(config)
|
|
|
93
98
|
local now,busy=os.time(),{}
|
|
94
99
|
for _,entry in ipairs(u.list_dir(root .. '/leases') or {})do
|
|
95
100
|
local path=root .. '/leases/' .. entry.name
|
|
96
|
-
local
|
|
97
|
-
if not
|
|
98
|
-
elseif lease_alive(path)then busy[
|
|
101
|
+
local version=entry.name:match('^(%d+%.%d+%.%d+)%-%x+$')
|
|
102
|
+
if not version then os.remove(path)
|
|
103
|
+
elseif lease_alive(path)then busy[version]=true end
|
|
99
104
|
end
|
|
100
105
|
for _,entry in ipairs(u.list_dir(root .. '/versions') or {})do
|
|
101
106
|
local removable=entry.dir and not keep[entry.name] and not busy[entry.name]
|
|
@@ -146,7 +151,8 @@ function M.open(config)
|
|
|
146
151
|
local envelope=c.decode_json(assert(c.read(dir .. '/manifest.json',1048576)))
|
|
147
152
|
local m=verified(envelope)
|
|
148
153
|
assert(u.stat(dir .. '/complete').exists,'installation incomplete')
|
|
149
|
-
assert(
|
|
154
|
+
assert(m.version==s.current,'active version directory mismatch')
|
|
155
|
+
assert(u.sha256_hex(envelope.payload)==s.currentIdentity,'invalid active identity')
|
|
150
156
|
local files=c.bundle(assert(c.read(dir .. '/bundle.json')),m)
|
|
151
157
|
for _,f in ipairs(files)do assert(c.read(dir .. '/files/' .. f.path)==f.data,'installed file changed')end
|
|
152
158
|
for path, hash in pairs(m.runtimeFiles or {}) do
|
|
@@ -168,9 +174,18 @@ function M.open(config)
|
|
|
168
174
|
return locked(function()
|
|
169
175
|
local s=state()
|
|
170
176
|
assert(m.sequence>=s.highSequence,'downgrade/replay rejected; use explicit local rollback')
|
|
171
|
-
if s.current==
|
|
172
|
-
|
|
173
|
-
|
|
177
|
+
if s.current==m.version then
|
|
178
|
+
assert(s.currentIdentity==identity, 'different content for an installed version; publish a new version number')
|
|
179
|
+
return api.current()
|
|
180
|
+
end
|
|
181
|
+
if m.sequence==s.highSequence and s.current then assert(s.previousIdentity==identity,'different content at previously accepted sequence')end
|
|
182
|
+
local dir=root .. '/versions/' .. m.version
|
|
183
|
+
if u.stat(dir .. '/complete').exists then
|
|
184
|
+
local existing=assert(c.decode_json(c.read(dir .. '/manifest.json',1048576)), 'installed manifest missing')
|
|
185
|
+
local original=verified(existing)
|
|
186
|
+
assert(original.version==m.version and u.sha256_hex(existing.payload)==identity,
|
|
187
|
+
'different content for an installed version; publish a new version number')
|
|
188
|
+
end
|
|
174
189
|
if not u.stat(dir .. '/complete').exists then
|
|
175
190
|
assert(u.mkdir_p(dir .. '/files'))
|
|
176
191
|
for _,f in ipairs(files)do
|
|
@@ -207,25 +222,27 @@ function M.open(config)
|
|
|
207
222
|
end
|
|
208
223
|
if config.validate then assert(config.validate(dir .. '/files',m),'project health validation failed')end
|
|
209
224
|
local previous=config.keepPrevious~=false and s.current or nil
|
|
210
|
-
save({schema=
|
|
225
|
+
save({schema=2,highSequence=math.max(s.highSequence,m.sequence),previous=previous,
|
|
226
|
+
previousIdentity=previous and s.currentIdentity or nil,current=m.version,currentIdentity=identity})
|
|
211
227
|
local ok,result=pcall(api.current)
|
|
212
228
|
if not ok then save(s);error(result)end
|
|
213
229
|
-- Cleanup never fails an installation that is already active.
|
|
214
|
-
if config.prune then pcall(prune,{[
|
|
230
|
+
if config.prune then pcall(prune,{[m.version]=true,[previous or m.version]=true})end
|
|
215
231
|
return result
|
|
216
232
|
end)
|
|
217
233
|
end
|
|
218
234
|
function api.use_initial()
|
|
219
235
|
return locked(function()
|
|
220
236
|
local s=state()
|
|
221
|
-
save({schema=
|
|
237
|
+
save({schema=2,highSequence=s.highSequence,previous=s.current,previousIdentity=s.currentIdentity})
|
|
222
238
|
return {initial=true}
|
|
223
239
|
end)
|
|
224
240
|
end
|
|
225
241
|
function api.rollback()
|
|
226
242
|
return locked(function()
|
|
227
243
|
local s=state();assert(s.previous,'no previous version')
|
|
228
|
-
save({schema=
|
|
244
|
+
save({schema=2,highSequence=s.highSequence,current=s.previous,currentIdentity=s.previousIdentity,
|
|
245
|
+
previous=s.current,previousIdentity=s.currentIdentity})
|
|
229
246
|
local ok,result=pcall(api.current)
|
|
230
247
|
if not ok then save(s);error(result)end
|
|
231
248
|
return result
|
|
@@ -43,10 +43,10 @@ function M.manifest(envelope, public_key)
|
|
|
43
43
|
assert(require('xupgate.signature').verify(public_key, envelope.payload, sig), 'manifest signature invalid')
|
|
44
44
|
local m = assert(M.decode_json(envelope.payload), 'invalid manifest JSON')
|
|
45
45
|
assert(m.schema == 1 and M.id(m.project) and M.version(m.version) and M.id(m.platform), 'invalid manifest identity')
|
|
46
|
-
assert(m.minUpdater == 1 or m.minUpdater == 2, 'unsupported updater version')
|
|
46
|
+
assert(m.minUpdater == 1 or m.minUpdater == 2 or m.minUpdater == 3, 'unsupported updater version')
|
|
47
47
|
assert(m.kind == nil or m.kind == 'full' or m.kind == 'scripts', 'invalid package kind')
|
|
48
48
|
if m.kind == 'scripts' then
|
|
49
|
-
assert(m.minUpdater
|
|
49
|
+
assert(m.minUpdater >= 2 and type(m.runtimeFiles) == 'table' and M.path(m.runtime), 'script package requires updater 2 or newer and runtime references')
|
|
50
50
|
local count, seen = 0, {}
|
|
51
51
|
for path, hash in pairs(m.runtimeFiles) do
|
|
52
52
|
assert(M.path(path) and type(hash) == 'string' and #hash == 64 and hash:match('^[0-9a-f]+$'), 'invalid runtime reference')
|
|
@@ -122,10 +122,15 @@ make_handler = function(state)
|
|
|
122
122
|
local h = {}
|
|
123
123
|
|
|
124
124
|
function h.on_connect(conn)
|
|
125
|
+
-- The runtime's default send queue is 10 MiB. A request is sent as a
|
|
126
|
+
-- single buffer, so size this connection's queue for that buffer.
|
|
127
|
+
if #state.request_bytes > 10 * 1024 * 1024 and conn.set_max_send then
|
|
128
|
+
conn:set_max_send(#state.request_bytes)
|
|
129
|
+
end
|
|
125
130
|
local ok, serr = conn:send_raw(state.request_bytes)
|
|
126
131
|
if not ok then
|
|
127
|
-
conn:close('send_failed')
|
|
128
132
|
fire_once(state, 'send failed: ' .. tostring(serr))
|
|
133
|
+
conn:close('send_failed')
|
|
129
134
|
end
|
|
130
135
|
end
|
|
131
136
|
|