@codua/codeoutline-win32-x64 0.2.6 → 0.2.9

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 (72) hide show
  1. package/README.md +205 -3
  2. package/README.zh-CN.md +40 -2
  3. package/bin/xnet.exe +0 -0
  4. package/build-info.json +1 -1
  5. package/package.json +1 -1
  6. package/scripts/codeoutline/affected.lua +145 -0
  7. package/scripts/codeoutline/automatic_events.lua +202 -0
  8. package/scripts/codeoutline/cache_repairs.lua +47 -0
  9. package/scripts/codeoutline/callers.lua +56 -16
  10. package/scripts/codeoutline/cargo_toml.lua +125 -0
  11. package/scripts/codeoutline/command.lua +26 -4
  12. package/scripts/codeoutline/common.lua +48 -7
  13. package/scripts/codeoutline/completion.lua +126 -22
  14. package/scripts/codeoutline/coverage.lua +63 -0
  15. package/scripts/codeoutline/cpp_bindings.lua +46 -11
  16. package/scripts/codeoutline/cpp_fragments.lua +143 -0
  17. package/scripts/codeoutline/cpp_implementations.lua +340 -0
  18. package/scripts/codeoutline/cpp_includes.lua +156 -0
  19. package/scripts/codeoutline/cpp_macros.lua +279 -0
  20. package/scripts/codeoutline/cpp_receivers.lua +342 -0
  21. package/scripts/codeoutline/cpp_types.lua +275 -28
  22. package/scripts/codeoutline/definition_candidates.lua +180 -0
  23. package/scripts/codeoutline/dispatch_aliases.lua +10 -5
  24. package/scripts/codeoutline/documents.lua +22 -9
  25. package/scripts/codeoutline/explore.lua +243 -122
  26. package/scripts/codeoutline/external_headers.lua +171 -0
  27. package/scripts/codeoutline/function_values.lua +69 -0
  28. package/scripts/codeoutline/go_methods.lua +931 -0
  29. package/scripts/codeoutline/go_modules.lua +329 -0
  30. package/scripts/codeoutline/graph.lua +322 -67
  31. package/scripts/codeoutline/implementations.lua +403 -0
  32. package/scripts/codeoutline/index.lua +161 -28
  33. package/scripts/codeoutline/index_worker.lua +11 -4
  34. package/scripts/codeoutline/indirect.lua +4 -2
  35. package/scripts/codeoutline/js_evidence.lua +2 -1
  36. package/scripts/codeoutline/js_resolution.lua +40 -12
  37. package/scripts/codeoutline/js_workspace.lua +325 -0
  38. package/scripts/codeoutline/lang/c.lua +15 -2
  39. package/scripts/codeoutline/lang/cpp.lua +7 -4
  40. package/scripts/codeoutline/lang/csharp.lua +1 -1
  41. package/scripts/codeoutline/lang/js.lua +56 -20
  42. package/scripts/codeoutline/lang/rust.lua +9 -1
  43. package/scripts/codeoutline/language_detect.lua +100 -0
  44. package/scripts/codeoutline/lsp.lua +173 -23
  45. package/scripts/codeoutline/lua_bindings.lua +151 -47
  46. package/scripts/codeoutline/lua_callback_loops.lua +210 -0
  47. package/scripts/codeoutline/main.lua +32 -7
  48. package/scripts/codeoutline/mcp.lua +52 -9
  49. package/scripts/codeoutline/navigation.lua +284 -64
  50. package/scripts/codeoutline/on_demand.lua +93 -0
  51. package/scripts/codeoutline/ordinary_bindings.lua +210 -34
  52. package/scripts/codeoutline/parse.lua +18 -2
  53. package/scripts/codeoutline/parse_pool.lua +1 -1
  54. package/scripts/codeoutline/parse_worker.lua +1 -1
  55. package/scripts/codeoutline/python_bindings.lua +2 -2
  56. package/scripts/codeoutline/query_filters.lua +65 -0
  57. package/scripts/codeoutline/query_report.lua +56 -19
  58. package/scripts/codeoutline/resolution.lua +23 -0
  59. package/scripts/codeoutline/rust_packages.lua +203 -0
  60. package/scripts/codeoutline/rust_resolution.lua +301 -0
  61. package/scripts/codeoutline/search_ranking.lua +70 -0
  62. package/scripts/codeoutline/service.lua +47 -7
  63. package/scripts/codeoutline/shared_events.lua +369 -0
  64. package/scripts/codeoutline/static_dispatch.lua +46 -11
  65. package/scripts/codeoutline/text.lua +3 -2
  66. package/scripts/codeoutline/ts_implementations.lua +81 -0
  67. package/scripts/codeoutline/type_bases.lua +61 -0
  68. package/scripts/codeoutline/type_hierarchy.lua +324 -0
  69. package/scripts/codeoutline/type_references.lua +290 -0
  70. package/scripts/codeoutline/type_uses.lua +260 -0
  71. package/scripts/codeoutline/update_sequence.lua +1 -1
  72. package/scripts/codeoutline/version.lua +1 -1
@@ -0,0 +1,329 @@
1
+ -- Query-owned local Go module lookup. No go command, module cache or network.
2
+ local M = { MAX_CONFIGS = 1024, MAX_CONFIG_BYTES = 1048576, MAX_TOTAL_BYTES = 8388608,
3
+ MAX_MODULES = 256, MAX_FILES = 512, MAX_NODES = 8192, MAX_RESULTS = 64, MAX_DIRECTORIES = 4096 }
4
+ local control = require('codeoutline.control')
5
+ local paths = require('codeoutline.path')
6
+ local function dir(p) return p:match('^(.*)/[^/]+$') or '' end
7
+ local function join(a, b) return a == '' and b or b == '' and a or a .. '/' .. b end
8
+ local function valid(p)
9
+ if type(p) ~= 'string' or p == '' or p:find('[\\:%s%z]') or p:sub(1, 1) == '/' then return false end
10
+ for s in (p .. '/'):gmatch('(.-)/') do if s == '' or s == '.' or s == '..' then return false end end
11
+ return true
12
+ end
13
+ local function relative(base, p)
14
+ if p:find('[\\:%z]') or p:sub(1, 1) == '/' then error('Go local path is outside the indexed project or unsupported', 0) end
15
+ local parts = {}
16
+ for s in join(base, p):gmatch('[^/]+') do
17
+ if s == '..' then
18
+ if #parts == 0 then error('Go local path escapes the indexed project', 0) end
19
+ parts[#parts] = nil
20
+ elseif s ~= '.' then parts[#parts + 1] = s end
21
+ end
22
+ return table.concat(parts, '/')
23
+ end
24
+
25
+ local function tokens(line)
26
+ local out, i = {}, 1
27
+ while i <= #line do
28
+ local c = line:sub(i, i)
29
+ if c:match('%s') then i = i + 1
30
+ elseif line:sub(i, i + 1) == '//' then break
31
+ elseif c == '"' then
32
+ local start, escaped, last = i, false, nil
33
+ for j = i + 1, #line do
34
+ local z = line:sub(j, j)
35
+ if z == '"' and not escaped then last = j; break end
36
+ escaped = z == '\\' and not escaped
37
+ end
38
+ local ok, value = pcall(xutils.json_unpack, last and line:sub(start, last) or '')
39
+ if not ok or type(value) ~= 'string' then error('unsupported Go configuration string', 0) end
40
+ out[#out + 1] = value; i = last + 1
41
+ else
42
+ local value = line:match('^([^%s]+)', i)
43
+ out[#out + 1] = value; i = i + #value
44
+ end
45
+ end
46
+ return out
47
+ end
48
+
49
+ local function parse(raw, root, work)
50
+ local C = { root = root, requires = {}, replaces = {}, uses = {} }
51
+ local block
52
+ for line in (raw .. '\n'):gmatch('(.-)\r?\n') do
53
+ control.check()
54
+ local t = tokens(line)
55
+ if #t > 0 then
56
+ if t[1] == ')' then
57
+ if not block or #t ~= 1 then error('invalid Go configuration block', 0) end
58
+ block = nil
59
+ else
60
+ local directive = block or table.remove(t, 1)
61
+ if not block and t[1] == '(' then
62
+ if #t ~= 1 then error('unsupported Go configuration block', 0) end
63
+ block = directive
64
+ elseif directive == 'module' then
65
+ if work or #t ~= 1 or not valid(t[1]) or C.name then error('invalid Go module directive', 0) end
66
+ C.name = t[1]
67
+ elseif directive == 'use' and work then
68
+ if #t ~= 1 then error('invalid Go workspace use directive', 0) end
69
+ C.uses[#C.uses + 1] = relative(root, t[1])
70
+ if #C.uses > M.MAX_MODULES then error('Go workspace module limit reached', 0) end
71
+ elseif directive == 'require' and not work then
72
+ if #t ~= 2 or not valid(t[1]) or C.requires[t[1]] then error('invalid Go require directive', 0) end
73
+ C.requires[t[1]] = t[2]
74
+ elseif directive == 'replace' then
75
+ local arrow = t[2] == '=>' and 2 or t[3] == '=>' and 3
76
+ if not arrow or not valid(t[1]) or #t < arrow + 1 or #t > arrow + 2 then
77
+ error('invalid Go replace directive', 0)
78
+ end
79
+ local replacement = { name = t[1], version = arrow == 3 and t[2] or '',
80
+ target = t[arrow + 1], target_version = t[arrow + 2] }
81
+ if #t == arrow + 1 then
82
+ local target = replacement.target
83
+ if target ~= '.' and target ~= '..' and not target:match('^%./') and not target:match('^%.%./') then
84
+ error('unsupported Go replacement: local targets must use ./ or ../', 0)
85
+ end
86
+ replacement.root = relative(root, target)
87
+ end
88
+ local key = replacement.name .. '\0' .. replacement.version
89
+ if C.replaces[key] then error('duplicate Go replace directive', 0) end
90
+ C.replaces[key] = replacement
91
+ end
92
+ end
93
+ end
94
+ end
95
+ if block or not work and not C.name then error('invalid or missing Go module directive', 0) end
96
+ return C
97
+ end
98
+
99
+ local function context(G, ctx)
100
+ if ctx.go_context then return ctx.go_context end
101
+ local C = { configs = {}, owners = {}, environments = {}, modules = {}, aliases = {}, probes = 0, bytes = 0,
102
+ stats = ctx.go_stats or { reads = 0, bytes = 0, modules = 0 } }
103
+ ctx.go_context, ctx.go_stats = C, C.stats
104
+ function C.read(rel)
105
+ if C.configs[rel] ~= nil then return C.configs[rel] or nil end
106
+ control.check(); C.probes = C.probes + 1
107
+ if C.probes > M.MAX_CONFIGS then error('Go configuration probe limit reached', 0) end
108
+ local absolute = join(G.root, rel)
109
+ local real = xutils.realpath(absolute)
110
+ if not real then C.configs[rel] = false; return nil end
111
+ if not paths.contains(G.root, real) then error('Go configuration escapes the indexed project', 0) end
112
+ local f = io.open(absolute, 'rb')
113
+ if not f then C.configs[rel] = false; return nil end
114
+ local raw = f:read(M.MAX_CONFIG_BYTES + 1); f:close()
115
+ C.bytes = C.bytes + #raw
116
+ if #raw > M.MAX_CONFIG_BYTES or C.bytes > M.MAX_TOTAL_BYTES then error('Go configuration size limit reached', 0) end
117
+ C.stats.reads, C.stats.bytes = C.stats.reads + 1, C.bytes
118
+ local value = parse(raw, dir(rel), rel:match('go%.work$'))
119
+ C.configs[rel] = value; return value
120
+ end
121
+ function C.owner(directory)
122
+ if C.owners[directory] ~= nil then return C.owners[directory] or nil end
123
+ local current = directory
124
+ while true do
125
+ local mod = C.read(join(current, 'go.mod'))
126
+ if mod then C.owners[directory] = mod; return mod end
127
+ if current == '' then break end
128
+ current = dir(current)
129
+ end
130
+ C.owners[directory] = false
131
+ end
132
+ function C.environment(directory)
133
+ if C.environments[directory] then return C.environments[directory] end
134
+ local owner, current, work = C.owner(directory), directory
135
+ while true do
136
+ work = C.read(join(current, 'go.work'))
137
+ if work or current == '' then break end
138
+ current = dir(current)
139
+ end
140
+ local env = { owner = owner, work = work, mains = {}, names = {}, requires = {}, replaces = {} }
141
+ local function add(mod)
142
+ if #env.mains >= M.MAX_MODULES then error('Go workspace module limit reached', 0) end
143
+ if env.names[mod.name] then error('ambiguous Go workspace module: ' .. mod.name, 0) end
144
+ env.names[mod.name] = mod; env.mains[#env.mains + 1] = mod
145
+ end
146
+ if work then
147
+ local seen = {}
148
+ for _, root in ipairs(work.uses) do
149
+ if not seen[root] then
150
+ local mod = C.read(join(root, 'go.mod'))
151
+ if not mod then error('Go workspace module has no go.mod: ' .. root, 0) end
152
+ add(mod); seen[root] = true
153
+ end
154
+ end
155
+ elseif owner then add(owner) end
156
+ env.active = not work or owner and env.names[owner.name] == owner
157
+ for _, mod in ipairs(env.mains) do
158
+ for name, version in pairs(mod.requires) do
159
+ if env.requires[name] and env.requires[name] ~= version then env.requires[name] = false
160
+ elseif env.requires[name] == nil then env.requires[name] = version end
161
+ end
162
+ for key, r in pairs(mod.replaces) do
163
+ local old = env.replaces[key]
164
+ if old and (old.root ~= r.root or not old.root
165
+ and (old.target ~= r.target or old.target_version ~= r.target_version)) then env.replaces[key] = false
166
+ elseif old == nil then env.replaces[key] = r end
167
+ end
168
+ end
169
+ C.stats.modules = math.max(C.stats.modules, #env.mains)
170
+ C.environments[directory] = env; return env
171
+ end
172
+ return C
173
+ end
174
+
175
+ -- Exact directory lookup, including unsaved new files. Nested modules are barriers.
176
+ local function package_files(G, directory, C, owner, external, package)
177
+ local result, seen, name = {}, {}, package
178
+ local function add(g)
179
+ if seen[g] then return end
180
+ seen[g] = true
181
+ local rec = G.files[g]
182
+ if rec.language ~= 'go' or external and rec.path:match('_test%.go$') then return end
183
+ if dir(rec.path) ~= directory or package and rec.package ~= package then return end
184
+ if name and name ~= rec.package then error('ambiguous Go package directory: ' .. directory, 0) end
185
+ name = rec.package
186
+ if #result >= M.MAX_FILES then error('Go package file limit reached', 0) end
187
+ result[#result + 1] = g
188
+ end
189
+ if C and owner and C.owner(directory) ~= owner then return {}, 'Go nested module boundary' end
190
+ for _, g in ipairs(G.dir_files[directory] or {}) do control.check(); add(g) end
191
+ for _, g in ipairs(G.new_files or {}) do add(g) end
192
+ return result
193
+ end
194
+
195
+ local function legacy(G, spec)
196
+ local last, suffix = spec:match('([^/]+)$'), spec
197
+ if #(G.dir_by_base[last] or {}) > M.MAX_DIRECTORIES then error('Go legacy directory limit reached', 0) end
198
+ while suffix do
199
+ local found
200
+ for _, directory in ipairs(G.dir_by_base[last] or {}) do
201
+ control.check()
202
+ if directory == suffix or directory:sub(-#suffix - 1) == '/' .. suffix then
203
+ local files = package_files(G, directory, nil, nil, true)
204
+ if #files > 0 then
205
+ if found then return {}, 'ambiguous legacy Go import: ' .. spec end
206
+ found = files
207
+ end
208
+ end
209
+ end
210
+ if found then return found end
211
+ suffix = suffix:match('^[^/]+/(.+)$')
212
+ end
213
+ return {}
214
+ end
215
+
216
+ local function locate(G, f, spec, ctx)
217
+ if not valid(spec) then return {}, 'invalid Go import path' end
218
+ if not G.root then return legacy(G, spec) end
219
+ local C = context(G, ctx)
220
+ local key = G.files[f].path .. '\0' .. spec
221
+ if C.modules[key] then return table.unpack(C.modules[key]) end
222
+ local env = C.environment(dir(G.files[f].path))
223
+ if not env.owner and not env.work then return legacy(G, spec) end
224
+ if not env.active then return {}, 'Go importer is not in the active workspace' end
225
+ local candidates, reason = {}, nil
226
+ local function add(name, root, owner)
227
+ if spec == name or spec:sub(1, #name + 1) == name .. '/' then
228
+ local files, why = package_files(G, join(root, spec:sub(#name + 2)), C, owner, true)
229
+ if #files > 0 then candidates[#candidates + 1] = files else reason = why end
230
+ end
231
+ end
232
+ for name, mod in pairs(env.names) do add(name, mod.root, mod) end
233
+ for name, version in pairs(env.requires) do
234
+ if not env.names[name] and (spec == name or spec:sub(1, #name + 1) == name .. '/') then
235
+ local wildcard, key = name .. '\0', name .. '\0' .. (version or '')
236
+ local replacements = env.work and env.work.replaces or {}
237
+ local r = replacements[key] or replacements[wildcard]
238
+ if r == nil then
239
+ if env.replaces[key] == false or env.replaces[wildcard] == false then
240
+ return {}, 'conflicting Go module replacements: ' .. name
241
+ end
242
+ r = env.replaces[key] or env.replaces[wildcard]
243
+ end
244
+ if r and (r.version == '' or version) then
245
+ if not r.root then reason = 'Go replacement requires an external module: ' .. name
246
+ else
247
+ local mod = C.read(join(r.root, 'go.mod'))
248
+ if mod and mod.name == name then add(name, r.root, mod)
249
+ else reason = 'Go replacement has no matching module declaration: ' .. name end
250
+ end
251
+ elseif version == false then reason = 'Go dependency version selection is not modeled: ' .. name end
252
+ end
253
+ end
254
+ local files
255
+ if #candidates > 1 then files, reason = {}, 'ambiguous Go package import: ' .. spec
256
+ else files = candidates[1] or {} end
257
+ reason = reason or (#files == 0 and 'Go module package is not indexed: ' .. spec or nil)
258
+ C.modules[key] = { files, reason }; return files, reason
259
+ end
260
+
261
+ local function guarded(ctx, fn, ...)
262
+ if ctx.go_error then return {}, ctx.go_error end
263
+ local ok, result, reason = pcall(fn, ...)
264
+ if ok then return result, reason end
265
+ if control.is_interrupted(result) then error(result, 0) end
266
+ ctx.go_incomplete, ctx.go_error = true, tostring(result)
267
+ return {}, ctx.go_error
268
+ end
269
+
270
+ function M.files(G, f, spec, ctx)
271
+ ctx = ctx or {}
272
+ return guarded(ctx, locate, G, f, spec, ctx)
273
+ end
274
+
275
+ function M.peers(G, f, ctx)
276
+ ctx = ctx or {}
277
+ return guarded(ctx, package_files, G, dir(G.files[f].path), nil, nil,
278
+ not G.files[f].path:match('_test%.go$'), G.files[f].package)
279
+ end
280
+
281
+ function M.aliases(G, f, ctx)
282
+ ctx = ctx or {}
283
+ local C = G.root and context(G, ctx)
284
+ local key = G.files[f].path
285
+ if C and C.aliases[key] then return C.aliases[key] end
286
+ local out = {}
287
+ for _, imp in ipairs(G.files[f].imports) do
288
+ local files, reason = M.files(G, f, imp.path, ctx)
289
+ local alias = imp.alias or (#files > 0 and G.files[files[1]].package) or imp.path:match('([^/]+)$')
290
+ if alias ~= '_' then
291
+ local entry = { path = imp.path, kind = 'import', files = files, reason = reason }
292
+ if out[alias] then out[alias] = { files = {}, reason = 'ambiguous Go package alias: ' .. alias }
293
+ else out[alias] = entry end
294
+ end
295
+ end
296
+ if C then C.aliases[key] = out end
297
+ return out
298
+ end
299
+
300
+ function M.resolve(G, f, name, recv, ctx)
301
+ ctx = ctx or {}
302
+ local aliases, files, reason, exported = M.aliases(G, f, ctx)
303
+ if recv then
304
+ local alias = aliases[recv]
305
+ if not alias then return nil end
306
+ files, reason, exported = alias.files, alias.reason, true
307
+ else files = M.peers(G, f, ctx) end
308
+ local function collect()
309
+ local ids, count = {}, 0
310
+ for _, g in ipairs(files) do
311
+ for _, id in ipairs(G.id_of[g]) do
312
+ control.check(); count = count + 1
313
+ if count > M.MAX_NODES then error('Go package node limit reached', 0) end
314
+ local node = G.nodes[id]
315
+ if node.name == name and not node.parent and node.kind ~= 'method'
316
+ and (not exported or name:match('^%u')) then
317
+ if #ids >= M.MAX_RESULTS then error('Go package result limit reached', 0) end
318
+ ids[#ids + 1] = id
319
+ end
320
+ end
321
+ end
322
+ return ids
323
+ end
324
+ local ids, why = guarded(ctx, collect)
325
+ -- Dot imports are deliberately not inferred; local declarations take priority.
326
+ return ids, why or reason or (#ids == 0 and 'Go package binding unresolved' or nil)
327
+ end
328
+
329
+ return M