@codua/codeoutline-win32-x64 0.1.9 → 0.2.1
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 +38 -6
- package/README.zh-CN.md +36 -6
- package/THIRD_PARTY.md +3 -3
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/package.json +1 -1
- package/scripts/codeoutline/cli.lua +2 -2
- package/scripts/codeoutline/command.lua +9 -1
- package/scripts/codeoutline/common.lua +45 -5
- package/scripts/codeoutline/completion.lua +936 -0
- package/scripts/codeoutline/control.lua +5 -1
- package/scripts/codeoutline/documents.lua +154 -0
- package/scripts/codeoutline/explore.lua +35 -8
- package/scripts/codeoutline/graph.lua +321 -102
- package/scripts/codeoutline/index.lua +170 -50
- package/scripts/codeoutline/index_worker.lua +108 -17
- package/scripts/codeoutline/indirect.lua +201 -0
- package/scripts/codeoutline/js_evidence.lua +175 -0
- package/scripts/codeoutline/js_resolution.lua +201 -0
- package/scripts/codeoutline/lang/c.lua +22 -12
- package/scripts/codeoutline/lang/cpp.lua +13 -12
- package/scripts/codeoutline/lang/csharp.lua +21 -21
- package/scripts/codeoutline/lang/go.lua +10 -10
- package/scripts/codeoutline/lang/java.lua +9 -9
- package/scripts/codeoutline/lang/js.lua +15 -14
- package/scripts/codeoutline/lang/kotlin.lua +384 -0
- package/scripts/codeoutline/lang/lua.lua +11 -6
- package/scripts/codeoutline/lang/python.lua +6 -6
- package/scripts/codeoutline/lang/rust.lua +23 -15
- package/scripts/codeoutline/lsp.lua +574 -0
- package/scripts/codeoutline/lua_bindings.lua +222 -0
- package/scripts/codeoutline/main.lua +28 -5
- package/scripts/codeoutline/navigation.lua +1046 -0
- package/scripts/codeoutline/parse.lua +9 -2
- package/scripts/codeoutline/parse_pool.lua +189 -0
- package/scripts/codeoutline/parse_worker.lua +24 -0
- package/scripts/codeoutline/service.lua +82 -31
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
- package/licenses/rpmalloc.txt +0 -12
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
-- Kotlin declarations and call sites over xscan; deliberately not a type checker.
|
|
2
|
+
local xscan = require('codeoutline.xscan')
|
|
3
|
+
local common = require('codeoutline.common')
|
|
4
|
+
local M = {}
|
|
5
|
+
|
|
6
|
+
M.config = {
|
|
7
|
+
keywords = { 'as', 'break', 'class', 'continue', 'do', 'else', 'false', 'for', 'fun',
|
|
8
|
+
'if', 'in', 'interface', 'is', 'null', 'object', 'package', 'return', 'super',
|
|
9
|
+
'this', 'throw', 'true', 'try', 'typealias', 'typeof', 'val', 'var', 'when', 'while', 'import' },
|
|
10
|
+
ops = { '===', '!==', '..<', '?.', '?:', '!!', '::', '->', '==', '!=', '<=', '>=',
|
|
11
|
+
'&&', '||', '++', '--', '+=', '-=', '*=', '/=', '%=', '..' },
|
|
12
|
+
line_comment = { '//' }, block_comment = { { '/*', '*/' } }, nested_comments = true,
|
|
13
|
+
strings = { { '"""', '"""', multiline = true }, { '"', '"', escape = '\\' },
|
|
14
|
+
{ "'", "'", escape = '\\' }, { '`', '`' } },
|
|
15
|
+
}
|
|
16
|
+
M.lang = xscan.lang(M.config)
|
|
17
|
+
|
|
18
|
+
local MOD = {}
|
|
19
|
+
for s in ([[public private protected internal final open abstract sealed data enum annotation value
|
|
20
|
+
inner companion override lateinit const tailrec operator infix inline noinline crossinline
|
|
21
|
+
external suspend expect actual reified vararg out]]):gmatch('%S+') do MOD[s] = true end
|
|
22
|
+
local DECL = { class = true, interface = true, object = true, ['fun'] = true,
|
|
23
|
+
val = true, var = true, typealias = true }
|
|
24
|
+
local CONTINUE = { ['='] = true, ['.'] = true, ['?.'] = true, ['?:'] = true, [','] = true,
|
|
25
|
+
[':'] = true, ['->'] = true, ['+'] = true, ['-'] = true, ['*'] = true, ['/'] = true,
|
|
26
|
+
['&&'] = true, ['||'] = true, ['in'] = true, ['is'] = true, ['as'] = true, ['by'] = true }
|
|
27
|
+
local function is(T, i, s) return T.k[i] == 'op' and T:text(i) == s end
|
|
28
|
+
local function word(T, i, s) return (T.k[i] == 'id' or T.k[i] == 'kw') and T:text(i) == s end
|
|
29
|
+
|
|
30
|
+
-- xscan handles ordinary/raw strings, but Kotlin templates can nest quoted
|
|
31
|
+
-- expressions: "${render("}")}". Hide template interiors before tokenizing,
|
|
32
|
+
-- preserving every byte offset/newline; their expressions are not indexed.
|
|
33
|
+
local function template_source(src)
|
|
34
|
+
if not src:find('${', 1, true) then return src end
|
|
35
|
+
local quoted, expression
|
|
36
|
+
local function comment(i)
|
|
37
|
+
if src:sub(i, i + 1) == '//' then return src:find('\n', i + 2, true) or #src + 1 end
|
|
38
|
+
if src:sub(i, i + 1) ~= '/*' then return nil end
|
|
39
|
+
local depth = 1
|
|
40
|
+
i = i + 2
|
|
41
|
+
while i <= #src and depth > 0 do
|
|
42
|
+
local pair = src:sub(i, i + 1)
|
|
43
|
+
if pair == '/*' then depth = depth + 1; i = i + 2
|
|
44
|
+
elseif pair == '*/' then depth = depth - 1; i = i + 2
|
|
45
|
+
else i = i + 1 end
|
|
46
|
+
end
|
|
47
|
+
return i
|
|
48
|
+
end
|
|
49
|
+
quoted = function(i, depth)
|
|
50
|
+
if depth > 64 then return #src + 1 end
|
|
51
|
+
local delimiter = src:sub(i, i)
|
|
52
|
+
if delimiter == '"' and src:sub(i, i + 2) == '"""' then delimiter = '"""' end
|
|
53
|
+
local k = i + #delimiter
|
|
54
|
+
while k <= #src do
|
|
55
|
+
if src:sub(k, k + #delimiter - 1) == delimiter then return k + #delimiter end
|
|
56
|
+
local c = src:sub(k, k)
|
|
57
|
+
if c == '\\' and delimiter ~= '"""' and delimiter ~= '`' then k = k + 2
|
|
58
|
+
elseif delimiter:sub(1, 1) == '"' and src:sub(k, k + 1) == '${' then k = expression(k + 2, depth + 1)
|
|
59
|
+
else k = k + 1 end
|
|
60
|
+
end
|
|
61
|
+
return #src + 1
|
|
62
|
+
end
|
|
63
|
+
expression = function(i, depth)
|
|
64
|
+
local braces = 1
|
|
65
|
+
while i <= #src and braces > 0 do
|
|
66
|
+
local c, after = src:sub(i, i), comment(i)
|
|
67
|
+
if after then i = after
|
|
68
|
+
elseif c == '"' or c == "'" or c == '`' then i = quoted(i, depth + 1)
|
|
69
|
+
else
|
|
70
|
+
if c == '{' then braces = braces + 1 elseif c == '}' then braces = braces - 1 end
|
|
71
|
+
i = i + 1
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
return i
|
|
75
|
+
end
|
|
76
|
+
local parts, start, i = {}, 1, 1
|
|
77
|
+
while i <= #src do
|
|
78
|
+
local c, after = src:sub(i, i), comment(i)
|
|
79
|
+
if after then i = after
|
|
80
|
+
elseif c == '"' or c == "'" or c == '`' then
|
|
81
|
+
local last = quoted(i, 0)
|
|
82
|
+
if c == '"' then
|
|
83
|
+
local width = src:sub(i, i + 2) == '"""' and 3 or 1
|
|
84
|
+
parts[#parts + 1] = src:sub(start, i + width - 1)
|
|
85
|
+
parts[#parts + 1] = src:sub(i + width, last - width - 1):gsub('[^\r\n]', ' ')
|
|
86
|
+
start = last - width
|
|
87
|
+
end
|
|
88
|
+
i = last
|
|
89
|
+
else i = i + 1 end
|
|
90
|
+
end
|
|
91
|
+
parts[#parts + 1] = src:sub(start)
|
|
92
|
+
return table.concat(parts)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
local function angles(T, i, b)
|
|
96
|
+
local d = 0
|
|
97
|
+
for j = i, b do
|
|
98
|
+
if is(T, j, '<') then d = d + 1
|
|
99
|
+
elseif is(T, j, '>') then d = d - 1; if d == 0 then return j end
|
|
100
|
+
elseif is(T, j, ';') or is(T, j, '{') or is(T, j, '=') then return nil end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
local function annotation(T, i, b, skip)
|
|
105
|
+
local j = i + 1
|
|
106
|
+
if is(T, j + 1, ':') then j = j + 2 end -- @file:JvmName, @get:Inject
|
|
107
|
+
if is(T, j, '[') and T.m[j] then return T.m[j] + 1 end
|
|
108
|
+
while j <= b and (T.k[j] == 'id' or T.k[j] == 'kw') do
|
|
109
|
+
skip[j] = true
|
|
110
|
+
j = j + 1
|
|
111
|
+
if is(T, j, '.') then j = j + 1 else break end
|
|
112
|
+
end
|
|
113
|
+
if is(T, j, '(') and T.m[j] then j = T.m[j] + 1 end
|
|
114
|
+
return j
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
-- End of a semicolon-free expression. Groups are skipped whole; operators,
|
|
118
|
+
-- chained receivers and control-expression bodies continue across newlines.
|
|
119
|
+
local function expression_end(T, a, b)
|
|
120
|
+
local j = a
|
|
121
|
+
while j <= b do
|
|
122
|
+
if is(T, j, ';') then return j - 1 end
|
|
123
|
+
if j > a then
|
|
124
|
+
local s, prev = T:text(j), T:text(j - 1)
|
|
125
|
+
if T.k[j] == 'kw' and DECL[s] and s ~= 'object' then return j - 1 end
|
|
126
|
+
if T:line(j) > T:eline(j - 1) and not CONTINUE[prev]
|
|
127
|
+
and not is(T, j, '.') and not is(T, j, '?.') and not is(T, j, '{')
|
|
128
|
+
and not word(T, j, 'else') and not word(T, j, 'catch') and not word(T, j, 'finally')
|
|
129
|
+
and not (is(T, j - 1, ')') and T.m[j - 1]
|
|
130
|
+
and (word(T, T.m[j - 1] - 1, 'if') or word(T, T.m[j - 1] - 1, 'when'))) then
|
|
131
|
+
return j - 1
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
if T.m[j] and T.m[j] > j then j = T.m[j] end
|
|
135
|
+
j = j + 1
|
|
136
|
+
end
|
|
137
|
+
return b
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
local function type_end(T, a, b)
|
|
141
|
+
local j = a
|
|
142
|
+
while j <= b do
|
|
143
|
+
if is(T, j, '=') or is(T, j, '{') or is(T, j, ';') or word(T, j, 'by') then break end
|
|
144
|
+
if j > a and (word(T, j, 'get') or word(T, j, 'set') or word(T, j, 'where')) then break end
|
|
145
|
+
if j > a and T:line(j) > T:eline(j - 1) and not CONTINUE[T:text(j - 1)] then break end
|
|
146
|
+
if is(T, j, '<') then j = angles(T, j, b) or j
|
|
147
|
+
elseif T.m[j] and T.m[j] > j then j = T.m[j] end
|
|
148
|
+
j = j + 1
|
|
149
|
+
end
|
|
150
|
+
return j - 1
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
local scope
|
|
154
|
+
local function add(r, T, start, last, ni, parent, kind, sig_end, extra)
|
|
155
|
+
local n = extra or {}
|
|
156
|
+
n.kind, n.name, n.ni, n.parent = kind, n.name or T:text(ni), ni, parent
|
|
157
|
+
n.ti, n.tj, n.sig = start, math.max(start, last), common.sig(T, start, sig_end or last)
|
|
158
|
+
return common.add_node(r, T, n)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
local function properties(T, r, a, b, parent, skip)
|
|
162
|
+
local j = a
|
|
163
|
+
while j <= b do
|
|
164
|
+
if (word(T, j, 'val') or word(T, j, 'var')) and T.k[j + 1] == 'id' then
|
|
165
|
+
local ni, last = j + 1, j + 1
|
|
166
|
+
if is(T, ni + 1, ':') then
|
|
167
|
+
last = ni + 2
|
|
168
|
+
while last <= b and not is(T, last, ',') and not is(T, last, '=') do
|
|
169
|
+
if is(T, last, '<') then last = angles(T, last, b) or last
|
|
170
|
+
elseif T.m[last] and T.m[last] > last then last = T.m[last] end
|
|
171
|
+
last = last + 1
|
|
172
|
+
end
|
|
173
|
+
last = last - 1
|
|
174
|
+
end
|
|
175
|
+
add(r, T, j, last, ni, parent, 'property', last,
|
|
176
|
+
{ type = last > ni + 1 and common.sig(T, ni + 2, last) or nil })
|
|
177
|
+
skip[ni] = true
|
|
178
|
+
j = last
|
|
179
|
+
elseif T.m[j] and T.m[j] > j then j = T.m[j] end
|
|
180
|
+
j = j + 1
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
scope = function(T, r, a, b, parent, skip)
|
|
185
|
+
local i = a
|
|
186
|
+
while i <= b do
|
|
187
|
+
local start, j, mods = i, i, {}
|
|
188
|
+
while j <= b do
|
|
189
|
+
if is(T, j, '@') then j = annotation(T, j, b, skip)
|
|
190
|
+
elseif T.k[j] == 'id' and MOD[T:text(j)] then mods[T:text(j)] = true; j = j + 1
|
|
191
|
+
else break end
|
|
192
|
+
end
|
|
193
|
+
local s = T:text(j)
|
|
194
|
+
local declaration = T.k[j] == 'kw' and DECL[s]
|
|
195
|
+
if s == 'package' or s == 'import' then
|
|
196
|
+
local parts, k = {}, j + 1
|
|
197
|
+
while k <= b and (T.k[k] == 'id' or T.k[k] == 'kw') do
|
|
198
|
+
parts[#parts + 1] = T:text(k); skip[k] = true; k = k + 1
|
|
199
|
+
if is(T, k, '.') then
|
|
200
|
+
k = k + 1
|
|
201
|
+
if is(T, k, '*') then parts[#parts + 1] = '*'; k = k + 1; break end
|
|
202
|
+
else break end
|
|
203
|
+
end
|
|
204
|
+
local path = table.concat(parts, '.')
|
|
205
|
+
if s == 'package' then r.package, r.prefix = path, path
|
|
206
|
+
else
|
|
207
|
+
local alias
|
|
208
|
+
if word(T, k, 'as') and T.k[k + 1] == 'id' then alias = T:text(k + 1); k = k + 2 end
|
|
209
|
+
r.imports[#r.imports + 1] = { path = path, line = T:line(j), alias = alias }
|
|
210
|
+
end
|
|
211
|
+
i = k
|
|
212
|
+
elseif declaration and (s == 'class' or s == 'interface' or s == 'object') then
|
|
213
|
+
local ni = j + 1
|
|
214
|
+
local named = T.k[ni] == 'id'
|
|
215
|
+
if not named and not mods.companion then
|
|
216
|
+
-- Anonymous object expressions: retain their members under the enclosing scope.
|
|
217
|
+
i = j + 1
|
|
218
|
+
else
|
|
219
|
+
local k, ctor, bases, in_bases = named and ni + 1 or ni, nil, {}, false
|
|
220
|
+
if not named then ni = j end
|
|
221
|
+
local last = k - 1
|
|
222
|
+
while k <= b and not is(T, k, '{') and not is(T, k, ';') do
|
|
223
|
+
if k > last + 1 and T:line(k) > T:eline(k - 1) and not CONTINUE[T:text(k - 1)]
|
|
224
|
+
and not is(T, k, ':') and not word(T, k, 'where') then break end
|
|
225
|
+
if T.k[k] == 'kw' and DECL[T:text(k)] then break end
|
|
226
|
+
if is(T, k, '<') then k = angles(T, k, b) or k
|
|
227
|
+
elseif is(T, k, '(') and T.m[k] then
|
|
228
|
+
if not in_bases then ctor = k end
|
|
229
|
+
k = T.m[k]
|
|
230
|
+
elseif is(T, k, ':') then in_bases = true
|
|
231
|
+
elseif in_bases and T.k[k] == 'id' and (is(T, k - 1, ':') or is(T, k - 1, ',')) then
|
|
232
|
+
local parts = { T:text(k) }
|
|
233
|
+
while is(T, k + 1, '.') and T.k[k + 2] == 'id' do k = k + 2; parts[#parts + 1] = T:text(k) end
|
|
234
|
+
bases[#bases + 1] = table.concat(parts, '.')
|
|
235
|
+
end
|
|
236
|
+
k = k + 1
|
|
237
|
+
end
|
|
238
|
+
local body = is(T, k, '{') and k or nil
|
|
239
|
+
local close = body and (T.m[body] or b) or k - 1
|
|
240
|
+
local kind = mods.enum and 'enum' or mods.annotation and 'annotation_type' or s == 'interface' and 'interface' or 'class'
|
|
241
|
+
local id = add(r, T, start, close, ni, parent, kind, k - 1,
|
|
242
|
+
{ name = named and T:text(ni) or 'Companion', bases = #bases > 0 and bases or nil,
|
|
243
|
+
singleton = s == 'object' or nil })
|
|
244
|
+
skip[ni] = true
|
|
245
|
+
if ctor then properties(T, r, ctor + 1, T.m[ctor] - 1, id, skip) end
|
|
246
|
+
if body then
|
|
247
|
+
local first = body + 1
|
|
248
|
+
if mods.enum then
|
|
249
|
+
while first < close and not is(T, first, ';') do
|
|
250
|
+
if T.k[first] ~= 'id' or MOD[T:text(first)] then break end
|
|
251
|
+
local name, e = first, first + 1
|
|
252
|
+
if is(T, e, '(') and T.m[e] then e = T.m[e] + 1 end
|
|
253
|
+
if is(T, e, '{') and T.m[e] then e = T.m[e] + 1 end
|
|
254
|
+
add(r, T, name, e - 1, name, id, 'enum_member'); skip[name] = true
|
|
255
|
+
first = e
|
|
256
|
+
if is(T, first, ',') then first = first + 1 else break end
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
scope(T, r, first, close - 1, id, skip)
|
|
260
|
+
end
|
|
261
|
+
i = close + 1
|
|
262
|
+
end
|
|
263
|
+
elseif declaration and s == 'fun' then
|
|
264
|
+
local k, ni, opening = j + 1
|
|
265
|
+
if is(T, k, '<') then k = (angles(T, k, b) or k) + 1 end
|
|
266
|
+
while k <= b do
|
|
267
|
+
if is(T, k, '(') and T.m[k] then
|
|
268
|
+
if T.k[k - 1] == 'id' then ni, opening = k - 1, k; break end
|
|
269
|
+
k = T.m[k]
|
|
270
|
+
elseif is(T, k, '<') then k = angles(T, k, b) or k
|
|
271
|
+
elseif is(T, k, '{') or is(T, k, '=') or is(T, k, ';') then break end
|
|
272
|
+
k = k + 1
|
|
273
|
+
end
|
|
274
|
+
if not opening then i = j + 1
|
|
275
|
+
else
|
|
276
|
+
local after, typ = T.m[opening] + 1, nil
|
|
277
|
+
if is(T, after, ':') then
|
|
278
|
+
local e = type_end(T, after + 1, b)
|
|
279
|
+
typ = e >= after + 1 and common.sig(T, after + 1, e) or nil
|
|
280
|
+
after = e + 1
|
|
281
|
+
end
|
|
282
|
+
-- Generic constraints belong to the header, not a body.
|
|
283
|
+
if word(T, after, 'where') then after = type_end(T, after, b) + 1 end
|
|
284
|
+
local body = is(T, after, '{') and after or nil
|
|
285
|
+
local expr = is(T, after, '=') and after + 1 or nil
|
|
286
|
+
local last = body and (T.m[body] or b) or expr and math.max(after, expression_end(T, expr, b)) or after - 1
|
|
287
|
+
local owner = parent and r.nodes[parent]
|
|
288
|
+
local kind = owner and (owner.kind == 'class' or owner.kind == 'interface' or owner.kind == 'enum') and 'method' or 'function'
|
|
289
|
+
local id = add(r, T, start, last, ni, parent, kind, after - 1,
|
|
290
|
+
{ type = typ, abstract = not body and not expr or nil,
|
|
291
|
+
static = not parent and mods.private or nil,
|
|
292
|
+
receiver = is(T, ni - 1, '.') and common.sig(T, j + 1, ni - 2) or nil })
|
|
293
|
+
skip[ni] = true
|
|
294
|
+
if body then scope(T, r, body + 1, last - 1, id, skip)
|
|
295
|
+
elseif expr then scope(T, r, expr, last, id, skip) end
|
|
296
|
+
i = last + 1
|
|
297
|
+
end
|
|
298
|
+
elseif declaration and (s == 'val' or s == 'var' or s == 'typealias') and T.k[j + 1] == 'id' then
|
|
299
|
+
local ni, k, typ = j + 1, j + 2, nil
|
|
300
|
+
if s == 'typealias' and is(T, k, '<') then k = (angles(T, k, b) or k) + 1 end
|
|
301
|
+
local receiver
|
|
302
|
+
if s ~= 'typealias' then
|
|
303
|
+
if is(T, k, '<') then k = (angles(T, k, b) or k) + 1 end
|
|
304
|
+
while (is(T, k, '.') or is(T, k, '?.')) and T.k[k + 1] == 'id' do
|
|
305
|
+
receiver = common.sig(T, j + 1, k - 1)
|
|
306
|
+
ni, k = k + 1, k + 2
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
if is(T, k, ':') then
|
|
310
|
+
local e = type_end(T, k + 1, b)
|
|
311
|
+
typ = e >= k + 1 and common.sig(T, k + 1, e) or nil; k = e + 1
|
|
312
|
+
end
|
|
313
|
+
local last = (is(T, k, '=') or word(T, k, 'by')) and math.max(k, expression_end(T, k + 1, b)) or k - 1
|
|
314
|
+
-- Accessors extend the property range, and their calls belong to it.
|
|
315
|
+
while word(T, last + 1, 'get') or word(T, last + 1, 'set') do
|
|
316
|
+
local ac = last + 1
|
|
317
|
+
skip[ac] = true
|
|
318
|
+
local e = is(T, ac + 1, '(') and T.m[ac + 1] or ac
|
|
319
|
+
e = e or ac
|
|
320
|
+
if is(T, e + 1, ':') then e = type_end(T, e + 2, b) end
|
|
321
|
+
if is(T, e + 1, '{') then last = T.m[e + 1] or b
|
|
322
|
+
elseif is(T, e + 1, '=') then last = math.max(e + 1, expression_end(T, e + 2, b))
|
|
323
|
+
else last = e end
|
|
324
|
+
end
|
|
325
|
+
local owner = parent and r.nodes[parent]
|
|
326
|
+
local kind = s == 'typealias' and 'typedef' or owner and
|
|
327
|
+
(owner.kind == 'class' or owner.kind == 'interface' or owner.kind == 'enum') and 'property' or 'variable'
|
|
328
|
+
local id = add(r, T, start, last, ni, parent, kind, s == 'typealias' and last or k - 1,
|
|
329
|
+
{ type = typ, receiver = receiver, static = not parent and mods.private or nil })
|
|
330
|
+
skip[ni] = true
|
|
331
|
+
if k <= last then scope(T, r, k + 1, last, id, skip) end
|
|
332
|
+
i = last + 1
|
|
333
|
+
elseif word(T, j, 'constructor') and parent and is(T, j + 1, '(') and T.m[j + 1] then
|
|
334
|
+
local k = T.m[j + 1] + 1
|
|
335
|
+
while k <= b and not is(T, k, '{') and T:line(k) == T:eline(k - 1) do k = k + 1 end
|
|
336
|
+
local body = is(T, k, '{') and k
|
|
337
|
+
local last = body and (T.m[body] or b) or k - 1
|
|
338
|
+
local id = add(r, T, start, last, j, parent, 'constructor', k - 1, { name = r.nodes[parent].name })
|
|
339
|
+
skip[j] = true
|
|
340
|
+
if body then scope(T, r, body + 1, last - 1, id, skip) end
|
|
341
|
+
i = last + 1
|
|
342
|
+
elseif is(T, j, '{') then
|
|
343
|
+
local last = T.m[j] or b
|
|
344
|
+
scope(T, r, j + 1, last - 1, parent, skip)
|
|
345
|
+
i = last + 1
|
|
346
|
+
else
|
|
347
|
+
if word(T, j, 'init') then skip[j] = true end
|
|
348
|
+
i = math.max(i + 1, j + 1)
|
|
349
|
+
end
|
|
350
|
+
end
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
function M.parse(path, src, language, opts)
|
|
354
|
+
local T = M.lang:tokenize(template_source(src))
|
|
355
|
+
T.src = src
|
|
356
|
+
-- Escaped identifiers are lexed as one token. Keep byte positions and text
|
|
357
|
+
-- consistent for both native and Lua scanners (native methods use raw data).
|
|
358
|
+
for i = 1, T.n do
|
|
359
|
+
if T.k[i] == 'str' and T:text(i):sub(1, 1) == '`' and T:text(i):sub(-1) == '`' then
|
|
360
|
+
T.k[i], T.s[i], T.e[i] = 'id', T.s[i] + 1, T.e[i] - 1
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
function T:text(i) return self.s[i] and self.src:sub(self.s[i], self.e[i]) or '' end
|
|
364
|
+
local r, skip = common.new(path, 'kotlin', opts), {}
|
|
365
|
+
r.package = '' -- Kotlin's default package is shared across source directories.
|
|
366
|
+
scope(T, r, 1, T.n, nil, skip)
|
|
367
|
+
for i = 1, T.n do
|
|
368
|
+
if T.k[i] == 'id' and not skip[i] then
|
|
369
|
+
local nexti = i + 1
|
|
370
|
+
if is(T, nexti, '<') then nexti = (angles(T, nexti, T.n) or nexti - 1) + 1 end
|
|
371
|
+
local call = is(T, nexti, '(') or is(T, nexti, '{')
|
|
372
|
+
local ref = is(T, i - 1, '::')
|
|
373
|
+
if call or ref then
|
|
374
|
+
local member = is(T, i - 1, '.') or is(T, i - 1, '?.') or ref
|
|
375
|
+
local recv = member and (T.k[i - 2] == 'id' or word(T, i - 2, 'this') or word(T, i - 2, 'super')) and T:text(i - 2) or nil
|
|
376
|
+
r.refs[#r.refs + 1] = { tok = i, name = T:text(i), kind = ref and 'ref' or member and 'member_call' or 'call',
|
|
377
|
+
recv = recv, line = T:line(i) }
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
return common.finish(r, T), T
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
return M
|
|
@@ -102,9 +102,9 @@ local function string_value(T, i)
|
|
|
102
102
|
return s:match('^"(.*)"$') or s:match("^'(.*)'$")
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
-
function M.parse(path, src)
|
|
105
|
+
function M.parse(path, src, language, opts)
|
|
106
106
|
local T = M.lang:tokenize(src)
|
|
107
|
-
local r = common.new(path, 'lua')
|
|
107
|
+
local r = common.new(path, 'lua', opts)
|
|
108
108
|
r.member_ops = { ['.'] = true, [':'] = true }
|
|
109
109
|
local stem = path:match('([^/\\]+)%.lua$') or path
|
|
110
110
|
local bm = block_matches(T)
|
|
@@ -122,12 +122,13 @@ function M.parse(path, src)
|
|
|
122
122
|
if k == 'kw' and T:text(i) == 'function' then
|
|
123
123
|
local close = bm[i] or T.n
|
|
124
124
|
local parent = parent_at(i)
|
|
125
|
-
local name, qualified, kind, start
|
|
125
|
+
local name, qualified, kind, start, name_tok
|
|
126
126
|
if T.k[i + 1] == 'id' then
|
|
127
127
|
-- function a.b:c(...) / local function f(...)
|
|
128
128
|
local x = i + 1
|
|
129
129
|
while (is(T, x + 1, '.') or is(T, x + 1, ':')) and T.k[x + 2] == 'id' do x = x + 2 end
|
|
130
130
|
name = T:text(x)
|
|
131
|
+
name_tok = x
|
|
131
132
|
qualified = common.sig(T, i + 1, x):gsub('%s', '')
|
|
132
133
|
kind = is(T, x - 1, ':') and 'method' or 'function'
|
|
133
134
|
start = kw(T, i - 1, 'local') and i - 1 or i
|
|
@@ -136,6 +137,7 @@ function M.parse(path, src)
|
|
|
136
137
|
-- x = function / a.b = function / { key = function }
|
|
137
138
|
local lhs, y = name_chain_left(T, i - 2)
|
|
138
139
|
name = T:text(i - 2)
|
|
140
|
+
name_tok = i - 2
|
|
139
141
|
qualified = lhs
|
|
140
142
|
kind = 'function'
|
|
141
143
|
start = kw(T, y - 1, 'local') and y - 1 or y
|
|
@@ -151,6 +153,7 @@ function M.parse(path, src)
|
|
|
151
153
|
if key and T.k[i - 5] == 'id' then
|
|
152
154
|
local lhs, y = name_chain_left(T, i - 5)
|
|
153
155
|
name = key
|
|
156
|
+
name_tok = i - 3
|
|
154
157
|
qualified = lhs .. '.' .. key
|
|
155
158
|
kind = 'function'
|
|
156
159
|
start = y
|
|
@@ -166,7 +169,7 @@ function M.parse(path, src)
|
|
|
166
169
|
local p = i + 1
|
|
167
170
|
while p < close and not is(T, p, '(') do p = p + 1 end
|
|
168
171
|
local node = common.add_node(r, T, {
|
|
169
|
-
kind = kind, name = name, ti = start, tj = close,
|
|
172
|
+
kind = kind, name = name, ni = name_tok, ti = start, tj = close,
|
|
170
173
|
sig = common.sig(T, start, T.m[p] or p),
|
|
171
174
|
['local'] = kw(T, start, 'local') or nil,
|
|
172
175
|
})
|
|
@@ -179,7 +182,7 @@ function M.parse(path, src)
|
|
|
179
182
|
local x = i + 1
|
|
180
183
|
while T.k[x] == 'id' do
|
|
181
184
|
if not kw(T, x + 2, 'function') or not is(T, x + 1, '=') then
|
|
182
|
-
common.add_node(r, T, { kind = 'variable', name = T:text(x), ti = x, tj = x, ['local'] = true })
|
|
185
|
+
common.add_node(r, T, { kind = 'variable', name = T:text(x), ni = x, ti = x, tj = x, ['local'] = true })
|
|
183
186
|
end
|
|
184
187
|
if is(T, x + 1, ',') then x = x + 2 else break end
|
|
185
188
|
end
|
|
@@ -211,8 +214,10 @@ function M.parse(path, src)
|
|
|
211
214
|
if not defs[ref.tok] then kept[#kept + 1] = ref end
|
|
212
215
|
end
|
|
213
216
|
r.refs = kept
|
|
217
|
+
common.assign_refs(r)
|
|
218
|
+
require('codeoutline.lua_bindings').collect(r, T, bm)
|
|
214
219
|
r.member_ops = nil
|
|
215
|
-
return common.finish(r), T
|
|
220
|
+
return common.finish(r, T), T
|
|
216
221
|
end
|
|
217
222
|
|
|
218
223
|
return M
|
|
@@ -120,8 +120,8 @@ parse_block = function(T, r, a, b, parent, in_class)
|
|
|
120
120
|
while last > i and (T.k[last] == 'dedent' or T.k[last] == 'nl') do last = last - 1 end
|
|
121
121
|
local node = common.add_node(r, T, {
|
|
122
122
|
kind = is_class and 'class' or (in_class and 'method' or 'function'),
|
|
123
|
-
name = T:text(name_tok), parent = parent,
|
|
124
|
-
ti = deco_start or i, tj = stop, end_line = T:eline(last),
|
|
123
|
+
name = T:text(name_tok), ni = name_tok, parent = parent,
|
|
124
|
+
ti = deco_start or i, tj = stop, range_end = last, end_line = T:eline(last),
|
|
125
125
|
sig = common.sig(T, i, e - 1),
|
|
126
126
|
decorators = decorators,
|
|
127
127
|
async = head ~= i or nil,
|
|
@@ -157,7 +157,7 @@ parse_block = function(T, r, a, b, parent, in_class)
|
|
|
157
157
|
and (parent == nil or in_class) then
|
|
158
158
|
-- NAME = ... / NAME: type = ... at module or class level
|
|
159
159
|
common.add_node(r, T, {
|
|
160
|
-
kind = in_class and 'field' or 'variable', name = T:text(i),
|
|
160
|
+
kind = in_class and 'field' or 'variable', name = T:text(i), ni = i,
|
|
161
161
|
parent = parent, ti = i, tj = e, sig = common.sig(T, i, e - 1, 120),
|
|
162
162
|
})
|
|
163
163
|
end
|
|
@@ -174,11 +174,11 @@ parse_block = function(T, r, a, b, parent, in_class)
|
|
|
174
174
|
end
|
|
175
175
|
end
|
|
176
176
|
|
|
177
|
-
function M.parse(path, src)
|
|
177
|
+
function M.parse(path, src, language, opts)
|
|
178
178
|
local T = M.lang:tokenize(src)
|
|
179
|
-
local r = common.new(path, 'python')
|
|
179
|
+
local r = common.new(path, 'python', opts)
|
|
180
180
|
parse_block(T, r, 1, T.n, nil, false)
|
|
181
|
-
return common.finish(r), T
|
|
181
|
+
return common.finish(r, T), T
|
|
182
182
|
end
|
|
183
183
|
|
|
184
184
|
return M
|
|
@@ -79,7 +79,7 @@ end
|
|
|
79
79
|
-- Type name in `impl<T> Trait<X> for Type<Y> where ...` / `impl Type`.
|
|
80
80
|
local function impl_target(T, x, body)
|
|
81
81
|
x = skip_angle(T, x, body)
|
|
82
|
-
local first, trait
|
|
82
|
+
local first, trait, name_tok
|
|
83
83
|
local d, y = 0, x
|
|
84
84
|
local names = {}
|
|
85
85
|
while y < body do
|
|
@@ -87,9 +87,11 @@ local function impl_target(T, x, body)
|
|
|
87
87
|
if kw(T, y, 'for') and d == 0 then
|
|
88
88
|
trait = names[#names]
|
|
89
89
|
names = {}
|
|
90
|
+
name_tok = nil
|
|
90
91
|
elseif (T.k[y] == 'id' or kw(T, y, 'Self')) and d == 0 and not is(T, y + 1, '::')
|
|
91
92
|
and T:text(y):sub(1, 1) ~= "'" then -- 'static is a lifetime, not the type
|
|
92
93
|
names[#names + 1] = T:text(y)
|
|
94
|
+
name_tok = name_tok or y
|
|
93
95
|
end
|
|
94
96
|
d = math.max(0, d + angle(T, y))
|
|
95
97
|
y = y + 1
|
|
@@ -103,7 +105,7 @@ local function impl_target(T, x, body)
|
|
|
103
105
|
for z = from, body - 1 do if T.k[z] == 'kw' and T:text(z) == 'where' then to = z - 1; break end end
|
|
104
106
|
if to >= from then first = common.sig(T, from, to, 60):gsub('%s', '') end
|
|
105
107
|
end
|
|
106
|
-
return first, trait
|
|
108
|
+
return first, trait, name_tok or x
|
|
107
109
|
end
|
|
108
110
|
|
|
109
111
|
-- Record calls in [a, b], including macro invocations `name!(..)` / `name![..]`.
|
|
@@ -127,15 +129,20 @@ local function body_members(T, r, o, c, parent, kind)
|
|
|
127
129
|
x = x + 1
|
|
128
130
|
if is(T, x, '(') and T.m[x] then x = T.m[x] + 1 end
|
|
129
131
|
end
|
|
132
|
+
local field
|
|
130
133
|
if T.k[x] == 'id' and (kind == 'enum' or is(T, x + 1, ':')) then
|
|
131
|
-
common.add_node(r, T, { kind = kind == 'enum' and 'enum_member' or 'field', name = T:text(x),
|
|
134
|
+
field = common.add_node(r, T, { kind = kind == 'enum' and 'enum_member' or 'field', name = T:text(x), ni = x,
|
|
132
135
|
parent = parent, ti = x, tj = x })
|
|
136
|
+
if kind == 'enum' then field = nil end
|
|
133
137
|
end
|
|
138
|
+
local type_start = x + 2
|
|
134
139
|
while x < c and not is(T, x, ',') do
|
|
135
140
|
if T.m[x] and T.m[x] > x then x = T.m[x] + 1
|
|
136
141
|
elseif is(T, x, '<') then x = skip_angle(T, x, c)
|
|
137
142
|
else x = x + 1 end
|
|
138
143
|
end
|
|
144
|
+
-- Declared field types serve completion; compact index records omit them.
|
|
145
|
+
if field and r.ranges and type_start <= x - 1 then r.nodes[field].type = common.sig(T, type_start, x - 1, 120) end
|
|
139
146
|
x = x + 1
|
|
140
147
|
end
|
|
141
148
|
end
|
|
@@ -173,7 +180,7 @@ parse_items = function(T, r, a, b, parent, impl_type, in_trait)
|
|
|
173
180
|
local p = skip_angle(T, x + 2, b)
|
|
174
181
|
local e, body = item_end(T, p, b)
|
|
175
182
|
local node = common.add_node(r, T, {
|
|
176
|
-
kind = (impl_type or in_trait) and 'method' or 'function', name = T:text(name_tok),
|
|
183
|
+
kind = (impl_type or in_trait) and 'method' or 'function', name = T:text(name_tok), ni = name_tok,
|
|
177
184
|
parent = parent, ti = start, tj = e,
|
|
178
185
|
sig = common.sig(T, start, body and body - 1 or e, 200), abstract = (not body) or nil,
|
|
179
186
|
})
|
|
@@ -185,21 +192,22 @@ parse_items = function(T, r, a, b, parent, impl_type, in_trait)
|
|
|
185
192
|
stop = e
|
|
186
193
|
elseif (t == 'struct' or t == 'enum' or t == 'union') and T.k[x + 1] == 'id' then
|
|
187
194
|
local e, body = item_end(T, x + 2, b)
|
|
188
|
-
local node = common.add_node(r, T, { kind = t == 'enum' and 'enum' or 'struct', name = T:text(x + 1),
|
|
195
|
+
local node = common.add_node(r, T, { kind = t == 'enum' and 'enum' or 'struct', name = T:text(x + 1), ni = x + 1,
|
|
189
196
|
parent = parent, ti = start, tj = e, sig = common.sig(T, start, body and body - 1 or e, 160) })
|
|
190
197
|
if body then body_members(T, r, body, e, node, t) end
|
|
191
198
|
stop = e
|
|
192
199
|
elseif t == 'trait' and T.k[x + 1] == 'id' then
|
|
193
200
|
local e, body = item_end(T, x + 2, b)
|
|
194
|
-
local node = common.add_node(r, T, { kind = 'interface', name = T:text(x + 1), parent = parent,
|
|
201
|
+
local node = common.add_node(r, T, { kind = 'interface', name = T:text(x + 1), ni = x + 1, parent = parent,
|
|
195
202
|
ti = start, tj = e, sig = common.sig(T, start, body and body - 1 or e, 160) })
|
|
196
203
|
if body then parse_items(T, r, body + 1, e - 1, node, nil, true) end
|
|
197
204
|
stop = e
|
|
198
205
|
elseif t == 'impl' then
|
|
199
206
|
local e, body = item_end(T, x + 1, b)
|
|
200
207
|
if body then
|
|
201
|
-
local ty, trait = impl_target(T, x + 1, body)
|
|
208
|
+
local ty, trait, name_tok = impl_target(T, x + 1, body)
|
|
202
209
|
local node = common.add_node(r, T, { kind = 'impl', name = ty or 'impl', parent = parent,
|
|
210
|
+
ni = name_tok,
|
|
203
211
|
ti = start, tj = e, sig = common.sig(T, start, body - 1, 160), trait = trait })
|
|
204
212
|
r.nodes[node].qualified = ty or 'impl'
|
|
205
213
|
parse_items(T, r, body + 1, e - 1, node, ty, false)
|
|
@@ -208,12 +216,12 @@ parse_items = function(T, r, a, b, parent, impl_type, in_trait)
|
|
|
208
216
|
elseif t == 'mod' and T.k[x + 1] == 'id' then
|
|
209
217
|
local e, body = item_end(T, x + 2, b)
|
|
210
218
|
if body then
|
|
211
|
-
local node = common.add_node(r, T, { kind = 'namespace', name = T:text(x + 1), parent = parent,
|
|
219
|
+
local node = common.add_node(r, T, { kind = 'namespace', name = T:text(x + 1), ni = x + 1, parent = parent,
|
|
212
220
|
ti = start, tj = e })
|
|
213
221
|
parse_items(T, r, body + 1, e - 1, node, nil, false)
|
|
214
222
|
else
|
|
215
223
|
-- `mod x;` declares a file module: a node and an import of x.rs / x/mod.rs
|
|
216
|
-
common.add_node(r, T, { kind = 'namespace', name = T:text(x + 1), parent = parent, ti = start, tj = e })
|
|
224
|
+
common.add_node(r, T, { kind = 'namespace', name = T:text(x + 1), ni = x + 1, parent = parent, ti = start, tj = e })
|
|
217
225
|
r.imports[#r.imports + 1] = { path = T:text(x + 1), line = T:line(x), kind = 'mod' }
|
|
218
226
|
end
|
|
219
227
|
stop = e
|
|
@@ -223,7 +231,7 @@ parse_items = function(T, r, a, b, parent, impl_type, in_trait)
|
|
|
223
231
|
stop = e
|
|
224
232
|
elseif (t == 'type') and T.k[x + 1] == 'id' then
|
|
225
233
|
local e = item_end(T, x + 2, b)
|
|
226
|
-
common.add_node(r, T, { kind = 'typedef', name = T:text(x + 1), parent = parent, ti = start, tj = e,
|
|
234
|
+
common.add_node(r, T, { kind = 'typedef', name = T:text(x + 1), ni = x + 1, parent = parent, ti = start, tj = e,
|
|
227
235
|
sig = common.sig(T, start, e, 160) })
|
|
228
236
|
stop = e
|
|
229
237
|
elseif (t == 'const' or t == 'static') then
|
|
@@ -231,7 +239,7 @@ parse_items = function(T, r, a, b, parent, impl_type, in_trait)
|
|
|
231
239
|
if kw(T, y, 'mut') then y = y + 1 end
|
|
232
240
|
local e = item_end(T, y, b)
|
|
233
241
|
if T.k[y] == 'id' then
|
|
234
|
-
local node = common.add_node(r, T, { kind = t == 'const' and 'constant' or 'variable', name = T:text(y),
|
|
242
|
+
local node = common.add_node(r, T, { kind = t == 'const' and 'constant' or 'variable', name = T:text(y), ni = y,
|
|
235
243
|
parent = parent, ti = start, tj = e, sig = common.sig(T, start, math.min(e, y + 2), 120) })
|
|
236
244
|
if impl_type then r.nodes[node].qualified = impl_type .. '::' .. T:text(y) end
|
|
237
245
|
calls(r, T, y, e)
|
|
@@ -241,7 +249,7 @@ parse_items = function(T, r, a, b, parent, impl_type, in_trait)
|
|
|
241
249
|
local o = x + 3
|
|
242
250
|
local e = (T.m[o] or o)
|
|
243
251
|
if is(T, e + 1, ';') then e = e + 1 end
|
|
244
|
-
common.add_node(r, T, { kind = 'macro', name = T:text(x + 2), parent = parent, ti = start, tj = e })
|
|
252
|
+
common.add_node(r, T, { kind = 'macro', name = T:text(x + 2), ni = x + 2, parent = parent, ti = start, tj = e })
|
|
245
253
|
stop = e
|
|
246
254
|
elseif kw(T, x, 'extern') and kw(T, x + 1, 'crate') then
|
|
247
255
|
local e = item_end(T, x, b)
|
|
@@ -264,13 +272,13 @@ parse_items = function(T, r, a, b, parent, impl_type, in_trait)
|
|
|
264
272
|
end
|
|
265
273
|
end
|
|
266
274
|
|
|
267
|
-
function M.parse(path, src)
|
|
275
|
+
function M.parse(path, src, language, opts)
|
|
268
276
|
local T = M.lang:tokenize(src)
|
|
269
|
-
local r = common.new(path, 'rust')
|
|
277
|
+
local r = common.new(path, 'rust', opts)
|
|
270
278
|
parse_items(T, r, 1, T.n, nil, nil, false)
|
|
271
279
|
-- '::' is the path separator: fix qualified names built with '.'
|
|
272
280
|
for _, n in ipairs(r.nodes) do n.qualified = n.qualified:gsub('%.', '::') end
|
|
273
|
-
return common.finish(r), T
|
|
281
|
+
return common.finish(r, T), T
|
|
274
282
|
end
|
|
275
283
|
|
|
276
284
|
return M
|