@codua/codeoutline-win32-x64 0.2.9 → 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.
Files changed (33) hide show
  1. package/DISTRIBUTION.md +93 -8
  2. package/README.md +112 -2
  3. package/README.zh-CN.md +86 -2
  4. package/bin/xnet.exe +0 -0
  5. package/build-info.json +1 -1
  6. package/editors/codeoutline.vsix +0 -0
  7. package/editors/zed/extension.toml +15 -0
  8. package/editors/zed/extension.wasm +0 -0
  9. package/package.json +1 -1
  10. package/scripts/codeoutline/agent_config.lua +291 -0
  11. package/scripts/codeoutline/agent_install.lua +195 -0
  12. package/scripts/codeoutline/command.lua +110 -9
  13. package/scripts/codeoutline/completion.lua +66 -20
  14. package/scripts/codeoutline/cpp_types.lua +12 -3
  15. package/scripts/codeoutline/definition_candidates.lua +13 -7
  16. package/scripts/codeoutline/editor_install.lua +168 -0
  17. package/scripts/codeoutline/external_headers.lua +22 -9
  18. package/scripts/codeoutline/foreign.lua +23 -3
  19. package/scripts/codeoutline/idle_gc.lua +45 -0
  20. package/scripts/codeoutline/index.lua +3 -1
  21. package/scripts/codeoutline/index_worker.lua +39 -5
  22. package/scripts/codeoutline/install_prompt.lua +15 -0
  23. package/scripts/codeoutline/lang/cpp.lua +25 -14
  24. package/scripts/codeoutline/lsp.lua +44 -4
  25. package/scripts/codeoutline/lsp_trace.lua +57 -0
  26. package/scripts/codeoutline/navigation.lua +109 -11
  27. package/scripts/codeoutline/service.lua +38 -5
  28. package/scripts/codeoutline/type_references.lua +3 -2
  29. package/scripts/codeoutline/update_sequence.lua +1 -1
  30. package/scripts/codeoutline/version.lua +1 -1
  31. package/scripts/xupgate/client.lua +35 -18
  32. package/scripts/xupgate/common.lua +2 -2
  33. 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 - 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]
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 }, uninstall = { port = 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 (os.getenv('npm_config_global') ~= 'true' or os.getenv('CODEOUTLINE_AUTOSTART') == '0') then return 0 end
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/%x+/files$'),
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 say('service listening on http://127.0.0.1:' .. port .. '/mcp')
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
- -- 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
@@ -182,7 +182,7 @@ function M.resolve(G, f, written, opts)
182
182
  end
183
183
  local function named(file, qualified, at, depth)
184
184
  local tail = qualified:match('([^:]+)$')
185
- local found, ids = false, {}
185
+ local found, ids, alias_declarations = false, {}, {}
186
186
  for index, id in ipairs(G.by_name[tail] or {}) do
187
187
  if index % 128 == 0 then control.check() end
188
188
  local n, g = G.nodes[id], G.node_file[id]
@@ -192,10 +192,18 @@ function M.resolve(G, f, written, opts)
192
192
  for _, alias in ipairs(aliases(g)) do
193
193
  if not alias.kind and not alias.local_alias and (alias.scope ~= '' and alias.scope .. '::' or '') .. alias.name == qualified then
194
194
  matched = true
195
- if g ~= file or not at or alias.at <= at then found = true; add(ids, follow(alias, g, depth)) end
195
+ if g ~= file or not at or alias.at <= at then
196
+ found = true; add(ids, follow(alias, g, depth))
197
+ if opts.navigation_alias and depth == 0 then add(alias_declarations, { id }) end
198
+ end
199
+ end
200
+ end
201
+ if not matched then
202
+ found = true -- unsupported alias is a barrier
203
+ if opts.navigation_alias and depth == 0 and (g ~= file or not at) then
204
+ add(alias_declarations, { id })
196
205
  end
197
206
  end
198
- if not matched then found = true end -- unsupported alias is a barrier
199
207
  else
200
208
  found = true
201
209
  add(ids, { id })
@@ -240,6 +248,7 @@ function M.resolve(G, f, written, opts)
240
248
  end
241
249
  end
242
250
  end
251
+ if #ids == 0 and opts.navigation_alias then add(ids, alias_declarations) end
243
252
  return ids, found
244
253
  end
245
254
  local function qualified(file, name, at, depth)
@@ -37,8 +37,8 @@ function M.find(G, f, site, ctx)
37
37
  -- These languages have package/project visibility that a name-only search
38
38
  -- cannot establish. Their existing resolvers retain authority.
39
39
  if language == 'go' or language == 'rust' or language == 'csharp' then return {}, info end
40
- if (language == 'c' or language == 'cpp')
41
- and require('codeoutline.cpp_includes').policy(G, f, ctx).configured then return {}, info end
40
+ local configured = (language == 'c' or language == 'cpp')
41
+ and require('codeoutline.cpp_includes').policy(G, f, ctx).configured
42
42
  local qualified
43
43
  if site.evidence and site.evidence ~= '' then qualified = site.evidence:match('^cpp:name:(.-)%z') end
44
44
  qualified = qualified and normalized(qualified)
@@ -47,7 +47,7 @@ function M.find(G, f, site, ctx)
47
47
  if site.recv == 'self' or site.recv == 'this' or site.recv == 'cls' then return {}, info end
48
48
  qualified = qualified or normalized(site.recv .. '.' .. site.name)
49
49
  elseif site.kind == 'member_call' or site.kind == 'member_symbol' then return {}, info end
50
- local list, hits = G.by_name[site.name] or {}, {}
50
+ local list, hits, macro_hits = G.by_name[site.name] or {}, {}, {}
51
51
  local source_dir = G.files[f].path:match('^(.*)/') or ''
52
52
  for i = 1, math.min(#list, M.MAX_SCAN) do
53
53
  if i % 16 == 0 then control.check() end
@@ -60,10 +60,12 @@ function M.find(G, f, site, ctx)
60
60
  local kind = site.kind == 'new' and types[node.kind]
61
61
  or site.kind ~= 'new' and (callable[node.kind]
62
62
  or (site.kind == 'symbol' or site.kind == 'member_symbol') and (types[node.kind] or values[node.kind]))
63
- -- An absent include context permits inspecting macro declarations.
64
- -- An explicit undef, uncertain expansion, or budget failure does not.
63
+ -- Unresolved macro visibility can still offer unconfirmed definition
64
+ -- tags for navigation, including when include paths are configured.
65
+ -- An explicit undef remains a barrier.
65
66
  if node.kind == 'macro' then
66
- kind = site.kind == 'call' and site.macro_state == 'unseen'
67
+ kind = site.kind == 'call' and (site.macro_state == 'unseen'
68
+ or site.macro_state == 'uncertain' or site.macro_state == 'limited')
67
69
  and (g ~= f or site.line and node.line < site.line)
68
70
  end
69
71
  local name_matches = (node.name == site.name or published) and (normalized(node.qualified) == site.name or published)
@@ -83,9 +85,13 @@ function M.find(G, f, site, ctx)
83
85
  and (qualified or node.kind ~= 'method' and node.kind ~= 'constructor') then
84
86
  local score = g == f and 100 or (rec.path:match('^(.*)/') or '') == source_dir and 20 or 0
85
87
  if node.kind ~= 'prototype' and not node.decl then score = score + 1 end
86
- hits[#hits + 1] = { id = id, score = score }
88
+ local bucket = node.kind == 'macro' and macro_hits or hits
89
+ bucket[#bucket + 1] = { id = id, score = score }
87
90
  end
88
91
  end
92
+ -- Ordinary definitions are more useful than unrelated proxy macros.
93
+ if #hits == 0 then hits = macro_hits
94
+ elseif configured then hits = {} end
89
95
  info.truncated = info.truncated or #list > M.MAX_SCAN
90
96
  -- Prefer implementations over repeated API declarations. A declaration is
91
97
  -- still useful when the project has no matching implementation at all.
@@ -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