@codua/codeoutline-win32-x64 0.3.0 → 0.3.2

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.
@@ -4,16 +4,29 @@ 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 - Lua code indexing for MCP and LSP
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 (codeoutline install does the same
11
- for other installations); it keeps itself updated. Register its URL once:
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]
16
- codeoutline uninstall [--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]
29
+ codeoutline uninstall [--port PORT] [--project PATH] [--service-only] [--purge]
17
30
  codeoutline daemon [--port PORT]
18
31
  codeoutline serve --stdio [--project PATH] [--allow-root PATH ...]
19
32
  codeoutline lsp --stdio [--project PATH]
@@ -27,11 +40,60 @@ 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 automatically configure detected apps
48
+ npm install -g codeoutline --foreground-scripts confirm each detected application
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
+ Use --foreground-scripts to give installation prompts access to terminal input.
61
+ With npm's default background scripts, 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
- install starts the background service and registers it at login; uninstall
34
- stops it and removes that entry. daemon is the service itself.
89
+ install starts the background service and registers it at login. uninstall
90
+ stops it, removes its login entry, user-level MCP registrations and editor clients.
91
+ --project also removes MCP entries from that project; --service-only keeps integrations.
92
+ --purge additionally removes ~/.codeoutline data after cleanup succeeds.
93
+ Run uninstall before npm uninstall -g codeoutline; npm has no uninstall hooks.
94
+ daemon is the service itself.
95
+ editors detects VS Code, Cursor and Zed and offers optional LSP client installation.
96
+ Use --editors or CODEOUTLINE_EDITORS to select clients without a prompt.
35
97
  Remote HTTP requires CODEOUTLINE_TOKEN (at least 16 bytes).
36
98
  Local HTTP without --allow-root serves any project; stdio and remote HTTP
37
99
  default to --project or the working directory.
@@ -62,7 +124,12 @@ local function parse(args)
62
124
  lsp = { stdio = true, project = true },
63
125
  serve = { stdio = true, http = true, project = true, host = true, port = true,
64
126
  ['allow-root'] = true, ['allow-host'] = true, ['allow-origin'] = true },
65
- daemon = { port = true }, install = { port = true, npm = true }, uninstall = { port = true },
127
+ daemon = { port = true }, install = { port = true, npm = true, editors = true, target = true, yes = true,
128
+ location = true, project = true, force = true, list = true, print = true, ['print-config'] = true },
129
+ uninstall = { port = true, project = true, ['service-only'] = true, purge = true },
130
+ agents = { target = true, yes = true, location = true, project = true, port = true, list = true,
131
+ ['print-config'] = true, print = true, remove = true, force = true },
132
+ editors = { list = true, editors = true },
66
133
  explore = { project = true, query = true, budget = true },
67
134
  callers = { project = true, query = true, budget = true, depth = true, ['max-nodes'] = true },
68
135
  affected = { project = true, file = true, ['files-from'] = true, budget = true, depth = true, ['max-nodes'] = true },
@@ -77,7 +144,8 @@ local function parse(args)
77
144
  local name, value = clean[i]:match('^%-%-([%w-]+)=(.*)$')
78
145
  if not name then name = clean[i]:match('^%-%-([%w-]+)$') end
79
146
  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'
147
+ local flag = name == 'check' or name == 'stdio' or name == 'http' or name == 'help' or name == 'npm' or name == 'list'
148
+ or name == 'yes' or name == 'remove' or name == 'force' or name == 'service-only' or name == 'purge'
81
149
  if flag then
82
150
  assert(value == nil, '--' .. name .. ' does not take a value')
83
151
  value = true
@@ -158,6 +226,12 @@ local function run()
158
226
  if command == 'update' then
159
227
  return require('codeoutline.updater').run(options.check and 'check' or 'update', options)
160
228
  end
229
+ if command == 'editors' then
230
+ return require('codeoutline.editor_install').run(os.getenv('CODEOUTLINE_INITIAL') or install, options)
231
+ end
232
+ if command == 'agents' or command == 'install' and (options.list or options.print or options['print-config']) then
233
+ return require('codeoutline.agent_install').run(options)
234
+ end
161
235
  if command == 'daemon' or command == 'install' or command == 'uninstall' then
162
236
  local daemon = require('codeoutline.daemon')
163
237
  local port = tonumber(options.port or daemon.PORT)
@@ -169,9 +243,34 @@ local function run()
169
243
  -- npm runs install after every installation; only global ones start a
170
244
  -- service, and nothing here may fail the installation.
171
245
  local npm = options.npm
172
- if npm and (os.getenv('npm_config_global') ~= 'true' or os.getenv('CODEOUTLINE_AUTOSTART') == '0') then return 0 end
246
+ if npm and os.getenv('npm_config_global') ~= 'true' then return 0 end
173
247
  local function say(text) io.write(text, '\n'); io.stdout:flush() end
174
248
  local status = 0
249
+ local integrations_ok = true
250
+ if command == 'install' then
251
+ -- npm backgrounds lifecycle scripts by default. A normal global
252
+ -- install must still finish setup; explicit selections always win.
253
+ local automatic = npm and os.getenv('CODEOUTLINE_INTERACTIVE') ~= '1'
254
+ if automatic and not options.target and not (os.getenv('CODEOUTLINE_AGENTS') or ''):match('%S') then
255
+ options.target = 'auto'
256
+ end
257
+ if automatic then say('Global npm setup: installing detected integrations by default. Use --foreground-scripts for per-application choices.') end
258
+ options.installing = true
259
+ say('Step 1/2: AI tools - code_explore over MCP')
260
+ local agent_ok, agent_result = pcall(require('codeoutline.agent_install').run, options)
261
+ if not agent_ok then io.stderr:write('codeoutline: ', tostring(agent_result), '\n') end
262
+ if not agent_ok or agent_result ~= 0 then integrations_ok = false end
263
+ if not npm and not agent_ok then return 1 end
264
+ say('Step 2/2: Editors - CodeOutline LSP (Zed, VS Code, Cursor)')
265
+ local editor_selection = options.editors or os.getenv('CODEOUTLINE_EDITORS')
266
+ if editor_selection == '' then editor_selection = nil end
267
+ local editor_options = { editors = editor_selection or (automatic and 'all' or options.yes and 'none' or nil) }
268
+ local ok, result = pcall(require('codeoutline.editor_install').run, os.getenv('CODEOUTLINE_INITIAL') or install, editor_options)
269
+ if not ok then io.stderr:write('codeoutline: ', tostring(result), '\n') end
270
+ if not ok or result ~= 0 then integrations_ok = false end
271
+ if not npm then status = ok and result or 1 end
272
+ if npm and os.getenv('CODEOUTLINE_AUTOSTART') == '0' then return 0 end
273
+ end
175
274
  local function attempt(fn, ...)
176
275
  local ok, err = pcall(fn, ...)
177
276
  if not ok then io.stderr:write('codeoutline: ', tostring(err), '\n'); status = npm and 0 or 1 end
@@ -193,14 +292,34 @@ local function run()
193
292
  for _, removed in ipairs(attempt(daemon.unregister) or {}) do say('removed login entry ' .. removed) end
194
293
  daemon.stop(port, 10000, function(stopped)
195
294
  say(stopped and 'service on port ' .. port .. ' stopped' or 'service on port ' .. port .. ' is still running')
196
- finish(stopped and status or 1)
295
+ if not stopped then status = 1 end
296
+ if not options['service-only'] then
297
+ if attempt(function() return require('codeoutline.agent_install').remove(options) end) ~= 0 then status = 1 end
298
+ if attempt(function() return require('codeoutline.editor_install').remove() end) ~= 0 then status = 1 end
299
+ end
300
+ if options.purge and status == 0 then
301
+ attempt(function()
302
+ local path = daemon.state_dir()
303
+ if xutils.stat(path).exists then
304
+ local actual = assert(xutils.realpath(path)):gsub('\\', '/'):gsub('/+$', '')
305
+ local expected = assert(xutils.realpath(path .. '/..')):gsub('\\', '/'):gsub('/+$', '') .. '/.codeoutline'
306
+ if package.config:sub(1, 1) == '\\' then actual, expected = actual:lower(), expected:lower() end
307
+ assert(actual == expected, 'refusing to purge a linked state directory')
308
+ assert(not install:lower():find(actual:lower() .. '/', 1, true), 'run uninstall from the initial installation before purging updates')
309
+ assert(xutils.rmtree(path) and not xutils.stat(path).exists, 'state files are busy; close CodeOutline clients and retry')
310
+ end
311
+ say('removed CodeOutline user data; custom cache/update directories require separate cleanup')
312
+ end)
313
+ end
314
+ if status == 0 then say('Cleanup completed. Run npm uninstall -g codeoutline to remove the npm package.') end
315
+ finish(status)
197
316
  end)
198
317
  return
199
318
  end
200
319
  if os.getenv('CODEOUTLINE_AUTOSTART') ~= '0' then
201
320
  local entry = attempt(function()
202
321
  -- Only launchers before 0.1.8 leave root inside an update.
203
- assert(not root:match('/versions/%x+/files$'),
322
+ assert(not root:match('/versions/[^/]+/files$'),
204
323
  'cannot register an installed update; run npm install -g codeoutline, or install from the native launcher')
205
324
  return daemon.register(root, port)
206
325
  end)
@@ -212,7 +331,14 @@ local function run()
212
331
  finish(status); return
213
332
  end
214
333
  daemon.wait(port, 20000, function(listening)
215
- if listening then say('service listening on http://127.0.0.1:' .. port .. '/mcp')
334
+ if listening then
335
+ say('service listening on http://127.0.0.1:' .. port .. '/mcp')
336
+ if integrations_ok then
337
+ say('Setup complete. Restart selected AI tools and reload/restart selected editors.')
338
+ say('No additional codeoutline install command is needed.')
339
+ else
340
+ say('Service started, but some integrations failed; see the errors above.')
341
+ end
216
342
  else io.stderr:write('codeoutline: the service did not start; see ', daemon.logs_dir(), '\n')
217
343
  if not npm then status = 1 end end
218
344
  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
- -- Items are unsorted and unfiltered by case; the editor filters them. Type
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, BUDGET_SECONDS = 0.3, MAX_DEPTH = 6 }
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
- entries[#entries + 1] = { name = entry.name, kind = 'variable',
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 entries[#entries + 1] = { name = alias, kind = 'namespace', detail = 'module' } end
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 entries[#entries + 1] = { name = d.alias:gsub('^@', ''), kind = 'class', detail = d.path }
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 entries[#entries + 1] = member end
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
- entries[#entries + 1] = { name = node.name, kind = node.kind, node = node, file = f }
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
- entries[#entries + 1] = { name = visible, kind = node.kind, node = node, file = g }
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
- entries[#entries + 1] = { name = node.name, kind = node.kind, node = node, file = g }
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 entries[#entries + 1] = entry end
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 entries[#entries + 1] = entry end
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 > M.MAX_ITEMS then
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 >= M.MAX_ITEMS then self.incomplete = true; break end
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,239 @@
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, extensions = h .. '/.vscode/extensions' },
63
+ { id = 'cursor', name = 'Cursor', command = cursor, detected = cursor ~= nil, extensions = h .. '/.cursor/extensions' },
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
+ -- Remove only our extension, including Zed's per-extension downloaded runtime.
169
+ -- Continue with other editors when one editor is unavailable or reports errors.
170
+ function M.remove()
171
+ local status = 0
172
+ local function remove_directory(target, parent)
173
+ if not exists(target) then return end
174
+ local actual = assert(xutils.realpath(target)):gsub('\\', '/'):gsub('/+$', '')
175
+ local expected = assert(xutils.realpath(parent)):gsub('\\', '/'):gsub('/+$', '') .. '/' .. assert(target:match('([^/]+)$'))
176
+ if windows then actual, expected = actual:lower(), expected:lower() end
177
+ assert(actual == expected, 'refusing to remove linked extension: ' .. target)
178
+ assert(xutils.rmtree(target), 'cannot remove ' .. target .. '; close the editor and retry')
179
+ assert(not exists(target), 'extension directory remains: ' .. target)
180
+ end
181
+ for _, editor in ipairs(M.detect()) do
182
+ local ok, err = pcall(function()
183
+ if editor.id == 'zed' then
184
+ for _, kind in ipairs({ 'installed', 'work', 'staging' }) do
185
+ local parent = editor.data .. '/extensions/' .. kind
186
+ local target = parent .. '/codeoutline'
187
+ remove_directory(target, parent)
188
+ end
189
+ -- This is Zed's generated extension registry, not user settings.
190
+ local index = editor.data .. '/extensions/index.json'
191
+ if exists(index) then
192
+ local before = read(index)
193
+ local after, changed = require('codeoutline.agent_config').json(before,
194
+ { 'extensions', 'codeoutline' }, {}, true, false)
195
+ if changed then
196
+ local temp = assert(xutils.temp_file(editor.data .. '/extensions'))
197
+ write(temp, after)
198
+ assert(read(index) == before, 'Zed extension registry changed; close Zed and retry')
199
+ assert(xutils.replace_file(temp, index), 'cannot update Zed extension registry')
200
+ end
201
+ end
202
+ say('CodeOutline removed from Zed. Restart Zed if it is open.')
203
+ elseif editor.detected then
204
+ local function command(args)
205
+ local text = quote(editor.command) .. ' ' .. args
206
+ return windows and ('"' .. text .. '"') or text
207
+ end
208
+ local function installed()
209
+ local pipe = assert(io.popen(command('--list-extensions')))
210
+ local output = pipe:read('a'); local closed = pipe:close()
211
+ assert(closed, editor.name .. ' extension listing failed')
212
+ for line in output:gmatch('[^\r\n]+') do
213
+ if line:lower():match('^%s*1dao%.codeoutline%s*$') then return true end
214
+ end
215
+ return false
216
+ end
217
+ if installed() then
218
+ local result = os.execute(command('--uninstall-extension 1dao.codeoutline'))
219
+ assert(result == true or result == 0, editor.name .. ' extension removal failed')
220
+ assert(not installed(), editor.name .. ' still lists CodeOutline')
221
+ end
222
+ -- The editor CLI may only mark old versions obsolete until its
223
+ -- next start. Remove those owned directories now or report locks.
224
+ for _, entry in ipairs(xutils.list_dir(editor.extensions) or {}) do
225
+ if entry.dir and entry.name:lower():match('^1dao%.codeoutline%-%d') then
226
+ remove_directory(editor.extensions .. '/' .. entry.name, editor.extensions)
227
+ end
228
+ end
229
+ say('CodeOutline removed from ' .. editor.name .. '. Reload the editor if it is open.')
230
+ else
231
+ say(editor.name .. ' CLI not detected; check other editor profiles manually.')
232
+ end
233
+ end)
234
+ if not ok then io.stderr:write('codeoutline: ', tostring(err), '\n'); status = 1 end
235
+ end
236
+ return status
237
+ end
238
+
239
+ return M