Move config file resolver to library#1013
Open
flip1995 wants to merge 1 commit intoJohnnyMorganz:mainfrom
Open
Move config file resolver to library#1013flip1995 wants to merge 1 commit intoJohnnyMorganz:mainfrom
flip1995 wants to merge 1 commit intoJohnnyMorganz:mainfrom
Conversation
flip1995
commented
Aug 12, 2025
| } | ||
|
|
||
| pub struct ConfigResolver<'a> { | ||
| config_cache: HashMap<PathBuf, Option<Config>>, |
Author
There was a problem hiding this comment.
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.
flip1995
commented
Aug 12, 2025
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); | ||
| } |
Author
There was a problem hiding this comment.
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.
28adeea to
f3255f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using stylua as a library, the only formatting interface it provides are the
format_codeandformat_astfunctions, 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.