From 985df4426b8a4f43339301e2be1fad024ac73187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Wed, 26 Jun 2024 15:02:24 +0200 Subject: [PATCH 1/6] Avoid setCurrentDirectory in hls-stylish-haskell-plugin --- .../src/Ide/Plugin/StylishHaskell.hs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs b/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs index a862e57fb8..d9e4a506c6 100644 --- a/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs +++ b/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs @@ -78,12 +78,8 @@ 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 = + loadConfig (makeVerbose False) (Just $ takeDirectory file) -- | Run stylish-haskell on the given text with the given configuration. runStylishHaskell :: FilePath -- ^ Location of the file being formatted. Used for error message From 907c5ed772ed044c6edf12c8940f5e3859dbc6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Thu, 27 Jun 2024 06:44:00 +0200 Subject: [PATCH 2/6] Revert "Avoid setCurrentDirectory in hls-stylish-haskell-plugin" This reverts commit 985df4426b8a4f43339301e2be1fad024ac73187. --- .../src/Ide/Plugin/StylishHaskell.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs b/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs index d9e4a506c6..a862e57fb8 100644 --- a/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs +++ b/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs @@ -78,8 +78,12 @@ 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 = - loadConfig (makeVerbose False) (Just $ takeDirectory file) +loadConfigFrom file = do + currDir <- getCurrentDirectory + setCurrentDirectory (takeDirectory file) + config <- loadConfig (makeVerbose False) Nothing + setCurrentDirectory currDir + pure config -- | Run stylish-haskell on the given text with the given configuration. runStylishHaskell :: FilePath -- ^ Location of the file being formatted. Used for error message From c4f6c137e82bdfa41fd87e87ffc7d61bfcb00fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Thu, 27 Jun 2024 07:40:04 +0200 Subject: [PATCH 3/6] Use functionality from upstream PR --- cabal.project | 5 +++++ .../src/Ide/Plugin/StylishHaskell.hs | 10 +++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cabal.project b/cabal.project index e430c76dee..90ea07ea75 100644 --- a/cabal.project +++ b/cabal.project @@ -42,6 +42,11 @@ constraints: -- in the future, thus: TODO: remove this flag. bitvec -simd, +source-repository-package + type: git + location: https://github.com/jhrcek/stylish-haskell.git + tag: afefca07e7d1c6b10b1d71006192afcf49c4783b + if impl(ghc >= 9.9) -- https://github.com/haskell/haskell-language-server/issues/4324 benchmarks: False diff --git a/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs b/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs index a862e57fb8..fb3ac81cd0 100644 --- a/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs +++ b/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs @@ -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 @@ -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 From a20cb954a7a97b22da143962978adad80285a96e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Thu, 27 Jun 2024 07:47:42 +0200 Subject: [PATCH 4/6] Fix build failure with ghc 9.10, remove unused directory dep --- cabal.project | 10 +++++----- haskell-language-server.cabal | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cabal.project b/cabal.project index 90ea07ea75..4fc85b50b9 100644 --- a/cabal.project +++ b/cabal.project @@ -42,11 +42,11 @@ constraints: -- in the future, thus: TODO: remove this flag. bitvec -simd, -source-repository-package - type: git - location: https://github.com/jhrcek/stylish-haskell.git - tag: afefca07e7d1c6b10b1d71006192afcf49c4783b - 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: afefca07e7d1c6b10b1d71006192afcf49c4783b \ No newline at end of file diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 0a325deaf6..47f00b75c1 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -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 From 69ee81fcd8a3108a5d0908e0d77529b96d269daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Thu, 27 Jun 2024 07:48:22 +0200 Subject: [PATCH 5/6] Newline fix --- cabal.project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal.project b/cabal.project index 4fc85b50b9..9dccb0b497 100644 --- a/cabal.project +++ b/cabal.project @@ -49,4 +49,4 @@ else source-repository-package type: git location: https://github.com/jhrcek/stylish-haskell.git - tag: afefca07e7d1c6b10b1d71006192afcf49c4783b \ No newline at end of file + tag: afefca07e7d1c6b10b1d71006192afcf49c4783b From eba4d524fb9bbe8de01c05f9aa9749ea19ddebb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Thu, 27 Jun 2024 08:02:20 +0200 Subject: [PATCH 6/6] Fix stylish-haskell executable build --- cabal.project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal.project b/cabal.project index 9dccb0b497..f36b736463 100644 --- a/cabal.project +++ b/cabal.project @@ -49,4 +49,4 @@ else source-repository-package type: git location: https://github.com/jhrcek/stylish-haskell.git - tag: afefca07e7d1c6b10b1d71006192afcf49c4783b + tag: 0b1f3bb50d25c7c30171d080643bc8badbe1883c