@codua/codeoutline-win32-x64 0.2.6 → 0.3.0
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 +48 -7
- package/scripts/codeoutline/completion.lua +126 -22
- package/scripts/codeoutline/coverage.lua +63 -0
- package/scripts/codeoutline/cpp_bindings.lua +46 -11
- 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 +285 -29
- package/scripts/codeoutline/definition_candidates.lua +186 -0
- package/scripts/codeoutline/dispatch_aliases.lua +10 -5
- package/scripts/codeoutline/documents.lua +22 -9
- package/scripts/codeoutline/explore.lua +243 -122
- package/scripts/codeoutline/external_headers.lua +176 -0
- package/scripts/codeoutline/foreign.lua +23 -3
- 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 +322 -67
- package/scripts/codeoutline/implementations.lua +403 -0
- package/scripts/codeoutline/index.lua +161 -28
- package/scripts/codeoutline/index_worker.lua +11 -4
- package/scripts/codeoutline/indirect.lua +4 -2
- package/scripts/codeoutline/js_evidence.lua +2 -1
- package/scripts/codeoutline/js_resolution.lua +40 -12
- package/scripts/codeoutline/js_workspace.lua +325 -0
- package/scripts/codeoutline/lang/c.lua +15 -2
- package/scripts/codeoutline/lang/cpp.lua +32 -18
- package/scripts/codeoutline/lang/csharp.lua +1 -1
- 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 +151 -47
- package/scripts/codeoutline/lua_callback_loops.lua +210 -0
- package/scripts/codeoutline/main.lua +32 -7
- package/scripts/codeoutline/mcp.lua +52 -9
- package/scripts/codeoutline/navigation.lua +351 -65
- package/scripts/codeoutline/on_demand.lua +93 -0
- package/scripts/codeoutline/ordinary_bindings.lua +210 -34
- 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 +2 -2
- package/scripts/codeoutline/query_filters.lua +65 -0
- package/scripts/codeoutline/query_report.lua +56 -19
- package/scripts/codeoutline/resolution.lua +23 -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 +46 -11
- 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 +291 -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,176 @@
|
|
|
1
|
+
-- Declaration navigation in selected external headers. Never extend the index.
|
|
2
|
+
local M = { MAX_FILES = 64, MAX_PROJECT_FILES = 128, MAX_BYTES = 4 * 1024 * 1024,
|
|
3
|
+
MAX_FILE_BYTES = 1024 * 1024, CACHE_FILES = 32, CACHE_BYTES = 8 * 1024 * 1024, TIME_MS = 500 }
|
|
4
|
+
local paths, control = require('codeoutline.path'), require('codeoutline.control')
|
|
5
|
+
local cache, order, cache_bytes, scanner = {}, {}, 0, nil
|
|
6
|
+
local function directory(file) return file:match('^(.*)/[^/]+$') end
|
|
7
|
+
local function existing(file)
|
|
8
|
+
control.check()
|
|
9
|
+
local stat = xutils.stat(file)
|
|
10
|
+
if stat and stat.type == 'file' then
|
|
11
|
+
local real = xutils.realpath(file)
|
|
12
|
+
return real and paths.normalize(real)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
local function read(file, info)
|
|
16
|
+
local stream = io.open(file, 'rb')
|
|
17
|
+
if not stream then return nil end
|
|
18
|
+
local raw = stream:read(M.MAX_FILE_BYTES + 1) or ''; stream:close()
|
|
19
|
+
info.files, info.bytes = info.files + 1, info.bytes + #raw
|
|
20
|
+
if #raw > M.MAX_FILE_BYTES or info.bytes > M.MAX_BYTES then info.truncated = true; return nil end
|
|
21
|
+
local crc = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
|
|
22
|
+
local key, entry = paths.key(file), cache[paths.key(file)]
|
|
23
|
+
if entry and entry.crc == crc and entry.size == #raw then return entry end
|
|
24
|
+
if entry then
|
|
25
|
+
cache_bytes = cache_bytes - entry.weight; cache[key] = nil
|
|
26
|
+
for i, old in ipairs(order) do if old == key then table.remove(order, i); break end end
|
|
27
|
+
end
|
|
28
|
+
local source = xutils.to_utf8(raw)
|
|
29
|
+
if not source then return nil end
|
|
30
|
+
if source:sub(1, 3) == '\239\187\191' then source = source:sub(4) end
|
|
31
|
+
if not scanner then
|
|
32
|
+
local config = {}; for k, v in pairs(require('codeoutline.lang.c').config) do config[k] = v end
|
|
33
|
+
config.pp_first_branch = false
|
|
34
|
+
scanner = require('codeoutline.xscan').lang(config)
|
|
35
|
+
end
|
|
36
|
+
local T = scanner:tokenize(source)
|
|
37
|
+
local imports = {}
|
|
38
|
+
for i = 1, T.n do
|
|
39
|
+
if i % 4096 == 0 then control.check() end
|
|
40
|
+
if T.k[i] == 'dir' then
|
|
41
|
+
local text = T:text(i)
|
|
42
|
+
local name = text:match('^#%s*include%s*[<"]([^>"]+)[>"]')
|
|
43
|
+
if name then imports[#imports + 1] = { path = name, system = text:match('^#%s*include%s*<') ~= nil } end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
entry = { file = file, source = source, imports = imports, crc = crc, size = #raw,
|
|
47
|
+
weight = #source * 2 + #imports * 128 + 256 }
|
|
48
|
+
while #order > 0 and (#order >= M.CACHE_FILES or cache_bytes + entry.weight > M.CACHE_BYTES) do
|
|
49
|
+
local old = table.remove(order, 1); cache_bytes = cache_bytes - cache[old].weight; cache[old] = nil
|
|
50
|
+
end
|
|
51
|
+
if entry.weight <= M.CACHE_BYTES then
|
|
52
|
+
cache[key] = entry; order[#order + 1] = key; cache_bytes = cache_bytes + entry.weight
|
|
53
|
+
end
|
|
54
|
+
return entry
|
|
55
|
+
end
|
|
56
|
+
local function declarations(entry, name, type_site)
|
|
57
|
+
local escaped = name:gsub('([^%w])', '%%%1')
|
|
58
|
+
if not entry.source:find('%f[%w_$]' .. escaped .. '%f[^%w_$]') then return {} end
|
|
59
|
+
if not entry.nodes then
|
|
60
|
+
local rec = require('codeoutline.parse').parse(entry.file, entry.source, { type_uses = false, analysis = false })
|
|
61
|
+
entry.nodes = rec and rec.nodes or {}
|
|
62
|
+
local weight = #entry.nodes * 256
|
|
63
|
+
if cache[paths.key(entry.file)] == entry then
|
|
64
|
+
cache_bytes, entry.weight = cache_bytes + weight, entry.weight + weight
|
|
65
|
+
while #order > 0 and cache_bytes > M.CACHE_BYTES do
|
|
66
|
+
local old = table.remove(order, 1); cache_bytes = cache_bytes - cache[old].weight; cache[old] = nil
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
local result = {}
|
|
71
|
+
for _, node in ipairs(entry.nodes) do
|
|
72
|
+
if node.name == name and node.qualified == name and not node.parent and node.name_start
|
|
73
|
+
and (type_site and require('codeoutline.type_references').kinds[node.kind]
|
|
74
|
+
or not type_site and (node.kind == 'prototype' or node.kind == 'function')) then
|
|
75
|
+
result[#result + 1] = { node = node, file = entry.file, source = entry.source,
|
|
76
|
+
declaration = node.kind == 'prototype' or node.decl == true }
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
return result
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
function M.find(G, f, site, ctx, system_directories)
|
|
83
|
+
local info = { files = 0, bytes = 0, truncated = false }
|
|
84
|
+
local type_site = site and site.kind == 'type' and site.reason == 'unresolved type'
|
|
85
|
+
and not site.recv and site.evidence and site.evidence.written == site.name
|
|
86
|
+
and not site.evidence.value_shadowed
|
|
87
|
+
if not site or site.recv or not type_site and (site.kind ~= 'call'
|
|
88
|
+
or not require('codeoutline.definition_candidates').allowed(site)) then return {}, info end
|
|
89
|
+
local includes = require('codeoutline.cpp_includes')
|
|
90
|
+
local headers, queued, projects, visited, project_queued = {}, {}, { f }, {}, { [f] = true }
|
|
91
|
+
local defaults, started = nil, xtimer.now_ms()
|
|
92
|
+
local function expired()
|
|
93
|
+
control.check()
|
|
94
|
+
if xtimer.now_ms() - started >= M.TIME_MS then info.truncated = true; return true end
|
|
95
|
+
return false
|
|
96
|
+
end
|
|
97
|
+
local function dirs(owner)
|
|
98
|
+
local policy = includes.policy(G, owner, ctx)
|
|
99
|
+
local result = {}
|
|
100
|
+
local function add_root(dir)
|
|
101
|
+
control.check()
|
|
102
|
+
local real = xutils.realpath(dir)
|
|
103
|
+
if real then result[#result + 1] = paths.normalize(real) end
|
|
104
|
+
end
|
|
105
|
+
for _, dir in ipairs(policy.paths) do add_root(dir) end
|
|
106
|
+
if not policy.configured then
|
|
107
|
+
defaults = defaults or (type(system_directories) == 'function' and system_directories() or system_directories or {})
|
|
108
|
+
for _, dir in ipairs(defaults) do add_root(dir) end
|
|
109
|
+
end
|
|
110
|
+
return result
|
|
111
|
+
end
|
|
112
|
+
local function add(file, roots)
|
|
113
|
+
if file and not paths.contains(G.root, file) and not queued[paths.key(file)] then
|
|
114
|
+
queued[paths.key(file)] = true; headers[#headers + 1] = { file = file, roots = roots }
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
local function locate(imp, roots, parent)
|
|
118
|
+
local written = imp.path:gsub('\\', '/')
|
|
119
|
+
if written:find('[%z\r\n]') or written:match('^[/\\]') or written:match('^%a:') then return end
|
|
120
|
+
if not imp.system and parent then
|
|
121
|
+
local file = existing(directory(parent) .. '/' .. written)
|
|
122
|
+
if file then
|
|
123
|
+
for _, root in ipairs(roots) do if paths.contains(root, file) then return file end end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
for _, root in ipairs(roots) do
|
|
127
|
+
local file = existing(root .. '/' .. written)
|
|
128
|
+
if file and paths.contains(root, file) then return file end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
local pi = 1
|
|
132
|
+
while pi <= #projects do
|
|
133
|
+
if expired() then return {}, info end
|
|
134
|
+
local owner = projects[pi]; pi = pi + 1
|
|
135
|
+
if not visited[owner] then
|
|
136
|
+
if pi > M.MAX_PROJECT_FILES + 1 then info.truncated = true; break end
|
|
137
|
+
visited[owner] = true
|
|
138
|
+
for _, imp in ipairs(G.files[owner].imports or {}) do
|
|
139
|
+
if owner ~= f or not site.line or imp.line <= site.line then
|
|
140
|
+
local ids, selected, file = includes.resolve(G, owner, imp, ctx)
|
|
141
|
+
for _, id in ipairs(ids) do
|
|
142
|
+
if not project_queued[id] then
|
|
143
|
+
if #projects >= M.MAX_PROJECT_FILES then info.truncated = true
|
|
144
|
+
else project_queued[id] = true; projects[#projects + 1] = id end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
if #ids == 0 then
|
|
148
|
+
local roots = dirs(owner)
|
|
149
|
+
if file then
|
|
150
|
+
file = existing(file)
|
|
151
|
+
if file and not paths.contains(G.root, file) then
|
|
152
|
+
roots[#roots + 1] = directory(file); add(file, roots)
|
|
153
|
+
end
|
|
154
|
+
elseif not selected then add(locate(imp, roots), roots) end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
local best, hi = {}, 1
|
|
161
|
+
while hi <= #headers do
|
|
162
|
+
if info.files >= M.MAX_FILES or expired() then info.truncated = true; break end
|
|
163
|
+
local target = headers[hi]; hi = hi + 1
|
|
164
|
+
local entry = read(target.file, info)
|
|
165
|
+
if entry then
|
|
166
|
+
local found = declarations(entry, site.name, type_site)
|
|
167
|
+
for _, hit in ipairs(found) do
|
|
168
|
+
if hit.declaration then return { hit }, info end
|
|
169
|
+
if #best < 8 then best[#best + 1] = hit end
|
|
170
|
+
end
|
|
171
|
+
for _, imp in ipairs(entry.imports) do add(locate(imp, target.roots, target.file), target.roots) end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
return best, info
|
|
175
|
+
end
|
|
176
|
+
return M
|
|
@@ -62,7 +62,9 @@ end
|
|
|
62
62
|
|
|
63
63
|
function M.exports(rec, language, module)
|
|
64
64
|
local exports = records[rec] or rec.foreign_exports
|
|
65
|
-
|
|
65
|
+
local modules = exports and exports[language]
|
|
66
|
+
return modules and (modules[module] or language == 'lua' and type(module) == 'string'
|
|
67
|
+
and modules[module:gsub('%.', '_')])
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
function M.collect(rec, T)
|
|
@@ -71,9 +73,11 @@ end
|
|
|
71
73
|
|
|
72
74
|
function M.modules(G, language, name, ctx)
|
|
73
75
|
ctx = ctx or {}
|
|
76
|
+
if not name then return {} end
|
|
77
|
+
local loader = language == 'lua' and name:gsub('%.', '_') or name
|
|
74
78
|
ctx.foreign = ctx.foreign or {}
|
|
75
79
|
ctx.foreign_loaded = ctx.foreign_loaded or {}
|
|
76
|
-
for _, f in ipairs(candidates(G, ctx)[
|
|
80
|
+
for _, f in ipairs(candidates(G, ctx)[loader] or {}) do
|
|
77
81
|
if not ctx.foreign_loaded[f] then
|
|
78
82
|
local exports = load(G, f)
|
|
79
83
|
-- Failed reads can be skipped within this query, but are never
|
|
@@ -89,12 +93,28 @@ function M.modules(G, language, name, ctx)
|
|
|
89
93
|
end
|
|
90
94
|
end
|
|
91
95
|
end
|
|
92
|
-
local
|
|
96
|
+
local modules = ctx.foreign[language] or {}
|
|
97
|
+
local files = modules[name] or modules[loader] or {}
|
|
93
98
|
-- A long query may have evicted a previously used record.
|
|
94
99
|
for _, f in ipairs(files) do load(G, f) end
|
|
95
100
|
return files
|
|
96
101
|
end
|
|
97
102
|
|
|
103
|
+
-- Lua's C loader replaces dots in a module name when naming the entry point.
|
|
104
|
+
-- The indexed entry alone is sufficient for navigating the require string;
|
|
105
|
+
-- member bindings still require the separately verified registration table.
|
|
106
|
+
function M.lua_entrypoints(G, name)
|
|
107
|
+
local result = {}
|
|
108
|
+
local symbol = 'luaopen_' .. name:gsub('%.', '_')
|
|
109
|
+
for _, id in ipairs(G.by_name[symbol] or {}) do
|
|
110
|
+
local node, f = G.nodes[id], G.node_file[id]
|
|
111
|
+
if node.kind == 'function' and not node.static and (G.files[f].language == 'c' or G.files[f].language == 'cpp') then
|
|
112
|
+
result[#result + 1] = id
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
return result
|
|
116
|
+
end
|
|
117
|
+
|
|
98
118
|
-- Parameter labels are structured data, never reparsed as host-language code.
|
|
99
119
|
function M.signature(node, language, name)
|
|
100
120
|
local signatures = contracts[node] or node.foreign_signatures
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
-- Compact function-as-value sites. Resolution reuses query-owned bindings;
|
|
2
|
+
-- these are references, never proof of a callback being executed.
|
|
3
|
+
local M = {}
|
|
4
|
+
local supported = { javascript = true, typescript = true, arkts = true, python = true, java = true }
|
|
5
|
+
local callable = { ['function'] = true, method = true }
|
|
6
|
+
local before = { ['('] = true, [','] = true, ['='] = true, ['['] = true, [':'] = true }
|
|
7
|
+
local after = { [')'] = true, [','] = true, [';'] = true, [']'] = true, ['}'] = true }
|
|
8
|
+
|
|
9
|
+
function M.collect(r, T)
|
|
10
|
+
if not supported[r.language] then return end
|
|
11
|
+
-- The ordinary parser does not represent every anonymous scope. Do not
|
|
12
|
+
-- borrow outer binding evidence where an unindexed parameter can shadow it.
|
|
13
|
+
if r.language ~= 'java' then
|
|
14
|
+
local headers = {}
|
|
15
|
+
for _, n in ipairs(r.nodes) do
|
|
16
|
+
if callable[n.kind] then
|
|
17
|
+
for i = n.ti, n.tj do
|
|
18
|
+
local s = T:text(i)
|
|
19
|
+
if s == 'function' or s == '=>' then headers[i] = true end
|
|
20
|
+
if s == '{' then break end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
for i = 1, T.n do
|
|
25
|
+
if (T:text(i) == '=>' or T:text(i) == 'function') and not headers[i]
|
|
26
|
+
or r.language == 'python' and T:text(i) == 'lambda' then return end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
local names, roots, seen = {}, {}, {}
|
|
30
|
+
for _, n in ipairs(r.nodes) do if callable[n.kind] then names[n.name] = true end end
|
|
31
|
+
if r.language ~= 'java' then
|
|
32
|
+
for _, imp in ipairs(require('codeoutline.dispatch_aliases').imports(r, T)) do
|
|
33
|
+
names[imp.name], roots[imp.name] = true, true
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
for _, ref in ipairs(r.refs) do seen[ref.tok] = true end
|
|
37
|
+
local aliases = {}
|
|
38
|
+
for i = 2, T.n - 1 do
|
|
39
|
+
if T:text(i) == '=' and T.k[i - 1] == 'id' and T.k[i + 1] == 'id'
|
|
40
|
+
and (after[T:text(i + 2)] or T.k[i + 2] == 'nl') then
|
|
41
|
+
aliases[#aliases + 1] = { T:text(i - 1), T:text(i + 1) }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
for _ = 1, 8 do
|
|
45
|
+
local changed = false
|
|
46
|
+
for _, alias in ipairs(aliases) do
|
|
47
|
+
if names[alias[2]] and not names[alias[1]] then names[alias[1]], changed = true, true end
|
|
48
|
+
end
|
|
49
|
+
if not changed then break end
|
|
50
|
+
end
|
|
51
|
+
for i = 1, T.n do
|
|
52
|
+
if i % 4096 == 0 then require('codeoutline.control').check() end
|
|
53
|
+
if T.k[i] == 'id' and not seen[i] then
|
|
54
|
+
local prev, next = T:text(i - 1), T:text(i + 1)
|
|
55
|
+
local explicit = prev == '::' and r.language == 'java'
|
|
56
|
+
local recv = (prev == '.' or explicit) and
|
|
57
|
+
(T.k[i - 2] == 'id' or T:text(i - 2) == 'this' or T:text(i - 2) == 'self' or T:text(i - 2) == 'cls') and T:text(i - 2)
|
|
58
|
+
local first = recv and i - 2 or i
|
|
59
|
+
local simple = before[T:text(first - 1)] and
|
|
60
|
+
(after[next] or T.k[i + 1] == 'nl' or i == T.n)
|
|
61
|
+
if (explicit or r.language ~= 'java' and simple and (names[T:text(i)] or roots[recv]))
|
|
62
|
+
and not (recv and (T:text(first - 1) == '.' or T:text(first - 1) == '?.')) then
|
|
63
|
+
r.refs[#r.refs + 1] = { tok = i, name = T:text(i), kind = 'ref', recv = recv, line = T:line(i) }
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
return M
|