@codua/codeoutline-win32-x64 0.2.1 → 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/README.md +1 -0
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/package.json +1 -1
- package/scripts/codeoutline/callers.lua +116 -0
- package/scripts/codeoutline/command.lua +7 -3
- package/scripts/codeoutline/common.lua +29 -3
- package/scripts/codeoutline/completion.lua +162 -62
- 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 +73 -12
- package/scripts/codeoutline/foreign.lua +125 -0
- package/scripts/codeoutline/foreign_lua.lua +273 -0
- package/scripts/codeoutline/graph.lua +80 -22
- package/scripts/codeoutline/index.lua +15 -6
- package/scripts/codeoutline/index_worker.lua +15 -7
- package/scripts/codeoutline/indirect.lua +148 -50
- 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/lang/lua.lua +17 -2
- package/scripts/codeoutline/lsp.lua +58 -34
- package/scripts/codeoutline/lua_bindings.lua +242 -34
- package/scripts/codeoutline/lua_literal.lua +38 -0
- package/scripts/codeoutline/main.lua +24 -3
- package/scripts/codeoutline/mcp.lua +13 -4
- package/scripts/codeoutline/navigation.lua +337 -96
- package/scripts/codeoutline/ordinary_bindings.lua +220 -0
- package/scripts/codeoutline/parse.lua +2 -0
- package/scripts/codeoutline/python_bindings.lua +112 -0
- package/scripts/codeoutline/query_report.lua +126 -0
- package/scripts/codeoutline/rules.lua +127 -0
- package/scripts/codeoutline/service.lua +11 -3
- package/scripts/codeoutline/static_dispatch.lua +534 -0
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
|
@@ -11,10 +11,9 @@
|
|
|
11
11
|
-- files are reparsed on demand within a time budget; running out of it, or
|
|
12
12
|
-- of items, marks the list incomplete.
|
|
13
13
|
local graph = require('codeoutline.graph')
|
|
14
|
-
local parse = require('codeoutline.parse')
|
|
15
14
|
local navigation = require('codeoutline.navigation')
|
|
16
15
|
local control = require('codeoutline.control')
|
|
17
|
-
local M = { MAX_ITEMS = 500, BUDGET_SECONDS = 0.3,
|
|
16
|
+
local M = { MAX_ITEMS = 500, BUDGET_SECONDS = 0.3, MAX_DEPTH = 6 }
|
|
18
17
|
|
|
19
18
|
local ITEM = { ['function'] = 3, method = 2, constructor = 4, destructor = 4, field = 5, variable = 6,
|
|
20
19
|
property = 10, class = 7, struct = 22, union = 22, record = 22, interface = 8, enum = 13, enum_member = 20,
|
|
@@ -41,9 +40,6 @@ for word in ([[Option Box Rc Arc RefCell Cell Mutex RwLock Weak unique_ptr share
|
|
|
41
40
|
local TYPE_AFTER = { go = true, rust = true, typescript = true, javascript = true, python = true, kotlin = true }
|
|
42
41
|
local DYNAMIC = { lua = true, python = true, javascript = true, typescript = true }
|
|
43
42
|
|
|
44
|
-
-- Full parses of type files, keyed by the index record they correspond to.
|
|
45
|
-
local cache, cache_order = setmetatable({}, { __mode = 'k' }), {}
|
|
46
|
-
|
|
47
43
|
local function text_of(T, i) return T.s[i] and T:text(i) or '' end
|
|
48
44
|
local function is(T, i, s) return T.k[i] == 'op' and text_of(T, i) == s end
|
|
49
45
|
local function kw(T, i, s) return T.k[i] == 'kw' and text_of(T, i) == s end
|
|
@@ -57,13 +53,21 @@ end
|
|
|
57
53
|
|
|
58
54
|
-- Type name for a declared type text: modifiers, pointers, references,
|
|
59
55
|
-- arrays, namespaces and well-known wrappers removed.
|
|
60
|
-
local function normalize(text)
|
|
56
|
+
local function normalize(text, language)
|
|
61
57
|
if type(text) ~= 'string' then return nil end
|
|
58
|
+
if language == 'cpp' then
|
|
59
|
+
local named = require('codeoutline.cpp_types').normalize(text)
|
|
60
|
+
if named then return named end
|
|
61
|
+
end
|
|
62
62
|
text = text:gsub('^%s+', ''):gsub('%s+$', '')
|
|
63
63
|
for _ = 1, 8 do
|
|
64
64
|
local first, rest = text:match('^([%a_]+)%s+(.+)$')
|
|
65
65
|
if first and MODIFIERS[first] then text = rest else break end
|
|
66
66
|
end
|
|
67
|
+
if language == 'csharp' then
|
|
68
|
+
local named = require('codeoutline.csharp_bindings').name(text)
|
|
69
|
+
if named then return named end
|
|
70
|
+
end
|
|
67
71
|
text = text:gsub('^[%*&%[%]]+', ''):gsub('[%*&%?!%s]+$', ''):gsub('%[%]$', '')
|
|
68
72
|
text = text:gsub('^%[%d*%]', ''):gsub('^map%b[]', '')
|
|
69
73
|
local outer, inner = text:match('^([%w_:%.]+)%s*<(.*)>$')
|
|
@@ -91,7 +95,7 @@ end
|
|
|
91
95
|
|
|
92
96
|
-- Declared type of a node from its signature (or the full-parse `type`).
|
|
93
97
|
local function declared(node, language)
|
|
94
|
-
if node.type then return normalize(node.type) end
|
|
98
|
+
if node.type then return normalize(node.type, language) end
|
|
95
99
|
local sig, name = node.sig, node.name
|
|
96
100
|
if not sig then return nil end
|
|
97
101
|
if node.kind == 'constructor' then return nil end
|
|
@@ -117,7 +121,7 @@ local function declared(node, language)
|
|
|
117
121
|
end
|
|
118
122
|
local at = sig:find('[%w_]*' .. name .. '%s*%(')
|
|
119
123
|
if not at then return nil end
|
|
120
|
-
return normalize(strip_name(sig:sub(1, at - 1), name))
|
|
124
|
+
return normalize(strip_name(sig:sub(1, at - 1), name), language)
|
|
121
125
|
end
|
|
122
126
|
if language == 'go' then
|
|
123
127
|
return normalize(sig:match('^%s*' .. name .. '%s+(.+)$'))
|
|
@@ -130,36 +134,12 @@ local function declared(node, language)
|
|
|
130
134
|
local at
|
|
131
135
|
for position in sig:gmatch('()' .. name .. '%f[^%w_]') do at = position end
|
|
132
136
|
if not at or at == 1 then return nil end
|
|
133
|
-
return normalize(sig:sub(1, at - 1))
|
|
137
|
+
return normalize(sig:sub(1, at - 1), language)
|
|
134
138
|
end
|
|
135
139
|
|
|
136
140
|
-- Full record and tokens of file f: the overlay document, else a cached
|
|
137
141
|
-- reparse of the indexed file (nil when too large or unreadable).
|
|
138
|
-
local
|
|
139
|
-
local draft = V.drafts[f]
|
|
140
|
-
if draft then
|
|
141
|
-
draft.completion = draft.completion or {}
|
|
142
|
-
local entry = draft.completion
|
|
143
|
-
if not entry.rec then entry.rec, entry.tokens = parse.parse_tokens(draft.path or V.files[f].path, draft.source) end
|
|
144
|
-
return entry.rec, entry.tokens, draft
|
|
145
|
-
end
|
|
146
|
-
local key = V.files[f]
|
|
147
|
-
local entry = cache[key]
|
|
148
|
-
if entry == nil then
|
|
149
|
-
if (key.size or 0) > M.MAX_FILE_BYTES then cache[key] = false; return nil end
|
|
150
|
-
local doc = navigation.source_doc(V, f)
|
|
151
|
-
entry = false
|
|
152
|
-
if doc then
|
|
153
|
-
local rec, tokens = parse.parse_tokens(key.path, doc.source)
|
|
154
|
-
entry = rec and { rec = rec, tokens = tokens } or false
|
|
155
|
-
end
|
|
156
|
-
cache[key] = entry
|
|
157
|
-
cache_order[#cache_order + 1] = key
|
|
158
|
-
if #cache_order > M.CACHE_FILES then cache[table.remove(cache_order, 1)] = nil end
|
|
159
|
-
end
|
|
160
|
-
if not entry then return nil end
|
|
161
|
-
return entry.rec, entry.tokens
|
|
162
|
-
end
|
|
142
|
+
local full = navigation.full
|
|
163
143
|
|
|
164
144
|
-- Parameters inside parentheses [a, b] of a function header.
|
|
165
145
|
local function parameters(T, a, b, language, out)
|
|
@@ -204,14 +184,14 @@ local function parameters(T, a, b, language, out)
|
|
|
204
184
|
else
|
|
205
185
|
local name
|
|
206
186
|
for k = y, x, -1 do if T.k[k] == 'id' then name = k; break end end
|
|
207
|
-
if name and name > x then out[#out + 1] = { name = text_of(T, name), type = normalize(span(T, x, name - 1)) } end
|
|
187
|
+
if name and name > x then out[#out + 1] = { name = text_of(T, name), type = normalize(span(T, x, name - 1), language), at = name } end
|
|
208
188
|
end
|
|
209
189
|
end
|
|
210
190
|
for _, name in ipairs(pending) do out[#out + 1] = { name = name } end
|
|
211
191
|
end
|
|
212
192
|
|
|
213
193
|
-- Initializer starting at token j: a type name, a module path, or a call chain.
|
|
214
|
-
local function initializer(T, j, stop)
|
|
194
|
+
local function initializer(T, j, stop, language)
|
|
215
195
|
if not j or j > stop then return {} end
|
|
216
196
|
if kw(T, j, 'new') or (T.k[j] == 'id' and text_of(T, j) == 'new') then
|
|
217
197
|
local k, last = j + 1, nil
|
|
@@ -226,6 +206,21 @@ local function initializer(T, j, stop)
|
|
|
226
206
|
local k = is(T, j + 1, '(') and j + 2 or j + 1
|
|
227
207
|
if T.k[k] == 'str' then return { module = text_of(T, k):gsub('^[%a]*["\'%[=]+', ''):gsub('["\'%]=]+$', '') } end
|
|
228
208
|
end
|
|
209
|
+
if language == 'lua' and T.k[j] == 'id' then
|
|
210
|
+
-- Lua `*import` loaders: `ks.import('path.lua')`, `skynet_import 'path.lua'`.
|
|
211
|
+
local k = j
|
|
212
|
+
while is(T, k + 1, '.') and T.k[k + 2] == 'id' do k = k + 2 end
|
|
213
|
+
local name = text_of(T, k)
|
|
214
|
+
if name:sub(-6) == 'import' then
|
|
215
|
+
local a = is(T, k + 1, '(') and k + 2 or k + 1
|
|
216
|
+
if T.k[a] == 'str' and (not is(T, k + 1, '(') or is(T, a + 1, ')')) then
|
|
217
|
+
local path = text_of(T, a):gsub('^[%a]*["\'%[=]+', ''):gsub('["\'%]=]+$', '')
|
|
218
|
+
local parts = {}
|
|
219
|
+
for x = j, k, 2 do parts[#parts + 1] = text_of(T, x) end
|
|
220
|
+
return { module = path, module_kind = table.concat(parts, '.') }
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
229
224
|
local chain, k = {}, j
|
|
230
225
|
while k <= stop and (T.k[k] == 'id' or (T.k[k] == 'kw' and SELF[text_of(T, k)])) do
|
|
231
226
|
local item = { name = text_of(T, k) }
|
|
@@ -259,12 +254,13 @@ local function declarations(T, a, b, language, skip, out)
|
|
|
259
254
|
return b
|
|
260
255
|
end
|
|
261
256
|
local function add(name_tok, type, init)
|
|
262
|
-
local entry = { name = text_of(T, name_tok), type = normalize(type), at = name_tok }
|
|
257
|
+
local entry = { name = text_of(T, name_tok), type = normalize(type, language), at = name_tok }
|
|
263
258
|
if init then
|
|
264
259
|
local stop = statement_end(init)
|
|
265
|
-
local value = initializer(T, init, stop)
|
|
260
|
+
local value = initializer(T, init, stop, language)
|
|
266
261
|
entry.type = entry.type or normalize(value.type)
|
|
267
262
|
entry.module, entry.chain = value.module, value.chain
|
|
263
|
+
entry.module_kind = value.module_kind
|
|
268
264
|
end
|
|
269
265
|
out[#out + 1] = entry
|
|
270
266
|
end
|
|
@@ -382,8 +378,10 @@ local function module_aliases(T, language)
|
|
|
382
378
|
local out = {}
|
|
383
379
|
for i = 1, T.n do
|
|
384
380
|
if language == 'lua' and kw(T, i, 'local') and T.k[i + 1] == 'id' and is(T, i + 2, '=') then
|
|
385
|
-
local value = initializer(T, i + 3, math.min(T.n, i +
|
|
386
|
-
if value.module then
|
|
381
|
+
local value = initializer(T, i + 3, math.min(T.n, i + 8), 'lua')
|
|
382
|
+
if value.module then
|
|
383
|
+
out[text_of(T, i + 1)] = { kind = value.module_kind or 'require', path = value.module }
|
|
384
|
+
end
|
|
387
385
|
elseif language == 'python' and kw(T, i, 'import') then
|
|
388
386
|
local from, k = nil, i - 1
|
|
389
387
|
while k >= 1 and T.k[k] ~= 'nl' and not kw(T, k, 'from') do k = k - 1 end
|
|
@@ -450,11 +448,26 @@ local Completion = {}
|
|
|
450
448
|
Completion.__index = Completion
|
|
451
449
|
|
|
452
450
|
-- Type nodes named name, as seen from file f.
|
|
453
|
-
function Completion:types(name, f)
|
|
451
|
+
function Completion:types(name, f, scope, at)
|
|
454
452
|
if not name then return {} end
|
|
455
453
|
f = f or self.f
|
|
456
454
|
local accept = self.language == 'lua' and LUA_TYPES or TYPES
|
|
457
455
|
local direct, paired = navigation.deps(self.V, f)
|
|
456
|
+
if self.V.files[f].language == 'csharp' then
|
|
457
|
+
local ids = require('codeoutline.csharp_bindings').types(self.V, f, name,
|
|
458
|
+
at or (f == self.f and self.offset) or 0, self.V.js_context, { scope = scope })
|
|
459
|
+
return ids
|
|
460
|
+
end
|
|
461
|
+
if self.V.files[f].language == 'cpp' then
|
|
462
|
+
if not scope and f == self.f then
|
|
463
|
+
local owner = self.fn and self.rec.nodes[self.fn] or self.owner and self.rec.nodes[self.owner]
|
|
464
|
+
scope = owner and (CALLABLE[owner.kind] and owner.qualified:match('^(.*)::[^:]+$') or owner.qualified)
|
|
465
|
+
end
|
|
466
|
+
if at == nil and f == self.f then at = self.offset end
|
|
467
|
+
local ids, known = require('codeoutline.cpp_types').resolve(self.V, f, name,
|
|
468
|
+
{ scope = scope, at = at or nil, deps = direct, context = self.V.js_context, accept = TYPES })
|
|
469
|
+
if known then return ids end
|
|
470
|
+
end
|
|
458
471
|
local found = graph.resolve(self.V, f, nil, name, 'call', nil, direct, paired, accept) or {}
|
|
459
472
|
if #found == 0 then
|
|
460
473
|
local family = graph.family(self.V.files[f].language)
|
|
@@ -534,7 +547,7 @@ function Completion:members(ids, depth, seen)
|
|
|
534
547
|
-- Base classes.
|
|
535
548
|
if depth < 3 and node.bases then
|
|
536
549
|
for _, base in ipairs(node.bases) do
|
|
537
|
-
local base_ids = self:types(normalize(base), f)
|
|
550
|
+
local base_ids = self:types(normalize(base, self.language), f, node.qualified:match('^(.*)::[^:]+$'), false)
|
|
538
551
|
for _, entry in ipairs(self:members(base_ids, depth + 1, seen)) do out[#out + 1] = entry end
|
|
539
552
|
end
|
|
540
553
|
end
|
|
@@ -591,19 +604,43 @@ function Completion:assigned(name)
|
|
|
591
604
|
end
|
|
592
605
|
|
|
593
606
|
-- Top-level members of module files.
|
|
594
|
-
function Completion:module_members(files)
|
|
607
|
+
function Completion:module_members(files, module_name)
|
|
595
608
|
local out = {}
|
|
596
609
|
for _, g in ipairs(files) do
|
|
597
610
|
if self:expired() then break end
|
|
598
611
|
local rec = self.V.files[g]
|
|
599
612
|
local language = rec.language
|
|
613
|
+
local native = require('codeoutline.foreign').exports(rec, self.language, module_name)
|
|
614
|
+
if native then
|
|
615
|
+
for name, n in pairs(native) do
|
|
616
|
+
local node = rec.nodes[n]
|
|
617
|
+
out[#out + 1] = { name = name, kind = node.kind, node = node, file = g }
|
|
618
|
+
end
|
|
619
|
+
end
|
|
600
620
|
local exported
|
|
621
|
+
local lua_contract = language == 'lua' and rec.lua_exports and next(rec.lua_exports) ~= nil
|
|
601
622
|
if language == 'lua' then
|
|
602
|
-
-- The
|
|
603
|
-
|
|
604
|
-
if
|
|
605
|
-
|
|
606
|
-
|
|
623
|
+
-- The verified module contract names the returned table's members.
|
|
624
|
+
exported = rec.lua_owner
|
|
625
|
+
if not exported and not lua_contract then
|
|
626
|
+
local _, T = full(self.V, g)
|
|
627
|
+
if T then
|
|
628
|
+
for i = T.n - 1, 1, -1 do
|
|
629
|
+
if kw(T, i, 'return') and T.k[i + 1] == 'id' then exported = text_of(T, i + 1); break end
|
|
630
|
+
end
|
|
631
|
+
end
|
|
632
|
+
end
|
|
633
|
+
if not exported and lua_contract then
|
|
634
|
+
-- Return-less `__exports` contract: the recorded exports are the members.
|
|
635
|
+
for name, n in pairs(rec.lua_exports) do
|
|
636
|
+
local node = rec.nodes[n]
|
|
637
|
+
if node then out[#out + 1] = { name = name, kind = node.kind, node = node, file = g } end
|
|
638
|
+
end
|
|
639
|
+
elseif not exported then
|
|
640
|
+
for _, node in ipairs(rec.nodes) do
|
|
641
|
+
if not node.parent and not node.qualified:find('[%.:]') then
|
|
642
|
+
out[#out + 1] = { name = node.name, kind = node.kind, node = node, file = g }
|
|
643
|
+
end
|
|
607
644
|
end
|
|
608
645
|
end
|
|
609
646
|
end
|
|
@@ -611,7 +648,8 @@ function Completion:module_members(files)
|
|
|
611
648
|
if exported then
|
|
612
649
|
local member = node.qualified:match('^' .. exported:gsub('%p', '%%%0') .. '[%.:]([%w_]+)$')
|
|
613
650
|
if member then out[#out + 1] = { name = member, kind = node.kind, node = node, file = g } end
|
|
614
|
-
elseif not node.parent and not node.qualified:find('[%.:]')
|
|
651
|
+
elseif not native and language ~= 'lua' and not node.parent and not node.qualified:find('[%.:]')
|
|
652
|
+
and (language ~= 'go' or node.name:match('^%u')) then
|
|
615
653
|
out[#out + 1] = { name = node.name, kind = node.kind, node = node, file = g }
|
|
616
654
|
end
|
|
617
655
|
end
|
|
@@ -722,6 +760,12 @@ end
|
|
|
722
760
|
-- A receiver: { types = ids } or { modules = files }.
|
|
723
761
|
function Completion:receiver(item, depth)
|
|
724
762
|
local name = item.name
|
|
763
|
+
if self.language == 'lua' then
|
|
764
|
+
local target, bound = require('codeoutline.lua_bindings').receiver(
|
|
765
|
+
self.V, self.rec, self.T, name, self.offset, self.V.js_context.lua)
|
|
766
|
+
if target then return target end
|
|
767
|
+
if bound then return { owner = name, local_only = true } end
|
|
768
|
+
end
|
|
725
769
|
if SELF[name] or (self.language == 'rust' and name == 'self') then
|
|
726
770
|
local ids = self:self_types()
|
|
727
771
|
if #ids > 0 then return { types = ids } end
|
|
@@ -729,9 +773,9 @@ function Completion:receiver(item, depth)
|
|
|
729
773
|
local entry = find_local(self:locals(), name)
|
|
730
774
|
if entry then
|
|
731
775
|
if entry.module then
|
|
732
|
-
return { modules = import_files(self.V, self.f, { kind = 'require', path = entry.module }) }
|
|
776
|
+
return { modules = import_files(self.V, self.f, { kind = entry.module_kind or 'require', path = entry.module }), module_name = entry.module }
|
|
733
777
|
elseif entry.type then
|
|
734
|
-
local ids = self:types(entry.type)
|
|
778
|
+
local ids = self:types(entry.type, nil, nil, entry.at and self.T.s[entry.at] - 1)
|
|
735
779
|
if #ids > 0 then return { types = ids } end
|
|
736
780
|
elseif entry.chain and depth < M.MAX_DEPTH then
|
|
737
781
|
return self:chain(entry.chain, depth + 1)
|
|
@@ -743,7 +787,17 @@ function Completion:receiver(item, depth)
|
|
|
743
787
|
local alias = self.aliases[name]
|
|
744
788
|
if alias then
|
|
745
789
|
local files = import_files(self.V, self.f, alias)
|
|
746
|
-
if #files > 0 then return { modules = files } end
|
|
790
|
+
if #files > 0 then return { modules = files, module_name = alias.path } end
|
|
791
|
+
end
|
|
792
|
+
if self.language == 'lua' and not entry then
|
|
793
|
+
local files = require('codeoutline.lua_bindings').native_modules(self.V, name, self.V.js_context.lua)
|
|
794
|
+
if #files > 0 then return { modules = files, module_name = name } end
|
|
795
|
+
end
|
|
796
|
+
if self.language == 'csharp' then
|
|
797
|
+
if name == 'global' then return { csharp_namespace = '' } end
|
|
798
|
+
local ids, namespace, known = require('codeoutline.csharp_bindings').types(self.V, self.f, name, self.offset, self.V.js_context)
|
|
799
|
+
if namespace then return { csharp_namespace = namespace } end
|
|
800
|
+
if known then return #ids > 0 and { types = ids, static = not item.call } or nil end
|
|
747
801
|
end
|
|
748
802
|
local ids = self:types(name)
|
|
749
803
|
if #ids > 0 then return { types = ids, static = true } end
|
|
@@ -755,13 +809,27 @@ end
|
|
|
755
809
|
|
|
756
810
|
function Completion:entries(target)
|
|
757
811
|
if not target then return {} end
|
|
758
|
-
if target.
|
|
812
|
+
if target.csharp_namespace ~= nil then
|
|
813
|
+
return require('codeoutline.csharp_bindings').namespace_members(self.V, self.f, target.csharp_namespace, self.V.js_context)
|
|
814
|
+
end
|
|
815
|
+
if target.modules then return self:module_members(target.modules, target.module_name) end
|
|
759
816
|
if target.owner then
|
|
760
817
|
local out = target.local_only and {} or self:owned(target.owner, graph.family(self.language))
|
|
761
818
|
for _, entry in ipairs(self:assigned(target.owner)) do out[#out + 1] = entry end
|
|
762
819
|
return out
|
|
763
820
|
end
|
|
764
|
-
|
|
821
|
+
local entries = self:members(target.types)
|
|
822
|
+
if self.language == 'csharp' then
|
|
823
|
+
local kept = {}
|
|
824
|
+
for _, entry in ipairs(entries) do
|
|
825
|
+
local n = entry.node
|
|
826
|
+
local bindings = require('codeoutline.csharp_bindings')
|
|
827
|
+
if not n or TYPES[n.kind] or (bindings.static_node(self.V, entry.file, n, self.V.js_context) == (target.static or false)
|
|
828
|
+
and bindings.visible_node(self.V, self.f, entry.file, n, self.offset, self.V.js_context)) then kept[#kept + 1] = entry end
|
|
829
|
+
end
|
|
830
|
+
return kept
|
|
831
|
+
end
|
|
832
|
+
return entries
|
|
765
833
|
end
|
|
766
834
|
|
|
767
835
|
-- Type of a receiver chain, element by element.
|
|
@@ -770,23 +838,38 @@ function Completion:chain(chain, depth)
|
|
|
770
838
|
local target = self:receiver(chain[1], depth)
|
|
771
839
|
for k = 2, #chain do
|
|
772
840
|
if not target or self:expired() then return nil end
|
|
773
|
-
local element, next_ids = chain[k], {}
|
|
841
|
+
local element, next_ids, next_files, next_module, next_namespace, next_static = chain[k], {}, nil, nil, nil, nil
|
|
774
842
|
for _, entry in ipairs(self:entries(target)) do
|
|
775
843
|
if entry.name == element.name then
|
|
776
844
|
local node = entry.node
|
|
777
|
-
if
|
|
845
|
+
if self.language == 'csharp' and node.kind == 'namespace' then next_namespace = node.qualified
|
|
846
|
+
elseif self.language == 'csharp' and TYPES[node.kind] then
|
|
847
|
+
next_static = not element.call
|
|
848
|
+
local ids = require('codeoutline.csharp_bindings').types(self.V, self.f, 'global::' .. node.qualified, self.offset, self.V.js_context)
|
|
849
|
+
for _, id in ipairs(ids) do next_ids[#next_ids + 1] = id end
|
|
850
|
+
elseif TYPES[node.kind] then
|
|
778
851
|
for _, id in ipairs(self:types(node.name, entry.file)) do next_ids[#next_ids + 1] = id end
|
|
779
852
|
else
|
|
780
|
-
local
|
|
853
|
+
local detail = navigation.detail(self.V, entry.file, node)
|
|
854
|
+
local type = declared(detail, self.V.files[entry.file].language)
|
|
781
855
|
if not type and element.call and FACTORY[element.name] and target.types then
|
|
782
856
|
for _, id in ipairs(target.types) do next_ids[#next_ids + 1] = id end
|
|
783
857
|
elseif type then
|
|
784
|
-
|
|
858
|
+
local scope = node.qualified:match('^(.*)::[^:]+$')
|
|
859
|
+
or self.language == 'csharp' and node.qualified:match('^(.*)%.[^.]+$')
|
|
860
|
+
for _, id in ipairs(self:types(type, entry.file, scope, self.language == 'csharp' and detail.name_start or false)) do next_ids[#next_ids + 1] = id end
|
|
861
|
+
end
|
|
862
|
+
if #next_ids == 0 and element.call and self.language == 'lua' then
|
|
863
|
+
-- A native object: the C implementation names the metatable
|
|
864
|
+
-- it returns, which is the type the guest sees.
|
|
865
|
+
local value = require('codeoutline.lua_bindings').return_target(self.V, node, self.V.js_context.lua)
|
|
866
|
+
if value then next_files, next_module = value.modules, value.module_name end
|
|
785
867
|
end
|
|
786
868
|
end
|
|
787
869
|
end
|
|
788
870
|
end
|
|
789
|
-
target = #next_ids > 0 and { types = next_ids
|
|
871
|
+
target = next_namespace and { csharp_namespace = next_namespace } or #next_ids > 0 and { types = next_ids, static = next_static }
|
|
872
|
+
or (next_module and { modules = next_files, module_name = next_module } or nil)
|
|
790
873
|
end
|
|
791
874
|
return target
|
|
792
875
|
end
|
|
@@ -809,10 +892,12 @@ local function receiver_chain(T, op, member)
|
|
|
809
892
|
return #chain > 0 and chain or nil
|
|
810
893
|
end
|
|
811
894
|
|
|
812
|
-
local function item_for(entry, language)
|
|
895
|
+
local function item_for(entry, language, V, details)
|
|
813
896
|
local node = entry.node
|
|
897
|
+
local foreign = node and require('codeoutline.foreign').signature(node, language, entry.name)
|
|
898
|
+
if details and node and entry.file and not foreign then node = navigation.detail(V, entry.file, node) end
|
|
814
899
|
return { label = entry.name, kind = ITEM[entry.kind] or 6,
|
|
815
|
-
detail = node and (node.sig or (node.type and (node.type .. ' ' .. entry.name))) or entry.detail }
|
|
900
|
+
detail = foreign and foreign.label or (node and (node.sig or (node.type and (node.type .. ' ' .. entry.name))) or entry.detail) }
|
|
816
901
|
end
|
|
817
902
|
|
|
818
903
|
-- Completion items at the cursor of req.uri.
|
|
@@ -855,6 +940,21 @@ function M.complete(req)
|
|
|
855
940
|
detail = entry.type and (entry.type .. ' ' .. entry.name) or nil }
|
|
856
941
|
end
|
|
857
942
|
for alias in pairs(self.aliases) do entries[#entries + 1] = { name = alias, kind = 'namespace', detail = 'module' } end
|
|
943
|
+
if self.language == 'csharp' then
|
|
944
|
+
local bindings = require('codeoutline.csharp_bindings')
|
|
945
|
+
for _, entry in ipairs(bindings.usings(V, f, self.offset, V.js_context)) do
|
|
946
|
+
local d = entry.directive
|
|
947
|
+
if d.alias then entries[#entries + 1] = { name = d.alias:gsub('^@', ''), kind = 'class', detail = d.path }
|
|
948
|
+
elseif d.static then
|
|
949
|
+
local ids = bindings.types(V, entry.file, d.path, d.first, V.js_context,
|
|
950
|
+
{ exclude = d.first, no_global = true, scope = d.scope })
|
|
951
|
+
for _, member in ipairs(self:members(ids)) do
|
|
952
|
+
if TYPES[member.kind] or bindings.static_node(V, member.file, member.node, V.js_context)
|
|
953
|
+
and bindings.visible_node(V, f, member.file, member.node, self.offset, V.js_context) then entries[#entries + 1] = member end
|
|
954
|
+
end
|
|
955
|
+
end
|
|
956
|
+
end
|
|
957
|
+
end
|
|
858
958
|
for _, node in ipairs(self.rec.nodes) do
|
|
859
959
|
if not node.parent and (self.language == 'kotlin' or not node.qualified:find('[%.:]')) then
|
|
860
960
|
entries[#entries + 1] = { name = node.name, kind = node.kind, node = node, file = f }
|
|
@@ -921,7 +1021,7 @@ function M.complete(req)
|
|
|
921
1021
|
if not seen[entry.name] then
|
|
922
1022
|
seen[entry.name] = true
|
|
923
1023
|
if #items >= M.MAX_ITEMS then self.incomplete = true; break end
|
|
924
|
-
items[#items + 1] = item_for(entry, self.language)
|
|
1024
|
+
items[#items + 1] = item_for(entry, self.language, V, not self:expired())
|
|
925
1025
|
end
|
|
926
1026
|
end
|
|
927
1027
|
return { items = items, incomplete = self.incomplete }
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
-- Bounded declared receiver types. Source evidence is compact; lookup uses the
|
|
2
|
+
-- same symbol tables and include visibility as ordinary graph queries.
|
|
3
|
+
local M = {}
|
|
4
|
+
local control = require('codeoutline.control')
|
|
5
|
+
local types = { class = true, struct = true, union = true }
|
|
6
|
+
local qualifiers = { const = true, volatile = true, static = true, mutable = true, struct = true, class = true }
|
|
7
|
+
local boundary = { [';'] = true, ['{'] = true, ['}'] = true, ['('] = true, [','] = true, [':'] = true }
|
|
8
|
+
local primitive = { auto = true, int = true, double = true, float = true, char = true, bool = true,
|
|
9
|
+
long = true, short = true, unsigned = true, signed = true, void = true }
|
|
10
|
+
|
|
11
|
+
function M.collect(r, T)
|
|
12
|
+
if r.language ~= 'cpp' then return end
|
|
13
|
+
require('codeoutline.cpp_types').collect(r, T)
|
|
14
|
+
local wanted = {}
|
|
15
|
+
for _, ref in ipairs(r.refs) do
|
|
16
|
+
if ref.kind == 'member_call' and ref.recv and ref.recv ~= 'this' then wanted[ref.recv] = true end
|
|
17
|
+
end
|
|
18
|
+
if not next(wanted) then return end
|
|
19
|
+
r.has_bindings = true
|
|
20
|
+
local scopes, stack = {}, {}
|
|
21
|
+
for i = 1, T.n do
|
|
22
|
+
if T:text(i) == '{' and T.m[i] then stack[#stack + 1] = i end
|
|
23
|
+
scopes[i] = stack[#stack] or 0
|
|
24
|
+
if stack[#stack] and T.m[stack[#stack]] == i then stack[#stack] = nil end
|
|
25
|
+
end
|
|
26
|
+
local bindings = {}
|
|
27
|
+
for i = 1, T.n do
|
|
28
|
+
if i % 4096 == 0 then control.check() end
|
|
29
|
+
if T.k[i] == 'id' and wanted[T:text(i)] then
|
|
30
|
+
local after = T:text(i + 1)
|
|
31
|
+
if after == ')' or after == ',' or after == ';' or after == '=' or after == '{' then
|
|
32
|
+
local j = i - 1
|
|
33
|
+
while T:text(j) == '*' or T:text(j) == '&' or T:text(j) == '&&' or qualifiers[T:text(j)] do j = j - 1 end
|
|
34
|
+
if T.k[j] == 'id' or primitive[T:text(j)] then
|
|
35
|
+
local ty = T:text(j)
|
|
36
|
+
j = j - 1
|
|
37
|
+
while T:text(j) == '::' and T.k[j - 1] == 'id' do
|
|
38
|
+
ty = T:text(j - 1) .. '::' .. ty; j = j - 2
|
|
39
|
+
end
|
|
40
|
+
if T:text(j) == '::' then ty = '::' .. ty; j = j - 1 end
|
|
41
|
+
while qualifiers[T:text(j)] do j = j - 1 end
|
|
42
|
+
while primitive[T:text(j)] do j = j - 1 end
|
|
43
|
+
if j == 0 or boundary[T:text(j)] then
|
|
44
|
+
local a = scopes[i]
|
|
45
|
+
local b = a > 0 and T.m[a] or T.n
|
|
46
|
+
for _, n in ipairs(r.nodes) do
|
|
47
|
+
if (n.kind == 'function' or n.kind == 'method' or n.kind == 'constructor')
|
|
48
|
+
and n.ti <= i and i <= n.tj and n.ti > a then a, b = n.ti, n.tj end
|
|
49
|
+
end
|
|
50
|
+
bindings[T:text(i)] = bindings[T:text(i)] or {}
|
|
51
|
+
bindings[T:text(i)][#bindings[T:text(i)] + 1] = { token = i, a = a, b = b, type = ty }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
for _, ref in ipairs(r.refs) do
|
|
58
|
+
if ref.kind == 'member_call' and ref.recv then
|
|
59
|
+
local best
|
|
60
|
+
for _, b in ipairs(bindings[ref.recv] or {}) do
|
|
61
|
+
if b.a <= ref.tok and ref.tok <= b.b and b.token < ref.tok
|
|
62
|
+
and (not best or b.a > best.a or b.a == best.a and b.token > best.token) then best = b end
|
|
63
|
+
end
|
|
64
|
+
if best then
|
|
65
|
+
ref.binding = 'cpp:type:' .. best.type .. '\0' .. (T.s[best.token] - 1)
|
|
66
|
+
-- A chain's tail is not the simple local sharing that name.
|
|
67
|
+
if T:text(ref.tok - 3) == '.' or T:text(ref.tok - 3) == '->' then ref.binding = 'cpp:?' end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
function M.resolve(G, f, src, name, evidence, deps, ctx)
|
|
74
|
+
if G.files[f].language ~= 'cpp' or not evidence or evidence:sub(1, 4) ~= 'cpp:' then return nil end
|
|
75
|
+
local ty = evidence:match('^cpp:type:(.+)$')
|
|
76
|
+
if not ty then return {} end
|
|
77
|
+
local written, at = ty:match('^(.-)%z(%d+)$')
|
|
78
|
+
ty = written or ty
|
|
79
|
+
local function classes(written, scope, file, position)
|
|
80
|
+
return require('codeoutline.cpp_types').resolve(G, file or f, written,
|
|
81
|
+
{ scope = scope, at = position, deps = deps, context = ctx })
|
|
82
|
+
end
|
|
83
|
+
local scope = src and G.nodes[src].qualified:match('^(.*)::[^:]+$')
|
|
84
|
+
local result, seen, emitted = {}, {}, {}
|
|
85
|
+
local function members(cls, depth)
|
|
86
|
+
control.check()
|
|
87
|
+
if seen[cls] or depth > 8 then return end
|
|
88
|
+
seen[cls] = true
|
|
89
|
+
local q = G.nodes[cls].qualified .. '::' .. name
|
|
90
|
+
local matches, has_definition = {}, false
|
|
91
|
+
for _, id in ipairs(G.by_name[name] or {}) do
|
|
92
|
+
local n = G.nodes[id]
|
|
93
|
+
local owner = n.parent and G.files[G.node_file[id]].nodes[n.parent]
|
|
94
|
+
if n.qualified == q and G.files[G.node_file[id]].language == 'cpp'
|
|
95
|
+
and (not owner or not types[owner.kind] or G.id_of[G.node_file[id]][n.parent] == cls) then
|
|
96
|
+
matches[#matches + 1] = id
|
|
97
|
+
if not n.decl and n.kind ~= 'prototype' then has_definition = true end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
for _, id in ipairs(matches) do
|
|
101
|
+
local n = G.nodes[id]
|
|
102
|
+
if not emitted[id] and (not has_definition or not n.decl and n.kind ~= 'prototype') then
|
|
103
|
+
emitted[id] = true; result[#result + 1] = id
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
if #matches == 0 then
|
|
107
|
+
for _, base in ipairs(G.nodes[cls].bases or {}) do
|
|
108
|
+
for _, id in ipairs(classes(base, G.nodes[cls].qualified:match('^(.*)::[^:]+$'), G.node_file[cls])) do members(id, depth + 1) end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
for _, cls in ipairs(classes(ty, scope, f, tonumber(at))) do members(cls, 0) end
|
|
113
|
+
return result
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
return M
|