-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to search for config without getCurrentDirectory #483
base: main
Are you sure you want to change the base?
Make it possible to search for config without getCurrentDirectory #483
Conversation
This looks good to me: but I think we should either
I don't think many tools are calling |
I went for option 2 as it was easier. But do let me know if you change your mind and I can implement 1 instead. Intuitively I dislike 1 because (if I understand it right) we'd have to introduce a new type of config type that would have to be called differently than the original Config and which would (for now) just specify the config loading strategy? Maybe this middle-ground solution would be enough to minimize backward api breakage? -- keep the original api
format :: Maybe ConfigPath -> Maybe FilePath -> String -> IO (Either String Lines)
format Nothing = formatWith SearchFromCurrentDirectory
format (Just cfgPath) = formatWith (UseConfig (unConfigPath cfgPath))
-- introduce new more general function
formatWith :: ConfigSearchStrategy -> Maybe FilePath -> String -> IO (Either String Lines)
formatWith configSearchStrategy maybeFilePath contents = do
conf <- loadConfig (makeVerbose True) configSearchStrategy
pure $ runSteps (configLanguageExtensions conf) maybeFilePath (configSteps conf) $ lines contents |
@jaspervdj friendly ping :) |
Thanks for the ping and of course the PR! This looks good to me. |
Co-Authored-By: Jan Hrček <[email protected]>
972f693
to
cbe47ce
Compare
Depends on #489 |
Thank you, it looks great. I didn't realize cabal files were also searched in this way. |
Reopening #482 whose branch I deleted by mistake.
Original description:
An attempt to resolve #478
The intention is to make it possible to avoid dependency on getCurrentDirectory (which is problematic in haskell-language-server where multiple things running concurrently might depend on current directory and having to setCurrentDirectory just for stylish-haskell to be able to find the right config might lead to various race conditions).
The way to achieve it is to introduce new datatype
ConfigSearchStrategy
whose constructorSearchFromDirectory startDir
makes it possible to supply a directory explicitly.See this HLS PR for an example of how this new functionality would be used: haskell/haskell-language-server#4338