@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,498 @@
|
|
|
1
|
+
-- C# using/receiver evidence shared by LSP and graph queries. No compiler execution.
|
|
2
|
+
local M = {}
|
|
3
|
+
local control = require('codeoutline.control')
|
|
4
|
+
local types = { class = true, struct = true, interface = true, record = true, enum = true }
|
|
5
|
+
local callable = { method = true, constructor = true, ['function'] = true, prototype = true }
|
|
6
|
+
local function clean(s) return s and s:gsub('^@', '') end
|
|
7
|
+
|
|
8
|
+
function M.name(text)
|
|
9
|
+
if type(text) ~= 'string' then return nil end
|
|
10
|
+
text = text:gsub('%s+', ''):gsub('@([%a_][%w_]*)', '%1')
|
|
11
|
+
local prefix, rest = text:match('^([%w_]+)::(.*)$')
|
|
12
|
+
rest = rest or text
|
|
13
|
+
local parts = {}
|
|
14
|
+
for part in rest:gmatch('[^.]+') do
|
|
15
|
+
if not part:match('^[%a_][%w_]*$') then return nil end
|
|
16
|
+
parts[#parts + 1] = part
|
|
17
|
+
end
|
|
18
|
+
if #parts == 0 or table.concat(parts, '.') ~= rest then return nil end
|
|
19
|
+
return (prefix and prefix .. '::' or '') .. rest
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
local function token_name(T, first, last)
|
|
23
|
+
if first > last then return nil end
|
|
24
|
+
return M.name(T.src:sub(T.s[first], T.e[last]))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
function M.collect(r, T)
|
|
28
|
+
r.csharp_usings = r.csharp_usings or {}
|
|
29
|
+
r.csharp_scopes, r.csharp_statics, r.csharp_access, r.has_bindings = {}, {}, {}, true
|
|
30
|
+
r.csharp_parameters = {}
|
|
31
|
+
for index, n in ipairs(r.nodes) do
|
|
32
|
+
if types[n.kind] or n.kind == 'namespace' then
|
|
33
|
+
r.csharp_scopes[#r.csharp_scopes + 1] = { scope = n.qualified, first = T.s[n.ti] - 1, last = T.e[n.tj] }
|
|
34
|
+
end
|
|
35
|
+
local header = (n.sig or ''):match('^(.-)%(') or n.sig or ''
|
|
36
|
+
if header:find('%f[%w]static%f[^%w]') then r.csharp_statics[index] = true end
|
|
37
|
+
local access = header:match('%f[%w](public)%f[^%w]') or header:match('%f[%w](internal)%f[^%w]')
|
|
38
|
+
or header:match('%f[%w](protected)%f[^%w]') or header:match('%f[%w](private)%f[^%w]')
|
|
39
|
+
r.csharp_access[index] = access or (n.parent and r.nodes[n.parent].kind == 'interface' and 'public') or 'private'
|
|
40
|
+
if types[n.kind] or callable[n.kind] then
|
|
41
|
+
for i = n.ti, n.tj do
|
|
42
|
+
local word = T:text(i)
|
|
43
|
+
if word == '(' or word == '{' then break end
|
|
44
|
+
if clean(word) == clean(n.name) and T:text(i + 1) == '<' then
|
|
45
|
+
local j, depth = i + 2, 1
|
|
46
|
+
while j <= n.tj and depth > 0 do
|
|
47
|
+
local s = T:text(j)
|
|
48
|
+
if depth == 1 and T.k[j] == 'id' and (T:text(j - 1) == '<' or T:text(j - 1) == ',') then
|
|
49
|
+
r.csharp_parameters[#r.csharp_parameters + 1] = { name = clean(s), first = T.s[n.ti] - 1, last = T.e[n.tj] }
|
|
50
|
+
end
|
|
51
|
+
if s == '<' then depth = depth + 1 elseif s == '>' then depth = depth - 1 elseif s == '>>' then depth = depth - 2 end
|
|
52
|
+
j = j + 1
|
|
53
|
+
end
|
|
54
|
+
break
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
local wanted, scopes, stack = {}, {}, {}
|
|
60
|
+
for _, ref in ipairs(r.refs) do if ref.recv then wanted[clean(ref.recv)] = true end end
|
|
61
|
+
for i = 1, T.n do
|
|
62
|
+
if T:text(i) == '{' and T.m[i] then stack[#stack + 1] = i end
|
|
63
|
+
scopes[i] = stack[#stack] or 0
|
|
64
|
+
if stack[#stack] and T.m[stack[#stack]] == i then stack[#stack] = nil end
|
|
65
|
+
end
|
|
66
|
+
local bindings = {}
|
|
67
|
+
local endings = { [')'] = true, [','] = true, [';'] = true, ['='] = true, ['{'] = true }
|
|
68
|
+
local forbidden = { ['return'] = true, ['new'] = true, ['throw'] = true, ['using'] = true, ['namespace'] = true }
|
|
69
|
+
for i = 2, T.n do
|
|
70
|
+
if i % 4096 == 0 then control.check() end
|
|
71
|
+
local name, prev = clean(T:text(i)), T:text(i - 1)
|
|
72
|
+
if T.k[i] == 'id' and wanted[name] and endings[T:text(i + 1)] and not forbidden[prev]
|
|
73
|
+
and (T.k[i - 1] == 'id' or T.k[i - 1] == 'kw' or prev == '>' or prev == '>>' or prev == ']' or prev == '?') then
|
|
74
|
+
local first = i - 1
|
|
75
|
+
while (T:text(first - 1) == '.' or T:text(first - 1) == '::') and T.k[first - 2] == 'id' do first = first - 2 end
|
|
76
|
+
local ty = token_name(T, first, i - 1)
|
|
77
|
+
if ty == 'var' then
|
|
78
|
+
ty = nil
|
|
79
|
+
if T:text(i + 1) == '=' and T:text(i + 2) == 'new' then
|
|
80
|
+
local last = i + 3
|
|
81
|
+
while T:text(last + 1) == '.' or T:text(last + 1) == '::' do last = last + 2 end
|
|
82
|
+
if T:text(last + 1) == '(' then ty = token_name(T, i + 3, last) end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
local a = scopes[i]
|
|
86
|
+
local b = a > 0 and T.m[a] or T.n
|
|
87
|
+
for _, n in ipairs(r.nodes) do
|
|
88
|
+
if callable[n.kind] and n.ti <= i and i <= n.tj and n.ti > a then a, b = n.ti, n.tj end
|
|
89
|
+
end
|
|
90
|
+
bindings[name] = bindings[name] or {}
|
|
91
|
+
bindings[name][#bindings[name] + 1] = { type = ty or false, token = i, first = a, last = b }
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
for _, ref in ipairs(r.refs) do
|
|
95
|
+
local first = ref.tok
|
|
96
|
+
while (T:text(first - 1) == '.' or T:text(first - 1) == '?.' or T:text(first - 1) == '::')
|
|
97
|
+
and (T.k[first - 2] == 'id' or T.k[first - 2] == 'kw') do first = first - 2 end
|
|
98
|
+
if T:text(first - 1) == 'new' then
|
|
99
|
+
ref.binding = 'cs:new:' .. (token_name(T, first, ref.tok) or '?') .. '\0' .. (T.s[first] - 1)
|
|
100
|
+
elseif ref.kind == 'member_call' then
|
|
101
|
+
local root, best = clean(T:text(first))
|
|
102
|
+
for _, b in ipairs(bindings[root] or {}) do
|
|
103
|
+
if b.first <= ref.tok and ref.tok <= b.last and b.token <= ref.tok
|
|
104
|
+
and (not best or b.first > best.first or b.first == best.first and b.token > best.token) then best = b end
|
|
105
|
+
end
|
|
106
|
+
if best then
|
|
107
|
+
ref.binding = best.type and first == ref.tok - 2 and 'cs:type:' .. best.type .. '\0' .. (T.s[best.token] - 1) or 'cs:?'
|
|
108
|
+
elseif root == 'this' or root == 'base' then ref.binding = 'cs:self:' .. root .. '\0' .. (T.s[first] - 1)
|
|
109
|
+
else ref.binding = 'cs:owner:' .. (token_name(T, first, ref.tok - 2) or '?') .. '\0' .. (T.s[first] - 1) end
|
|
110
|
+
elseif ref.kind == 'call' then ref.binding = 'cs:call:\0' .. (T.s[ref.tok] - 1) end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
local function context(G, ctx)
|
|
115
|
+
ctx = ctx or {}
|
|
116
|
+
if ctx.csharp then return ctx.csharp end
|
|
117
|
+
local C = {}
|
|
118
|
+
ctx.csharp = C
|
|
119
|
+
function C.data(f) return ctx.ordinary and ctx.ordinary.data(f) or G.files[f] end
|
|
120
|
+
local directories, groups = {}, {}
|
|
121
|
+
local function directory_group(dir)
|
|
122
|
+
if directories[dir] ~= nil then return directories[dir] end
|
|
123
|
+
local found
|
|
124
|
+
if G.root then
|
|
125
|
+
local entries, truncated = xutils.list_dir(G.root .. (dir ~= '' and '/' .. dir or ''), 8192, true)
|
|
126
|
+
if truncated then directories[dir] = '!'; return '!' end
|
|
127
|
+
for _, entry in ipairs(entries or {}) do
|
|
128
|
+
if not entry.dir and entry.name:lower():match('%.csproj$') then
|
|
129
|
+
if found then directories[dir] = '!'; return '!' end
|
|
130
|
+
found = dir .. '/' .. entry.name
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
if not found and dir ~= '' then found = directory_group(dir:match('^(.*)/[^/]+$') or '') end
|
|
135
|
+
directories[dir] = found or '@workspace'
|
|
136
|
+
return directories[dir]
|
|
137
|
+
end
|
|
138
|
+
function C.group(f)
|
|
139
|
+
if not groups[f] then
|
|
140
|
+
local group = directory_group(G.files[f].path:match('^(.*)/[^/]+$') or '')
|
|
141
|
+
groups[f] = group == '!' and '!file:' .. f or group
|
|
142
|
+
end
|
|
143
|
+
return groups[f]
|
|
144
|
+
end
|
|
145
|
+
function C.same(f, g) return C.group(f) == C.group(g) end
|
|
146
|
+
local files = {}
|
|
147
|
+
for _, f in ipairs(G.file_order) do files[#files + 1] = f end
|
|
148
|
+
for _, f in ipairs(G.new_files or {}) do files[#files + 1] = f end
|
|
149
|
+
local global_candidates, namespaces = {}, {}
|
|
150
|
+
for _, f in ipairs(files) do
|
|
151
|
+
local rec = G.files[f]
|
|
152
|
+
if rec.language == 'csharp' then
|
|
153
|
+
control.check()
|
|
154
|
+
local group = C.group(f)
|
|
155
|
+
namespaces[group] = namespaces[group] or {}
|
|
156
|
+
for _, n in ipairs(rec.nodes) do
|
|
157
|
+
if n.kind == 'namespace' then
|
|
158
|
+
local scope = n.qualified
|
|
159
|
+
while scope and scope ~= '' do
|
|
160
|
+
namespaces[group][scope] = true; scope = scope:match('^(.*)%.[^.]+$')
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
local candidate = rec.ordinary_bindings
|
|
165
|
+
for _, imp in ipairs(rec.imports) do if imp.global then candidate = true; break end end
|
|
166
|
+
if candidate then
|
|
167
|
+
global_candidates[group] = global_candidates[group] or {}
|
|
168
|
+
global_candidates[group][#global_candidates[group] + 1] = f
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
function C.scope(f, at)
|
|
173
|
+
local scope, first = '', -1
|
|
174
|
+
for _, n in ipairs(C.data(f).csharp_scopes or {}) do
|
|
175
|
+
if n.first <= at and at <= n.last and n.first > first then scope, first = n.scope, n.first end
|
|
176
|
+
end
|
|
177
|
+
return scope
|
|
178
|
+
end
|
|
179
|
+
function C.active(f, at, exclude, no_global)
|
|
180
|
+
local out = {}
|
|
181
|
+
for _, d in ipairs(C.data(f).csharp_usings or {}) do
|
|
182
|
+
if not d.global and d.first <= at and at <= d.last and d.first ~= exclude then out[#out + 1] = { file = f, directive = d } end
|
|
183
|
+
end
|
|
184
|
+
if not no_global then
|
|
185
|
+
for _, g in ipairs(global_candidates[C.group(f)] or {}) do
|
|
186
|
+
for _, d in ipairs(C.data(g).csharp_usings or {}) do
|
|
187
|
+
if d.global and d.scope == '' then out[#out + 1] = { file = g, directive = d } end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
return out
|
|
192
|
+
end
|
|
193
|
+
function C.exact(f, name)
|
|
194
|
+
local ids = {}
|
|
195
|
+
for _, id in ipairs(G.by_name[name:match('([^.]+)$')] or {}) do
|
|
196
|
+
local n, g = G.nodes[id], G.node_file[id]
|
|
197
|
+
if n.qualified == name and types[n.kind] and G.files[g].language == 'csharp' and C.same(f, g) then ids[#ids + 1] = id end
|
|
198
|
+
end
|
|
199
|
+
return ids
|
|
200
|
+
end
|
|
201
|
+
function C.namespace(f, name)
|
|
202
|
+
return namespaces[C.group(f)] and namespaces[C.group(f)][name] or false
|
|
203
|
+
end
|
|
204
|
+
function C.namespace_children(f, namespace)
|
|
205
|
+
local result = {}
|
|
206
|
+
local prefix = namespace ~= '' and namespace .. '.' or ''
|
|
207
|
+
for name in pairs(namespaces[C.group(f)] or {}) do
|
|
208
|
+
if name:sub(1, #prefix) == prefix then
|
|
209
|
+
local suffix = name:sub(#prefix + 1)
|
|
210
|
+
if not suffix:find('.', 1, true) and suffix ~= '' then result[#result + 1] = suffix end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
table.sort(result)
|
|
214
|
+
return result
|
|
215
|
+
end
|
|
216
|
+
return C
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
-- Result: type ids, resolved namespace (if any), and whether a binding was known.
|
|
220
|
+
function M.types(G, f, name, at, ctx, options)
|
|
221
|
+
local C = context(G, ctx)
|
|
222
|
+
options = options or {}
|
|
223
|
+
name = M.name(name)
|
|
224
|
+
if not name then return {}, nil, true end
|
|
225
|
+
at = at or 0
|
|
226
|
+
local active = C.active(f, at, options.exclude, options.no_global)
|
|
227
|
+
local qualifier, rest = name:match('^([%w_]+)::(.*)$')
|
|
228
|
+
if qualifier == 'global' then
|
|
229
|
+
return C.exact(f, rest), C.namespace(f, rest) and rest or nil, true
|
|
230
|
+
end
|
|
231
|
+
local head, tail = (rest or name):match('^([^.]+)%.(.*)$')
|
|
232
|
+
head = qualifier or head or name
|
|
233
|
+
if qualifier then tail = rest end
|
|
234
|
+
if not qualifier then
|
|
235
|
+
for _, parameter in ipairs(C.data(f).csharp_parameters or {}) do
|
|
236
|
+
if parameter.name == head and parameter.first <= at and at <= parameter.last then return {}, nil, true end
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
local aliases, priority = {}, -2
|
|
240
|
+
for _, entry in ipairs(active) do
|
|
241
|
+
local d = entry.directive
|
|
242
|
+
if clean(d.alias) == head then
|
|
243
|
+
local rank = d.global and -1 or d.first
|
|
244
|
+
if rank > priority then aliases, priority = {}, rank end
|
|
245
|
+
if rank == priority then aliases[#aliases + 1] = entry end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
if #aliases > 0 then
|
|
249
|
+
if #aliases ~= 1 or (options.depth or 0) >= 8 then return {}, nil, true end
|
|
250
|
+
local entry = aliases[1]
|
|
251
|
+
local d = entry.directive
|
|
252
|
+
if not d.global and d.scope == '' then
|
|
253
|
+
for _, other in ipairs(active) do
|
|
254
|
+
if other.directive.global and clean(other.directive.alias) == head then return {}, nil, true end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
-- A nested type is looked up before a using alias from an enclosing
|
|
258
|
+
-- namespace/file. The explicit alias:: form still selects the alias.
|
|
259
|
+
if not qualifier then
|
|
260
|
+
local scope = options.scope or C.scope(f, at)
|
|
261
|
+
while scope ~= '' and scope ~= d.scope do
|
|
262
|
+
local q = scope .. '.' .. name
|
|
263
|
+
local ids, namespace = C.exact(f, q), C.namespace(f, q)
|
|
264
|
+
if #ids > 0 or namespace then return ids, namespace and q or nil, true end
|
|
265
|
+
if #C.exact(f, scope .. '.' .. head) > 0 then return {}, nil, true end
|
|
266
|
+
scope = scope:match('^(.*)%.[^.]+$') or ''
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
local ids, namespace = M.types(G, entry.file, d.path, d.first, ctx,
|
|
270
|
+
{ exclude = d.first, no_global = true, scope = d.scope, depth = (options.depth or 0) + 1 })
|
|
271
|
+
local target = namespace or (#ids > 0 and G.nodes[ids[1]].qualified)
|
|
272
|
+
if not target or qualifier and not namespace then return {}, nil, true end
|
|
273
|
+
if tail then target = target .. '.' .. tail end
|
|
274
|
+
return C.exact(f, target), C.namespace(f, target) and target or nil, true
|
|
275
|
+
end
|
|
276
|
+
if qualifier then return {}, nil, true end -- extern aliases require assembly identity
|
|
277
|
+
local scope = options.scope or C.scope(f, at)
|
|
278
|
+
while true do
|
|
279
|
+
local q = (scope ~= '' and scope .. '.' or '') .. name
|
|
280
|
+
local ids = C.exact(f, q)
|
|
281
|
+
if #ids > 0 or C.namespace(f, q) then return ids, C.namespace(f, q) and q or nil, true end
|
|
282
|
+
if scope == '' then break end
|
|
283
|
+
scope = scope:match('^(.*)%.[^.]+$') or ''
|
|
284
|
+
end
|
|
285
|
+
local ids, seen = {}, {}
|
|
286
|
+
for _, entry in ipairs(active) do
|
|
287
|
+
local d = entry.directive
|
|
288
|
+
if not d.alias then
|
|
289
|
+
if (options.depth or 0) < 8 then
|
|
290
|
+
local owners, path = M.types(G, entry.file, d.path, d.first, ctx,
|
|
291
|
+
{ exclude = d.first, no_global = true, scope = d.scope, depth = (options.depth or 0) + 1 })
|
|
292
|
+
if d.static then
|
|
293
|
+
for _, owner in ipairs(owners) do
|
|
294
|
+
for _, id in ipairs(C.exact(f, G.nodes[owner].qualified .. '.' .. name)) do
|
|
295
|
+
if not seen[id] then seen[id] = true; ids[#ids + 1] = id end
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
elseif path then
|
|
299
|
+
for _, id in ipairs(C.exact(f, path .. '.' .. name)) do if not seen[id] then seen[id] = true; ids[#ids + 1] = id end end
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
return ids, nil, #ids > 0
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
function M.members(G, f, ids, name, static, ctx, depth, seen, access_scope)
|
|
308
|
+
depth, seen = depth or 0, seen or {}
|
|
309
|
+
local C, out, emitted = context(G, ctx), {}, {}
|
|
310
|
+
for _, cls in ipairs(ids) do
|
|
311
|
+
if not seen[cls] and depth <= 8 then
|
|
312
|
+
seen[cls] = true
|
|
313
|
+
local found = false
|
|
314
|
+
for _, id in ipairs(G.by_name[name] or {}) do
|
|
315
|
+
local n, g = G.nodes[id], G.node_file[id]
|
|
316
|
+
if callable[n.kind] and n.qualified == G.nodes[cls].qualified .. '.' .. name
|
|
317
|
+
and G.files[g].language == 'csharp' and C.same(f, g) then
|
|
318
|
+
local data, index = C.data(g), id - G.id_of[g][1] + 1
|
|
319
|
+
local is_static, access = (data.csharp_statics or {})[index] or false, (data.csharp_access or {})[index]
|
|
320
|
+
local owner = G.nodes[cls].qualified
|
|
321
|
+
local own = access_scope and (access_scope == owner or access_scope:sub(1, #owner + 1) == owner .. '.')
|
|
322
|
+
if (static == nil or is_static == static) and (access == 'public' or access == 'internal' or own) then
|
|
323
|
+
if not emitted[id] then emitted[id] = true; out[#out + 1] = id end
|
|
324
|
+
found = true
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
if not found and static ~= true then
|
|
329
|
+
for _, base in ipairs(G.nodes[cls].bases or {}) do
|
|
330
|
+
local g = G.node_file[cls]
|
|
331
|
+
local at = 0
|
|
332
|
+
for _, scope in ipairs(C.data(g).csharp_scopes or {}) do if scope.scope == G.nodes[cls].qualified then at = scope.first; break end end
|
|
333
|
+
local more = M.types(G, g, base, at, ctx, { scope = G.nodes[cls].qualified:match('^(.*)%.[^.]+$') or '' })
|
|
334
|
+
for _, id in ipairs(M.members(G, f, more, name, static, ctx, depth + 1, seen, access_scope)) do
|
|
335
|
+
if not emitted[id] then emitted[id] = true; out[#out + 1] = id end
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
end
|
|
341
|
+
return out
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
function M.resolve(G, f, src, name, kind, recv, evidence, ctx)
|
|
345
|
+
if not evidence or evidence:sub(1, 3) ~= 'cs:' then return nil end
|
|
346
|
+
local tag, value, offset = evidence:match('^cs:(%w+):(.-)%z(%d+)$')
|
|
347
|
+
if not tag then return {} end
|
|
348
|
+
local at, C = tonumber(offset), context(G, ctx)
|
|
349
|
+
local access_scope = C.scope(f, at)
|
|
350
|
+
if tag == 'new' then
|
|
351
|
+
local result = {}
|
|
352
|
+
for _, cls in ipairs(M.types(G, f, value, at, ctx)) do
|
|
353
|
+
local n, explicit = G.nodes[cls], false
|
|
354
|
+
for _, id in ipairs(G.by_name[n.name] or {}) do
|
|
355
|
+
if G.nodes[id].kind == 'constructor' and G.nodes[id].qualified == n.qualified .. '.' .. n.name
|
|
356
|
+
and C.same(f, G.node_file[id]) then explicit = true; break end
|
|
357
|
+
end
|
|
358
|
+
if explicit then
|
|
359
|
+
for _, id in ipairs(M.members(G, f, { cls }, n.name, false, ctx, nil, nil, access_scope)) do result[#result + 1] = id end
|
|
360
|
+
else result[#result + 1] = cls end
|
|
361
|
+
end
|
|
362
|
+
return result
|
|
363
|
+
end
|
|
364
|
+
if tag == 'name' then
|
|
365
|
+
local ids, namespace, known = M.types(G, f, value, at, ctx)
|
|
366
|
+
if namespace then
|
|
367
|
+
for _, id in ipairs(G.by_name[namespace:match('([^.]+)$')] or {}) do
|
|
368
|
+
if G.nodes[id].kind == 'namespace' and G.nodes[id].qualified == namespace and C.same(f, G.node_file[id]) then ids[#ids + 1] = id end
|
|
369
|
+
end
|
|
370
|
+
end
|
|
371
|
+
if known then return ids end
|
|
372
|
+
return nil
|
|
373
|
+
end
|
|
374
|
+
if tag == 'self' then
|
|
375
|
+
local scope = src and G.nodes[src].qualified:match('^(.*)%.[^.]+$') or C.scope(f, at)
|
|
376
|
+
local owners = C.exact(f, scope)
|
|
377
|
+
if value == 'base' then
|
|
378
|
+
local bases = {}
|
|
379
|
+
for _, id in ipairs(owners) do
|
|
380
|
+
for _, base in ipairs(G.nodes[id].bases or {}) do
|
|
381
|
+
for _, target in ipairs(M.types(G, f, base, at, ctx)) do bases[#bases + 1] = target end
|
|
382
|
+
end
|
|
383
|
+
end
|
|
384
|
+
owners = bases
|
|
385
|
+
end
|
|
386
|
+
return M.members(G, f, owners, name, false, ctx, nil, nil, access_scope)
|
|
387
|
+
end
|
|
388
|
+
if tag == 'type' or tag == 'owner' then
|
|
389
|
+
local ids, _, known = M.types(G, f, value, at, ctx)
|
|
390
|
+
if tag == 'type' or known then return M.members(G, f, ids, name, tag == 'owner', ctx, nil, nil, access_scope) end
|
|
391
|
+
return nil
|
|
392
|
+
end
|
|
393
|
+
if tag == 'call' then
|
|
394
|
+
local owner = src and G.nodes[src].qualified:match('^(.*)%.[^.]+$')
|
|
395
|
+
if owner then
|
|
396
|
+
local own = M.members(G, f, C.exact(f, owner), name, nil, ctx, nil, nil, access_scope)
|
|
397
|
+
if #own > 0 then return own end
|
|
398
|
+
end
|
|
399
|
+
local out, known, seen = {}, false, {}
|
|
400
|
+
for _, entry in ipairs(C.active(f, at)) do
|
|
401
|
+
local d = entry.directive
|
|
402
|
+
if d.static then
|
|
403
|
+
known = true
|
|
404
|
+
local ids = M.types(G, entry.file, d.path, d.first, ctx, { exclude = d.first, no_global = true, scope = d.scope })
|
|
405
|
+
for _, id in ipairs(M.members(G, f, ids, name, true, ctx, nil, nil, access_scope)) do
|
|
406
|
+
if not seen[id] then seen[id] = true; out[#out + 1] = id end
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
if known then return out end
|
|
411
|
+
end
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
function M.incoming_aliases(G, f, wanted, ctx)
|
|
415
|
+
local hits, possible = {}, false
|
|
416
|
+
for id in pairs(wanted) do
|
|
417
|
+
if G.files[G.node_file[id]].language == 'csharp' and (types[G.nodes[id].kind] or G.nodes[id].kind == 'constructor') then possible = true; break end
|
|
418
|
+
end
|
|
419
|
+
if not possible then return hits end
|
|
420
|
+
local C, relevant = context(G, ctx), false
|
|
421
|
+
for id in pairs(wanted) do
|
|
422
|
+
local kind = G.nodes[id].kind
|
|
423
|
+
if G.files[G.node_file[id]].language == 'csharp' and (types[kind] or kind == 'constructor') and C.same(f, G.node_file[id]) then relevant = true; break end
|
|
424
|
+
end
|
|
425
|
+
if not relevant then return hits end
|
|
426
|
+
local refs = G.files[f].refs
|
|
427
|
+
for i, kind in ipairs(refs.kind) do
|
|
428
|
+
if kind == 'new' then
|
|
429
|
+
control.check()
|
|
430
|
+
local value = ctx.ordinary.evidence(f, i)
|
|
431
|
+
for _, id in ipairs(M.resolve(G, f, nil, refs.name[i], kind, refs.recv[i], value, ctx) or {}) do
|
|
432
|
+
if wanted[id] then hits[i] = true; break end
|
|
433
|
+
end
|
|
434
|
+
end
|
|
435
|
+
end
|
|
436
|
+
return hits
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
function M.usings(G, f, at, ctx)
|
|
440
|
+
return context(G, ctx).active(f, at)
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
function M.is_static(G, id, ctx)
|
|
444
|
+
local g, C = G.node_file[id], context(G, ctx)
|
|
445
|
+
return (C.data(g).csharp_statics or {})[id - G.id_of[g][1] + 1] or false
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
function M.static_node(G, f, node, ctx)
|
|
449
|
+
for _, id in ipairs(G.by_name[node.name] or {}) do
|
|
450
|
+
local n = G.nodes[id]
|
|
451
|
+
if G.node_file[id] == f and n.qualified == node.qualified and n.line == node.line and n.kind == node.kind then
|
|
452
|
+
return M.is_static(G, id, ctx)
|
|
453
|
+
end
|
|
454
|
+
end
|
|
455
|
+
return false
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
function M.visible_node(G, caller, f, node, at, ctx)
|
|
459
|
+
local C = context(G, ctx)
|
|
460
|
+
for _, id in ipairs(G.by_name[node.name] or {}) do
|
|
461
|
+
local n = G.nodes[id]
|
|
462
|
+
if G.node_file[id] == f and n.qualified == node.qualified and n.line == node.line and n.kind == node.kind then
|
|
463
|
+
local access = (C.data(f).csharp_access or {})[id - G.id_of[f][1] + 1]
|
|
464
|
+
local owner, scope = n.qualified:match('^(.*)%.[^.]+$'), C.scope(caller, at)
|
|
465
|
+
return access == 'public' or access == 'internal' or owner and (scope == owner or scope:sub(1, #owner + 1) == owner .. '.')
|
|
466
|
+
end
|
|
467
|
+
end
|
|
468
|
+
return false
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
-- Namespace alias completion uses the same type/namespace target as navigation.
|
|
472
|
+
function M.namespace_members(G, f, namespace, ctx)
|
|
473
|
+
local C, out, seen = context(G, ctx), {}, {}
|
|
474
|
+
local prefix = namespace ~= '' and namespace .. '.' or ''
|
|
475
|
+
-- A dotted namespace declaration need not contain a separate node for
|
|
476
|
+
-- each enclosing namespace (namespace A.B still exposes A then B).
|
|
477
|
+
for _, name in ipairs(C.namespace_children(f, namespace)) do
|
|
478
|
+
seen[name] = true
|
|
479
|
+
out[#out + 1] = { name = name, kind = 'namespace', node = { kind = 'namespace', name = name, qualified = prefix .. name } }
|
|
480
|
+
end
|
|
481
|
+
local files = {}
|
|
482
|
+
for _, g in ipairs(G.file_order) do files[#files + 1] = g end
|
|
483
|
+
for _, g in ipairs(G.new_files or {}) do files[#files + 1] = g end
|
|
484
|
+
for _, g in ipairs(files) do
|
|
485
|
+
if G.files[g].language == 'csharp' and C.same(f, g) then
|
|
486
|
+
for _, id in ipairs(G.id_of[g]) do
|
|
487
|
+
local n = G.nodes[id]
|
|
488
|
+
local suffix = n.qualified:sub(1, #prefix) == prefix and n.qualified:sub(#prefix + 1)
|
|
489
|
+
if suffix and not suffix:find('.', 1, true) and (types[n.kind] or n.kind == 'namespace') and not seen[suffix] then
|
|
490
|
+
seen[suffix] = true; out[#out + 1] = { name = suffix, kind = n.kind, node = n, file = g }
|
|
491
|
+
end
|
|
492
|
+
end
|
|
493
|
+
end
|
|
494
|
+
end
|
|
495
|
+
return out
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
return M
|