@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
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
-- Query-owned ES module EventEmitter identities. Indexing keeps only role bits.
|
|
2
|
+
local M = { MAX_FILES = 32, MAX_BYTES = 2097152, MAX_FILE_BYTES = 262144,
|
|
3
|
+
MAX_SITES = 512, MAX_TARGETS = 64, MAX_DEPTH = 8, MAX_MS = 200 }
|
|
4
|
+
local control = require('codeoutline.control')
|
|
5
|
+
local methods = { emit = 1, on = 2, once = 2, addListener = 2,
|
|
6
|
+
off = 4, removeListener = 4, removeAllListeners = 4 }
|
|
7
|
+
local function supported(r) return r.language == 'javascript' or r.language == 'typescript' end
|
|
8
|
+
local function builtin(path) return path == 'events' or path == 'node:events' end
|
|
9
|
+
|
|
10
|
+
function M.roles(r, calls)
|
|
11
|
+
if not supported(r) then return 0 end
|
|
12
|
+
local found = {}
|
|
13
|
+
for name in pairs(calls) do
|
|
14
|
+
local role = methods[name:match('%.([%w_$]+)$')]
|
|
15
|
+
if role then found[role] = true end
|
|
16
|
+
end
|
|
17
|
+
for _, imp in ipairs(r.js_imports or {}) do if builtin(imp.path) then found[8] = true end end
|
|
18
|
+
return (found[1] and 1 or 0) + (found[2] and 2 or 0) + (found[4] and 4 or 0) + (found[8] and 8 or 0)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
local function has(r, role)
|
|
22
|
+
if not supported(r) then return false end
|
|
23
|
+
local roles = r.event_roles
|
|
24
|
+
if roles == nil then
|
|
25
|
+
local calls = {}; for _, name in ipairs(r.dispatch_calls or {}) do calls[name] = true end
|
|
26
|
+
roles = M.roles(r, calls)
|
|
27
|
+
end
|
|
28
|
+
if role == 7 then return roles % 8 ~= 0 end
|
|
29
|
+
return math.floor(roles / role) % 2 == 1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
local function literal(T, i)
|
|
33
|
+
local s = T:text(i)
|
|
34
|
+
if T.k[i] == 'str' and (s:sub(1, 1) == '"' or s:sub(1, 1) == "'")
|
|
35
|
+
and s:sub(-1) == s:sub(1, 1) and not s:find('[\\$]') then return s:sub(2, -2) end
|
|
36
|
+
end
|
|
37
|
+
local function ending(T, i)
|
|
38
|
+
return T:text(i + 1) == ';' or T:text(i + 1) == '' or T:text(i + 1) == '}'
|
|
39
|
+
or T.l[i + 1] and T.l[i + 1] > T.l[i] and T.k[i + 1] ~= 'op'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
function M.collect(r, T)
|
|
43
|
+
if not supported(r) or not r.js_imports or #r.js_imports == 0 then return end
|
|
44
|
+
local candidate, imported = false, {}
|
|
45
|
+
for _, imp in ipairs(r.js_imports) do
|
|
46
|
+
imported[imp.local_name] = true
|
|
47
|
+
if builtin(imp.path) then candidate = true end
|
|
48
|
+
end
|
|
49
|
+
if not candidate then
|
|
50
|
+
for _, ref in ipairs(r.refs) do if ref.recv and methods[ref.name] then candidate = true; break end end
|
|
51
|
+
for _, export in ipairs(r.js_exports or {}) do
|
|
52
|
+
if not export.path and imported[export.local_name] then candidate = true; break end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
if not candidate then return end
|
|
56
|
+
local expand, binding = require('codeoutline.dispatch_aliases').prepare(r, T)
|
|
57
|
+
local result = { objects = {}, exports = {}, entities = {}, sites = {}, weight = 0 }
|
|
58
|
+
r.shared_events = result
|
|
59
|
+
local headers, classes, skip, objects, refs, variables = {}, {}, {}, {}, {}, {}
|
|
60
|
+
for id, n in ipairs(r.nodes) do
|
|
61
|
+
if not n.parent and n.kind == 'variable' then variables[n.name] = id end
|
|
62
|
+
if n.kind == 'class' or n.kind == 'interface' then classes[n.name] = true end
|
|
63
|
+
if n.kind == 'function' or n.kind == 'method' or n.kind == 'constructor' then
|
|
64
|
+
for i = n.ti, n.tj do
|
|
65
|
+
if T:text(i) == 'function' or T:text(i) == '=>' then headers[i] = true end
|
|
66
|
+
if T:text(i) == '{' then break end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
for _, ref in ipairs(r.refs) do refs[ref.tok] = ref end
|
|
71
|
+
for i = 1, T.n do
|
|
72
|
+
if i % 4096 == 0 then control.check() end
|
|
73
|
+
local word = T:text(i)
|
|
74
|
+
if (word == 'function' or word == '=>') and not headers[i] then result.unsupported = true; return end
|
|
75
|
+
if word == 'import' and T:text(i + 1) ~= '(' or word == 'export' and T:text(i + 1) == '{' then
|
|
76
|
+
local j = i + 1
|
|
77
|
+
while j <= T.n do
|
|
78
|
+
skip[j] = true
|
|
79
|
+
if T.m[j] and T.m[j] > j then
|
|
80
|
+
for x = j, T.m[j] do skip[x] = true end
|
|
81
|
+
j = T.m[j]
|
|
82
|
+
end
|
|
83
|
+
if T:text(j) == ';' or T.k[j] == 'str' or T:text(j) == '}' or j > i + 1 and (T.l[j + 1] or math.huge) > T.l[j] then break end
|
|
84
|
+
j = j + 1
|
|
85
|
+
end
|
|
86
|
+
elseif word == 'export' and T:text(i + 1) == 'default' and T.k[i + 2] == 'id' then skip[i + 2] = true end
|
|
87
|
+
if T:text(i - 1) == 'const' and T.k[i] == 'id' and T:text(i + 1) == '='
|
|
88
|
+
and T:text(i + 2) == 'new' and T.k[i + 3] == 'id' then
|
|
89
|
+
local last = i + 3
|
|
90
|
+
if T:text(last + 1) == '.' and T.k[last + 2] == 'id' then last = last + 2 end
|
|
91
|
+
local open = last + 1
|
|
92
|
+
local factory = expand({ symbol = T.src:sub(T.s[i + 3], T.e[last]):gsub('%s+', '') }, i + 3)
|
|
93
|
+
local token, scope = binding(T:text(i), i)
|
|
94
|
+
if token == i and scope == 0 and not classes[T:text(i + 3)] and factory and factory.import
|
|
95
|
+
and builtin(factory.import.path) and (factory.member == 'EventEmitter' or factory.member == 'default')
|
|
96
|
+
and T:text(open) == '(' and T.m[open] == open + 1 and ending(T, T.m[open]) then
|
|
97
|
+
local object = { name = T:text(i), token = i }
|
|
98
|
+
object.node = variables[object.name]
|
|
99
|
+
if object.node then objects[i] = object end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
local entities = {}
|
|
104
|
+
local function entity(name, at)
|
|
105
|
+
local token = binding(name, at)
|
|
106
|
+
local object = token and objects[token]
|
|
107
|
+
local value = not object and expand({ symbol = name }, at)
|
|
108
|
+
local key, descriptor
|
|
109
|
+
if object then key, descriptor = 'local:' .. token, { object = object.name }
|
|
110
|
+
elseif value and value.import and not builtin(value.import.path) and value.member:match('^[%w_$]+$') then
|
|
111
|
+
key, descriptor = value.import.path .. '\0' .. value.member, { path = value.import.path, member = value.member }
|
|
112
|
+
else return end
|
|
113
|
+
if not entities[key] then
|
|
114
|
+
if #result.entities >= M.MAX_SITES then result.incomplete = true; return end
|
|
115
|
+
descriptor.name = name; result.entities[#result.entities + 1] = descriptor
|
|
116
|
+
entities[key] = descriptor; result.weight = result.weight + 256
|
|
117
|
+
end
|
|
118
|
+
return entities[key]
|
|
119
|
+
end
|
|
120
|
+
for i = 1, T.n do
|
|
121
|
+
if i % 4096 == 0 then control.check() end
|
|
122
|
+
if not skip[i] and T.k[i] == 'id' and T:text(i - 1) ~= '.' and T:text(i - 1) ~= '?.'
|
|
123
|
+
and T:text(i - 1) ~= 'const' and not objects[i] then
|
|
124
|
+
local e = entity(T:text(i), i)
|
|
125
|
+
if e then
|
|
126
|
+
local method, ref, open = T:text(i + 2), refs[i + 2], i + 3
|
|
127
|
+
local before = T:text(i - 1)
|
|
128
|
+
local start = before == '' or before == ';' or before == '{' or before == '}'
|
|
129
|
+
or T.l[i] > T.l[i - 1] and T.k[i - 1] ~= 'op'
|
|
130
|
+
-- Simple local aliases of an imported binding reuse lexical validation.
|
|
131
|
+
local alias = e.path and before == '=' and T:text(i - 3) == 'const' and ending(T, i)
|
|
132
|
+
if alias then
|
|
133
|
+
elseif not start or T:text(i + 1) ~= '.' or not ref or T:text(open) ~= '('
|
|
134
|
+
or not T.m[open] or not ending(T, T.m[open]) or not methods[method] or methods[method] == 4 then e.invalid = true
|
|
135
|
+
else
|
|
136
|
+
local close, event = T.m[open], literal(T, open + 1)
|
|
137
|
+
local handler
|
|
138
|
+
if methods[method] == 2 and T:text(open + 2) == ',' then
|
|
139
|
+
local text = T.src:sub(T.s[open + 3] or 1, T.e[close - 1] or 0):gsub('%s+', '')
|
|
140
|
+
handler = text:match('^[%a_$][%w_$.]*$') and not classes[text:match('^[%w_$]+')]
|
|
141
|
+
and expand({ symbol = text }, open + 3)
|
|
142
|
+
if not handler or not (handler.node or handler.import) or ref.from ~= 0 then e.invalid = true end
|
|
143
|
+
end
|
|
144
|
+
if not event or T:text(open + 2) ~= ',' and open + 2 ~= close then e.invalid = true end
|
|
145
|
+
if not e.invalid and (method == 'emit' or handler) then
|
|
146
|
+
if #result.sites >= M.MAX_SITES then result.incomplete = true; break end
|
|
147
|
+
result.sites[#result.sites + 1] = { entity = e, event = event, method = method, handler = handler,
|
|
148
|
+
from = ref.from, line = ref.line, first = T.s[open + 1] - 1, last = T.e[open + 1] }
|
|
149
|
+
result.weight = result.weight + 512
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
for token, object in pairs(objects) do
|
|
156
|
+
local e = entity(object.name, T.n)
|
|
157
|
+
if e and not e.invalid then result.objects[object.name] = object end
|
|
158
|
+
end
|
|
159
|
+
for _, export in ipairs(r.js_exports or {}) do
|
|
160
|
+
if not export.path and export.local_name then
|
|
161
|
+
local e = entity(export.local_name, T.n)
|
|
162
|
+
result.exports[export.local_name] = e
|
|
163
|
+
if e and e.object and result.objects[e.object] then result.objects[e.object].exported = true end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
function M.context(G, ctx, report)
|
|
169
|
+
if ctx.shared_event_context then return ctx.shared_event_context end
|
|
170
|
+
local reasons = {}
|
|
171
|
+
local C = { incomplete = false, stats = { files = 0, bytes = 0, sites = 0, links = 0, identities = 0,
|
|
172
|
+
incomplete_reasons = reasons } }
|
|
173
|
+
local function incomplete(reason) C.incomplete = true; reasons[reason] = true end
|
|
174
|
+
ctx.shared_event_context = C
|
|
175
|
+
local js = require('codeoutline.js_resolution')
|
|
176
|
+
local cache, identities, buses, started = {}, {}, {}, nil
|
|
177
|
+
local all_files, emitting = nil, {}
|
|
178
|
+
local function files()
|
|
179
|
+
if not all_files then
|
|
180
|
+
all_files = {}; local seen = {}
|
|
181
|
+
for _, list in ipairs({ G.file_order, G.new_files or {} }) do for _, f in ipairs(list) do
|
|
182
|
+
if not seen[f] then seen[f] = true; all_files[#all_files + 1] = f end
|
|
183
|
+
end end
|
|
184
|
+
table.sort(all_files, function(a,b) return G.files[a].path < G.files[b].path end)
|
|
185
|
+
end
|
|
186
|
+
return all_files
|
|
187
|
+
end
|
|
188
|
+
local function emits(f)
|
|
189
|
+
if not emitting[f] then
|
|
190
|
+
local found, refs = {}, G.files[f].refs
|
|
191
|
+
for i, name in ipairs(refs.name) do
|
|
192
|
+
if i % 128 == 0 then control.check() end
|
|
193
|
+
if name == 'emit' and refs.recv[i] and refs.from[i] > 0 then
|
|
194
|
+
found[G.id_of[f][refs.from[i]]] = true
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
emitting[f] = found
|
|
198
|
+
end
|
|
199
|
+
return emitting[f]
|
|
200
|
+
end
|
|
201
|
+
local function allowed()
|
|
202
|
+
control.check(); started = started or xtimer.now_ms()
|
|
203
|
+
if xtimer.now_ms() - started > M.MAX_MS then incomplete('time_limit'); return false end
|
|
204
|
+
return true
|
|
205
|
+
end
|
|
206
|
+
local function data(f)
|
|
207
|
+
if cache[f] ~= nil then return cache[f] or nil end
|
|
208
|
+
local rec = G.files[f]
|
|
209
|
+
if not supported(rec) or not allowed() then return end
|
|
210
|
+
local size = ctx.ordinary.source_size(f) or 0
|
|
211
|
+
if C.stats.files >= M.MAX_FILES then incomplete('file_limit'); return end
|
|
212
|
+
if size > M.MAX_FILE_BYTES then incomplete('file_size_limit'); return end
|
|
213
|
+
if C.stats.bytes + size > M.MAX_BYTES then incomplete('source_byte_limit'); return end
|
|
214
|
+
C.stats.files, C.stats.bytes = C.stats.files + 1, C.stats.bytes + size
|
|
215
|
+
local d = ctx.ordinary.data(f).shared_events
|
|
216
|
+
if d and d.unsupported then incomplete('unsupported_syntax'); d = nil end
|
|
217
|
+
if d and d.incomplete then incomplete('site_limit'); d = nil end
|
|
218
|
+
if d and C.stats.sites + #d.sites + #d.entities > M.MAX_SITES then incomplete('site_limit'); d = nil end
|
|
219
|
+
if d then C.stats.sites = C.stats.sites + #d.sites + #d.entities end
|
|
220
|
+
cache[f] = d or false; return d
|
|
221
|
+
end
|
|
222
|
+
local identity, descriptor
|
|
223
|
+
descriptor = function(f, e, seen, depth)
|
|
224
|
+
if not e or e.invalid or not allowed() then return end
|
|
225
|
+
if e.object then
|
|
226
|
+
local d = data(f); local object = d and d.objects[e.object]
|
|
227
|
+
if object and object.exported then return { key = f .. '\0' .. object.node, file = f, node = G.id_of[f][object.node] } end
|
|
228
|
+
elseif e.path then
|
|
229
|
+
local target = js.module(G, f, e.path, ctx)
|
|
230
|
+
if target then return identity(target, e.member, seen, depth + 1) end
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
identity = function(f, name, seen, depth)
|
|
234
|
+
if depth > M.MAX_DEPTH then incomplete('depth_limit'); return end
|
|
235
|
+
if not allowed() then return end
|
|
236
|
+
local key = f .. '\0' .. name
|
|
237
|
+
if identities[key] ~= nil then return identities[key] or nil end
|
|
238
|
+
if seen[key] then incomplete('cyclic_export'); return end
|
|
239
|
+
seen[key] = true; C.stats.identities = C.stats.identities + 1
|
|
240
|
+
local entries, explicit, found, ambiguous = G.files[f].js_exports or {}, false, nil, false
|
|
241
|
+
for _, e in ipairs(entries) do if e.name == name then explicit = true end end
|
|
242
|
+
for _, e in ipairs(entries) do
|
|
243
|
+
if e.name == name or not explicit and e.name == '*' and name ~= 'default' then
|
|
244
|
+
local value, want = nil, e.local_name == '*' and name or e.local_name
|
|
245
|
+
if e.path then
|
|
246
|
+
local target = js.module(G, f, e.path, ctx)
|
|
247
|
+
if target then value = identity(target, want, seen, depth + 1) end
|
|
248
|
+
else
|
|
249
|
+
local d = data(f)
|
|
250
|
+
value = d and descriptor(f, d.exports[want], seen, depth)
|
|
251
|
+
end
|
|
252
|
+
if value then
|
|
253
|
+
if found and found.key ~= value.key then ambiguous = true else found = value end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
seen[key] = nil
|
|
258
|
+
if ambiguous then incomplete('ambiguous_binding'); found = nil end
|
|
259
|
+
identities[key] = found or false; return found
|
|
260
|
+
end
|
|
261
|
+
local function handler(f, value)
|
|
262
|
+
if value.node then return { G.id_of[f][value.node] } end
|
|
263
|
+
return js.imported(G, f, value.import.path, value.member, ctx)
|
|
264
|
+
end
|
|
265
|
+
local function load_bus(owner)
|
|
266
|
+
if buses[owner.key] then return buses[owner.key] end
|
|
267
|
+
local out, emits, registrations, invalid = {}, {}, {}, false
|
|
268
|
+
buses[owner.key] = out
|
|
269
|
+
local related = ctx.ordinary.candidates({ [owner.node] = true })
|
|
270
|
+
for _, f in ipairs(files()) do
|
|
271
|
+
if related[f] and has(G.files[f], 7) then
|
|
272
|
+
if not allowed() then return {} end
|
|
273
|
+
local d = data(f)
|
|
274
|
+
if d then
|
|
275
|
+
local selected = {}
|
|
276
|
+
for _, e in ipairs(d.entities) do
|
|
277
|
+
-- Resolve identity even for poisoned uses, so remove/escape
|
|
278
|
+
-- in one consumer invalidates this bus's whole result.
|
|
279
|
+
local copy = {}; for k, v in pairs(e) do if k ~= 'invalid' then copy[k] = v end end
|
|
280
|
+
local value = descriptor(f, copy, {}, 0)
|
|
281
|
+
if value and value.key == owner.key then selected[e] = true; invalid = invalid or e.invalid end
|
|
282
|
+
end
|
|
283
|
+
for _, site in ipairs(d.sites) do if selected[site.entity] then
|
|
284
|
+
local value = { file = f, site = site }
|
|
285
|
+
if site.method == 'emit' and site.from > 0 then emits[#emits + 1] = value
|
|
286
|
+
elseif site.method ~= 'emit' then registrations[#registrations + 1] = value end
|
|
287
|
+
end end
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
if C.incomplete or invalid then return out end
|
|
292
|
+
local seen = {}
|
|
293
|
+
for _, emit in ipairs(emits) do for _, reg in ipairs(registrations) do
|
|
294
|
+
if emit.file ~= reg.file and emit.site.event == reg.site.event then
|
|
295
|
+
local ids = handler(reg.file, reg.site.handler)
|
|
296
|
+
if #ids == 1 and (G.nodes[ids[1]].kind == 'function' or G.nodes[ids[1]].kind == 'method') then
|
|
297
|
+
local source = G.id_of[emit.file][emit.site.from]
|
|
298
|
+
local key = source .. ':' .. ids[1] .. ':' .. emit.site.line
|
|
299
|
+
if not seen[key] then
|
|
300
|
+
if C.stats.links >= M.MAX_TARGETS then incomplete('target_limit'); buses[owner.key] = {}; return {} end
|
|
301
|
+
seen[key] = true; C.stats.links = C.stats.links + 1
|
|
302
|
+
out[#out + 1] = { source = source, target = ids[1], line = emit.site.line,
|
|
303
|
+
kind = 'automatic:event', site = emit.site, registered_at = G.files[reg.file].path .. ':' .. reg.site.line }
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
end end
|
|
308
|
+
return out
|
|
309
|
+
end
|
|
310
|
+
local function edges_for(f, site)
|
|
311
|
+
local owner = descriptor(f, site.entity, {}, 0)
|
|
312
|
+
return owner and load_bus(owner) or {}
|
|
313
|
+
end
|
|
314
|
+
local function publish(edge)
|
|
315
|
+
if report then report:add({ source = edge.source, target = edge.target, line = edge.line,
|
|
316
|
+
call = edge.site.entity.name .. '.emit', kind = 'possible event delivery (shared imported Node EventEmitter and literal event)',
|
|
317
|
+
registered_at = edge.registered_at }) end
|
|
318
|
+
end
|
|
319
|
+
function C.outgoing(id)
|
|
320
|
+
local f, out, seen = G.node_file[id], {}, {}
|
|
321
|
+
if not has(G.files[f], 1) or not emits(f)[id] then return out end
|
|
322
|
+
local d = data(f)
|
|
323
|
+
for _, site in ipairs(d and d.sites or {}) do
|
|
324
|
+
if site.method == 'emit' and G.id_of[f][site.from] == id then
|
|
325
|
+
for _, edge in ipairs(edges_for(f, site)) do
|
|
326
|
+
if edge.source == id and edge.site == site and not seen[edge] then seen[edge] = true; out[#out + 1] = edge; publish(edge) end
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
end
|
|
330
|
+
return out
|
|
331
|
+
end
|
|
332
|
+
function C.incoming(wanted)
|
|
333
|
+
local related, out, seen = ctx.ordinary.candidates(wanted), {}, {}
|
|
334
|
+
for _, f in ipairs(files()) do if related[f] and has(G.files[f], 2) then
|
|
335
|
+
local d = data(f)
|
|
336
|
+
for _, site in ipairs(d and d.sites or {}) do if site.handler then
|
|
337
|
+
local ids, relevant = handler(f, site.handler), false
|
|
338
|
+
for _, id in ipairs(ids) do if wanted[id] then relevant = true end end
|
|
339
|
+
if relevant then for _, edge in ipairs(edges_for(f, site)) do
|
|
340
|
+
if wanted[edge.target] and not seen[edge] then
|
|
341
|
+
seen[edge] = true; out[edge.source] = out[edge.source] or {}; out[edge.source][#out[edge.source] + 1] = edge; publish(edge)
|
|
342
|
+
end
|
|
343
|
+
end end
|
|
344
|
+
end end
|
|
345
|
+
end end
|
|
346
|
+
return out
|
|
347
|
+
end
|
|
348
|
+
function C.definition(f, offset, line)
|
|
349
|
+
if not has(G.files[f], 1) then return {} end
|
|
350
|
+
if line then
|
|
351
|
+
local found, refs = false, G.files[f].refs
|
|
352
|
+
for i, name in ipairs(refs.name) do if name == 'emit' and refs.line[i] == line then found = true; break end end
|
|
353
|
+
if not found then return {} end
|
|
354
|
+
end
|
|
355
|
+
local d, out, seen, recognized = data(f), {}, {}, false
|
|
356
|
+
for _, site in ipairs(d and d.sites or {}) do
|
|
357
|
+
if site.method == 'emit' and site.first <= offset and offset < site.last and site.from > 0 then
|
|
358
|
+
recognized = true
|
|
359
|
+
for _, edge in ipairs(C.outgoing(G.id_of[f][site.from])) do
|
|
360
|
+
if edge.site == site and not seen[edge.target] then seen[edge.target] = true; out[#out + 1] = edge.target end
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
return out, recognized
|
|
365
|
+
end
|
|
366
|
+
return C
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
return M
|