@codua/codeoutline-win32-x64 0.2.4 → 0.2.6
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/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/package.json +1 -1
- package/scripts/codeoutline/common.lua +19 -4
- package/scripts/codeoutline/completion.lua +101 -49
- package/scripts/codeoutline/cpp_bindings.lua +116 -0
- package/scripts/codeoutline/cpp_types.lua +209 -0
- package/scripts/codeoutline/csharp_bindings.lua +498 -0
- package/scripts/codeoutline/dispatch_aliases.lua +474 -0
- package/scripts/codeoutline/documents.lua +11 -1
- package/scripts/codeoutline/explore.lua +43 -9
- package/scripts/codeoutline/foreign.lua +79 -14
- package/scripts/codeoutline/foreign_lua.lua +146 -19
- package/scripts/codeoutline/graph.lua +31 -3
- package/scripts/codeoutline/index.lua +10 -5
- package/scripts/codeoutline/indirect.lua +113 -39
- package/scripts/codeoutline/js_evidence.lua +30 -2
- package/scripts/codeoutline/js_resolution.lua +34 -0
- package/scripts/codeoutline/lang/csharp.lua +15 -3
- package/scripts/codeoutline/lua_bindings.lua +79 -9
- package/scripts/codeoutline/lua_literal.lua +38 -0
- package/scripts/codeoutline/navigation.lua +321 -95
- package/scripts/codeoutline/ordinary_bindings.lua +220 -0
- package/scripts/codeoutline/python_bindings.lua +112 -0
- package/scripts/codeoutline/query_report.lua +91 -1
- package/scripts/codeoutline/rules.lua +127 -0
- package/scripts/codeoutline/static_dispatch.lua +534 -0
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
-- Shared C++ named-type lookup. Alias bodies and lexical ranges are query-only.
|
|
2
|
+
local M = {}
|
|
3
|
+
local control = require('codeoutline.control')
|
|
4
|
+
local classes = { class = true, struct = true, union = true }
|
|
5
|
+
local declaring = { class = true, struct = true, union = true, enum = true, namespace = true, typedef = true }
|
|
6
|
+
local callable = { ['function'] = true, method = true, constructor = true, destructor = true }
|
|
7
|
+
local qualifiers = { const = true, volatile = true, struct = true, class = true, union = true }
|
|
8
|
+
|
|
9
|
+
-- Only named types with cv/pointer/reference decoration. Never erase template
|
|
10
|
+
-- arguments or dependent expressions and then guess an unrelated class.
|
|
11
|
+
function M.normalize(text)
|
|
12
|
+
if type(text) ~= 'string' then return nil end
|
|
13
|
+
text = text:gsub('^%s+', ''):gsub('%s+$', '')
|
|
14
|
+
for _ = 1, 8 do
|
|
15
|
+
local word, rest = text:match('^(%w+)%s+(.+)$')
|
|
16
|
+
if qualifiers[word] then text = rest else break end
|
|
17
|
+
end
|
|
18
|
+
for _ = 1, 8 do
|
|
19
|
+
local before, word = text:match('^(.-)%s+(%w+)$')
|
|
20
|
+
if word == 'const' or word == 'volatile' then text = before
|
|
21
|
+
else
|
|
22
|
+
local stripped = text:gsub('[%*&%s]+$', '')
|
|
23
|
+
if stripped == text then break end
|
|
24
|
+
text = stripped
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
text = text:gsub('%s*::%s*', '::')
|
|
28
|
+
local rest = text:gsub('^::', '')
|
|
29
|
+
local parts = {}
|
|
30
|
+
for part in rest:gmatch('[^:]+') do
|
|
31
|
+
if not part:match('^[%a_][%w_]*$') then return nil end
|
|
32
|
+
parts[#parts + 1] = part
|
|
33
|
+
end
|
|
34
|
+
if #parts == 0 or table.concat(parts, '::') ~= rest then return nil end
|
|
35
|
+
if rest == 'auto' or rest == 'decltype' then return nil end
|
|
36
|
+
return text
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
function M.collect(r, T)
|
|
40
|
+
if r.language ~= 'cpp' then return end
|
|
41
|
+
local result, scopes, stack = {}, {}, {}
|
|
42
|
+
for i = 1, T.n do
|
|
43
|
+
if T:text(i) == '{' and T.m[i] then stack[#stack + 1] = i end
|
|
44
|
+
scopes[i] = stack[#stack] or 0
|
|
45
|
+
if stack[#stack] and T.m[stack[#stack]] == i then stack[#stack] = nil end
|
|
46
|
+
end
|
|
47
|
+
for i = 1, T.n do
|
|
48
|
+
if i % 4096 == 0 then control.check() end
|
|
49
|
+
local word = T:text(i)
|
|
50
|
+
if word == 'using' and T.k[i + 1] == 'id' and T:text(i + 2) == '=' or word == 'typedef' then
|
|
51
|
+
local stop = i + 1
|
|
52
|
+
while stop <= T.n and T:text(stop) ~= ';' do
|
|
53
|
+
if T.m[stop] and T.m[stop] > stop then stop = T.m[stop] end
|
|
54
|
+
stop = stop + 1
|
|
55
|
+
end
|
|
56
|
+
local name, first, last
|
|
57
|
+
if word == 'using' then name, first, last = i + 1, i + 3, stop - 1
|
|
58
|
+
elseif T.k[stop - 1] == 'id' then name, first, last = stop - 1, i + 1, stop - 2 end
|
|
59
|
+
-- Unsupported function-pointer typedefs still introduce a name barrier.
|
|
60
|
+
if not name then
|
|
61
|
+
for j = i + 1, stop - 1 do
|
|
62
|
+
if T:text(j) == '*' and T.k[j + 1] == 'id' and T:text(j + 2) == ')' then name = j + 1; break end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
if name and stop <= T.n then
|
|
66
|
+
local owner, templated
|
|
67
|
+
for _, n in ipairs(r.nodes) do
|
|
68
|
+
if (classes[n.kind] or n.kind == 'namespace' or callable[n.kind]) and n.ti < i and i < n.tj then
|
|
69
|
+
if not owner or n.ti > owner.ti then owner = n end
|
|
70
|
+
if T:text(n.ti) == 'template' then templated = true end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
for j = i - 1, 1, -1 do
|
|
74
|
+
local s = T:text(j)
|
|
75
|
+
if s == ';' or s == '{' or s == '}' then break end
|
|
76
|
+
if s == 'template' then templated = true; break end
|
|
77
|
+
end
|
|
78
|
+
local scope = owner and owner.qualified or ''
|
|
79
|
+
local local_alias = owner and callable[owner.kind] or false
|
|
80
|
+
if local_alias then scope = scope:match('^(.*)::[^:]+$') or '' end
|
|
81
|
+
local text = first and T.src:sub(T.s[first], T.e[last])
|
|
82
|
+
local open = scopes[i]
|
|
83
|
+
result[#result + 1] = { name = T:text(name), target = not templated and M.normalize(text) or false,
|
|
84
|
+
scope = scope, local_alias = local_alias, at = T.s[name] - 1,
|
|
85
|
+
first = open > 0 and T.s[open] - 1 or 0,
|
|
86
|
+
last = open > 0 and T.e[T.m[open]] or #T.src }
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
if #result > 0 then r.cpp_aliases = result end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
-- opts.at is a byte position in file f, normally the receiver declaration.
|
|
94
|
+
-- The boolean result distinguishes an unknown name from a known but unresolved
|
|
95
|
+
-- declaration, so completion cannot revive a hidden outer type on failure.
|
|
96
|
+
function M.resolve(G, f, written, opts)
|
|
97
|
+
opts = opts or {}
|
|
98
|
+
written = M.normalize(written)
|
|
99
|
+
if not written then return {}, true end
|
|
100
|
+
local deps, ctx, accept = opts.deps or {}, opts.context, opts.accept or classes
|
|
101
|
+
local visibility = { [f] = deps }
|
|
102
|
+
local function visible(file, target)
|
|
103
|
+
if file == target then return true end
|
|
104
|
+
if not visibility[file] then visibility[file] = require('codeoutline.graph').dependencies(G, file, ctx) end
|
|
105
|
+
return visibility[file][target]
|
|
106
|
+
end
|
|
107
|
+
local function aliases(file)
|
|
108
|
+
local rec = G.files[file]
|
|
109
|
+
return (ctx and ctx.ordinary and ctx.ordinary.data(file) or rec).cpp_aliases or {}
|
|
110
|
+
end
|
|
111
|
+
local seen = {}
|
|
112
|
+
local resolve
|
|
113
|
+
local function follow(alias, file, depth)
|
|
114
|
+
if not alias.target then return {} end
|
|
115
|
+
local key = file .. ':' .. alias.at
|
|
116
|
+
if seen[key] or depth >= 8 then return {} end
|
|
117
|
+
seen[key] = true
|
|
118
|
+
local ids = resolve(file, alias.target, alias.scope, alias.at, depth + 1)
|
|
119
|
+
seen[key] = nil
|
|
120
|
+
return ids
|
|
121
|
+
end
|
|
122
|
+
local function named(file, qualified, at, depth)
|
|
123
|
+
local tail = qualified:match('([^:]+)$')
|
|
124
|
+
local found, ids, unique = false, {}, {}
|
|
125
|
+
local function add(more) for _, id in ipairs(more) do if not unique[id] then unique[id] = true; ids[#ids + 1] = id end end end
|
|
126
|
+
for _, id in ipairs(G.by_name[tail] or {}) do
|
|
127
|
+
local n, g = G.nodes[id], G.node_file[id]
|
|
128
|
+
if n.qualified == qualified and declaring[n.kind] and visible(file, g) then
|
|
129
|
+
if n.kind == 'typedef' then
|
|
130
|
+
local matched = false
|
|
131
|
+
for _, alias in ipairs(aliases(g)) do
|
|
132
|
+
if not alias.local_alias and (alias.scope ~= '' and alias.scope .. '::' or '') .. alias.name == qualified then
|
|
133
|
+
matched = true
|
|
134
|
+
if g ~= file or not at or alias.at <= at then found = true; add(follow(alias, g, depth)) end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
if not matched then found = true end -- unsupported alias is a barrier
|
|
138
|
+
else
|
|
139
|
+
found = true
|
|
140
|
+
if accept[n.kind] then add({ id }) end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
return ids, found
|
|
145
|
+
end
|
|
146
|
+
local function qualified(file, name, at, depth)
|
|
147
|
+
local ids, found = named(file, name, at, depth)
|
|
148
|
+
if found then return ids, true end
|
|
149
|
+
-- A class alias may qualify a nested type, e.g. Alias::Inner.
|
|
150
|
+
local prefix, suffix = name:match('^(.*)::([^:]+)$')
|
|
151
|
+
if prefix and depth < 8 then
|
|
152
|
+
local owners, known = qualified(file, prefix, at, depth + 1)
|
|
153
|
+
if known then
|
|
154
|
+
local result = {}
|
|
155
|
+
for _, owner in ipairs(owners) do
|
|
156
|
+
local more = named(file, G.nodes[owner].qualified .. '::' .. suffix, nil, depth + 1)
|
|
157
|
+
for _, id in ipairs(more) do result[#result + 1] = id end
|
|
158
|
+
end
|
|
159
|
+
-- Namespace nodes are not class results, so do not stop lexical
|
|
160
|
+
-- lookup merely because a namespace prefix exists.
|
|
161
|
+
if #owners > 0 then return result, true end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
return {}, false
|
|
165
|
+
end
|
|
166
|
+
resolve = function(file, name, scope, at, depth)
|
|
167
|
+
control.check()
|
|
168
|
+
if depth > 8 then return {}, true end
|
|
169
|
+
if name:sub(1, 2) == '::' then return qualified(file, name:sub(3), at, depth) end
|
|
170
|
+
local head, tail = name:match('^([^:]+)::(.*)$')
|
|
171
|
+
head = head or name
|
|
172
|
+
if at then
|
|
173
|
+
local best
|
|
174
|
+
for _, alias in ipairs(aliases(file)) do
|
|
175
|
+
if alias.local_alias and alias.name == head and alias.at <= at and alias.first <= at and at <= alias.last
|
|
176
|
+
and (not best or alias.first > best.first or alias.first == best.first and alias.at > best.at) then best = alias end
|
|
177
|
+
end
|
|
178
|
+
if best then
|
|
179
|
+
local ids = follow(best, file, depth)
|
|
180
|
+
if not tail then return ids, true end
|
|
181
|
+
local result = {}
|
|
182
|
+
for _, id in ipairs(ids) do
|
|
183
|
+
local more = qualified(file, G.nodes[id].qualified .. '::' .. tail, nil, depth + 1)
|
|
184
|
+
for _, target in ipairs(more) do result[#result + 1] = target end
|
|
185
|
+
end
|
|
186
|
+
return result, true
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
while true do
|
|
190
|
+
local prefix = scope and scope ~= '' and scope .. '::' or ''
|
|
191
|
+
local ids, found
|
|
192
|
+
if not tail then ids, found = named(file, prefix .. name, at, depth)
|
|
193
|
+
else
|
|
194
|
+
ids, found = qualified(file, prefix .. name, at, depth)
|
|
195
|
+
if not found then
|
|
196
|
+
local _, declared = named(file, prefix .. head, at, depth)
|
|
197
|
+
found = declared
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
if found then return ids, true end
|
|
201
|
+
if not scope or scope == '' then break end
|
|
202
|
+
scope = scope:match('^(.*)::[^:]+$') or ''
|
|
203
|
+
end
|
|
204
|
+
return {}, false
|
|
205
|
+
end
|
|
206
|
+
return resolve(f, written, opts.scope, opts.at, 0)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
return M
|