@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
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
-- Explicit dispatch contracts. No wildcard API guesses or source evaluation.
|
|
2
2
|
local control = require('codeoutline.control')
|
|
3
3
|
local M = {}
|
|
4
|
+
local aliases = require('codeoutline.dispatch_aliases')
|
|
4
5
|
local member = { ['.'] = true, [':'] = true, ['::'] = true, ['->'] = true }
|
|
5
6
|
|
|
6
|
-
local function value(T, a, b)
|
|
7
|
+
local function value(T, a, b, language)
|
|
7
8
|
if a == b and T.k[a] == 'str' then
|
|
8
9
|
local raw = T:text(a)
|
|
10
|
+
if language == 'lua' then
|
|
11
|
+
local literal = require('codeoutline.lua_literal').decode(raw)
|
|
12
|
+
return literal and { literal = literal } or false
|
|
13
|
+
end
|
|
9
14
|
local q = raw:sub(1, 1)
|
|
10
15
|
if (q == '"' or q == "'") and raw:sub(-1) == q then
|
|
11
16
|
local body = raw:sub(2, -2)
|
|
@@ -25,6 +30,7 @@ end
|
|
|
25
30
|
|
|
26
31
|
function M.collect(r, T)
|
|
27
32
|
local sites, calls = {}, {}
|
|
33
|
+
local expand = r.collect_dispatch and aliases.prepare(r, T)
|
|
28
34
|
for index, ref in ipairs(r.refs) do
|
|
29
35
|
if index % 128 == 0 then control.check() end
|
|
30
36
|
local x = ref.tok
|
|
@@ -33,53 +39,65 @@ function M.collect(r, T)
|
|
|
33
39
|
if close then
|
|
34
40
|
local first = x
|
|
35
41
|
while first > 2 and member[T:text(first - 1)] and T.k[first - 2] == 'id' do first = first - 2 end
|
|
36
|
-
local call = value(T, first, x)
|
|
42
|
+
local call = value(T, first, x, r.language)
|
|
37
43
|
if call then calls[call.symbol] = true end
|
|
38
|
-
if not r.collect_dispatch
|
|
39
|
-
local
|
|
44
|
+
if not r.collect_dispatch then goto next_ref end
|
|
45
|
+
local api = call and expand(call, first)
|
|
46
|
+
if not api or not api.symbol or type(r.collect_dispatch) == 'table'
|
|
47
|
+
and not r.collect_dispatch[call.symbol] and not r.collect_dispatch[api.symbol] then goto next_ref end
|
|
48
|
+
local args, ranges, a, i = {}, r.ranges and {} or nil, x + 2, x + 2
|
|
40
49
|
while i <= close do
|
|
41
50
|
if i == close or T:text(i) == ',' then
|
|
42
|
-
args[#args + 1] = value(T, a, i - 1)
|
|
51
|
+
args[#args + 1] = expand(value(T, a, i - 1, r.language), a)
|
|
52
|
+
if ranges then ranges[#args] = a < i and { T.s[a] - 1, T.e[i - 1] } or false end
|
|
43
53
|
a = i + 1
|
|
44
|
-
elseif T:match(i) and T:match(i) > i then i = T:match(i)
|
|
54
|
+
elseif T:match(i) and T:match(i) > i then i = T:match(i)
|
|
55
|
+
elseif r.language == 'lua' and T.k[i] == 'kw' and T:text(i) == 'function' then
|
|
56
|
+
local depth = 1
|
|
57
|
+
while depth > 0 and i < close do
|
|
58
|
+
i = i + 1
|
|
59
|
+
local kw = T.k[i] == 'kw' and T:text(i)
|
|
60
|
+
if kw == 'function' or kw == 'if' or kw == 'do' or kw == 'repeat' then depth = depth + 1
|
|
61
|
+
elseif kw == 'end' or kw == 'until' then depth = depth - 1 end
|
|
62
|
+
end
|
|
63
|
+
if depth > 0 then break end
|
|
64
|
+
end
|
|
45
65
|
i = i + 1
|
|
46
66
|
end
|
|
47
|
-
if call then sites[#sites + 1] = { call = call.symbol,
|
|
67
|
+
if call then sites[#sites + 1] = { call = call.symbol, api = api.symbol,
|
|
68
|
+
args = args, ranges = ranges, from = ref.from, line = ref.line } end
|
|
48
69
|
end
|
|
49
70
|
end
|
|
50
71
|
::next_ref::
|
|
51
72
|
end
|
|
73
|
+
if not r.collect_dispatch and next(calls) then aliases.hints(r, T, calls) end
|
|
52
74
|
local names = {}
|
|
53
75
|
for name in pairs(calls) do names[#names + 1] = name end
|
|
54
76
|
table.sort(names)
|
|
55
77
|
if #names > 0 then r.dispatch_calls = names end
|
|
56
|
-
|
|
78
|
+
local roles = require('codeoutline.shared_events').roles(r, calls)
|
|
79
|
+
if roles ~= 0 then r.event_roles = roles end
|
|
80
|
+
if r.collect_dispatch then r.dispatch_sites = sites end
|
|
57
81
|
end
|
|
58
82
|
|
|
59
83
|
local function rules_for(G, rules)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
84
|
+
local config = require('codeoutline.rules')
|
|
85
|
+
if rules ~= nil then return config.dispatch(rules) end
|
|
86
|
+
return config.load(G.root).dispatch
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
function M.candidate(rec, call)
|
|
90
|
+
if rec.dispatch_sites then return true end -- explicit in-memory parse option
|
|
91
|
+
for _, name in ipairs(rec.dispatch_calls or {}) do
|
|
92
|
+
if name == call then return true end
|
|
93
|
+
if name:sub(1, 1) == '@' then
|
|
94
|
+
local root = name:sub(2)
|
|
95
|
+
if root == call or call:sub(1, #root + 1) == root .. '.'
|
|
96
|
+
or call:sub(1, #root + 1) == root .. ':'
|
|
97
|
+
or call:sub(1, #root + 2) == root .. '->' then return true end
|
|
68
98
|
end
|
|
69
99
|
end
|
|
70
|
-
|
|
71
|
-
assert(type(rules) == 'table' and #rules <= 32, 'dispatchRules must contain at most 32 rules')
|
|
72
|
-
for _, r in ipairs(rules) do
|
|
73
|
-
assert(type(r) == 'table' and type(r.call) == 'string' and r.call:match('^[%a_][%w_%.:>%-]*$'), 'invalid dispatchRules.call')
|
|
74
|
-
assert(r.kind == 'target' or r.kind == 'callback' or r.kind == 'event', 'invalid dispatchRules.kind')
|
|
75
|
-
assert(r.language == nil or type(r.language) == 'string', 'invalid dispatchRules.language')
|
|
76
|
-
for _, key in ipairs(r.kind == 'event' and { 'argument', 'keyArgument', 'handlerArgument' } or { 'argument' }) do
|
|
77
|
-
local n = r[key]
|
|
78
|
-
assert(type(n) == 'number' and n >= 1 and n <= 32 and n % 1 == 0, 'invalid dispatchRules.' .. key)
|
|
79
|
-
end
|
|
80
|
-
if r.kind == 'event' then assert(type(r.register) == 'string' and r.register:match('^[%a_][%w_%.:>%-]*$'), 'invalid dispatchRules.register') end
|
|
81
|
-
end
|
|
82
|
-
return rules
|
|
100
|
+
return false
|
|
83
101
|
end
|
|
84
102
|
|
|
85
103
|
function M.query(G, rules, report)
|
|
@@ -89,12 +107,8 @@ function M.query(G, rules, report)
|
|
|
89
107
|
local names, cache, order, bytes, registrations_by_rule = {}, {}, {}, 0, {}
|
|
90
108
|
local dependencies = {}
|
|
91
109
|
for _, rule in ipairs(rules) do names[rule.call] = true; if rule.register then names[rule.register] = true end end
|
|
92
|
-
local
|
|
93
|
-
|
|
94
|
-
for _, name in ipairs(rec.dispatch_calls or {}) do if name == call then return true end end
|
|
95
|
-
return false
|
|
96
|
-
end
|
|
97
|
-
local function sites(f)
|
|
110
|
+
local candidate = M.candidate
|
|
111
|
+
local function sites(f, literals)
|
|
98
112
|
local rec = G.files[f]
|
|
99
113
|
if rec.dispatch_sites then return rec.dispatch_sites end
|
|
100
114
|
if cache[f] then return cache[f].sites end
|
|
@@ -107,8 +121,26 @@ function M.query(G, rules, report)
|
|
|
107
121
|
if rec.encoding ~= 'utf-8' and rec.encoding ~= 'utf-8-bom' then
|
|
108
122
|
source = assert(xutils.to_utf8(raw, rec.encoding == 'gbk' and 'gbk' or 'auto'))
|
|
109
123
|
end
|
|
124
|
+
-- Target rules can only obtain a literal command from this file. Reject
|
|
125
|
+
-- broad module hints before scope/registry analysis, but decode escaped
|
|
126
|
+
-- Lua literals so aliases and alternate spellings remain candidates.
|
|
127
|
+
if literals and rec.language == 'lua' then
|
|
128
|
+
local relevant = false
|
|
129
|
+
for name in pairs(literals) do if source:find(name, 1, true) then relevant = true; break end end
|
|
130
|
+
if not relevant and source:find('\\', 1, true) then
|
|
131
|
+
local T = require('codeoutline.lang.lua').lang:tokenize(source)
|
|
132
|
+
local decode = require('codeoutline.lua_literal').decode
|
|
133
|
+
for i = 1, T.n do
|
|
134
|
+
if i % 4096 == 0 then control.check() end
|
|
135
|
+
if T.k[i] == 'str' and literals[decode(T:text(i))] then relevant = true; break end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
-- Do not cache negatives: later incoming calls can request other
|
|
139
|
+
-- targets within this same query, and outgoing needs all sites.
|
|
140
|
+
if not relevant then return {} end
|
|
141
|
+
end
|
|
110
142
|
local parsed = assert(require('codeoutline.parse').parse(rec.path, source,
|
|
111
|
-
{ ranges = false, dispatch = names, dispatch_only = true }))
|
|
143
|
+
{ ranges = false, dispatch = names, dispatch_only = true, language = rec.language }))
|
|
112
144
|
assert(#parsed.nodes == #rec.nodes, 'source encoding changed; refresh index before indirect query: ' .. rec.path)
|
|
113
145
|
for i, n in ipairs(parsed.nodes) do
|
|
114
146
|
assert(n.qualified == rec.nodes[i].qualified and n.line == rec.nodes[i].line,
|
|
@@ -126,6 +158,37 @@ function M.query(G, rules, report)
|
|
|
126
158
|
return result
|
|
127
159
|
end
|
|
128
160
|
local function targets(f, site, arg, literal)
|
|
161
|
+
if arg and not literal and arg.node then return { G.id_of[f][arg.node] } end
|
|
162
|
+
if arg and not literal and arg.import then
|
|
163
|
+
local imp = arg.import
|
|
164
|
+
local rec = G.files[f]
|
|
165
|
+
if rec.language == 'javascript' or rec.language == 'typescript' or rec.language == 'arkts' then
|
|
166
|
+
local js = require('codeoutline.js_resolution')
|
|
167
|
+
dependencies.js = dependencies.js or js.context(G)
|
|
168
|
+
return js.imported(G, f, imp.path, arg.member, dependencies.js) or {}
|
|
169
|
+
elseif rec.language == 'lua' then
|
|
170
|
+
local bindings = require('codeoutline.lua_bindings')
|
|
171
|
+
dependencies.lua = dependencies.lua or bindings.context(G)
|
|
172
|
+
local result = {}
|
|
173
|
+
for _, file in ipairs(bindings.modules(G, { path = imp.path, kind = imp.loader }, dependencies.lua)) do
|
|
174
|
+
local record = G.files[file]
|
|
175
|
+
local exports = require('codeoutline.foreign').exports(record, 'lua', imp.path) or record.lua_exports
|
|
176
|
+
local id = exports and exports[arg.member]
|
|
177
|
+
if id then result[#result + 1] = G.id_of[file][id] end
|
|
178
|
+
end
|
|
179
|
+
return result
|
|
180
|
+
elseif rec.language == 'python' then
|
|
181
|
+
local base = imp.path:gsub('%.', '/')
|
|
182
|
+
local file = G.file_index[base .. '.py'] or G.file_index[base .. '/__init__.py']
|
|
183
|
+
local result = {}
|
|
184
|
+
for _, id in ipairs(file and G.id_of[file] or {}) do
|
|
185
|
+
local n = G.nodes[id]
|
|
186
|
+
if not n.parent and n.name == arg.member then result[#result + 1] = id end
|
|
187
|
+
end
|
|
188
|
+
return result
|
|
189
|
+
end
|
|
190
|
+
return {}
|
|
191
|
+
end
|
|
129
192
|
local name
|
|
130
193
|
if arg then
|
|
131
194
|
if literal then name = arg.literal else name = arg.symbol end
|
|
@@ -158,7 +221,7 @@ function M.query(G, rules, report)
|
|
|
158
221
|
if (not rule.language or rule.language == rec.language) and candidate(rec, rule.register) then
|
|
159
222
|
for _, site in ipairs(sites(f)) do
|
|
160
223
|
local key = site.args[rule.keyArgument]
|
|
161
|
-
if site.call == rule.register and key and key.literal then
|
|
224
|
+
if (site.call == rule.register or site.api == rule.register) and key and key.literal then
|
|
162
225
|
local bucket = rec.language .. '\0' .. key.literal
|
|
163
226
|
registrations[bucket] = registrations[bucket] or {}
|
|
164
227
|
for _, id in ipairs(targets(f, site, site.args[rule.handlerArgument])) do
|
|
@@ -175,6 +238,18 @@ function M.query(G, rules, report)
|
|
|
175
238
|
end
|
|
176
239
|
local function scan(only, wanted)
|
|
177
240
|
local out = {}
|
|
241
|
+
local literals
|
|
242
|
+
if wanted then
|
|
243
|
+
local targets_only = true
|
|
244
|
+
for _, rule in ipairs(rules) do if rule.kind ~= 'target' then targets_only = false; break end end
|
|
245
|
+
if targets_only then
|
|
246
|
+
literals = {}
|
|
247
|
+
for id in pairs(wanted) do
|
|
248
|
+
local node = G.nodes[id]
|
|
249
|
+
literals[node.name], literals[node.qualified or node.name] = true, true
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
178
253
|
local files = only and { G.node_file[only] } or G.file_order
|
|
179
254
|
for _, f in ipairs(files) do
|
|
180
255
|
control.check()
|
|
@@ -183,9 +258,9 @@ function M.query(G, rules, report)
|
|
|
183
258
|
if (not rule.language or rule.language == rec.language) and candidate(rec, rule.call) then
|
|
184
259
|
-- Process every applicable rule while this file is available,
|
|
185
260
|
-- even if event registration scans evict it from the FIFO.
|
|
186
|
-
file_sites = file_sites or sites(f)
|
|
261
|
+
file_sites = file_sites or sites(f, literals)
|
|
187
262
|
for _, site in ipairs(file_sites) do
|
|
188
|
-
if site.call == rule.call and site.from > 0 and (not only or G.id_of[f][site.from] == only) then
|
|
263
|
+
if (site.call == rule.call or site.api == rule.call) and site.from > 0 and (not only or G.id_of[f][site.from] == only) then
|
|
189
264
|
local ids, arg, registered = {}, site.args[rule.argument], nil
|
|
190
265
|
if rule.kind == 'event' then
|
|
191
266
|
registered = registrations(ri, rule)
|
|
@@ -219,7 +294,8 @@ function M.query(G, rules, report)
|
|
|
219
294
|
end
|
|
220
295
|
return out
|
|
221
296
|
end
|
|
222
|
-
return { outgoing = function(id) return scan(id)[id] or {} end, incoming = function(wanted) return scan(nil, wanted) end
|
|
297
|
+
return { outgoing = function(id) return scan(id)[id] or {} end, incoming = function(wanted) return scan(nil, wanted) end,
|
|
298
|
+
resolve_targets = targets }
|
|
223
299
|
end
|
|
224
300
|
|
|
225
301
|
return M
|
|
@@ -16,7 +16,7 @@ local function type_name(T, i)
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
function M.collect(r, T)
|
|
19
|
-
if r.language ~= 'javascript' and r.language ~= 'typescript' then return end
|
|
19
|
+
if r.language ~= 'javascript' and r.language ~= 'typescript' and r.language ~= 'arkts' then return end
|
|
20
20
|
r.js_imports, r.js_exports = {}, {}
|
|
21
21
|
local skip = {}
|
|
22
22
|
local function export(name, local_name, path)
|
|
@@ -75,6 +75,7 @@ function M.collect(r, T)
|
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
+
if r.defer_analysis or not r.ordinary_bindings and not r.ranges then return end
|
|
78
79
|
-- Braces provide block lifetime; node ranges extend parameter bindings to bodies.
|
|
79
80
|
local scopes, stack = {}, {}
|
|
80
81
|
for i = 1, T.n do
|
|
@@ -82,7 +83,7 @@ function M.collect(r, T)
|
|
|
82
83
|
scopes[i] = stack[#stack] or 0
|
|
83
84
|
if stack[#stack] and T.m[stack[#stack]] == i then stack[#stack] = nil end
|
|
84
85
|
end
|
|
85
|
-
local bindings, parameters = {}, {}
|
|
86
|
+
local bindings, parameters, alias_tokens = {}, {}, {}
|
|
86
87
|
local callable_at = {}
|
|
87
88
|
for _, n in ipairs(r.nodes) do
|
|
88
89
|
if n.kind == 'function' or n.kind == 'method' or n.kind == 'constructor' then
|
|
@@ -141,6 +142,10 @@ function M.collect(r, T)
|
|
|
141
142
|
if after and T:text(after) ~= '=' and T:text(after) ~= ',' and T:text(after) ~= ')' and T:text(after) ~= ';' then typ = nil end
|
|
142
143
|
elseif next == '=' and T:text(i + 2) == 'new' then typ = type_name(T, i + 3) end
|
|
143
144
|
local a, b = scope_for(i, parameter)
|
|
145
|
+
local eq = next == '=' and i + 1 or after
|
|
146
|
+
if r.ordinary_bindings and declaration and eq and T:text(eq) == '=' and T.k[eq + 1] == 'id' then
|
|
147
|
+
alias_tokens[i] = require('codeoutline.dispatch_aliases').simple(T, eq + 1, r.language, true) and 'simple' or true
|
|
148
|
+
end
|
|
144
149
|
bindings[#bindings + 1] = { name = T:text(i), type = typ or '?', token = i, a = a, b = b,
|
|
145
150
|
declaration = declaration or parameter, target = declaration and callable_at[i] or nil }
|
|
146
151
|
end
|
|
@@ -151,6 +156,17 @@ function M.collect(r, T)
|
|
|
151
156
|
by_name[binding.name] = by_name[binding.name] or {}
|
|
152
157
|
by_name[binding.name][#by_name[binding.name] + 1] = binding
|
|
153
158
|
end
|
|
159
|
+
-- Reuse dispatch's bounded lexical validation in explicit query parses.
|
|
160
|
+
-- Ordinary indexing leaves this extra evidence ungenerated.
|
|
161
|
+
local expand
|
|
162
|
+
local function alias_evidence(name, at, token)
|
|
163
|
+
if alias_tokens[token] ~= 'simple' then return '?' end
|
|
164
|
+
expand = expand or require('codeoutline.dispatch_aliases').prepare(r, T)
|
|
165
|
+
local v = expand({ symbol = name }, at)
|
|
166
|
+
if v and v.node then return 'node:' .. v.node end
|
|
167
|
+
if v and v.import then return 'import:' .. v.import.path .. '\0' .. v.member end
|
|
168
|
+
return '?'
|
|
169
|
+
end
|
|
154
170
|
for index, ref in ipairs(r.refs) do
|
|
155
171
|
if index % 128 == 0 then control.check() end
|
|
156
172
|
local target = ref.recv or ref.name
|
|
@@ -163,13 +179,26 @@ function M.collect(r, T)
|
|
|
163
179
|
end
|
|
164
180
|
end
|
|
165
181
|
if best then
|
|
166
|
-
if not ref.recv and best.
|
|
182
|
+
if not ref.recv and alias_tokens[best.token] then ref.js_receiver = alias_evidence(ref.name, ref.tok, best.token)
|
|
183
|
+
elseif not ref.recv and best.target and (best.token <= ref.tok or best.hoisted) then ref.js_receiver = 'node:' .. best.target
|
|
167
184
|
else ref.js_receiver = ref.recv and best.token <= ref.tok and best.type or '?' end
|
|
168
185
|
end
|
|
169
186
|
if ref.kind == 'member_call' and (not ref.recv or T:text(ref.tok - 3) == '.' or T:text(ref.tok - 3) == '?.') then
|
|
170
187
|
ref.js_receiver = '?' -- A field/call-result chain is not the local variable sharing its tail.
|
|
171
188
|
end
|
|
172
189
|
end
|
|
190
|
+
if next(alias_tokens) then
|
|
191
|
+
for _, e in ipairs(r.js_exports) do
|
|
192
|
+
if not e.path then
|
|
193
|
+
for _, b in ipairs(by_name[e.local_name] or {}) do
|
|
194
|
+
if b.a == 0 and alias_tokens[b.token] then
|
|
195
|
+
e.binding = alias_evidence(e.local_name, T.n, b.token)
|
|
196
|
+
break
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
173
202
|
end
|
|
174
203
|
|
|
175
204
|
return M
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
-- JS/TS module and receiver evidence; deliberately not a type checker.
|
|
2
2
|
local M = {}
|
|
3
3
|
local control = require('codeoutline.control')
|
|
4
|
-
local function js(rec) return rec and (rec.language == 'javascript' or rec.language == 'typescript') end
|
|
4
|
+
local function js(rec) return rec and (rec.language == 'javascript' or rec.language == 'typescript' or rec.language == 'arkts') end
|
|
5
5
|
local function dir(p) return p:match('^(.*)/[^/]*$') or '' end
|
|
6
6
|
local function norm(p)
|
|
7
7
|
local parts = {}
|
|
@@ -43,7 +43,9 @@ local function config(path, seen, depth)
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
function M.context(G)
|
|
46
|
-
local ctx = { modules = {}, exports = {} }
|
|
46
|
+
local ctx = { modules = {}, exports = {}, module_reasons = {},
|
|
47
|
+
workspace_stats = { reads = 0, bytes = 0, directories = 0, packages = 0 },
|
|
48
|
+
go_stats = { reads = 0, bytes = 0, modules = 0 }, rust_stats = { reads = 0, bytes = 0, packages = 0 } }
|
|
47
49
|
if G.root then
|
|
48
50
|
for _, name in ipairs({ 'tsconfig.json', 'jsconfig.json', 'tsconfig.base.json' }) do
|
|
49
51
|
local opts = config(G.root .. '/' .. name, {}, 0)
|
|
@@ -70,10 +72,11 @@ end
|
|
|
70
72
|
|
|
71
73
|
local extensions = { '', '.ts', '.tsx', '.js', '.jsx', '.mts', '.cts', '.mjs', '.cjs',
|
|
72
74
|
'/index.ts', '/index.tsx', '/index.js', '/index.jsx', '/index.mts', '/index.mjs' }
|
|
73
|
-
function M.module(G, f, spec, ctx)
|
|
75
|
+
function M.module(G, f, spec, ctx, mode)
|
|
74
76
|
ctx = ctx or M.context(G)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
mode = mode or 'import'
|
|
78
|
+
local key = G.files[f].path .. '\0' .. spec .. '\0' .. mode
|
|
79
|
+
if ctx.modules[key] ~= nil then return ctx.modules[key] or nil, ctx.module_reasons[key] end
|
|
77
80
|
local bases = {}
|
|
78
81
|
if spec:sub(1, 1) == '.' then bases[1] = norm(dir(G.files[f].path) .. '/' .. spec):gsub('^/', '')
|
|
79
82
|
else
|
|
@@ -94,16 +97,41 @@ function M.module(G, f, spec, ctx)
|
|
|
94
97
|
end
|
|
95
98
|
end
|
|
96
99
|
end
|
|
97
|
-
|
|
100
|
+
local function find(base)
|
|
98
101
|
local candidates = { base }
|
|
99
|
-
if
|
|
102
|
+
if G.files[f].language == 'arkts' then
|
|
103
|
+
candidates[#candidates + 1] = base .. '.ets'
|
|
104
|
+
candidates[#candidates + 1] = base .. '/index.ets'
|
|
105
|
+
end
|
|
106
|
+
if base:match('%.js$') then candidates[#candidates + 1] = base:gsub('%.js$', '.ts'); candidates[#candidates + 1] = base:gsub('%.js$', '.tsx')
|
|
107
|
+
elseif base:match('%.mjs$') then candidates[#candidates + 1] = base:gsub('%.mjs$', '.mts')
|
|
108
|
+
elseif base:match('%.cjs$') then candidates[#candidates + 1] = base:gsub('%.cjs$', '.cts') end
|
|
100
109
|
for _, ext in ipairs(extensions) do candidates[#candidates + 1] = base .. ext end
|
|
101
110
|
for _, candidate in ipairs(candidates) do
|
|
102
111
|
local target = G.file_index[candidate]
|
|
103
|
-
if target and js(G.files[target]) then
|
|
112
|
+
if target and js(G.files[target]) then return target end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
for _, base in ipairs(bases) do
|
|
116
|
+
local target = find(base)
|
|
117
|
+
if target then ctx.modules[key] = target; return target end
|
|
118
|
+
end
|
|
119
|
+
if spec:sub(1, 1) ~= '.' then
|
|
120
|
+
if ctx.workspace_error then
|
|
121
|
+
ctx.modules[key], ctx.module_reasons[key] = false, ctx.workspace_error
|
|
122
|
+
return nil, ctx.workspace_error
|
|
104
123
|
end
|
|
124
|
+
local ok, target, reason = pcall(require('codeoutline.js_workspace').resolve, G, f, spec, ctx, mode, find)
|
|
125
|
+
if not ok then
|
|
126
|
+
if control.is_interrupted(target) then error(target, 0) end
|
|
127
|
+
ctx.workspace_incomplete = true; reason, target = tostring(target), nil
|
|
128
|
+
ctx.workspace_error = reason
|
|
129
|
+
end
|
|
130
|
+
if target then ctx.modules[key] = target; return target end
|
|
131
|
+
ctx.module_reasons[key] = reason
|
|
105
132
|
end
|
|
106
133
|
ctx.modules[key] = false
|
|
134
|
+
return nil, ctx.module_reasons[key]
|
|
107
135
|
end
|
|
108
136
|
|
|
109
137
|
local function exported(G, f, name, ctx, seen, depth)
|
|
@@ -117,6 +145,21 @@ local function exported(G, f, name, ctx, seen, depth)
|
|
|
117
145
|
local function add(ids) for _, id in ipairs(ids) do if not unique[id] then unique[id] = true; result[#result + 1] = id end end end
|
|
118
146
|
local rec = G.files[f]
|
|
119
147
|
local entries = rec.js_exports or {}
|
|
148
|
+
-- Only variable exports may need the new lexical alias analysis. Ordinary
|
|
149
|
+
-- declared exports continue to resolve entirely from the resident index.
|
|
150
|
+
if ctx.ordinary and not rec.ordinary_bindings then
|
|
151
|
+
local needed = false
|
|
152
|
+
for _, e in ipairs(entries) do
|
|
153
|
+
if e.name == name and not e.path then
|
|
154
|
+
for _, id in ipairs(G.by_name[e.local_name] or {}) do
|
|
155
|
+
local n = G.nodes[id]
|
|
156
|
+
if G.node_file[id] == f and not n.parent and n.kind == 'variable' then needed = true; break end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
if needed then break end
|
|
160
|
+
end
|
|
161
|
+
if needed then entries = ctx.ordinary.data(f).js_exports or entries end
|
|
162
|
+
end
|
|
120
163
|
local explicit = false
|
|
121
164
|
for _, e in ipairs(entries) do if e.name == name then explicit = true end end
|
|
122
165
|
for _, e in ipairs(entries) do
|
|
@@ -125,6 +168,16 @@ local function exported(G, f, name, ctx, seen, depth)
|
|
|
125
168
|
if e.path then
|
|
126
169
|
local target = M.module(G, f, e.path, ctx)
|
|
127
170
|
if target then add(exported(G, target, want, ctx, seen, depth + 1)) end
|
|
171
|
+
elseif e.binding then
|
|
172
|
+
local node = e.binding:match('^node:(%d+)$')
|
|
173
|
+
local path, member = e.binding:match('^import:(.-)%z(.*)$')
|
|
174
|
+
if node then
|
|
175
|
+
local id = G.id_of[f][tonumber(node)]
|
|
176
|
+
if id then add({ id }) end
|
|
177
|
+
elseif path then
|
|
178
|
+
local target = M.module(G, f, path, ctx)
|
|
179
|
+
if target then add(exported(G, target, member, ctx, seen, depth + 1)) end
|
|
180
|
+
end
|
|
128
181
|
else
|
|
129
182
|
for _, id in ipairs(G.id_of[f]) do
|
|
130
183
|
local n = G.nodes[id]
|
|
@@ -143,6 +196,13 @@ local function exported(G, f, name, ctx, seen, depth)
|
|
|
143
196
|
return result
|
|
144
197
|
end
|
|
145
198
|
|
|
199
|
+
-- Shared named/namespace import lookup for query-owned callback aliases.
|
|
200
|
+
function M.imported(G, f, path, name, ctx)
|
|
201
|
+
ctx = ctx or M.context(G)
|
|
202
|
+
local target, reason = M.module(G, f, path, ctx)
|
|
203
|
+
return target and name ~= '' and exported(G, target, name, ctx, {}, 0) or {}, reason
|
|
204
|
+
end
|
|
205
|
+
|
|
146
206
|
function M.resolve(G, f, name, kind, recv, evidence, ctx)
|
|
147
207
|
local rec = G.files[f]
|
|
148
208
|
if not js(rec) then return nil end
|
|
@@ -150,8 +210,8 @@ function M.resolve(G, f, name, kind, recv, evidence, ctx)
|
|
|
150
210
|
local function binding(local_name, member)
|
|
151
211
|
for _, b in ipairs(rec.js_imports or {}) do
|
|
152
212
|
if b.local_name == local_name then
|
|
153
|
-
local target = M.module(G, f, b.path, ctx)
|
|
154
|
-
if not target then return {} end
|
|
213
|
+
local target, reason = M.module(G, f, b.path, ctx)
|
|
214
|
+
if not target then return {}, reason end
|
|
155
215
|
if b.imported == '*' then return member and exported(G, target, member, ctx, {}, 0) or {} end
|
|
156
216
|
return exported(G, target, b.imported, ctx, {}, 0)
|
|
157
217
|
end
|
|
@@ -161,6 +221,8 @@ function M.resolve(G, f, name, kind, recv, evidence, ctx)
|
|
|
161
221
|
if evidence then
|
|
162
222
|
local node = evidence:match('^node:(%d+)$')
|
|
163
223
|
if node then return { G.id_of[f][tonumber(node)] } end
|
|
224
|
+
local path, member = evidence:match('^import:(.-)%z(.*)$')
|
|
225
|
+
if path then return M.imported(G, f, path, member, ctx) end
|
|
164
226
|
local head, tail = evidence:match('^([%w_$]+)%.([%w_$]+)$')
|
|
165
227
|
local classes = binding(head or evidence, tail)
|
|
166
228
|
if classes == nil then
|