@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.
Files changed (39) hide show
  1. package/README.md +1 -0
  2. package/bin/xnet.exe +0 -0
  3. package/build-info.json +1 -1
  4. package/package.json +1 -1
  5. package/scripts/codeoutline/callers.lua +116 -0
  6. package/scripts/codeoutline/command.lua +7 -3
  7. package/scripts/codeoutline/common.lua +29 -3
  8. package/scripts/codeoutline/completion.lua +162 -62
  9. package/scripts/codeoutline/cpp_bindings.lua +116 -0
  10. package/scripts/codeoutline/cpp_types.lua +209 -0
  11. package/scripts/codeoutline/csharp_bindings.lua +498 -0
  12. package/scripts/codeoutline/dispatch_aliases.lua +474 -0
  13. package/scripts/codeoutline/documents.lua +11 -1
  14. package/scripts/codeoutline/explore.lua +73 -12
  15. package/scripts/codeoutline/foreign.lua +125 -0
  16. package/scripts/codeoutline/foreign_lua.lua +273 -0
  17. package/scripts/codeoutline/graph.lua +80 -22
  18. package/scripts/codeoutline/index.lua +15 -6
  19. package/scripts/codeoutline/index_worker.lua +15 -7
  20. package/scripts/codeoutline/indirect.lua +148 -50
  21. package/scripts/codeoutline/js_evidence.lua +30 -2
  22. package/scripts/codeoutline/js_resolution.lua +34 -0
  23. package/scripts/codeoutline/lang/csharp.lua +15 -3
  24. package/scripts/codeoutline/lang/lua.lua +17 -2
  25. package/scripts/codeoutline/lsp.lua +58 -34
  26. package/scripts/codeoutline/lua_bindings.lua +242 -34
  27. package/scripts/codeoutline/lua_literal.lua +38 -0
  28. package/scripts/codeoutline/main.lua +24 -3
  29. package/scripts/codeoutline/mcp.lua +13 -4
  30. package/scripts/codeoutline/navigation.lua +337 -96
  31. package/scripts/codeoutline/ordinary_bindings.lua +220 -0
  32. package/scripts/codeoutline/parse.lua +2 -0
  33. package/scripts/codeoutline/python_bindings.lua +112 -0
  34. package/scripts/codeoutline/query_report.lua +126 -0
  35. package/scripts/codeoutline/rules.lua +127 -0
  36. package/scripts/codeoutline/service.lua +11 -3
  37. package/scripts/codeoutline/static_dispatch.lua +534 -0
  38. package/scripts/codeoutline/update_sequence.lua +1 -1
  39. package/scripts/codeoutline/version.lua +1 -1
@@ -82,7 +82,7 @@ function M.collect(r, T)
82
82
  scopes[i] = stack[#stack] or 0
83
83
  if stack[#stack] and T.m[stack[#stack]] == i then stack[#stack] = nil end
84
84
  end
85
- local bindings, parameters = {}, {}
85
+ local bindings, parameters, alias_tokens = {}, {}, {}
86
86
  local callable_at = {}
87
87
  for _, n in ipairs(r.nodes) do
88
88
  if n.kind == 'function' or n.kind == 'method' or n.kind == 'constructor' then
@@ -141,6 +141,10 @@ function M.collect(r, T)
141
141
  if after and T:text(after) ~= '=' and T:text(after) ~= ',' and T:text(after) ~= ')' and T:text(after) ~= ';' then typ = nil end
142
142
  elseif next == '=' and T:text(i + 2) == 'new' then typ = type_name(T, i + 3) end
143
143
  local a, b = scope_for(i, parameter)
144
+ local eq = next == '=' and i + 1 or after
145
+ if r.ordinary_bindings and declaration and eq and T:text(eq) == '=' and T.k[eq + 1] == 'id' then
146
+ alias_tokens[i] = require('codeoutline.dispatch_aliases').simple(T, eq + 1, r.language, true) and 'simple' or true
147
+ end
144
148
  bindings[#bindings + 1] = { name = T:text(i), type = typ or '?', token = i, a = a, b = b,
145
149
  declaration = declaration or parameter, target = declaration and callable_at[i] or nil }
146
150
  end
@@ -151,6 +155,17 @@ function M.collect(r, T)
151
155
  by_name[binding.name] = by_name[binding.name] or {}
152
156
  by_name[binding.name][#by_name[binding.name] + 1] = binding
153
157
  end
158
+ -- Reuse dispatch's bounded lexical validation in explicit query parses.
159
+ -- Ordinary indexing leaves this extra evidence ungenerated.
160
+ local expand
161
+ local function alias_evidence(name, at, token)
162
+ if alias_tokens[token] ~= 'simple' then return '?' end
163
+ expand = expand or require('codeoutline.dispatch_aliases').prepare(r, T)
164
+ local v = expand({ symbol = name }, at)
165
+ if v and v.node then return 'node:' .. v.node end
166
+ if v and v.import then return 'import:' .. v.import.path .. '\0' .. v.member end
167
+ return '?'
168
+ end
154
169
  for index, ref in ipairs(r.refs) do
155
170
  if index % 128 == 0 then control.check() end
156
171
  local target = ref.recv or ref.name
@@ -163,13 +178,26 @@ function M.collect(r, T)
163
178
  end
164
179
  end
165
180
  if best then
166
- if not ref.recv and best.target and (best.token <= ref.tok or best.hoisted) then ref.js_receiver = 'node:' .. best.target
181
+ if not ref.recv and alias_tokens[best.token] then ref.js_receiver = alias_evidence(ref.name, ref.tok, best.token)
182
+ elseif not ref.recv and best.target and (best.token <= ref.tok or best.hoisted) then ref.js_receiver = 'node:' .. best.target
167
183
  else ref.js_receiver = ref.recv and best.token <= ref.tok and best.type or '?' end
168
184
  end
169
185
  if ref.kind == 'member_call' and (not ref.recv or T:text(ref.tok - 3) == '.' or T:text(ref.tok - 3) == '?.') then
170
186
  ref.js_receiver = '?' -- A field/call-result chain is not the local variable sharing its tail.
171
187
  end
172
188
  end
189
+ if next(alias_tokens) then
190
+ for _, e in ipairs(r.js_exports) do
191
+ if not e.path then
192
+ for _, b in ipairs(by_name[e.local_name] or {}) do
193
+ if b.a == 0 and alias_tokens[b.token] then
194
+ e.binding = alias_evidence(e.local_name, T.n, b.token)
195
+ break
196
+ end
197
+ end
198
+ end
199
+ end
200
+ end
173
201
  end
174
202
 
175
203
  return M
@@ -117,6 +117,21 @@ local function exported(G, f, name, ctx, seen, depth)
117
117
  local function add(ids) for _, id in ipairs(ids) do if not unique[id] then unique[id] = true; result[#result + 1] = id end end end
118
118
  local rec = G.files[f]
119
119
  local entries = rec.js_exports or {}
120
+ -- Only variable exports may need the new lexical alias analysis. Ordinary
121
+ -- declared exports continue to resolve entirely from the resident index.
122
+ if ctx.ordinary and not rec.ordinary_bindings then
123
+ local needed = false
124
+ for _, e in ipairs(entries) do
125
+ if e.name == name and not e.path then
126
+ for _, id in ipairs(G.by_name[e.local_name] or {}) do
127
+ local n = G.nodes[id]
128
+ if G.node_file[id] == f and not n.parent and n.kind == 'variable' then needed = true; break end
129
+ end
130
+ end
131
+ if needed then break end
132
+ end
133
+ if needed then entries = ctx.ordinary.data(f).js_exports or entries end
134
+ end
120
135
  local explicit = false
121
136
  for _, e in ipairs(entries) do if e.name == name then explicit = true end end
122
137
  for _, e in ipairs(entries) do
@@ -125,6 +140,16 @@ local function exported(G, f, name, ctx, seen, depth)
125
140
  if e.path then
126
141
  local target = M.module(G, f, e.path, ctx)
127
142
  if target then add(exported(G, target, want, ctx, seen, depth + 1)) end
143
+ elseif e.binding then
144
+ local node = e.binding:match('^node:(%d+)$')
145
+ local path, member = e.binding:match('^import:(.-)%z(.*)$')
146
+ if node then
147
+ local id = G.id_of[f][tonumber(node)]
148
+ if id then add({ id }) end
149
+ elseif path then
150
+ local target = M.module(G, f, path, ctx)
151
+ if target then add(exported(G, target, member, ctx, seen, depth + 1)) end
152
+ end
128
153
  else
129
154
  for _, id in ipairs(G.id_of[f]) do
130
155
  local n = G.nodes[id]
@@ -143,6 +168,13 @@ local function exported(G, f, name, ctx, seen, depth)
143
168
  return result
144
169
  end
145
170
 
171
+ -- Shared named/namespace import lookup for query-owned callback aliases.
172
+ function M.imported(G, f, path, name, ctx)
173
+ ctx = ctx or M.context(G)
174
+ local target = M.module(G, f, path, ctx)
175
+ return target and name ~= '' and exported(G, target, name, ctx, {}, 0) or {}
176
+ end
177
+
146
178
  function M.resolve(G, f, name, kind, recv, evidence, ctx)
147
179
  local rec = G.files[f]
148
180
  if not js(rec) then return nil end
@@ -161,6 +193,8 @@ function M.resolve(G, f, name, kind, recv, evidence, ctx)
161
193
  if evidence then
162
194
  local node = evidence:match('^node:(%d+)$')
163
195
  if node then return { G.id_of[f][tonumber(node)] } end
196
+ local path, member = evidence:match('^import:(.-)%z(.*)$')
197
+ if path then return M.imported(G, f, path, member, ctx) end
164
198
  local head, tail = evidence:match('^([%w_$]+)%.([%w_$]+)$')
165
199
  local classes = binding(head or evidence, tail)
166
200
  if classes == nil then
@@ -190,10 +190,22 @@ parse_members = function(T, r, a, b, parent, class_name)
190
190
  local j = i
191
191
  while j <= b and not is(T, j, ';') do j = j + 1 end
192
192
  local x = kw(T, i, 'using') and i + 1 or i + 2
193
- if kw(T, x, 'static') then x = x + 1 end
194
- if T.k[x] == 'id' and is(T, x + 1, '=') then x = x + 2 end -- alias
193
+ local global = t == 'global'
194
+ local static = kw(T, x, 'static')
195
+ if static or T:text(x) == 'unsafe' then x = x + 1 end
196
+ local alias = T.k[x] == 'id' and is(T, x + 1, '=') and T:text(x) or nil
197
+ if alias then x = x + 2 end
198
+ local target = x
199
+ if T:text(x) == 'global' and is(T, x + 1, '::') then x = x + 2 end
195
200
  local path = dotted(T, x)
196
- if path ~= '' then r.imports[#r.imports + 1] = { path = path, line = T:line(i) } end
201
+ if path ~= '' or global then r.imports[#r.imports + 1] = { path = path, line = T:line(i), global = global or nil } end
202
+ if r.ordinary_bindings and (not parent or r.nodes[parent].kind == 'namespace') then
203
+ local owner = parent and r.nodes[parent]
204
+ r.csharp_usings = r.csharp_usings or {}
205
+ r.csharp_usings[#r.csharp_usings + 1] = { alias = alias, static = static or nil, global = global or nil,
206
+ path = common.sig(T, target, j - 1, 4096), scope = owner and owner.qualified or '',
207
+ first = owner and T.s[owner.ti] - 1 or 0, last = owner and T.e[owner.tj] or #T.src }
208
+ end
197
209
  i = j + 1
198
210
  elseif k == 'kw' and t == 'namespace' then
199
211
  local name, x = dotted(T, i + 1)
@@ -192,6 +192,19 @@ function M.parse(path, src, language, opts)
192
192
  local v = string_value(T, arg)
193
193
  if v then r.imports[#r.imports + 1] = { path = v, line = T:line(i), kind = T:text(i) } end
194
194
  end
195
+ elseif k == 'id' and T:text(i):sub(-6) == 'import' and not is(T, i - 1, ':') then
196
+ -- `*import` loader pattern: `ks.import('path')`, `skynet_import 'path'`.
197
+ -- Path-based; resolution keeps it only when the file exists.
198
+ local paren = is(T, i + 1, '(')
199
+ local arg = paren and i + 2 or i + 1
200
+ if T.k[arg] == 'str' and (not paren or is(T, arg + 1, ')') or is(T, arg + 1, ',')) then
201
+ local v = string_value(T, arg)
202
+ if v then
203
+ local kind = T:text(i)
204
+ if is(T, i - 1, '.') and T.k[i - 2] == 'id' then kind = T:text(i - 2) .. '.' .. kind end
205
+ r.imports[#r.imports + 1] = { path = v, line = T:line(i), kind = kind }
206
+ end
207
+ end
195
208
  end
196
209
  end
197
210
 
@@ -214,8 +227,10 @@ function M.parse(path, src, language, opts)
214
227
  if not defs[ref.tok] then kept[#kept + 1] = ref end
215
228
  end
216
229
  r.refs = kept
217
- common.assign_refs(r)
218
- require('codeoutline.lua_bindings').collect(r, T, bm)
230
+ if not r.dispatch_only then
231
+ common.assign_refs(r)
232
+ require('codeoutline.lua_bindings').collect(r, T, bm)
233
+ end
219
234
  r.member_ops = nil
220
235
  return common.finish(r, T), T
221
236
  end
@@ -89,7 +89,7 @@ local feature_of = { ['textDocument/documentSymbol'] = 'documentSymbol', ['works
89
89
  ['textDocument/completion'] = 'completion', ['textDocument/signatureHelp'] = 'signatureHelp' }
90
90
  local sessions = 0
91
91
 
92
- function M.new(config, emit, submit, cancel, stop)
92
+ function M.new(config, emit, submit, cancel, stop, await_worker)
93
93
  config = config or {}
94
94
  sessions = sessions + 1
95
95
  local self = { state = 'new', documents = {}, roots = {}, pending = {}, scans = {}, ready = {},
@@ -360,27 +360,41 @@ function M.new(config, emit, submit, cancel, stop)
360
360
  local doc = document(params)
361
361
  reply(id, doc and M.document_symbols(doc, self.hierarchical) or array())
362
362
  end
363
- -- One worker job per request; late results of cancelled requests are dropped.
364
- local function request(id, req, finish)
363
+ -- Callback transports remain usable by embedders/tests. Production LSP
364
+ -- supplies an RPC transport; both expose the same yielding interface.
365
+ await_worker = await_worker or function(req, started)
366
+ local co = assert(coroutine.running())
367
+ local waiting, completed, outcome, value = false, false, nil, nil
368
+ local id, err = submit(req, function(ok, result)
369
+ completed, outcome, value = true, ok, result
370
+ if waiting then assert(coroutine.resume(co)) end
371
+ end)
372
+ if not id then return false, err end
373
+ started(id)
374
+ if not completed then waiting = true; coroutine.yield() end
375
+ return outcome, value
376
+ end
377
+ -- Each query owns a coroutine; cancelled/replaced requests discard replies.
378
+ local function request(id, req, started)
365
379
  local count = 0
366
380
  for _ in pairs(self.pending) do count = count + 1 end
367
381
  assert(count < M.MAX_PENDING, 'too many pending requests')
368
- local job = {}
382
+ local job = { coroutine = coroutine.running() }
369
383
  self.pending[id] = job
370
- local job_id, err = submit(req, function(ok, result)
371
- if self.pending[id] ~= job then return end
372
- self.pending[id] = nil
373
- if not ok then
374
- if req.changed then self.synced = {} end -- resend drafts with the next request
375
- error_response(id, -32603, tostring(result)); return
376
- end
377
- finish(result)
384
+ local called, ok, result = pcall(await_worker, req, function(job_id)
385
+ job.id = job_id
386
+ if started then started() end
378
387
  end)
379
- job.id = job_id
380
- if not job_id and self.pending[id] == job then
381
- self.pending[id] = nil; error_response(id, -32603, err)
388
+ if not called then result, ok = ok, false end
389
+ -- Even a cancelled request may fail before its drafts reach the worker.
390
+ if not ok and req.changed then self.synced = {} end
391
+ if self.pending[id] ~= job then return nil, false end
392
+ self.pending[id] = nil
393
+ if not ok then
394
+ error_response(id, -32603, tostring(result))
395
+ return nil, false
382
396
  end
383
- return job_id ~= nil
397
+ return result, true
384
398
  end
385
399
  handlers['workspace/symbol'] = function(id, params)
386
400
  assert(id ~= nil, 'symbol query must be a request')
@@ -406,11 +420,11 @@ function M.new(config, emit, submit, cancel, stop)
406
420
  for _, root in ipairs(self.roots) do
407
421
  if not self.ready[root] then reply(id, result); return end
408
422
  end
409
- request(id, { method = 'lsp_symbols', roots = self.roots, exclude = exclude,
410
- query = params.query, limit = M.MAX_SYMBOLS - #result }, function(symbols)
411
- for _, symbol in ipairs(to_client(symbols)) do result[#result + 1] = symbol end
412
- reply(id, result)
413
- end)
423
+ local symbols, ok = request(id, { method = 'lsp_symbols', roots = self.roots, exclude = exclude,
424
+ query = params.query, limit = M.MAX_SYMBOLS - #result })
425
+ if not ok then return end
426
+ for _, symbol in ipairs(to_client(symbols)) do result[#result + 1] = symbol end
427
+ reply(id, result)
414
428
  end
415
429
  -- Navigation runs in the worker against the session's drafts: every request
416
430
  -- carries the open set and the text of versions the worker has not seen.
@@ -429,17 +443,18 @@ function M.new(config, emit, submit, cancel, stop)
429
443
  end
430
444
  req.session, req.open, req.changed = self.session, open, changed
431
445
  req.includePaths = self.include_paths
432
- local submitted = request(id, req, function(value)
433
- if value.error then error_response(id, -32803, value.error); return end
434
- if value.incomplete then
435
- emit({ jsonrpc = '2.0', method = 'window/showMessage', params = { type = 2,
436
- message = 'CodeOutline: results were truncated; too many matching references' } })
437
- end
438
- reply(id, to_client(finish(value.result)))
439
- end)
440
- if submitted then
446
+ local value, ok = request(id, req, function()
447
+ -- Record submission before yielding so subsequent requests send only
448
+ -- newer drafts. The worker applies drafts even to cancelled jobs.
441
449
  for uri, version in pairs(sent) do self.synced[uri] = version end
450
+ end)
451
+ if not ok then return end
452
+ if value.error then error_response(id, -32803, value.error); return end
453
+ if value.incomplete then
454
+ emit({ jsonrpc = '2.0', method = 'window/showMessage', params = { type = 2,
455
+ message = 'CodeOutline: results were truncated; too many matching references' } })
442
456
  end
457
+ reply(id, to_client(finish(value.result)))
443
458
  end
444
459
  -- Worker results lose array metatables in transit; empty lists must stay JSON arrays.
445
460
  local function list(value) return array(value or nil) end
@@ -562,11 +577,20 @@ function M.new(config, emit, submit, cancel, stop)
562
577
  error_response(object(msg) and valid_id(msg.id) and msg.id or nil, -32600, 'Invalid JSON-RPC request'); return
563
578
  end
564
579
  if (msg.method == 'initialize' or msg.method == 'shutdown') and msg.id == nil then return end
565
- local dispatched, err = pcall(dispatch, msg)
566
- if not dispatched then
567
- if msg.id ~= nil then error_response(msg.id, -32602, tostring(err))
568
- else io.stderr:write('[codeoutline lsp] ', tostring(err), '\n') end
580
+ local function handle()
581
+ local dispatched, err = pcall(dispatch, msg)
582
+ if not dispatched then
583
+ if msg.id ~= nil then error_response(msg.id, -32602, tostring(err))
584
+ else io.stderr:write('[codeoutline lsp] ', tostring(err), '\n') end
585
+ end
569
586
  end
587
+ -- Lifecycle and document notifications remain ordered on the main loop.
588
+ -- Queries run immediately up to their first wait, capturing that state.
589
+ if msg.id ~= nil and feature_of[msg.method] then
590
+ local co = coroutine.create(handle)
591
+ local resumed, err = coroutine.resume(co)
592
+ if not resumed then error_response(msg.id, -32603, tostring(err)) end
593
+ else handle() end
570
594
  end
571
595
  return self
572
596
  end