@codua/codeoutline-win32-x64 0.2.4 → 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 (77) 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 +65 -9
  13. package/scripts/codeoutline/completion.lua +221 -65
  14. package/scripts/codeoutline/coverage.lua +63 -0
  15. package/scripts/codeoutline/cpp_bindings.lua +151 -0
  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 +456 -0
  22. package/scripts/codeoutline/csharp_bindings.lua +498 -0
  23. package/scripts/codeoutline/definition_candidates.lua +180 -0
  24. package/scripts/codeoutline/dispatch_aliases.lua +479 -0
  25. package/scripts/codeoutline/documents.lua +32 -9
  26. package/scripts/codeoutline/explore.lua +274 -119
  27. package/scripts/codeoutline/external_headers.lua +171 -0
  28. package/scripts/codeoutline/foreign.lua +79 -14
  29. package/scripts/codeoutline/foreign_lua.lua +146 -19
  30. package/scripts/codeoutline/function_values.lua +69 -0
  31. package/scripts/codeoutline/go_methods.lua +931 -0
  32. package/scripts/codeoutline/go_modules.lua +329 -0
  33. package/scripts/codeoutline/graph.lua +346 -63
  34. package/scripts/codeoutline/implementations.lua +403 -0
  35. package/scripts/codeoutline/index.lua +165 -27
  36. package/scripts/codeoutline/index_worker.lua +11 -4
  37. package/scripts/codeoutline/indirect.lua +116 -40
  38. package/scripts/codeoutline/js_evidence.lua +32 -3
  39. package/scripts/codeoutline/js_resolution.lua +72 -10
  40. package/scripts/codeoutline/js_workspace.lua +325 -0
  41. package/scripts/codeoutline/lang/c.lua +15 -2
  42. package/scripts/codeoutline/lang/cpp.lua +7 -4
  43. package/scripts/codeoutline/lang/csharp.lua +15 -3
  44. package/scripts/codeoutline/lang/js.lua +56 -20
  45. package/scripts/codeoutline/lang/rust.lua +9 -1
  46. package/scripts/codeoutline/language_detect.lua +100 -0
  47. package/scripts/codeoutline/lsp.lua +173 -23
  48. package/scripts/codeoutline/lua_bindings.lua +228 -54
  49. package/scripts/codeoutline/lua_callback_loops.lua +210 -0
  50. package/scripts/codeoutline/lua_literal.lua +38 -0
  51. package/scripts/codeoutline/main.lua +32 -7
  52. package/scripts/codeoutline/mcp.lua +52 -9
  53. package/scripts/codeoutline/navigation.lua +593 -147
  54. package/scripts/codeoutline/on_demand.lua +93 -0
  55. package/scripts/codeoutline/ordinary_bindings.lua +396 -0
  56. package/scripts/codeoutline/parse.lua +18 -2
  57. package/scripts/codeoutline/parse_pool.lua +1 -1
  58. package/scripts/codeoutline/parse_worker.lua +1 -1
  59. package/scripts/codeoutline/python_bindings.lua +112 -0
  60. package/scripts/codeoutline/query_filters.lua +65 -0
  61. package/scripts/codeoutline/query_report.lua +135 -8
  62. package/scripts/codeoutline/resolution.lua +23 -0
  63. package/scripts/codeoutline/rules.lua +127 -0
  64. package/scripts/codeoutline/rust_packages.lua +203 -0
  65. package/scripts/codeoutline/rust_resolution.lua +301 -0
  66. package/scripts/codeoutline/search_ranking.lua +70 -0
  67. package/scripts/codeoutline/service.lua +47 -7
  68. package/scripts/codeoutline/shared_events.lua +369 -0
  69. package/scripts/codeoutline/static_dispatch.lua +569 -0
  70. package/scripts/codeoutline/text.lua +3 -2
  71. package/scripts/codeoutline/ts_implementations.lua +81 -0
  72. package/scripts/codeoutline/type_bases.lua +61 -0
  73. package/scripts/codeoutline/type_hierarchy.lua +324 -0
  74. package/scripts/codeoutline/type_references.lua +290 -0
  75. package/scripts/codeoutline/type_uses.lua +260 -0
  76. package/scripts/codeoutline/update_sequence.lua +1 -1
  77. package/scripts/codeoutline/version.lua +1 -1
@@ -0,0 +1,156 @@
1
+ -- Ordered C/C++ include lookup over indexed paths. Configuration is query-owned.
2
+ local M = { MAX_PATHS = 128, MAX_RULES = 128, MAX_CACHED_TARGETS = 8192 }
3
+ local paths = require('codeoutline.path')
4
+ local control = require('codeoutline.control')
5
+ local function absolute(path) return path:sub(1, 1) == '/' or path:match('^%a:/') ~= nil end
6
+ local function normalize(path)
7
+ path = path:gsub('\\', '/')
8
+ local prefix = path:match('^%a:/') or (path:sub(1, 2) == '//' and '//') or (path:sub(1, 1) == '/' and '/') or ''
9
+ local parts, floor = {}, prefix == '//' and 2 or 0
10
+ for part in path:sub(#prefix + 1):gmatch('[^/]+') do
11
+ if part == '..' and #parts > floor and parts[#parts] ~= '..' then parts[#parts] = nil
12
+ elseif part == '..' then if prefix == '' then parts[#parts + 1] = part end
13
+ elseif part ~= '.' then parts[#parts + 1] = part end
14
+ end
15
+ return prefix .. table.concat(parts, '/')
16
+ end
17
+ local function join(root, path)
18
+ path = path:gsub('\\', '/')
19
+ return normalize(absolute(path) and path or (root ~= '' and root .. '/' or '') .. path)
20
+ end
21
+ local function array(value, label, cap)
22
+ assert(type(value) == 'table' and #value <= cap, label .. ' must be an array with at most ' .. cap .. ' entries')
23
+ for key in pairs(value) do
24
+ assert(type(key) == 'number' and key >= 1 and key <= #value and key % 1 == 0, label .. ' must be an array')
25
+ end
26
+ end
27
+ local function directory(value, label)
28
+ assert(type(value) == 'string' and value ~= '' and #value <= 4096 and not value:find('[%z\r\n]'),
29
+ label .. ' must contain non-empty directory strings of at most 4096 bytes')
30
+ value = value:gsub('\\', '/')
31
+ assert(not value:find(':', 1, true) or value:match('^%a:/'), label .. ' must not use drive-relative paths')
32
+ return value
33
+ end
34
+
35
+ function M.context(G, client_paths)
36
+ local config = require('codeoutline.rules').read(G.root)
37
+ local root = normalize(G.root or '')
38
+ local function directories(value, label)
39
+ array(value, label, M.MAX_PATHS)
40
+ local result = {}
41
+ for _, dir in ipairs(value) do result[#result + 1] = join(root, directory(dir, label)) end
42
+ return result
43
+ end
44
+ local C = { root = root, rules = {}, policies = {}, targets = {}, target_count = 0, configured = config.includePaths ~= nil }
45
+ local defaults, client = config.includePaths, client_paths
46
+ if defaults == nil then defaults = {} end
47
+ if client == nil then client = {} end
48
+ C.defaults = directories(defaults, 'includePaths')
49
+ C.client = directories(client, 'includePaths')
50
+ C.configured = C.configured or #C.client > 0
51
+ local rules = config.includePathRules
52
+ if rules == nil then rules = {} end
53
+ array(rules, 'includePathRules', M.MAX_RULES)
54
+ local seen = {}
55
+ for _, rule in ipairs(rules) do
56
+ control.check()
57
+ assert(type(rule) == 'table', 'includePathRules entries must be objects')
58
+ for key in pairs(rule) do assert(key == 'directory' or key == 'paths', 'unknown includePathRules field: ' .. tostring(key)) end
59
+ local dir = directory(rule.directory, 'includePathRules.directory')
60
+ assert(not absolute(dir), 'includePathRules.directory must be project-relative')
61
+ dir = normalize(dir)
62
+ assert(dir ~= '..' and dir:sub(1, 3) ~= '../', 'includePathRules.directory must stay inside the project')
63
+ local key = paths.key(dir)
64
+ assert(not seen[key], 'duplicate includePathRules.directory: ' .. dir); seen[key] = true
65
+ C.rules[#C.rules + 1] = { directory = key, paths = directories(rule.paths, 'includePathRules.paths') }
66
+ end
67
+ table.sort(C.rules, function(a, b) return #a.directory > #b.directory end)
68
+ return C
69
+ end
70
+
71
+ function M.policy(G, f, ctx)
72
+ local C = ctx and ctx.cpp_includes
73
+ if not C then
74
+ C = M.context(G, ctx and ctx.include_paths)
75
+ if ctx then ctx.cpp_includes = C end
76
+ end
77
+ local rel, rule = paths.key(G.files[f].path), nil
78
+ for _, candidate in ipairs(C.rules) do
79
+ if candidate.directory == '' or rel:sub(1, #candidate.directory + 1) == candidate.directory .. '/' then
80
+ rule = candidate; break
81
+ end
82
+ end
83
+ local key = rule and rule.directory or false
84
+ if not C.policies[key] then
85
+ local dirs, seen = {}, {}
86
+ for _, list in ipairs({ rule and rule.paths or {}, C.defaults, C.client }) do
87
+ for _, dir in ipairs(list) do
88
+ local identity = paths.key(dir)
89
+ if not seen[identity] then
90
+ assert(#dirs < M.MAX_PATHS, 'effective includePaths exceeds ' .. M.MAX_PATHS .. ' directories')
91
+ dirs[#dirs + 1], seen[identity] = dir, true
92
+ end
93
+ end
94
+ end
95
+ C.policies[key] = { paths = dirs, configured = C.configured or rule ~= nil, root = C.root }
96
+ end
97
+ return C.policies[key], C
98
+ end
99
+
100
+ -- `selected` distinguishes an ordered search (including a configured miss)
101
+ -- from the legacy suffix fallback. External selected headers are never indexed.
102
+ function M.resolve(G, f, imp, ctx)
103
+ local policy, C = M.policy(G, f, ctx)
104
+ local rec, written = G.files[f], imp.path:gsub('\\', '/')
105
+ local function target(file)
106
+ local old = C.targets[file]
107
+ if old then return old[1], old[2] end
108
+ control.check()
109
+ local rel = file
110
+ if policy.root ~= '' then
111
+ if paths.contains(policy.root, file) then rel = file:sub(#policy.root + 2) else rel = nil end
112
+ end
113
+ local id = rel and (G.file_index[rel] or G.file_index[paths.key(rel)])
114
+ local exists = id ~= nil
115
+ if not exists and policy.root ~= '' then
116
+ local stat = xutils.stat(file); exists = stat and stat.type == 'file' or false
117
+ if exists then
118
+ local real = xutils.realpath(file)
119
+ real = real and paths.normalize(real)
120
+ if real and paths.contains(policy.root, real) then id = G.file_index[real:sub(#policy.root + 2)] end
121
+ end
122
+ end
123
+ if C.target_count < M.MAX_CACHED_TARGETS then
124
+ C.targets[file] = { id, exists }; C.target_count = C.target_count + 1
125
+ end
126
+ return id, exists
127
+ end
128
+ local function find(file)
129
+ local id, exists = target(file)
130
+ if exists then return id and { id } or {}, true, file end
131
+ end
132
+ if absolute(written) then
133
+ local ids, selected, file = find(normalize(written))
134
+ return ids or {}, selected or true, file
135
+ end
136
+ if not imp.system then
137
+ local here = rec.path:match('^(.*)/[^/]*$') or ''
138
+ local ids, selected, file = find(join(join(policy.root, here), written))
139
+ if selected then return ids, true, file end
140
+ end
141
+ for _, dir in ipairs(policy.paths) do
142
+ local ids, selected, file = find(join(dir, written))
143
+ if selected then return ids, true, file end
144
+ end
145
+ if policy.configured then return {}, true end
146
+ local ids = {}
147
+ local base = written:match('([^/]*)$')
148
+ for i, id in ipairs(G.by_base[base] or G.by_base[paths.key(base)] or {}) do
149
+ if i % 128 == 0 then control.check() end
150
+ local path, name = paths.key(G.files[id].path), paths.key(written)
151
+ if path == name or path:sub(-#name - 1) == '/' .. name then ids[#ids + 1] = id end
152
+ end
153
+ return ids, false
154
+ end
155
+
156
+ return M
@@ -0,0 +1,279 @@
1
+ -- Query-owned project macro visibility. No expansion or compiler execution.
2
+ local M = { MAX_FILES = 128, MAX_BYTES = 8 * 1024 * 1024, MAX_SUMMARY_BYTES = 1024 * 1024, MAX_EVENTS = 20000,
3
+ MAX_DIRECTIVES = 4096, MAX_DEPTH = 32, MAX_RESULTS = 4096 }
4
+ local control = require('codeoutline.control')
5
+ local scanners = {}
6
+ local UNKNOWN = {}
7
+ local function trim(s) return (s:gsub('^%s+', ''):gsub('%s+$', '')) end
8
+ local function conjunction(a, b) if a == false or b == false then return false end; if a == true and b == true then return true end end
9
+ local function disjunction(a, b) if a == true or b == true then return true end; if a == false and b == false then return false end end
10
+ local function negate(a) if a ~= nil then return not a end end
11
+ local function defined(env, name)
12
+ local value = env[name]
13
+ if value == false then return false end
14
+ if value and value ~= UNKNOWN then return true end
15
+ end
16
+
17
+ local function condition(expr, env, depth)
18
+ depth = (depth or 0) + 1
19
+ if depth > 16 then return nil end
20
+ expr = trim(expr)
21
+ local level, split_or, split_and = 0
22
+ for i = 1, #expr do
23
+ local c = expr:sub(i, i)
24
+ if c == '(' then level = level + 1 elseif c == ')' then level = level - 1 end
25
+ if level == 0 then
26
+ local op = expr:sub(i, i + 1)
27
+ if op == '||' then split_or = i elseif op == '&&' then split_and = i end
28
+ end
29
+ if level < 0 then return nil end
30
+ end
31
+ if level ~= 0 then return nil end
32
+ local at = split_or or split_and
33
+ if at then
34
+ local a, b = condition(expr:sub(1, at - 1), env, depth), condition(expr:sub(at + 2), env, depth)
35
+ if split_or then return disjunction(a, b) end
36
+ return conjunction(a, b)
37
+ end
38
+ if expr:sub(1, 1) == '(' and expr:sub(-1) == ')' then return condition(expr:sub(2, -2), env, depth) end
39
+ if expr:sub(1, 1) == '!' then return negate(condition(expr:sub(2), env, depth)) end
40
+ local name = expr:match('^defined%s*%(%s*([%a_][%w_]*)%s*%)$') or expr:match('^defined%s+([%a_][%w_]*)$')
41
+ if name then return defined(env, name) end
42
+ local number = tonumber((expr:gsub('[uUlL]+$', '')))
43
+ if number then return number ~= 0 end
44
+ if expr:match('^[%a_][%w_]*$') then
45
+ local value = env[expr]
46
+ if value == false then return false end
47
+ if value and value ~= UNKNOWN and value.number then return value.number ~= 0 end
48
+ end
49
+ end
50
+
51
+ local function scanner_for(language)
52
+ local scanner = scanners[language]
53
+ if not scanner then
54
+ local config = {}
55
+ for k, v in pairs(require('codeoutline.lang.' .. language).config) do config[k] = v end
56
+ config.pp_first_branch = false
57
+ scanner = require('codeoutline.xscan').lang(config); scanners[language] = scanner
58
+ end
59
+ return scanner
60
+ end
61
+
62
+ function M.collect(r, T, all_branches)
63
+ if r.language ~= 'c' and r.language ~= 'cpp' then return end
64
+ local result = {}; r.cpp_macros = result
65
+ if not T.src:find('#', 1, true) then return end
66
+ local scanner = scanner_for(r.language)
67
+ local source = T.src
68
+ if r.language == 'cpp' and source:find('R"', 1, true) then
69
+ local starts = {}
70
+ for i = 1, T.n do
71
+ if T.k[i] == 'str' then
72
+ local prefix = T:text(i):match('^([LuU8]*R)"')
73
+ if prefix then starts[T.s[i] + #prefix - 1] = true end
74
+ elseif T.k[i] == 'id' and T:text(i) == 'u8R' and T.s[i + 1] == T.e[i] + 1 and T:text(i + 1):sub(1, 1) == '"' then
75
+ starts[T.e[i]] = true -- scanners accepting at most two prefix characters
76
+ end
77
+ end
78
+ local parts, at = {}, 1
79
+ while true do
80
+ local first, last, delimiter = source:find('R"([^%s%(%)"\\]*)%(', at)
81
+ if not first then break end
82
+ if not starts[first] or #delimiter > 16 then at = last + 1
83
+ else
84
+ local close = source:find(')' .. delimiter .. '"', last + 1, true)
85
+ if not close then result.incomplete = true; return end
86
+ parts[#parts + 1] = { first = first, last = close + #delimiter + 1 }
87
+ at = close + #delimiter + 2
88
+ end
89
+ end
90
+ local pieces, previous = {}, 1
91
+ for _, span in ipairs(parts) do
92
+ pieces[#pieces + 1] = source:sub(previous, span.first - 1)
93
+ pieces[#pieces + 1] = source:sub(span.first, span.last):gsub('[^\r\n]', ' ')
94
+ previous = span.last + 1
95
+ end
96
+ pieces[#pieces + 1] = source:sub(previous)
97
+ source = table.concat(pieces)
98
+ end
99
+ local full = source == T.src and (all_branches or not source:find('#%s*if')) and T or scanner:tokenize(source)
100
+ local nodes = {}
101
+ for i, n in ipairs(r.nodes) do
102
+ if n.kind == 'macro' then nodes[n.line .. '\0' .. n.name] = i end
103
+ end
104
+ for i = 1, full.n do
105
+ if i % 4096 == 0 then control.check() end
106
+ if full.k[i] == 'dir' then
107
+ if #result >= M.MAX_DIRECTIVES then result.incomplete = true; break end
108
+ local raw = full:text(i):gsub('\\\r?\n', ' ')
109
+ local kind, rest = raw:match('^#%s*(%a+)%s*(.*)$')
110
+ local e = { kind = kind, line = full:line(i) }
111
+ if kind == 'include' then
112
+ e.path = rest:match('^"([^"]+)"') or rest:match('^<([^>]+)>')
113
+ e.system = rest:sub(1, 1) == '<'
114
+ else
115
+ rest = trim(rest:gsub('/%*.-%*/', ' '):gsub('//[^\n]*', ''))
116
+ e.name = rest:match('^([%a_][%w_]*)')
117
+ if kind == 'define' and e.name then
118
+ local body = rest:sub(#e.name + 1)
119
+ e.callable = body:sub(1, 1) == '('
120
+ e.number = not e.callable and tonumber((trim(body):gsub('[uUlL]+$', ''))) or nil
121
+ e.node = nodes[e.line .. '\0' .. e.name]
122
+ -- Recursive wrapper expansion needs expansion semantics.
123
+ e.recursive = e.callable and body:find('%f[%w_]' .. e.name .. '%f[^%w_]') ~= nil
124
+ elseif kind == 'if' or kind == 'elif' then e.expression = rest
125
+ elseif kind == 'pragma' then e.once = trim(rest) == 'once' end
126
+ end
127
+ result[#result + 1] = e
128
+ end
129
+ end
130
+ if result[1] and result[2] and result[1].kind == 'ifndef' and result[2].kind == 'define'
131
+ and result[1].name == result[2].name then result.guard = result[1].name end
132
+ end
133
+
134
+ function M.summary(rec, source)
135
+ if source:sub(1, 3) == '\239\187\191' then source = source:sub(4) end
136
+ local r = { language = rec.language, nodes = rec.nodes }
137
+ M.collect(r, scanner_for(rec.language):tokenize(source), true)
138
+ return r.cpp_macros
139
+ end
140
+
141
+ function M.context(G, ctx)
142
+ if ctx.cpp_macro_context then return ctx.cpp_macro_context end
143
+ local C = { stats = { files = 0, bytes = 0, summary_bytes = 0, events = 0, checks = 0 }, incomplete = false }
144
+ ctx.cpp_macro_context = C
145
+ local summaries, results, result_count = {}, {}, 0
146
+ local function limited() C.incomplete = true; return nil end
147
+ local function data(f)
148
+ if summaries[f] then return summaries[f] end
149
+ local rec = G.files[f]
150
+ if C.stats.files >= M.MAX_FILES or C.stats.bytes + (rec.size or 0) > M.MAX_BYTES then return limited() end
151
+ local value = ctx.ordinary.macros(f)
152
+ if not value or value.incomplete then return limited() end
153
+ local weight = #value * 192
154
+ for _, e in ipairs(value) do weight = weight + #(e.name or '') + #(e.expression or '') + #(e.path or '') end
155
+ if C.stats.summary_bytes + weight > M.MAX_SUMMARY_BYTES then return limited() end
156
+ C.stats.summary_bytes = C.stats.summary_bytes + weight
157
+ summaries[f] = value; C.stats.files = C.stats.files + 1; C.stats.bytes = C.stats.bytes + (rec.size or 0)
158
+ return value
159
+ end
160
+ -- Only definition navigation opts into ambiguous include alternatives;
161
+ -- execution queries keep their own strict, separately cached result.
162
+ function C.resolve(f, name, line, declarations)
163
+ local key = f .. '\0' .. name .. '\0' .. line .. (declarations and '\0declarations' or '')
164
+ if results[key] then return results[key][1], results[key][2], results[key][3], results[key][4] end
165
+ if result_count >= M.MAX_RESULTS then limited(); return {}, true, nil, 'limited' end
166
+ C.stats.checks = C.stats.checks + 1
167
+ local env, once, active_files, definitions = {}, {}, {}, {}
168
+ local failed = false
169
+ local function walk(file, cutoff, parent, depth)
170
+ control.check()
171
+ if depth > M.MAX_DEPTH then limited(); failed = true; return end
172
+ if active_files[file] or once[file] then return end
173
+ local events = data(file)
174
+ if not events then failed = true; return end
175
+ -- Conventional include guards are initially absent unless a source
176
+ -- directive established their state. Arbitrary build flags stay unknown.
177
+ if events.guard and env[events.guard] == nil and parent == true then env[events.guard] = false end
178
+ active_files[file] = true
179
+ local stack, active = {}, parent
180
+ for _, e in ipairs(events) do
181
+ if e.line > cutoff then break end
182
+ C.stats.events = C.stats.events + 1
183
+ if C.stats.events % 128 == 0 then control.check() end
184
+ if C.stats.events > M.MAX_EVENTS then limited(); failed = true; break end
185
+ local kind = e.kind
186
+ if kind == 'if' or kind == 'ifdef' or kind == 'ifndef' then
187
+ local test
188
+ if kind == 'if' then test = condition(e.expression, env)
189
+ else test = defined(env, e.name); if kind == 'ifndef' then test = negate(test) end end
190
+ stack[#stack + 1] = { parent = active, taken = test }
191
+ active = conjunction(active, test)
192
+ elseif kind == 'elif' or kind == 'else' then
193
+ local frame = stack[#stack]
194
+ if not frame then failed = true; break end
195
+ local test = kind == 'else' and true or condition(e.expression, env)
196
+ active = conjunction(frame.parent, conjunction(negate(frame.taken), test))
197
+ frame.taken = disjunction(frame.taken, test)
198
+ elseif kind == 'endif' then
199
+ local frame = table.remove(stack)
200
+ if not frame then failed = true; break end
201
+ active = frame.parent
202
+ elseif active ~= false then
203
+ if (kind == 'define' or kind == 'undef') and e.name then
204
+ if e.name == name then
205
+ if active == true then definitions = {} end
206
+ if kind == 'define' and e.node then definitions[G.id_of[file][e.node]] = true end
207
+ end
208
+ if active == nil then env[e.name] = UNKNOWN
209
+ elseif kind == 'undef' then env[e.name] = false
210
+ else env[e.name] = { callable = e.callable, number = e.number, node = e.node,
211
+ file = file, recursive = e.recursive } end
212
+ elseif kind == 'pragma' and e.once and active == true then once[file] = true
213
+ elseif kind == 'include' then
214
+ if not e.path then env[name] = UNKNOWN
215
+ else
216
+ local targets = require('codeoutline.cpp_includes').resolve(G, file, e, ctx)
217
+ if #targets == 1 then walk(targets[1], math.huge, active, depth + 1)
218
+ elseif #targets > 1 then
219
+ if declarations then
220
+ -- F12 may show alternatives without choosing a
221
+ -- build's include path. Evaluate each header
222
+ -- independently: sibling include guards, undef
223
+ -- and pragma once must not affect each other.
224
+ local original_env, original_once, original_definitions = env, once, definitions
225
+ local candidates = {}
226
+ local function copy(values)
227
+ local result = {}; for k, v in pairs(values) do result[k] = v end; return result
228
+ end
229
+ for _, target in ipairs(targets) do
230
+ env, once, definitions = copy(original_env), copy(original_once), copy(original_definitions)
231
+ walk(target, math.huge, active, depth + 1)
232
+ for id in pairs(definitions) do candidates[id] = true end
233
+ if failed then break end
234
+ end
235
+ env, once, definitions = original_env, original_once, candidates
236
+ end
237
+ env[name] = UNKNOWN
238
+ end
239
+ -- External/unindexed headers are not interpreted.
240
+ end
241
+ end
242
+ end
243
+ end
244
+ active_files[file] = nil
245
+ end
246
+ walk(f, line, true, 1)
247
+ local value, ids, handled = env[name], {}, true
248
+ if not failed and (value == false or value == nil) then handled = false
249
+ elseif not failed and value ~= UNKNOWN and value and value.callable and value.node and not value.recursive then
250
+ ids[1] = G.id_of[value.file][value.node]
251
+ end
252
+ -- Definition navigation may inspect the declarations reached on an
253
+ -- unknown branch without asserting an execution edge. An unconditional
254
+ -- redefine/undef clears older candidates; directives after the call and
255
+ -- known-false branches never contribute. Graph resolution stays strict.
256
+ local sites = {}
257
+ if not failed then for id in pairs(definitions) do sites[#sites + 1] = id end end
258
+ table.sort(sites)
259
+ local state = failed and 'limited' or value == nil and 'unseen' or value == false and 'undefined'
260
+ or value == UNKNOWN and 'uncertain' or 'defined'
261
+ result_count = result_count + 1; results[key] = { ids, handled, sites, state }
262
+ return ids, handled, sites, state
263
+ end
264
+ return C
265
+ end
266
+
267
+ function M.resolve(G, f, name, line, ctx, declarations)
268
+ if not line or not ctx or (G.files[f].language ~= 'c' and G.files[f].language ~= 'cpp') then return nil end
269
+ local candidate = false
270
+ for i, id in ipairs(G.by_name[name] or {}) do
271
+ if i % 128 == 0 then control.check() end
272
+ if G.nodes[id].kind == 'macro' then candidate = true; break end
273
+ end
274
+ if not candidate then return nil end
275
+ local ids, handled, definitions, state = M.context(G, ctx).resolve(f, name, line, declarations)
276
+ return handled and ids or false, definitions, state
277
+ end
278
+
279
+ return M