@codua/codeoutline-win32-x64 0.2.9 → 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/cpp_types.lua +12 -3
- package/scripts/codeoutline/definition_candidates.lua +13 -7
- package/scripts/codeoutline/editor_install.lua +168 -0
- package/scripts/codeoutline/external_headers.lua +22 -9
- package/scripts/codeoutline/foreign.lua +23 -3
- 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/lang/cpp.lua +25 -14
- package/scripts/codeoutline/lsp.lua +44 -4
- package/scripts/codeoutline/lsp_trace.lua +57 -0
- package/scripts/codeoutline/navigation.lua +109 -11
- package/scripts/codeoutline/service.lua +38 -5
- package/scripts/codeoutline/type_references.lua +3 -2
- 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
|
@@ -189,11 +189,12 @@ local function recursive(node, recv)
|
|
|
189
189
|
end
|
|
190
190
|
|
|
191
191
|
-- Targets of one occurrence of name in file f, enclosed by node index from.
|
|
192
|
-
local function resolve_site(V, f, from, name, kind, recv, evidence, offset, index, cursor_line)
|
|
192
|
+
local function resolve_site(V, f, from, name, kind, recv, evidence, offset, index, cursor_line, definition)
|
|
193
193
|
if kind == 'type' then
|
|
194
194
|
local site = type(evidence) == 'table' and evidence
|
|
195
195
|
if not site then return {}, 'unsupported type position' end
|
|
196
|
-
return require('codeoutline.type_references').resolve(V, f, from > 0 and V.id_of[f][from] or nil,
|
|
196
|
+
return require('codeoutline.type_references').resolve(V, f, from > 0 and V.id_of[f][from] or nil,
|
|
197
|
+
site, V.js_context, nil, definition)
|
|
197
198
|
end
|
|
198
199
|
if index then evidence = V.js_context.ordinary.evidence(f, index) end
|
|
199
200
|
if V.files[f].language == 'go' and offset and evidence ~= 'go:?' and not (evidence and evidence:match('^go:expr:')) then
|
|
@@ -204,7 +205,8 @@ local function resolve_site(V, f, from, name, kind, recv, evidence, offset, inde
|
|
|
204
205
|
local direct, paired = deps(V, f)
|
|
205
206
|
local rkind, accept = kind, nil
|
|
206
207
|
if kind == 'symbol' then rkind, accept = 'call', ANY
|
|
207
|
-
elseif kind == 'member_symbol' then rkind, accept = 'member_call', ANY
|
|
208
|
+
elseif kind == 'member_symbol' then rkind, accept = 'member_call', ANY
|
|
209
|
+
elseif definition and kind == 'member_call' and V.files[f].language == 'cpp' then accept = ANY end
|
|
208
210
|
local site_line = index and V.files[f].refs.line[index] or cursor_line
|
|
209
211
|
local targets, reason, macro_state = graph.resolve(V, f, src, name, rkind, recv or nil, direct, paired, accept, evidence, V.js_context, site_line)
|
|
210
212
|
targets = targets or {}
|
|
@@ -285,7 +287,65 @@ local function find_cursor(doc, offset, strict, parsed)
|
|
|
285
287
|
end
|
|
286
288
|
end
|
|
287
289
|
|
|
290
|
+
local macro_body_scanners = {}
|
|
291
|
+
local function macro_body_cursor(doc, offset, rec)
|
|
292
|
+
if not C_FAMILY[rec.language] then return nil end
|
|
293
|
+
local line = doc:position(offset).line + 1
|
|
294
|
+
while line > 1 do
|
|
295
|
+
local previous = doc.source:sub(doc.lines[line - 1] + 1, doc.lines[line]):gsub('[\r\n]+$', '')
|
|
296
|
+
if not previous:match('\\$') then break end
|
|
297
|
+
line = line - 1
|
|
298
|
+
end
|
|
299
|
+
if not doc.source:sub(doc.lines[line] + 1, (doc.lines[line + 1] or #doc.source)):match('^%s*#%s*define%s') then return nil end
|
|
300
|
+
local T = doc:tokens(true)
|
|
301
|
+
for i = 1, T.n do
|
|
302
|
+
if T.s[i] - 1 > offset then break end
|
|
303
|
+
if T.k[i] == 'dir' and T.s[i] - 1 <= offset and offset < T.e[i] then
|
|
304
|
+
local text = T:text(i)
|
|
305
|
+
local name_start, name = text:match('^#%s*define%s+()([%a_][%w_]*)')
|
|
306
|
+
if not name then return nil end
|
|
307
|
+
local start = T.s[i] - 1
|
|
308
|
+
if offset < start + name_start - 1 + #name then return nil end
|
|
309
|
+
local scanner = macro_body_scanners[rec.language]
|
|
310
|
+
if not scanner then
|
|
311
|
+
local config = {}
|
|
312
|
+
for k, v in pairs(require('codeoutline.lang.' .. rec.language).config) do config[k] = v end
|
|
313
|
+
config.directive, config.pp_first_branch = nil, nil
|
|
314
|
+
scanner = require('codeoutline.xscan').lang(config)
|
|
315
|
+
macro_body_scanners[rec.language] = scanner
|
|
316
|
+
end
|
|
317
|
+
local body = scanner:tokenize(text)
|
|
318
|
+
local macro, parameters = nil, {}
|
|
319
|
+
for n = 1, body.n do if body.s[n] == name_start then macro = n; break end end
|
|
320
|
+
if not macro then return false end
|
|
321
|
+
local first = macro + 1
|
|
322
|
+
if body:text(first) == '(' and body.s[first] == body.e[macro] + 1 and body.m[first] then
|
|
323
|
+
local close = body.m[first]
|
|
324
|
+
for n = first + 1, close - 1 do if body.k[n] == 'id' then parameters[body:text(n)] = true end end
|
|
325
|
+
first = close + 1
|
|
326
|
+
end
|
|
327
|
+
for n = first, body.n do
|
|
328
|
+
local a, b = start + body.s[n] - 1, start + body.e[n]
|
|
329
|
+
if a <= offset and offset < b and body.k[n] == 'id' then
|
|
330
|
+
local word = body:text(n)
|
|
331
|
+
if parameters[word] then return false end
|
|
332
|
+
local op = body:text(n - 1)
|
|
333
|
+
local member = op == '.' or op == '->' or op == '::'
|
|
334
|
+
return { from = 0, name = word, kind = member and (body:text(n + 1) == '(' and 'member_call' or 'member_symbol')
|
|
335
|
+
or (body:text(n + 1) == '(' and 'call' or 'symbol'),
|
|
336
|
+
recv = member and body.k[n - 2] == 'id' and body:text(n - 2) or nil, first = a, last = b }
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
return false
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
288
344
|
local function cursor(doc, offset, V, f, include_inactive)
|
|
345
|
+
if include_inactive then
|
|
346
|
+
local macro = macro_body_cursor(doc, offset, doc:parse())
|
|
347
|
+
if macro ~= nil then return macro or nil end
|
|
348
|
+
end
|
|
289
349
|
local found = find_cursor(doc, offset, true) or find_cursor(doc, offset, false)
|
|
290
350
|
if found and found.decl then return found end
|
|
291
351
|
local rec, T
|
|
@@ -692,6 +752,12 @@ local function probe_includes()
|
|
|
692
752
|
return unique
|
|
693
753
|
end
|
|
694
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
|
+
|
|
695
761
|
-- Locations of the files an import on this line names: project files by the
|
|
696
762
|
-- dependency rules, and C/C++ headers found in the include directories.
|
|
697
763
|
local function import_targets(V, f, line)
|
|
@@ -701,6 +767,12 @@ local function import_targets(V, f, line)
|
|
|
701
767
|
end
|
|
702
768
|
for _, imp in ipairs(rec.imports or {}) do
|
|
703
769
|
if imp.line == line then
|
|
770
|
+
if rec.language == 'lua' and imp.kind == 'require' then
|
|
771
|
+
for _, id in ipairs(require('codeoutline.foreign').lua_entrypoints(V, imp.path)) do
|
|
772
|
+
local loc = location(V, id)
|
|
773
|
+
if loc and not seen[loc.uri] then seen[loc.uri] = true; result[#result + 1] = loc end
|
|
774
|
+
end
|
|
775
|
+
end
|
|
704
776
|
local files, selected, header
|
|
705
777
|
if C_FAMILY[rec.language] then
|
|
706
778
|
files, selected, header = require('codeoutline.cpp_includes').resolve(V, f, imp, V.js_context)
|
|
@@ -1108,8 +1180,8 @@ local function at(req)
|
|
|
1108
1180
|
if c and c.decl then targets = { V.id_of[f][c.decl] }
|
|
1109
1181
|
elseif c then
|
|
1110
1182
|
c.line = doc:position(c.first).line + 1
|
|
1111
|
-
targets, reason, evidence, macro_state = resolve_site(V, f, c.from, c.name, c.kind, c.recv, c.evidence, c.first, c.index, c.line)
|
|
1112
|
-
c.reason, c.evidence, c.macro_state = reason, evidence, macro_state
|
|
1183
|
+
targets, reason, evidence, macro_state = resolve_site(V, f, c.from, c.name, c.kind, c.recv, c.evidence, c.first, c.index, c.line, req.method == 'lsp_definition')
|
|
1184
|
+
c.reason, c.evidence, c.macro_state = reason, c.kind == 'type' and c.evidence or evidence, macro_state
|
|
1113
1185
|
end
|
|
1114
1186
|
return V, doc, c, targets, f, offset
|
|
1115
1187
|
end
|
|
@@ -1254,6 +1326,21 @@ function handlers.lsp_definition(req)
|
|
|
1254
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
|
|
1255
1327
|
end
|
|
1256
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
|
+
|
|
1257
1344
|
-- Follow unmatched delimiters up to the cursor. Commas in nested calls,
|
|
1258
1345
|
-- literals and indexing expressions do not advance the enclosing argument.
|
|
1259
1346
|
function handlers.lsp_signature(req)
|
|
@@ -1312,19 +1399,16 @@ function handlers.lsp_signature(req)
|
|
|
1312
1399
|
local query = {}
|
|
1313
1400
|
for key, value in pairs(req) do query[key] = value end
|
|
1314
1401
|
query.position = doc:position(T.s[name_token] - 1)
|
|
1315
|
-
local V, _, c, targets = at(query)
|
|
1402
|
+
local V, _, c, targets, f = at(query)
|
|
1316
1403
|
if not V or not c or c.decl then return false end
|
|
1317
1404
|
local signatures, seen = {}, {}
|
|
1318
|
-
|
|
1319
|
-
local node = V.nodes[id]
|
|
1320
|
-
local foreign = require('codeoutline.foreign').signature(node, doc:parse().language, T:text(name_token))
|
|
1321
|
-
local label = M.detail(V, V.node_file[id], node).sig
|
|
1405
|
+
local function add_signature(node, label, uri, foreign)
|
|
1322
1406
|
if foreign and not seen[foreign.label] then
|
|
1323
1407
|
foreign.activeParameter = #foreign.parameters > 0 and math.min(call.argument, #foreign.parameters - 1) or nil
|
|
1324
1408
|
signatures[#signatures + 1] = foreign
|
|
1325
1409
|
seen[foreign.label] = true
|
|
1326
1410
|
elseif not foreign and REFERENCE[node.kind] and label and not seen[label] then
|
|
1327
|
-
local sig_doc = documents.new(
|
|
1411
|
+
local sig_doc = documents.new(uri, label, 0)
|
|
1328
1412
|
local S = sig_doc:tokens()
|
|
1329
1413
|
local opening
|
|
1330
1414
|
for i = 1, S and S.n - 1 or 0 do
|
|
@@ -1352,6 +1436,20 @@ function handlers.lsp_signature(req)
|
|
|
1352
1436
|
end
|
|
1353
1437
|
end
|
|
1354
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
|
|
1355
1453
|
if #signatures == 0 then return false end
|
|
1356
1454
|
return { signatures = signatures, activeSignature = 0, activeParameter = signatures[1].activeParameter }
|
|
1357
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
|
|
@@ -11,7 +11,7 @@ function M.validate(query, opts)
|
|
|
11
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
12
|
return budget
|
|
13
13
|
end
|
|
14
|
-
function M.resolve(G, f, from, site, ctx, details)
|
|
14
|
+
function M.resolve(G, f, from, site, ctx, details, navigation)
|
|
15
15
|
if site.value_shadowed and not site.elaborated then return {}, 'value binding' end
|
|
16
16
|
local language, written = G.files[f].language, site.written
|
|
17
17
|
local data, head = details or ctx.ordinary.data(f), written:match('^([%w_$]+)')
|
|
@@ -21,7 +21,8 @@ function M.resolve(G, f, from, site, ctx, details)
|
|
|
21
21
|
local scope = from and from > 0 and G.nodes[from] and G.nodes[from].qualified or ''
|
|
22
22
|
local ids
|
|
23
23
|
if language == 'cpp' then
|
|
24
|
-
ids = require('codeoutline.cpp_types').resolve(G, f, written, { context = ctx, scope = scope,
|
|
24
|
+
ids = require('codeoutline.cpp_types').resolve(G, f, written, { context = ctx, scope = scope,
|
|
25
|
+
at = site.at, accept = M.kinds, definitions = true, navigation_alias = navigation })
|
|
25
26
|
elseif language == 'c' then
|
|
26
27
|
local visible = graph.visible_dependencies(G, f, ctx); ids = {}
|
|
27
28
|
local own = {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return
|
|
1
|
+
return 20
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return '0.
|
|
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
|
|