@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,143 @@
|
|
|
1
|
+
-- Include-driven admission of unknown suffixes from the normal file listing.
|
|
2
|
+
local paths = require('codeoutline.path')
|
|
3
|
+
local parse = require('codeoutline.parse')
|
|
4
|
+
local includes = require('codeoutline.cpp_includes')
|
|
5
|
+
local control = require('codeoutline.control')
|
|
6
|
+
local M = { MAX_FILES = 4096, MAX_BYTES = 67108864, MAX_DEPTH = 32 }
|
|
7
|
+
local function c_family(rec) return rec and (rec.language == 'c' or rec.language == 'cpp') end
|
|
8
|
+
|
|
9
|
+
function M.inventory(root)
|
|
10
|
+
return { root = root, files = {}, file_index = {}, by_base = {}, count = 0 }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
function M.policy_key(root)
|
|
14
|
+
local policy = includes.context({ root = root })
|
|
15
|
+
local parts = { tostring(policy.configured) }
|
|
16
|
+
for _, dir in ipairs(policy.defaults) do parts[#parts + 1] = 'path:' .. dir end
|
|
17
|
+
for _, rule in ipairs(policy.rules) do
|
|
18
|
+
parts[#parts + 1] = 'rule:' .. rule.directory
|
|
19
|
+
for _, dir in ipairs(rule.paths) do parts[#parts + 1] = 'path:' .. dir end
|
|
20
|
+
end
|
|
21
|
+
return table.concat(parts, '\0')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
function M.add(G, rel)
|
|
25
|
+
if parse.language(rel) then return end
|
|
26
|
+
local key = paths.key(rel)
|
|
27
|
+
if G.file_index[key] then return end
|
|
28
|
+
G.count = G.count + 1
|
|
29
|
+
G.files[rel] = { path = rel }
|
|
30
|
+
G.file_index[rel], G.file_index[key] = rel, rel
|
|
31
|
+
local base = rel:match('([^/]*)$')
|
|
32
|
+
local key_base = paths.key(base)
|
|
33
|
+
G.by_base[key_base] = G.by_base[key_base] or {}
|
|
34
|
+
G.by_base[key_base][#G.by_base[key_base] + 1] = rel
|
|
35
|
+
G.by_base[base] = G.by_base[key_base]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
-- sync(batch, seen) uses the regular index loader and parse worker path.
|
|
39
|
+
-- Parents, macro environments and detailed bindings stay query-owned.
|
|
40
|
+
function M.refresh(idx, stats, seen, sync, changed)
|
|
41
|
+
local G = idx.fragment_inventory
|
|
42
|
+
if not G or G.count == 0 then return end
|
|
43
|
+
local ctx, frontier = {}, {}
|
|
44
|
+
for rel, rec in pairs(idx.files) do
|
|
45
|
+
if seen[rel] and not rec.cpp_fragment and c_family(rec) then frontier[#frontier + 1] = rel end
|
|
46
|
+
end
|
|
47
|
+
table.sort(frontier)
|
|
48
|
+
if #frontier == 0 then return end
|
|
49
|
+
local admitted, canonical, count, bytes = {}, {}, 0, 0
|
|
50
|
+
local function target(rel)
|
|
51
|
+
local old = canonical[rel]
|
|
52
|
+
if old ~= nil then return old or nil end
|
|
53
|
+
local real = xutils.realpath(idx:abs(rel))
|
|
54
|
+
local found
|
|
55
|
+
if real and paths.contains(idx.root, real) then
|
|
56
|
+
real = paths.normalize(real)
|
|
57
|
+
local relative = real:sub(#idx.root + (idx.root:sub(-1) == '/' and 1 or 2))
|
|
58
|
+
found = G.file_index[paths.key(relative)]
|
|
59
|
+
end
|
|
60
|
+
canonical[rel] = found or false
|
|
61
|
+
return found
|
|
62
|
+
end
|
|
63
|
+
local function dependency(rel, imp)
|
|
64
|
+
if parse.language(imp.path) then return end
|
|
65
|
+
local ids = includes.resolve(G, rel, imp, ctx)
|
|
66
|
+
if #ids == 1 then return target(ids[1]) end
|
|
67
|
+
end
|
|
68
|
+
local metadata = {}
|
|
69
|
+
local function stat(rel)
|
|
70
|
+
if metadata[rel] == nil then metadata[rel] = xutils.stat(idx:abs(rel)) or false end
|
|
71
|
+
return metadata[rel] or nil
|
|
72
|
+
end
|
|
73
|
+
-- Settle C++ precedence through unchanged cached includes before loading a
|
|
74
|
+
-- batch. Otherwise a shared fragment can flip C -> C++ on every refresh
|
|
75
|
+
-- when the C++ includer is reached a round later than the C includer.
|
|
76
|
+
local cpp_hints, queue, queued = {}, {}, {}
|
|
77
|
+
for _, rel in ipairs(frontier) do
|
|
78
|
+
queued[rel] = idx.files[rel].language == 'cpp'
|
|
79
|
+
queue[#queue + 1] = { rel, queued[rel] }
|
|
80
|
+
end
|
|
81
|
+
local at, limit = 1, #queue + 2 * M.MAX_FILES
|
|
82
|
+
while at <= #queue and at <= limit do
|
|
83
|
+
control.check()
|
|
84
|
+
local rel, cpp = queue[at][1], queue[at][2]
|
|
85
|
+
local rec = idx.files[rel]; G.files[rel] = rec
|
|
86
|
+
cpp = cpp or rec.cpp_fragment_cpp or false
|
|
87
|
+
for _, imp in ipairs(rec.imports) do
|
|
88
|
+
local p = dependency(rel, imp)
|
|
89
|
+
if p then
|
|
90
|
+
if cpp then cpp_hints[p] = true end
|
|
91
|
+
local cached, st = idx.files[p], stat(p)
|
|
92
|
+
if cached and cached.cpp_fragment and not (changed and changed[p]) and st
|
|
93
|
+
and cached.size == st.size and cached.mtime == st.mtime then
|
|
94
|
+
local mode = cpp or cached.cpp_fragment_cpp or false
|
|
95
|
+
if queued[p] == nil or mode and not queued[p] then
|
|
96
|
+
queued[p] = mode; queue[#queue + 1] = { p, mode }
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
at = at + 1
|
|
102
|
+
end
|
|
103
|
+
for depth = 1, M.MAX_DEPTH do
|
|
104
|
+
local pending = {}
|
|
105
|
+
for _, rel in ipairs(frontier) do
|
|
106
|
+
control.check()
|
|
107
|
+
local rec = idx.files[rel]
|
|
108
|
+
G.files[rel] = rec
|
|
109
|
+
for _, imp in ipairs(rec.imports) do
|
|
110
|
+
local p = dependency(rel, imp)
|
|
111
|
+
if p then
|
|
112
|
+
local desired = cpp_hints[p] and 'cpp' or rec.language
|
|
113
|
+
local language = pending[p] or admitted[p]
|
|
114
|
+
if not language or language == 'c' and desired == 'cpp' then pending[p] = desired end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
local ordered = {}; for p in pairs(pending) do ordered[#ordered + 1] = p end
|
|
119
|
+
table.sort(ordered)
|
|
120
|
+
local batch = {}
|
|
121
|
+
for _, p in ipairs(ordered) do
|
|
122
|
+
local st = stat(p)
|
|
123
|
+
if st and st.type == 'file' and st.size <= idx.max_bytes then
|
|
124
|
+
if not admitted[p] and (count >= M.MAX_FILES or bytes + st.size > M.MAX_BYTES) then stats.fragment_limited = true
|
|
125
|
+
else
|
|
126
|
+
if not admitted[p] then count, bytes = count + 1, bytes + st.size end
|
|
127
|
+
admitted[p] = pending[p]
|
|
128
|
+
batch[#batch + 1] = { rel = p, language = pending[p], stat = st }
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
if #batch == 0 then break end
|
|
133
|
+
frontier = sync(batch, seen)
|
|
134
|
+
table.sort(frontier)
|
|
135
|
+
if #frontier == 0 then break end
|
|
136
|
+
if depth == M.MAX_DEPTH then stats.fragment_limited = true end
|
|
137
|
+
end
|
|
138
|
+
local retained = 0
|
|
139
|
+
for rel in pairs(admitted) do if seen[rel] then retained = retained + 1 end end
|
|
140
|
+
stats.fragment_files = retained
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
return M
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
-- C++ override evidence belongs to a query, never the resident index.
|
|
2
|
+
local M = { MAX_ALIAS_FILES = 128, MAX_ALIAS_BYTES = 1024 * 1024 }
|
|
3
|
+
local control = require('codeoutline.control')
|
|
4
|
+
local lookup = require('codeoutline.cpp_types')
|
|
5
|
+
local classes = { class = true, struct = true }
|
|
6
|
+
local cv = { const = true, volatile = true }
|
|
7
|
+
local builtin = { void = true, bool = true, char = true, wchar_t = true, char8_t = true,
|
|
8
|
+
char16_t = true, char32_t = true, short = true, int = true, long = true,
|
|
9
|
+
signed = true, unsigned = true, float = true, double = true }
|
|
10
|
+
local modifiers = { virtual = true, static = true, inline = true, constexpr = true,
|
|
11
|
+
consteval = true, explicit = true, friend = true, extern = true }
|
|
12
|
+
|
|
13
|
+
local function tokens(T, a, b)
|
|
14
|
+
local out = {}
|
|
15
|
+
for i = a, b do out[#out + 1] = T:text(i) end
|
|
16
|
+
return out
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
local function parameter(T, a, b)
|
|
20
|
+
for i = a, b do if T:text(i) == '=' then b = i - 1; break end end
|
|
21
|
+
-- A trailing identifier is a name only when a type precedes it. Preserve
|
|
22
|
+
-- unnamed `const Item`, qualified types, and all pointer/cv decoration.
|
|
23
|
+
if T.k[b] == 'id' and T:text(b - 1) ~= '::' then
|
|
24
|
+
local typed = false
|
|
25
|
+
for i = a, b - 1 do
|
|
26
|
+
local s = T:text(i)
|
|
27
|
+
if not cv[s] and s ~= 'struct' and s ~= 'class' and s ~= '::' then typed = true end
|
|
28
|
+
end
|
|
29
|
+
if typed then b = b - 1 end
|
|
30
|
+
end
|
|
31
|
+
return tokens(T, a, b)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
function M.collect(r, T)
|
|
35
|
+
local evidence = {}
|
|
36
|
+
for id, n in ipairs(r.nodes) do
|
|
37
|
+
if id % 128 == 0 then control.check() end
|
|
38
|
+
if classes[n.kind] or n.kind == 'method' then
|
|
39
|
+
local d = { at = T.s[n.ti] - 1 }
|
|
40
|
+
if classes[n.kind] then d.hierarchy_bases = require('codeoutline.type_bases').collect(T, n, r.language) end
|
|
41
|
+
local ni, opening
|
|
42
|
+
for i = n.ti, n.tj do
|
|
43
|
+
local s = T:text(i)
|
|
44
|
+
if s == '{' then break end
|
|
45
|
+
if s == 'template' or s == '<' or s == '>' then d.unsupported = true end
|
|
46
|
+
if s == 'virtual' or s == 'static' or s == 'final' or s == 'friend' then d[s] = true end
|
|
47
|
+
if s == n.name and T:text(i + 1) == '(' and n.kind == 'method' then
|
|
48
|
+
ni, opening = i, i + 1; break
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
if n.kind == 'method' and opening and T.m[opening] then
|
|
52
|
+
local close, params, first = T.m[opening], {}, opening + 1
|
|
53
|
+
local i = first
|
|
54
|
+
while i <= close do
|
|
55
|
+
local s = T:text(i)
|
|
56
|
+
if i == close or s == ',' then
|
|
57
|
+
if first < i then params[#params + 1] = parameter(T, first, i - 1) end
|
|
58
|
+
first = i + 1
|
|
59
|
+
elseif T.m[i] and T.m[i] > i then i = T.m[i] end
|
|
60
|
+
i = i + 1
|
|
61
|
+
end
|
|
62
|
+
if #params == 1 and #params[1] == 1 and params[1][1] == 'void' then params = {} end
|
|
63
|
+
d.params = params
|
|
64
|
+
local head = ni
|
|
65
|
+
while T:text(head - 1) == '::' and T.k[head - 2] == 'id' do head = head - 2 end
|
|
66
|
+
if T:text(head - 1) == '::' then head = head - 1 end
|
|
67
|
+
local ret = {}
|
|
68
|
+
for j = n.ti, head - 1 do
|
|
69
|
+
local s = T:text(j)
|
|
70
|
+
if not modifiers[s] then ret[#ret + 1] = s end
|
|
71
|
+
end
|
|
72
|
+
d.returns = ret
|
|
73
|
+
i = close + 1
|
|
74
|
+
while i <= n.tj do
|
|
75
|
+
local s = T:text(i)
|
|
76
|
+
if s == '{' or s == ';' then break end
|
|
77
|
+
if cv[s] or s == 'final' or s == 'override' then d[s] = true
|
|
78
|
+
elseif s == '&' or s == '&&' then d.ref = s
|
|
79
|
+
elseif s == '=' and T:text(i + 1) == '0' then d.pure = true; i = i + 1
|
|
80
|
+
elseif s == 'noexcept' then
|
|
81
|
+
if T:text(i + 1) == '(' and T.m[i + 1] then i = T.m[i + 1] end
|
|
82
|
+
else d.unsupported = true end
|
|
83
|
+
i = i + 1
|
|
84
|
+
end
|
|
85
|
+
elseif n.kind == 'method' then d.unsupported = true end
|
|
86
|
+
evidence[id] = d
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
r.implementation_evidence = evidence
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
function M.context(G, ctx, report, limits, C)
|
|
93
|
+
local details, owners, chains, lists, outgoing, incoming = {}, {}, {}, {}, {}, {}
|
|
94
|
+
local alias_records, alias_count, alias_bytes, alias_limited = {}, 0, 0, false
|
|
95
|
+
local function aliases(f)
|
|
96
|
+
if alias_records[f] then return alias_records[f] end
|
|
97
|
+
if alias_limited then return {} end
|
|
98
|
+
local data = lookup.aliases(G, f, ctx)
|
|
99
|
+
local weight = 0
|
|
100
|
+
for _, alias in ipairs(data) do
|
|
101
|
+
weight = weight + 128
|
|
102
|
+
for _, value in pairs(alias) do if type(value) == 'string' then weight = weight + #value end end
|
|
103
|
+
end
|
|
104
|
+
if alias_count >= M.MAX_ALIAS_FILES or alias_bytes + weight > M.MAX_ALIAS_BYTES then
|
|
105
|
+
alias_limited, C.incomplete = true, true; return {}
|
|
106
|
+
end
|
|
107
|
+
-- Retain only the alias arrays already produced by the shared loader.
|
|
108
|
+
-- Repeated parameter lookups must not thrash its 16-file source FIFO.
|
|
109
|
+
alias_count, alias_bytes = alias_count + 1, alias_bytes + weight
|
|
110
|
+
alias_records[f] = data
|
|
111
|
+
C.stats.cpp_alias_files, C.stats.cpp_alias_bytes = alias_count, alias_bytes
|
|
112
|
+
return data
|
|
113
|
+
end
|
|
114
|
+
local function info(id)
|
|
115
|
+
if not details[id] then
|
|
116
|
+
local f = G.node_file[id]
|
|
117
|
+
local data = ctx.ordinary and ctx.ordinary.data(f) or G.files[f]
|
|
118
|
+
details[id] = (data.implementation_evidence or {})[id - G.id_of[f][1] + 1] or {}
|
|
119
|
+
end
|
|
120
|
+
return details[id]
|
|
121
|
+
end
|
|
122
|
+
local function resolve(id, text, accept)
|
|
123
|
+
local ids = lookup.resolve(G, G.node_file[id], text, { context = ctx,
|
|
124
|
+
scope = G.nodes[id].qualified, at = info(id).at, accept = accept or classes,
|
|
125
|
+
undecorated = true, aliases = aliases })
|
|
126
|
+
if ctx.include_incomplete then C.incomplete = true end
|
|
127
|
+
return #ids == 1 and ids[1] or nil
|
|
128
|
+
end
|
|
129
|
+
local function owner(id)
|
|
130
|
+
if owners[id] == nil then
|
|
131
|
+
local n, f = G.nodes[id], G.node_file[id]
|
|
132
|
+
local parent = n.parent and G.id_of[f][n.parent]
|
|
133
|
+
owners[id] = parent and classes[G.nodes[parent].kind] and parent
|
|
134
|
+
or resolve(id, n.qualified:match('^(.*)::[^:]+$')) or false
|
|
135
|
+
end
|
|
136
|
+
return owners[id] or nil
|
|
137
|
+
end
|
|
138
|
+
local function ancestry(id)
|
|
139
|
+
if chains[id] then return chains[id] end
|
|
140
|
+
local out, visited, current = {}, {}, id
|
|
141
|
+
while current do
|
|
142
|
+
control.check()
|
|
143
|
+
if visited[current] or #out > limits.MAX_DEPTH or C.stats.hierarchy >= limits.MAX_HIERARCHY then
|
|
144
|
+
C.incomplete = true; out = {}; break
|
|
145
|
+
end
|
|
146
|
+
visited[current] = true; C.stats.hierarchy = C.stats.hierarchy + 1
|
|
147
|
+
local n, d = G.nodes[current], info(current)
|
|
148
|
+
local bases = n.bases or {}
|
|
149
|
+
-- Multiple/virtual inheritance, templates, and unresolved bases
|
|
150
|
+
-- need a final-overrider model; do not approximate by class name.
|
|
151
|
+
if d.unsupported or d.virtual or current ~= id and d.final or #bases > 1 then out = {}; break end
|
|
152
|
+
if #bases == 0 then break end
|
|
153
|
+
local parent = resolve(current, bases[1])
|
|
154
|
+
if not parent then out = {}; break end
|
|
155
|
+
out[#out + 1] = parent; current = parent
|
|
156
|
+
end
|
|
157
|
+
chains[id] = out; return out
|
|
158
|
+
end
|
|
159
|
+
local function type_key(id, words, value)
|
|
160
|
+
if not words or #words == 0 then return nil end
|
|
161
|
+
local base, layers, layer = {}, {}, {}
|
|
162
|
+
layers[1] = layer
|
|
163
|
+
for _, s in ipairs(words) do
|
|
164
|
+
if cv[s] then layer[s] = true
|
|
165
|
+
elseif s == '*' or s == '&' or s == '&&' then
|
|
166
|
+
if layer.op == '&' or layer.op == '&&' then return nil end
|
|
167
|
+
layer = { op = s }; layers[#layers + 1] = layer
|
|
168
|
+
elseif s == '::' or s:match('^[%a_][%w_]*$') then
|
|
169
|
+
if #layers ~= 1 then return nil end
|
|
170
|
+
if s ~= 'struct' and s ~= 'class' and s ~= 'enum' then base[#base + 1] = s end
|
|
171
|
+
else return nil end
|
|
172
|
+
end
|
|
173
|
+
if #base == 0 then return nil end
|
|
174
|
+
local primitive = true
|
|
175
|
+
for _, s in ipairs(base) do if not builtin[s] then primitive = false end end
|
|
176
|
+
local canonical
|
|
177
|
+
if primitive then
|
|
178
|
+
canonical = table.concat(base, ' ')
|
|
179
|
+
canonical = canonical:gsub('^signed int$', 'int'):gsub('^signed$', 'int')
|
|
180
|
+
:gsub('^unsigned$', 'unsigned int'):gsub('short int$', 'short'):gsub('long int$', 'long')
|
|
181
|
+
else
|
|
182
|
+
local written = table.concat(base):gsub('::', ':')
|
|
183
|
+
if written:find('[^%w_:]') or not written:match('^:?[A-Za-z_][%w_:]*$') then return nil end
|
|
184
|
+
-- Adjacent identifiers are not a qualified named type.
|
|
185
|
+
for i = 2, #base do if base[i] ~= '::' and base[i - 1] ~= '::' then return nil end end
|
|
186
|
+
local ty = resolve(id, table.concat(base), { class = true, struct = true, enum = true })
|
|
187
|
+
if not ty then return nil end
|
|
188
|
+
canonical = '#' .. ty
|
|
189
|
+
end
|
|
190
|
+
local result = { canonical }
|
|
191
|
+
for i, part in ipairs(layers) do
|
|
192
|
+
local ignore = value and i == #layers and part.op ~= '&' and part.op ~= '&&'
|
|
193
|
+
result[#result + 1] = (part.op or '') .. (not ignore and part.const and ' const' or '')
|
|
194
|
+
.. (not ignore and part.volatile and ' volatile' or '')
|
|
195
|
+
end
|
|
196
|
+
return table.concat(result)
|
|
197
|
+
end
|
|
198
|
+
local function signature(id)
|
|
199
|
+
local d, cls = info(id), owner(id)
|
|
200
|
+
if not cls or not d.params or d.unsupported or d.friend or info(cls).unsupported
|
|
201
|
+
or info(cls).virtual or #(G.nodes[cls].bases or {}) > 1 then return nil end
|
|
202
|
+
local enclosing, depth = cls, 0
|
|
203
|
+
while enclosing do
|
|
204
|
+
if info(enclosing).unsupported then return nil end
|
|
205
|
+
depth = depth + 1
|
|
206
|
+
if depth > limits.MAX_DEPTH + 1 then C.incomplete = true; return nil end
|
|
207
|
+
local n, f = G.nodes[enclosing], G.node_file[enclosing]
|
|
208
|
+
enclosing = n.parent and G.id_of[f][n.parent]
|
|
209
|
+
if enclosing and not classes[G.nodes[enclosing].kind] then enclosing = nil end
|
|
210
|
+
end
|
|
211
|
+
local params = {}
|
|
212
|
+
for _, p in ipairs(d.params) do
|
|
213
|
+
local key = type_key(id, p, true)
|
|
214
|
+
if not key then return nil end
|
|
215
|
+
params[#params + 1] = key
|
|
216
|
+
end
|
|
217
|
+
local ret = type_key(id, d.returns, false)
|
|
218
|
+
if not ret then return nil end
|
|
219
|
+
return table.concat(params, ',') .. '|' .. (d.const and 'const' or '')
|
|
220
|
+
.. (d.volatile and 'volatile' or '') .. (d.ref or ''), ret
|
|
221
|
+
end
|
|
222
|
+
local function methods(name)
|
|
223
|
+
if lists[name] then return lists[name] end
|
|
224
|
+
local groups, by_id, ordered, checked = {}, {}, {}, 0
|
|
225
|
+
for _, id in ipairs(G.by_name[name] or {}) do
|
|
226
|
+
control.check()
|
|
227
|
+
if G.nodes[id].kind == 'method' and G.files[G.node_file[id]].language == 'cpp' then
|
|
228
|
+
if checked >= limits.MAX_CANDIDATES then C.incomplete = true; break end
|
|
229
|
+
checked = checked + 1; C.stats.candidates = C.stats.candidates + 1
|
|
230
|
+
local sig, ret = signature(id)
|
|
231
|
+
if sig then
|
|
232
|
+
local cls, d = owner(id), info(id)
|
|
233
|
+
groups[cls] = groups[cls] or {}
|
|
234
|
+
local group = groups[cls][sig]
|
|
235
|
+
if not group then
|
|
236
|
+
group = { cls = cls, sig = sig, ret = ret, ids = {} }; groups[cls][sig] = group
|
|
237
|
+
ordered[#ordered + 1] = group
|
|
238
|
+
end
|
|
239
|
+
if group.ret ~= ret then group.invalid = true end
|
|
240
|
+
group.ids[#group.ids + 1] = id; by_id[id] = group
|
|
241
|
+
local n, f = G.nodes[id], G.node_file[id]
|
|
242
|
+
if n.parent and G.id_of[f][n.parent] == cls then group.declared = true end
|
|
243
|
+
for _, flag in ipairs({ 'virtual', 'pure', 'static', 'final' }) do if d[flag] then group[flag] = true end end
|
|
244
|
+
if not G.nodes[id].decl then
|
|
245
|
+
if group.body then group.invalid = true end
|
|
246
|
+
group.body = id
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
for _, members in pairs(groups) do
|
|
252
|
+
for _, group in pairs(members) do if not group.declared then group.invalid = true end end
|
|
253
|
+
end
|
|
254
|
+
local result = { groups = groups, by_id = by_id, ordered = ordered }; lists[name] = result; return result
|
|
255
|
+
end
|
|
256
|
+
local function inherited(list, group)
|
|
257
|
+
local result = {}
|
|
258
|
+
for _, cls in ipairs(ancestry(group.cls)) do
|
|
259
|
+
local parent = list.groups[cls] and list.groups[cls][group.sig]
|
|
260
|
+
if parent then result[#result + 1] = parent end
|
|
261
|
+
end
|
|
262
|
+
return result
|
|
263
|
+
end
|
|
264
|
+
local function contract(list, group)
|
|
265
|
+
if group.invalid or group.static then return false end
|
|
266
|
+
local virtual = group.virtual
|
|
267
|
+
for _, parent in ipairs(inherited(list, group)) do
|
|
268
|
+
if parent.invalid or parent.static or parent.final or parent.ret ~= group.ret then return false end
|
|
269
|
+
virtual = virtual or parent.virtual
|
|
270
|
+
end
|
|
271
|
+
return virtual
|
|
272
|
+
end
|
|
273
|
+
local function matches(list, base, candidate)
|
|
274
|
+
if candidate.invalid or candidate.pure or candidate.static or candidate.ret ~= base.ret or base.final then return false end
|
|
275
|
+
for _, parent in ipairs(inherited(list, candidate)) do
|
|
276
|
+
if parent == base then return true end
|
|
277
|
+
if parent.invalid or parent.static or parent.final or parent.ret ~= candidate.ret then return false end
|
|
278
|
+
end
|
|
279
|
+
return false
|
|
280
|
+
end
|
|
281
|
+
local function link(source, target)
|
|
282
|
+
C.stats.links = C.stats.links + 1
|
|
283
|
+
if report then report:add({ source = source, target = target, line = G.nodes[source].line,
|
|
284
|
+
kind = 'possible implementation (C++ virtual declaration and exact signature)' }) end
|
|
285
|
+
end
|
|
286
|
+
local function potential(id)
|
|
287
|
+
local cls = owner(id)
|
|
288
|
+
if not cls or info(cls).final then return false end
|
|
289
|
+
if #(G.nodes[cls].bases or {}) > 0 or info(id).virtual then return true end
|
|
290
|
+
-- A class-outside body inherits the virtual marker from its declaration.
|
|
291
|
+
-- A plain root method must not expand hundreds of same-name candidates.
|
|
292
|
+
for _, declaration in ipairs(G.by_qualified[G.nodes[id].qualified] or {}) do
|
|
293
|
+
if G.files[G.node_file[declaration]].language == 'cpp' and G.nodes[declaration].kind == 'method'
|
|
294
|
+
and owner(declaration) == cls and info(declaration).virtual then return true end
|
|
295
|
+
end
|
|
296
|
+
return false
|
|
297
|
+
end
|
|
298
|
+
local D = {}
|
|
299
|
+
function D.outgoing(id)
|
|
300
|
+
if outgoing[id] then return outgoing[id] end
|
|
301
|
+
if not potential(id) then outgoing[id] = {}; return outgoing[id] end
|
|
302
|
+
local result, list = {}, methods(G.nodes[id].name)
|
|
303
|
+
local base = list.by_id[id]
|
|
304
|
+
if base and contract(list, base) and not base.final then
|
|
305
|
+
for _, group in ipairs(list.ordered) do
|
|
306
|
+
if group.sig == base.sig and matches(list, base, group) then
|
|
307
|
+
if #result >= limits.MAX_TARGETS then C.incomplete = true; break end
|
|
308
|
+
local target = group.body or group.ids[1]
|
|
309
|
+
result[#result + 1] = target
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
if alias_limited then result = {} end
|
|
314
|
+
for _, target in ipairs(result) do link(id, target) end
|
|
315
|
+
table.sort(result); outgoing[id] = result; return result
|
|
316
|
+
end
|
|
317
|
+
function D.incoming(id)
|
|
318
|
+
if incoming[id] then return incoming[id] end
|
|
319
|
+
local cls = owner(id)
|
|
320
|
+
if not cls or #(G.nodes[cls].bases or {}) == 0 then incoming[id] = {}; return incoming[id] end
|
|
321
|
+
local result, list = {}, methods(G.nodes[id].name)
|
|
322
|
+
local candidate = list.by_id[id]
|
|
323
|
+
if candidate then
|
|
324
|
+
for _, base in ipairs(inherited(list, candidate)) do
|
|
325
|
+
if contract(list, base) and matches(list, base, candidate) then
|
|
326
|
+
for _, source in ipairs(base.ids) do
|
|
327
|
+
if #result >= limits.MAX_TARGETS then C.incomplete = true; break end
|
|
328
|
+
result[#result + 1] = source
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
if alias_limited then result = {} end
|
|
334
|
+
for _, source in ipairs(result) do link(source, id) end
|
|
335
|
+
table.sort(result); incoming[id] = result; return result
|
|
336
|
+
end
|
|
337
|
+
return D
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
return M
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
-- Ordered C/C++ include lookup over indexed paths. Configuration is query-owned.
|
|
2
|
+
local M = { MAX_PATHS = 128, MAX_RULES = 128, MAX_CACHED_TARGETS = 8192 }
|
|
3
|
+
local paths = require('codeoutline.path')
|
|
4
|
+
local control = require('codeoutline.control')
|
|
5
|
+
local function absolute(path) return path:sub(1, 1) == '/' or path:match('^%a:/') ~= nil end
|
|
6
|
+
local function normalize(path)
|
|
7
|
+
path = path:gsub('\\', '/')
|
|
8
|
+
local prefix = path:match('^%a:/') or (path:sub(1, 2) == '//' and '//') or (path:sub(1, 1) == '/' and '/') or ''
|
|
9
|
+
local parts, floor = {}, prefix == '//' and 2 or 0
|
|
10
|
+
for part in path:sub(#prefix + 1):gmatch('[^/]+') do
|
|
11
|
+
if part == '..' and #parts > floor and parts[#parts] ~= '..' then parts[#parts] = nil
|
|
12
|
+
elseif part == '..' then if prefix == '' then parts[#parts + 1] = part end
|
|
13
|
+
elseif part ~= '.' then parts[#parts + 1] = part end
|
|
14
|
+
end
|
|
15
|
+
return prefix .. table.concat(parts, '/')
|
|
16
|
+
end
|
|
17
|
+
local function join(root, path)
|
|
18
|
+
path = path:gsub('\\', '/')
|
|
19
|
+
return normalize(absolute(path) and path or (root ~= '' and root .. '/' or '') .. path)
|
|
20
|
+
end
|
|
21
|
+
local function array(value, label, cap)
|
|
22
|
+
assert(type(value) == 'table' and #value <= cap, label .. ' must be an array with at most ' .. cap .. ' entries')
|
|
23
|
+
for key in pairs(value) do
|
|
24
|
+
assert(type(key) == 'number' and key >= 1 and key <= #value and key % 1 == 0, label .. ' must be an array')
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
local function directory(value, label)
|
|
28
|
+
assert(type(value) == 'string' and value ~= '' and #value <= 4096 and not value:find('[%z\r\n]'),
|
|
29
|
+
label .. ' must contain non-empty directory strings of at most 4096 bytes')
|
|
30
|
+
value = value:gsub('\\', '/')
|
|
31
|
+
assert(not value:find(':', 1, true) or value:match('^%a:/'), label .. ' must not use drive-relative paths')
|
|
32
|
+
return value
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
function M.context(G, client_paths)
|
|
36
|
+
local config = require('codeoutline.rules').read(G.root)
|
|
37
|
+
local root = normalize(G.root or '')
|
|
38
|
+
local function directories(value, label)
|
|
39
|
+
array(value, label, M.MAX_PATHS)
|
|
40
|
+
local result = {}
|
|
41
|
+
for _, dir in ipairs(value) do result[#result + 1] = join(root, directory(dir, label)) end
|
|
42
|
+
return result
|
|
43
|
+
end
|
|
44
|
+
local C = { root = root, rules = {}, policies = {}, targets = {}, target_count = 0, configured = config.includePaths ~= nil }
|
|
45
|
+
local defaults, client = config.includePaths, client_paths
|
|
46
|
+
if defaults == nil then defaults = {} end
|
|
47
|
+
if client == nil then client = {} end
|
|
48
|
+
C.defaults = directories(defaults, 'includePaths')
|
|
49
|
+
C.client = directories(client, 'includePaths')
|
|
50
|
+
C.configured = C.configured or #C.client > 0
|
|
51
|
+
local rules = config.includePathRules
|
|
52
|
+
if rules == nil then rules = {} end
|
|
53
|
+
array(rules, 'includePathRules', M.MAX_RULES)
|
|
54
|
+
local seen = {}
|
|
55
|
+
for _, rule in ipairs(rules) do
|
|
56
|
+
control.check()
|
|
57
|
+
assert(type(rule) == 'table', 'includePathRules entries must be objects')
|
|
58
|
+
for key in pairs(rule) do assert(key == 'directory' or key == 'paths', 'unknown includePathRules field: ' .. tostring(key)) end
|
|
59
|
+
local dir = directory(rule.directory, 'includePathRules.directory')
|
|
60
|
+
assert(not absolute(dir), 'includePathRules.directory must be project-relative')
|
|
61
|
+
dir = normalize(dir)
|
|
62
|
+
assert(dir ~= '..' and dir:sub(1, 3) ~= '../', 'includePathRules.directory must stay inside the project')
|
|
63
|
+
local key = paths.key(dir)
|
|
64
|
+
assert(not seen[key], 'duplicate includePathRules.directory: ' .. dir); seen[key] = true
|
|
65
|
+
C.rules[#C.rules + 1] = { directory = key, paths = directories(rule.paths, 'includePathRules.paths') }
|
|
66
|
+
end
|
|
67
|
+
table.sort(C.rules, function(a, b) return #a.directory > #b.directory end)
|
|
68
|
+
return C
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
function M.policy(G, f, ctx)
|
|
72
|
+
local C = ctx and ctx.cpp_includes
|
|
73
|
+
if not C then
|
|
74
|
+
C = M.context(G, ctx and ctx.include_paths)
|
|
75
|
+
if ctx then ctx.cpp_includes = C end
|
|
76
|
+
end
|
|
77
|
+
local rel, rule = paths.key(G.files[f].path), nil
|
|
78
|
+
for _, candidate in ipairs(C.rules) do
|
|
79
|
+
if candidate.directory == '' or rel:sub(1, #candidate.directory + 1) == candidate.directory .. '/' then
|
|
80
|
+
rule = candidate; break
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
local key = rule and rule.directory or false
|
|
84
|
+
if not C.policies[key] then
|
|
85
|
+
local dirs, seen = {}, {}
|
|
86
|
+
for _, list in ipairs({ rule and rule.paths or {}, C.defaults, C.client }) do
|
|
87
|
+
for _, dir in ipairs(list) do
|
|
88
|
+
local identity = paths.key(dir)
|
|
89
|
+
if not seen[identity] then
|
|
90
|
+
assert(#dirs < M.MAX_PATHS, 'effective includePaths exceeds ' .. M.MAX_PATHS .. ' directories')
|
|
91
|
+
dirs[#dirs + 1], seen[identity] = dir, true
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
C.policies[key] = { paths = dirs, configured = C.configured or rule ~= nil, root = C.root }
|
|
96
|
+
end
|
|
97
|
+
return C.policies[key], C
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
-- `selected` distinguishes an ordered search (including a configured miss)
|
|
101
|
+
-- from the legacy suffix fallback. External selected headers are never indexed.
|
|
102
|
+
function M.resolve(G, f, imp, ctx)
|
|
103
|
+
local policy, C = M.policy(G, f, ctx)
|
|
104
|
+
local rec, written = G.files[f], imp.path:gsub('\\', '/')
|
|
105
|
+
local function target(file)
|
|
106
|
+
local old = C.targets[file]
|
|
107
|
+
if old then return old[1], old[2] end
|
|
108
|
+
control.check()
|
|
109
|
+
local rel = file
|
|
110
|
+
if policy.root ~= '' then
|
|
111
|
+
if paths.contains(policy.root, file) then rel = file:sub(#policy.root + 2) else rel = nil end
|
|
112
|
+
end
|
|
113
|
+
local id = rel and (G.file_index[rel] or G.file_index[paths.key(rel)])
|
|
114
|
+
local exists = id ~= nil
|
|
115
|
+
if not exists and policy.root ~= '' then
|
|
116
|
+
local stat = xutils.stat(file); exists = stat and stat.type == 'file' or false
|
|
117
|
+
if exists then
|
|
118
|
+
local real = xutils.realpath(file)
|
|
119
|
+
real = real and paths.normalize(real)
|
|
120
|
+
if real and paths.contains(policy.root, real) then id = G.file_index[real:sub(#policy.root + 2)] end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
if C.target_count < M.MAX_CACHED_TARGETS then
|
|
124
|
+
C.targets[file] = { id, exists }; C.target_count = C.target_count + 1
|
|
125
|
+
end
|
|
126
|
+
return id, exists
|
|
127
|
+
end
|
|
128
|
+
local function find(file)
|
|
129
|
+
local id, exists = target(file)
|
|
130
|
+
if exists then return id and { id } or {}, true, file end
|
|
131
|
+
end
|
|
132
|
+
if absolute(written) then
|
|
133
|
+
local ids, selected, file = find(normalize(written))
|
|
134
|
+
return ids or {}, selected or true, file
|
|
135
|
+
end
|
|
136
|
+
if not imp.system then
|
|
137
|
+
local here = rec.path:match('^(.*)/[^/]*$') or ''
|
|
138
|
+
local ids, selected, file = find(join(join(policy.root, here), written))
|
|
139
|
+
if selected then return ids, true, file end
|
|
140
|
+
end
|
|
141
|
+
for _, dir in ipairs(policy.paths) do
|
|
142
|
+
local ids, selected, file = find(join(dir, written))
|
|
143
|
+
if selected then return ids, true, file end
|
|
144
|
+
end
|
|
145
|
+
if policy.configured then return {}, true end
|
|
146
|
+
local ids = {}
|
|
147
|
+
local base = written:match('([^/]*)$')
|
|
148
|
+
for i, id in ipairs(G.by_base[base] or G.by_base[paths.key(base)] or {}) do
|
|
149
|
+
if i % 128 == 0 then control.check() end
|
|
150
|
+
local path, name = paths.key(G.files[id].path), paths.key(written)
|
|
151
|
+
if path == name or path:sub(-#name - 1) == '/' .. name then ids[#ids + 1] = id end
|
|
152
|
+
end
|
|
153
|
+
return ids, false
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
return M
|