@codua/codeoutline-win32-x64 0.2.0 → 0.2.4
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 +7 -1
- package/README.zh-CN.md +4 -1
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/package.json +1 -1
- package/scripts/codeoutline/callers.lua +116 -0
- package/scripts/codeoutline/command.lua +7 -3
- package/scripts/codeoutline/common.lua +21 -1
- package/scripts/codeoutline/completion.lua +93 -22
- package/scripts/codeoutline/documents.lua +1 -1
- package/scripts/codeoutline/explore.lua +39 -10
- package/scripts/codeoutline/foreign.lua +60 -0
- package/scripts/codeoutline/foreign_lua.lua +146 -0
- package/scripts/codeoutline/graph.lua +107 -54
- package/scripts/codeoutline/index.lua +7 -3
- package/scripts/codeoutline/index_worker.lua +15 -7
- package/scripts/codeoutline/indirect.lua +225 -0
- package/scripts/codeoutline/js_evidence.lua +175 -0
- package/scripts/codeoutline/js_resolution.lua +201 -0
- package/scripts/codeoutline/lang/kotlin.lua +384 -0
- package/scripts/codeoutline/lang/lua.lua +17 -0
- package/scripts/codeoutline/lsp.lua +58 -34
- package/scripts/codeoutline/lua_bindings.lua +360 -0
- package/scripts/codeoutline/main.lua +24 -3
- package/scripts/codeoutline/mcp.lua +13 -4
- package/scripts/codeoutline/navigation.lua +161 -34
- package/scripts/codeoutline/parse.lua +3 -0
- package/scripts/codeoutline/query_report.lua +36 -0
- package/scripts/codeoutline/service.lua +11 -3
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
package/README.md
CHANGED
|
@@ -56,6 +56,7 @@ Three tools are provided:
|
|
|
56
56
|
| Tool | Purpose |
|
|
57
57
|
| --- | --- |
|
|
58
58
|
| `codeoutline_explore` | Query source, call paths, and callers/callees by symbol or file name (`query`; optional `projectPath`, `budget`) |
|
|
59
|
+
| `codeoutline_callers` | [Find recursive callers and affected files](docs/CALLERS.md) for an exact symbol/qualified name (`query`; optional `projectPath`, `depth` default 3, `max_nodes` default 200, `budget`) |
|
|
59
60
|
| `codeoutline_status` | Refresh and report index, cache, scanner, and parser statistics |
|
|
60
61
|
| `codeoutline_rebuild` | Rebuild fully, bypassing the cache |
|
|
61
62
|
|
|
@@ -95,7 +96,12 @@ On Linux, decoding GBK sources needs the GBK module of the system iconv. Minimal
|
|
|
95
96
|
|
|
96
97
|
## Supported languages
|
|
97
98
|
|
|
98
|
-
C, C++, C#, Go, Java, JavaScript / TypeScript (including JSX/TSX), Lua, Python, and Rust.
|
|
99
|
+
C, C++, C#, Go, Java, JavaScript / TypeScript (including JSX/TSX), Kotlin (`.kt` / `.kts`), Lua, Python, and Rust.
|
|
100
|
+
|
|
101
|
+
Kotlin includes declarations, constructor properties, extension functions, expression bodies,
|
|
102
|
+
package imports (including aliases), and ordinary, generic and trailing-lambda calls.
|
|
103
|
+
Resolution is heuristic: compiler-generated members, implicit lambda receivers, string-template
|
|
104
|
+
expressions, Java interop and coroutine/framework dispatch are not modeled.
|
|
99
105
|
|
|
100
106
|
## Command line
|
|
101
107
|
|
package/README.zh-CN.md
CHANGED
|
@@ -95,7 +95,10 @@ Linux 上解码 GBK 源码需要系统 iconv 的 GBK 模块;EL8/EL9 最小安
|
|
|
95
95
|
|
|
96
96
|
## 支持的语言
|
|
97
97
|
|
|
98
|
-
C、C++、C#、Go、Java、JavaScript / TypeScript(含 JSX/TSX)、Lua、Python、Rust。
|
|
98
|
+
C、C++、C#、Go、Java、JavaScript / TypeScript(含 JSX/TSX)、Kotlin(`.kt` / `.kts`)、Lua、Python、Rust。
|
|
99
|
+
|
|
100
|
+
Kotlin 支持声明、主构造器属性、扩展函数、表达式函数体、包导入与别名,以及普通、泛型和尾随 lambda 调用。
|
|
101
|
+
关系解析仍是启发式的;不建模编译器生成成员、lambda 隐式接收者、字符串模板内的表达式、Java 互操作或协程/框架分派。
|
|
99
102
|
|
|
100
103
|
## 命令行
|
|
101
104
|
|
package/bin/xnet.exe
CHANGED
|
Binary file
|
package/build-info.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"target":"win32-x64","lua":"LuaJIT 2.1.1774896198","sourceCommit":"ed96402bbd84f392f4d98a53467ace4b9af4042d","sourceDirty":false,"version":"0.2.4","note":"Release build from a clean checkout","releaseReady":true,"updateSequence":13,"sha256":{"scripts/codeoutline/updater.lua":"267c4b6e9704fce710f44d1bfceac69c1857e34e064d8444d7890f0e10d921c7","scripts/codeoutline/http.lua":"3d957628ecc9592d57cc68a61e5d4229a71da501eb8fb3aa0bbb5e1cd772adf0","keys/update-public.pem":"7ff853339e19631b20ed3fa2cf221daa31c581e2e84d161b344b8f06de6562a8","keys/update-ca.crt":"d9b5ec3d4628de9c5559871f39841a5f84d47c53ded4d58d6e3bba2b4c669a02","scripts/codeoutline/update_sequence.lua":"bce1625b261d4cbe8d9ed46deaaa4ba0e51188a28eadb29d40a2eb38c7887a86","scripts/codeoutline/index.lua":"b4bd637a5e4c573738ec4e9477ba5090949e7d5b9a35a968d3d4731540ae1630","licenses/xnet2lua.txt":"1aa8af3df70f60f1ebf2d23e14c27af1606057ad9c32a9a0d15fd76cff257532","licenses/libdeflate.txt":"41b60f2caab6bffdd5ba360687bd23ca653c0a1235c00380ecffc939b4cd8d75","scripts/codeoutline/update_worker.lua":"7e2ec28e4b911d7b90fd97d0a4c0e2f5b295d1a9200c5c7250e47a99139ca550","scripts/codeoutline/index_worker.lua":"ad6b300fcca6f2eadb0373179d1c5c3321319a3ab0cae3d9a8996ce760e55671","licenses/luajit.txt":"1b10a02c9474cb908da2d87bc908edd8798f9ad28d9a8c53fbd05c13227f7394","scripts/codeoutline/version.lua":"98080592a13c231e3d35fc5b8d8c35406cbb6d9c759d2cc6a786ee489c02d900","scripts/codeoutline/indirect.lua":"6bb422611b82ee370b29c5e1eafa25753fa5e4f722b5f2dcda99ad21a7d55a1e","scripts/codeoutline/xscan.lua":"bd95a1b0b7022d029a41aab615897502478b5834612505e8d299343cb5ca8ef9","scripts/codeoutline/js_evidence.lua":"ddb9f8a4f22b1f7fd397a75c6c5660d434133b5148dbf396586bb5b443161776","README.md":"b58cd12615dd7b796c3a3e8ce86ec0adb36a92f7d32025eed1fb78a843616fcf","README.zh-CN.md":"fea0ffb9835e1b78925b1aa0a6a3019591e376d23e94da5b4f58773601e2d7da","scripts/codeoutline/js_resolution.lua":"76be5143d2d5ff5b381c1cde0c1039fa26cb035f309a0aba7c3683efdcdd4b58","DISTRIBUTION.md":"da4a1048fc9b44670fd6fcef97e7d92ac3f50d3523da1773930c49f7e2c38dc3","THIRD_PARTY.md":"a0d596a8600c5244b27c1426a81b4ec7046d213d733ec6b4287a4b1e8db501b5","scripts/xupgate/client.lua":"967c29c1eeebd8596458025ab3237816a91591cca64236ea0e7ba1762814e6ba","bin/xnet.exe":"e3011f838676974c8b534ed53f18b299d5b08ede9d00a6c8744a0c1aa9de62f8","scripts/codeoutline/lang/python.lua":"1ae8f1658e25220ec4d952c17ed817bfc92d0c45d4585d3dd4716d5585b60cc6","scripts/xupgate/http_client.lua":"a189506c3d0fcc454f5e001fdeecdd6349a1019ea0970d11ce2fbfdf035166d6","licenses/lua-cmsgpack.txt":"8edfdc5282278a1268d8a6ee52f9245f1a5fe3d1c8065be00330196b1de49873","scripts/codeoutline/callers.lua":"d5b11e92bd32a823f1d198a6e7b4dca73e15daa4713762cf29d1062f26ec20d6","scripts/xupgate/http_codec.lua":"a5b0f127105ba6dbd4a518a214ca55e22c7510e6b2fc8c25c325898d8346ef8c","scripts/codeoutline/lang/cpp.lua":"47e3dc18cbc8b9a93567897e9ff69a026434a1971fe1dcc3e07d3af03c54a4f2","licenses/mbedtls.txt":"9b405ef4c89342f5eae1dd828882f931747f71001cfba7d114801039b52ad09b","scripts/xupgate/proxy.lua":"5bf532e7005f44555d6a5277336e5ad395af060585c13a1cdc2441de50e0dcff","scripts/codeoutline/cli.lua":"f7ac4addd32ced58069954cb81edd4836c6043bb5d143683b80bd7b11554c733","codeoutline":"3d3970e488e077e8acd67d174b506a361d43578b3360c7b29f2ec3f0103ba899","codeoutline.cmd":"607b60c6d107becdb6793df8f41aaf2cff944baf69f5ece59dba990d0f24c13b","scripts/codeoutline/main.lua":"0e1731a4e931ed8cc3ec42c537bb61c22094c3462fe7c20ed49ed7831ce71bd4","scripts/codeoutline/command.lua":"e4bd7698e03dbca3728084454a2e9a4b1a9902e76c3d69b85107ffac80981716","scripts/codeoutline/mcp.lua":"d68f3648a31befeabb846faae3e13efe4f8c7406f6d9b14a1fab6c77014c6b50","scripts/codeoutline/common.lua":"481731dbaeeb937d516e11031f1bef7d1237eaa0999f372ebc3c22fd1ab1898f","scripts/codeoutline/navigation.lua":"032532577b225d31aad9df7a4667b6e082d6612b234acc2079297d33c6b594a3","scripts/codeoutline/lang/js.lua":"62570ddc38c974991763e11770059880b87ec87f14578891df9d935af6cb4786","scripts/codeoutline/parse.lua":"52eadb0b4b5bb5db2f6064170414377c5a23e2b24b3409ae00b9969273076435","scripts/codeoutline/control.lua":"b67a2e382e021f0793ef313aa4e71faab76f6cb77ca127f499d01ae96f36a8db","scripts/codeoutline/parse_pool.lua":"acaafe74a568ec450e428f4a1a2ff704834588bba0f8b808e4c7a1d552861941","scripts/codeoutline/daemon.lua":"06863991135cc9a85f07bca8310296f0df9e415b3e2de97ae006393e777b009b","scripts/codeoutline/parse_worker.lua":"c5f1745d15332c5040b1e97f6da08f2f456d9afe7c2491275cc97d7113b75e45","scripts/codeoutline/documents.lua":"320a7d40fd5c0fef03a18df586848059a65c0f4e7ab4b218e9e84561eb5a7007","scripts/codeoutline/path.lua":"407bd960c1ad04e5006b321ce33263393bb40eee5dee5c123be9b36d3ad10937","scripts/codeoutline/explore.lua":"f4e378d300d2ff8dc30ea59a1c8d13f7371e9e49352f203272b420d09f0df240","scripts/codeoutline/lua_bindings.lua":"0ceac2704b3bb2d9b88b6840617d6030d725546ec4b0e19f3ce52aa5be590adb","scripts/codeoutline/lang/lua.lua":"f50a169549475d5d71f8af920feeb82797e8f24ccfe0c3f416abc5a32e942713","LICENSE":"1b63179362acd482b4a9a07ca526b3fce6d9103dcded361de2159ade174568b6","scripts/codeoutline/query_report.lua":"7b6c5e5aae8bcebd10612e360ee7e4cd0f0795f7594479d54e074e50fd6b97bc","scripts/codeoutline/foreign.lua":"ac5b3868430b4f2f8b5182d86e45305b71fa3ffd9a7f5ce034ac49f31e047008","scripts/codeoutline/lang/kotlin.lua":"cefaad1c412cb42ea6b2027ad9f81ad38d8d821f05c1cfde7f89c600d745a708","scripts/codeoutline/lsp.lua":"5403311a9fd5cdc85bcbe158c35d5f1515d279f8374fc41d1f0c694a629ba824","scripts/codeoutline/lang/rust.lua":"294cee85786caaa5f29dedd5058877c7a4786349431faf33b36357ef69406a9e","scripts/codeoutline/lang/csharp.lua":"4bfa8555955c7de98ea12d36ee6f7d817c40cb87e77350fe2af4783517190a3d","scripts/codeoutline/service.lua":"91ac502048f8e5be4521284ca77f45af1a8f6421aff59c41361c88015a531b03","scripts/codeoutline/foreign_lua.lua":"035e8f38408e3bd9a6923a8551c5c37780496f74720862ad1b45ca820c0c364a","scripts/codeoutline/lang/c.lua":"9cd8abbdfda6cae5d6c04a9ae68bbd9f7589b217e88b7682917106e80df9b0c5","scripts/codeoutline/lang/java.lua":"0ea34298770cb3431f4bc3521c4d2ecf363d55e768d6cd30b3f11ad05d7e8f0d","scripts/xupgate/common.lua":"86267648c0dbbd3a05f90de4d6e1dbee53ba57bf4801783c2ae636224b1f228c","scripts/xupgate/signature.lua":"f07de8a4093d08cc69d3c1d8296d23318c5d81344ece788d4453a9b3b700f000","scripts/codeoutline/text.lua":"75f9af87ff5ce62def74f69d8972a6b11ff660723fc5cf515369ee3012ff0675","scripts/codeoutline/graph.lua":"1e07b86bb47aebce50658fc4f6e691e48e92436803939e5d395676fc6e4fec3b","scripts/codeoutline/lang/go.lua":"3a62d4dc451b0d2f7f2aefd5e77d11449a5d725f59379728eba8dda0aacc13f3","scripts/codeoutline/completion.lua":"4781d195e543a56d0e52cd1e54d451cb4a02dafab60e772daee7b1fad58e6b2c","lib/xhttp_codec.lua":"a5b0f127105ba6dbd4a518a214ca55e22c7510e6b2fc8c25c325898d8346ef8c"},"runtimeBuild":"b9b847244c68283df56e7858fe3daaafd35b756f0ff67cfa379f998133ddf29d","runtimeCommit":"d33491598d199b1a2f5fd3d9840c5b17d49b1e13"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"name":"@codua/codeoutline-win32-x64","files":["bin/","lib/","keys/","scripts/","licenses/","LICENSE","codeoutline","codeoutline.cmd","build-info.json","*.md"],"version":"0.2.4","publishConfig":{"access":"public"},"description":"CodeOutline native runtime and Lua implementation for win32-x64","cpu":["x64","arm64"],"license":"BSD-2-Clause","repository":{"type":"git","url":"git+https://github.com/1dao/codeoutline.git"},"os":["win32"]}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
-- Reverse BFS over query-owned relationships. No persistent impact graph.
|
|
2
|
+
local graph = require('codeoutline.graph')
|
|
3
|
+
local control = require('codeoutline.control')
|
|
4
|
+
local text = require('codeoutline.text')
|
|
5
|
+
local M = {}
|
|
6
|
+
|
|
7
|
+
function M.validate(query, opts)
|
|
8
|
+
require('codeoutline.explore').validate(query, opts)
|
|
9
|
+
opts = opts or {}
|
|
10
|
+
for _, item in ipairs({ { 'depth', 3, 8 }, { 'max_nodes', 200, 2000 } }) do
|
|
11
|
+
local value = opts[item[1]]
|
|
12
|
+
if value == nil then value = item[2] end
|
|
13
|
+
assert(type(value) == 'number' and value % 1 == 0 and value >= 1 and value <= item[3],
|
|
14
|
+
item[1] .. ' must be an integer between 1 and ' .. item[3])
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
function M.run(symbols, idx, query, opts)
|
|
19
|
+
M.validate(query, opts)
|
|
20
|
+
opts = opts or {}
|
|
21
|
+
local depth, cap = opts.depth or 3, opts.max_nodes or 200
|
|
22
|
+
local budget = require('codeoutline.explore').validate(query, opts)
|
|
23
|
+
local Q = graph.query(symbols, opts)
|
|
24
|
+
local result = { targets = {}, callers = {}, files = {}, depth = depth,
|
|
25
|
+
node_limit_reached = false, depth_limit_reached = false }
|
|
26
|
+
local function describe(id)
|
|
27
|
+
return { id = id, name = Q.nodes[id].qualified, file = Q.files[Q.node_file[id]].path, line = Q.nodes[id].line }
|
|
28
|
+
end
|
|
29
|
+
local candidates = symbols.by_qualified[query] or symbols.by_name[query] or {}
|
|
30
|
+
local ordered = {}
|
|
31
|
+
for _, id in ipairs(candidates) do ordered[#ordered + 1] = id end
|
|
32
|
+
table.sort(ordered, function(a, b) return graph.before(Q, a, b) end)
|
|
33
|
+
local frontier, seen, next_hop = {}, {}, {}
|
|
34
|
+
for _, id in ipairs(ordered) do
|
|
35
|
+
if #frontier >= cap then result.node_limit_reached = true; break end
|
|
36
|
+
frontier[#frontier + 1] = id; seen[id] = true
|
|
37
|
+
result.targets[#result.targets + 1] = describe(id)
|
|
38
|
+
end
|
|
39
|
+
local files = {}
|
|
40
|
+
for level = 1, depth do
|
|
41
|
+
if #frontier == 0 then break end
|
|
42
|
+
control.check()
|
|
43
|
+
Q:load_incoming(frontier) -- one project reference scan per layer
|
|
44
|
+
local pending, links = {}, {}
|
|
45
|
+
for _, dst in ipairs(frontier) do
|
|
46
|
+
local edges = Q.inn[dst] or {}
|
|
47
|
+
for i = 1, #edges, graph.EDGE do
|
|
48
|
+
if i % 384 == 1 then control.check() end
|
|
49
|
+
local src = edges[i]
|
|
50
|
+
if not seen[src] and not links[src] then
|
|
51
|
+
links[src] = { target = dst, line = edges[i + 1], kind = edges[i + 2] }
|
|
52
|
+
pending[#pending + 1] = src
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
table.sort(pending, function(a, b) return graph.before(Q, a, b) end)
|
|
57
|
+
frontier = {}
|
|
58
|
+
for _, src in ipairs(pending) do
|
|
59
|
+
if #result.callers >= cap then result.node_limit_reached = true; break end
|
|
60
|
+
seen[src], next_hop[src] = true, links[src]
|
|
61
|
+
frontier[#frontier + 1] = src
|
|
62
|
+
local entry = describe(src)
|
|
63
|
+
entry.depth, entry.path = level, {}
|
|
64
|
+
local current = src
|
|
65
|
+
while next_hop[current] do
|
|
66
|
+
local hop = describe(current)
|
|
67
|
+
local edge = next_hop[current]
|
|
68
|
+
hop.call_line, hop.kind = edge.line, edge.kind
|
|
69
|
+
entry.path[#entry.path + 1] = hop
|
|
70
|
+
current = edge.target
|
|
71
|
+
end
|
|
72
|
+
entry.path[#entry.path + 1] = describe(current)
|
|
73
|
+
result.callers[#result.callers + 1] = entry
|
|
74
|
+
files[entry.file] = true
|
|
75
|
+
end
|
|
76
|
+
if level == depth and #frontier > 0 then result.depth_limit_reached = true end
|
|
77
|
+
if result.node_limit_reached then break end
|
|
78
|
+
end
|
|
79
|
+
for file in pairs(files) do result.files[#result.files + 1] = file end
|
|
80
|
+
table.sort(result.files)
|
|
81
|
+
-- Source validation may repair encodings and invalidate IDs: retry the query.
|
|
82
|
+
local paths = {}
|
|
83
|
+
for _, target in ipairs(result.targets) do paths[target.file] = true end
|
|
84
|
+
for _, file in ipairs(result.files) do paths[file] = true end
|
|
85
|
+
local changed = false
|
|
86
|
+
for path in pairs(paths) do
|
|
87
|
+
local source, repaired = idx:query_source(path)
|
|
88
|
+
assert(source, 'cannot read source: ' .. path)
|
|
89
|
+
changed = changed or repaired
|
|
90
|
+
end
|
|
91
|
+
if changed then return nil, { encoding_retry = true } end
|
|
92
|
+
local lines = { string.format('Matched %d target(s); %d potential callers in %d files, searched up to %d levels.',
|
|
93
|
+
#result.targets, #result.callers, #result.files, depth),
|
|
94
|
+
'Static potential impact; each caller has one shortest path. This is not proof of runtime execution or complete impact coverage.' }
|
|
95
|
+
if #result.targets == 0 then lines[#lines + 1] = 'No exact symbol matched; use a symbol name or qualified name.' end
|
|
96
|
+
if #result.targets > 1 then lines[#lines + 1] = 'Multiple definitions matched; results cover the listed targets.' end
|
|
97
|
+
if result.node_limit_reached then lines[#lines + 1] = 'Node limit reached; targets or callers were omitted.' end
|
|
98
|
+
if result.depth_limit_reached then lines[#lines + 1] = 'Depth limit reached; callers beyond this depth were not checked.' end
|
|
99
|
+
for _, target in ipairs(result.targets) do
|
|
100
|
+
lines[#lines + 1] = string.format('Target: %s (%s:%d)', target.name, target.file, target.line)
|
|
101
|
+
end
|
|
102
|
+
for _, entry in ipairs(result.callers) do
|
|
103
|
+
local path = {}
|
|
104
|
+
for _, hop in ipairs(entry.path) do
|
|
105
|
+
path[#path + 1] = string.format('%s (%s:%d)%s', hop.name, hop.file, hop.call_line or hop.line,
|
|
106
|
+
hop.kind and ' [' .. hop.kind .. ']' or '')
|
|
107
|
+
end
|
|
108
|
+
lines[#lines + 1] = string.format('Depth %d: %s', entry.depth, table.concat(path, ' -> '))
|
|
109
|
+
end
|
|
110
|
+
if #result.files > 0 then lines[#lines + 1] = 'Affected caller files:\n' .. table.concat(result.files, '\n') end
|
|
111
|
+
local output, cut = text.limit(table.concat(lines, '\n'), budget, result.node_limit_reached)
|
|
112
|
+
result.truncated, result.query_stats = cut, Q.stats
|
|
113
|
+
return output, result
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
return M
|
|
@@ -19,6 +19,7 @@ Usage:
|
|
|
19
19
|
codeoutline lsp --stdio [--project PATH]
|
|
20
20
|
codeoutline serve --http [--host HOST] [--port PORT] [--project PATH] [--allow-root PATH ...]
|
|
21
21
|
codeoutline explore --project PATH --query QUERY [--budget BYTES]
|
|
22
|
+
codeoutline callers --project PATH --query SYMBOL [--depth 3] [--max-nodes 200] [--budget BYTES]
|
|
22
23
|
codeoutline status [--project PATH]
|
|
23
24
|
codeoutline rebuild [--project PATH]
|
|
24
25
|
codeoutline doctor [--project PATH]
|
|
@@ -60,6 +61,7 @@ local function parse(args)
|
|
|
60
61
|
['allow-root'] = true, ['allow-host'] = true, ['allow-origin'] = true },
|
|
61
62
|
daemon = { port = true }, install = { port = true, npm = true }, uninstall = { port = true },
|
|
62
63
|
explore = { project = true, query = true, budget = true },
|
|
64
|
+
callers = { project = true, query = true, budget = true, depth = true, ['max-nodes'] = true },
|
|
63
65
|
update = { check = true, channel = true },
|
|
64
66
|
status = { project = true }, rebuild = { project = true }, doctor = { project = true },
|
|
65
67
|
}
|
|
@@ -237,11 +239,13 @@ local function run()
|
|
|
237
239
|
local root = options.project or '.'
|
|
238
240
|
if command == 'doctor' then return doctor(root) end
|
|
239
241
|
local svc = require('codeoutline.service')
|
|
240
|
-
if command == 'explore' then
|
|
241
|
-
assert(options.query, '
|
|
242
|
+
if command == 'explore' or command == 'callers' then
|
|
243
|
+
assert(options.query, command .. ' requires --query')
|
|
242
244
|
local budget
|
|
243
245
|
if options.budget then budget = assert(tonumber(options.budget), '--budget must be a number') end
|
|
244
|
-
local
|
|
246
|
+
local depth = options.depth and assert(tonumber(options.depth), '--depth must be a number')
|
|
247
|
+
local max_nodes = options['max-nodes'] and assert(tonumber(options['max-nodes']), '--max-nodes must be a number')
|
|
248
|
+
local text = svc[command](root, options.query, { budget = budget, depth = depth, max_nodes = max_nodes })
|
|
245
249
|
io.write(text, '\n')
|
|
246
250
|
else
|
|
247
251
|
io.write(xutils.json_pack(svc[command](root)), '\n')
|
|
@@ -24,7 +24,8 @@ local text = require('codeoutline.text')
|
|
|
24
24
|
|
|
25
25
|
function M.new(path, language, opts)
|
|
26
26
|
return { path = path, language = language, nodes = {}, refs = {}, imports = {},
|
|
27
|
-
ranges = not opts or opts.ranges ~= false
|
|
27
|
+
ranges = not opts or opts.ranges ~= false, collect_dispatch = opts and opts.dispatch,
|
|
28
|
+
dispatch_only = opts and opts.dispatch_only }
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
-- Collapse a token span into a one-line signature.
|
|
@@ -131,17 +132,36 @@ end
|
|
|
131
132
|
|
|
132
133
|
-- Drop parser-internal fields so the result is plain data.
|
|
133
134
|
function M.finish(r, T)
|
|
135
|
+
if T and (r.language == 'c' or r.language == 'cpp') then
|
|
136
|
+
require('codeoutline.foreign').collect(r, T)
|
|
137
|
+
end
|
|
134
138
|
M.assign_refs(r)
|
|
139
|
+
-- Query-only parse: preserve normal declaration/call attribution, but do
|
|
140
|
+
-- not build binding evidence or compact records that will be discarded.
|
|
141
|
+
if r.dispatch_only then
|
|
142
|
+
require('codeoutline.indirect').collect(r, T)
|
|
143
|
+
r.dispatch_only, r.collect_dispatch = nil, nil
|
|
144
|
+
return r
|
|
145
|
+
end
|
|
146
|
+
if T then require('codeoutline.js_evidence').collect(r, T) end
|
|
147
|
+
if T then require('codeoutline.indirect').collect(r, T) end
|
|
148
|
+
r.collect_dispatch = nil
|
|
135
149
|
local name, from, kind, line, recv = {}, {}, {}, {}, {}
|
|
150
|
+
local js_receiver = r.js_imports and {}
|
|
151
|
+
local lua_binding = r.lua_imports and {}
|
|
136
152
|
local start, stop = r.ranges and T and {}, r.ranges and T and {}
|
|
137
153
|
for i, ref in ipairs(r.refs) do
|
|
138
154
|
name[i], from[i], kind[i], line[i], recv[i] = ref.name, ref.from, ref.kind, ref.line, ref.recv or false
|
|
155
|
+
if js_receiver then js_receiver[i] = ref.js_receiver or '' end
|
|
156
|
+
if lua_binding then lua_binding[i] = ref.lua_binding or '' end
|
|
139
157
|
if start then
|
|
140
158
|
local named = T:text(ref.tok) == ref.name
|
|
141
159
|
start[i], stop[i] = named and T.s[ref.tok] - 1 or false, named and T.e[ref.tok] or false
|
|
142
160
|
end
|
|
143
161
|
end
|
|
144
162
|
r.refs = { name = name, from = from, kind = kind, line = line, recv = recv, start = start or nil, stop = stop or nil }
|
|
163
|
+
r.refs.js_receiver = js_receiver
|
|
164
|
+
r.refs.lua_binding = lua_binding
|
|
145
165
|
for i, n in ipairs(r.nodes) do
|
|
146
166
|
n.ti, n.tj = nil, nil
|
|
147
167
|
if not r.ranges then
|
|
@@ -38,7 +38,7 @@ end
|
|
|
38
38
|
local WRAPPERS = {}
|
|
39
39
|
for word in ([[Option Box Rc Arc RefCell Cell Mutex RwLock Weak unique_ptr shared_ptr weak_ptr Ptr Ref
|
|
40
40
|
Optional Nullable Promise Future Lazy]]):gmatch('%S+') do WRAPPERS[word] = true end
|
|
41
|
-
local TYPE_AFTER = { go = true, rust = true, typescript = true, javascript = true, python = true }
|
|
41
|
+
local TYPE_AFTER = { go = true, rust = true, typescript = true, javascript = true, python = true, kotlin = true }
|
|
42
42
|
local DYNAMIC = { lua = true, python = true, javascript = true, typescript = true }
|
|
43
43
|
|
|
44
44
|
-- Full parses of type files, keyed by the index record they correspond to.
|
|
@@ -109,7 +109,7 @@ local function declared(node, language)
|
|
|
109
109
|
rest = rest:sub(#params + 1):gsub('^%s+', '')
|
|
110
110
|
if rest:sub(1, 1) == '(' then rest = rest:match('^%((.-)[,%)]') or '' end
|
|
111
111
|
return normalize(rest)
|
|
112
|
-
elseif language == 'typescript' or language == 'javascript' then
|
|
112
|
+
elseif language == 'typescript' or language == 'javascript' or language == 'kotlin' then
|
|
113
113
|
local after = sig:match('%)%s*:%s*([^{=]+)$')
|
|
114
114
|
return after and normalize(after)
|
|
115
115
|
elseif language == 'lua' then
|
|
@@ -211,7 +211,7 @@ local function parameters(T, a, b, language, out)
|
|
|
211
211
|
end
|
|
212
212
|
|
|
213
213
|
-- Initializer starting at token j: a type name, a module path, or a call chain.
|
|
214
|
-
local function initializer(T, j, stop)
|
|
214
|
+
local function initializer(T, j, stop, language)
|
|
215
215
|
if not j or j > stop then return {} end
|
|
216
216
|
if kw(T, j, 'new') or (T.k[j] == 'id' and text_of(T, j) == 'new') then
|
|
217
217
|
local k, last = j + 1, nil
|
|
@@ -226,6 +226,21 @@ local function initializer(T, j, stop)
|
|
|
226
226
|
local k = is(T, j + 1, '(') and j + 2 or j + 1
|
|
227
227
|
if T.k[k] == 'str' then return { module = text_of(T, k):gsub('^[%a]*["\'%[=]+', ''):gsub('["\'%]=]+$', '') } end
|
|
228
228
|
end
|
|
229
|
+
if language == 'lua' and T.k[j] == 'id' then
|
|
230
|
+
-- Lua `*import` loaders: `ks.import('path.lua')`, `skynet_import 'path.lua'`.
|
|
231
|
+
local k = j
|
|
232
|
+
while is(T, k + 1, '.') and T.k[k + 2] == 'id' do k = k + 2 end
|
|
233
|
+
local name = text_of(T, k)
|
|
234
|
+
if name:sub(-6) == 'import' then
|
|
235
|
+
local a = is(T, k + 1, '(') and k + 2 or k + 1
|
|
236
|
+
if T.k[a] == 'str' and (not is(T, k + 1, '(') or is(T, a + 1, ')')) then
|
|
237
|
+
local path = text_of(T, a):gsub('^[%a]*["\'%[=]+', ''):gsub('["\'%]=]+$', '')
|
|
238
|
+
local parts = {}
|
|
239
|
+
for x = j, k, 2 do parts[#parts + 1] = text_of(T, x) end
|
|
240
|
+
return { module = path, module_kind = table.concat(parts, '.') }
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
end
|
|
229
244
|
local chain, k = {}, j
|
|
230
245
|
while k <= stop and (T.k[k] == 'id' or (T.k[k] == 'kw' and SELF[text_of(T, k)])) do
|
|
231
246
|
local item = { name = text_of(T, k) }
|
|
@@ -262,9 +277,10 @@ local function declarations(T, a, b, language, skip, out)
|
|
|
262
277
|
local entry = { name = text_of(T, name_tok), type = normalize(type), at = name_tok }
|
|
263
278
|
if init then
|
|
264
279
|
local stop = statement_end(init)
|
|
265
|
-
local value = initializer(T, init, stop)
|
|
280
|
+
local value = initializer(T, init, stop, language)
|
|
266
281
|
entry.type = entry.type or normalize(value.type)
|
|
267
282
|
entry.module, entry.chain = value.module, value.chain
|
|
283
|
+
entry.module_kind = value.module_kind
|
|
268
284
|
end
|
|
269
285
|
out[#out + 1] = entry
|
|
270
286
|
end
|
|
@@ -311,12 +327,13 @@ local function declarations(T, a, b, language, skip, out)
|
|
|
311
327
|
local k = i + 1
|
|
312
328
|
while T.k[k] == 'id' do add(k); if is(T, k + 1, ',') then k = k + 2 else break end end
|
|
313
329
|
elseif kw(T, i, 'as') and T.k[i + 1] == 'id' then add(i + 1) end
|
|
314
|
-
elseif language == 'javascript' or language == 'typescript' then
|
|
315
|
-
if (kw(T, i, 'let') or kw(T, i, 'const') or kw(T, i, 'var')) and T.k[i + 1] == 'id' then
|
|
330
|
+
elseif language == 'javascript' or language == 'typescript' or language == 'kotlin' then
|
|
331
|
+
if (kw(T, i, 'let') or kw(T, i, 'const') or kw(T, i, 'var') or kw(T, i, 'val')) and T.k[i + 1] == 'id' then
|
|
316
332
|
local k, type = i + 2, nil
|
|
317
333
|
if is(T, k, ':') then
|
|
318
334
|
local e = k + 1
|
|
319
|
-
while e <= b and not is(T, e, '=') and not is(T, e, ';') and not is(T, e, ',')
|
|
335
|
+
while e <= b and not is(T, e, '=') and not is(T, e, ';') and not is(T, e, ',')
|
|
336
|
+
and not (language == 'kotlin' and e > k + 1 and T:line(e) > T:eline(e - 1)) do e = e + 1 end
|
|
320
337
|
type = span(T, k + 1, e - 1); k = e
|
|
321
338
|
end
|
|
322
339
|
add(i + 1, type, is(T, k, '=') and k + 1 or nil)
|
|
@@ -381,8 +398,10 @@ local function module_aliases(T, language)
|
|
|
381
398
|
local out = {}
|
|
382
399
|
for i = 1, T.n do
|
|
383
400
|
if language == 'lua' and kw(T, i, 'local') and T.k[i + 1] == 'id' and is(T, i + 2, '=') then
|
|
384
|
-
local value = initializer(T, i + 3, math.min(T.n, i +
|
|
385
|
-
if value.module then
|
|
401
|
+
local value = initializer(T, i + 3, math.min(T.n, i + 8), 'lua')
|
|
402
|
+
if value.module then
|
|
403
|
+
out[text_of(T, i + 1)] = { kind = value.module_kind or 'require', path = value.module }
|
|
404
|
+
end
|
|
386
405
|
elseif language == 'python' and kw(T, i, 'import') then
|
|
387
406
|
local from, k = nil, i - 1
|
|
388
407
|
while k >= 1 and T.k[k] ~= 'nl' and not kw(T, k, 'from') do k = k - 1 end
|
|
@@ -470,7 +489,7 @@ function Completion:types(name, f)
|
|
|
470
489
|
for _, id in ipairs(found) do
|
|
471
490
|
local q = self.V.nodes[id].qualified
|
|
472
491
|
local family = graph.family(self.V.files[self.V.node_file[id]].language)
|
|
473
|
-
for _, cid in ipairs(self.V.by_name[name] or {}) do
|
|
492
|
+
for _, cid in ipairs(self.V.by_name[self.V.nodes[id].name] or {}) do
|
|
474
493
|
local c = self.V.nodes[cid]
|
|
475
494
|
if not set[cid] and accept[c.kind] and c.qualified == q
|
|
476
495
|
and graph.family(self.V.files[self.V.node_file[cid]].language) == family then
|
|
@@ -590,19 +609,43 @@ function Completion:assigned(name)
|
|
|
590
609
|
end
|
|
591
610
|
|
|
592
611
|
-- Top-level members of module files.
|
|
593
|
-
function Completion:module_members(files)
|
|
612
|
+
function Completion:module_members(files, module_name)
|
|
594
613
|
local out = {}
|
|
595
614
|
for _, g in ipairs(files) do
|
|
596
615
|
if self:expired() then break end
|
|
597
616
|
local rec = self.V.files[g]
|
|
598
617
|
local language = rec.language
|
|
618
|
+
local native = rec.foreign_exports and rec.foreign_exports[self.language]
|
|
619
|
+
if native then
|
|
620
|
+
for name, n in pairs(native[module_name] or {}) do
|
|
621
|
+
local node = rec.nodes[n]
|
|
622
|
+
out[#out + 1] = { name = name, kind = node.kind, node = node, file = g }
|
|
623
|
+
end
|
|
624
|
+
end
|
|
599
625
|
local exported
|
|
626
|
+
local lua_contract = language == 'lua' and rec.lua_exports and next(rec.lua_exports) ~= nil
|
|
600
627
|
if language == 'lua' then
|
|
601
|
-
-- The
|
|
602
|
-
|
|
603
|
-
if
|
|
604
|
-
|
|
605
|
-
|
|
628
|
+
-- The verified module contract names the returned table's members.
|
|
629
|
+
exported = rec.lua_owner
|
|
630
|
+
if not exported and not lua_contract then
|
|
631
|
+
local _, T = full(self.V, g)
|
|
632
|
+
if T then
|
|
633
|
+
for i = T.n - 1, 1, -1 do
|
|
634
|
+
if kw(T, i, 'return') and T.k[i + 1] == 'id' then exported = text_of(T, i + 1); break end
|
|
635
|
+
end
|
|
636
|
+
end
|
|
637
|
+
end
|
|
638
|
+
if not exported and lua_contract then
|
|
639
|
+
-- Return-less `__exports` contract: the recorded exports are the members.
|
|
640
|
+
for name, n in pairs(rec.lua_exports) do
|
|
641
|
+
local node = rec.nodes[n]
|
|
642
|
+
if node then out[#out + 1] = { name = name, kind = node.kind, node = node, file = g } end
|
|
643
|
+
end
|
|
644
|
+
elseif not exported then
|
|
645
|
+
for _, node in ipairs(rec.nodes) do
|
|
646
|
+
if not node.parent and not node.qualified:find('[%.:]') then
|
|
647
|
+
out[#out + 1] = { name = node.name, kind = node.kind, node = node, file = g }
|
|
648
|
+
end
|
|
606
649
|
end
|
|
607
650
|
end
|
|
608
651
|
end
|
|
@@ -610,7 +653,8 @@ function Completion:module_members(files)
|
|
|
610
653
|
if exported then
|
|
611
654
|
local member = node.qualified:match('^' .. exported:gsub('%p', '%%%0') .. '[%.:]([%w_]+)$')
|
|
612
655
|
if member then out[#out + 1] = { name = member, kind = node.kind, node = node, file = g } end
|
|
613
|
-
elseif not node.parent and not node.qualified:find('[%.:]')
|
|
656
|
+
elseif not native and language ~= 'lua' and not node.parent and not node.qualified:find('[%.:]')
|
|
657
|
+
and (language ~= 'go' or node.name:match('^%u')) then
|
|
614
658
|
out[#out + 1] = { name = node.name, kind = node.kind, node = node, file = g }
|
|
615
659
|
end
|
|
616
660
|
end
|
|
@@ -662,6 +706,7 @@ function Completion:self_types()
|
|
|
662
706
|
if owner then return { self.V.id_of[self.f][owner] } end
|
|
663
707
|
if not fn then return {} end
|
|
664
708
|
local node = self.rec.nodes[fn]
|
|
709
|
+
if self.language == 'kotlin' and node.receiver then return self:types(normalize(node.receiver)) end
|
|
665
710
|
local prefix = node.qualified:match('^(.*)::[%w_]+$') or node.qualified:match('^(.*)[%.:][%w_]+$')
|
|
666
711
|
if not prefix and self.language == 'go' then
|
|
667
712
|
prefix = (node.sig or ''):match('^func%s*%(%s*[%w_]*%s*%*?%s*([%w_]+)')
|
|
@@ -727,7 +772,7 @@ function Completion:receiver(item, depth)
|
|
|
727
772
|
local entry = find_local(self:locals(), name)
|
|
728
773
|
if entry then
|
|
729
774
|
if entry.module then
|
|
730
|
-
return { modules = import_files(self.V, self.f, { kind = 'require', path = entry.module }) }
|
|
775
|
+
return { modules = import_files(self.V, self.f, { kind = entry.module_kind or 'require', path = entry.module }), module_name = entry.module }
|
|
731
776
|
elseif entry.type then
|
|
732
777
|
local ids = self:types(entry.type)
|
|
733
778
|
if #ids > 0 then return { types = ids } end
|
|
@@ -741,7 +786,11 @@ function Completion:receiver(item, depth)
|
|
|
741
786
|
local alias = self.aliases[name]
|
|
742
787
|
if alias then
|
|
743
788
|
local files = import_files(self.V, self.f, alias)
|
|
744
|
-
if #files > 0 then return { modules = files } end
|
|
789
|
+
if #files > 0 then return { modules = files, module_name = alias.path } end
|
|
790
|
+
end
|
|
791
|
+
if self.language == 'lua' and not entry then
|
|
792
|
+
local files = require('codeoutline.lua_bindings').native_modules(self.V, name, self.V.js_context.lua)
|
|
793
|
+
if #files > 0 then return { modules = files, module_name = name } end
|
|
745
794
|
end
|
|
746
795
|
local ids = self:types(name)
|
|
747
796
|
if #ids > 0 then return { types = ids, static = true } end
|
|
@@ -753,7 +802,7 @@ end
|
|
|
753
802
|
|
|
754
803
|
function Completion:entries(target)
|
|
755
804
|
if not target then return {} end
|
|
756
|
-
if target.modules then return self:module_members(target.modules) end
|
|
805
|
+
if target.modules then return self:module_members(target.modules, target.module_name) end
|
|
757
806
|
if target.owner then
|
|
758
807
|
local out = target.local_only and {} or self:owned(target.owner, graph.family(self.language))
|
|
759
808
|
for _, entry in ipairs(self:assigned(target.owner)) do out[#out + 1] = entry end
|
|
@@ -809,8 +858,9 @@ end
|
|
|
809
858
|
|
|
810
859
|
local function item_for(entry, language)
|
|
811
860
|
local node = entry.node
|
|
861
|
+
local foreign = node and require('codeoutline.foreign').signature(node, language, entry.name)
|
|
812
862
|
return { label = entry.name, kind = ITEM[entry.kind] or 6,
|
|
813
|
-
detail = node and (node.sig or (node.type and (node.type .. ' ' .. entry.name))) or entry.detail }
|
|
863
|
+
detail = foreign and foreign.label or (node and (node.sig or (node.type and (node.type .. ' ' .. entry.name))) or entry.detail) }
|
|
814
864
|
end
|
|
815
865
|
|
|
816
866
|
-- Completion items at the cursor of req.uri.
|
|
@@ -854,10 +904,31 @@ function M.complete(req)
|
|
|
854
904
|
end
|
|
855
905
|
for alias in pairs(self.aliases) do entries[#entries + 1] = { name = alias, kind = 'namespace', detail = 'module' } end
|
|
856
906
|
for _, node in ipairs(self.rec.nodes) do
|
|
857
|
-
if not node.parent and not node.qualified:find('[%.:]') then
|
|
907
|
+
if not node.parent and (self.language == 'kotlin' or not node.qualified:find('[%.:]')) then
|
|
858
908
|
entries[#entries + 1] = { name = node.name, kind = node.kind, node = node, file = f }
|
|
859
909
|
end
|
|
860
910
|
end
|
|
911
|
+
if self.language == 'kotlin' then
|
|
912
|
+
local direct = navigation.deps(V, f)
|
|
913
|
+
for g in pairs(direct) do
|
|
914
|
+
if self:expired() then break end
|
|
915
|
+
local rec = V.files[g]
|
|
916
|
+
if rec.language == 'kotlin' then
|
|
917
|
+
for _, node in ipairs(rec.nodes) do
|
|
918
|
+
local visible = not node.parent and rec.package == self.rec.package and node.name or nil
|
|
919
|
+
for _, imp in ipairs(self.rec.imports) do
|
|
920
|
+
if node.qualified == imp.path then visible = imp.alias or node.name
|
|
921
|
+
elseif imp.path:sub(-2) == '.*' and graph.owner(node.qualified) == imp.path:sub(1, -3) then
|
|
922
|
+
visible = node.name
|
|
923
|
+
end
|
|
924
|
+
end
|
|
925
|
+
if visible and not node.static then
|
|
926
|
+
entries[#entries + 1] = { name = visible, kind = node.kind, node = node, file = g }
|
|
927
|
+
end
|
|
928
|
+
end
|
|
929
|
+
end
|
|
930
|
+
end
|
|
931
|
+
end
|
|
861
932
|
if self.language == 'c' or self.language == 'cpp' then
|
|
862
933
|
-- Use actual includes (including transitive headers), not paired
|
|
863
934
|
-- implementation files, whose private symbols are not visible here.
|
|
@@ -122,7 +122,7 @@ function Doc:offset(position)
|
|
|
122
122
|
return p
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
-
local extensions = { javascript = 'js', typescript = 'ts', python = 'py', csharp = 'cs', rust = 'rs', cpp = 'cpp' }
|
|
125
|
+
local extensions = { javascript = 'js', typescript = 'ts', python = 'py', csharp = 'cs', rust = 'rs', cpp = 'cpp', kotlin = 'kt' }
|
|
126
126
|
local function parser_name(doc)
|
|
127
127
|
local name = doc.path or ('document.' .. (extensions[doc.language] or doc.language or 'txt'))
|
|
128
128
|
if not parse.language(name) and doc.language then name = 'document.' .. (extensions[doc.language] or doc.language) end
|