@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,93 @@
|
|
|
1
|
+
-- Explicit unknown-suffix files live in a bounded query overlay, never in idx.
|
|
2
|
+
local M = { MAX_FILES = 4, MAX_BYTES = 2 * 1048576, MAX_PROBES = 16 }
|
|
3
|
+
local graph = require('codeoutline.graph')
|
|
4
|
+
local parse = require('codeoutline.parse')
|
|
5
|
+
local documents = require('codeoutline.documents')
|
|
6
|
+
local paths = require('codeoutline.path')
|
|
7
|
+
local control = require('codeoutline.control')
|
|
8
|
+
|
|
9
|
+
local function fork(G)
|
|
10
|
+
local V = setmetatable({}, { __index = G })
|
|
11
|
+
for _, key in ipairs({ 'files', 'file_index', 'file_dir', 'dir_ids', 'nodes', 'node_file', 'id_of', 'children' }) do
|
|
12
|
+
V[key] = setmetatable({}, { __index = G[key] })
|
|
13
|
+
end
|
|
14
|
+
for _, key in ipairs({ 'by_name', 'by_lname', 'by_qualified', 'by_owner', 'by_base', 'by_stem',
|
|
15
|
+
'pkg_files', 'dir_files', 'dir_by_base', 'ns_files' }) do
|
|
16
|
+
local base = G[key]
|
|
17
|
+
V[key] = setmetatable({}, { __index = function(t, name)
|
|
18
|
+
local old = base[name]
|
|
19
|
+
if not old then return nil end
|
|
20
|
+
local list = {}; for i, value in ipairs(old) do list[i] = value end
|
|
21
|
+
rawset(t, name, list); return list
|
|
22
|
+
end })
|
|
23
|
+
end
|
|
24
|
+
V.file_order = {}
|
|
25
|
+
for i, f in ipairs(G.file_order) do
|
|
26
|
+
if i % 4096 == 0 then control.check() end
|
|
27
|
+
V.file_order[i] = f
|
|
28
|
+
end
|
|
29
|
+
V.query_base_names = G.by_name
|
|
30
|
+
return V
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
function M.open(G, idx, query)
|
|
34
|
+
local result = { files = {}, rejected = {}, truncated = false }
|
|
35
|
+
local candidates, seen = {}, {}
|
|
36
|
+
local function add(value)
|
|
37
|
+
value = value:gsub('^path:', ''):gsub('[,;?]+$', ''):gsub('\\', '/')
|
|
38
|
+
if value:match('%.[%w_]+$') and not parse.language(value) and not seen[value] then
|
|
39
|
+
seen[value] = true; candidates[#candidates + 1] = value
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
for value in query:gmatch('"([^"]+)"') do add(value) end
|
|
43
|
+
for value in query:gsub('"[^"]+"', ''):gmatch('%S+') do add(value) end
|
|
44
|
+
local records, sources, V, bytes = {}, {}, nil, 0
|
|
45
|
+
for i, written in ipairs(candidates) do
|
|
46
|
+
if i > M.MAX_PROBES then result.truncated = true; break end
|
|
47
|
+
control.check()
|
|
48
|
+
local full = written:match('^%a:/') or written:sub(1, 1) == '/' and written
|
|
49
|
+
full = full and written or idx.root .. '/' .. written
|
|
50
|
+
local real = xutils.realpath(full)
|
|
51
|
+
real = real and paths.normalize(real)
|
|
52
|
+
if real and paths.contains(idx.root, real) then
|
|
53
|
+
local rel = real:sub(#idx.root + 2)
|
|
54
|
+
local stat = xutils.stat(real)
|
|
55
|
+
if not G.file_index[rel] and not records[rel] and stat and stat.type == 'file' then
|
|
56
|
+
if #result.files >= M.MAX_FILES or stat.size > 1048576 or bytes + stat.size > M.MAX_BYTES then
|
|
57
|
+
result.truncated = true
|
|
58
|
+
else
|
|
59
|
+
local doc = documents.read(real)
|
|
60
|
+
local filters = require('codeoutline.query_filters').parse(query)
|
|
61
|
+
local hint = #filters.languages == 1 and filters.languages[1] or nil
|
|
62
|
+
local rec = doc and parse.parse(rel, doc.source, { detect = true, language = hint, ordinary_bindings = true })
|
|
63
|
+
if rec then
|
|
64
|
+
-- Validate the raw file when the result is rendered too.
|
|
65
|
+
local file = assert(io.open(real, 'rb')); local raw = file:read(1048577); file:close()
|
|
66
|
+
assert(#raw <= 1048576 and bytes + #raw <= M.MAX_BYTES, 'source grew beyond query limits: ' .. rel)
|
|
67
|
+
local current = assert(documents.read(real))
|
|
68
|
+
assert(current.source == doc.source, 'source changed during query; retry: ' .. rel)
|
|
69
|
+
rec.size = #raw
|
|
70
|
+
if rec.language_source == 'editor' then rec.language_source = 'query' end
|
|
71
|
+
rec.crc = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
|
|
72
|
+
records[rel], sources[rel], bytes = rec, doc.source, bytes + #raw
|
|
73
|
+
V = V or fork(G)
|
|
74
|
+
graph.add_file(V, rel, rec)
|
|
75
|
+
result.files[#result.files + 1] = { path = rel, language = rec.language, basis = rec.language_source }
|
|
76
|
+
else result.rejected[#result.rejected + 1] = { path = rel, reason = 'language not confidently identified' } end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
if not V then return G, idx, result end
|
|
82
|
+
local transient = setmetatable({ root = idx.root }, { __index = idx })
|
|
83
|
+
function transient:query_source(rel)
|
|
84
|
+
if records[rel] then
|
|
85
|
+
assert(documents.read(idx.root .. '/' .. rel, records[rel]), 'cannot read source: ' .. rel)
|
|
86
|
+
return sources[rel], false
|
|
87
|
+
end
|
|
88
|
+
return idx:query_source(rel)
|
|
89
|
+
end
|
|
90
|
+
return V, transient, result
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
return M
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
-- Ordinary binding evidence belongs to one query, never to the resident index.
|
|
2
|
+
local M = {}
|
|
3
|
+
local control = require('codeoutline.control')
|
|
4
|
+
local function js(rec) return rec.language == 'javascript' or rec.language == 'typescript' or rec.language == 'arkts' end
|
|
5
|
+
local function evidence(rec, i)
|
|
6
|
+
local refs = rec.refs
|
|
7
|
+
return refs.binding and refs.binding[i] or refs.lua_binding and refs.lua_binding[i]
|
|
8
|
+
or refs.js_receiver and refs.js_receiver[i]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
function M.context(G, ctx, source, options)
|
|
12
|
+
options = options or {}
|
|
13
|
+
local storage = options.cache or { entries = {}, order = {}, bytes = 0 }
|
|
14
|
+
local cache, order = storage.entries, storage.order
|
|
15
|
+
local validated = {}
|
|
16
|
+
local max_files, max_bytes = options.max_files or 16, options.max_bytes or 8 * 1024 * 1024
|
|
17
|
+
while #order > 0 and (#order > max_files or storage.bytes > max_bytes) do
|
|
18
|
+
local old = table.remove(order, 1); storage.bytes = storage.bytes - cache[old].weight; cache[old] = nil
|
|
19
|
+
end
|
|
20
|
+
local C = { stats = { parses = 0, files = 0, bytes = 0, alias_files = 0, alias_bytes = 0 } }
|
|
21
|
+
-- A query may visit more headers than the shared full-evidence FIFO holds.
|
|
22
|
+
-- Retain only their small, validated alias lists for this query, so looking
|
|
23
|
+
-- up another name does not repeatedly parse the same evicted headers.
|
|
24
|
+
local query_aliases = {}
|
|
25
|
+
local max_alias_files, max_alias_bytes = options.max_alias_files or 256, options.max_alias_bytes or 1048576
|
|
26
|
+
local function alias_list(rec, list)
|
|
27
|
+
list = list or {}
|
|
28
|
+
if not query_aliases[rec.nodes] then
|
|
29
|
+
local weight = 64 + #list * 128
|
|
30
|
+
for _, alias in ipairs(list) do
|
|
31
|
+
weight = weight + #(alias.name or '') + #(alias.target or '') + #(alias.scope or '')
|
|
32
|
+
end
|
|
33
|
+
if C.stats.alias_files < max_alias_files and C.stats.alias_bytes + weight <= max_alias_bytes then
|
|
34
|
+
query_aliases[rec.nodes] = list
|
|
35
|
+
C.stats.alias_files, C.stats.alias_bytes = C.stats.alias_files + 1, C.stats.alias_bytes + weight
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
return list
|
|
39
|
+
end
|
|
40
|
+
function C.available(f)
|
|
41
|
+
local rec = G.files[f]
|
|
42
|
+
return rec.ordinary_bindings or rec.size ~= nil or source ~= nil
|
|
43
|
+
end
|
|
44
|
+
function C.source_size(f)
|
|
45
|
+
local draft = source and source(f)
|
|
46
|
+
return draft and #draft or G.files[f].size
|
|
47
|
+
end
|
|
48
|
+
local hints = {}
|
|
49
|
+
local function alias_hints(f)
|
|
50
|
+
if hints[f] and hints[f].record == G.files[f] then return hints[f].roots end
|
|
51
|
+
local result = {}
|
|
52
|
+
for _, name in ipairs(G.files[f].dispatch_calls or {}) do
|
|
53
|
+
if name:sub(1, 1) == '@' then result[name:sub(2):match('^([%w_$]+)')] = true end
|
|
54
|
+
end
|
|
55
|
+
hints[f] = { record = G.files[f], roots = result }
|
|
56
|
+
return result
|
|
57
|
+
end
|
|
58
|
+
local function read_source(f)
|
|
59
|
+
local rec = G.files[f]
|
|
60
|
+
control.check()
|
|
61
|
+
local raw = source and source(f)
|
|
62
|
+
if not raw then
|
|
63
|
+
local file = assert(io.open(G.root .. '/' .. rec.path, 'rb'), 'cannot read binding source: ' .. rec.path)
|
|
64
|
+
raw = file:read('a'); file:close()
|
|
65
|
+
local crc = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
|
|
66
|
+
assert(#raw == rec.size and crc == rec.crc, 'source changed during query; retry: ' .. rec.path)
|
|
67
|
+
if rec.encoding ~= 'utf-8' and rec.encoding ~= 'utf-8-bom' then
|
|
68
|
+
raw = assert(xutils.to_utf8(raw, rec.encoding == 'gbk' and 'gbk' or 'auto'))
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
return raw
|
|
72
|
+
end
|
|
73
|
+
local function cached_data(rec, raw)
|
|
74
|
+
local key, entry = rec.nodes, cache[rec.nodes]
|
|
75
|
+
if not entry then return nil end
|
|
76
|
+
if not validated[key] then
|
|
77
|
+
if not raw then return nil end
|
|
78
|
+
local checksum = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
|
|
79
|
+
if entry.checksum ~= checksum or entry.size ~= #raw or entry.language ~= rec.language then return nil end
|
|
80
|
+
validated[key] = true
|
|
81
|
+
end
|
|
82
|
+
C.stats.files, C.stats.bytes = #order, storage.bytes
|
|
83
|
+
return entry.data
|
|
84
|
+
end
|
|
85
|
+
local function remember(rec, raw, data, weight)
|
|
86
|
+
local key = rec.nodes
|
|
87
|
+
if cache[key] then
|
|
88
|
+
storage.bytes = storage.bytes - cache[key].weight; cache[key] = nil
|
|
89
|
+
for i, old in ipairs(order) do if old == key then table.remove(order, i); break end end
|
|
90
|
+
end
|
|
91
|
+
while #order > 0 and (#order >= max_files or storage.bytes + weight > max_bytes) do
|
|
92
|
+
local old = table.remove(order, 1); storage.bytes = storage.bytes - cache[old].weight; cache[old] = nil
|
|
93
|
+
end
|
|
94
|
+
if weight <= max_bytes then
|
|
95
|
+
local checksum = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
|
|
96
|
+
cache[key] = { data = data, weight = weight, checksum = checksum, size = #raw, language = rec.language }
|
|
97
|
+
order[#order + 1] = key; storage.bytes = storage.bytes + weight; validated[key] = true
|
|
98
|
+
end
|
|
99
|
+
C.stats.parses, C.stats.files, C.stats.bytes = C.stats.parses + 1, #order, storage.bytes
|
|
100
|
+
return data
|
|
101
|
+
end
|
|
102
|
+
function C.cpp_aliases(f)
|
|
103
|
+
local rec = G.files[f]
|
|
104
|
+
if rec.ordinary_bindings or not G.root and not source then return rec.cpp_aliases or {} end
|
|
105
|
+
local cached = cached_data(rec)
|
|
106
|
+
if cached then return alias_list(rec, cached.cpp_aliases) end
|
|
107
|
+
if query_aliases[rec.nodes] then return query_aliases[rec.nodes] end
|
|
108
|
+
local raw = read_source(f)
|
|
109
|
+
cached = cached_data(rec, raw)
|
|
110
|
+
if cached then return alias_list(rec, cached.cpp_aliases) end
|
|
111
|
+
local parsed = assert(require('codeoutline.parse').parse(rec.path, raw,
|
|
112
|
+
{ ranges = false, omit_signatures = true, cpp_aliases_only = true, language = rec.language }))
|
|
113
|
+
assert(#parsed.nodes == #rec.nodes, 'source changed; refresh index before alias query: ' .. rec.path)
|
|
114
|
+
for i, n in ipairs(parsed.nodes) do
|
|
115
|
+
assert(n.qualified == rec.nodes[i].qualified and n.line == rec.nodes[i].line,
|
|
116
|
+
'source changed; refresh index before alias query: ' .. rec.path)
|
|
117
|
+
end
|
|
118
|
+
local data = remember(rec, raw, { cpp_aliases = parsed.cpp_aliases, cpp_aliases_only = true },
|
|
119
|
+
#raw + #(parsed.cpp_aliases or {}) * 256)
|
|
120
|
+
return alias_list(rec, data.cpp_aliases)
|
|
121
|
+
end
|
|
122
|
+
function C.macros(f)
|
|
123
|
+
local rec = G.files[f]
|
|
124
|
+
if rec.cpp_macros then return rec.cpp_macros end
|
|
125
|
+
local cached = cached_data(rec)
|
|
126
|
+
if cached and not cached.cpp_aliases_only then return cached.cpp_macros end
|
|
127
|
+
if not G.root and not source then return nil end
|
|
128
|
+
local raw = read_source(f)
|
|
129
|
+
cached = cached_data(rec, raw)
|
|
130
|
+
if cached and not cached.cpp_aliases_only then return cached.cpp_macros end
|
|
131
|
+
-- Macro visibility needs directive events, not a second syntax tree,
|
|
132
|
+
-- receiver bindings or implementation evidence for the whole header.
|
|
133
|
+
return require('codeoutline.cpp_macros').summary(rec, raw)
|
|
134
|
+
end
|
|
135
|
+
-- Inheritance queries need class headers and aliases, not every call,
|
|
136
|
+
-- receiver, type-use site and method signature in the file.
|
|
137
|
+
function C.hierarchy(f)
|
|
138
|
+
local rec = G.files[f]
|
|
139
|
+
if rec.language ~= 'cpp' or rec.ordinary_bindings or not G.root and not source then return C.data(f) end
|
|
140
|
+
local cached = cached_data(rec)
|
|
141
|
+
if cached and (not cached.cpp_aliases_only or cached.implementation_evidence) then return cached end
|
|
142
|
+
local raw = read_source(f)
|
|
143
|
+
cached = cached_data(rec, raw)
|
|
144
|
+
if cached and (not cached.cpp_aliases_only or cached.implementation_evidence) then return cached end
|
|
145
|
+
local parsed, T = require('codeoutline.parse').parse_tokens(rec.path, raw,
|
|
146
|
+
{ ranges = false, cpp_aliases_only = true, language = rec.language })
|
|
147
|
+
local function check(ok) assert(ok, 'source changed; refresh index before hierarchy query: ' .. rec.path) end
|
|
148
|
+
check(parsed and #parsed.nodes == #rec.nodes)
|
|
149
|
+
local evidence, count = {}, 0
|
|
150
|
+
for i, n in ipairs(parsed.nodes) do
|
|
151
|
+
if i % 128 == 0 then control.check() end
|
|
152
|
+
check(n.qualified == rec.nodes[i].qualified and n.line == rec.nodes[i].line)
|
|
153
|
+
if n.kind == 'class' or n.kind == 'struct' then
|
|
154
|
+
evidence[i] = { at = T.s[n.ti] - 1,
|
|
155
|
+
hierarchy_bases = require('codeoutline.type_bases').collect(T, n, rec.language) }
|
|
156
|
+
count = count + 1
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
return remember(rec, raw, { cpp_aliases = parsed.cpp_aliases, cpp_aliases_only = true,
|
|
160
|
+
implementation_evidence = evidence }, #raw + count * 256 + #(parsed.cpp_aliases or {}) * 256)
|
|
161
|
+
end
|
|
162
|
+
function C.data(f)
|
|
163
|
+
local rec = G.files[f]
|
|
164
|
+
if rec.ordinary_bindings then return rec end -- explicit in-memory parse
|
|
165
|
+
local cached = cached_data(rec)
|
|
166
|
+
if cached and not cached.cpp_aliases_only then return cached end
|
|
167
|
+
if not G.root and not source then return rec end
|
|
168
|
+
local raw = read_source(f)
|
|
169
|
+
cached = cached_data(rec, raw)
|
|
170
|
+
if cached and not cached.cpp_aliases_only then return cached end
|
|
171
|
+
local parsed = options.parsed and options.parsed(f)
|
|
172
|
+
parsed = parsed or assert(require('codeoutline.parse').parse(rec.path, raw,
|
|
173
|
+
{ ranges = false, ordinary_bindings = true, language = rec.language }))
|
|
174
|
+
local function check(ok) assert(ok, 'source changed; refresh index before binding query: ' .. rec.path) end
|
|
175
|
+
check(#parsed.nodes == #rec.nodes and #parsed.refs.name == #rec.refs.name)
|
|
176
|
+
for i, n in ipairs(parsed.nodes) do
|
|
177
|
+
check(n.qualified == rec.nodes[i].qualified and n.line == rec.nodes[i].line)
|
|
178
|
+
end
|
|
179
|
+
for i, name in ipairs(parsed.refs.name) do
|
|
180
|
+
check(name == rec.refs.name[i] and parsed.refs.from[i] == rec.refs.from[i]
|
|
181
|
+
and parsed.refs.line[i] == rec.refs.line[i] and parsed.refs.kind[i] == rec.refs.kind[i])
|
|
182
|
+
end
|
|
183
|
+
-- Keep only compact query evidence; source, tokens, and duplicate symbols die here.
|
|
184
|
+
local data = { refs = { binding = parsed.refs.binding, js_receiver = parsed.refs.js_receiver, lua_binding = parsed.refs.lua_binding },
|
|
185
|
+
js_exports = parsed.js_exports, python_imports = parsed.python_imports, cpp_aliases = parsed.cpp_aliases,
|
|
186
|
+
csharp_usings = parsed.csharp_usings, csharp_statics = parsed.csharp_statics,
|
|
187
|
+
csharp_scopes = parsed.csharp_scopes, csharp_parameters = parsed.csharp_parameters, csharp_access = parsed.csharp_access }
|
|
188
|
+
data.implementation_evidence = parsed.implementation_evidence
|
|
189
|
+
data.lua_locals = parsed.lua_locals
|
|
190
|
+
data.static_dispatch = parsed.static_dispatch
|
|
191
|
+
data.type_sites, data.type_parameters = parsed.type_sites, parsed.type_parameters
|
|
192
|
+
data.type_exclusions = parsed.type_exclusions
|
|
193
|
+
data.go_methods = parsed.go_methods
|
|
194
|
+
data.cpp_receivers = parsed.cpp_receivers
|
|
195
|
+
data.cpp_macros = parsed.cpp_macros
|
|
196
|
+
data.automatic_events = parsed.automatic_events
|
|
197
|
+
data.shared_events = parsed.shared_events
|
|
198
|
+
data.lua_callback_loops = parsed.lua_callback_loops
|
|
199
|
+
data.rust_imports, data.rust_public = parsed.rust_imports, parsed.rust_public
|
|
200
|
+
local type_count = 0; for _ in pairs(parsed.type_sites or {}) do type_count = type_count + 1 end
|
|
201
|
+
local static_count = 0
|
|
202
|
+
for _, site in ipairs(parsed.static_dispatch and parsed.static_dispatch.sites or {}) do
|
|
203
|
+
static_count = static_count + 1 + #site.registrations
|
|
204
|
+
end
|
|
205
|
+
local weight = #raw + #parsed.refs.name * 128 + #(parsed.js_exports or {}) * 256
|
|
206
|
+
+ type_count * 256 + #(parsed.type_parameters or {}) * 96
|
|
207
|
+
+ static_count * 256
|
|
208
|
+
+ #(parsed.lua_locals or {}) * 256
|
|
209
|
+
+ #(parsed.python_imports or {}) * 256 + #(parsed.cpp_aliases or {}) * 256
|
|
210
|
+
+ #(parsed.csharp_usings or {}) * 256 + #(parsed.csharp_scopes or {}) * 256
|
|
211
|
+
+ #(parsed.csharp_parameters or {}) * 128 + #parsed.nodes * (parsed.implementation_evidence and 256 or 0)
|
|
212
|
+
+ #(parsed.rust_imports or {}) * 256 + #(parsed.rust_public or {}) * 32
|
|
213
|
+
+ #(parsed.cpp_macros or {}) * 256
|
|
214
|
+
+ (parsed.go_methods and (#parsed.nodes * 384 + #parsed.go_methods.bindings * 256
|
|
215
|
+
+ (parsed.go_methods.receiver_weight or 0)) or 0)
|
|
216
|
+
+ (parsed.cpp_receivers and parsed.cpp_receivers.weight or 0)
|
|
217
|
+
+ #(parsed.automatic_events or {}) * 512
|
|
218
|
+
+ (parsed.shared_events and parsed.shared_events.weight or 0)
|
|
219
|
+
+ (parsed.lua_callback_loops and parsed.lua_callback_loops.weight or 0)
|
|
220
|
+
return remember(rec, raw, data, weight)
|
|
221
|
+
end
|
|
222
|
+
function C.evidence(f, i)
|
|
223
|
+
local rec = G.files[f]
|
|
224
|
+
local value = evidence(rec, i)
|
|
225
|
+
if rec.language == 'go' and not C.available(f) then return value end
|
|
226
|
+
if rec.language == 'go' then
|
|
227
|
+
local data = require('codeoutline.go_methods').context(G, ctx).data(f)
|
|
228
|
+
if not data then return 'go:?' end
|
|
229
|
+
return data.evidence[i] or value
|
|
230
|
+
end
|
|
231
|
+
local kind = rec.refs.kind[i]
|
|
232
|
+
if kind ~= 'call' and kind ~= 'member_call' and not (rec.language == 'csharp' and kind == 'new')
|
|
233
|
+
and kind ~= 'ref' then return value end
|
|
234
|
+
if rec.language == 'lua' then
|
|
235
|
+
if rec.refs.lua_binding then return value end
|
|
236
|
+
local wanted = rec.refs.recv[i] or rec.refs.name[i]
|
|
237
|
+
for _, imp in ipairs(rec.lua_imports or {}) do
|
|
238
|
+
if imp.member == rec.refs.name[i] then return evidence(C.data(f), i) or value end
|
|
239
|
+
end
|
|
240
|
+
for _, name in ipairs(rec.lua_binding_names or {}) do
|
|
241
|
+
if name == wanted then return evidence(C.data(f), i) or value end
|
|
242
|
+
end
|
|
243
|
+
return value
|
|
244
|
+
end
|
|
245
|
+
-- Explicit in-memory parses may already carry receiver evidence. Base
|
|
246
|
+
-- index records keep only imports/exports; their barriers are lazy.
|
|
247
|
+
if js(rec) and rec.refs.js_receiver then
|
|
248
|
+
if kind ~= 'ref' and (kind ~= 'call' or value ~= '?') then return value end
|
|
249
|
+
if kind ~= 'ref' and not next(alias_hints(f)) then return value end
|
|
250
|
+
end
|
|
251
|
+
local recv = rec.refs.recv[i]
|
|
252
|
+
if (rec.language == 'c' or rec.language == 'cpp') and kind == 'member_call' and not recv then
|
|
253
|
+
local data = require('codeoutline.cpp_receivers').context(G, ctx).data(f)
|
|
254
|
+
if not data then return value end
|
|
255
|
+
return data.evidence[i] or value
|
|
256
|
+
end
|
|
257
|
+
if rec.language == 'c' and kind == 'member_call' then return evidence(C.data(f), i) or value end
|
|
258
|
+
if rec.language == 'python' and (recv == 'self' or recv == 'cls') then return value end
|
|
259
|
+
if rec.language == 'cpp' and recv == 'this' then return value end
|
|
260
|
+
if rec.language == 'rust' and require('codeoutline.rust_packages').owner(G, f, ctx) then
|
|
261
|
+
return require('codeoutline.rust_packages').guard(ctx, function() return evidence(C.data(f), i) or value end) or value
|
|
262
|
+
end
|
|
263
|
+
if js(rec) or rec.language == 'python' or rec.language == 'csharp' or rec.language == 'cpp'
|
|
264
|
+
or (rec.language == 'java' or rec.language == 'kotlin') and (kind == 'member_call' or kind == 'ref') then
|
|
265
|
+
return evidence(C.data(f), i) or value
|
|
266
|
+
end
|
|
267
|
+
return value
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
-- Renamed calls can only originate in the target file or an import chain
|
|
271
|
+
-- leading to it. Build this cheap reverse map from existing import records.
|
|
272
|
+
-- No indexed source is opened; workspace lookup may read package manifests.
|
|
273
|
+
local reverse
|
|
274
|
+
function C.candidates(wanted)
|
|
275
|
+
local found, queue = {}, {}
|
|
276
|
+
for id in pairs(wanted) do
|
|
277
|
+
local f = G.node_file[id]
|
|
278
|
+
if (js(G.files[f]) or G.files[f].language == 'python') and not found[f] then
|
|
279
|
+
found[f] = true; queue[#queue + 1] = f
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
if #queue == 0 then return found end
|
|
283
|
+
if not reverse then
|
|
284
|
+
reverse = {}
|
|
285
|
+
local function add(f, target)
|
|
286
|
+
if target then reverse[target] = reverse[target] or {}; reverse[target][f] = true end
|
|
287
|
+
end
|
|
288
|
+
local files = {}
|
|
289
|
+
for _, f in ipairs(G.file_order) do files[#files + 1] = f end
|
|
290
|
+
for _, f in ipairs(G.new_files or {}) do files[#files + 1] = f end
|
|
291
|
+
for _, f in ipairs(files) do
|
|
292
|
+
local rec = G.files[f]
|
|
293
|
+
control.check()
|
|
294
|
+
if js(rec) then
|
|
295
|
+
for _, imp in ipairs(rec.imports) do add(f, require('codeoutline.js_resolution').module(G, f, imp.path, ctx, imp.kind)) end
|
|
296
|
+
elseif rec.language == 'python' then
|
|
297
|
+
local module = require('codeoutline.python_bindings').module
|
|
298
|
+
for _, imp in ipairs(rec.imports) do
|
|
299
|
+
add(f, module(G, f, imp.path))
|
|
300
|
+
for _, name in ipairs(imp.names or {}) do
|
|
301
|
+
local path = imp.path
|
|
302
|
+
if path:sub(-1) ~= '.' then path = path .. '.' end
|
|
303
|
+
add(f, module(G, f, path .. name))
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
local at = 1
|
|
310
|
+
while at <= #queue do
|
|
311
|
+
control.check()
|
|
312
|
+
for f in pairs(reverse[queue[at]] or {}) do
|
|
313
|
+
if not found[f] then found[f] = true; queue[#queue + 1] = f end
|
|
314
|
+
end
|
|
315
|
+
at = at + 1
|
|
316
|
+
end
|
|
317
|
+
return found
|
|
318
|
+
end
|
|
319
|
+
function C.aliases(f, wanted, candidates)
|
|
320
|
+
if G.files[f].language == 'csharp' then
|
|
321
|
+
return require('codeoutline.csharp_bindings').incoming_aliases(G, f, wanted, ctx)
|
|
322
|
+
end
|
|
323
|
+
if not candidates[f] then return {} end
|
|
324
|
+
local rec, hits, resolved = G.files[f], {}, {}
|
|
325
|
+
local imports = {}
|
|
326
|
+
local relevant = false
|
|
327
|
+
for id in pairs(wanted) do if G.node_file[id] == f then relevant = true; break end end
|
|
328
|
+
local function matches(ids)
|
|
329
|
+
for _, id in ipairs(ids) do if wanted[id] then return true end end
|
|
330
|
+
return false
|
|
331
|
+
end
|
|
332
|
+
if js(rec) then
|
|
333
|
+
local resolver = require('codeoutline.js_resolution')
|
|
334
|
+
for _, imp in ipairs(rec.js_imports or {}) do
|
|
335
|
+
local target = resolver.module(G, f, imp.path, ctx)
|
|
336
|
+
if target and candidates[target] and (imp.imported == '*'
|
|
337
|
+
or matches(resolver.imported(G, f, imp.path, imp.imported, ctx))) then
|
|
338
|
+
relevant = true; imports[imp.local_name] = true
|
|
339
|
+
end
|
|
340
|
+
end
|
|
341
|
+
elseif not relevant and rec.language == 'python' then
|
|
342
|
+
local resolver = require('codeoutline.python_bindings')
|
|
343
|
+
for _, imp in ipairs(rec.imports) do
|
|
344
|
+
local target = resolver.module(G, f, imp.path)
|
|
345
|
+
if target and candidates[target] then
|
|
346
|
+
if not imp.names then relevant = true; break end
|
|
347
|
+
for _, name in ipairs(imp.names) do
|
|
348
|
+
if matches(resolver.imported(G, f, imp.path, name, ctx)) then relevant = true; break end
|
|
349
|
+
local path = imp.path .. (imp.path:sub(-1) == '.' and '' or '.') .. name
|
|
350
|
+
local sub = resolver.module(G, f, path)
|
|
351
|
+
if sub and candidates[sub] then relevant = true; break end
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
if relevant then break end
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
if not relevant then return hits end
|
|
358
|
+
local analyze = not js(rec)
|
|
359
|
+
if js(rec) then
|
|
360
|
+
local roots = alias_hints(f)
|
|
361
|
+
for id in pairs(wanted) do
|
|
362
|
+
if G.node_file[id] == f and roots[G.nodes[id].name] then analyze = true; break end
|
|
363
|
+
end
|
|
364
|
+
for name in pairs(imports) do if roots[name] then analyze = true; break end end
|
|
365
|
+
end
|
|
366
|
+
for i, kind in ipairs(rec.refs.kind) do
|
|
367
|
+
if kind == 'call' or kind == 'member_call' or kind == 'ref' or imports[rec.refs.name[i]] or imports[rec.refs.recv[i]] then
|
|
368
|
+
local value = (analyze or kind == 'ref') and C.evidence(f, i) or evidence(rec, i)
|
|
369
|
+
local path = value and (value:match('^import:(.-)%z') or value:match('^py:import:(.-)%z'))
|
|
370
|
+
if path then
|
|
371
|
+
local resolver = js(rec) and require('codeoutline.js_resolution') or require('codeoutline.python_bindings')
|
|
372
|
+
local target = resolver.module(G, f, path, ctx)
|
|
373
|
+
if not target or not candidates[target] then goto next_ref end
|
|
374
|
+
end
|
|
375
|
+
if value and (value:match('^node:') or value:match('^import:') or value:match('^py:'))
|
|
376
|
+
or imports[rec.refs.name[i]] or imports[rec.refs.recv[i]] then
|
|
377
|
+
if value == '' then value = nil end
|
|
378
|
+
local key = value or rec.refs.name[i] .. '\0' .. (rec.refs.recv[i] or '')
|
|
379
|
+
local targets = resolved[key]
|
|
380
|
+
if not targets then
|
|
381
|
+
if js(rec) then targets = require('codeoutline.js_resolution').resolve(G, f,
|
|
382
|
+
rec.refs.name[i], kind, rec.refs.recv[i], value, ctx)
|
|
383
|
+
else targets = require('codeoutline.python_bindings').resolve(G, f, value, ctx) end
|
|
384
|
+
targets = targets or {}; resolved[key] = targets
|
|
385
|
+
end
|
|
386
|
+
for _, id in ipairs(targets) do if wanted[id] then hits[i] = true; break end end
|
|
387
|
+
end
|
|
388
|
+
end
|
|
389
|
+
::next_ref::
|
|
390
|
+
end
|
|
391
|
+
return hits
|
|
392
|
+
end
|
|
393
|
+
return C
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
return M
|
|
@@ -25,12 +25,13 @@ M.EXTENSIONS = {
|
|
|
25
25
|
go = 'go',
|
|
26
26
|
js = 'javascript', jsx = 'javascript', mjs = 'javascript', cjs = 'javascript',
|
|
27
27
|
ts = 'typescript', tsx = 'typescript', mts = 'typescript', cts = 'typescript',
|
|
28
|
+
ets = 'arkts',
|
|
28
29
|
cs = 'csharp',
|
|
29
30
|
rs = 'rust',
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
-- Languages sharing one parser module; the language name is passed along.
|
|
33
|
-
local MODULE = { javascript = 'js', typescript = 'js' }
|
|
34
|
+
local MODULE = { javascript = 'js', typescript = 'js', arkts = 'js' }
|
|
34
35
|
|
|
35
36
|
function M.language(path)
|
|
36
37
|
local ext = path:match('%.([%w]+)$')
|
|
@@ -40,12 +41,27 @@ end
|
|
|
40
41
|
-- Returns the record and its tokens; positions in both exclude a UTF-8 BOM.
|
|
41
42
|
function M.parse_tokens(path, src, opts)
|
|
42
43
|
local lang = M.language(path)
|
|
44
|
+
local inferred, cpp_syntax
|
|
45
|
+
if not lang and opts and (opts.language or opts.detect) then
|
|
46
|
+
lang, inferred = require('codeoutline.language_detect').resolve(src, opts.language, opts.detect)
|
|
47
|
+
end
|
|
43
48
|
if not lang then return nil end
|
|
49
|
+
if opts and opts.cpp_fragment then
|
|
50
|
+
assert(not M.language(path) and (opts.cpp_fragment == 'c' or opts.cpp_fragment == 'cpp'))
|
|
51
|
+
if src:find('\0', 1, true) then return nil end
|
|
52
|
+
local detected = require('codeoutline.language_detect').resolve(src, nil, true)
|
|
53
|
+
if detected and detected ~= 'c' and detected ~= 'cpp' then return nil end
|
|
54
|
+
cpp_syntax = not not parser('cpp').looks_cpp(src)
|
|
55
|
+
if lang == 'c' and cpp_syntax then lang = 'cpp' end
|
|
56
|
+
end
|
|
44
57
|
-- Strip a UTF-8 BOM so it is not read as part of the first token.
|
|
45
58
|
if src:sub(1, 3) == '\239\187\191' then src = src:sub(4) end
|
|
46
59
|
-- .h is shared by C and C++: sniff for C++-only syntax.
|
|
47
60
|
if lang == 'c' and path:match('%.[hH]$') and parser('cpp').looks_cpp(src) then lang = 'cpp' end
|
|
48
|
-
|
|
61
|
+
local rec, tokens = parser(MODULE[lang] or lang).parse(path, src, lang, opts)
|
|
62
|
+
if opts and opts.cpp_fragment then rec.cpp_fragment, rec.cpp_fragment_cpp = opts.cpp_fragment, cpp_syntax or nil
|
|
63
|
+
elseif inferred then rec.on_demand, rec.language_source = true, inferred end
|
|
64
|
+
return rec, tokens
|
|
49
65
|
end
|
|
50
66
|
|
|
51
67
|
-- opts.ranges=false emits compact index nodes; default parsing retains positions.
|
|
@@ -149,7 +149,7 @@ function M.run(jobs, max_bytes, on_result)
|
|
|
149
149
|
chunk, bytes = {}, 0
|
|
150
150
|
end
|
|
151
151
|
for _, j in ipairs(bucket) do
|
|
152
|
-
chunk[#chunk + 1] = { j.rel, j.abs, j.size or false, j.crc or false }
|
|
152
|
+
chunk[#chunk + 1] = { j.rel, j.abs, j.size or false, j.crc or false, j.language or false }
|
|
153
153
|
bytes = bytes + j.weight
|
|
154
154
|
if #chunk >= M.CHUNK_FILES or bytes >= M.CHUNK_BYTES then flush() end
|
|
155
155
|
end
|
|
@@ -14,7 +14,7 @@ return {
|
|
|
14
14
|
for i, f in ipairs(files) do
|
|
15
15
|
-- An abandoned pass (cancelled, failed, shutting down) skips its rest.
|
|
16
16
|
if shared:get('shutdown') or (shared:get('parse_abort') or 0) >= token then return end
|
|
17
|
-
local res = index.load_file(f[2], f[1], max_bytes, f[3] or nil, f[4] or nil)
|
|
17
|
+
local res = index.load_file(f[2], f[1], max_bytes, f[3] or nil, f[4] or nil, f[5] or nil)
|
|
18
18
|
res.rel = f[1]
|
|
19
19
|
results[i] = res
|
|
20
20
|
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
-- Explicit Python imports and lexical barriers, shared by graph and navigation.
|
|
2
|
+
-- No sys.path execution or project-wide suffix guesses.
|
|
3
|
+
local M = {}
|
|
4
|
+
local aliases = require('codeoutline.dispatch_aliases')
|
|
5
|
+
local control = require('codeoutline.control')
|
|
6
|
+
|
|
7
|
+
function M.collect(r, T)
|
|
8
|
+
if r.language ~= 'python' then return end
|
|
9
|
+
local imports = aliases.imports(r, T)
|
|
10
|
+
local expand = aliases.prepare(r, T)
|
|
11
|
+
r.python_imports = {}
|
|
12
|
+
for _, imp in ipairs(imports) do
|
|
13
|
+
local nested = false
|
|
14
|
+
for _, n in ipairs(r.nodes) do
|
|
15
|
+
if n.ti <= imp.token and imp.token <= n.tj then nested = true; break end
|
|
16
|
+
end
|
|
17
|
+
if not nested then
|
|
18
|
+
local value = expand({ symbol = imp.name }, T.n)
|
|
19
|
+
r.python_imports[#r.python_imports + 1] = {
|
|
20
|
+
name = imp.name, path = imp.path, imported = imp.imported,
|
|
21
|
+
blocked = not value or not value.import or nil,
|
|
22
|
+
}
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
for i, ref in ipairs(r.refs) do
|
|
26
|
+
if i % 128 == 0 then control.check() end
|
|
27
|
+
if (ref.kind == 'call' or ref.kind == 'member_call' or ref.kind == 'ref') and ref.recv ~= 'self' and ref.recv ~= 'cls' then
|
|
28
|
+
local symbol, first = ref.name, ref.tok
|
|
29
|
+
while T:text(first - 1) == '.' and T.k[first - 2] == 'id' do
|
|
30
|
+
symbol = T:text(first - 2) .. '.' .. symbol; first = first - 2
|
|
31
|
+
end
|
|
32
|
+
local value = expand({ symbol = symbol }, ref.tok)
|
|
33
|
+
if value == false or ref.recv and first == ref.tok then ref.binding = 'py:?'
|
|
34
|
+
elseif value and value.import then
|
|
35
|
+
ref.binding = 'py:import:' .. value.import.path .. '\0' .. value.member
|
|
36
|
+
elseif value and value.node and not ref.recv then ref.binding = 'py:node:' .. value.node end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
local function directory(path) return path:match('^(.*)/[^/]*$') or '' end
|
|
42
|
+
local function module(G, f, path)
|
|
43
|
+
local dots = path:match('^(%.+)')
|
|
44
|
+
local base = ''
|
|
45
|
+
if dots then
|
|
46
|
+
base = directory(G.files[f].path)
|
|
47
|
+
for _ = 2, #dots do
|
|
48
|
+
if base == '' then return nil end
|
|
49
|
+
base = directory(base)
|
|
50
|
+
end
|
|
51
|
+
path = path:sub(#dots + 1)
|
|
52
|
+
end
|
|
53
|
+
local rel = (base ~= '' and base .. '/' or '') .. path:gsub('%.', '/')
|
|
54
|
+
rel = rel:gsub('/$', '')
|
|
55
|
+
for _, candidate in ipairs({ rel .. '.py', rel .. '/__init__.py' }) do
|
|
56
|
+
local id = G.file_index[candidate]
|
|
57
|
+
if id then return id end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
local function exported(G, f, member, seen, depth, ctx)
|
|
62
|
+
control.check()
|
|
63
|
+
if depth > 8 then return {} end
|
|
64
|
+
local key = f .. '\0' .. member
|
|
65
|
+
if seen[key] then return {} end
|
|
66
|
+
seen[key] = true
|
|
67
|
+
local result = {}
|
|
68
|
+
for _, id in ipairs(G.id_of[f]) do
|
|
69
|
+
local node = G.nodes[id]
|
|
70
|
+
if not node.parent and node.name == member then result[#result + 1] = id end
|
|
71
|
+
end
|
|
72
|
+
if #result > 0 then return result end
|
|
73
|
+
local head, tail = member:match('^([^.]+)%.(.*)$')
|
|
74
|
+
head = head or member
|
|
75
|
+
local rec = ctx and ctx.ordinary and ctx.ordinary.data(f) or G.files[f]
|
|
76
|
+
for _, imp in ipairs(rec.python_imports or {}) do
|
|
77
|
+
if imp.name == head then
|
|
78
|
+
if imp.blocked then return {} end
|
|
79
|
+
local target = module(G, f, imp.path)
|
|
80
|
+
local want = imp.imported == '*' and (tail or '') or imp.imported .. (tail and '.' .. tail or '')
|
|
81
|
+
if target then
|
|
82
|
+
for _, id in ipairs(exported(G, target, want, seen, depth + 1, ctx)) do result[#result + 1] = id end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
-- A package may expose a submodule without re-exporting its declarations.
|
|
87
|
+
if head and tail and G.files[f].path:match('/__init__%.py$') then
|
|
88
|
+
local sub = G.file_index[directory(G.files[f].path) .. '/' .. head .. '.py']
|
|
89
|
+
or G.file_index[directory(G.files[f].path) .. '/' .. head .. '/__init__.py']
|
|
90
|
+
if sub then
|
|
91
|
+
for _, id in ipairs(exported(G, sub, tail, seen, depth + 1, ctx)) do result[#result + 1] = id end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
return result
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
function M.resolve(G, f, evidence, ctx)
|
|
98
|
+
if G.files[f].language ~= 'python' or not evidence or evidence:sub(1, 3) ~= 'py:' then return nil end
|
|
99
|
+
local node = evidence:match('^py:node:(%d+)$')
|
|
100
|
+
if node then return { G.id_of[f][tonumber(node)] } end
|
|
101
|
+
local path, member = evidence:match('^py:import:(.-)%z(.*)$')
|
|
102
|
+
if not path then return {} end
|
|
103
|
+
local target = module(G, f, path)
|
|
104
|
+
return target and exported(G, target, member, {}, 0, ctx) or {}
|
|
105
|
+
end
|
|
106
|
+
M.module = module
|
|
107
|
+
function M.imported(G, f, path, name, ctx)
|
|
108
|
+
local target = module(G, f, path)
|
|
109
|
+
return target and exported(G, target, name, {}, 0, ctx) or {}
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
return M
|