@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.
- package/README.md +32 -5
- package/README.zh-CN.md +32 -5
- 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 +36 -5
- package/scripts/codeoutline/completion.lua +913 -0
- package/scripts/codeoutline/control.lua +5 -1
- package/scripts/codeoutline/daemon.lua +4 -2
- package/scripts/codeoutline/documents.lua +154 -0
- package/scripts/codeoutline/explore.lua +32 -7
- package/scripts/codeoutline/graph.lua +264 -68
- package/scripts/codeoutline/index.lua +168 -48
- package/scripts/codeoutline/index_worker.lua +108 -17
- 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/lua.lua +9 -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/main.lua +28 -5
- package/scripts/codeoutline/navigation.lua +934 -0
- package/scripts/codeoutline/parse.lua +8 -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/updater.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
- package/scripts/xupgate/client.lua +8 -0
- package/licenses/rpmalloc.txt +0 -12
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
-- Per-Lua-state
|
|
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
|
|
@@ -37,10 +37,12 @@ end
|
|
|
37
37
|
function M.current_root(install)
|
|
38
38
|
local own = sequence(install)
|
|
39
39
|
if not own then return install end
|
|
40
|
+
-- active() applies the same rule as launcher selection: this install's
|
|
41
|
+
-- sequence is the updater's minimum, so an older update is skipped.
|
|
40
42
|
local ok, current = pcall(function()
|
|
41
|
-
return require('xupgate.client').open(require('codeoutline.updater').config()).
|
|
43
|
+
return require('xupgate.client').open(require('codeoutline.updater').config()).active()
|
|
42
44
|
end)
|
|
43
|
-
if ok and current
|
|
45
|
+
if ok and current then return current.root end
|
|
44
46
|
return install
|
|
45
47
|
end
|
|
46
48
|
function M.is_current(install) return same_path(M.current_root(install), install) end
|
|
@@ -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' }
|
|
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
|
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
@@ -497,8 +517,13 @@ function M.run(G, idx, query, opts)
|
|
|
497
517
|
if used + #block <= budget + 400 then emit(block) else omitted = true end
|
|
498
518
|
end
|
|
499
519
|
|
|
520
|
+
if G.incomplete then
|
|
521
|
+
table.insert(parts, 1, 'Call-path expansion limit reached; relationships are incomplete.')
|
|
522
|
+
omitted = true
|
|
523
|
+
end
|
|
500
524
|
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
|
|
525
|
+
return result, { seeds = seeds, spine = spine, shown = shown, flows = flows, truncated = truncated,
|
|
526
|
+
relationships_incomplete = G.incomplete or false, query_stats = G.stats }
|
|
502
527
|
end
|
|
503
528
|
|
|
504
529
|
return M
|