@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,171 @@
1
+ -- Declaration navigation in selected external headers. Never extend the index.
2
+ local M = { MAX_FILES = 64, MAX_PROJECT_FILES = 128, MAX_BYTES = 4 * 1024 * 1024,
3
+ MAX_FILE_BYTES = 1024 * 1024, CACHE_FILES = 32, CACHE_BYTES = 8 * 1024 * 1024, TIME_MS = 500 }
4
+ local paths, control = require('codeoutline.path'), require('codeoutline.control')
5
+ local cache, order, cache_bytes, scanner = {}, {}, 0, nil
6
+ local function directory(file) return file:match('^(.*)/[^/]+$') end
7
+ local function existing(file)
8
+ control.check()
9
+ local stat = xutils.stat(file)
10
+ if stat and stat.type == 'file' then
11
+ local real = xutils.realpath(file)
12
+ return real and paths.normalize(real)
13
+ end
14
+ end
15
+ local function read(file, info)
16
+ local stream = io.open(file, 'rb')
17
+ if not stream then return nil end
18
+ local raw = stream:read(M.MAX_FILE_BYTES + 1) or ''; stream:close()
19
+ info.files, info.bytes = info.files + 1, info.bytes + #raw
20
+ if #raw > M.MAX_FILE_BYTES or info.bytes > M.MAX_BYTES then info.truncated = true; return nil end
21
+ local crc = xcompress and xcompress.crc32 and xcompress.crc32(raw) or xutils.sha256_hex(raw)
22
+ local key, entry = paths.key(file), cache[paths.key(file)]
23
+ if entry and entry.crc == crc and entry.size == #raw then return entry end
24
+ if entry then
25
+ cache_bytes = cache_bytes - entry.weight; cache[key] = nil
26
+ for i, old in ipairs(order) do if old == key then table.remove(order, i); break end end
27
+ end
28
+ local source = xutils.to_utf8(raw)
29
+ if not source then return nil end
30
+ if source:sub(1, 3) == '\239\187\191' then source = source:sub(4) end
31
+ if not scanner then
32
+ local config = {}; for k, v in pairs(require('codeoutline.lang.c').config) do config[k] = v end
33
+ config.pp_first_branch = false
34
+ scanner = require('codeoutline.xscan').lang(config)
35
+ end
36
+ local T = scanner:tokenize(source)
37
+ local imports = {}
38
+ for i = 1, T.n do
39
+ if i % 4096 == 0 then control.check() end
40
+ if T.k[i] == 'dir' then
41
+ local text = T:text(i)
42
+ local name = text:match('^#%s*include%s*[<"]([^>"]+)[>"]')
43
+ if name then imports[#imports + 1] = { path = name, system = text:match('^#%s*include%s*<') ~= nil } end
44
+ end
45
+ end
46
+ entry = { file = file, source = source, imports = imports, crc = crc, size = #raw,
47
+ weight = #source * 2 + #imports * 128 + 256 }
48
+ while #order > 0 and (#order >= M.CACHE_FILES or cache_bytes + entry.weight > M.CACHE_BYTES) do
49
+ local old = table.remove(order, 1); cache_bytes = cache_bytes - cache[old].weight; cache[old] = nil
50
+ end
51
+ if entry.weight <= M.CACHE_BYTES then
52
+ cache[key] = entry; order[#order + 1] = key; cache_bytes = cache_bytes + entry.weight
53
+ end
54
+ return entry
55
+ end
56
+ local function declarations(entry, name)
57
+ local escaped = name:gsub('([^%w])', '%%%1')
58
+ if not entry.source:find('%f[%w_$]' .. escaped .. '%f[^%w_$]') then return {} end
59
+ if not entry.nodes then
60
+ local rec = require('codeoutline.parse').parse(entry.file, entry.source, { type_uses = false, analysis = false })
61
+ entry.nodes = rec and rec.nodes or {}
62
+ local weight = #entry.nodes * 256
63
+ if cache[paths.key(entry.file)] == entry then
64
+ cache_bytes, entry.weight = cache_bytes + weight, entry.weight + weight
65
+ while #order > 0 and cache_bytes > M.CACHE_BYTES do
66
+ local old = table.remove(order, 1); cache_bytes = cache_bytes - cache[old].weight; cache[old] = nil
67
+ end
68
+ end
69
+ end
70
+ local result = {}
71
+ for _, node in ipairs(entry.nodes) do
72
+ if node.name == name and node.qualified == name and not node.parent and node.name_start
73
+ and (node.kind == 'prototype' or node.kind == 'function') then
74
+ result[#result + 1] = { node = node, file = entry.file, source = entry.source,
75
+ declaration = node.kind == 'prototype' or node.decl == true }
76
+ end
77
+ end
78
+ return result
79
+ end
80
+
81
+ function M.find(G, f, site, ctx, system_directories)
82
+ local info = { files = 0, bytes = 0, truncated = false }
83
+ if not site or site.recv or site.kind ~= 'call' or not require('codeoutline.definition_candidates').allowed(site) then return {}, info end
84
+ local includes = require('codeoutline.cpp_includes')
85
+ local headers, queued, projects, visited, project_queued = {}, {}, { f }, {}, { [f] = true }
86
+ local defaults, started = nil, xtimer.now_ms()
87
+ local function expired()
88
+ control.check()
89
+ if xtimer.now_ms() - started >= M.TIME_MS then info.truncated = true; return true end
90
+ return false
91
+ end
92
+ local function dirs(owner)
93
+ local policy = includes.policy(G, owner, ctx)
94
+ local result = {}
95
+ local function add_root(dir)
96
+ control.check()
97
+ local real = xutils.realpath(dir)
98
+ if real then result[#result + 1] = paths.normalize(real) end
99
+ end
100
+ for _, dir in ipairs(policy.paths) do add_root(dir) end
101
+ if not policy.configured then
102
+ defaults = defaults or (type(system_directories) == 'function' and system_directories() or system_directories or {})
103
+ for _, dir in ipairs(defaults) do add_root(dir) end
104
+ end
105
+ return result
106
+ end
107
+ local function add(file, roots)
108
+ if file and not paths.contains(G.root, file) and not queued[paths.key(file)] then
109
+ queued[paths.key(file)] = true; headers[#headers + 1] = { file = file, roots = roots }
110
+ end
111
+ end
112
+ local function locate(imp, roots, parent)
113
+ local written = imp.path:gsub('\\', '/')
114
+ if written:find('[%z\r\n]') or written:match('^[/\\]') or written:match('^%a:') then return end
115
+ if not imp.system and parent then
116
+ local file = existing(directory(parent) .. '/' .. written)
117
+ if file then
118
+ for _, root in ipairs(roots) do if paths.contains(root, file) then return file end end
119
+ end
120
+ end
121
+ for _, root in ipairs(roots) do
122
+ local file = existing(root .. '/' .. written)
123
+ if file and paths.contains(root, file) then return file end
124
+ end
125
+ end
126
+ local pi = 1
127
+ while pi <= #projects do
128
+ if expired() then return {}, info end
129
+ local owner = projects[pi]; pi = pi + 1
130
+ if not visited[owner] then
131
+ if pi > M.MAX_PROJECT_FILES + 1 then info.truncated = true; break end
132
+ visited[owner] = true
133
+ for _, imp in ipairs(G.files[owner].imports or {}) do
134
+ if owner ~= f or not site.line or imp.line <= site.line then
135
+ local ids, selected, file = includes.resolve(G, owner, imp, ctx)
136
+ for _, id in ipairs(ids) do
137
+ if not project_queued[id] then
138
+ if #projects >= M.MAX_PROJECT_FILES then info.truncated = true
139
+ else project_queued[id] = true; projects[#projects + 1] = id end
140
+ end
141
+ end
142
+ if #ids == 0 then
143
+ local roots = dirs(owner)
144
+ if file then
145
+ file = existing(file)
146
+ if file and not paths.contains(G.root, file) then
147
+ roots[#roots + 1] = directory(file); add(file, roots)
148
+ end
149
+ elseif not selected then add(locate(imp, roots), roots) end
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+ local best, hi = {}, 1
156
+ while hi <= #headers do
157
+ if info.files >= M.MAX_FILES or expired() then info.truncated = true; break end
158
+ local target = headers[hi]; hi = hi + 1
159
+ local entry = read(target.file, info)
160
+ if entry then
161
+ local found = declarations(entry, site.name)
162
+ for _, hit in ipairs(found) do
163
+ if hit.declaration then return { hit }, info end
164
+ if #best < 8 then best[#best + 1] = hit end
165
+ end
166
+ for _, imp in ipairs(entry.imports) do add(locate(imp, target.roots, target.file), target.roots) end
167
+ end
168
+ end
169
+ return best, info
170
+ end
171
+ return M
@@ -0,0 +1,69 @@
1
+ -- Compact function-as-value sites. Resolution reuses query-owned bindings;
2
+ -- these are references, never proof of a callback being executed.
3
+ local M = {}
4
+ local supported = { javascript = true, typescript = true, arkts = true, python = true, java = true }
5
+ local callable = { ['function'] = true, method = true }
6
+ local before = { ['('] = true, [','] = true, ['='] = true, ['['] = true, [':'] = true }
7
+ local after = { [')'] = true, [','] = true, [';'] = true, [']'] = true, ['}'] = true }
8
+
9
+ function M.collect(r, T)
10
+ if not supported[r.language] then return end
11
+ -- The ordinary parser does not represent every anonymous scope. Do not
12
+ -- borrow outer binding evidence where an unindexed parameter can shadow it.
13
+ if r.language ~= 'java' then
14
+ local headers = {}
15
+ for _, n in ipairs(r.nodes) do
16
+ if callable[n.kind] then
17
+ for i = n.ti, n.tj do
18
+ local s = T:text(i)
19
+ if s == 'function' or s == '=>' then headers[i] = true end
20
+ if s == '{' then break end
21
+ end
22
+ end
23
+ end
24
+ for i = 1, T.n do
25
+ if (T:text(i) == '=>' or T:text(i) == 'function') and not headers[i]
26
+ or r.language == 'python' and T:text(i) == 'lambda' then return end
27
+ end
28
+ end
29
+ local names, roots, seen = {}, {}, {}
30
+ for _, n in ipairs(r.nodes) do if callable[n.kind] then names[n.name] = true end end
31
+ if r.language ~= 'java' then
32
+ for _, imp in ipairs(require('codeoutline.dispatch_aliases').imports(r, T)) do
33
+ names[imp.name], roots[imp.name] = true, true
34
+ end
35
+ end
36
+ for _, ref in ipairs(r.refs) do seen[ref.tok] = true end
37
+ local aliases = {}
38
+ for i = 2, T.n - 1 do
39
+ if T:text(i) == '=' and T.k[i - 1] == 'id' and T.k[i + 1] == 'id'
40
+ and (after[T:text(i + 2)] or T.k[i + 2] == 'nl') then
41
+ aliases[#aliases + 1] = { T:text(i - 1), T:text(i + 1) }
42
+ end
43
+ end
44
+ for _ = 1, 8 do
45
+ local changed = false
46
+ for _, alias in ipairs(aliases) do
47
+ if names[alias[2]] and not names[alias[1]] then names[alias[1]], changed = true, true end
48
+ end
49
+ if not changed then break end
50
+ end
51
+ for i = 1, T.n do
52
+ if i % 4096 == 0 then require('codeoutline.control').check() end
53
+ if T.k[i] == 'id' and not seen[i] then
54
+ local prev, next = T:text(i - 1), T:text(i + 1)
55
+ local explicit = prev == '::' and r.language == 'java'
56
+ local recv = (prev == '.' or explicit) and
57
+ (T.k[i - 2] == 'id' or T:text(i - 2) == 'this' or T:text(i - 2) == 'self' or T:text(i - 2) == 'cls') and T:text(i - 2)
58
+ local first = recv and i - 2 or i
59
+ local simple = before[T:text(first - 1)] and
60
+ (after[next] or T.k[i + 1] == 'nl' or i == T.n)
61
+ if (explicit or r.language ~= 'java' and simple and (names[T:text(i)] or roots[recv]))
62
+ and not (recv and (T:text(first - 1) == '.' or T:text(first - 1) == '?.')) then
63
+ r.refs[#r.refs + 1] = { tok = i, name = T:text(i), kind = 'ref', recv = recv, line = T:line(i) }
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ return M