From 880cc559ec5f6418cab301fcf5af0e0a65c05cc2 Mon Sep 17 00:00:00 2001 From: jneira Date: Fri, 15 Jan 2021 14:44:20 +0100 Subject: [PATCH 1/6] Use runtime libdir for ghc-exactprint --- .../hls-hlint-plugin/src/Ide/Plugin/Hlint.hs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs index 3e63501980..f4790cc5bd 100644 --- a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs +++ b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs @@ -41,10 +41,12 @@ import Development.IDE.Core.Shake (getDiagnostics) import Data.List (nub) import "ghc-lib" GHC hiding (DynFlags(..), ms_hspp_opts) import "ghc-lib-parser" GHC.LanguageExtensions (Extension) +import "ghc" DynFlags as RealGHC.DynFlags (topDir) import "ghc" GHC as RealGHC (DynFlags(..)) import "ghc" HscTypes as RealGHC.HscTypes (hsc_dflags, ms_hspp_opts) import qualified "ghc" EnumSet as EnumSet import Language.Haskell.GhclibParserEx.GHC.Driver.Session as GhclibParserEx (readExtension) +import System.Environment(setEnv, unsetEnv) import System.FilePath (takeFileName) import System.IO (hPutStr, noNewlineTranslation, hSetNewlineMode, utf8, hSetEncoding, IOMode(WriteMode), withFile, hClose) import System.IO.Temp @@ -362,6 +364,8 @@ applyHint ide nfp mhint = let fp = fromNormalizedFilePath nfp (_, mbOldContent) <- liftIO $ runAction' $ getFileContents nfp oldContent <- maybe (liftIO $ T.readFile fp) return mbOldContent + (modsum, _) <- liftIO $ runAction' $ use_ GetModSummary nfp + let dflags = ms_hspp_opts modsum -- set Nothing as "position" for "applyRefactorings" because -- applyRefactorings expects the provided position to be _within_ the scope -- of each refactoring it will apply. @@ -383,6 +387,17 @@ applyHint ide nfp mhint = hSetEncoding h utf8 hSetNewlineMode h noNewlineTranslation hPutStr h (T.unpack txt) + -- Setting a environment variable with the libdir used by ghc-exactprint. + -- It is a workaround for an error caused by the use of a hadcoded at compile time libdir + -- in ghc-exactprint that makes dependent executables non portables. + -- See https://github.com/alanz/ghc-exactprint/issues/96. + -- WARNING: this code is not thread safe, so if you try to apply several async refactorings + -- in files associated with ghc sessions with different libdir's within the same hls process, + -- it could fail. + -- That case is quite improbable so we assume the risk. + let withRuntimeLibdir :: IO a -> IO a + withRuntimeLibdir = bracket (setEnv key $ topDir dflags) (const $ unsetEnv key) . const + where key = "GHC_EXACTPRINT_GHC_LIBDIR" res <- liftIO $ withSystemTempFile (takeFileName fp) $ \temp h -> do hClose h @@ -392,7 +407,7 @@ applyHint ide nfp mhint = -- We have to reparse extensions to remove the invalid ones let (enabled, disabled, _invalid) = parseExtensions $ map show exts let refactExts = map show $ enabled ++ disabled - (Right <$> applyRefactorings Nothing commands temp refactExts) + (Right <$> withRuntimeLibdir (applyRefactorings Nothing commands temp refactExts)) `catches` errorHandlers #else mbParsedModule <- liftIO $ runAction' $ getParsedModuleWithComments nfp @@ -402,8 +417,6 @@ applyHint ide nfp mhint = Just pm -> do let anns = pm_annotations pm let modu = pm_parsed_source pm - (modsum, _) <- liftIO $ runAction' $ use_ GetModSummary nfp - let dflags = ms_hspp_opts modsum -- apply-refact uses RigidLayout let rigidLayout = deltaOptions RigidLayout (anns', modu') <- From f642e39fffd2859b47d952b1ebb3399155d800ce Mon Sep 17 00:00:00 2001 From: jneira Date: Sun, 17 Jan 2021 22:36:52 +0100 Subject: [PATCH 2/6] Use released apply-refact and master ghc-exactprint --- cabal.project | 6 +++--- stack-8.10.1.yaml | 7 ++++--- stack-8.10.2.yaml | 5 +++-- stack-8.10.3.yaml | 7 ++++--- stack-8.6.4.yaml | 9 ++++----- stack-8.6.5.yaml | 9 ++++----- stack-8.8.2.yaml | 9 ++++----- stack-8.8.3.yaml | 9 ++++----- stack-8.8.4.yaml | 9 ++++----- stack.yaml | 9 ++++----- 10 files changed, 38 insertions(+), 41 deletions(-) diff --git a/cabal.project b/cabal.project index dc4ad52982..456a57cc92 100644 --- a/cabal.project +++ b/cabal.project @@ -15,8 +15,8 @@ packages: source-repository-package type: git - location: https://github.com/mpickering/apply-refact.git - tag: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d + location: https://github.com/alanz/ghc-exactprint.git + tag: 6748e24da18a6cea985d20cc3e1e7920cb743795 tests: true @@ -30,7 +30,7 @@ package ghcide write-ghc-environment-files: never -index-state: 2021-01-14T12:49:26Z +index-state: 2021-01-17T17:47:48Z allow-newer: active:base, diff --git a/stack-8.10.1.yaml b/stack-8.10.1.yaml index cb1b8db061..032ecfa50a 100644 --- a/stack-8.10.1.yaml +++ b/stack-8.10.1.yaml @@ -19,15 +19,16 @@ ghc-options: "$everything": -haddock extra-deps: - - git: https://github.com/mpickering/apply-refact.git - commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d + - apply-refact-0.9.0.0 - brittany-0.13.1.0 - Cabal-3.0.2.0 - clock-0.7.2 - data-tree-print-0.1.0.2@rev:2 - floskell-0.10.4 - fourmolu-0.3.0.0 - - ghc-exactprint-0.6.3.3 + # - ghc-exactprint-0.6.3.3 + - git: https://github.com/alanz/ghc-exactprint.git + commit: 6748e24da18a6cea985d20cc3e1e7920cb743795 - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 - heapsize-0.3.0 diff --git a/stack-8.10.2.yaml b/stack-8.10.2.yaml index a71dfcf756..47638f1788 100644 --- a/stack-8.10.2.yaml +++ b/stack-8.10.2.yaml @@ -19,14 +19,15 @@ ghc-options: "$everything": -haddock extra-deps: - - git: https://github.com/mpickering/apply-refact.git - commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d + - apply-refact-0.9.0.0 - brittany-0.13.1.0 - Cabal-3.0.2.0 - clock-0.7.2 - data-tree-print-0.1.0.2@rev:2 - floskell-0.10.4 - fourmolu-0.3.0.0 + - git: https://github.com/alanz/ghc-exactprint.git + commit: 6748e24da18a6cea985d20cc3e1e7920cb743795 - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 - heapsize-0.3.0 diff --git a/stack-8.10.3.yaml b/stack-8.10.3.yaml index bfa23521f0..cd38185829 100644 --- a/stack-8.10.3.yaml +++ b/stack-8.10.3.yaml @@ -1,4 +1,4 @@ -resolver: nightly-2021-01-01 # first ghc-8.10.3 nightly +resolver: nightly-2021-01-17 packages: - . @@ -19,14 +19,15 @@ ghc-options: "$everything": -haddock extra-deps: - - git: https://github.com/mpickering/apply-refact.git - commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d + - apply-refact-0.9.0.0 - brittany-0.13.1.0 - Cabal-3.0.2.0 - clock-0.7.2 - data-tree-print-0.1.0.2@rev:2 - floskell-0.10.4 - fourmolu-0.3.0.0 + - git: https://github.com/alanz/ghc-exactprint.git + commit: 6748e24da18a6cea985d20cc3e1e7920cb743795 - heapsize-0.3.0 - implicit-hie-cradle-0.3.0.2 - implicit-hie-0.1.2.5 diff --git a/stack-8.6.4.yaml b/stack-8.6.4.yaml index d9efc8cee2..4cdd8443a6 100644 --- a/stack-8.6.4.yaml +++ b/stack-8.6.4.yaml @@ -21,9 +21,7 @@ ghc-options: extra-deps: - aeson-1.5.2.0 - # - apply-refact-0.8.2.1 - - git: https://github.com/mpickering/apply-refact.git - commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d + - apply-refact-0.9.0.0 - ansi-terminal-0.10.3 - base-compat-0.10.5 - brittany-0.13.1.0 @@ -36,10 +34,11 @@ extra-deps: - floskell-0.10.4 - fourmolu-0.3.0.0 - fuzzy-0.1.0.0 - # - ghcide-0.1.0 - ghc-check-0.5.0.1 - ghc-events-0.13.0 - - ghc-exactprint-0.6.3.3 + # - ghc-exactprint-0.6.3.3 + - git: https://github.com/alanz/ghc-exactprint.git + commit: 6748e24da18a6cea985d20cc3e1e7920cb743795 - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 - ghc-lib-parser-ex-8.10.0.17 diff --git a/stack-8.6.5.yaml b/stack-8.6.5.yaml index e62ed4f925..c6e351b1ee 100644 --- a/stack-8.6.5.yaml +++ b/stack-8.6.5.yaml @@ -20,9 +20,7 @@ ghc-options: extra-deps: - aeson-1.5.2.0 - # - apply-refact-0.8.2.1 - - git: https://github.com/mpickering/apply-refact.git - commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d + - apply-refact-0.9.0.0 - ansi-terminal-0.10.3 - base-compat-0.10.5 - brittany-0.13.1.0 @@ -35,10 +33,11 @@ extra-deps: - floskell-0.10.4 - fourmolu-0.3.0.0 - fuzzy-0.1.0.0 - # - ghcide-0.1.0 - ghc-check-0.5.0.1 - ghc-events-0.13.0 - - ghc-exactprint-0.6.3.3 + # - ghc-exactprint-0.6.3.3 + - git: https://github.com/alanz/ghc-exactprint.git + commit: 6748e24da18a6cea985d20cc3e1e7920cb743795 - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 - ghc-lib-parser-ex-8.10.0.17 diff --git a/stack-8.8.2.yaml b/stack-8.8.2.yaml index 264b74559a..4ab1a4c047 100644 --- a/stack-8.8.2.yaml +++ b/stack-8.8.2.yaml @@ -20,9 +20,7 @@ ghc-options: extra-deps: - aeson-1.5.2.0 - # - apply-refact-0.8.2.1 - - git: https://github.com/mpickering/apply-refact.git - commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d + - apply-refact-0.9.0.0 - brittany-0.13.1.0 - butcher-1.3.3.2 - bytestring-trie-0.2.5.0 @@ -31,10 +29,11 @@ extra-deps: - extra-1.7.3 - floskell-0.10.4 - fourmolu-0.3.0.0 - # - ghcide-0.6.0 - ghc-check-0.5.0.1 - ghc-events-0.13.0 - - ghc-exactprint-0.6.3.3 + # - ghc-exactprint-0.6.3.3 + - git: https://github.com/alanz/ghc-exactprint.git + commit: 6748e24da18a6cea985d20cc3e1e7920cb743795 - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 - ghc-lib-parser-ex-8.10.0.17 diff --git a/stack-8.8.3.yaml b/stack-8.8.3.yaml index 3f4491fbc9..ac7df606af 100644 --- a/stack-8.8.3.yaml +++ b/stack-8.8.3.yaml @@ -20,9 +20,7 @@ ghc-options: extra-deps: - aeson-1.5.2.0 - # - apply-refact-0.8.2.1 - - git: https://github.com/mpickering/apply-refact.git - commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d + - apply-refact-0.9.0.0 - brittany-0.13.1.0 - bytestring-trie-0.2.5.0 - cabal-plan-0.6.2.0 @@ -31,8 +29,9 @@ extra-deps: - extra-1.7.3 - floskell-0.10.4 - fourmolu-0.3.0.0 - # - ghcide-0.6.0 - - ghc-exactprint-0.6.3.3 + # - ghc-exactprint-0.6.3.3 + - git: https://github.com/alanz/ghc-exactprint.git + commit: 6748e24da18a6cea985d20cc3e1e7920cb743795 - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 - ghc-trace-events-0.1.2.1 diff --git a/stack-8.8.4.yaml b/stack-8.8.4.yaml index ab3fb4e770..e54ea4ae01 100644 --- a/stack-8.8.4.yaml +++ b/stack-8.8.4.yaml @@ -20,9 +20,7 @@ ghc-options: extra-deps: - aeson-1.5.2.0 - # - apply-refact-0.8.2.1 - - git: https://github.com/mpickering/apply-refact.git - commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d + - apply-refact-0.9.0.0 - brittany-0.13.1.0 - bytestring-trie-0.2.5.0 - cabal-plan-0.6.2.0 @@ -30,8 +28,9 @@ extra-deps: - constrained-dynamic-0.1.0.0 - floskell-0.10.4 - fourmolu-0.3.0.0 - # - ghcide-0.6.0 - - ghc-exactprint-0.6.3.3 + # - ghc-exactprint-0.6.3.3 + - git: https://github.com/alanz/ghc-exactprint.git + commit: 6748e24da18a6cea985d20cc3e1e7920cb743795 - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 - ghc-trace-events-0.1.2.1 diff --git a/stack.yaml b/stack.yaml index 87dad30bff..c2ab6ba6cb 100644 --- a/stack.yaml +++ b/stack.yaml @@ -22,9 +22,7 @@ ghc-options: extra-deps: - aeson-1.5.2.0 - # - apply-refact-0.8.2.1 - - git: https://github.com/mpickering/apply-refact.git - commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d + - apply-refact-0.9.0.0 - ansi-terminal-0.10.3 - base-compat-0.10.5 - brittany-0.13.1.0 @@ -37,10 +35,11 @@ extra-deps: - floskell-0.10.4 - fourmolu-0.3.0.0 - fuzzy-0.1.0.0 - # - ghcide-0.1.0 - ghc-check-0.5.0.1 - ghc-events-0.13.0 - - ghc-exactprint-0.6.3.3 + # - ghc-exactprint-0.6.3.3 + - git: https://github.com/alanz/ghc-exactprint.git + commit: 6748e24da18a6cea985d20cc3e1e7920cb743795 - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 - ghc-lib-parser-ex-8.10.0.17 From 95baf797a6d786a192a171c75b56cf5972ed06f3 Mon Sep 17 00:00:00 2001 From: Javier Neira Date: Mon, 18 Jan 2021 07:46:18 +0100 Subject: [PATCH 3/6] Rephrase warning --- plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs index f4790cc5bd..1f7db37a15 100644 --- a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs +++ b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs @@ -392,9 +392,7 @@ applyHint ide nfp mhint = -- in ghc-exactprint that makes dependent executables non portables. -- See https://github.com/alanz/ghc-exactprint/issues/96. -- WARNING: this code is not thread safe, so if you try to apply several async refactorings - -- in files associated with ghc sessions with different libdir's within the same hls process, - -- it could fail. - -- That case is quite improbable so we assume the risk. + -- it could fail. That case is not very likely so we assume the risk. let withRuntimeLibdir :: IO a -> IO a withRuntimeLibdir = bracket (setEnv key $ topDir dflags) (const $ unsetEnv key) . const where key = "GHC_EXACTPRINT_GHC_LIBDIR" From 78a41e8f617e9ee67acd417387dc3a4f076b7754 Mon Sep 17 00:00:00 2001 From: jneira Date: Mon, 18 Jan 2021 09:13:53 +0100 Subject: [PATCH 4/6] Add required uniplate-1.6.13 --- stack-8.10.1.yaml | 5 +++-- stack-8.10.2.yaml | 4 ++-- stack-8.6.4.yaml | 1 + stack-8.6.5.yaml | 1 + stack-8.8.2.yaml | 1 + stack-8.8.3.yaml | 7 +++---- stack-8.8.4.yaml | 7 +++---- stack.yaml | 1 + 8 files changed, 15 insertions(+), 12 deletions(-) diff --git a/stack-8.10.1.yaml b/stack-8.10.1.yaml index 032ecfa50a..392dce1a79 100644 --- a/stack-8.10.1.yaml +++ b/stack-8.10.1.yaml @@ -31,6 +31,8 @@ extra-deps: commit: 6748e24da18a6cea985d20cc3e1e7920cb743795 - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 + - haskell-lsp-0.23.0.0 + - haskell-lsp-types-0.23.0.0 - heapsize-0.3.0 - hie-bios-0.7.1 - hlint-3.2.3 @@ -47,8 +49,7 @@ extra-deps: - stylish-haskell-0.12.2.0 - semigroups-0.18.5 - temporary-1.2.1.1 - - haskell-lsp-0.23.0.0 - - haskell-lsp-types-0.23.0.0 + - uniplate-1.6.13 configure-options: ghcide: diff --git a/stack-8.10.2.yaml b/stack-8.10.2.yaml index 47638f1788..9ca762d148 100644 --- a/stack-8.10.2.yaml +++ b/stack-8.10.2.yaml @@ -30,6 +30,8 @@ extra-deps: commit: 6748e24da18a6cea985d20cc3e1e7920cb743795 - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 + - haskell-lsp-0.23.0.0 + - haskell-lsp-types-0.23.0.0 - heapsize-0.3.0 - implicit-hie-cradle-0.3.0.2 - implicit-hie-0.1.2.5 @@ -40,8 +42,6 @@ extra-deps: - stylish-haskell-0.12.2.0 - semigroups-0.18.5 - temporary-1.2.1.1 - - haskell-lsp-0.23.0.0 - - haskell-lsp-types-0.23.0.0 configure-options: ghcide: diff --git a/stack-8.6.4.yaml b/stack-8.6.4.yaml index 4cdd8443a6..edfdcf6497 100644 --- a/stack-8.6.4.yaml +++ b/stack-8.6.4.yaml @@ -79,6 +79,7 @@ extra-deps: - these-1.1.1.1 - type-equality-1 - topograph-1 + - uniplate-1.6.13 - with-utf8-1.0.2.1@sha256:95c02fffa643ddbeb092359802a512007c3e644cd509809f4716ad54592c437b,3057 - th-env-0.1.0.2@sha256:d8f1f37f42a8f1a22404d7d0579528af18f5dac7232cca6bdbd5117c115a0ad5,1370 diff --git a/stack-8.6.5.yaml b/stack-8.6.5.yaml index c6e351b1ee..31fab4bf90 100644 --- a/stack-8.6.5.yaml +++ b/stack-8.6.5.yaml @@ -78,6 +78,7 @@ extra-deps: - these-1.1.1.1 - type-equality-1 - topograph-1 + - uniplate-1.6.13 - with-utf8-1.0.2.1@sha256:95c02fffa643ddbeb092359802a512007c3e644cd509809f4716ad54592c437b,3057 - th-env-0.1.0.2@sha256:d8f1f37f42a8f1a22404d7d0579528af18f5dac7232cca6bdbd5117c115a0ad5,1370 diff --git a/stack-8.8.2.yaml b/stack-8.8.2.yaml index 4ab1a4c047..5ad422fe8e 100644 --- a/stack-8.8.2.yaml +++ b/stack-8.8.2.yaml @@ -63,6 +63,7 @@ extra-deps: - stylish-haskell-0.12.2.0 - temporary-1.2.1.1 - these-1.1.1.1 + - uniplate-1.6.13 - with-utf8-1.0.2.1@sha256:95c02fffa643ddbeb092359802a512007c3e644cd509809f4716ad54592c437b,3057 - th-env-0.1.0.2@sha256:d8f1f37f42a8f1a22404d7d0579528af18f5dac7232cca6bdbd5117c115a0ad5,1370 diff --git a/stack-8.8.3.yaml b/stack-8.8.3.yaml index ac7df606af..c0a975de35 100644 --- a/stack-8.8.3.yaml +++ b/stack-8.8.3.yaml @@ -35,6 +35,8 @@ extra-deps: - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 - ghc-trace-events-0.1.2.1 + - haskell-lsp-0.23.0.0 + - haskell-lsp-types-0.23.0.0 - haskell-src-exts-1.21.1 - heapsize-0.3.0 - hie-bios-0.7.1 @@ -53,12 +55,9 @@ extra-deps: - refinery-0.3.0.0 - retrie-0.1.1.1 - semigroups-0.18.5 - # - github: wz1000/shake - # commit: fb3859dca2e54d1bbb2c873e68ed225fa179fbef - stylish-haskell-0.12.2.0 - temporary-1.2.1.1 - - haskell-lsp-0.23.0.0 - - haskell-lsp-types-0.23.0.0 + - uniplate-1.6.13 configure-options: ghcide: diff --git a/stack-8.8.4.yaml b/stack-8.8.4.yaml index e54ea4ae01..47e3dadd7f 100644 --- a/stack-8.8.4.yaml +++ b/stack-8.8.4.yaml @@ -34,6 +34,8 @@ extra-deps: - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 - ghc-trace-events-0.1.2.1 + - haskell-lsp-0.23.0.0 + - haskell-lsp-types-0.23.0.0 - haskell-src-exts-1.21.1 - heapsize-0.3.0 - hie-bios-0.7.1 @@ -51,12 +53,9 @@ extra-deps: - refinery-0.3.0.0 - retrie-0.1.1.1 - semigroups-0.18.5 - # - github: wz1000/shake - # commit: fb3859dca2e54d1bbb2c873e68ed225fa179fbef - stylish-haskell-0.12.2.0 - temporary-1.2.1.1 - - haskell-lsp-0.23.0.0 - - haskell-lsp-types-0.23.0.0 + - uniplate-1.6.13 configure-options: ghcide: diff --git a/stack.yaml b/stack.yaml index c2ab6ba6cb..a544abb25a 100644 --- a/stack.yaml +++ b/stack.yaml @@ -80,6 +80,7 @@ extra-deps: - these-1.1.1.1 - type-equality-1 - topograph-1 + - uniplate-1.6.13 - with-utf8-1.0.2.1@sha256:95c02fffa643ddbeb092359802a512007c3e644cd509809f4716ad54592c437b,3057 - th-env-0.1.0.2@sha256:d8f1f37f42a8f1a22404d7d0579528af18f5dac7232cca6bdbd5117c115a0ad5,1370 From fcfc83a7d18a9c3168a56f7eff97a9c42885973f Mon Sep 17 00:00:00 2001 From: jneira Date: Mon, 18 Jan 2021 23:30:29 +0100 Subject: [PATCH 5/6] Use bracket_ to simplify code --- plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs index 1f7db37a15..b65e95c1ec 100644 --- a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs +++ b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs @@ -394,7 +394,7 @@ applyHint ide nfp mhint = -- WARNING: this code is not thread safe, so if you try to apply several async refactorings -- it could fail. That case is not very likely so we assume the risk. let withRuntimeLibdir :: IO a -> IO a - withRuntimeLibdir = bracket (setEnv key $ topDir dflags) (const $ unsetEnv key) . const + withRuntimeLibdir = bracket_ (setEnv key $ topDir dflags) (unsetEnv key) where key = "GHC_EXACTPRINT_GHC_LIBDIR" res <- liftIO $ withSystemTempFile (takeFileName fp) $ \temp h -> do From 4b48f5042add69ba95924324ce53ccacdac3f687 Mon Sep 17 00:00:00 2001 From: jneira Date: Mon, 18 Jan 2021 23:31:01 +0100 Subject: [PATCH 6/6] Use runtime ghc libdir for brittany --- plugins/default/src/Ide/Plugin/Brittany.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/default/src/Ide/Plugin/Brittany.hs b/plugins/default/src/Ide/Plugin/Brittany.hs index 6001363181..a12de7fe9a 100644 --- a/plugins/default/src/Ide/Plugin/Brittany.hs +++ b/plugins/default/src/Ide/Plugin/Brittany.hs @@ -1,14 +1,16 @@ module Ide.Plugin.Brittany where +import Control.Exception (bracket_) import Control.Lens import Control.Monad.IO.Class import Control.Monad.Trans.Maybe (MaybeT, runMaybeT) import Data.Coerce +import Data.Maybe (maybeToList) import Data.Semigroup import Data.Text (Text) import qualified Data.Text as T import Development.IDE --- import Development.IDE.Plugin.Formatter +import Development.IDE.GHC.Compat (topDir, ModSummary(ms_hspp_opts)) import Language.Haskell.Brittany import Language.Haskell.LSP.Types as J import qualified Language.Haskell.LSP.Types.Lens as J @@ -16,7 +18,7 @@ import Ide.PluginUtils import Ide.Types import System.FilePath -import Data.Maybe (maybeToList) +import System.Environment (setEnv, unsetEnv) descriptor :: PluginId -> PluginDescriptor IdeState descriptor plId = (defaultPluginDescriptor plId) @@ -28,14 +30,17 @@ descriptor plId = (defaultPluginDescriptor plId) -- If the provider fails an error is returned that can be displayed to the user. provider :: FormattingProvider IdeState IO -provider _lf _ideState typ contents fp opts = do +provider _lf ide typ contents nfp opts = do -- text uri formatType opts = pluginGetFile "brittanyCmd: " uri $ \fp -> do - confFile <- liftIO $ getConfFile fp + confFile <- liftIO $ getConfFile nfp let (range, selectedContents) = case typ of FormatText -> (fullRange contents, contents) FormatRange r -> (normalize r, extractRange r contents) - - res <- formatText confFile opts selectedContents + (modsum, _) <- runAction "brittany" ide $ use_ GetModSummary nfp + let dflags = ms_hspp_opts modsum + let withRuntimeLibdir = bracket_ (setEnv key $ topDir dflags) (unsetEnv key) + where key = "GHC_EXACTPRINT_GHC_LIBDIR" + res <- withRuntimeLibdir $ formatText confFile opts selectedContents case res of Left err -> return $ Left $ responseError (T.pack $ "brittanyCmd: " ++ unlines (map showErr err)) Right newText -> return $ Right $ J.List [TextEdit range newText]