@codua/codeoutline-win32-x64 0.1.8 → 0.2.0

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.
Files changed (38) hide show
  1. package/README.md +32 -5
  2. package/README.zh-CN.md +32 -5
  3. package/THIRD_PARTY.md +3 -3
  4. package/bin/xnet.exe +0 -0
  5. package/build-info.json +1 -1
  6. package/package.json +1 -1
  7. package/scripts/codeoutline/cli.lua +2 -2
  8. package/scripts/codeoutline/command.lua +9 -1
  9. package/scripts/codeoutline/common.lua +36 -5
  10. package/scripts/codeoutline/completion.lua +913 -0
  11. package/scripts/codeoutline/control.lua +5 -1
  12. package/scripts/codeoutline/daemon.lua +4 -2
  13. package/scripts/codeoutline/documents.lua +154 -0
  14. package/scripts/codeoutline/explore.lua +32 -7
  15. package/scripts/codeoutline/graph.lua +264 -68
  16. package/scripts/codeoutline/index.lua +168 -48
  17. package/scripts/codeoutline/index_worker.lua +108 -17
  18. package/scripts/codeoutline/lang/c.lua +22 -12
  19. package/scripts/codeoutline/lang/cpp.lua +13 -12
  20. package/scripts/codeoutline/lang/csharp.lua +21 -21
  21. package/scripts/codeoutline/lang/go.lua +10 -10
  22. package/scripts/codeoutline/lang/java.lua +9 -9
  23. package/scripts/codeoutline/lang/js.lua +15 -14
  24. package/scripts/codeoutline/lang/lua.lua +9 -6
  25. package/scripts/codeoutline/lang/python.lua +6 -6
  26. package/scripts/codeoutline/lang/rust.lua +23 -15
  27. package/scripts/codeoutline/lsp.lua +574 -0
  28. package/scripts/codeoutline/main.lua +28 -5
  29. package/scripts/codeoutline/navigation.lua +934 -0
  30. package/scripts/codeoutline/parse.lua +8 -2
  31. package/scripts/codeoutline/parse_pool.lua +189 -0
  32. package/scripts/codeoutline/parse_worker.lua +24 -0
  33. package/scripts/codeoutline/service.lua +82 -31
  34. package/scripts/codeoutline/update_sequence.lua +1 -1
  35. package/scripts/codeoutline/updater.lua +1 -1
  36. package/scripts/codeoutline/version.lua +1 -1
  37. package/scripts/xupgate/client.lua +8 -0
  38. package/licenses/rpmalloc.txt +0 -12
@@ -121,6 +121,7 @@ local function name_before_paren(T, o, floor)
121
121
  return nil
122
122
  end
123
123
  -- qualifier chain: A::B::name, A<T>::name
124
+ local name_first = first
124
125
  local quals = {}
125
126
  local q = first - 1
126
127
  while q > floor and is(T, q, '::') do
@@ -131,7 +132,7 @@ local function name_before_paren(T, o, floor)
131
132
  first = z
132
133
  q = z - 1
133
134
  end
134
- return { first = first, name = name, quals = quals }
135
+ return { first = first, name = name, quals = quals, ni = name_first, nj = p }
135
136
  end
136
137
 
137
138
  -- If the '{' at j opens a function body, describe the head; the parameter
@@ -205,7 +206,7 @@ local function cpp_decl(T, r, i, j, parent)
205
206
  if first == 'typedef' then return c.declaration(T, r, i, j, parent) end
206
207
  if first == 'using' then
207
208
  if T.k[i + 1] == 'id' and is(T, i + 2, '=') then
208
- common.add_node(r, T, { kind = 'typedef', name = T:text(i + 1), parent = parent, ti = i, tj = j, sig = common.sig(T, i, j) })
209
+ common.add_node(r, T, { kind = 'typedef', name = T:text(i + 1), ni = i + 1, parent = parent, ti = i, tj = j, sig = common.sig(T, i, j) })
209
210
  end
210
211
  return
211
212
  end
@@ -231,7 +232,7 @@ local function cpp_decl(T, r, i, j, parent)
231
232
  return
232
233
  end
233
234
  common.add_node(r, T, {
234
- kind = 'prototype', name = info.name, parent = parent,
235
+ kind = 'prototype', name = info.name, ni = info.ni, nj = info.nj, parent = parent,
235
236
  ti = i, tj = j, sig = common.sig(T, i, T.m[y]),
236
237
  quals = #info.quals > 0 and info.quals or nil,
237
238
  static = first == 'static' or nil,
@@ -262,7 +263,7 @@ local function cpp_decl(T, r, i, j, parent)
262
263
  q = q - 2
263
264
  end
264
265
  common.add_node(r, T, {
265
- kind = 'variable', name = T:text(x), parent = parent, ti = x, tj = j,
266
+ kind = 'variable', name = T:text(x), ni = x, parent = parent, ti = x, tj = j,
266
267
  static = first == 'static' or nil, sig = common.sig(T, i, math.min(j, x + 1)),
267
268
  quals = #quals > 0 and quals or nil,
268
269
  })
@@ -333,7 +334,7 @@ local function aggregate(T, r, i, head, j, close, b, parent, agg)
333
334
  local node
334
335
  if nm then
335
336
  node = common.add_node(r, T, {
336
- kind = kind, name = T:text(nm), parent = parent,
337
+ kind = kind, name = T:text(nm), ni = nm, parent = parent,
337
338
  ti = i, tj = close, sig = common.sig(T, head, j - 1), bases = bases,
338
339
  })
339
340
  if kind == 'enum' then
@@ -347,7 +348,7 @@ local function aggregate(T, r, i, head, j, close, b, parent, agg)
347
348
  cpp_range(T, r, j + 1, close - 1, parent) -- anonymous struct/union members
348
349
  end
349
350
  if alias and alias ~= nm then
350
- common.add_node(r, T, { kind = 'typedef', name = T:text(alias), parent = parent, ti = alias, tj = alias })
351
+ common.add_node(r, T, { kind = 'typedef', name = T:text(alias), ni = alias, parent = parent, ti = alias, tj = alias })
351
352
  elseif not alias and stop > close + 1 then
352
353
  cpp_decl(T, r, close + 1, math.min(stop, b), parent)
353
354
  end
@@ -382,7 +383,7 @@ cpp_range = function(T, r, a, b, parent)
382
383
  for part in full:gmatch('[^:]+') do quals[#quals + 1] = part end
383
384
  local name = table.remove(quals)
384
385
  node = common.add_node(r, T, {
385
- kind = 'namespace', name = name, parent = parent, ti = i, tj = close,
386
+ kind = 'namespace', name = name, ni = j - 1, parent = parent, ti = i, tj = close,
386
387
  quals = #quals > 0 and quals or nil,
387
388
  })
388
389
  end
@@ -423,7 +424,7 @@ cpp_range = function(T, r, a, b, parent)
423
424
  local close = T.m[body] or c.fallback_close(T, body, b)
424
425
  if info then
425
426
  common.add_node(r, T, {
426
- kind = 'function', name = info.name, parent = parent, ti = i, tj = close,
427
+ kind = 'function', name = info.name, ni = info.ni, nj = info.nj, parent = parent, ti = i, tj = close,
427
428
  sig = common.sig(T, head, info.close),
428
429
  quals = #info.quals > 0 and info.quals or nil,
429
430
  })
@@ -450,7 +451,7 @@ cpp_range = function(T, r, a, b, parent)
450
451
  end
451
452
  if info then
452
453
  common.add_node(r, T, {
453
- kind = 'function', name = info.name, parent = parent, ti = i, tj = close,
454
+ kind = 'function', name = info.name, ni = info.ni, nj = info.nj, parent = parent, ti = i, tj = close,
454
455
  sig = common.sig(T, head, info.close),
455
456
  quals = #info.quals > 0 and info.quals or nil,
456
457
  static = T:text(head) == 'static' or nil,
@@ -520,13 +521,13 @@ local function finalize(r)
520
521
  end
521
522
  end
522
523
 
523
- function M.parse(path, src)
524
+ function M.parse(path, src, language, opts)
524
525
  local T = M.lang:tokenize(src)
525
- local r = common.new(path, 'cpp')
526
+ local r = common.new(path, 'cpp', opts)
526
527
  r.skip_calls = ATTR
527
528
  cpp_range(T, r, 1, T.n, nil)
528
529
  finalize(r)
529
- return common.finish(r), T
530
+ return common.finish(r, T), T
530
531
  end
531
532
 
532
533
  -- A .h file is C++ when it uses C++-only syntax; otherwise the C parser
@@ -79,7 +79,7 @@ local function member_head(T, i, j)
79
79
  while x < j do
80
80
  if is(T, x, '(') and d == 0 then
81
81
  local p = x - 1
82
- if T.k[p] == 'op' and kw(T, p - 1, 'operator') then return 'operator' .. T:text(p), p, x end
82
+ if T.k[p] == 'op' and kw(T, p - 1, 'operator') then return 'operator' .. T:text(p), p - 1, x, p end
83
83
  if is(T, p, '>') or is(T, p, '>>') then
84
84
  local dd = 0
85
85
  while p > i do
@@ -90,12 +90,12 @@ local function member_head(T, i, j)
90
90
  p = p - 1
91
91
  end
92
92
  if T.k[p] == 'id' then
93
- if is(T, p - 1, '~') then return '~' .. T:text(p), p, x end
94
- if kw(T, p - 1, 'operator') then return 'operator ' .. T:text(p), p, x end -- conversion
95
- return T:text(p), p, x
93
+ if is(T, p - 1, '~') then return '~' .. T:text(p), p - 1, x, p end
94
+ if kw(T, p - 1, 'operator') then return 'operator ' .. T:text(p), p - 1, x, p end -- conversion
95
+ return T:text(p), p, x, p
96
96
  end
97
- if T.k[p] == 'op' and kw(T, p - 1, 'operator') then return 'operator' .. T:text(p), p, x end
98
- if T.k[p] == 'kw' and kw(T, p - 1, 'operator') then return 'operator ' .. T:text(p), p, x end
97
+ if T.k[p] == 'op' and kw(T, p - 1, 'operator') then return 'operator' .. T:text(p), p - 1, x, p end
98
+ if T.k[p] == 'kw' and kw(T, p - 1, 'operator') then return 'operator ' .. T:text(p), p - 1, x, p end
99
99
  -- not after a name: a tuple type such as `(int, string) Name(...)`
100
100
  if T.m[x] then x = T.m[x] end
101
101
  elseif (is(T, x, '(') or is(T, x, '[')) and T.m[x] then
@@ -134,7 +134,7 @@ local function type_decl(T, r, i, kwi, o, parent, kind)
134
134
  if kind == 'record' and (kw(T, name_tok, 'class') or kw(T, name_tok, 'struct')) then name_tok = name_tok + 1 end
135
135
  local bodyless = is(T, o, ';')
136
136
  local close = bodyless and o or (T.m[o] or T.n)
137
- local node = common.add_node(r, T, { kind = kind, name = T:text(name_tok), parent = parent,
137
+ local node = common.add_node(r, T, { kind = kind, name = T:text(name_tok), ni = name_tok, parent = parent,
138
138
  ti = i, tj = close, sig = common.sig(T, i, o - 1, 200) })
139
139
  -- `: Base, IFace` after the name, generic parameters and record params
140
140
  local x = name_tok + 1
@@ -149,7 +149,7 @@ local function type_decl(T, r, i, kwi, o, parent, kind)
149
149
  if kind == 'record' then -- positional record parameters -> properties
150
150
  for z = x + 1, T.m[x] - 1 do
151
151
  if T.k[z] == 'id' and (is(T, z + 1, ',') or z + 1 == T.m[x] or is(T, z + 1, '=')) then
152
- common.add_node(r, T, { kind = 'property', name = T:text(z), parent = node, ti = z, tj = z })
152
+ common.add_node(r, T, { kind = 'property', name = T:text(z), ni = z, parent = node, ti = z, tj = z })
153
153
  end
154
154
  end
155
155
  end
@@ -164,7 +164,7 @@ local function type_decl(T, r, i, kwi, o, parent, kind)
164
164
  while y < close do
165
165
  while is(T, y, '[') and T.m[y] do y = T.m[y] + 1 end
166
166
  if T.k[y] == 'id' then
167
- common.add_node(r, T, { kind = 'enum_member', name = T:text(y), parent = node, ti = y, tj = y })
167
+ common.add_node(r, T, { kind = 'enum_member', name = T:text(y), ni = y, parent = node, ti = y, tj = y })
168
168
  end
169
169
  while y < close and not is(T, y, ',') do y = (T.m[y] and T.m[y] > y) and T.m[y] + 1 or y + 1 end
170
170
  y = y + 1
@@ -198,12 +198,12 @@ parse_members = function(T, r, a, b, parent, class_name)
198
198
  elseif k == 'kw' and t == 'namespace' then
199
199
  local name, x = dotted(T, i + 1)
200
200
  if is(T, x, '{') and T.m[x] then
201
- local node = common.add_node(r, T, { kind = 'namespace', name = name, parent = parent, ti = i, tj = T.m[x] })
201
+ local node = common.add_node(r, T, { kind = 'namespace', name = name, ni = i + 1, nj = x - 1, parent = parent, ti = i, tj = T.m[x] })
202
202
  parse_members(T, r, x + 1, T.m[x] - 1, node, nil)
203
203
  i = T.m[x] + 1
204
204
  else
205
205
  -- file-scoped: namespace A.B; applies to the rest of the file
206
- local node = common.add_node(r, T, { kind = 'namespace', name = name, parent = parent, ti = i, tj = b })
206
+ local node = common.add_node(r, T, { kind = 'namespace', name = name, ni = i + 1, nj = x - 1, parent = parent, ti = i, tj = b })
207
207
  parse_members(T, r, x + 1, b, node, nil)
208
208
  i = b + 1
209
209
  end
@@ -229,16 +229,16 @@ parse_members = function(T, r, a, b, parent, class_name)
229
229
  -- declaration without a '{' body
230
230
  local is_delegate = false
231
231
  for y = i, j do if kw(T, y, 'delegate') then is_delegate = true; break end end
232
- local name, nt, o = member_head(T, i, j)
232
+ local name, nt, o, ne = member_head(T, i, j)
233
233
  if name and (not eq or eq > o) then
234
234
  local kind = is_delegate and 'typedef' or (name == class_name and 'constructor')
235
235
  or (name:sub(1, 1) == '~' and 'destructor') or 'method'
236
- common.add_node(r, T, { kind = kind, name = name, parent = parent, ti = i, tj = j,
236
+ common.add_node(r, T, { kind = kind, name = name, ni = nt, nj = ne, parent = parent, ti = i, tj = j,
237
237
  sig = common.sig(T, i, T.m[o] or o, 200), abstract = (not eq) or nil })
238
238
  common.add_calls(r, T, (T.m[o] or o) + 1, j)
239
239
  elseif eq and is(T, eq, '=>') and T.k[eq - 1] == 'id' then
240
240
  -- expression-bodied property: int X => expr;
241
- common.add_node(r, T, { kind = 'property', name = T:text(eq - 1), parent = parent,
241
+ common.add_node(r, T, { kind = 'property', name = T:text(eq - 1), ni = eq - 1, parent = parent,
242
242
  ti = i, tj = j, sig = common.sig(T, i, eq - 1, 160) })
243
243
  common.add_calls(r, T, eq, j)
244
244
  else
@@ -251,7 +251,7 @@ parse_members = function(T, r, a, b, parent, class_name)
251
251
  elseif not init and dd == 0 and T.k[y] == 'id' and T.k[y + 1] == 'op' then
252
252
  local nx = T:text(y + 1)
253
253
  if nx == '=' or nx == ';' or nx == ',' then
254
- common.add_node(r, T, { kind = 'field', name = T:text(y), parent = parent,
254
+ common.add_node(r, T, { kind = 'field', name = T:text(y), ni = y, parent = parent,
255
255
  ti = y, tj = j, sig = common.sig(T, i, math.min(j - 1, y + 1), 160) })
256
256
  end
257
257
  end
@@ -284,18 +284,18 @@ parse_members = function(T, r, a, b, parent, class_name)
284
284
  elseif eq then
285
285
  j = close -- initializer { ... }: continue to ';'
286
286
  else
287
- local name, nt, o = member_head(T, i, j)
287
+ local name, nt, o, ne = member_head(T, i, j)
288
288
  if name and o < j then
289
289
  local kind = (name == class_name and 'constructor')
290
290
  or (name:sub(1, 1) == '~' and 'destructor') or 'method'
291
- common.add_node(r, T, { kind = kind, name = name, parent = parent, ti = i, tj = close,
291
+ common.add_node(r, T, { kind = kind, name = name, ni = nt, nj = ne, parent = parent, ti = i, tj = close,
292
292
  sig = common.sig(T, i, T.m[o] or o, 200) })
293
293
  common.add_calls(r, T, (T.m[o] or o) + 1, close)
294
294
  j = close
295
295
  done = true
296
296
  elseif T.k[j - 1] == 'id' then
297
297
  -- property with accessors: Type Name { get; set; } [= init;]
298
- common.add_node(r, T, { kind = 'property', name = T:text(j - 1), parent = parent,
298
+ common.add_node(r, T, { kind = 'property', name = T:text(j - 1), ni = j - 1, parent = parent,
299
299
  ti = i, tj = close, sig = common.sig(T, i, j - 1, 160) })
300
300
  common.add_calls(r, T, j, close)
301
301
  if is(T, close + 1, '=') then
@@ -324,11 +324,11 @@ parse_members = function(T, r, a, b, parent, class_name)
324
324
  end
325
325
  end
326
326
 
327
- function M.parse(path, src)
327
+ function M.parse(path, src, language, opts)
328
328
  local T = M.lang:tokenize(src)
329
- local r = common.new(path, 'csharp')
329
+ local r = common.new(path, 'csharp', opts)
330
330
  parse_members(T, r, 1, T.n, nil, nil)
331
- return common.finish(r), T
331
+ return common.finish(r, T), T
332
332
  end
333
333
 
334
334
  return M
@@ -90,7 +90,7 @@ local function type_members(T, r, o, c, parent, is_interface)
90
90
  if T.k[first] == 'id' then
91
91
  if is_interface then
92
92
  if is(T, first + 1, '(') then
93
- common.add_node(r, T, { kind = 'method', name = T:text(first), parent = parent,
93
+ common.add_node(r, T, { kind = 'method', name = T:text(first), ni = first, parent = parent,
94
94
  ti = first, tj = last, sig = common.sig(T, first, last), abstract = true })
95
95
  end
96
96
  else
@@ -104,18 +104,18 @@ local function type_members(T, r, o, c, parent, is_interface)
104
104
  or (last == first + 1 and T.k[last] == 'str'))
105
105
  if embedded then
106
106
  local e = is(T, first + 1, '.') and first + 2 or first
107
- common.add_node(r, T, { kind = 'field', name = T:text(e), parent = parent,
107
+ common.add_node(r, T, { kind = 'field', name = T:text(e), ni = e, parent = parent,
108
108
  ti = first, tj = last, sig = common.sig(T, first, last), embedded = true })
109
109
  else
110
110
  for _, nz in ipairs(names) do
111
- common.add_node(r, T, { kind = 'field', name = T:text(nz), parent = parent,
111
+ common.add_node(r, T, { kind = 'field', name = T:text(nz), ni = nz, parent = parent,
112
112
  ti = nz, tj = last, sig = common.sig(T, first, last) })
113
113
  end
114
114
  end
115
115
  end
116
116
  elseif is(T, first, '*') and T.k[first + 1] == 'id' and not is_interface then
117
117
  local e = is(T, first + 2, '.') and first + 3 or first + 1
118
- common.add_node(r, T, { kind = 'field', name = T:text(e), parent = parent,
118
+ common.add_node(r, T, { kind = 'field', name = T:text(e), ni = e, parent = parent,
119
119
  ti = first, tj = last, embedded = true })
120
120
  end
121
121
  x = last + 1
@@ -137,7 +137,7 @@ local function type_spec(T, r, x, b, start)
137
137
  end
138
138
  local stop = body and (T.m[body] or b) or stmt_end(T, x, b)
139
139
  local node = common.add_node(r, T, {
140
- kind = kind, name = T:text(x), ti = start or x, tj = stop,
140
+ kind = kind, name = T:text(x), ni = x, ti = start or x, tj = stop,
141
141
  sig = common.sig(T, start or x, body and body - 1 or stop, 160),
142
142
  })
143
143
  if body then type_members(T, r, body, stop, node, kind == 'interface') end
@@ -151,7 +151,7 @@ local function value_specs(T, r, a, b, kind)
151
151
  local last = stmt_end(T, x, b)
152
152
  local z = x
153
153
  while T.k[z] == 'id' and z <= last do
154
- common.add_node(r, T, { kind = kind, name = T:text(z), ti = z, tj = last,
154
+ common.add_node(r, T, { kind = kind, name = T:text(z), ni = z, ti = z, tj = last,
155
155
  sig = common.sig(T, x, last, 120) })
156
156
  if is(T, z + 1, ',') then z = z + 2 else break end
157
157
  end
@@ -160,9 +160,9 @@ local function value_specs(T, r, a, b, kind)
160
160
  end
161
161
  end
162
162
 
163
- function M.parse(path, src)
163
+ function M.parse(path, src, language, opts)
164
164
  local T = M.lang:tokenize(src)
165
- local r = common.new(path, 'go')
165
+ local r = common.new(path, 'go', opts)
166
166
  local i, n = 1, T.n
167
167
  while i <= n do
168
168
  if kw(T, i, 'package') and T.k[i + 1] == 'id' then
@@ -191,7 +191,7 @@ function M.parse(path, src)
191
191
  local body = func_body(T, pc, n)
192
192
  local close = body and (T.m[body] or n) or pc
193
193
  local node = common.add_node(r, T, {
194
- kind = recv and 'method' or 'function', name = T:text(x), ti = i, tj = close,
194
+ kind = recv and 'method' or 'function', name = T:text(x), ni = x, ti = i, tj = close,
195
195
  sig = common.sig(T, i, body and body - 1 or pc, 200), recv = recv,
196
196
  })
197
197
  if recv then r.nodes[node].qualified = recv .. '.' .. T:text(x) end
@@ -227,7 +227,7 @@ function M.parse(path, src)
227
227
  i = i + 1
228
228
  end
229
229
  end
230
- return common.finish(r), T
230
+ return common.finish(r, T), T
231
231
  end
232
232
 
233
233
  return M
@@ -87,7 +87,7 @@ local parse_members
87
87
  local function type_decl(T, r, i, kwi, o, parent, kind)
88
88
  local name_tok = kwi + 1
89
89
  local node = common.add_node(r, T, {
90
- kind = kind, name = T:text(name_tok), parent = parent,
90
+ kind = kind, name = T:text(name_tok), ni = name_tok, parent = parent,
91
91
  ti = i, tj = T.m[o] or T.n, sig = common.sig(T, i, o - 1),
92
92
  })
93
93
  local n = r.nodes[node]
@@ -113,7 +113,7 @@ local function type_decl(T, r, i, kwi, o, parent, kind)
113
113
  local c = T.m[name_tok + 1]
114
114
  for x = name_tok + 2, c - 1 do
115
115
  if T.k[x] == 'id' and (is(T, x + 1, ',') or x + 1 == c) then
116
- common.add_node(r, T, { kind = 'field', name = T:text(x), parent = node, ti = x, tj = x })
116
+ common.add_node(r, T, { kind = 'field', name = T:text(x), ni = x, parent = node, ti = x, tj = x })
117
117
  end
118
118
  end
119
119
  end
@@ -128,7 +128,7 @@ local function type_decl(T, r, i, kwi, o, parent, kind)
128
128
  local y = x + 1
129
129
  if is(T, y, '(') and T.m[y] then y = T.m[y] + 1 end
130
130
  if is(T, y, '{') and T.m[y] then y = T.m[y] + 1 end
131
- common.add_node(r, T, { kind = 'enum_member', name = T:text(x), parent = node, ti = x, tj = y - 1 })
131
+ common.add_node(r, T, { kind = 'enum_member', name = T:text(x), ni = x, parent = node, ti = x, tj = y - 1 })
132
132
  common.add_calls(r, T, x + 1, y - 1)
133
133
  x = y
134
134
  end
@@ -170,7 +170,7 @@ parse_members = function(T, r, a, b, parent, class_name)
170
170
  if eq and y >= eq then break end
171
171
  end
172
172
  if p then
173
- common.add_node(r, T, { kind = 'method', name = T:text(p), parent = parent, ti = mstart, tj = j, sig = common.sig(T, i, T.m[p + 1]), abstract = true })
173
+ common.add_node(r, T, { kind = 'method', name = T:text(p), ni = p, parent = parent, ti = mstart, tj = j, sig = common.sig(T, i, T.m[p + 1]), abstract = true })
174
174
  else
175
175
  -- field names: identifiers at angle depth 0 followed by = , ;
176
176
  -- (initializer bracket groups are skipped whole, so
@@ -185,7 +185,7 @@ parse_members = function(T, r, a, b, parent, class_name)
185
185
  -- `Type[] name`: a '[' after the type, not the name
186
186
  local array_type = nx == '[' and T.m[y + 1] and T.k[T.m[y + 1] + 1] == 'id'
187
187
  if (nx == '=' or nx == ';' or nx == ',' or nx == '[') and not array_type then
188
- common.add_node(r, T, { kind = 'field', name = T:text(y), parent = parent, ti = y, tj = j, sig = common.sig(T, i, math.min(j - 1, y + 1)) })
188
+ common.add_node(r, T, { kind = 'field', name = T:text(y), ni = y, parent = parent, ti = y, tj = j, sig = common.sig(T, i, math.min(j - 1, y + 1)) })
189
189
  end
190
190
  end
191
191
  if init and T.m[y] and T.m[y] > y and T.k[y] == 'op' then y = T.m[y] end
@@ -224,7 +224,7 @@ parse_members = function(T, r, a, b, parent, class_name)
224
224
  local name = T:text(o - 1)
225
225
  common.add_node(r, T, {
226
226
  kind = (name == class_name) and 'constructor' or 'method',
227
- name = name, parent = parent, ti = mstart, tj = close,
227
+ name = name, ni = o - 1, parent = parent, ti = mstart, tj = close,
228
228
  sig = common.sig(T, i, x),
229
229
  })
230
230
  end
@@ -243,9 +243,9 @@ parse_members = function(T, r, a, b, parent, class_name)
243
243
  end
244
244
  end
245
245
 
246
- function M.parse(path, src)
246
+ function M.parse(path, src, language, opts)
247
247
  local T = M.lang:tokenize(src)
248
- local r = common.new(path, 'java')
248
+ local r = common.new(path, 'java', opts)
249
249
  local i = 1
250
250
  while i <= T.n do
251
251
  if T.k[i] == 'kw' and T:text(i) == 'package' then
@@ -268,7 +268,7 @@ function M.parse(path, src)
268
268
  end
269
269
  end
270
270
  parse_members(T, r, i, T.n, nil, nil)
271
- return common.finish(r), T
271
+ return common.finish(r, T), T
272
272
  end
273
273
 
274
274
  return M
@@ -178,7 +178,7 @@ local function scan(T, r, a, b, parent, defs, stem)
178
178
  or kw(T, start - 1, 'default') or word(T, start - 1, 'declare')) do start = start - 1 end
179
179
  local close = body and (T.m[body] or b) or T.m[p]
180
180
  defs[name_tok] = true
181
- local node = common.add_node(r, T, { kind = 'function', name = T:text(name_tok), parent = parent,
181
+ local node = common.add_node(r, T, { kind = 'function', name = T:text(name_tok), ni = name_tok, parent = parent,
182
182
  ti = start, tj = close, sig = common.sig(T, start, body and body - 1 or T.m[p], 200) })
183
183
  if body then scan(T, r, body + 1, close - 1, node, defs, stem) end
184
184
  i = close + 1
@@ -214,6 +214,7 @@ local function scan(T, r, a, b, parent, defs, stem)
214
214
  local kind = t == 'class' and 'class' or 'interface'
215
215
  local node = common.add_node(r, T, {
216
216
  kind = kind, name = name_tok and T:text(name_tok) or (is(T, i - 1, '=') and T:text(i - 2)) or 'default',
217
+ ni = name_tok or i,
217
218
  parent = parent, ti = start, tj = T.m[x], sig = common.sig(T, start, x - 1, 200),
218
219
  extends = #extends > 0 and extends or nil, implements = #implements > 0 and implements or nil,
219
220
  })
@@ -224,12 +225,12 @@ local function scan(T, r, a, b, parent, defs, stem)
224
225
  end
225
226
  elseif k == 'kw' and t == 'enum' and T.k[i + 1] == 'id' and is(T, i + 2, '{') and T.m[i + 2] then
226
227
  local c = T.m[i + 2]
227
- local node = common.add_node(r, T, { kind = 'enum', name = T:text(i + 1), parent = parent, ti = i, tj = c })
228
+ local node = common.add_node(r, T, { kind = 'enum', name = T:text(i + 1), ni = i + 1, parent = parent, ti = i, tj = c })
228
229
  local x = i + 3
229
230
  while x < c do
230
231
  if T.k[x] == 'id' or T.k[x] == 'str' then
231
232
  local nm = T.k[x] == 'str' and T:text(x):sub(2, -2) or T:text(x)
232
- common.add_node(r, T, { kind = 'enum_member', name = nm, parent = node, ti = x, tj = x })
233
+ common.add_node(r, T, { kind = 'enum_member', name = nm, ni = x, parent = node, ti = x, tj = x })
233
234
  end
234
235
  while x < c and not is(T, x, ',') do x = (T.m[x] and T.m[x] > x) and T.m[x] + 1 or x + 1 end
235
236
  x = x + 1
@@ -241,7 +242,7 @@ local function scan(T, r, a, b, parent, defs, stem)
241
242
  local y = skip_angle(T, i + 2, b)
242
243
  if is(T, y, '=') then
243
244
  local stop = expr_end(T, y + 1, b)
244
- common.add_node(r, T, { kind = 'typedef', name = T:text(i + 1), parent = parent, ti = i, tj = stop,
245
+ common.add_node(r, T, { kind = 'typedef', name = T:text(i + 1), ni = i + 1, parent = parent, ti = i, tj = stop,
245
246
  sig = common.sig(T, i, stop, 160) })
246
247
  i = stop + 1
247
248
  handled = true
@@ -252,7 +253,7 @@ local function scan(T, r, a, b, parent, defs, stem)
252
253
  while x <= b and (T.k[x] == 'id' or is(T, x, '.') or T.k[x] == 'str') do x = x + 1 end
253
254
  if is(T, x, '{') and T.m[x] then
254
255
  local nm = common.sig(T, i + 1, x - 1):gsub('%s', ''):gsub('^["\']', ''):gsub('["\']$', '')
255
- local node = common.add_node(r, T, { kind = 'namespace', name = nm, parent = parent, ti = i, tj = T.m[x] })
256
+ local node = common.add_node(r, T, { kind = 'namespace', name = nm, ni = i + 1, nj = x - 1, parent = parent, ti = i, tj = T.m[x] })
256
257
  scan(T, r, x + 1, T.m[x] - 1, node, defs, stem)
257
258
  i = T.m[x] + 1
258
259
  handled = true
@@ -272,7 +273,7 @@ local function scan(T, r, a, b, parent, defs, stem)
272
273
  local start = kw(T, i - 1, 'export') and i - 1 or i
273
274
  if fs then
274
275
  defs[name_tok] = true
275
- local node = common.add_node(r, T, { kind = 'function', name = T:text(name_tok), parent = parent,
276
+ local node = common.add_node(r, T, { kind = 'function', name = T:text(name_tok), ni = name_tok, parent = parent,
276
277
  ti = start, tj = fe, sig = common.sig(T, start, math.max(fb - 1, name_tok), 200) })
277
278
  if fb and is(T, fb, '{') then scan(T, r, fb + 1, fe - 1, node, defs, stem) end
278
279
  i = fe + 1
@@ -280,7 +281,7 @@ local function scan(T, r, a, b, parent, defs, stem)
280
281
  elseif not parent then
281
282
  local stop = expr_end(T, y + 1, b)
282
283
  defs[name_tok] = true
283
- common.add_node(r, T, { kind = 'variable', name = T:text(name_tok), ti = start, tj = stop,
284
+ common.add_node(r, T, { kind = 'variable', name = T:text(name_tok), ni = name_tok, ti = start, tj = stop,
284
285
  sig = common.sig(T, start, math.min(stop, y + 1), 120) })
285
286
  -- keep scanning inside the initializer (object literals with functions, IIFEs)
286
287
  end
@@ -325,7 +326,7 @@ local function scan(T, r, a, b, parent, defs, stem)
325
326
  y = y - 2
326
327
  end
327
328
  defs[i] = true
328
- local node = common.add_node(r, T, { kind = 'function', name = T:text(i), parent = parent,
329
+ local node = common.add_node(r, T, { kind = 'function', name = T:text(i), ni = i, parent = parent,
329
330
  ti = y, tj = fe, sig = common.sig(T, y, math.max(fb - 1, i), 200) })
330
331
  r.nodes[node].qualified = table.concat(parts, '.')
331
332
  if fb and is(T, fb, '{') then scan(T, r, fb + 1, fe - 1, node, defs, stem) end
@@ -409,7 +410,7 @@ parse_class_body = function(T, r, o, c, parent, defs, stem)
409
410
  if name then
410
411
  defs[name_tok] = true
411
412
  local kind = (name == 'constructor') and 'constructor' or 'method'
412
- local node = common.add_node(r, T, { kind = kind, name = name, parent = parent,
413
+ local node = common.add_node(r, T, { kind = kind, name = name, ni = name_tok, parent = parent,
413
414
  ti = start, tj = close, sig = common.sig(T, start, body and body - 1 or T.m[y], 200),
414
415
  abstract = (not body) or nil })
415
416
  if body then scan(T, r, body + 1, close - 1, node, defs, stem) end
@@ -431,12 +432,12 @@ parse_class_body = function(T, r, o, c, parent, defs, stem)
431
432
  local fs, fe, fb
432
433
  if eq then fs, fe, fb = func_expr(T, eq + 1, c - 1) end
433
434
  if fs then
434
- local node = common.add_node(r, T, { kind = 'method', name = name, parent = parent,
435
+ local node = common.add_node(r, T, { kind = 'method', name = name, ni = name_tok, parent = parent,
435
436
  ti = start, tj = fe, sig = common.sig(T, start, math.max(fb - 1, name_tok), 200) })
436
437
  if is(T, fb, '{') then scan(T, r, fb + 1, fe - 1, node, defs, stem) end
437
438
  stop = math.max(stop, fe)
438
439
  else
439
- common.add_node(r, T, { kind = 'field', name = name, parent = parent,
440
+ common.add_node(r, T, { kind = 'field', name = name, ni = name_tok, parent = parent,
440
441
  ti = start, tj = stop, sig = common.sig(T, start, stop, 120) })
441
442
  if eq then scan(T, r, eq + 1, stop, parent, defs, stem) end
442
443
  end
@@ -448,9 +449,9 @@ parse_class_body = function(T, r, o, c, parent, defs, stem)
448
449
  end
449
450
  end
450
451
 
451
- function M.parse(path, src, language)
452
+ function M.parse(path, src, language, opts)
452
453
  local T = M.lang:tokenize(src)
453
- local r = common.new(path, language or 'javascript')
454
+ local r = common.new(path, language or 'javascript', opts)
454
455
  local defs = {}
455
456
  local stem = path:match('([^/\\]+)%.[^./\\]+$') or path
456
457
  scan(T, r, 1, T.n, nil, defs, stem)
@@ -460,7 +461,7 @@ function M.parse(path, src, language)
460
461
  if not defs[ref.tok] then kept[#kept + 1] = ref end
461
462
  end
462
463
  r.refs = kept
463
- return common.finish(r), T
464
+ return common.finish(r, T), T
464
465
  end
465
466
 
466
467
  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
@@ -212,7 +215,7 @@ function M.parse(path, src)
212
215
  end
213
216
  r.refs = kept
214
217
  r.member_ops = nil
215
- return common.finish(r), T
218
+ return common.finish(r, T), T
216
219
  end
217
220
 
218
221
  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