Skip to content
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

Avoid setCurrentDirectory in hls-stylish-haskell-plugin (closes #4234) #4338

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ constraints:
if impl(ghc >= 9.9)
-- https://github.com/haskell/haskell-language-server/issues/4324
benchmarks: False
else
source-repository-package
type: git
location: https://github.com/jhrcek/stylish-haskell.git
tag: 0b1f3bb50d25c7c30171d080643bc8badbe1883c
1 change: 0 additions & 1 deletion haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,6 @@ library hls-stylish-haskell-plugin
hs-source-dirs: plugins/hls-stylish-haskell-plugin/src
build-depends:
, base >=4.12 && <5
, directory
, filepath
, ghc-boot-th
, ghcide == 2.9.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import Ide.PluginUtils
import Ide.Types hiding (Config)
import Language.Haskell.Stylish
import Language.LSP.Protocol.Types as LSP
import System.Directory
import System.FilePath

data Log
Expand Down Expand Up @@ -78,12 +77,9 @@ provider recorder ide _token typ contents fp _opts = do
-- | Recursively search in every directory of the given filepath for .stylish-haskell.yaml.
-- If no such file has been found, return default config.
loadConfigFrom :: FilePath -> IO Config
loadConfigFrom file = do
currDir <- getCurrentDirectory
setCurrentDirectory (takeDirectory file)
config <- loadConfig (makeVerbose False) Nothing
setCurrentDirectory currDir
pure config
loadConfigFrom file =
let configSearchStrategy = SearchFromDirectory (takeDirectory file)
in loadConfig (makeVerbose False) configSearchStrategy

-- | Run stylish-haskell on the given text with the given configuration.
runStylishHaskell :: FilePath -- ^ Location of the file being formatted. Used for error message
Expand Down
Loading