@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
|
@@ -19,16 +19,24 @@ local paths = require('codeoutline.path')
|
|
|
19
19
|
local control = require('codeoutline.control')
|
|
20
20
|
local graph = require('codeoutline.graph')
|
|
21
21
|
local pool = require('codeoutline.parse_pool')
|
|
22
|
+
local fragments = require('codeoutline.cpp_fragments')
|
|
22
23
|
|
|
23
24
|
local M = {}
|
|
24
|
-
local INDEX_PARSE = { ranges = false }
|
|
25
|
+
local INDEX_PARSE = { ranges = false, omit_signatures = true }
|
|
26
|
+
local LARGE_PARSE = { ranges = false }
|
|
27
|
+
-- Keep signatures for files beyond the shared query parser's 1 MiB limit.
|
|
28
|
+
local function parse_options(source, language)
|
|
29
|
+
local options = #source <= 1048576 and INDEX_PARSE or LARGE_PARSE
|
|
30
|
+
if not language then return options end
|
|
31
|
+
return { ranges = false, omit_signatures = options.omit_signatures, language = language, cpp_fragment = language }
|
|
32
|
+
end
|
|
25
33
|
|
|
26
34
|
-- Cache version: a checksum of the parser sources, so any parser change
|
|
27
35
|
-- rebuilds stale caches instead of silently reusing old parse results.
|
|
28
36
|
M.VERSION = (function()
|
|
29
37
|
local parts = {}
|
|
30
|
-
for _, m in ipairs({ 'xscan', 'text', 'common', 'indirect', 'js_evidence', 'lua_bindings', 'foreign', 'foreign_lua', 'parse', 'lang.c', 'lang.cpp', 'lang.lua', 'lang.python',
|
|
31
|
-
'lang.java', 'lang.kotlin', 'lang.go', 'lang.js', 'lang.csharp', 'lang.rust' }) do
|
|
38
|
+
for _, m in ipairs({ 'xscan', 'text', 'common', 'type_uses', 'indirect', 'dispatch_aliases', 'static_dispatch', 'js_evidence', 'python_bindings', 'cpp_bindings', 'cpp_types', 'csharp_bindings', 'lua_bindings', 'foreign', 'foreign_lua', 'parse', 'lang.c', 'lang.cpp', 'lang.lua', 'lang.python',
|
|
39
|
+
'cpp_receivers', 'cpp_macros', 'cpp_includes', 'cpp_fragments', 'language_detect', 'go_methods', 'function_values', 'implementations', 'cpp_implementations', 'ts_implementations', 'type_bases', 'automatic_events', 'shared_events', 'lua_callback_loops', 'lang.java', 'lang.kotlin', 'lang.go', 'lang.js', 'lang.csharp', 'lang.rust' }) do
|
|
32
40
|
local file = package.searchpath and package.searchpath('codeoutline.' .. m, package.path)
|
|
33
41
|
local h = file and io.open(file, 'rb')
|
|
34
42
|
if h then parts[#parts + 1] = h:read('a'); h:close() end
|
|
@@ -132,13 +140,15 @@ function Index:load()
|
|
|
132
140
|
local t = cmsgpack.unpack(payload)
|
|
133
141
|
assert(t.version == M.VERSION and t.root == paths.key(self.root) and type(t.files) == 'table')
|
|
134
142
|
local records = {}
|
|
135
|
-
|
|
143
|
+
local function validate(rec, destination)
|
|
136
144
|
control.check()
|
|
137
145
|
assert(type(rec) == 'table' and type(rec.path) == 'string')
|
|
138
146
|
assert(not rec.path:find('[\\:%z]') and rec.path:sub(1, 1) ~= '/')
|
|
139
147
|
for part in rec.path:gmatch('[^/]+') do assert(part ~= '..' and part ~= '.') end
|
|
140
148
|
assert(type(rec.nodes) == 'table' and type(rec.refs) == 'table' and type(rec.imports) == 'table')
|
|
141
149
|
assert(type(rec.size) == 'number' and type(rec.language) == 'string')
|
|
150
|
+
assert(rec.cpp_fragment == nil or rec.cpp_fragment == 'c' or rec.cpp_fragment == 'cpp')
|
|
151
|
+
assert(rec.cpp_fragment_cpp == nil or rec.cpp_fragment_cpp == true)
|
|
142
152
|
assert(rec.encoding == nil or rec.encoding == 'utf-8' or rec.encoding == 'utf-8-bom' or rec.encoding == 'gbk')
|
|
143
153
|
for i, n in ipairs(rec.nodes) do
|
|
144
154
|
if i % 128 == 0 then control.check() end
|
|
@@ -158,8 +168,23 @@ function Index:load()
|
|
|
158
168
|
assert(recv == false or type(recv) == 'string')
|
|
159
169
|
end
|
|
160
170
|
for _, imp in ipairs(rec.imports) do assert(type(imp.path) == 'string') end
|
|
161
|
-
|
|
171
|
+
destination[rec.path] = rec
|
|
162
172
|
end
|
|
173
|
+
for _, rec in ipairs(t.files) do validate(rec, records) end
|
|
174
|
+
local patches = require('codeoutline.cache_repairs').load(self.cache_path, envelope.sha256, M.VERSION, paths.key(self.root))
|
|
175
|
+
local valid, applied = pcall(function()
|
|
176
|
+
local result = {}
|
|
177
|
+
for path, rec in pairs(patches) do
|
|
178
|
+
local base = assert(records[path])
|
|
179
|
+
assert(rec.crc == base.crc and rec.size == base.size and rec.language == base.language and rec.encoding == 'gbk')
|
|
180
|
+
validate(rec, result)
|
|
181
|
+
end
|
|
182
|
+
return result
|
|
183
|
+
end)
|
|
184
|
+
if not valid and control.is_interrupted(applied) then error(applied, 0) end
|
|
185
|
+
self.repair_records = valid and applied or {}
|
|
186
|
+
for path, rec in pairs(self.repair_records) do records[path] = rec end
|
|
187
|
+
self.cache_hash = envelope.sha256
|
|
163
188
|
return records
|
|
164
189
|
end)
|
|
165
190
|
if not ok then
|
|
@@ -182,12 +207,21 @@ function Index:save()
|
|
|
182
207
|
if not (cmsgpack and xcompress and xcompress.deflate and xutils.temp_file and xutils.replace_file) then
|
|
183
208
|
return false, 'runtime requires cmsgpack, xcompress, temp_file and replace_file'
|
|
184
209
|
end
|
|
210
|
+
if self.repair_only and self.cache_hash then
|
|
211
|
+
local ok, err = require('codeoutline.cache_repairs').save(self.cache_path, self.cache_hash,
|
|
212
|
+
M.VERSION, paths.key(self.root), self.repair_records)
|
|
213
|
+
if ok then
|
|
214
|
+
self.saved_generation, self.encoding_dirty, self.repair_only = self.generation, false, false
|
|
215
|
+
end
|
|
216
|
+
return ok, err
|
|
217
|
+
end
|
|
185
218
|
local list = {}
|
|
186
219
|
for _, rec in pairs(self.files) do list[#list + 1] = rec end
|
|
187
220
|
table.sort(list, function(a, b) return a.path < b.path end)
|
|
188
221
|
local payload = cmsgpack.pack({ version = M.VERSION, root = paths.key(self.root), files = list })
|
|
189
222
|
local packed = xcompress.deflate(payload, M.CACHE_COMPRESSION_LEVEL)
|
|
190
|
-
local
|
|
223
|
+
local hash = xutils.sha256_hex(packed)
|
|
224
|
+
local blob = cmsgpack.pack({ codec = 'deflate', size = #payload, sha256 = hash, payload = packed })
|
|
191
225
|
local d = self.cache_path:match('^(.*)/[^/]*$') or '.'
|
|
192
226
|
local made, err = xutils.mkdir_p(d)
|
|
193
227
|
if not made then return false, err end
|
|
@@ -205,6 +239,8 @@ function Index:save()
|
|
|
205
239
|
if not published then os.remove(tmp); return false, err end
|
|
206
240
|
self.saved_generation = self.generation
|
|
207
241
|
self.encoding_dirty = false
|
|
242
|
+
self.cache_hash, self.repair_records, self.repair_only = hash, {}, false
|
|
243
|
+
os.remove(self.cache_path .. '.repairs') -- a stale sidecar cannot match the new hash
|
|
208
244
|
return true
|
|
209
245
|
end
|
|
210
246
|
|
|
@@ -213,6 +249,7 @@ end
|
|
|
213
249
|
-- so an interrupted refresh leaves every file either old or new. A failed
|
|
214
250
|
-- table update drops the tables; the next symbols() call rebuilds them.
|
|
215
251
|
function Index:commit(rel, rec)
|
|
252
|
+
self.repair_only = false
|
|
216
253
|
local old = self.files[rel]
|
|
217
254
|
self.files[rel] = rec
|
|
218
255
|
self.generation = self.generation + 1
|
|
@@ -237,6 +274,24 @@ function Index:symbols()
|
|
|
237
274
|
return self.symbol_tables
|
|
238
275
|
end
|
|
239
276
|
|
|
277
|
+
-- Encoding confirmation need not replace a semantically identical parse.
|
|
278
|
+
local function same_value(a, b)
|
|
279
|
+
if type(a) ~= type(b) then return false end
|
|
280
|
+
if type(a) ~= 'table' then return a == b end
|
|
281
|
+
local count = 0
|
|
282
|
+
for key, value in pairs(a) do
|
|
283
|
+
count = count + 1
|
|
284
|
+
if count % 128 == 0 then control.check() end
|
|
285
|
+
if not same_value(value, b[key]) then return false end
|
|
286
|
+
end
|
|
287
|
+
for key in pairs(b) do
|
|
288
|
+
count = count + 1
|
|
289
|
+
if count % 128 == 0 then control.check() end
|
|
290
|
+
if a[key] == nil then return false end
|
|
291
|
+
end
|
|
292
|
+
return true
|
|
293
|
+
end
|
|
294
|
+
|
|
240
295
|
-- Only query-selected files are decoded. This cache lasts for one query and
|
|
241
296
|
-- holds the exact snapshot used for both reparsing and source rendering.
|
|
242
297
|
function Index:query_source(rel)
|
|
@@ -266,16 +321,29 @@ function Index:query_source(rel)
|
|
|
266
321
|
local changed = false
|
|
267
322
|
if not rec.encoding then
|
|
268
323
|
if encoding == 'gbk' then
|
|
269
|
-
local parsed = assert(ci.parse(rel, src,
|
|
324
|
+
local parsed = assert(ci.parse(rel, src, parse_options(src, rec.cpp_fragment)), 'cannot parse decoded source: ' .. rel)
|
|
270
325
|
parsed.size, parsed.crc, parsed.mtime, parsed.checked = rec.size, rec.crc, rec.mtime, rec.checked
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
326
|
+
local repair_only = not self:needs_save() or self.repair_only
|
|
327
|
+
if same_value(parsed, rec) then
|
|
328
|
+
-- GBK comments often leave every compact parse field intact.
|
|
329
|
+
-- Keep IDs and query evidence valid instead of restarting work.
|
|
330
|
+
rec.encoding = encoding
|
|
331
|
+
parsed = rec
|
|
332
|
+
else
|
|
333
|
+
parsed.encoding = encoding
|
|
334
|
+
self:commit(rel, parsed)
|
|
335
|
+
changed = true
|
|
336
|
+
end
|
|
337
|
+
self.repair_only = repair_only
|
|
338
|
+
self.repair_records = self.repair_records or {}
|
|
339
|
+
self.repair_records[rel] = parsed
|
|
340
|
+
self.encoding_dirty = true
|
|
274
341
|
else
|
|
275
|
-
-- Metadata only: names and positions are unchanged.
|
|
342
|
+
-- Metadata only: names and positions are unchanged. Keep this hint
|
|
343
|
+
-- resident and include it in the next normal save; confirming UTF-8
|
|
344
|
+
-- must not rewrite a large project cache on the query's hot path.
|
|
276
345
|
rec.encoding = encoding
|
|
277
346
|
end
|
|
278
|
-
self.encoding_dirty = true
|
|
279
347
|
end
|
|
280
348
|
self.query_sources[rel] = src
|
|
281
349
|
return src, changed
|
|
@@ -339,6 +407,7 @@ end
|
|
|
339
407
|
-- Also returns each file's stat fields when the runtime lists them.
|
|
340
408
|
function Index:walk_files()
|
|
341
409
|
local out, meta = {}, {}
|
|
410
|
+
self.fragment_inventory = fragments.inventory(self.root)
|
|
342
411
|
assert(xutils and xutils.list_dir, 'file enumeration unavailable: install rg or use a runtime with list_dir')
|
|
343
412
|
local rules = load_ignore(self.root)
|
|
344
413
|
local dirs = { '' }
|
|
@@ -359,9 +428,11 @@ function Index:walk_files()
|
|
|
359
428
|
if st and st.type ~= 'link' and name:sub(1, 1) ~= '.' and not ignored(rules, rel, name, e.dir) then
|
|
360
429
|
if e.dir then
|
|
361
430
|
if not M.WALK_SKIP[name] then dirs[#dirs + 1] = rel end
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
431
|
+
else
|
|
432
|
+
if ci.language(name) then
|
|
433
|
+
out[#out + 1] = rel
|
|
434
|
+
meta[rel] = st
|
|
435
|
+
else fragments.add(self.fragment_inventory, rel) end
|
|
365
436
|
end
|
|
366
437
|
end
|
|
367
438
|
end
|
|
@@ -385,6 +456,7 @@ function Index:list_files()
|
|
|
385
456
|
local p = io.popen(cmd .. (package.config:sub(1, 1) == '\\' and ' 2>nul' or ' 2>/dev/null'))
|
|
386
457
|
assert(p, 'cannot start rg file enumeration')
|
|
387
458
|
local out = {}
|
|
459
|
+
self.fragment_inventory = fragments.inventory(self.root)
|
|
388
460
|
local prefix = self.root:sub(-1) == '/' and self.root or self.root .. '/'
|
|
389
461
|
local listing = p:read('a')
|
|
390
462
|
local ok, _, code = p:close()
|
|
@@ -395,14 +467,15 @@ function Index:list_files()
|
|
|
395
467
|
if ci.language(path) then
|
|
396
468
|
out[#out + 1] = path
|
|
397
469
|
assert(#out <= M.MAX_WALK_FILES, 'file enumeration limit exceeded')
|
|
470
|
+
else
|
|
471
|
+
fragments.add(self.fragment_inventory, path)
|
|
472
|
+
assert(self.fragment_inventory.count <= M.MAX_WALK_FILES, 'file enumeration limit exceeded')
|
|
398
473
|
end
|
|
399
474
|
end
|
|
400
475
|
table.sort(out)
|
|
401
476
|
return out
|
|
402
477
|
end
|
|
403
478
|
|
|
404
|
-
local MISSING = { exists = false }
|
|
405
|
-
|
|
406
479
|
-- Stat fields for every listed file, read one directory at a time:
|
|
407
480
|
-- list_dir reports them per entry, so a tree costs a call per directory
|
|
408
481
|
-- rather than a stat per file. Older runtimes fall back to stat.
|
|
@@ -426,7 +499,9 @@ function Index:stat_listing(list)
|
|
|
426
499
|
end
|
|
427
500
|
for _, name in ipairs(names) do
|
|
428
501
|
local rel = dir == '' and name or (dir .. '/' .. name)
|
|
429
|
-
|
|
502
|
+
-- rg and a native directory listing can disagree on filename
|
|
503
|
+
-- encoding. Check a listed path before treating it as deleted.
|
|
504
|
+
meta[rel] = by_name and by_name[name] or xutils.stat(self:abs(rel))
|
|
430
505
|
end
|
|
431
506
|
end
|
|
432
507
|
return meta
|
|
@@ -439,7 +514,7 @@ end
|
|
|
439
514
|
-- Read one file and parse it unless its size and checksum match the known
|
|
440
515
|
-- record. Touches no index state, so a parse thread can run it too. `checked`
|
|
441
516
|
-- is taken before the read: content read after that second is current.
|
|
442
|
-
function M.load_file(abs, rel, max_bytes, old_size, old_crc)
|
|
517
|
+
function M.load_file(abs, rel, max_bytes, old_size, old_crc, language)
|
|
443
518
|
local checked = os.time()
|
|
444
519
|
local src = slurp(abs)
|
|
445
520
|
if not src or #src > max_bytes then return { status = 'skipped' } end
|
|
@@ -447,7 +522,7 @@ function M.load_file(abs, rel, max_bytes, old_size, old_crc)
|
|
|
447
522
|
if old_size == #src and old_crc == crc then
|
|
448
523
|
return { status = 'unchanged', checked = checked }
|
|
449
524
|
end
|
|
450
|
-
local ok, r = pcall(ci.parse, rel, src,
|
|
525
|
+
local ok, r = pcall(ci.parse, rel, src, parse_options(src, language))
|
|
451
526
|
if not ok and control.is_interrupted(r) then error(r, 0) end
|
|
452
527
|
-- A parser exception must not permanently hide a GBK file.
|
|
453
528
|
-- Successful speculative parsing does not scan encoding here.
|
|
@@ -455,13 +530,13 @@ function M.load_file(abs, rel, max_bytes, old_size, old_crc)
|
|
|
455
530
|
if xutils.to_utf8 then
|
|
456
531
|
local decoded, encoding = xutils.to_utf8(src)
|
|
457
532
|
if decoded then
|
|
458
|
-
ok, r = pcall(ci.parse, rel, decoded,
|
|
533
|
+
ok, r = pcall(ci.parse, rel, decoded, parse_options(src, language))
|
|
459
534
|
if not ok and control.is_interrupted(r) then error(r, 0) end
|
|
460
535
|
if ok and r then r.encoding = encoding end
|
|
461
536
|
end
|
|
462
537
|
end
|
|
463
538
|
end
|
|
464
|
-
if not (ok and r) then return { status = 'failed' } end
|
|
539
|
+
if not (ok and r) then return { status = language and ok and 'skipped' or 'failed' } end
|
|
465
540
|
r.size, r.crc, r.checked = #src, crc, checked
|
|
466
541
|
return { status = 'parsed', rec = r }
|
|
467
542
|
end
|
|
@@ -508,13 +583,48 @@ function Index:apply_load(rel, st, res, stats)
|
|
|
508
583
|
return true
|
|
509
584
|
end
|
|
510
585
|
|
|
511
|
-
function Index:read_file(rel, st, stats)
|
|
586
|
+
function Index:read_file(rel, st, stats, language)
|
|
512
587
|
local rec = self.files[rel]
|
|
513
|
-
|
|
588
|
+
language = language or rec and rec.cpp_fragment
|
|
589
|
+
local same = rec and rec.cpp_fragment == language
|
|
590
|
+
local res = M.load_file(self:abs(rel), rel, self.max_bytes, same and rec.size, same and rec.crc, language)
|
|
514
591
|
control.check()
|
|
515
592
|
return self:apply_load(rel, st, res, stats)
|
|
516
593
|
end
|
|
517
594
|
|
|
595
|
+
function Index:refresh_fragments(stats, seen, changed)
|
|
596
|
+
fragments.refresh(self, stats, seen, function(batch)
|
|
597
|
+
local frontier, reads, meta = {}, {}, {}
|
|
598
|
+
for _, candidate in ipairs(batch) do
|
|
599
|
+
local rel, language, st = candidate.rel, candidate.language, candidate.stat
|
|
600
|
+
local rec = self.files[rel]
|
|
601
|
+
local settled
|
|
602
|
+
if not (changed and changed[rel]) and rec and rec.cpp_fragment == language then
|
|
603
|
+
settled = self:check_stat(rel, st, stats)
|
|
604
|
+
end
|
|
605
|
+
if settled then seen[rel] = true; frontier[#frontier + 1] = rel
|
|
606
|
+
elseif settled == nil then
|
|
607
|
+
local same = rec and rec.cpp_fragment == language
|
|
608
|
+
reads[#reads + 1] = { rel = rel, abs = self:abs(rel), language = language,
|
|
609
|
+
size = same and rec.size, crc = same and rec.crc, weight = st.size + M.FILE_WEIGHT }
|
|
610
|
+
meta[rel] = st
|
|
611
|
+
end
|
|
612
|
+
end
|
|
613
|
+
local function apply(rel, response)
|
|
614
|
+
control.check()
|
|
615
|
+
if self:apply_load(rel, meta[rel], response, stats) then seen[rel] = true; frontier[#frontier + 1] = rel end
|
|
616
|
+
end
|
|
617
|
+
if #reads >= M.PARALLEL_MIN_FILES and pool.ready() then pool.run(reads, self.max_bytes, apply)
|
|
618
|
+
else
|
|
619
|
+
for _, job in ipairs(reads) do
|
|
620
|
+
control.check()
|
|
621
|
+
apply(job.rel, M.load_file(job.abs, job.rel, self.max_bytes, job.size, job.crc, job.language))
|
|
622
|
+
end
|
|
623
|
+
end
|
|
624
|
+
return frontier
|
|
625
|
+
end, changed)
|
|
626
|
+
end
|
|
627
|
+
|
|
518
628
|
-- Bring one listed file in line with the tree, given its stat fields (nil
|
|
519
629
|
-- when the runtime has no stat). Returns false when it no longer belongs in
|
|
520
630
|
-- the index: gone, too large, unreadable or unparsable.
|
|
@@ -558,7 +668,7 @@ local IGNORE_FILES = { ['.gitignore'] = true, ['.ignore'] = true, ['.rgignore']
|
|
|
558
668
|
local function relevant(paths)
|
|
559
669
|
local changed = {}
|
|
560
670
|
for _, rel in ipairs(paths) do
|
|
561
|
-
if IGNORE_FILES[rel:match('[^/]*$')] then return nil end
|
|
671
|
+
if IGNORE_FILES[rel:match('[^/]*$')] or rel == '.codeoutline.json' then return nil end
|
|
562
672
|
if rel:sub(1, 1) ~= '.' and not rel:find('/.', 1, true) then changed[rel] = true end
|
|
563
673
|
end
|
|
564
674
|
return changed
|
|
@@ -569,6 +679,13 @@ end
|
|
|
569
679
|
-- files that differ from the index.
|
|
570
680
|
function Index:refresh_changed(changed, structural)
|
|
571
681
|
local stats = new_stats('changes')
|
|
682
|
+
local refresh_fragments = structural or false
|
|
683
|
+
for rel in pairs(changed) do
|
|
684
|
+
local rec, language = self.files[rel], ci.language(rel)
|
|
685
|
+
if (rec and (rec.cpp_fragment or rec.language == 'c' or rec.language == 'cpp'))
|
|
686
|
+
or language == 'c' or language == 'cpp' or not language then refresh_fragments = true end
|
|
687
|
+
end
|
|
688
|
+
if refresh_fragments and not self.fragment_inventory then structural = true end
|
|
572
689
|
if not structural then
|
|
573
690
|
-- A supported file the index lacks may have shrunk under the size
|
|
574
691
|
-- limit or been fixed after a failed parse: let the listing decide.
|
|
@@ -578,6 +695,7 @@ function Index:refresh_changed(changed, structural)
|
|
|
578
695
|
end
|
|
579
696
|
local listed
|
|
580
697
|
if structural then
|
|
698
|
+
refresh_fragments = true
|
|
581
699
|
stats.mode = 'relisted'
|
|
582
700
|
listed = {}
|
|
583
701
|
for _, rel in ipairs(self:list_files()) do
|
|
@@ -585,14 +703,16 @@ function Index:refresh_changed(changed, structural)
|
|
|
585
703
|
if not self.files[rel] then changed[rel] = true end
|
|
586
704
|
end
|
|
587
705
|
for rel in pairs(self.files) do
|
|
588
|
-
if not listed[rel] then changed[rel] = true end
|
|
706
|
+
if not listed[rel] and not self.files[rel].cpp_fragment then changed[rel] = true end
|
|
589
707
|
end
|
|
590
708
|
end
|
|
591
709
|
local has_stat = xutils and xutils.stat
|
|
592
710
|
for rel in pairs(changed) do
|
|
593
711
|
control.check()
|
|
594
712
|
local known = self.files[rel] ~= nil
|
|
595
|
-
if
|
|
713
|
+
if known and self.files[rel].cpp_fragment then
|
|
714
|
+
-- Recheck through the reachable include closure below.
|
|
715
|
+
elseif listed and listed[rel] or (not listed and known) then
|
|
596
716
|
if not self:sync_file(rel, has_stat and xutils.stat(self:abs(rel)) or nil, stats) and known then
|
|
597
717
|
self:commit(rel, nil)
|
|
598
718
|
stats.removed = stats.removed + 1
|
|
@@ -602,6 +722,14 @@ function Index:refresh_changed(changed, structural)
|
|
|
602
722
|
stats.removed = stats.removed + 1
|
|
603
723
|
end
|
|
604
724
|
end
|
|
725
|
+
if refresh_fragments then
|
|
726
|
+
local seen = {}
|
|
727
|
+
for rel, rec in pairs(self.files) do if not rec.cpp_fragment then seen[rel] = true end end
|
|
728
|
+
self:refresh_fragments(stats, seen, changed)
|
|
729
|
+
local gone = {}
|
|
730
|
+
for rel, rec in pairs(self.files) do if rec.cpp_fragment and not seen[rel] then gone[#gone + 1] = rel end end
|
|
731
|
+
for _, rel in ipairs(gone) do self:commit(rel, nil); stats.removed = stats.removed + 1 end
|
|
732
|
+
end
|
|
605
733
|
local total = 0
|
|
606
734
|
for _ in pairs(self.files) do total = total + 1 end
|
|
607
735
|
stats.unchanged = total - stats.parsed
|
|
@@ -614,12 +742,20 @@ end
|
|
|
614
742
|
-- watcher is reopened before one.
|
|
615
743
|
function Index:refresh(opts)
|
|
616
744
|
opts = opts or {}
|
|
745
|
+
local policy = fragments.policy_key(self.root)
|
|
746
|
+
if self.fragment_policy and self.fragment_policy ~= policy then
|
|
747
|
+
self.watch_ready = false
|
|
748
|
+
local stats = self:refresh_all()
|
|
749
|
+
if self.watcher then self.watch_ready = true end
|
|
750
|
+
return stats
|
|
751
|
+
end
|
|
617
752
|
if opts.paths then
|
|
618
753
|
local changed = {}
|
|
619
754
|
for _, path in ipairs(opts.paths) do
|
|
620
755
|
if paths.contains(self.root, path) then
|
|
621
756
|
local prefix = self.root:sub(-1) == '/' and self.root or self.root .. '/'
|
|
622
757
|
local rel = path:sub(#prefix + 1)
|
|
758
|
+
if rel == '.codeoutline.json' then return self:refresh_all() end
|
|
623
759
|
-- Unindexed/ignored files are admitted by watcher enumeration.
|
|
624
760
|
if self.files[rel] then changed[rel] = true end
|
|
625
761
|
end
|
|
@@ -662,6 +798,7 @@ end
|
|
|
662
798
|
function Index:refresh_all()
|
|
663
799
|
local stats = new_stats('full')
|
|
664
800
|
self.next_full = nil
|
|
801
|
+
self.fragment_policy = fragments.policy_key(self.root)
|
|
665
802
|
local seen = {}
|
|
666
803
|
local list, meta = self:list_files()
|
|
667
804
|
if not meta and xutils and xutils.stat then meta = self:stat_listing(list) end
|
|
@@ -689,6 +826,7 @@ function Index:refresh_all()
|
|
|
689
826
|
if self:read_file(rel, meta and meta[rel], stats) then seen[rel] = true end
|
|
690
827
|
end
|
|
691
828
|
end
|
|
829
|
+
self:refresh_fragments(stats, seen)
|
|
692
830
|
local gone = {}
|
|
693
831
|
for rel in pairs(self.files) do
|
|
694
832
|
if not seen[rel] then gone[#gone + 1] = rel end
|
|
@@ -55,11 +55,16 @@ 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
|
-
service.refresh(root, { full_interval = 45, paths = req.paths })
|
|
58
|
+
local idx = service.refresh(root, { full_interval = 45, paths = req.paths })
|
|
59
|
+
-- Ready navigation must not leave a whole-project symbol-table build
|
|
60
|
+
-- on the first definition request. Symbol-only clients retain lazy data.
|
|
61
|
+
if req.prepare_navigation then idx:symbols() end
|
|
59
62
|
return true
|
|
60
|
-
elseif req.method == 'explore' or req.method == 'callers' then
|
|
61
|
-
local text, info = service[req.method](root, req.query, { budget = req.budget, depth = req.depth,
|
|
62
|
-
|
|
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
|
+
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 })
|
|
66
|
+
return { text = text, truncated = info.truncated or false, coverage = info.coverage,
|
|
67
|
+
resolution = info.resolution, generation = info.generation, refresh = info.refresh }
|
|
63
68
|
elseif req.method == 'status' then return service.status(root)
|
|
64
69
|
elseif req.method == 'rebuild' then return service.rebuild(root)
|
|
65
70
|
else error('unknown operation') end
|
|
@@ -71,11 +76,13 @@ end
|
|
|
71
76
|
local queue, active = {}, nil
|
|
72
77
|
|
|
73
78
|
local function run(id, req, reply)
|
|
79
|
+
if req.queue_until then assert(xthread.post(1, 'worker_started', id)) end
|
|
74
80
|
-- Draft text applies even to a cancelled request: the session counts it as sent.
|
|
75
81
|
if req.session and req.open then
|
|
76
82
|
local synced, err = pcall(navigation.sync, req)
|
|
77
83
|
if not synced then io.stderr:write('[codeoutline lsp] ', tostring(err), '\n') end
|
|
78
84
|
end
|
|
85
|
+
if req.method == 'lsp_warm' then req.deadline = math.min(req.deadline, xtimer.now_ms() + 5000) end
|
|
79
86
|
control.callback = function()
|
|
80
87
|
if shared:get('shutdown') or shared:get('cancel:' .. id) then error(control.cancelled(), 0) end
|
|
81
88
|
if xtimer.now_ms() > req.deadline then error(control.deadline(), 0) end
|