@codua/codeoutline-win32-x64 0.3.0 → 0.3.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/DISTRIBUTION.md +93 -8
- package/README.md +112 -2
- package/README.zh-CN.md +86 -2
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/editors/codeoutline.vsix +0 -0
- package/editors/zed/extension.toml +15 -0
- package/editors/zed/extension.wasm +0 -0
- package/package.json +1 -1
- package/scripts/codeoutline/agent_config.lua +291 -0
- package/scripts/codeoutline/agent_install.lua +195 -0
- package/scripts/codeoutline/command.lua +110 -9
- package/scripts/codeoutline/completion.lua +66 -20
- package/scripts/codeoutline/editor_install.lua +168 -0
- package/scripts/codeoutline/external_headers.lua +15 -7
- package/scripts/codeoutline/idle_gc.lua +45 -0
- package/scripts/codeoutline/index.lua +3 -1
- package/scripts/codeoutline/index_worker.lua +39 -5
- package/scripts/codeoutline/install_prompt.lua +15 -0
- package/scripts/codeoutline/lsp.lua +44 -4
- package/scripts/codeoutline/lsp_trace.lua +57 -0
- package/scripts/codeoutline/navigation.lua +38 -6
- package/scripts/codeoutline/service.lua +38 -5
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/version.lua +1 -1
- package/scripts/xupgate/client.lua +35 -18
- package/scripts/xupgate/common.lua +2 -2
- package/scripts/xupgate/http_client.lua +6 -1
|
@@ -4,15 +4,28 @@ local scripts = assert(source:match('^(.*)/codeoutline/[^/]+$'))
|
|
|
4
4
|
local install = assert(scripts:match('^(.*)/scripts$'))
|
|
5
5
|
package.path = scripts .. '/?.lua;' .. package.path
|
|
6
6
|
local version = require('codeoutline.version')
|
|
7
|
-
local help = [[CodeOutline -
|
|
7
|
+
local help = [[CodeOutline - code exploration tool and LSP server, powered by Lua
|
|
8
|
+
|
|
9
|
+
Code exploration (code_explore): agents use the MCP tool codeoutline_explore
|
|
10
|
+
to query symbols, line-numbered source, call paths and callers/callees.
|
|
11
|
+
Use codeoutline explore for code exploration from a terminal.
|
|
12
|
+
|
|
13
|
+
LSP server: codeoutline lsp --stdio provides editor symbols, definitions,
|
|
14
|
+
references, hover, call hierarchy, completion and signature help.
|
|
15
|
+
Bundled clients support VS Code, Cursor and Zed. VS Code/Cursor default to
|
|
16
|
+
full navigation; no codeoutline.mode setting is needed for a new installation.
|
|
8
17
|
|
|
9
18
|
One shared background service serves every MCP client. A global npm install
|
|
10
|
-
starts it and registers it to start at login
|
|
11
|
-
|
|
19
|
+
starts it and registers it to start at login; it keeps itself updated.
|
|
20
|
+
Run codeoutline install --yes to detect and register agents globally, or
|
|
21
|
+
codeoutline install --target cursor,claude,codex to select agents explicitly.
|
|
22
|
+
You can also register the URL manually:
|
|
12
23
|
claude mcp add --transport http codeoutline --scope user http://127.0.0.1:19876/mcp
|
|
13
24
|
|
|
14
25
|
Usage:
|
|
15
|
-
codeoutline install [--port PORT]
|
|
26
|
+
codeoutline install [--yes] [--target auto|all|none|IDS] [--location global|local] [--port PORT] [--editors all|none|vscode,cursor,zed]
|
|
27
|
+
codeoutline agents [--list] [--target auto|all|none|IDS] [--location global|local] [--port PORT] [--remove] [--force]
|
|
28
|
+
codeoutline editors [--list] [--editors all|none|vscode,cursor,zed]
|
|
16
29
|
codeoutline uninstall [--port PORT]
|
|
17
30
|
codeoutline daemon [--port PORT]
|
|
18
31
|
codeoutline serve --stdio [--project PATH] [--allow-root PATH ...]
|
|
@@ -27,11 +40,56 @@ Usage:
|
|
|
27
40
|
codeoutline rebuild [--project PATH]
|
|
28
41
|
codeoutline doctor [--project PATH]
|
|
29
42
|
codeoutline update [--check] [--channel CHANNEL]
|
|
43
|
+
codeoutline --help
|
|
30
44
|
codeoutline --version
|
|
31
45
|
|
|
46
|
+
Editor setup:
|
|
47
|
+
npm install -g codeoutline detect apps and confirm each installation
|
|
48
|
+
npm install -g codeoutline --foreground-scripts compatibility fallback for terminal prompts
|
|
49
|
+
codeoutline editors detect and choose afterward
|
|
50
|
+
codeoutline editors --list only show detected editors
|
|
51
|
+
codeoutline editors --editors all install for all detected editors
|
|
52
|
+
codeoutline editors --editors vscode install for VS Code only
|
|
53
|
+
codeoutline editors --editors cursor install for Cursor only
|
|
54
|
+
codeoutline editors --editors zed install for Zed only
|
|
55
|
+
codeoutline editors --editors vscode,cursor install for selected editors
|
|
56
|
+
During global npm setup, confirm each detected AI tool first, then each editor.
|
|
57
|
+
Each install prompt is [Y/n]: Enter or y installs it; n skips just that app.
|
|
58
|
+
EOF skips remaining apps. Explicit target/editor lists bypass the prompts.
|
|
59
|
+
The same setup starts the service; no second codeoutline install is needed.
|
|
60
|
+
The npm launcher reconnects to the terminal for confirmations automatically.
|
|
61
|
+
--foreground-scripts is a fallback for restricted terminal hosts. In CI or
|
|
62
|
+
without a terminal, global npm setup installs all detected integrations. Explicit environment
|
|
63
|
+
selections override these defaults; project-local npm installs skip global setup.
|
|
64
|
+
Reload VS Code/Cursor or restart Zed after installation.
|
|
65
|
+
The LSP server runs separately from the shared MCP HTTP service.
|
|
66
|
+
|
|
67
|
+
Agent MCP setup (independent of LSP clients):
|
|
68
|
+
codeoutline install --yes detect agents, configure MCP, start service
|
|
69
|
+
codeoutline install --target cursor,claude,codex configure selected agents and start service
|
|
70
|
+
codeoutline agents detect and choose agents interactively
|
|
71
|
+
codeoutline agents --list show detection and config paths only
|
|
72
|
+
codeoutline agents --target all configure all detected agents
|
|
73
|
+
codeoutline agents --print codex print config only, without writing files
|
|
74
|
+
codeoutline agents --target cursor --remove remove only CodeOutline's MCP entry
|
|
75
|
+
Targets: claude, cursor, codex, gemini, opencode, hermes, kiro, antigravity,
|
|
76
|
+
copilot-vscode, copilot-cli, copilot-jetbrains.
|
|
77
|
+
all and auto select detected targets; comma-separated ids select explicitly.
|
|
78
|
+
Use --location local [--project PATH] for project scope where supported;
|
|
79
|
+
Antigravity, Hermes, Copilot CLI and Copilot JetBrains support global scope only.
|
|
80
|
+
--port changes the local endpoint (default 19876); agents only edits config,
|
|
81
|
+
while install also starts the service. Restart agents after configuration.
|
|
82
|
+
Existing unrelated settings are preserved; original files get .codeoutline.bak
|
|
83
|
+
backups. Different existing codeoutline settings require --force to replace.
|
|
84
|
+
CODEOUTLINE_AGENTS=auto|all|none|IDS selects agents for unattended npm installs.
|
|
85
|
+
Without an explicit selection or terminal, global npm configures detected agents.
|
|
86
|
+
Set CODEOUTLINE_AGENTS=none and CODEOUTLINE_EDITORS=none to skip integrations.
|
|
87
|
+
|
|
32
88
|
HTTP options: --allow-host HOST, --allow-origin ORIGIN (repeatable).
|
|
33
89
|
install starts the background service and registers it at login; uninstall
|
|
34
90
|
stops it and removes that entry. daemon is the service itself.
|
|
91
|
+
editors detects VS Code, Cursor and Zed and offers optional LSP client installation.
|
|
92
|
+
Use --editors or CODEOUTLINE_EDITORS to select clients without a prompt.
|
|
35
93
|
Remote HTTP requires CODEOUTLINE_TOKEN (at least 16 bytes).
|
|
36
94
|
Local HTTP without --allow-root serves any project; stdio and remote HTTP
|
|
37
95
|
default to --project or the working directory.
|
|
@@ -62,7 +120,11 @@ local function parse(args)
|
|
|
62
120
|
lsp = { stdio = true, project = true },
|
|
63
121
|
serve = { stdio = true, http = true, project = true, host = true, port = true,
|
|
64
122
|
['allow-root'] = true, ['allow-host'] = true, ['allow-origin'] = true },
|
|
65
|
-
daemon = { port = true }, install = { port = true, npm = true
|
|
123
|
+
daemon = { port = true }, install = { port = true, npm = true, editors = true, target = true, yes = true,
|
|
124
|
+
location = true, project = true, force = true, list = true, print = true, ['print-config'] = true }, uninstall = { port = true },
|
|
125
|
+
agents = { target = true, yes = true, location = true, project = true, port = true, list = true,
|
|
126
|
+
['print-config'] = true, print = true, remove = true, force = true },
|
|
127
|
+
editors = { list = true, editors = true },
|
|
66
128
|
explore = { project = true, query = true, budget = true },
|
|
67
129
|
callers = { project = true, query = true, budget = true, depth = true, ['max-nodes'] = true },
|
|
68
130
|
affected = { project = true, file = true, ['files-from'] = true, budget = true, depth = true, ['max-nodes'] = true },
|
|
@@ -77,7 +139,8 @@ local function parse(args)
|
|
|
77
139
|
local name, value = clean[i]:match('^%-%-([%w-]+)=(.*)$')
|
|
78
140
|
if not name then name = clean[i]:match('^%-%-([%w-]+)$') end
|
|
79
141
|
assert(name and (allowed[command][name] or name == 'help'), 'unknown option: ' .. clean[i])
|
|
80
|
-
local flag = name == 'check' or name == 'stdio' or name == 'http' or name == 'help' or name == 'npm'
|
|
142
|
+
local flag = name == 'check' or name == 'stdio' or name == 'http' or name == 'help' or name == 'npm' or name == 'list'
|
|
143
|
+
or name == 'yes' or name == 'remove' or name == 'force'
|
|
81
144
|
if flag then
|
|
82
145
|
assert(value == nil, '--' .. name .. ' does not take a value')
|
|
83
146
|
value = true
|
|
@@ -158,6 +221,12 @@ local function run()
|
|
|
158
221
|
if command == 'update' then
|
|
159
222
|
return require('codeoutline.updater').run(options.check and 'check' or 'update', options)
|
|
160
223
|
end
|
|
224
|
+
if command == 'editors' then
|
|
225
|
+
return require('codeoutline.editor_install').run(os.getenv('CODEOUTLINE_INITIAL') or install, options)
|
|
226
|
+
end
|
|
227
|
+
if command == 'agents' or command == 'install' and (options.list or options.print or options['print-config']) then
|
|
228
|
+
return require('codeoutline.agent_install').run(options)
|
|
229
|
+
end
|
|
161
230
|
if command == 'daemon' or command == 'install' or command == 'uninstall' then
|
|
162
231
|
local daemon = require('codeoutline.daemon')
|
|
163
232
|
local port = tonumber(options.port or daemon.PORT)
|
|
@@ -169,9 +238,34 @@ local function run()
|
|
|
169
238
|
-- npm runs install after every installation; only global ones start a
|
|
170
239
|
-- service, and nothing here may fail the installation.
|
|
171
240
|
local npm = options.npm
|
|
172
|
-
if npm and
|
|
241
|
+
if npm and os.getenv('npm_config_global') ~= 'true' then return 0 end
|
|
173
242
|
local function say(text) io.write(text, '\n'); io.stdout:flush() end
|
|
174
243
|
local status = 0
|
|
244
|
+
local integrations_ok = true
|
|
245
|
+
if command == 'install' then
|
|
246
|
+
-- npm backgrounds lifecycle scripts by default. A normal global
|
|
247
|
+
-- install must still finish setup; explicit selections always win.
|
|
248
|
+
local automatic = npm and os.getenv('CODEOUTLINE_INTERACTIVE') ~= '1'
|
|
249
|
+
if automatic and not options.target and not (os.getenv('CODEOUTLINE_AGENTS') or ''):match('%S') then
|
|
250
|
+
options.target = 'auto'
|
|
251
|
+
end
|
|
252
|
+
if automatic then say('Global npm setup: installing detected integrations by default. Use --foreground-scripts for per-application choices.') end
|
|
253
|
+
options.installing = true
|
|
254
|
+
say('Step 1/2: AI tools - code_explore over MCP')
|
|
255
|
+
local agent_ok, agent_result = pcall(require('codeoutline.agent_install').run, options)
|
|
256
|
+
if not agent_ok then io.stderr:write('codeoutline: ', tostring(agent_result), '\n') end
|
|
257
|
+
if not agent_ok or agent_result ~= 0 then integrations_ok = false end
|
|
258
|
+
if not npm and not agent_ok then return 1 end
|
|
259
|
+
say('Step 2/2: Editors - CodeOutline LSP (Zed, VS Code, Cursor)')
|
|
260
|
+
local editor_selection = options.editors or os.getenv('CODEOUTLINE_EDITORS')
|
|
261
|
+
if editor_selection == '' then editor_selection = nil end
|
|
262
|
+
local editor_options = { editors = editor_selection or (automatic and 'all' or options.yes and 'none' or nil) }
|
|
263
|
+
local ok, result = pcall(require('codeoutline.editor_install').run, os.getenv('CODEOUTLINE_INITIAL') or install, editor_options)
|
|
264
|
+
if not ok then io.stderr:write('codeoutline: ', tostring(result), '\n') end
|
|
265
|
+
if not ok or result ~= 0 then integrations_ok = false end
|
|
266
|
+
if not npm then status = ok and result or 1 end
|
|
267
|
+
if npm and os.getenv('CODEOUTLINE_AUTOSTART') == '0' then return 0 end
|
|
268
|
+
end
|
|
175
269
|
local function attempt(fn, ...)
|
|
176
270
|
local ok, err = pcall(fn, ...)
|
|
177
271
|
if not ok then io.stderr:write('codeoutline: ', tostring(err), '\n'); status = npm and 0 or 1 end
|
|
@@ -200,7 +294,7 @@ local function run()
|
|
|
200
294
|
if os.getenv('CODEOUTLINE_AUTOSTART') ~= '0' then
|
|
201
295
|
local entry = attempt(function()
|
|
202
296
|
-- Only launchers before 0.1.8 leave root inside an update.
|
|
203
|
-
assert(not root:match('/versions
|
|
297
|
+
assert(not root:match('/versions/[^/]+/files$'),
|
|
204
298
|
'cannot register an installed update; run npm install -g codeoutline, or install from the native launcher')
|
|
205
299
|
return daemon.register(root, port)
|
|
206
300
|
end)
|
|
@@ -212,7 +306,14 @@ local function run()
|
|
|
212
306
|
finish(status); return
|
|
213
307
|
end
|
|
214
308
|
daemon.wait(port, 20000, function(listening)
|
|
215
|
-
if listening then
|
|
309
|
+
if listening then
|
|
310
|
+
say('service listening on http://127.0.0.1:' .. port .. '/mcp')
|
|
311
|
+
if integrations_ok then
|
|
312
|
+
say('Setup complete. Restart selected AI tools and reload/restart selected editors.')
|
|
313
|
+
say('No additional codeoutline install command is needed.')
|
|
314
|
+
else
|
|
315
|
+
say('Service started, but some integrations failed; see the errors above.')
|
|
316
|
+
end
|
|
216
317
|
else io.stderr:write('codeoutline: the service did not start; see ', daemon.logs_dir(), '\n')
|
|
217
318
|
if not npm then status = 1 end end
|
|
218
319
|
finish(status)
|
|
@@ -7,13 +7,15 @@
|
|
|
7
7
|
-- and return types (read from signatures), initializers (`new T`, `T(`,
|
|
8
8
|
-- `T{`, `T::new(`), imports and static names, then its members are listed:
|
|
9
9
|
-- children, out-of-line definitions, assigned attributes and base classes.
|
|
10
|
-
--
|
|
10
|
+
-- Short bare prefixes stay local. Longer prefixes are filtered before details
|
|
11
|
+
-- are generated; the editor retains responsibility for ranking. Type
|
|
11
12
|
-- files are reparsed on demand within a time budget; running out of it, or
|
|
12
13
|
-- of items, marks the list incomplete.
|
|
13
14
|
local graph = require('codeoutline.graph')
|
|
14
15
|
local navigation = require('codeoutline.navigation')
|
|
15
16
|
local control = require('codeoutline.control')
|
|
16
|
-
local M = { MAX_ITEMS = 500,
|
|
17
|
+
local M = { MAX_ITEMS = 500, AUTO_MAX_ITEMS = 100, MIN_GLOBAL_PREFIX = 2,
|
|
18
|
+
BUDGET_SECONDS = 0.3, MAX_DEPTH = 6 }
|
|
17
19
|
|
|
18
20
|
local ITEM = { ['function'] = 3, method = 2, constructor = 4, destructor = 4, field = 5, variable = 6,
|
|
19
21
|
property = 10, class = 7, struct = 22, union = 22, record = 22, interface = 8, enum = 13, enum_member = 20,
|
|
@@ -999,11 +1001,45 @@ function M.complete(req)
|
|
|
999
1001
|
self.rust_static = self.language == 'rust' and is_member and text_of(T, op) == '::'
|
|
1000
1002
|
if req.trigger and not is_member then return { items = {} } end
|
|
1001
1003
|
self.fn, self.owner = self:scope()
|
|
1002
|
-
local prefix = t and T.k[t] == 'id' and T.e[t] >= offset
|
|
1004
|
+
local prefix = t and (T.k[t] == 'id' or T.k[t] == 'kw') and T.e[t] >= offset
|
|
1003
1005
|
and doc.source:sub(T.s[t], offset):lower() or ''
|
|
1006
|
+
local narrow = not is_member and #prefix > 0 and #prefix < M.MIN_GLOBAL_PREFIX
|
|
1007
|
+
local limit = not is_member and prefix == '' and M.MAX_ITEMS or M.AUTO_MAX_ITEMS
|
|
1008
|
+
local function matches(name)
|
|
1009
|
+
if prefix == '' then return true end
|
|
1010
|
+
name = name:lower()
|
|
1011
|
+
if #prefix == 1 then return name:sub(1, 1) == prefix end
|
|
1012
|
+
-- Preserve subsequence matching (e.g. fop -> file_open).
|
|
1013
|
+
local at = 1
|
|
1014
|
+
for i = 1, #prefix do
|
|
1015
|
+
local found = name:find(prefix:sub(i, i), at, true)
|
|
1016
|
+
if not found then return false end
|
|
1017
|
+
at = found + 1
|
|
1018
|
+
end
|
|
1019
|
+
return true
|
|
1020
|
+
end
|
|
1004
1021
|
self.aliases = module_aliases(T, self.language)
|
|
1005
1022
|
if self.language == 'go' then self.aliases = require('codeoutline.go_modules').aliases(V, f, V.js_context) end
|
|
1006
1023
|
local entries = {}
|
|
1024
|
+
local added = {}
|
|
1025
|
+
local function add(entry)
|
|
1026
|
+
if not matches(entry.name) or added[entry.name] then return end
|
|
1027
|
+
if #entries >= limit then
|
|
1028
|
+
self.incomplete = true
|
|
1029
|
+
if prefix ~= '' and entry.name:sub(1, #prefix):lower() == prefix then
|
|
1030
|
+
for i = #entries, 1, -1 do
|
|
1031
|
+
if entries[i].name:sub(1, #prefix):lower() ~= prefix then
|
|
1032
|
+
added[entries[i].name] = nil
|
|
1033
|
+
entries[i], added[entry.name] = entry, true
|
|
1034
|
+
break
|
|
1035
|
+
end
|
|
1036
|
+
end
|
|
1037
|
+
end
|
|
1038
|
+
return
|
|
1039
|
+
end
|
|
1040
|
+
added[entry.name] = true
|
|
1041
|
+
entries[#entries + 1] = entry
|
|
1042
|
+
end
|
|
1007
1043
|
if is_member then
|
|
1008
1044
|
local chain = receiver_chain(T, op, member)
|
|
1009
1045
|
local target
|
|
@@ -1034,31 +1070,31 @@ function M.complete(req)
|
|
|
1034
1070
|
end
|
|
1035
1071
|
else
|
|
1036
1072
|
for _, entry in ipairs(self:locals()) do
|
|
1037
|
-
|
|
1038
|
-
detail = entry.type and (entry.type .. ' ' .. entry.name) or nil }
|
|
1073
|
+
add({ name = entry.name, kind = 'variable',
|
|
1074
|
+
detail = entry.type and (entry.type .. ' ' .. entry.name) or nil })
|
|
1039
1075
|
end
|
|
1040
|
-
for alias in pairs(self.aliases) do
|
|
1041
|
-
if self.language == 'csharp' then
|
|
1076
|
+
for alias in pairs(self.aliases) do add({ name = alias, kind = 'namespace', detail = 'module' }) end
|
|
1077
|
+
if not narrow and self.language == 'csharp' then
|
|
1042
1078
|
local bindings = require('codeoutline.csharp_bindings')
|
|
1043
1079
|
for _, entry in ipairs(bindings.usings(V, f, self.offset, V.js_context)) do
|
|
1044
1080
|
local d = entry.directive
|
|
1045
|
-
if d.alias then
|
|
1081
|
+
if d.alias then add({ name = d.alias:gsub('^@', ''), kind = 'class', detail = d.path })
|
|
1046
1082
|
elseif d.static then
|
|
1047
1083
|
local ids = bindings.types(V, entry.file, d.path, d.first, V.js_context,
|
|
1048
1084
|
{ exclude = d.first, no_global = true, scope = d.scope })
|
|
1049
1085
|
for _, member in ipairs(self:members(ids)) do
|
|
1050
1086
|
if TYPES[member.kind] or bindings.static_node(V, member.file, member.node, V.js_context)
|
|
1051
|
-
and bindings.visible_node(V, f, member.file, member.node, self.offset, V.js_context) then
|
|
1087
|
+
and bindings.visible_node(V, f, member.file, member.node, self.offset, V.js_context) then add(member) end
|
|
1052
1088
|
end
|
|
1053
1089
|
end
|
|
1054
1090
|
end
|
|
1055
1091
|
end
|
|
1056
1092
|
for _, node in ipairs(self.rec.nodes) do
|
|
1057
1093
|
if not node.parent and (self.language == 'kotlin' or not node.qualified:find('[%.:]')) then
|
|
1058
|
-
|
|
1094
|
+
add({ name = node.name, kind = node.kind, node = node, file = f })
|
|
1059
1095
|
end
|
|
1060
1096
|
end
|
|
1061
|
-
if self.language == 'kotlin' then
|
|
1097
|
+
if not narrow and self.language == 'kotlin' then
|
|
1062
1098
|
local direct = navigation.deps(V, f)
|
|
1063
1099
|
for g in pairs(direct) do
|
|
1064
1100
|
if self:expired() then break end
|
|
@@ -1073,13 +1109,13 @@ function M.complete(req)
|
|
|
1073
1109
|
end
|
|
1074
1110
|
end
|
|
1075
1111
|
if visible and not node.static then
|
|
1076
|
-
|
|
1112
|
+
add({ name = visible, kind = node.kind, node = node, file = g })
|
|
1077
1113
|
end
|
|
1078
1114
|
end
|
|
1079
1115
|
end
|
|
1080
1116
|
end
|
|
1081
1117
|
end
|
|
1082
|
-
if self.language == 'c' or self.language == 'cpp' then
|
|
1118
|
+
if not narrow and (self.language == 'c' or self.language == 'cpp') then
|
|
1083
1119
|
-- Use actual includes (including transitive headers), not paired
|
|
1084
1120
|
-- implementation files, whose private symbols are not visible here.
|
|
1085
1121
|
local included = navigation.deps(V, f)
|
|
@@ -1090,25 +1126,35 @@ function M.complete(req)
|
|
|
1090
1126
|
if self:expired() then break end
|
|
1091
1127
|
for _, node in ipairs(V.files[g].nodes) do
|
|
1092
1128
|
if not node.parent and not node.qualified:find('[%.:]') then
|
|
1093
|
-
|
|
1129
|
+
add({ name = node.name, kind = node.kind, node = node, file = g })
|
|
1094
1130
|
end
|
|
1095
1131
|
end
|
|
1096
1132
|
end
|
|
1133
|
+
if #prefix >= M.MIN_GLOBAL_PREFIX and not self:expired() then
|
|
1134
|
+
local external, info = navigation.external_completions(V, f, prefix,
|
|
1135
|
+
doc:position(offset).line + 1, function() return self:expired() end, limit)
|
|
1136
|
+
for _, entry in ipairs(external) do
|
|
1137
|
+
add({ name = entry.node.name, kind = entry.node.kind, detail = entry.node.sig })
|
|
1138
|
+
end
|
|
1139
|
+
self.incomplete = self.incomplete or info.truncated
|
|
1140
|
+
end
|
|
1097
1141
|
end
|
|
1098
|
-
if self.language == 'cpp' and not self:expired() then
|
|
1142
|
+
if not narrow and self.language == 'cpp' and not self:expired() then
|
|
1099
1143
|
local owner = self.fn and self.rec.nodes[self.fn] or self.owner and self.rec.nodes[self.owner]
|
|
1100
1144
|
local scope = owner and (CALLABLE[owner.kind] and owner.qualified:match('^(.*)::[^:]+$') or owner.qualified)
|
|
1101
1145
|
for _, entry in ipairs(require('codeoutline.cpp_types').imported_members(V, f, scope, offset, V.js_context,
|
|
1102
|
-
function() return self:expired() end, prefix)) do
|
|
1146
|
+
function() return self:expired() end, prefix)) do add(entry) end
|
|
1103
1147
|
end
|
|
1104
1148
|
if self.owner or self.fn then
|
|
1105
1149
|
local ids = self:self_types()
|
|
1106
|
-
for _, entry in ipairs(self:members(ids)) do
|
|
1150
|
+
for _, entry in ipairs(self:members(ids)) do add(entry) end
|
|
1107
1151
|
end
|
|
1152
|
+
-- Clients must query again when another character opens dependency lookup.
|
|
1153
|
+
if narrow then self.incomplete = true end
|
|
1108
1154
|
end
|
|
1109
1155
|
-- Preserve editor-side fuzzy filtering, but keep prefix matches ahead of
|
|
1110
1156
|
-- unrelated items when a large include tree exceeds the response limit.
|
|
1111
|
-
if prefix ~= '' and #entries >
|
|
1157
|
+
if prefix ~= '' and #entries > limit then
|
|
1112
1158
|
local ordered = {}
|
|
1113
1159
|
for _, entry in ipairs(entries) do
|
|
1114
1160
|
if entry.name:sub(1, #prefix):lower() == prefix then ordered[#ordered + 1] = entry end
|
|
@@ -1120,9 +1166,9 @@ function M.complete(req)
|
|
|
1120
1166
|
end
|
|
1121
1167
|
local items, seen = {}, {}
|
|
1122
1168
|
for _, entry in ipairs(entries) do
|
|
1123
|
-
if not seen[entry.name] then
|
|
1169
|
+
if matches(entry.name) and not seen[entry.name] then
|
|
1124
1170
|
seen[entry.name] = true
|
|
1125
|
-
if #items >=
|
|
1171
|
+
if #items >= limit then self.incomplete = true; break end
|
|
1126
1172
|
items[#items + 1] = item_for(entry, self.language, V, not self:expired())
|
|
1127
1173
|
end
|
|
1128
1174
|
end
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
-- Optional editor clients. Detection, selection and installation stay in Lua.
|
|
2
|
+
local M = {}
|
|
3
|
+
local windows = package.config:sub(1, 1) == '\\'
|
|
4
|
+
local function exists(path) return path and xutils.stat(path).exists end
|
|
5
|
+
local function home() return os.getenv('USERPROFILE') or os.getenv('HOME') or '.' end
|
|
6
|
+
local function platform()
|
|
7
|
+
if windows then return 'windows' end
|
|
8
|
+
local p = assert(io.popen('uname -s'))
|
|
9
|
+
local name = p:read('a'); p:close()
|
|
10
|
+
return name:match('Darwin') and 'darwin' or 'linux'
|
|
11
|
+
end
|
|
12
|
+
local function quote(value)
|
|
13
|
+
assert(not value:find('%z') and not value:find('[\r\n]'), 'unsupported control character in path')
|
|
14
|
+
if windows then
|
|
15
|
+
-- cmd expands these even inside quotes. Refuse rather than execute them.
|
|
16
|
+
assert(not value:find('[%%"!%^&|<>]'), 'unsupported shell character in path')
|
|
17
|
+
return '"' .. value:gsub('/', '\\') .. '"'
|
|
18
|
+
end
|
|
19
|
+
return "'" .. value:gsub("'", "'\\''") .. "'"
|
|
20
|
+
end
|
|
21
|
+
local function first(paths)
|
|
22
|
+
for _, path in ipairs(paths) do if exists(path) then return path end end
|
|
23
|
+
end
|
|
24
|
+
local function on_path(name)
|
|
25
|
+
local separator = windows and ';' or ':'
|
|
26
|
+
for dir in ((os.getenv('PATH') or '') .. separator):gmatch('(.-)' .. separator) do
|
|
27
|
+
dir = dir:gsub('^"(.*)"$', '%1')
|
|
28
|
+
if dir ~= '' then
|
|
29
|
+
local found = first(windows and { dir .. '/' .. name .. '.cmd', dir .. '/' .. name .. '.exe' }
|
|
30
|
+
or { dir .. '/' .. name })
|
|
31
|
+
if found then return found end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
function M.detect()
|
|
37
|
+
local kind, h = platform(), home()
|
|
38
|
+
local vscode, cursor, zed = on_path('code'), on_path('cursor'), on_path('zed') or on_path('zeditor')
|
|
39
|
+
local zed_data
|
|
40
|
+
if kind == 'windows' then
|
|
41
|
+
local local_app = os.getenv('LOCALAPPDATA') or h .. '/AppData/Local'
|
|
42
|
+
local program = os.getenv('ProgramFiles') or 'C:/Program Files'
|
|
43
|
+
vscode = vscode or first({ local_app .. '/Programs/Microsoft VS Code/bin/code.cmd', program .. '/Microsoft VS Code/bin/code.cmd' })
|
|
44
|
+
cursor = cursor or first({ local_app .. '/Programs/cursor/resources/app/bin/cursor.cmd', program .. '/cursor/resources/app/bin/cursor.cmd' })
|
|
45
|
+
zed = zed or first({ local_app .. '/Programs/Zed/bin/zed.exe', local_app .. '/Programs/Zed/zed.exe',
|
|
46
|
+
program .. '/Zed/bin/zed.exe', program .. '/Zed/zed.exe' })
|
|
47
|
+
zed_data = local_app .. '/Zed'
|
|
48
|
+
elseif kind == 'darwin' then
|
|
49
|
+
for _, dir in ipairs({ '/Applications', h .. '/Applications' }) do
|
|
50
|
+
vscode = vscode or first({ dir .. '/Visual Studio Code.app/Contents/Resources/app/bin/code' })
|
|
51
|
+
cursor = cursor or first({ dir .. '/Cursor.app/Contents/Resources/app/bin/cursor' })
|
|
52
|
+
zed = zed or first({ dir .. '/Zed.app/Contents/MacOS/zed' })
|
|
53
|
+
end
|
|
54
|
+
zed_data = h .. '/Library/Application Support/Zed'
|
|
55
|
+
else
|
|
56
|
+
vscode = vscode or first({ '/usr/share/code/bin/code', '/snap/bin/code' })
|
|
57
|
+
cursor = cursor or first({ '/opt/Cursor/resources/app/bin/cursor', h .. '/.local/bin/cursor' })
|
|
58
|
+
zed = zed or first({ h .. '/.local/bin/zed' })
|
|
59
|
+
zed_data = (os.getenv('XDG_DATA_HOME') or h .. '/.local/share') .. '/zed'
|
|
60
|
+
end
|
|
61
|
+
return {
|
|
62
|
+
{ id = 'vscode', name = 'VS Code', command = vscode, detected = vscode ~= nil },
|
|
63
|
+
{ id = 'cursor', name = 'Cursor', command = cursor, detected = cursor ~= nil },
|
|
64
|
+
{ id = 'zed', name = 'Zed', command = zed, data = zed_data, detected = zed ~= nil },
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
local function say(message) io.write(message, '\n'); io.stdout:flush() end
|
|
69
|
+
local function read(path)
|
|
70
|
+
local f = assert(io.open(path, 'rb'), 'missing editor asset ' .. path .. '; use a packaged release or build the editor clients')
|
|
71
|
+
local data = f:read('a'); assert(f:close()); return data
|
|
72
|
+
end
|
|
73
|
+
local function write(path, data)
|
|
74
|
+
assert(xutils.mkdir_p(assert(path:match('^(.*)/[^/]+$'))))
|
|
75
|
+
local f = assert(io.open(path, 'wb')); assert(f:write(data)); assert(f:close())
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
-- Parse before any writes so a typo cannot cause a partial selection.
|
|
79
|
+
function M.select(value, detected)
|
|
80
|
+
value = value:lower():gsub('%s+', '')
|
|
81
|
+
if value == 'y' or value == 'yes' then value = 'all' end
|
|
82
|
+
if value == 'n' or value == 'no' then value = 'none' end
|
|
83
|
+
if value == 'none' or value == '' then return {} end
|
|
84
|
+
local wanted = {}
|
|
85
|
+
if value ~= 'all' then
|
|
86
|
+
assert(not value:match('^,') and not value:match(',$') and not value:find(',,', 1, true), 'invalid editor selection')
|
|
87
|
+
for id in value:gmatch('[^,]+') do
|
|
88
|
+
assert(id == 'vscode' or id == 'cursor' or id == 'zed', 'unknown editor: ' .. id)
|
|
89
|
+
wanted[id] = true
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
local selected = {}
|
|
93
|
+
for _, editor in ipairs(detected) do
|
|
94
|
+
if value == 'all' and editor.detected or wanted[editor.id] then
|
|
95
|
+
assert(editor.detected, editor.name .. ' not detected; add its CLI to PATH and retry')
|
|
96
|
+
selected[#selected + 1] = editor
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
return selected
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
function M.run(root, options)
|
|
103
|
+
options = options or {}
|
|
104
|
+
local value = options.editors or os.getenv('CODEOUTLINE_EDITORS')
|
|
105
|
+
if value == '' then value = nil end
|
|
106
|
+
-- Opting out should work even on machines without editor CLIs.
|
|
107
|
+
if value and value:lower() == 'none' and not options.list then return 0 end
|
|
108
|
+
local editors = M.detect()
|
|
109
|
+
if options.list then
|
|
110
|
+
for _, editor in ipairs(editors) do
|
|
111
|
+
say(editor.id .. ': ' .. (editor.detected and ('detected (' .. (editor.command or editor.data) .. ')') or 'not detected'))
|
|
112
|
+
end
|
|
113
|
+
return 0
|
|
114
|
+
end
|
|
115
|
+
if not value then
|
|
116
|
+
if os.getenv('CODEOUTLINE_INTERACTIVE') ~= '1' then
|
|
117
|
+
say('Optional LSP clients: run codeoutline editors to choose, or codeoutline editors --editors all.')
|
|
118
|
+
return 0
|
|
119
|
+
end
|
|
120
|
+
local available = {}
|
|
121
|
+
for _, editor in ipairs(editors) do
|
|
122
|
+
if editor.detected then available[#available + 1] = editor end
|
|
123
|
+
end
|
|
124
|
+
if #available == 0 then say('No supported editors detected. Add the editor CLI to PATH and retry.'); return 0 end
|
|
125
|
+
say('Detected editors: ' .. #available .. '. Confirm each editor; Enter installs it.')
|
|
126
|
+
local chosen = {}
|
|
127
|
+
for _, editor in ipairs(available) do
|
|
128
|
+
local answer = require('codeoutline.install_prompt').confirm('Install CodeOutline LSP for ' .. editor.name .. ' (' .. editor.id .. ')?', true)
|
|
129
|
+
if answer == nil then break end
|
|
130
|
+
if answer then chosen[#chosen + 1] = editor.id end
|
|
131
|
+
end
|
|
132
|
+
value = #chosen > 0 and table.concat(chosen, ',') or 'none'
|
|
133
|
+
end
|
|
134
|
+
local selected = M.select(value, editors)
|
|
135
|
+
local status = 0
|
|
136
|
+
for _, editor in ipairs(selected) do
|
|
137
|
+
local ok, err = pcall(function()
|
|
138
|
+
if editor.id == 'zed' then
|
|
139
|
+
-- Read both assets before touching the installed extension.
|
|
140
|
+
local manifest = read(root .. '/editors/zed/extension.toml')
|
|
141
|
+
local wasm = read(root .. '/editors/zed/extension.wasm')
|
|
142
|
+
local target = editor.data .. '/extensions/installed/codeoutline'
|
|
143
|
+
assert(not exists(editor.data .. '/extensions/development/codeoutline'), 'Zed dev extension exists; remove it before installing the packaged client')
|
|
144
|
+
if exists(target) then
|
|
145
|
+
local actual = assert(xutils.realpath(target)):gsub('\\', '/'):gsub('/+$', '')
|
|
146
|
+
local expected = assert(xutils.realpath(editor.data .. '/extensions/installed')):gsub('\\', '/'):gsub('/+$', '') .. '/codeoutline'
|
|
147
|
+
if windows then actual, expected = actual:lower(), expected:lower() end
|
|
148
|
+
assert(actual == expected, 'Zed extension is linked to another directory; remove the dev extension before installing the packaged client')
|
|
149
|
+
end
|
|
150
|
+
write(target .. '/extension.wasm', wasm)
|
|
151
|
+
write(target .. '/extension.toml', manifest)
|
|
152
|
+
say('Installed CodeOutline for Zed. Restart Zed to load the client.')
|
|
153
|
+
else
|
|
154
|
+
local vsix = root .. '/editors/codeoutline.vsix'
|
|
155
|
+
assert(exists(vsix), 'missing editor asset ' .. vsix .. '; use a packaged release or build the editor clients')
|
|
156
|
+
local command = quote(editor.command) .. ' --install-extension ' .. quote(vsix) .. ' --force'
|
|
157
|
+
if windows then command = '"' .. command .. '"' end
|
|
158
|
+
local result = os.execute(command)
|
|
159
|
+
assert(result == true or result == 0, editor.name .. ' extension installation failed')
|
|
160
|
+
say('Installed CodeOutline for ' .. editor.name .. '. Reload the editor window if it is open.')
|
|
161
|
+
end
|
|
162
|
+
end)
|
|
163
|
+
if not ok then io.stderr:write('codeoutline: ', tostring(err), '\n'); status = 1 end
|
|
164
|
+
end
|
|
165
|
+
return status
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
return M
|
|
@@ -53,9 +53,10 @@ local function read(file, info)
|
|
|
53
53
|
end
|
|
54
54
|
return entry
|
|
55
55
|
end
|
|
56
|
-
local function declarations(entry, name, type_site)
|
|
56
|
+
local function declarations(entry, name, type_site, prefix)
|
|
57
57
|
local escaped = name:gsub('([^%w])', '%%%1')
|
|
58
|
-
|
|
58
|
+
local source = prefix and entry.source:lower() or entry.source
|
|
59
|
+
if not source:find('%f[%w_$]' .. escaped .. (prefix and '' or '%f[^%w_$]')) then return {} end
|
|
59
60
|
if not entry.nodes then
|
|
60
61
|
local rec = require('codeoutline.parse').parse(entry.file, entry.source, { type_uses = false, analysis = false })
|
|
61
62
|
entry.nodes = rec and rec.nodes or {}
|
|
@@ -69,7 +70,8 @@ local function declarations(entry, name, type_site)
|
|
|
69
70
|
end
|
|
70
71
|
local result = {}
|
|
71
72
|
for _, node in ipairs(entry.nodes) do
|
|
72
|
-
if node.name
|
|
73
|
+
if (prefix and node.name:sub(1, #name):lower() == name or not prefix and node.name == name)
|
|
74
|
+
and node.qualified == node.name and not node.parent and node.name_start
|
|
73
75
|
and (type_site and require('codeoutline.type_references').kinds[node.kind]
|
|
74
76
|
or not type_site and (node.kind == 'prototype' or node.kind == 'function')) then
|
|
75
77
|
result[#result + 1] = { node = node, file = entry.file, source = entry.source,
|
|
@@ -79,7 +81,7 @@ local function declarations(entry, name, type_site)
|
|
|
79
81
|
return result
|
|
80
82
|
end
|
|
81
83
|
|
|
82
|
-
function M.find(G, f, site, ctx, system_directories)
|
|
84
|
+
function M.find(G, f, site, ctx, system_directories, completion)
|
|
83
85
|
local info = { files = 0, bytes = 0, truncated = false }
|
|
84
86
|
local type_site = site and site.kind == 'type' and site.reason == 'unresolved type'
|
|
85
87
|
and not site.recv and site.evidence and site.evidence.written == site.name
|
|
@@ -91,6 +93,7 @@ function M.find(G, f, site, ctx, system_directories)
|
|
|
91
93
|
local defaults, started = nil, xtimer.now_ms()
|
|
92
94
|
local function expired()
|
|
93
95
|
control.check()
|
|
96
|
+
if completion and completion.expired() then info.truncated = true; return true end
|
|
94
97
|
if xtimer.now_ms() - started >= M.TIME_MS then info.truncated = true; return true end
|
|
95
98
|
return false
|
|
96
99
|
end
|
|
@@ -163,10 +166,15 @@ function M.find(G, f, site, ctx, system_directories)
|
|
|
163
166
|
local target = headers[hi]; hi = hi + 1
|
|
164
167
|
local entry = read(target.file, info)
|
|
165
168
|
if entry then
|
|
166
|
-
local found = declarations(entry, site.name, type_site)
|
|
169
|
+
local found = declarations(entry, site.name, type_site, completion ~= nil)
|
|
167
170
|
for _, hit in ipairs(found) do
|
|
168
|
-
if
|
|
169
|
-
|
|
171
|
+
if completion then
|
|
172
|
+
if #best >= completion.limit then info.truncated = true; return best, info end
|
|
173
|
+
best[#best + 1] = hit
|
|
174
|
+
else
|
|
175
|
+
if hit.declaration then return { hit }, info end
|
|
176
|
+
if #best < 8 then best[#best + 1] = hit end
|
|
177
|
+
end
|
|
170
178
|
end
|
|
171
179
|
for _, imp in ipairs(entry.imports) do add(locate(imp, target.roots, target.file), target.roots) end
|
|
172
180
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
-- One pending native timer per worker. Timer callbacks run on the same Lua
|
|
2
|
+
-- state: they advance one GC step only while foreground work is absent.
|
|
3
|
+
-- The owning worker initializes xtimer in __init before scheduling requests.
|
|
4
|
+
local M = {}
|
|
5
|
+
|
|
6
|
+
function M.new(opts)
|
|
7
|
+
local timer = opts.timer or xtimer
|
|
8
|
+
local handle, wanted, start_cycle, closed = nil, false, false, false
|
|
9
|
+
local generation = 0
|
|
10
|
+
local arm
|
|
11
|
+
local function cancel()
|
|
12
|
+
generation = generation + 1
|
|
13
|
+
if handle then timer.del(handle); handle = nil end
|
|
14
|
+
end
|
|
15
|
+
arm = function()
|
|
16
|
+
cancel()
|
|
17
|
+
if closed or not wanted then return end
|
|
18
|
+
local token = generation
|
|
19
|
+
handle = timer.add(opts.delay_ms, function()
|
|
20
|
+
if closed or token ~= generation then return end
|
|
21
|
+
handle = nil
|
|
22
|
+
-- A suspended foreground coroutine also owns its resident state.
|
|
23
|
+
-- Its eventual reply will rearm us; do not poll while it waits.
|
|
24
|
+
if opts.busy() then return end
|
|
25
|
+
if start_cycle then opts.request(); start_cycle = false end
|
|
26
|
+
wanted = opts.step()
|
|
27
|
+
if wanted then arm() end
|
|
28
|
+
end, 1)
|
|
29
|
+
end
|
|
30
|
+
local self = {}
|
|
31
|
+
function self.schedule()
|
|
32
|
+
if closed then return end
|
|
33
|
+
wanted, start_cycle = true, true
|
|
34
|
+
arm()
|
|
35
|
+
end
|
|
36
|
+
function self.suspend() cancel() end
|
|
37
|
+
function self.pending() return wanted end
|
|
38
|
+
function self.close()
|
|
39
|
+
closed, wanted, start_cycle = true, false, false
|
|
40
|
+
cancel()
|
|
41
|
+
end
|
|
42
|
+
return self
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
return M
|
|
@@ -112,9 +112,11 @@ function M.open(root, opts)
|
|
|
112
112
|
local max_bytes = opts.max_file_bytes or M.MAX_FILE_BYTES
|
|
113
113
|
assert(type(max_bytes) == 'number' and max_bytes >= 1 and max_bytes < math.huge and max_bytes % 1 == 0,
|
|
114
114
|
'max_file_bytes must be a positive integer')
|
|
115
|
+
local cache_override = os.getenv('CODEOUTLINE_MEMORY_CACHE')
|
|
116
|
+
if cache_override == '' then cache_override = nil end
|
|
115
117
|
local self = setmetatable({
|
|
116
118
|
root = norm(root),
|
|
117
|
-
cache_path = opts.cache_path and norm(opts.cache_path) or cache_path_for(root),
|
|
119
|
+
cache_path = cache_override and norm(cache_override) or (opts.cache_path and norm(opts.cache_path) or cache_path_for(root)),
|
|
118
120
|
max_bytes = max_bytes,
|
|
119
121
|
lister = opts.lister, -- 'rg' | 'walk' | nil (rg when it runs here)
|
|
120
122
|
files = {}, -- rel path -> record
|