@codua/codeoutline-win32-x64 0.3.6 → 0.3.8
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/editors/codeoutline.vsix +0 -0
- package/editors/zed/extension.wasm +0 -0
- package/package.json +1 -1
- package/scripts/codeoutline/analysis/csharp/csharp_bindings.lua +77 -40
- package/scripts/codeoutline/analysis/graph.lua +2 -0
- package/scripts/codeoutline/analysis/implementations.lua +2 -0
- package/scripts/codeoutline/analysis/lua/lua_bindings.lua +206 -25
- package/scripts/codeoutline/analysis/receivers.lua +181 -16
- package/scripts/codeoutline/lang/lua.lua +3 -2
- package/scripts/codeoutline/query/completion.lua +11 -1
- package/scripts/codeoutline/query/definition_candidates.lua +81 -59
- package/scripts/codeoutline/query/navigation.lua +162 -23
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
|
@@ -10,7 +10,7 @@ function M.at(meta, name, offset)
|
|
|
10
10
|
local best, index, future
|
|
11
11
|
for _, i in ipairs(meta and meta.by_name[name] or {}) do
|
|
12
12
|
local b = meta.bindings[i]
|
|
13
|
-
if b.first <= offset and offset < b.last and b.at <= offset
|
|
13
|
+
if b.first <= offset and offset < b.last and b.at <= offset and (not b.branch_end or offset < b.branch_end)
|
|
14
14
|
and (not best or b.first > best.first or b.first == best.first and b.at > best.at) then best, index = b, i end
|
|
15
15
|
if b.hoisted and b.first <= offset and offset < b.last and b.at > offset
|
|
16
16
|
and (not future or b.first > future.first) then future = b end
|
|
@@ -19,19 +19,131 @@ function M.at(meta, name, offset)
|
|
|
19
19
|
return best, index
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
-- Collect simple if/else joins using existing delimiter matches. Assignments in
|
|
23
|
+
-- compound bodies stay with the language's ordinary lexical analysis.
|
|
24
|
+
local function join_conditionals(T, language, assignments, meta, add)
|
|
25
|
+
local python = language == 'python'
|
|
26
|
+
local function text(i) return T:text(i) end
|
|
27
|
+
local function end_offset(close) return python and T.s[close] - 1 or T.e[close] end
|
|
28
|
+
local function arm_at(i)
|
|
29
|
+
if python then
|
|
30
|
+
local limit = i + 128
|
|
31
|
+
while i <= T.n and T.k[i] ~= 'nl' do
|
|
32
|
+
if i > limit then return nil end
|
|
33
|
+
i = (T.m[i] and T.m[i] > i and T.m[i] or i) + 1
|
|
34
|
+
end
|
|
35
|
+
i = i + 1
|
|
36
|
+
if T.k[i] ~= 'indent' then return nil end
|
|
37
|
+
else
|
|
38
|
+
if text(i) == '(' then i = T.m[i] and T.m[i] + 1 or i end
|
|
39
|
+
if text(i) ~= '{' then return nil end
|
|
40
|
+
end
|
|
41
|
+
local close = T.m[i]
|
|
42
|
+
if not close then return nil end
|
|
43
|
+
local first = i + 1
|
|
44
|
+
while T.k[first] == 'nl' do first = first + 1 end
|
|
45
|
+
if first == close or (python and text(first) == 'pass' and first + 2 == close) then return close end
|
|
46
|
+
local b = assignments[first]
|
|
47
|
+
if not b or text(first + 1) ~= '=' then return nil end
|
|
48
|
+
-- Check that the assignment occupies the arm. A second statement or
|
|
49
|
+
-- a nested block needs richer control-flow analysis.
|
|
50
|
+
local j = first + 2
|
|
51
|
+
while j < close and text(j) ~= ';' and T.k[j] ~= 'nl' do
|
|
52
|
+
if j > first + 128 then return nil end
|
|
53
|
+
if text(j) == '{' and not T.m[j] then return nil end
|
|
54
|
+
if not python and j > first + 2 and T.l[j] > T.el[j - 1] then return nil end
|
|
55
|
+
j = (T.m[j] and T.m[j] > j and T.m[j] or j) + 1
|
|
56
|
+
end
|
|
57
|
+
local last = j
|
|
58
|
+
if text(j) == ';' then j = j + 1 end
|
|
59
|
+
while T.k[j] == 'nl' do j = j + 1 end
|
|
60
|
+
if j ~= close then return nil end
|
|
61
|
+
local value = first + 2
|
|
62
|
+
if not python and text(value) == 'new' then value = value + 1 end
|
|
63
|
+
value = value + 1
|
|
64
|
+
while text(value) == '.' and T.k[value + 1] == 'id' do value = value + 2 end
|
|
65
|
+
if text(value) == '(' and T.m[value] then value = T.m[value] + 1 end
|
|
66
|
+
return close, b, value == last
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
local blocks = {}
|
|
70
|
+
for i = 1, T.n do
|
|
71
|
+
if i % 1024 == 0 then control.check() end
|
|
72
|
+
while blocks[#blocks] and blocks[#blocks] <= i do blocks[#blocks] = nil end
|
|
73
|
+
if (python and T.k[i] == 'indent' or not python and text(i) == '{') and T.m[i] and T.m[i] > i then
|
|
74
|
+
blocks[#blocks + 1] = T.m[i]
|
|
75
|
+
end
|
|
76
|
+
if T.k[i] == 'kw' and text(i) == 'if' and (python and (i == 1 or T.k[i - 1] == 'nl'
|
|
77
|
+
or T.k[i - 1] == 'indent' or T.k[i - 1] == 'dedent') or not python and text(i - 1) ~= 'else') then
|
|
78
|
+
local arms, next_arm, has_else = {}, i + 1, false
|
|
79
|
+
while next_arm and #arms < 8 do
|
|
80
|
+
local close, assignment, simple_value = arm_at(next_arm)
|
|
81
|
+
if not close then break end
|
|
82
|
+
arms[#arms + 1] = { close = close, assignment = assignment, simple_value = simple_value }
|
|
83
|
+
local after = close + (python and 0 or 1)
|
|
84
|
+
if python and T.k[after] == 'dedent' then after = after + 1 end
|
|
85
|
+
if python and text(after) == 'elif' then next_arm = after + 1
|
|
86
|
+
elseif text(after) == 'else' and not has_else then
|
|
87
|
+
has_else = python or text(after + 1) ~= 'if'
|
|
88
|
+
next_arm = after + (has_else and 1 or 2)
|
|
89
|
+
else next_arm = nil end
|
|
90
|
+
end
|
|
91
|
+
if not next_arm then
|
|
92
|
+
local writes, count = {}, {}
|
|
93
|
+
for _, arm in ipairs(arms) do
|
|
94
|
+
local b = arm.assignment
|
|
95
|
+
if b then writes[b.name] = b; count[b.name] = (count[b.name] or 0) + 1 end
|
|
96
|
+
end
|
|
97
|
+
for name, sample in pairs(writes) do
|
|
98
|
+
local before = M.at(meta, name, T.s[i] - 1)
|
|
99
|
+
if python and before and before.blocked and not before.name then before = nil end
|
|
100
|
+
if python or before and not before.blocked and before.first < sample.first then
|
|
101
|
+
local values, seen, unknown, empty = {}, {}, false, false
|
|
102
|
+
local function include(b)
|
|
103
|
+
if not b or b.empty then empty = true end
|
|
104
|
+
if not b then return end
|
|
105
|
+
for _, value in ipairs(b.alternatives or { b }) do
|
|
106
|
+
if value.type or value.owner then
|
|
107
|
+
local key = (value.type or '') .. '\0' .. tostring(value.owner) .. '\0' .. tostring(value.static)
|
|
108
|
+
if not seen[key] then seen[key] = true; values[#values + 1] = value end
|
|
109
|
+
elseif not value.empty then unknown = true end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
if not has_else or count[name] < #arms then include(before) end
|
|
113
|
+
for _, arm in ipairs(arms) do
|
|
114
|
+
local b = arm.assignment
|
|
115
|
+
if b and b.name == name then
|
|
116
|
+
if arm.simple_value then include(b) else unknown = true end
|
|
117
|
+
if python then b.branch_end = end_offset(arm.close) end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
local close = arms[#arms].close
|
|
121
|
+
local scope = python and sample or before
|
|
122
|
+
local parent_end = blocks[#blocks]
|
|
123
|
+
local last = parent_end and math.min(scope.last, end_offset(parent_end)) or scope.last
|
|
124
|
+
local value = not unknown and #values <= 8 and { alternatives = values, empty = empty } or { blocked = true }
|
|
125
|
+
add(name, close, scope.first, last, value, end_offset(close))
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
22
133
|
function M.collect(r, T)
|
|
23
134
|
local language = r.language
|
|
24
135
|
if language ~= 'python' and language ~= 'kotlin' and not js(language) then return end
|
|
25
136
|
local meta = { bindings = {}, by_name = {}, statics = {}, fields = {}, weight = 128 }
|
|
26
137
|
r.receivers = meta
|
|
27
|
-
local function add(name, token, first, last, value)
|
|
138
|
+
local function add(name, token, first, last, value, at)
|
|
28
139
|
if #meta.bindings >= M.MAX_BINDINGS then meta.incomplete = true; return end
|
|
29
|
-
local b = { name = name, at = token > 0 and T.s[token] - 1 or 0, first = first, last = last,
|
|
140
|
+
local b = { name = name, at = at or (token > 0 and T.s[token] - 1 or 0), first = first, last = last,
|
|
30
141
|
owner = value and value.owner, type = value and value.type, static = value and value.static,
|
|
31
|
-
super = value and value.super
|
|
142
|
+
super = value and value.super, alternatives = value and value.alternatives,
|
|
143
|
+
empty = value and value.empty, blocked = value and value.blocked }
|
|
32
144
|
local n = #meta.bindings + 1; meta.bindings[n] = b
|
|
33
145
|
meta.by_name[name] = meta.by_name[name] or {}; table.insert(meta.by_name[name], n)
|
|
34
|
-
meta.weight = meta.weight + 192 + #name + #(b.type or '')
|
|
146
|
+
meta.weight = meta.weight + 192 + #name + #(b.type or '') + 16 * #(b.alternatives or {})
|
|
35
147
|
if name == 'this' and js(language) then
|
|
36
148
|
add('super', token, first, last, { owner = b.owner, type = b.type, static = b.static, super = true })
|
|
37
149
|
end
|
|
@@ -53,6 +165,7 @@ function M.collect(r, T)
|
|
|
53
165
|
while text(j) == '.' and T.k[j + 1] == 'id' do parts[#parts + 1] = text(j + 1); j = j + 2 end
|
|
54
166
|
return table.concat(parts, '.'), j
|
|
55
167
|
end
|
|
168
|
+
local assignments = {}
|
|
56
169
|
if language == 'kotlin' then
|
|
57
170
|
local declarations = {}
|
|
58
171
|
for _, node in ipairs(r.nodes) do
|
|
@@ -142,11 +255,12 @@ function M.collect(r, T)
|
|
|
142
255
|
local value
|
|
143
256
|
if next == '=' or next == ':=' then
|
|
144
257
|
local name, after = written(i + 2)
|
|
145
|
-
if
|
|
258
|
+
if text(i + 2) == 'None' and (T.k[i + 3] == 'nl' or text(i + 3) == ';') then value = { empty = true }
|
|
259
|
+
elseif name and text(after) == '(' then value = { type = name }
|
|
146
260
|
elseif name then value = M.at(meta, name, T.s[i] - 1) end
|
|
147
261
|
end
|
|
148
262
|
local b = add(text(i), i, first, last, value)
|
|
149
|
-
if b then b.hoisted = true end
|
|
263
|
+
if b then b.hoisted = true; if next == '=' then assignments[i] = b end end
|
|
150
264
|
end
|
|
151
265
|
if T.k[i] == 'id' and prev == 'for' and next == 'in' and depth > 0 then
|
|
152
266
|
local open = brackets[#brackets]
|
|
@@ -212,6 +326,10 @@ function M.collect(r, T)
|
|
|
212
326
|
local bindings = {}
|
|
213
327
|
for _, list in pairs(T.js_bindings or {}) do for _, b in ipairs(list) do bindings[#bindings + 1] = b end end
|
|
214
328
|
table.sort(bindings, function(a, b) return a.token < b.token end)
|
|
329
|
+
local function ends_statement(i)
|
|
330
|
+
return text(i) == ';' or text(i) == '}' or text(i) == ''
|
|
331
|
+
or (T.k[i] == 'id' or T.k[i] == 'kw') and T.l[i] > T.el[i - 1]
|
|
332
|
+
end
|
|
215
333
|
for _, b in ipairs(bindings) do
|
|
216
334
|
local first = b.a > 0 and T.s[b.a] - 1 or 0
|
|
217
335
|
local last = b.b > 0 and T.e[b.b] + 1 or #T.src + 1
|
|
@@ -219,10 +337,25 @@ function M.collect(r, T)
|
|
|
219
337
|
if text(b.token + 1) == '=' and (text(b.token + 2) == 'this' or T.k[b.token + 2] == 'id') then
|
|
220
338
|
value = value or M.at(meta, text(b.token + 2), T.s[b.token] - 1)
|
|
221
339
|
end
|
|
340
|
+
if not value then
|
|
341
|
+
local tail = b.token + 1
|
|
342
|
+
local _, after = written(b.token + 2)
|
|
343
|
+
if text(tail) == ':' and after and text(after) == '|'
|
|
344
|
+
and (text(after + 1) == 'undefined' or text(after + 1) == 'null') then tail = after + 2 end
|
|
345
|
+
local nil_value = text(tail + 1) == 'null' or text(tail + 1) == 'undefined'
|
|
346
|
+
and not M.at(meta, 'undefined', T.s[b.token] - 1)
|
|
347
|
+
if b.declaration and ends_statement(tail) or text(tail) == '=' and nil_value and ends_statement(tail + 2) then
|
|
348
|
+
value = { empty = true }
|
|
349
|
+
end
|
|
350
|
+
end
|
|
222
351
|
local added = add(b.name, b.token, first, last, value)
|
|
223
|
-
if added then
|
|
352
|
+
if added then
|
|
353
|
+
added.hoisted = b.declaration
|
|
354
|
+
if not b.declaration then assignments[b.token] = added end
|
|
355
|
+
end
|
|
224
356
|
end
|
|
225
357
|
end
|
|
358
|
+
if next(assignments) then join_conditionals(T, language, assignments, meta, add) end
|
|
226
359
|
for _, ref in ipairs(r.refs) do
|
|
227
360
|
if ref.recv and text(ref.tok - 3) ~= '.' and text(ref.tok - 3) ~= '?.' then
|
|
228
361
|
local name = ref.recv
|
|
@@ -291,6 +424,19 @@ end
|
|
|
291
424
|
|
|
292
425
|
local function from_binding(G, f, b, ctx)
|
|
293
426
|
if not b then return nil end
|
|
427
|
+
if b.alternatives then
|
|
428
|
+
local ids, seen, static = {}, {}, nil
|
|
429
|
+
for _, alternative in ipairs(b.alternatives) do
|
|
430
|
+
local target = from_binding(G, f, alternative, ctx)
|
|
431
|
+
local mode = target.static == true
|
|
432
|
+
if #target.ids == 0 or static ~= nil and static ~= mode then ids = {}; break end
|
|
433
|
+
static = mode
|
|
434
|
+
for _, id in ipairs(target.ids) do
|
|
435
|
+
if not seen[id] then seen[id] = true; ids[#ids + 1] = id end
|
|
436
|
+
end
|
|
437
|
+
end
|
|
438
|
+
return { kind = 'types', ids = ids, static = static, language = G.files[f].language, file = f }
|
|
439
|
+
end
|
|
294
440
|
local ids = b.owner and { G.id_of[f][b.owner] } or M.types(G, f, b.type, ctx)
|
|
295
441
|
if b.super then
|
|
296
442
|
local bases = {}
|
|
@@ -357,7 +503,7 @@ local function field_visible(target, bound)
|
|
|
357
503
|
end
|
|
358
504
|
|
|
359
505
|
function M.member_ids(G, target, name, ctx, accept)
|
|
360
|
-
local result = {}
|
|
506
|
+
local result, emitted = {}, {}
|
|
361
507
|
for _, cls in ipairs(target.ids or {}) do
|
|
362
508
|
local chain = ancestors(G, cls, ctx)
|
|
363
509
|
for _, id in ipairs(chain or {}) do
|
|
@@ -381,7 +527,12 @@ function M.member_ids(G, target, name, ctx, accept)
|
|
|
381
527
|
end
|
|
382
528
|
end
|
|
383
529
|
end
|
|
384
|
-
if shadowed then
|
|
530
|
+
if shadowed then
|
|
531
|
+
for _, mid in ipairs(found) do
|
|
532
|
+
if not emitted[mid] then emitted[mid] = true; result[#result + 1] = mid end
|
|
533
|
+
end
|
|
534
|
+
break
|
|
535
|
+
end
|
|
385
536
|
end
|
|
386
537
|
end
|
|
387
538
|
return result
|
|
@@ -414,7 +565,9 @@ function M.binding(G, f, src, name, ctx, options)
|
|
|
414
565
|
local index = options.evidence and tonumber(options.evidence:match('^receiver:(%d+)$'))
|
|
415
566
|
local b = index == 0 and { blocked = true } or index and meta and meta.bindings[index]
|
|
416
567
|
or options.offset and M.at(meta, name, options.offset)
|
|
417
|
-
if b and (index or b.blocked or b.owner or b.type or language == 'python' or name == 'this') then
|
|
568
|
+
if b and (index or b.blocked or b.empty or b.owner or b.type or b.alternatives or language == 'python' or name == 'this') then
|
|
569
|
+
return from_binding(G, f, b, ctx)
|
|
570
|
+
end
|
|
418
571
|
if js(language) and (name == 'this' or name == 'super') or language == 'python' and (name == 'self' or name == 'cls') then
|
|
419
572
|
return { kind = 'types', ids = {}, language = language, file = f }
|
|
420
573
|
end
|
|
@@ -429,10 +582,16 @@ function M.binding(G, f, src, name, ctx, options)
|
|
|
429
582
|
if info and info.static or G.nodes[src].static then ids = {} end
|
|
430
583
|
end
|
|
431
584
|
if language == 'kotlin' and src and G.nodes[src].receiver then ids = M.types(G, f, G.nodes[src].receiver, ctx) end
|
|
432
|
-
if name ~= 'this' then
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
585
|
+
if name ~= 'this' and #ids > 0 then
|
|
586
|
+
if language == 'csharp' then
|
|
587
|
+
ids = require('codeoutline.analysis.csharp.csharp_bindings').base_classes(G, ids, ctx)
|
|
588
|
+
else
|
|
589
|
+
local node = cls and G.nodes[cls]
|
|
590
|
+
local bases = node and (language == 'java' and node.extends or node.bases)
|
|
591
|
+
ids = {}
|
|
592
|
+
for _, base in ipairs(bases or {}) do
|
|
593
|
+
for _, id in ipairs(M.types(G, f, base, ctx, node.qualified)) do ids[#ids + 1] = id end
|
|
594
|
+
end
|
|
436
595
|
end
|
|
437
596
|
end
|
|
438
597
|
return { kind = 'types', ids = ids, language = language, file = f }
|
|
@@ -448,6 +607,7 @@ function M.resolve(G, f, src, name, kind, recv, evidence, ctx, accept, offset)
|
|
|
448
607
|
return require('codeoutline.analysis.go.go_modules').resolve(G, f, name, recv, ctx)
|
|
449
608
|
end
|
|
450
609
|
if evidence == '?' or evidence == 'py:?' then return nil end
|
|
610
|
+
if language == 'java' and recv == 'super' and evidence == 'jvm:?' then return {}, 'receiver: qualified Java super' end
|
|
451
611
|
if language == 'lua' and (recv == 'self' or evidence and evidence:match('^lua%-self:')) then
|
|
452
612
|
local ids = require('codeoutline.analysis.lua.lua_bindings').resolve(G, f, name, evidence, ctx.lua, recv)
|
|
453
613
|
return ids or {}, 'receiver: Lua lexical binding'
|
|
@@ -468,7 +628,7 @@ function M.resolve(G, f, src, name, kind, recv, evidence, ctx, accept, offset)
|
|
|
468
628
|
elseif language == 'csharp' then
|
|
469
629
|
local cls = owner(G, f, src)
|
|
470
630
|
return require('codeoutline.analysis.csharp.csharp_bindings').members(G, f, target.ids, name, false, ctx,
|
|
471
|
-
|
|
631
|
+
cls and G.nodes[cls].qualified, recv == 'base'), 'receiver: C# instance binding'
|
|
472
632
|
elseif language == 'java' or language == 'kotlin' then
|
|
473
633
|
local ids = {}
|
|
474
634
|
for _, id in ipairs(target.ids) do
|
|
@@ -508,6 +668,11 @@ function M.entries(C, target)
|
|
|
508
668
|
out[#out + 1] = { name = name, node = node, kind = node.kind, file = C.f }
|
|
509
669
|
end
|
|
510
670
|
for name in pairs(info.fields) do out[#out + 1] = { name = name, kind = 'field' } end
|
|
671
|
+
if target.value.modules then
|
|
672
|
+
for _, entry in ipairs(C:module_members(target.value.modules, target.value.module_name)) do
|
|
673
|
+
if not info.members[entry.name] and not info.fields[entry.name] then out[#out + 1] = entry end
|
|
674
|
+
end
|
|
675
|
+
end
|
|
511
676
|
return out
|
|
512
677
|
end
|
|
513
678
|
if target.kind == 'rust' then
|
|
@@ -38,7 +38,8 @@ local function block_matches(T)
|
|
|
38
38
|
for i = 1, T.n do
|
|
39
39
|
if T.k[i] == 'kw' then
|
|
40
40
|
local t = T:text(i)
|
|
41
|
-
|
|
41
|
+
-- Lua dialect annotations can use the keyword as a type (`cb:function`).
|
|
42
|
+
if OPENS[t] and (t ~= 'function' or not is(T, i - 1, ':')) then
|
|
42
43
|
stack[#stack + 1] = i
|
|
43
44
|
elseif t == 'end' or t == 'until' then
|
|
44
45
|
local top = stack[#stack]
|
|
@@ -119,7 +120,7 @@ function M.parse(path, src, language, opts)
|
|
|
119
120
|
|
|
120
121
|
for i = 1, T.n do
|
|
121
122
|
local k = T.k[i]
|
|
122
|
-
if k == 'kw' and T:text(i) == 'function' then
|
|
123
|
+
if k == 'kw' and T:text(i) == 'function' and not is(T, i - 1, ':') then
|
|
123
124
|
local close = bm[i] or T.n
|
|
124
125
|
local parent = parent_at(i)
|
|
125
126
|
local name, qualified, kind, start, name_tok
|
|
@@ -681,7 +681,9 @@ function Completion:module_members(files, module_name)
|
|
|
681
681
|
local ids = self.V.id_of[g]
|
|
682
682
|
for n, node in ipairs(rec.nodes) do
|
|
683
683
|
if node.name == exported and not node.parent then
|
|
684
|
-
for _, entry in ipairs(self:members({ ids[n] })) do
|
|
684
|
+
for _, entry in ipairs(self:members({ ids[n] })) do
|
|
685
|
+
if entry.file == g or not node['local'] then out[#out + 1] = entry end
|
|
686
|
+
end
|
|
685
687
|
break
|
|
686
688
|
end
|
|
687
689
|
end
|
|
@@ -865,6 +867,14 @@ function Completion:entries(target)
|
|
|
865
867
|
if target.csharp_namespace ~= nil then
|
|
866
868
|
return require('codeoutline.analysis.csharp.csharp_bindings').namespace_members(self.V, self.f, target.csharp_namespace, self.V.js_context)
|
|
867
869
|
end
|
|
870
|
+
if target.alternatives then
|
|
871
|
+
local out = {}
|
|
872
|
+
for _, alternative in ipairs(target.alternatives) do
|
|
873
|
+
if self:expired() then break end
|
|
874
|
+
for _, entry in ipairs(self:module_members(alternative.modules, alternative.module_name)) do out[#out + 1] = entry end
|
|
875
|
+
end
|
|
876
|
+
return out
|
|
877
|
+
end
|
|
868
878
|
if target.modules then return self:module_members(target.modules, target.module_name) end
|
|
869
879
|
if target.owner then
|
|
870
880
|
local out = target.local_only and {} or self:owned(target.owner, graph.family(self.language))
|
|
@@ -6,33 +6,26 @@ local callable = { ['function'] = true, prototype = true, method = true, constru
|
|
|
6
6
|
local types = { class = true, struct = true, union = true, interface = true, record = true,
|
|
7
7
|
enum = true, typedef = true }
|
|
8
8
|
local values = { variable = true, constant = true, field = true, enum_member = true }
|
|
9
|
-
local reasons = { ['no indexed target'] = true, ['no eligible target'] = true,
|
|
10
|
-
['unresolved c++ name'] = true, ['name/locality match'] = true,
|
|
11
|
-
['multiple name/locality candidates'] = true }
|
|
12
9
|
local function normalized(name) return (name:gsub('::', '.'):gsub(':', '.'):gsub('^%.', '')) end
|
|
13
10
|
|
|
11
|
+
-- An empty answer leaves the editor and the agent nothing to inspect, so a
|
|
12
|
+
-- failed binding still gets name-based suggestions. They remain unconfirmed
|
|
13
|
+
-- candidates: never call edges, references or index data.
|
|
14
14
|
function M.allowed(site)
|
|
15
15
|
if not site or site.decl or not site.name or not site.name:match('^[%a_$][%w_$]*$') then return false end
|
|
16
|
-
--
|
|
17
|
-
--
|
|
18
|
-
--
|
|
19
|
-
--
|
|
20
|
-
|
|
21
|
-
and (site.macro_state == 'uncertain' or site.macro_state == 'limited')
|
|
22
|
-
if not macro_unknown and not reasons[site.reason]
|
|
23
|
-
and not (site.reason or ''):match('^ambiguous name candidates') then return false end
|
|
24
|
-
-- A known binding that failed is a barrier, not permission to guess another
|
|
25
|
-
-- imported value, local, receiver type, package, or constructor.
|
|
26
|
-
if site.evidence ~= nil and site.evidence ~= ''
|
|
27
|
-
and not (type(site.evidence) == 'string' and site.evidence:match('^cpp:name:')) then return false end
|
|
16
|
+
-- A table literal declared in this file is a bound receiver, not a failed
|
|
17
|
+
-- one: its whole contents are visible, so another file's member is a
|
|
18
|
+
-- different object. A module binding stays eligible because members can be
|
|
19
|
+
-- attached to it from other files.
|
|
20
|
+
if type(site.evidence) == 'string' and site.evidence:match('^lua%-local:') then return false end
|
|
28
21
|
return site.kind == 'call' or site.kind == 'ref' or site.kind == 'symbol' or site.kind == 'new'
|
|
29
22
|
or site.kind == 'member_call' or site.kind == 'member_symbol'
|
|
30
23
|
end
|
|
31
24
|
|
|
32
|
-
function M.find(G, f, site, ctx)
|
|
25
|
+
function M.find(G, f, site, ctx, lua_self, lua_initializers)
|
|
33
26
|
local info = { truncated = site and site.macro_state == 'limited' or false,
|
|
34
27
|
scanned = 0, reason = 'exact name; binding unconfirmed' }
|
|
35
|
-
if not M.allowed(site) then return {}, info end
|
|
28
|
+
if not lua_self and not M.allowed(site) then return {}, info end
|
|
36
29
|
local language = G.files[f].language
|
|
37
30
|
-- These languages have package/project visibility that a name-only search
|
|
38
31
|
-- cannot establish. Their existing resolvers retain authority.
|
|
@@ -43,52 +36,81 @@ function M.find(G, f, site, ctx)
|
|
|
43
36
|
if site.evidence and site.evidence ~= '' then qualified = site.evidence:match('^cpp:name:(.-)%z') end
|
|
44
37
|
qualified = qualified and normalized(qualified)
|
|
45
38
|
if qualified and not qualified:find('.', 1, true) then qualified = nil end
|
|
46
|
-
if
|
|
47
|
-
if site.recv
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
local
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
or site.kind ~= 'new' and (callable[node.kind]
|
|
62
|
-
or (site.kind == 'symbol' or site.kind == 'member_symbol') and (types[node.kind] or values[node.kind]))
|
|
63
|
-
-- Unresolved macro visibility can still offer unconfirmed definition
|
|
64
|
-
-- tags for navigation, including when include paths are configured.
|
|
65
|
-
-- An explicit undef remains a barrier.
|
|
66
|
-
if node.kind == 'macro' then
|
|
67
|
-
kind = site.kind == 'call' and (site.macro_state == 'unseen'
|
|
68
|
-
or site.macro_state == 'uncertain' or site.macro_state == 'limited')
|
|
69
|
-
and (g ~= f or site.line and node.line < site.line)
|
|
39
|
+
if not lua_self then
|
|
40
|
+
if site.recv then
|
|
41
|
+
if site.recv == 'self' or site.recv == 'this' or site.recv == 'cls' then return {}, info end
|
|
42
|
+
qualified = qualified or normalized(site.recv .. '.' .. site.name)
|
|
43
|
+
elseif site.kind == 'member_call' or site.kind == 'member_symbol' then return {}, info end
|
|
44
|
+
end
|
|
45
|
+
local list = G.by_name[site.name] or {}
|
|
46
|
+
-- A Lua member alias is only reachable through its dotted name; its bare
|
|
47
|
+
-- key stays unpublished unless the owner is a configured export table.
|
|
48
|
+
local dotted = language == 'lua' and qualified and G.by_name[qualified]
|
|
49
|
+
if dotted and dotted ~= list then
|
|
50
|
+
local merged, seen = {}, {}
|
|
51
|
+
for _, id in ipairs(list) do merged[#merged + 1], seen[id] = id, true end
|
|
52
|
+
for _, id in ipairs(dotted) do
|
|
53
|
+
if not seen[id] then merged[#merged + 1], seen[id] = id, true end
|
|
70
54
|
end
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
55
|
+
list = merged
|
|
56
|
+
end
|
|
57
|
+
local source_dir = G.files[f].path:match('^(.*)/') or ''
|
|
58
|
+
-- `bare` drops the receiver qualifier: the member name alone still names a
|
|
59
|
+
-- definition worth offering, including top-level method definitions.
|
|
60
|
+
local function scan(qualifier, bare)
|
|
61
|
+
local hits, macro_hits, scanned = {}, {}, 0
|
|
62
|
+
for i = 1, math.min(#list, M.MAX_SCAN) do
|
|
63
|
+
if i % 16 == 0 then control.check() end
|
|
64
|
+
scanned = i
|
|
65
|
+
local id = list[i]
|
|
66
|
+
local node, g = G.nodes[id], G.node_file[id]
|
|
67
|
+
local rec = G.files[g]
|
|
68
|
+
local parent = node.parent and rec.nodes[node.parent]
|
|
69
|
+
local published = language == 'lua' and require('codeoutline.analysis.lua.lua_bindings').exported(node, site.name, G.lua_global_export_tables)
|
|
70
|
+
local kind = site.kind == 'new' and types[node.kind]
|
|
71
|
+
or site.kind ~= 'new' and (callable[node.kind]
|
|
72
|
+
or (site.kind == 'symbol' or site.kind == 'member_symbol') and (types[node.kind] or values[node.kind]))
|
|
73
|
+
-- Unresolved macro visibility can still offer unconfirmed definition
|
|
74
|
+
-- tags for navigation, including when include paths are configured.
|
|
75
|
+
-- An explicit undef remains a barrier.
|
|
76
|
+
if node.kind == 'macro' then
|
|
77
|
+
kind = site.kind == 'call' and (site.macro_state == 'unseen'
|
|
78
|
+
or site.macro_state == 'uncertain' or site.macro_state == 'limited')
|
|
79
|
+
and (g ~= f or site.line and node.line < site.line)
|
|
80
|
+
end
|
|
81
|
+
local name_matches = node.name == site.name or published
|
|
82
|
+
if not bare then name_matches = name_matches and (normalized(node.qualified) == site.name or published) end
|
|
83
|
+
local aliased = language == 'lua' and require('codeoutline.analysis.lua.lua_bindings').member_alias(node, qualifier)
|
|
84
|
+
if qualifier then name_matches = normalized(node.qualified) == qualifier or aliased end
|
|
85
|
+
-- No call sites, private locals, nested functions or unrelated class
|
|
86
|
+
-- methods. A class-nested member stays excluded even in the bare
|
|
87
|
+
-- pass, so an unbound C++ receiver cannot reach another class.
|
|
88
|
+
-- A lexical self can inherit through runtime metatables. The editor
|
|
89
|
+
-- can offer method definition tags even without a receiver binding.
|
|
90
|
+
local lua_method = lua_self and rec.language == 'lua' and node.name == site.name and not parent
|
|
91
|
+
and not graph.is_decl(node) and (node.kind == 'method' or node.kind == 'function' and graph.owner(node.qualified))
|
|
92
|
+
local initialized_member = lua_initializers and language == 'lua' and rec.language == 'lua' and site.recv and parent
|
|
93
|
+
and callable[parent.kind] and (node.kind == 'function' or node.kind == 'method')
|
|
94
|
+
and graph.owner(parent.qualified) == site.recv and normalized(node.qualified) == qualifier
|
|
95
|
+
if lua_method or not lua_self and kind and name_matches and graph.family(rec.language) == graph.family(language)
|
|
96
|
+
and (not node['local'] or published or aliased) and not (node.static and g ~= f)
|
|
97
|
+
and (not parent or parent.kind == 'namespace' or qualifier and types[parent.kind] or initialized_member)
|
|
98
|
+
and (qualifier or bare or node.kind ~= 'method' and node.kind ~= 'constructor') then
|
|
99
|
+
local score = g == f and 100 or (rec.path:match('^(.*)/') or '') == source_dir and 20 or 0
|
|
100
|
+
if node.kind ~= 'prototype' and not node.decl then score = score + 1 end
|
|
101
|
+
local bucket = node.kind == 'macro' and macro_hits or hits
|
|
102
|
+
bucket[#bucket + 1] = { id = id, score = score }
|
|
78
103
|
end
|
|
79
104
|
end
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if node.kind ~= 'prototype' and not node.decl then score = score + 1 end
|
|
88
|
-
local bucket = node.kind == 'macro' and macro_hits or hits
|
|
89
|
-
bucket[#bucket + 1] = { id = id, score = score }
|
|
90
|
-
end
|
|
105
|
+
return hits, macro_hits, scanned
|
|
106
|
+
end
|
|
107
|
+
local hits, macro_hits, scanned = scan(qualified, false)
|
|
108
|
+
-- An unbound receiver still names a member. Offer the bare name instead of
|
|
109
|
+
-- an empty answer, keeping the qualified match authoritative when it hits.
|
|
110
|
+
if #hits == 0 and #macro_hits == 0 and qualified and not lua_self then
|
|
111
|
+
hits, macro_hits, scanned = scan(nil, true)
|
|
91
112
|
end
|
|
113
|
+
info.scanned = scanned
|
|
92
114
|
-- Ordinary definitions are more useful than unrelated proxy macros.
|
|
93
115
|
if #hits == 0 then hits = macro_hits
|
|
94
116
|
elseif configured then hits = {} end
|