@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.
Files changed (40) hide show
  1. package/README.md +38 -6
  2. package/README.zh-CN.md +36 -6
  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 +45 -5
  10. package/scripts/codeoutline/completion.lua +936 -0
  11. package/scripts/codeoutline/control.lua +5 -1
  12. package/scripts/codeoutline/documents.lua +154 -0
  13. package/scripts/codeoutline/explore.lua +35 -8
  14. package/scripts/codeoutline/graph.lua +321 -102
  15. package/scripts/codeoutline/index.lua +170 -50
  16. package/scripts/codeoutline/index_worker.lua +108 -17
  17. package/scripts/codeoutline/indirect.lua +201 -0
  18. package/scripts/codeoutline/js_evidence.lua +175 -0
  19. package/scripts/codeoutline/js_resolution.lua +201 -0
  20. package/scripts/codeoutline/lang/c.lua +22 -12
  21. package/scripts/codeoutline/lang/cpp.lua +13 -12
  22. package/scripts/codeoutline/lang/csharp.lua +21 -21
  23. package/scripts/codeoutline/lang/go.lua +10 -10
  24. package/scripts/codeoutline/lang/java.lua +9 -9
  25. package/scripts/codeoutline/lang/js.lua +15 -14
  26. package/scripts/codeoutline/lang/kotlin.lua +384 -0
  27. package/scripts/codeoutline/lang/lua.lua +11 -6
  28. package/scripts/codeoutline/lang/python.lua +6 -6
  29. package/scripts/codeoutline/lang/rust.lua +23 -15
  30. package/scripts/codeoutline/lsp.lua +574 -0
  31. package/scripts/codeoutline/lua_bindings.lua +222 -0
  32. package/scripts/codeoutline/main.lua +28 -5
  33. package/scripts/codeoutline/navigation.lua +1046 -0
  34. package/scripts/codeoutline/parse.lua +9 -2
  35. package/scripts/codeoutline/parse_pool.lua +189 -0
  36. package/scripts/codeoutline/parse_worker.lua +24 -0
  37. package/scripts/codeoutline/service.lua +82 -31
  38. package/scripts/codeoutline/update_sequence.lua +1 -1
  39. package/scripts/codeoutline/version.lua +1 -1
  40. package/licenses/rpmalloc.txt +0 -12
@@ -1,4 +1,8 @@
1
- -- Per-Lua-state cancellation checkpoint installed only by the service worker.
1
+ -- Per-Lua-state checkpoint for worker cancellation or cooperative indexing.
2
2
  local M = {}
3
+ local error_mt = { __tostring = function(e) return e.message end }
4
+ function M.cancelled(message) return setmetatable({ code = 'cancelled', message = message or 'Request cancelled' }, error_mt) end
5
+ function M.deadline() return setmetatable({ code = 'deadline', message = 'Indexing deadline exceeded' }, error_mt) end
6
+ function M.is_interrupted(value) return getmetatable(value) == error_mt end
3
7
  function M.check() if M.callback then M.callback() end end
4
8
  return M
@@ -0,0 +1,154 @@
1
+ local parse = require('codeoutline.parse')
2
+ local paths = require('codeoutline.path')
3
+ local text = require('codeoutline.text')
4
+ local M = { MAX_BYTES = 1500000 }
5
+ local Doc = {}
6
+ Doc.__index = Doc
7
+
8
+ function M.path(uri)
9
+ assert(type(uri) == 'string' and not uri:find('[%z\r\n]'), 'invalid document URI')
10
+ local host, path = uri:match('^file://([^/?#]*)(/[^?#]*)$')
11
+ if not path then return nil end
12
+ assert(not path:gsub('%%(%x%x)', ''):find('%%'), 'invalid URI escape')
13
+ path = path:gsub('%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end)
14
+ assert(not path:find('[%z\r\n]'), 'invalid file path')
15
+ if host ~= '' and host:lower() ~= 'localhost' then path = '//' .. host .. path
16
+ else path = path:match('^/(%a:.*)$') or path end
17
+ path = paths.normalize(path)
18
+ local prefix, rest
19
+ if path:match('^%a:/') then prefix, rest = path:sub(1, 3), path:sub(4)
20
+ elseif path:sub(1, 2) == '//' then prefix, rest = '//', path:sub(3)
21
+ else prefix, rest = '/', path:sub(2) end
22
+ local parts = {}
23
+ for part in rest:gmatch('[^/]+') do
24
+ if part == '..' then assert(#parts > 0, 'path escapes its root'); parts[#parts] = nil
25
+ elseif part ~= '.' then parts[#parts + 1] = part end
26
+ end
27
+ return prefix .. table.concat(parts, '/')
28
+ end
29
+
30
+ function M.uri(path)
31
+ path = paths.normalize(path)
32
+ local host = ''
33
+ if path:sub(1, 2) == '//' then host, path = assert(path:match('^//([^/]+)(/.*)$')) end
34
+ if path:match('^%a:/') then path = '/' .. path end
35
+ local escaped = path:gsub('[^%w%-%._~/:]', function(c) return string.format('%%%02X', c:byte()) end)
36
+ return 'file://' .. host .. escaped
37
+ end
38
+
39
+ function M.new(uri, source, version, language)
40
+ assert(type(source) == 'string' and #source <= M.MAX_BYTES, 'document exceeds size limit')
41
+ assert(text.valid(source) == source, 'document is not valid UTF-8')
42
+ if source:sub(1, 3) == '\239\187\191' then source = source:sub(4) end
43
+ local self = setmetatable({ uri = uri, path = M.path(uri), source = source,
44
+ version = version, language = language, lines = { 0 }, line_units = { 0 },
45
+ checkpoints = { offsets = { 0 }, units = { 0 } } }, Doc)
46
+ local p, units, checkpoint = 1, 0, 0
47
+ while p <= #source do
48
+ local b = source:byte(p)
49
+ if b == 13 then
50
+ if source:byte(p + 1) == 10 then p = p + 1; units = units + 1 end
51
+ units = units + 1
52
+ self.lines[#self.lines + 1] = p
53
+ self.line_units[#self.line_units + 1] = units
54
+ elseif b == 10 then
55
+ units = units + 1
56
+ self.lines[#self.lines + 1] = p
57
+ self.line_units[#self.line_units + 1] = units
58
+ else
59
+ local width = b < 128 and 1 or b < 224 and 2 or b < 240 and 3 or 4
60
+ p, units = p + width - 1, units + (width == 4 and 2 or 1)
61
+ end
62
+ -- Sparse prefix counts keep repeated positions on long lines bounded.
63
+ if p - checkpoint >= 512 then
64
+ local points = self.checkpoints
65
+ points.offsets[#points.offsets + 1], points.units[#points.units + 1] = p, units
66
+ checkpoint = p
67
+ end
68
+ p = p + 1
69
+ end
70
+ return self
71
+ end
72
+
73
+ function Doc:position(offset)
74
+ assert(type(offset) == 'number' and offset >= 0 and offset <= #self.source, 'invalid byte offset')
75
+ local lo, hi = 1, #self.lines
76
+ while lo < hi do
77
+ local mid = math.floor((lo + hi + 1) / 2)
78
+ if self.lines[mid] <= offset then lo = mid else hi = mid - 1 end
79
+ end
80
+ local line = lo
81
+ local next_line = self.lines[line + 1]
82
+ if next_line then
83
+ local last = next_line - 1
84
+ if self.source:byte(next_line) == 10 and self.source:byte(last) == 13 then last = last - 1 end
85
+ offset = math.min(offset, last)
86
+ end
87
+ local points = self.checkpoints
88
+ lo, hi = 1, #points.offsets
89
+ while lo < hi do
90
+ local mid = math.floor((lo + hi + 1) / 2)
91
+ if points.offsets[mid] <= offset then lo = mid else hi = mid - 1 end
92
+ end
93
+ local units, p = points.units[lo], points.offsets[lo] + 1
94
+ while p <= offset do
95
+ local b = self.source:byte(p)
96
+ local width = b < 128 and 1 or b < 224 and 2 or b < 240 and 3 or 4
97
+ assert(p + width - 1 <= offset, 'offset splits a UTF-8 character')
98
+ units, p = units + (width == 4 and 2 or 1), p + width
99
+ end
100
+ return { line = line - 1, character = units - self.line_units[line] }
101
+ end
102
+
103
+ function Doc:range(first, last)
104
+ return { start = self:position(first), ['end'] = self:position(last) }
105
+ end
106
+
107
+ -- Byte offset of an LSP position; lines and characters past the end clamp.
108
+ function Doc:offset(position)
109
+ assert(type(position) == 'table' and type(position.line) == 'number' and type(position.character) == 'number'
110
+ and position.line >= 0 and position.character >= 0, 'invalid position')
111
+ local line = position.line + 1
112
+ if line > #self.lines then return #self.source end
113
+ local p = self.lines[line]
114
+ local stop = self.lines[line + 1] and self.lines[line + 1] - 1 or #self.source
115
+ local units = 0
116
+ while p < stop and units < position.character do
117
+ local b = self.source:byte(p + 1)
118
+ if b == 10 or b == 13 then break end
119
+ local width = b < 128 and 1 or b < 224 and 2 or b < 240 and 3 or 4
120
+ p, units = p + width, units + (width == 4 and 2 or 1)
121
+ end
122
+ return p
123
+ end
124
+
125
+ local extensions = { javascript = 'js', typescript = 'ts', python = 'py', csharp = 'cs', rust = 'rs', cpp = 'cpp', kotlin = 'kt' }
126
+ local function parser_name(doc)
127
+ local name = doc.path or ('document.' .. (extensions[doc.language] or doc.language or 'txt'))
128
+ if not parse.language(name) and doc.language then name = 'document.' .. (extensions[doc.language] or doc.language) end
129
+ return name
130
+ end
131
+
132
+ function Doc:parse()
133
+ if self.parsed then return self.parsed end
134
+ self.parsed = parse.parse(parser_name(self), self.source) or { nodes = {} }
135
+ return self.parsed
136
+ end
137
+
138
+ -- Tokens are not retained: only cursor lookups outside indexed refs need them.
139
+ function Doc:tokens()
140
+ local _, tokens = parse.parse_tokens(parser_name(self), self.source)
141
+ return tokens
142
+ end
143
+
144
+ function M.read(path)
145
+ local f = io.open(path, 'rb')
146
+ if not f then return nil end
147
+ local raw = f:read(M.MAX_BYTES + 1); f:close()
148
+ if not raw or #raw > M.MAX_BYTES then return nil end
149
+ local source = xutils.to_utf8(raw)
150
+ if not source then return nil end
151
+ return M.new(M.uri(path), source)
152
+ end
153
+
154
+ return M
@@ -15,6 +15,7 @@
15
15
 
16
16
  local graph = require('codeoutline.graph')
17
17
  local text = require('codeoutline.text')
18
+ local control = require('codeoutline.control')
18
19
 
19
20
  local M = {}
20
21
 
@@ -78,7 +79,7 @@ local function segments(name)
78
79
  end
79
80
 
80
81
  local SOURCE_EXT = {}
81
- for e in ('c h py pyi java lua cpp cc cxx hpp hh hxx'):gmatch('%a+') do SOURCE_EXT[e] = true end
82
+ for e in ('c h py pyi java kt kts lua cpp cc cxx hpp hh hxx'):gmatch('%a+') do SOURCE_EXT[e] = true end
82
83
 
83
84
  -- Query -> candidate terms: qualified chains, identifiers, file names.
84
85
  local function terms(query)
@@ -125,7 +126,10 @@ end
125
126
  local function find_seeds(G, query)
126
127
  local cands = {} -- id -> score
127
128
  local files = {} -- file indices named in the query
129
+ local considered = 0
128
130
  local function consider(id, s)
131
+ considered = considered + 1
132
+ if considered % 128 == 0 then control.check() end
129
133
  if not cands[id] or cands[id] < s then cands[id] = s end
130
134
  end
131
135
  local list_terms = terms(query)
@@ -134,6 +138,7 @@ local function find_seeds(G, query)
134
138
  if t.kind ~= 'word' then has_code = true end
135
139
  end
136
140
  for _, t in ipairs(list_terms) do
141
+ control.check()
137
142
  if t.kind == 'word' then
138
143
  -- Plain words count only as exact names (no case folding or fuzzy
139
144
  -- matching, which is where English words pick up noise), and rank
@@ -143,13 +148,16 @@ local function find_seeds(G, query)
143
148
  end
144
149
  elseif t.kind == 'file' then
145
150
  local want = t.text:gsub('\\', '/')
146
- for f, rec in ipairs(G.files) do
151
+ for i, f in ipairs(G.file_order) do
152
+ if i % 128 == 0 then control.check() end
153
+ local rec = G.files[f]
147
154
  if rec.path == want or rec.path:sub(-(#want + 1)) == '/' .. want then files[#files + 1] = f end
148
155
  end
149
156
  elseif t.kind == 'qualified' then
150
157
  local last = t.text:match('([%w_]+)$')
151
158
  local first = t.text:match('^([%w_]+)')
152
- for _, id in ipairs(G.by_name[last] or {}) do
159
+ for i, id in ipairs(G.by_name[last] or {}) do
160
+ if i % 128 == 0 then control.check() end
153
161
  local q = G.nodes[id].qualified:gsub('[:]+', '.')
154
162
  if q == t.text or q:sub(-(#t.text + 1)) == '.' .. t.text then
155
163
  consider(id, seed_score(G, id, true) + 10)
@@ -172,8 +180,10 @@ local function find_seeds(G, query)
172
180
  elseif #t.text >= 4 then
173
181
  -- fuzzy: every query segment appears in the name's segments
174
182
  local want = segments(t.text)
175
- local hits = 0
183
+ local hits, visited = 0, 0
176
184
  for name, ids in pairs(G.by_name) do
185
+ visited = visited + 1
186
+ if visited % 128 == 0 then control.check() end
177
187
  local lname = name:lower()
178
188
  local ok = true
179
189
  for _, w in ipairs(want) do
@@ -190,10 +200,13 @@ local function find_seeds(G, query)
190
200
  end
191
201
  end
192
202
  local list = {}
193
- for id, s in pairs(cands) do list[#list + 1] = { id = id, s = s } end
203
+ for id, s in pairs(cands) do
204
+ if #list % 128 == 0 then control.check() end
205
+ list[#list + 1] = { id = id, s = s }
206
+ end
194
207
  table.sort(list, function(a, b)
195
208
  if a.s ~= b.s then return a.s > b.s end
196
- return a.id < b.id
209
+ return graph.before(G, a.id, b.id)
197
210
  end)
198
211
  return list, files
199
212
  end
@@ -204,8 +217,10 @@ local function path_between(G, a, b, depth)
204
217
  for _ = 1, depth do
205
218
  local next_frontier = {}
206
219
  for _, x in ipairs(frontier) do
220
+ control.check()
207
221
  local out = G.out[x] or {}
208
222
  for i = 1, #out, graph.EDGE do
223
+ if i % 128 == 1 then control.check() end
209
224
  local dst = out[i]
210
225
  if not prev[dst] then
211
226
  prev[dst] = x
@@ -286,10 +301,13 @@ local function label(G, id)
286
301
  return string.format('%s %s (%s)', node.kind, node.qualified, graph.where(G, id))
287
302
  end
288
303
 
289
- -- Run a query. Returns the text and a table with what was selected.
304
+ -- Run a query over symbol tables (graph.build). Returns the text and a table
305
+ -- with what was selected; relationships resolve per query.
290
306
  function M.run(G, idx, query, opts)
307
+ control.check()
291
308
  opts = opts or {}
292
309
  local budget = M.validate(query, opts)
310
+ G = graph.query(G, opts)
293
311
  file_cache = {}
294
312
  local ranked, named_files = find_seeds(G, query)
295
313
 
@@ -397,6 +415,8 @@ function M.run(G, idx, query, opts)
397
415
  by_file[f].outline = true
398
416
  end
399
417
 
418
+ if G.load_incoming then G:load_incoming(seeds) end
419
+
400
420
  -- Confirm every file whose source or symbol labels this query can emit.
401
421
  -- GBK reparsing invalidates node IDs, so rebuild and select again before
402
422
  -- producing any output. Unrelated project files remain speculative.
@@ -459,6 +479,7 @@ function M.run(G, idx, query, opts)
459
479
  if not seen_in[src] and #callers < M.LIST_CAP then
460
480
  seen_in[src] = true
461
481
  callers[#callers + 1] = string.format('%s (%s:%d)', G.nodes[src].name, G.files[G.node_file[src]].path, inn[i + 1])
482
+ .. (inn[i + 2]:match('^indirect:') and (' [' .. inn[i + 2] .. ']') or '')
462
483
  end
463
484
  end
464
485
  for i = 1, #out, graph.EDGE do
@@ -466,6 +487,7 @@ function M.run(G, idx, query, opts)
466
487
  if not seen_out[dst] and #callees < M.LIST_CAP then
467
488
  seen_out[dst] = true
468
489
  callees[#callees + 1] = G.nodes[dst].name .. ' (' .. graph.where(G, dst) .. ')'
490
+ .. (out[i + 2]:match('^indirect:') and (' [' .. out[i + 2] .. ']') or '')
469
491
  end
470
492
  end
471
493
  if #callers > 0 or #callees > 0 then
@@ -497,8 +519,13 @@ function M.run(G, idx, query, opts)
497
519
  if used + #block <= budget + 400 then emit(block) else omitted = true end
498
520
  end
499
521
 
522
+ if G.incomplete then
523
+ table.insert(parts, 1, 'Call-path expansion limit reached; relationships are incomplete.')
524
+ omitted = true
525
+ end
500
526
  local result, truncated = text.limit(table.concat(parts, '\n'), budget, omitted or #pointers > 0)
501
- return result, { seeds = seeds, spine = spine, shown = shown, flows = flows, truncated = truncated }
527
+ return result, { seeds = seeds, spine = spine, shown = shown, flows = flows, truncated = truncated,
528
+ relationships_incomplete = G.incomplete or false, query_stats = G.stats }
502
529
  end
503
530
 
504
531
  return M