Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

flip1995
Copy link

When using stylua as a library, the only formatting interface it provides are the format_code and format_ast functions, which both already expect a config file. To replicate the config file discovery that the stylua CLI implements, one would have to copy this.

My motivation: For one of my projects I'm creating bindings for other languages to the stylua_lib. There it would be really useful, if I could use the config file discovery.

}

pub struct ConfigResolver<'a> {
config_cache: HashMap<PathBuf, Option<Config>>,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the config_cache. The config_cache was only used in the find_config_file function, which is only called in 2 places and then calls itself recursively. When recursively calling itself, it just passes dir.parent(). So every time it is called, it is not possible that the directory is already in the cache. So the cache did effectively nothing.

The downside of having it was that 3 functions had to take &mut self instead of just &self.

Comment on lines -293 to -298
fn test_override_syntax() {
let override_opt = Opt::parse_from(vec!["BINARY_NAME", "--syntax", "Lua51"]);
let default_config = Config::new();
let config = load_overrides(default_config, &override_opt);
assert_eq!(config.syntax, LuaVersion::Lua51);
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those tests are no longer possible, as the load_overrides was moved to the lib part. Testing this function there, without involving Opt::parse_from seemed pointless to me. So I removed them.

When using stylua as a library, the only formatting interface it
provides are the `format_code` and `format_ast` functions, which both
already expect a config file. To replicate the config file discovery
that the stylua CLI implements, one would have to copy this.

My motivation: For one of my projects I'm creating bindings for other
languages to the stylua_lib. There it would be really useful, if I could
use the config file discovery.
@flip1995 flip1995 force-pushed the config-file-res-lib branch from 28adeea to f3255f7 Compare August 12, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.