@codua/codeoutline-win32-x64 0.2.1 → 0.2.4
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 +1 -0
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/package.json +1 -1
- package/scripts/codeoutline/callers.lua +116 -0
- package/scripts/codeoutline/command.lua +7 -3
- package/scripts/codeoutline/common.lua +12 -1
- package/scripts/codeoutline/completion.lua +63 -15
- package/scripts/codeoutline/explore.lua +36 -9
- package/scripts/codeoutline/foreign.lua +60 -0
- package/scripts/codeoutline/foreign_lua.lua +146 -0
- package/scripts/codeoutline/graph.lua +49 -19
- package/scripts/codeoutline/index.lua +6 -2
- package/scripts/codeoutline/index_worker.lua +15 -7
- package/scripts/codeoutline/indirect.lua +36 -12
- package/scripts/codeoutline/lang/lua.lua +17 -2
- package/scripts/codeoutline/lsp.lua +58 -34
- package/scripts/codeoutline/lua_bindings.lua +167 -29
- package/scripts/codeoutline/main.lua +24 -3
- package/scripts/codeoutline/mcp.lua +13 -4
- package/scripts/codeoutline/navigation.lua +18 -3
- package/scripts/codeoutline/parse.lua +2 -0
- package/scripts/codeoutline/query_report.lua +36 -0
- package/scripts/codeoutline/service.lua +11 -3
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
-- Lua C API adapter for the language-neutral foreign interface model.
|
|
2
|
+
local M = {}
|
|
3
|
+
local control = require('codeoutline.control')
|
|
4
|
+
local function literal(T, i)
|
|
5
|
+
local s = T:text(i)
|
|
6
|
+
if T.k[i] ~= 'str' or s:find('\\', 1, true) then return nil end
|
|
7
|
+
return s:sub(2, -2)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
local READ = {
|
|
11
|
+
luaL_checkinteger = 'int', luaL_optinteger = 'int', lua_tointeger = 'int', lua_tointegerx = 'int',
|
|
12
|
+
luaL_checknumber = 'number', luaL_optnumber = 'number', lua_tonumber = 'number', lua_tonumberx = 'number',
|
|
13
|
+
luaL_checkstring = 'string', luaL_checklstring = 'string', luaL_optstring = 'string', luaL_optlstring = 'string',
|
|
14
|
+
lua_tostring = 'string', lua_tolstring = 'string', lua_toboolean = 'boolean',
|
|
15
|
+
luaL_checkudata = 'userdata', luaL_testudata = 'userdata', lua_touserdata = 'userdata',
|
|
16
|
+
luaL_checkany = 'unknown', luaL_checktype = 'unknown',
|
|
17
|
+
lua_isinteger = 'int', lua_isnumber = 'number', lua_isstring = 'string', lua_isboolean = 'boolean',
|
|
18
|
+
lua_istable = 'table', lua_isfunction = 'function', lua_isthread = 'thread', lua_isuserdata = 'userdata',
|
|
19
|
+
}
|
|
20
|
+
local TYPES = { LUA_TNUMBER = 'number', LUA_TSTRING = 'string', LUA_TBOOLEAN = 'boolean',
|
|
21
|
+
LUA_TTABLE = 'table', LUA_TFUNCTION = 'function', LUA_TTHREAD = 'thread',
|
|
22
|
+
LUA_TUSERDATA = 'userdata', LUA_TLIGHTUSERDATA = 'lightuserdata', LUA_TNIL = 'nil' }
|
|
23
|
+
|
|
24
|
+
local function parameters(T, node)
|
|
25
|
+
local state
|
|
26
|
+
for i = node.ti, node.tj - 2 do
|
|
27
|
+
if T:text(i) == 'lua_State' and T:text(i + 1) == '*' and T.k[i + 2] == 'id' then
|
|
28
|
+
state = T:text(i + 2); break
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
local slots, highest, unknown = {}, 0, false
|
|
32
|
+
for i = node.ti, node.tj do
|
|
33
|
+
if i % 4096 == 0 then control.check() end
|
|
34
|
+
local api = T:text(i)
|
|
35
|
+
if READ[api] and T:text(i + 1) == '(' and T:text(i + 2) == state and T:text(i + 3) == ',' then
|
|
36
|
+
local position = tonumber(T:text(i + 4))
|
|
37
|
+
local ending = T:text(i + 5)
|
|
38
|
+
if position and position > 0 and position <= 64 and position == math.floor(position)
|
|
39
|
+
and (ending == ',' or ending == ')') then
|
|
40
|
+
highest = math.max(highest, position)
|
|
41
|
+
local p = slots[position] or { types = {} }
|
|
42
|
+
slots[position] = p
|
|
43
|
+
local kind = READ[api]
|
|
44
|
+
if api == 'luaL_checktype' then kind = TYPES[T:text(i + 6)] or 'unknown' end
|
|
45
|
+
if api == 'luaL_checkudata' or api == 'luaL_testudata' then kind = literal(T, i + 6) or kind end
|
|
46
|
+
p.types[kind] = true
|
|
47
|
+
local optional = api:match('^luaL_opt') ~= nil
|
|
48
|
+
if p.optional == nil then p.optional = optional else p.optional = p.optional and optional end
|
|
49
|
+
if optional then
|
|
50
|
+
local close = T.m[i + 1]
|
|
51
|
+
local last = close and close - 1
|
|
52
|
+
if last and api == 'luaL_optlstring' then
|
|
53
|
+
last = i + 6
|
|
54
|
+
while last < close and T:text(last) ~= ',' do last = last + 1 end
|
|
55
|
+
last = last - 1
|
|
56
|
+
end
|
|
57
|
+
if last and last >= i + 6 then p.default = T.src:sub(T.s[i + 6], T.e[last]) end
|
|
58
|
+
end
|
|
59
|
+
-- Only a direct assignment supplies a public argument name.
|
|
60
|
+
-- Casts between '=' and the API call are harmless; expressions aren't.
|
|
61
|
+
local j = i - 1
|
|
62
|
+
while j >= node.ti and T:text(j) ~= ';' and T:text(j) ~= '{' and T:text(j) ~= '}' do
|
|
63
|
+
if T:text(j) == '=' then
|
|
64
|
+
local direct = j == i - 1 or (T:text(j + 1) == '(' and T.m[j + 1] == i - 1)
|
|
65
|
+
if direct and not api:match('^lua_is') and api ~= 'luaL_checktype'
|
|
66
|
+
and T.k[j - 1] == 'id' and T:text(j - 2) ~= '.' and T:text(j - 2) ~= '->' then
|
|
67
|
+
local name = T:text(j - 1)
|
|
68
|
+
if not p.name then p.name = name elseif p.name ~= name then p.ambiguous = true end
|
|
69
|
+
end
|
|
70
|
+
break
|
|
71
|
+
end
|
|
72
|
+
j = j - 1
|
|
73
|
+
end
|
|
74
|
+
elseif T:text(i + 4) ~= '-' and T:text(i + 4) ~= 'lua_upvalueindex' then
|
|
75
|
+
unknown = true
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
local result, used = { parameters = {}, unknown_tail = unknown }, {}
|
|
80
|
+
for i = 1, highest do
|
|
81
|
+
local p = slots[i] or { types = {} }
|
|
82
|
+
p.types.unknown = nil
|
|
83
|
+
local types = {}
|
|
84
|
+
for kind in pairs(p.types) do types[#types + 1] = kind end
|
|
85
|
+
table.sort(types)
|
|
86
|
+
local name = not p.ambiguous and p.name or nil
|
|
87
|
+
if name and used[name] then name = nil end
|
|
88
|
+
if name then used[name] = true end
|
|
89
|
+
result.parameters[i] = { name = name, type = #types > 0 and table.concat(types, '|') or 'unknown',
|
|
90
|
+
optional = p.optional or nil, default = p.optional and p.default or nil }
|
|
91
|
+
end
|
|
92
|
+
return result
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
-- Only explicit registration tables wired inside luaopen_* are exports.
|
|
96
|
+
-- Keep the original C nodes, including their source ranges and signatures.
|
|
97
|
+
function M.collect(r, T)
|
|
98
|
+
local tables, functions = {}, {}
|
|
99
|
+
for n, node in ipairs(r.nodes) do
|
|
100
|
+
if node.kind == 'function' then functions[node.name] = n end
|
|
101
|
+
end
|
|
102
|
+
for i = 1, T.n do
|
|
103
|
+
if i % 4096 == 0 then control.check() end
|
|
104
|
+
if T:text(i) == 'luaL_Reg' and T.k[i + 1] == 'id' then
|
|
105
|
+
local j = i + 2
|
|
106
|
+
if T:text(j) == '[' and T.m[j] then j = T.m[j] + 1 end
|
|
107
|
+
if T:text(j) == '=' and T:text(j + 1) == '{' and T.m[j + 1] then
|
|
108
|
+
local entries = {}
|
|
109
|
+
for k = j + 2, T.m[j + 1] - 1 do
|
|
110
|
+
if T:text(k) == '{' and T.k[k + 1] == 'str' and T:text(k + 2) == ',' then
|
|
111
|
+
local name, target = literal(T, k + 1), functions[T:text(k + 3)]
|
|
112
|
+
if name and target and T:text(k + 4) == '}' then entries[name] = target end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
tables[T:text(i + 1)] = entries
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
for _, node in ipairs(r.nodes) do
|
|
120
|
+
local module = node.kind == 'function' and node.name:match('^luaopen_(.+)$')
|
|
121
|
+
if module then
|
|
122
|
+
local exports = {}
|
|
123
|
+
for i = node.ti, node.tj do
|
|
124
|
+
local call = T:text(i)
|
|
125
|
+
-- A fresh table replaces registrations for earlier metatables.
|
|
126
|
+
if T:text(i + 1) == '(' and (call == 'luaL_newlib' or call == 'lua_newtable'
|
|
127
|
+
or call == 'lua_createtable' or call == 'luaL_newmetatable') then exports = {} end
|
|
128
|
+
if T:text(i + 1) == '(' and T:text(i + 3) == ',' then
|
|
129
|
+
local arg = (call == 'luaL_newlib' or call == 'luaL_setfuncs') and i + 4
|
|
130
|
+
if call == 'luaL_register' and T:text(i + 5) == ',' then arg = i + 6 end
|
|
131
|
+
for name, n in pairs(tables[arg and T:text(arg)] or {}) do exports[name] = n end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
if next(exports) then
|
|
135
|
+
require('codeoutline.foreign').register(r, 'lua', module, exports)
|
|
136
|
+
for _, n in pairs(exports) do
|
|
137
|
+
local target = r.nodes[n]
|
|
138
|
+
target.foreign_signatures = target.foreign_signatures or {}
|
|
139
|
+
target.foreign_signatures.lua = target.foreign_signatures.lua or parameters(T, target)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
return M
|
|
@@ -287,12 +287,16 @@ local function resolve_ref(G, f, src_id, name, kind, recv, deps, paired, accept,
|
|
|
287
287
|
if kind == 'annotation' then return nil end
|
|
288
288
|
accept = accept or (kind == 'new' and NEWABLE) or (kind == 'ref' and VALUE) or CALLABLE
|
|
289
289
|
if evidence == '' then evidence = nil end
|
|
290
|
+
local strategy = 'js/ts binding'
|
|
290
291
|
local exact = js_resolution.resolve(G, f, name, kind, recv, evidence, js_context)
|
|
291
|
-
if exact == nil then
|
|
292
|
+
if exact == nil then
|
|
293
|
+
strategy = 'lua binding'
|
|
294
|
+
exact = lua_bindings.resolve(G, f, name, evidence, js_context and js_context.lua, recv)
|
|
295
|
+
end
|
|
292
296
|
if exact ~= nil then
|
|
293
297
|
local result = {}
|
|
294
298
|
for _, id in ipairs(exact) do if accept[G.nodes[id].kind] then result[#result + 1] = id end end
|
|
295
|
-
return result
|
|
299
|
+
return result, #result == 0 and 'binding target unresolved' or strategy
|
|
296
300
|
end
|
|
297
301
|
local cands = G.by_name[name]
|
|
298
302
|
if G.files[f].language == 'kotlin' and not recv then
|
|
@@ -308,7 +312,7 @@ local function resolve_ref(G, f, src_id, name, kind, recv, deps, paired, accept,
|
|
|
308
312
|
end
|
|
309
313
|
end
|
|
310
314
|
end
|
|
311
|
-
if not cands then return nil end
|
|
315
|
+
if not cands then return nil, 'no indexed target' end
|
|
312
316
|
-- Score first: score() rejects other languages and statics of other
|
|
313
317
|
-- files, so "is there a real definition?" is only asked among the
|
|
314
318
|
-- candidates this call could actually reach. (Asking it over all
|
|
@@ -320,7 +324,7 @@ local function resolve_ref(G, f, src_id, name, kind, recv, deps, paired, accept,
|
|
|
320
324
|
-- score() rejects an unknown-receiver member call to an unrelated file;
|
|
321
325
|
-- checking placement first skips most candidates of common method names.
|
|
322
326
|
local local_only = kind == 'member_call' and not self_call
|
|
323
|
-
local n, has_def = 0, false
|
|
327
|
+
local n, has_def, has_name = 0, false, false
|
|
324
328
|
for i = 1, math.min(#cands, M.MAX_CANDIDATES) do
|
|
325
329
|
local cid = cands[i]
|
|
326
330
|
local node = G.nodes[cid]
|
|
@@ -331,26 +335,33 @@ local function resolve_ref(G, f, src_id, name, kind, recv, deps, paired, accept,
|
|
|
331
335
|
n = n + 1
|
|
332
336
|
scored_ids[n], scored_vals[n] = cid, s
|
|
333
337
|
if not is_decl(node) then has_def = true end
|
|
338
|
+
if node.name == name then has_name = true end
|
|
334
339
|
end
|
|
335
340
|
end
|
|
336
341
|
end
|
|
337
|
-
-- Prefer
|
|
338
|
-
--
|
|
339
|
-
local best, ties = nil, {}
|
|
342
|
+
-- Prefer real names over export aliases (which may be platform stubs),
|
|
343
|
+
-- then definitions over prototypes / in-class declarations.
|
|
344
|
+
local best, ties, tie_count = nil, {}, 0
|
|
340
345
|
for i = 1, n do
|
|
341
346
|
local cid, s = scored_ids[i], scored_vals[i]
|
|
342
|
-
if not (has_def and is_decl(G.nodes[cid])) then
|
|
347
|
+
if not (has_def and is_decl(G.nodes[cid])) and (not has_name or G.nodes[cid].name == name) then
|
|
343
348
|
if not best or s > best then
|
|
344
|
-
best, ties = s, { cid }
|
|
345
|
-
elseif s == best
|
|
346
|
-
|
|
349
|
+
best, ties, tie_count = s, { cid }, 1
|
|
350
|
+
elseif s == best then
|
|
351
|
+
tie_count = tie_count + 1
|
|
352
|
+
if #ties < M.MAX_TIES then ties[#ties + 1] = cid end
|
|
347
353
|
end
|
|
348
354
|
end
|
|
349
355
|
end
|
|
350
356
|
-- A lone candidate far away (score 0) is still a match for a unique
|
|
351
357
|
-- name; many far candidates with nothing to separate them is a guess.
|
|
352
|
-
if best and best <= 0 and #ties > 1 then
|
|
353
|
-
|
|
358
|
+
if best and best <= 0 and #ties > 1 then
|
|
359
|
+
return nil, 'ambiguous name candidates' .. (#cands > M.MAX_CANDIDATES and '; candidate scan limit reached' or '')
|
|
360
|
+
end
|
|
361
|
+
local reason = #ties == 0 and 'no eligible target' or #ties > 1 and 'multiple name/locality candidates' or 'name/locality match'
|
|
362
|
+
if #cands > M.MAX_CANDIDATES then reason = reason .. '; candidate scan limit reached' end
|
|
363
|
+
if tie_count > M.MAX_TIES then reason = reason .. '; tied candidate limit reached' end
|
|
364
|
+
return ties, reason
|
|
354
365
|
end
|
|
355
366
|
|
|
356
367
|
-- Files compare by path; nodes by file path, then node order (ids ascend
|
|
@@ -395,6 +406,7 @@ end
|
|
|
395
406
|
function M.new()
|
|
396
407
|
return { files = {}, file_index = {}, file_order = {}, file_dir = {}, dir_ids = {}, nodes = {}, node_file = {},
|
|
397
408
|
id_of = {}, by_name = {}, by_lname = {}, by_qualified = {}, by_owner = {}, by_base = {}, by_stem = {}, pkg_files = {},
|
|
409
|
+
lua_global_export_tables = { 'g_exports' },
|
|
398
410
|
children = {}, dir_files = {}, dir_by_base = {}, ns_files = {},
|
|
399
411
|
next_file = 0, next_node = 0, next_dir = 0, file_count = 0, node_count = 0 }
|
|
400
412
|
end
|
|
@@ -446,6 +458,7 @@ function M.add_file(G, rel, rec)
|
|
|
446
458
|
G.nodes[id], G.node_file[id] = node, f
|
|
447
459
|
ids[n] = id
|
|
448
460
|
insert(G, G.by_name, node.name, id, node_before)
|
|
461
|
+
for _, alias in ipairs(lua_bindings.aliases(node, G.lua_global_export_tables)) do insert(G, G.by_name, alias, id, node_before) end
|
|
449
462
|
insert(G, G.by_lname, node.name:lower(), id, node_before)
|
|
450
463
|
insert(G, G.by_qualified, node.qualified, id, node_before)
|
|
451
464
|
local owner = M.owner(node.qualified)
|
|
@@ -463,6 +476,7 @@ function M.remove_file(G, rel)
|
|
|
463
476
|
for _, id in ipairs(ids) do
|
|
464
477
|
local node = G.nodes[id]
|
|
465
478
|
remove(G, G.by_name, node.name, id, node_before)
|
|
479
|
+
for _, alias in ipairs(lua_bindings.aliases(node, G.lua_global_export_tables)) do remove(G, G.by_name, alias, id, node_before) end
|
|
466
480
|
remove(G, G.by_lname, node.name:lower(), id, node_before)
|
|
467
481
|
remove(G, G.by_qualified, node.qualified, id, node_before)
|
|
468
482
|
local owner = M.owner(node.qualified)
|
|
@@ -485,9 +499,10 @@ end
|
|
|
485
499
|
|
|
486
500
|
-- Symbol tables for every record of idx. Checkpoints per file: a cancelled
|
|
487
501
|
-- build is simply discarded.
|
|
488
|
-
function M.build(idx)
|
|
502
|
+
function M.build(idx, lua_context)
|
|
489
503
|
local G = M.new()
|
|
490
504
|
G.root = idx.root
|
|
505
|
+
G.lua_global_export_tables = (lua_context or lua_bindings.context(G)).global_export_tables
|
|
491
506
|
local paths = {}
|
|
492
507
|
for rel in pairs(idx.files) do paths[#paths + 1] = rel end
|
|
493
508
|
table.sort(paths)
|
|
@@ -511,7 +526,9 @@ function M.query(symbols, opts)
|
|
|
511
526
|
local dependencies, references = {}, {}
|
|
512
527
|
local js_context = js_resolution.context(symbols)
|
|
513
528
|
js_context.lua = lua_bindings.context(symbols)
|
|
514
|
-
local
|
|
529
|
+
local report = opts.explain and require('codeoutline.query_report').new() or nil
|
|
530
|
+
Q.report = report
|
|
531
|
+
local indirect = require('codeoutline.indirect').query(symbols, opts.dispatch_rules, report)
|
|
515
532
|
local function deps(f)
|
|
516
533
|
local entry = dependencies[f]
|
|
517
534
|
if not entry then
|
|
@@ -520,13 +537,25 @@ function M.query(symbols, opts)
|
|
|
520
537
|
end
|
|
521
538
|
return entry[1], entry[2]
|
|
522
539
|
end
|
|
523
|
-
local function targets(f, i)
|
|
540
|
+
local function targets(f, i, explain)
|
|
524
541
|
local rec, ids = symbols.files[f], symbols.id_of[f]
|
|
525
542
|
local refs = rec.refs
|
|
526
543
|
local direct, paired = deps(f)
|
|
527
544
|
Q.stats.resolved_refs = Q.stats.resolved_refs + 1
|
|
528
|
-
|
|
545
|
+
local found, reason = resolve_ref(symbols, f, ids[refs.from[i]], refs.name[i], refs.kind[i],
|
|
529
546
|
refs.recv[i] or nil, direct, paired, nil, refs.lua_binding and refs.lua_binding[i] or refs.js_receiver and refs.js_receiver[i], js_context)
|
|
547
|
+
if report and explain and (refs.kind[i] == 'call' or refs.kind[i] == 'member_call') then
|
|
548
|
+
if (not found or #found == 0) and explain == true then
|
|
549
|
+
report:add({ source = ids[refs.from[i]], line = refs.line[i], call = refs.name[i], reason = reason or 'unresolved reference' })
|
|
550
|
+
else
|
|
551
|
+
for _, dst in ipairs(found or {}) do
|
|
552
|
+
if explain == true or explain[dst] then
|
|
553
|
+
report:add({ source = ids[refs.from[i]], target = dst, line = refs.line[i], kind = reason })
|
|
554
|
+
end
|
|
555
|
+
end
|
|
556
|
+
end
|
|
557
|
+
end
|
|
558
|
+
return found
|
|
530
559
|
end
|
|
531
560
|
setmetatable(Q.out, { __index = function(cache, id)
|
|
532
561
|
control.check()
|
|
@@ -551,7 +580,7 @@ function M.query(symbols, opts)
|
|
|
551
580
|
end
|
|
552
581
|
for _, i in ipairs(grouped[id] or {}) do
|
|
553
582
|
control.check()
|
|
554
|
-
for _, dst in ipairs(targets(f, i) or {}) do
|
|
583
|
+
for _, dst in ipairs(targets(f, i, true) or {}) do
|
|
555
584
|
edges[#edges + 1] = dst
|
|
556
585
|
edges[#edges + 1] = rec.refs.line[i]
|
|
557
586
|
edges[#edges + 1] = rec.refs.kind[i]
|
|
@@ -566,6 +595,7 @@ function M.query(symbols, opts)
|
|
|
566
595
|
for _, id in ipairs(ids) do
|
|
567
596
|
if rawget(self.inn, id) == nil then
|
|
568
597
|
wanted[id], names[symbols.nodes[id].name], found = true, true, true
|
|
598
|
+
for _, alias in ipairs(lua_bindings.aliases(symbols.nodes[id], symbols.lua_global_export_tables)) do names[alias] = true end
|
|
569
599
|
end
|
|
570
600
|
end
|
|
571
601
|
if not found then return end
|
|
@@ -599,7 +629,7 @@ function M.query(symbols, opts)
|
|
|
599
629
|
if first > 1 then control.check() end
|
|
600
630
|
for i = first, math.min(count, first + 4095) do
|
|
601
631
|
if (names[ref_names[i]] or aliases[ref_names[i]] or aliases[refs.recv[i]] or (refs.lua_binding and refs.lua_binding[i] ~= '')) and froms[i] > 0 then
|
|
602
|
-
for _, dst in ipairs(targets(f, i) or {}) do
|
|
632
|
+
for _, dst in ipairs(targets(f, i, wanted) or {}) do
|
|
603
633
|
if wanted[dst] then
|
|
604
634
|
push3(incoming, dst, symbols.id_of[f][froms[i]], refs.line[i], refs.kind[i])
|
|
605
635
|
end
|
|
@@ -27,7 +27,7 @@ local INDEX_PARSE = { ranges = false }
|
|
|
27
27
|
-- rebuilds stale caches instead of silently reusing old parse results.
|
|
28
28
|
M.VERSION = (function()
|
|
29
29
|
local parts = {}
|
|
30
|
-
for _, m in ipairs({ 'xscan', 'text', 'common', 'indirect', 'js_evidence', 'lua_bindings', 'parse', 'lang.c', 'lang.cpp', 'lang.lua', 'lang.python',
|
|
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
31
|
'lang.java', 'lang.kotlin', 'lang.go', 'lang.js', 'lang.csharp', 'lang.rust' }) do
|
|
32
32
|
local file = package.searchpath and package.searchpath('codeoutline.' .. m, package.path)
|
|
33
33
|
local h = file and io.open(file, 'rb')
|
|
@@ -229,7 +229,11 @@ end
|
|
|
229
229
|
-- Symbol tables over the records, built on first use and then kept current
|
|
230
230
|
-- by commit(). Hosts that never resolve names do not pay for them.
|
|
231
231
|
function Index:symbols()
|
|
232
|
-
|
|
232
|
+
local ctx = require('codeoutline.lua_bindings').context(self)
|
|
233
|
+
if not self.symbol_tables or table.concat(self.symbol_tables.lua_global_export_tables, '\0')
|
|
234
|
+
~= table.concat(ctx.global_export_tables, '\0') then
|
|
235
|
+
self.symbol_tables = graph.build(self, ctx)
|
|
236
|
+
end
|
|
233
237
|
return self.symbol_tables
|
|
234
238
|
end
|
|
235
239
|
|
|
@@ -57,8 +57,8 @@ local function execute(req)
|
|
|
57
57
|
service.configure({ max_projects = lsp.MAX_ROOTS })
|
|
58
58
|
service.refresh(root, { full_interval = 45, paths = req.paths })
|
|
59
59
|
return true
|
|
60
|
-
elseif req.method == 'explore' then
|
|
61
|
-
local text, info = service.
|
|
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, max_nodes = req.max_nodes })
|
|
62
62
|
return { text = text, truncated = info.truncated or false, refresh = info.refresh }
|
|
63
63
|
elseif req.method == 'status' then return service.status(root)
|
|
64
64
|
elseif req.method == 'rebuild' then return service.rebuild(root)
|
|
@@ -70,7 +70,7 @@ end
|
|
|
70
70
|
-- threads; jobs arriving meanwhile queue behind it.
|
|
71
71
|
local queue, active = {}, nil
|
|
72
72
|
|
|
73
|
-
local function run(id, req)
|
|
73
|
+
local function run(id, req, reply)
|
|
74
74
|
-- Draft text applies even to a cancelled request: the session counts it as sent.
|
|
75
75
|
if req.session and req.open then
|
|
76
76
|
local synced, err = pcall(navigation.sync, req)
|
|
@@ -84,7 +84,11 @@ local function run(id, req)
|
|
|
84
84
|
control.callback = nil
|
|
85
85
|
if not ok then result = tostring(result) end
|
|
86
86
|
shared:delete('cancel:' .. id)
|
|
87
|
-
|
|
87
|
+
if reply then
|
|
88
|
+
assert(_thread_replys[reply.router](reply.co, reply.sk, 'run_rpc', ok, result))
|
|
89
|
+
else
|
|
90
|
+
assert(xthread.post(1, 'worker_result', id, ok, result))
|
|
91
|
+
end
|
|
88
92
|
end
|
|
89
93
|
|
|
90
94
|
local function resume(...)
|
|
@@ -98,7 +102,7 @@ local function pump()
|
|
|
98
102
|
local item = table.remove(queue, 1)
|
|
99
103
|
active = coroutine.create(run)
|
|
100
104
|
pool.bind(active)
|
|
101
|
-
resume(item[1], item[2])
|
|
105
|
+
resume(item[1], item[2], item[3])
|
|
102
106
|
end
|
|
103
107
|
end
|
|
104
108
|
|
|
@@ -115,8 +119,12 @@ return {
|
|
|
115
119
|
pool.sweep()
|
|
116
120
|
if not active then service.sweep(); service.collect() end
|
|
117
121
|
end,
|
|
118
|
-
__thread_handle = function(
|
|
119
|
-
if
|
|
122
|
+
__thread_handle = function(router, op, id, req, failure, rpc_request)
|
|
123
|
+
if type(router) == 'string' and req == 'run_rpc' then
|
|
124
|
+
-- RPC wire: router, coroutine id, session key, method, job id, request.
|
|
125
|
+
queue[#queue + 1] = { failure, rpc_request, { router = router, co = op, sk = id } }
|
|
126
|
+
pump()
|
|
127
|
+
elseif op == 'run' then
|
|
120
128
|
queue[#queue + 1] = { id, req }
|
|
121
129
|
pump()
|
|
122
130
|
elseif op == 'parsed' then
|
|
@@ -82,11 +82,12 @@ local function rules_for(G, rules)
|
|
|
82
82
|
return rules
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
function M.query(G, rules)
|
|
85
|
+
function M.query(G, rules, report)
|
|
86
86
|
rules = rules_for(G, rules)
|
|
87
87
|
if #rules == 0 then return { outgoing = function() return {} end, incoming = function() return {} end } end
|
|
88
88
|
local graph = require('codeoutline.graph')
|
|
89
89
|
local names, cache, order, bytes, registrations_by_rule = {}, {}, {}, 0, {}
|
|
90
|
+
local dependencies = {}
|
|
90
91
|
for _, rule in ipairs(rules) do names[rule.call] = true; if rule.register then names[rule.register] = true end end
|
|
91
92
|
local function candidate(rec, call)
|
|
92
93
|
if rec.dispatch_sites then return true end -- explicit in-memory parse option
|
|
@@ -106,7 +107,8 @@ function M.query(G, rules)
|
|
|
106
107
|
if rec.encoding ~= 'utf-8' and rec.encoding ~= 'utf-8-bom' then
|
|
107
108
|
source = assert(xutils.to_utf8(raw, rec.encoding == 'gbk' and 'gbk' or 'auto'))
|
|
108
109
|
end
|
|
109
|
-
local parsed = assert(require('codeoutline.parse').parse(rec.path, source,
|
|
110
|
+
local parsed = assert(require('codeoutline.parse').parse(rec.path, source,
|
|
111
|
+
{ ranges = false, dispatch = names, dispatch_only = true }))
|
|
110
112
|
assert(#parsed.nodes == #rec.nodes, 'source encoding changed; refresh index before indirect query: ' .. rec.path)
|
|
111
113
|
for i, n in ipairs(parsed.nodes) do
|
|
112
114
|
assert(n.qualified == rec.nodes[i].qualified and n.line == rec.nodes[i].line,
|
|
@@ -130,7 +132,12 @@ function M.query(G, rules)
|
|
|
130
132
|
end
|
|
131
133
|
if not name or not name:match('^[%a_][%w_%.:>%-]*$') then return {} end
|
|
132
134
|
local short = name:match('([%w_]+)$')
|
|
133
|
-
local
|
|
135
|
+
local dependency = dependencies[f]
|
|
136
|
+
if not dependency then
|
|
137
|
+
local deps, paired = graph.dependencies(G, f)
|
|
138
|
+
dependency = { deps, paired }; dependencies[f] = dependency
|
|
139
|
+
end
|
|
140
|
+
local deps, paired = dependency[1], dependency[2]
|
|
134
141
|
local view = G
|
|
135
142
|
if short ~= name then
|
|
136
143
|
local filtered = {}
|
|
@@ -155,7 +162,8 @@ function M.query(G, rules)
|
|
|
155
162
|
local bucket = rec.language .. '\0' .. key.literal
|
|
156
163
|
registrations[bucket] = registrations[bucket] or {}
|
|
157
164
|
for _, id in ipairs(targets(f, site, site.args[rule.handlerArgument])) do
|
|
158
|
-
registrations[bucket][id] =
|
|
165
|
+
registrations[bucket][id] = registrations[bucket][id]
|
|
166
|
+
or (report and (rec.path .. ':' .. site.line) or true)
|
|
159
167
|
end
|
|
160
168
|
end
|
|
161
169
|
end
|
|
@@ -167,23 +175,39 @@ function M.query(G, rules)
|
|
|
167
175
|
end
|
|
168
176
|
local function scan(only, wanted)
|
|
169
177
|
local out = {}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
local files = only and { G.node_file[only] } or G.file_order
|
|
179
|
+
for _, f in ipairs(files) do
|
|
180
|
+
control.check()
|
|
181
|
+
local rec, file_sites = G.files[f], nil
|
|
182
|
+
for ri, rule in ipairs(rules) do
|
|
175
183
|
if (not rule.language or rule.language == rec.language) and candidate(rec, rule.call) then
|
|
176
|
-
|
|
184
|
+
-- Process every applicable rule while this file is available,
|
|
185
|
+
-- even if event registration scans evict it from the FIFO.
|
|
186
|
+
file_sites = file_sites or sites(f)
|
|
187
|
+
for _, site in ipairs(file_sites) do
|
|
177
188
|
if site.call == rule.call and site.from > 0 and (not only or G.id_of[f][site.from] == only) then
|
|
178
|
-
local ids, arg = {}, site.args[rule.argument]
|
|
189
|
+
local ids, arg, registered = {}, site.args[rule.argument], nil
|
|
179
190
|
if rule.kind == 'event' then
|
|
180
|
-
|
|
191
|
+
registered = registrations(ri, rule)
|
|
181
192
|
for id in pairs(arg and arg.literal and registered[rec.language .. '\0' .. arg.literal] or {}) do ids[#ids + 1] = id end
|
|
182
193
|
table.sort(ids, function(a, b) return graph.before(G, a, b) end)
|
|
183
194
|
else ids = targets(f, site, arg, rule.kind == 'target') end
|
|
184
195
|
local src = G.id_of[f][site.from]
|
|
196
|
+
if report and only and #ids == 0 then
|
|
197
|
+
local static = arg and (rule.kind == 'callback' and arg.symbol or rule.kind ~= 'callback' and arg.literal)
|
|
198
|
+
report:add({ source = src, line = site.line, rule = ri, argument = rule.argument, call = rule.call,
|
|
199
|
+
reason = not static and 'dispatch argument is dynamic, unsupported or missing'
|
|
200
|
+
or rule.kind == 'event' and 'no resolved registration for event key'
|
|
201
|
+
or 'dispatch target unresolved or ambiguous' })
|
|
202
|
+
end
|
|
185
203
|
for _, id in ipairs(ids) do
|
|
186
204
|
if not wanted or wanted[id] then
|
|
205
|
+
if report then
|
|
206
|
+
local bucket = registered and arg and arg.literal and registered[rec.language .. '\0' .. arg.literal]
|
|
207
|
+
report:add({ source = src, target = id, line = site.line, rule = ri, argument = rule.argument,
|
|
208
|
+
call = rule.call, kind = 'configured ' .. rule.kind,
|
|
209
|
+
registered_at = bucket and bucket[id] or nil })
|
|
210
|
+
end
|
|
187
211
|
out[src] = out[src] or {}
|
|
188
212
|
out[src][#out[src] + 1] = { target = id, line = site.line, kind = 'indirect:' .. rule.kind .. '#' .. ri }
|
|
189
213
|
end
|
|
@@ -192,6 +192,19 @@ function M.parse(path, src, language, opts)
|
|
|
192
192
|
local v = string_value(T, arg)
|
|
193
193
|
if v then r.imports[#r.imports + 1] = { path = v, line = T:line(i), kind = T:text(i) } end
|
|
194
194
|
end
|
|
195
|
+
elseif k == 'id' and T:text(i):sub(-6) == 'import' and not is(T, i - 1, ':') then
|
|
196
|
+
-- `*import` loader pattern: `ks.import('path')`, `skynet_import 'path'`.
|
|
197
|
+
-- Path-based; resolution keeps it only when the file exists.
|
|
198
|
+
local paren = is(T, i + 1, '(')
|
|
199
|
+
local arg = paren and i + 2 or i + 1
|
|
200
|
+
if T.k[arg] == 'str' and (not paren or is(T, arg + 1, ')') or is(T, arg + 1, ',')) then
|
|
201
|
+
local v = string_value(T, arg)
|
|
202
|
+
if v then
|
|
203
|
+
local kind = T:text(i)
|
|
204
|
+
if is(T, i - 1, '.') and T.k[i - 2] == 'id' then kind = T:text(i - 2) .. '.' .. kind end
|
|
205
|
+
r.imports[#r.imports + 1] = { path = v, line = T:line(i), kind = kind }
|
|
206
|
+
end
|
|
207
|
+
end
|
|
195
208
|
end
|
|
196
209
|
end
|
|
197
210
|
|
|
@@ -214,8 +227,10 @@ function M.parse(path, src, language, opts)
|
|
|
214
227
|
if not defs[ref.tok] then kept[#kept + 1] = ref end
|
|
215
228
|
end
|
|
216
229
|
r.refs = kept
|
|
217
|
-
|
|
218
|
-
|
|
230
|
+
if not r.dispatch_only then
|
|
231
|
+
common.assign_refs(r)
|
|
232
|
+
require('codeoutline.lua_bindings').collect(r, T, bm)
|
|
233
|
+
end
|
|
219
234
|
r.member_ops = nil
|
|
220
235
|
return common.finish(r, T), T
|
|
221
236
|
end
|