Skip to main content

luaur_analyze_cli/methods/
cli_config_resolver_get_config.rs

1use crate::records::cli_config_resolver::CliConfigResolver;
2use luaur_analysis::records::config_resolver::ConfigResolver;
3use luaur_analysis::records::type_check_limits::TypeCheckLimits;
4use luaur_cli_lib::functions::get_parent_path::get_parent_path;
5use luaur_config::records::config::Config;
6use luaur_config::type_aliases::module_name::ModuleName;
7
8/// `const Config& getConfig(const ModuleName&, const TypeCheckLimits&) const` thunk.
9///
10/// # Safety
11/// `this` must point at the `base` subobject of a live `CliConfigResolver`.
12pub(crate) unsafe fn cli_config_resolver_get_config_thunk(
13    this: *const ConfigResolver,
14    name: *const ModuleName,
15    limits: *const TypeCheckLimits,
16) -> *const Config {
17    let this = this as *const CliConfigResolver;
18    (*this).get_config(&*name, &*limits) as *const Config
19}
20
21impl CliConfigResolver {
22    /// C++ `const Config& getConfig(const ModuleName& name, const TypeCheckLimits& limits) const`
23    /// (`CLI/src/Analyze.cpp:243-250`).
24    ///
25    /// `getConfig` is logically `const` in C++ but mutates the `mutable` `configCache`
26    /// / `configErrors` members through `readConfigRec`; the `&self` receiver is cast
27    /// to `&mut self` for those interior mutations, matching the C++ `mutable` intent.
28    pub fn get_config(&self, name: &ModuleName, limits: &TypeCheckLimits) -> &Config {
29        // std::optional<std::string> path = getParentPath(name);
30        // if (!path) return defaultConfig;
31        let path = match get_parent_path(name) {
32            None => return &self.default_config,
33            Some(path) => path,
34        };
35
36        // return readConfigRec(*path, limits);
37        let this = self as *const CliConfigResolver as *mut CliConfigResolver;
38        unsafe { (*this).read_config_rec(&path, limits) }
39    }
40}