@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,222 @@
|
|
|
1
|
+
-- Static Lua module return bindings. Never execute indexed source.
|
|
2
|
+
local M = {}
|
|
3
|
+
local control = require('codeoutline.control')
|
|
4
|
+
local loaders = { require = true, dofile = true, loadfile = true }
|
|
5
|
+
local function literal(T, i)
|
|
6
|
+
if T.k[i] ~= 'str' then return nil end
|
|
7
|
+
local s = T:text(i)
|
|
8
|
+
local long = s:match('^%[(=*)%[')
|
|
9
|
+
if long then return s:sub(#long + 3, -#long - 3):gsub('^\r?\n', '', 1) end
|
|
10
|
+
if s:find('\\', 1, true) then return nil end
|
|
11
|
+
return s:sub(2, -2)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
function M.collect(r, T, bm)
|
|
15
|
+
r.lua_imports, r.lua_exports, r.lua_locals = {}, {}, {}
|
|
16
|
+
local scopes, stack, params, bindings = {}, {}, {}, {}
|
|
17
|
+
for i = 1, T.n do
|
|
18
|
+
if bm[i] and bm[i] > i then stack[#stack + 1] = i end
|
|
19
|
+
scopes[i] = stack[#stack] or 0
|
|
20
|
+
if stack[#stack] and bm[stack[#stack]] == i then stack[#stack] = nil end
|
|
21
|
+
if T:text(i) == 'function' and T.k[i] == 'kw' then
|
|
22
|
+
local p = i + 1
|
|
23
|
+
while p < (bm[i] or i) and T:text(p) ~= '(' do p = p + 1 end
|
|
24
|
+
for j = p + 1, (T.m[p] or p) - 1 do if T.k[j] == 'id' then params[j] = i end end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
local function add(name, token, scope, hint, imported)
|
|
28
|
+
bindings[name] = bindings[name] or {}
|
|
29
|
+
bindings[name][#bindings[name] + 1] = { token = token, a = scope, b = bm[scope] or T.n, hint = hint, imported = imported }
|
|
30
|
+
end
|
|
31
|
+
for i = 1, T.n do
|
|
32
|
+
if i % 4096 == 0 then control.check() end
|
|
33
|
+
if T.k[i] == 'id' then
|
|
34
|
+
local prev, next = T:text(i - 1), T:text(i + 1)
|
|
35
|
+
if params[i] then add(T:text(i), i, params[i], '?')
|
|
36
|
+
elseif prev == 'function' and T:text(i - 2) == 'local' then add(T:text(i), i, scopes[i - 2], '')
|
|
37
|
+
elseif prev == 'local' or (next == '=' and prev ~= '.' and prev ~= ':' and prev ~= '{' and prev ~= ',') then
|
|
38
|
+
local hint = '?'
|
|
39
|
+
if next == '=' and T:text(i + 2) == '{' then hint = 'lua-local:' .. T:text(i) end
|
|
40
|
+
local imported = next == '=' and loaders[T:text(i + 2)]
|
|
41
|
+
if next == '=' and loaders[T:text(i + 2)] then
|
|
42
|
+
local kind, call = T:text(i + 2), i + 2
|
|
43
|
+
local arg = T:text(call + 1) == '(' and call + 2 or call + 1
|
|
44
|
+
local path = literal(T, arg)
|
|
45
|
+
local close = T:text(call + 1) == '(' and T.m[call + 1] or arg
|
|
46
|
+
if close and ((close == arg) or (close == arg + 1)) and path then
|
|
47
|
+
-- A concatenation/operation after the loader is not its return value.
|
|
48
|
+
local tail = T:text(close + 1)
|
|
49
|
+
if tail ~= '..' and tail ~= '.' and tail ~= ':' and tail ~= 'or' and tail ~= 'and'
|
|
50
|
+
and tail ~= '(' and tail ~= '[' and tail ~= '+' and tail ~= '-' and tail ~= '*' and tail ~= '/' then
|
|
51
|
+
local shadowed = false
|
|
52
|
+
for _, b in ipairs(bindings[kind] or {}) do
|
|
53
|
+
if b.token < call and b.a <= call and b.b >= call then shadowed = true end
|
|
54
|
+
end
|
|
55
|
+
if not shadowed then
|
|
56
|
+
r.lua_imports[#r.lua_imports + 1] = { path = path, kind = kind }
|
|
57
|
+
hint = 'lua:' .. #r.lua_imports
|
|
58
|
+
if kind == 'loadfile' then hint = '?' end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
-- Keep ordinary local function/table lookup; block unknown imported receivers.
|
|
64
|
+
add(T:text(i), i, scopes[i], hint, imported)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
for name, list in pairs(bindings) do
|
|
69
|
+
for _, b in ipairs(list) do
|
|
70
|
+
if b.hint:match('^lua%-local:') then
|
|
71
|
+
local members = {}
|
|
72
|
+
for index, n in ipairs(r.nodes) do
|
|
73
|
+
local scope = T:text(n.ti) == 'function' and scopes[n.ti - 1] or scopes[n.ti]
|
|
74
|
+
if n.ti >= b.token and n.ti <= b.b and scope == b.a
|
|
75
|
+
and (n.qualified == name .. '.' .. n.name or n.qualified == name .. ':' .. n.name) then members[n.name] = index end
|
|
76
|
+
end
|
|
77
|
+
r.lua_locals[#r.lua_locals + 1] = members
|
|
78
|
+
b.hint = 'lua-local:' .. #r.lua_locals
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
for _, ref in ipairs(r.refs) do
|
|
83
|
+
do
|
|
84
|
+
local best
|
|
85
|
+
for _, b in ipairs(bindings[ref.recv or ref.name] or {}) do
|
|
86
|
+
if b.token <= ref.tok and b.a <= ref.tok and b.b >= ref.tok
|
|
87
|
+
and (not best or b.a > best.a or (b.a == best.a and b.token > best.token)) then best = b end
|
|
88
|
+
end
|
|
89
|
+
if best and (ref.recv or best.imported) then ref.lua_binding = ref.recv and best.hint or '?' end
|
|
90
|
+
if ref.recv and (T:text(ref.tok - 3) == '.' or T:text(ref.tok - 3) == ':') then ref.lua_binding = '?' end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
-- A single unconditional top-level return is the supported module contract.
|
|
95
|
+
local ret
|
|
96
|
+
for i = 1, T.n do
|
|
97
|
+
if T:text(i) == 'return' and T.k[i] == 'kw' then
|
|
98
|
+
local in_function = false
|
|
99
|
+
for _, n in ipairs(r.nodes) do
|
|
100
|
+
if (n.kind == 'function' or n.kind == 'method') and n.ti <= i and n.tj >= i then in_function = true; break end
|
|
101
|
+
end
|
|
102
|
+
if not in_function then
|
|
103
|
+
if ret or scopes[i] ~= 0 then r.lua_exports = {}; return end
|
|
104
|
+
ret = i
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
if not ret then return end
|
|
109
|
+
local owner, table_start
|
|
110
|
+
if T.k[ret + 1] == 'id' and (ret + 1 == T.n or T:text(ret + 2) == ';') then
|
|
111
|
+
owner = T:text(ret + 1)
|
|
112
|
+
for i = 1, ret - 1 do
|
|
113
|
+
if T:text(i) == owner and T:text(i + 1) == '=' and T:text(i + 2) == '{' and scopes[i] == 0 then table_start = i + 2 end
|
|
114
|
+
end
|
|
115
|
+
elseif T:text(ret + 1) == '{' and T.m[ret + 1] then
|
|
116
|
+
table_start = ret + 1
|
|
117
|
+
owner = r.path:match('([^/\\]+)%.lua$') or r.path
|
|
118
|
+
else return end
|
|
119
|
+
if owner then
|
|
120
|
+
if not table_start or not T.m[table_start] then return end
|
|
121
|
+
for i = table_start + 1, ret - 1 do
|
|
122
|
+
if scopes[i] == 0 and T:text(i) == owner and T:text(i + 1) == '=' then r.lua_exports = {}; return end
|
|
123
|
+
end
|
|
124
|
+
for index, n in ipairs(r.nodes) do
|
|
125
|
+
if not n.parent and n.ti >= table_start and (n.qualified == owner .. '.' .. n.name or n.qualified == owner .. ':' .. n.name)
|
|
126
|
+
and (n.kind == 'function' or n.kind == 'method') then r.lua_exports[n.name] = index end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
local function alias(key, target)
|
|
130
|
+
for index, n in ipairs(r.nodes) do
|
|
131
|
+
if not n.parent and n.name == target and n.qualified == target and (n.kind == 'function' or n.kind == 'method') then
|
|
132
|
+
r.lua_exports[key] = index
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
if table_start then
|
|
137
|
+
local i, close = table_start + 1, T.m[table_start]
|
|
138
|
+
while i < close do
|
|
139
|
+
if T.k[i] == 'id' and T:text(i + 1) == '=' and T.k[i + 2] == 'id'
|
|
140
|
+
and (T:text(i + 3) == ',' or T:text(i + 3) == ';' or i + 3 == close) then alias(T:text(i), T:text(i + 2)) end
|
|
141
|
+
if T.m[i] and T.m[i] > i then i = T.m[i]
|
|
142
|
+
elseif bm[i] and bm[i] > i then i = bm[i] end
|
|
143
|
+
i = i + 1
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
for i = 1, ret - 1 do
|
|
147
|
+
if scopes[i] == 0 and T:text(i) == owner and T:text(i + 1) == '.' and T.k[i + 2] == 'id'
|
|
148
|
+
and T:text(i + 3) == '=' and T:text(i + 4) ~= 'function' then
|
|
149
|
+
r.lua_exports[T:text(i + 2)] = nil
|
|
150
|
+
if T.k[i + 4] == 'id' and (T.l[i + 5] ~= T.l[i + 4] or T:text(i + 5) == ';') then alias(T:text(i + 2), T:text(i + 4)) end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
local function normalize(p)
|
|
156
|
+
local parts = {}
|
|
157
|
+
for s in p:gsub('\\', '/'):gmatch('[^/]+') do
|
|
158
|
+
if s == '..' and #parts > 0 and parts[#parts] ~= '..' then parts[#parts] = nil
|
|
159
|
+
elseif s ~= '.' then parts[#parts + 1] = s end
|
|
160
|
+
end
|
|
161
|
+
return table.concat(parts, '/')
|
|
162
|
+
end
|
|
163
|
+
function M.context(G)
|
|
164
|
+
local ctx = { directory = '', modules = {} }
|
|
165
|
+
local f = G.root and io.open(G.root .. '/.codeoutline.json', 'rb')
|
|
166
|
+
if f then
|
|
167
|
+
local raw = f:read(65537); f:close()
|
|
168
|
+
assert(#raw <= 65536, '.codeoutline.json exceeds 64 KiB')
|
|
169
|
+
local ok, config = pcall(xutils.json_unpack, raw)
|
|
170
|
+
assert(ok and type(config) == 'table', 'invalid .codeoutline.json')
|
|
171
|
+
local value = config.luaRuntimeDirectory
|
|
172
|
+
if value ~= nil then
|
|
173
|
+
assert(type(value) == 'string' and not value:match('^[/\\]') and not value:find(':', 1, true), 'luaRuntimeDirectory must be project-relative')
|
|
174
|
+
ctx.directory = normalize(value)
|
|
175
|
+
assert(not ctx.directory:match('^%.%.'), 'luaRuntimeDirectory must stay inside project')
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
return ctx
|
|
179
|
+
end
|
|
180
|
+
function M.modules(G, imp, ctx)
|
|
181
|
+
ctx = ctx or M.context(G)
|
|
182
|
+
local key = imp.kind .. '\0' .. imp.path
|
|
183
|
+
if ctx.modules[key] then return ctx.modules[key] end
|
|
184
|
+
local result = {}
|
|
185
|
+
if imp.kind == 'require' then
|
|
186
|
+
local sub = imp.path:gsub('%.', '/')
|
|
187
|
+
for _, want in ipairs({ sub .. '.lua', sub .. '/init.lua' }) do
|
|
188
|
+
local candidates = {}
|
|
189
|
+
for _, f in ipairs(G.by_base[want:match('([^/]+)$')] or {}) do candidates[#candidates + 1] = f end
|
|
190
|
+
for _, f in ipairs(G.new_files or {}) do candidates[#candidates + 1] = f end
|
|
191
|
+
for _, f in ipairs(candidates) do
|
|
192
|
+
local rec = G.files[f]
|
|
193
|
+
if rec.language == 'lua' and (rec.path == want or rec.path:sub(-#want - 1) == '/' .. want) then result[#result + 1] = f end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
elseif not imp.path:match('^[/\\]') and not imp.path:find(':', 1, true) then
|
|
197
|
+
local path = normalize(ctx.directory .. '/' .. imp.path)
|
|
198
|
+
local f = G.file_index[path]
|
|
199
|
+
if f and G.files[f].language == 'lua' then result[1] = f end
|
|
200
|
+
end
|
|
201
|
+
ctx.modules[key] = result
|
|
202
|
+
return result
|
|
203
|
+
end
|
|
204
|
+
function M.resolve(G, f, name, hint, ctx)
|
|
205
|
+
if G.files[f].language ~= 'lua' or not hint or hint == '' then return nil end
|
|
206
|
+
if hint == '?' then return {} end
|
|
207
|
+
local local_index = tonumber(hint:match('^lua%-local:(%d+)$'))
|
|
208
|
+
if local_index then
|
|
209
|
+
local n = ((G.files[f].lua_locals or {})[local_index] or {})[name]
|
|
210
|
+
return n and { G.id_of[f][n] } or {}
|
|
211
|
+
end
|
|
212
|
+
local index = tonumber(hint:match('^lua:(%d+)$'))
|
|
213
|
+
local imp = index and (G.files[f].lua_imports or {})[index]
|
|
214
|
+
if not imp then return nil end
|
|
215
|
+
local result = {}
|
|
216
|
+
for _, target in ipairs(M.modules(G, imp, ctx)) do
|
|
217
|
+
local n = (G.files[target].lua_exports or {})[name]
|
|
218
|
+
if n then result[#result + 1] = G.id_of[target][n] end
|
|
219
|
+
end
|
|
220
|
+
return result
|
|
221
|
+
end
|
|
222
|
+
return M
|
|
@@ -16,6 +16,10 @@ for _, argument in ipairs(arg or {}) do
|
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
assert((options.STDIO == '1') ~= (options.HTTP == '1'), 'Specify exactly one of STDIO=1 or HTTP=1')
|
|
19
|
+
local lsp_mode = options.LSP == '1'
|
|
20
|
+
assert(not lsp_mode or options.STDIO == '1', 'LSP=1 requires STDIO=1')
|
|
21
|
+
local lsp = lsp_mode and require('codeoutline.lsp')
|
|
22
|
+
local lsp_reader = lsp_mode and lsp.reader()
|
|
19
23
|
local managed = options.DAEMON == '1'
|
|
20
24
|
assert(not managed or options.HTTP == '1', 'DAEMON=1 requires HTTP=1')
|
|
21
25
|
local config = { roots = {}, project = options.PROJECT and assert(paths.canonical(options.PROJECT)),
|
|
@@ -74,7 +78,10 @@ local function submit(req, done)
|
|
|
74
78
|
end
|
|
75
79
|
local function cancel(id) if id and jobs[id] then shared:set('cancel:' .. id, true) end end
|
|
76
80
|
local function send(response)
|
|
77
|
-
if response then
|
|
81
|
+
if response then
|
|
82
|
+
io.stdout:write(lsp_mode and lsp.frame(response) or (xutils.json_pack(response) .. '\n'))
|
|
83
|
+
io.stdout:flush()
|
|
84
|
+
end
|
|
78
85
|
end
|
|
79
86
|
local function listen()
|
|
80
87
|
endpoint = http.start(config, submit, cancel, codec)
|
|
@@ -110,7 +117,10 @@ return {
|
|
|
110
117
|
end
|
|
111
118
|
if options.STDIO == '1' then
|
|
112
119
|
assert(xutils.read_stdin, 'Rebuild runtime for nonblocking stdin support')
|
|
113
|
-
|
|
120
|
+
if lsp_mode then
|
|
121
|
+
assert(xutils.stdout_binary and xutils.stdout_binary(), 'Rebuild runtime for binary stdout support')
|
|
122
|
+
stdio = lsp.new(config, send, submit, cancel, stop)
|
|
123
|
+
else stdio = mcp.new(config, submit, cancel) end
|
|
114
124
|
else
|
|
115
125
|
-- Packages ship the codec as lib/xhttp_codec.lua; a source checkout
|
|
116
126
|
-- reads it from the xnet2lua submodule.
|
|
@@ -135,7 +145,11 @@ return {
|
|
|
135
145
|
__thread_handle = function(_, op, id, ok, result)
|
|
136
146
|
if op == 'worker_ready' then
|
|
137
147
|
worker_ready = true
|
|
138
|
-
|
|
148
|
+
local waiting = {}
|
|
149
|
+
for job_id in pairs(jobs) do waiting[#waiting + 1] = job_id end
|
|
150
|
+
table.sort(waiting, function(a, b) return tonumber(a) < tonumber(b) end)
|
|
151
|
+
for _, job_id in ipairs(waiting) do
|
|
152
|
+
local job = jobs[job_id]
|
|
139
153
|
local posted, err = xthread.post(2, 'run', job_id, job.request)
|
|
140
154
|
if not posted then jobs[job_id], job_count = nil, job_count - 1; job.done(false, tostring(err)) end
|
|
141
155
|
end
|
|
@@ -155,6 +169,7 @@ return {
|
|
|
155
169
|
if stopping then return end
|
|
156
170
|
if not worker_ready and xtimer.now_ms() - startup > 10000 then error('Index worker failed to start') end
|
|
157
171
|
if installed_update and exit_on_update and job_count == 0
|
|
172
|
+
and not (lsp_mode and stdio and stdio.state ~= 'closed')
|
|
158
173
|
and not (stdio and next(stdio.pending)) and not (endpoint and endpoint.busy()) then
|
|
159
174
|
notice('exiting to start update ' .. tostring(installed_update))
|
|
160
175
|
if managed then
|
|
@@ -171,12 +186,20 @@ return {
|
|
|
171
186
|
if stdio then
|
|
172
187
|
local data, err = xutils.read_stdin(65536)
|
|
173
188
|
if not data then
|
|
174
|
-
local incomplete = err == 'eof' and input:find('%S') ~= nil
|
|
175
|
-
if incomplete then send(mcp.error(nil, -32700, 'EOF before message newline')) end
|
|
189
|
+
local incomplete = err == 'eof' and (lsp_mode and not lsp_reader:complete() or (not lsp_mode and input:find('%S') ~= nil))
|
|
190
|
+
if incomplete then send(mcp.error(nil, -32700, lsp_mode and 'EOF before complete LSP frame' or 'EOF before message newline')) end
|
|
176
191
|
if err == 'stdio requires redirected stdin' then err = 'run by an MCP client; see codeoutline --help' end
|
|
177
192
|
if err ~= 'eof' then io.stderr:write(tostring(err) .. '\n') end
|
|
178
193
|
stdio:close(); shared:set('shutdown', true); xthread.stop(err == 'eof' and not incomplete and 0 or 1); return
|
|
179
194
|
end
|
|
195
|
+
if lsp_mode then
|
|
196
|
+
local ok, why = pcall(lsp_reader.feed, lsp_reader, data, function(body) stdio:accept(body) end)
|
|
197
|
+
if not ok then
|
|
198
|
+
send(mcp.error(nil, -32700, tostring(why))); stdio:close(); stop(1); return
|
|
199
|
+
end
|
|
200
|
+
if not stopping then stdio:poll() end
|
|
201
|
+
return
|
|
202
|
+
end
|
|
180
203
|
input = input .. data
|
|
181
204
|
while true do
|
|
182
205
|
local pos = input:find('\n', 1, true)
|