Skip to content

Commit 4ecf9d3

Browse files
jneiramergify[bot]
andauthored
Use the runtime ghc libdir for ghc-exactprint (#1225)
* Use runtime libdir for ghc-exactprint * Use released apply-refact and master ghc-exactprint * Rephrase warning * Add required uniplate-1.6.13 * Use bracket_ to simplify code * Use runtime ghc libdir for brittany Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 18227b3 commit 4ecf9d3

File tree

12 files changed

+78
-62
lines changed

12 files changed

+78
-62
lines changed

cabal.project

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ packages:
1515

1616
source-repository-package
1717
type: git
18-
location: https://github.com/mpickering/apply-refact.git
19-
tag: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d
18+
location: https://github.com/alanz/ghc-exactprint.git
19+
tag: 6748e24da18a6cea985d20cc3e1e7920cb743795
2020

2121
tests: true
2222

@@ -30,7 +30,7 @@ package ghcide
3030

3131
write-ghc-environment-files: never
3232

33-
index-state: 2021-01-14T12:49:26Z
33+
index-state: 2021-01-17T17:47:48Z
3434

3535
allow-newer:
3636
active:base,

plugins/default/src/Ide/Plugin/Brittany.hs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
module Ide.Plugin.Brittany where
22

3+
import Control.Exception (bracket_)
34
import Control.Lens
45
import Control.Monad.IO.Class
56
import Control.Monad.Trans.Maybe (MaybeT, runMaybeT)
67
import Data.Coerce
8+
import Data.Maybe (maybeToList)
79
import Data.Semigroup
810
import Data.Text (Text)
911
import qualified Data.Text as T
1012
import Development.IDE
11-
-- import Development.IDE.Plugin.Formatter
13+
import Development.IDE.GHC.Compat (topDir, ModSummary(ms_hspp_opts))
1214
import Language.Haskell.Brittany
1315
import Language.Haskell.LSP.Types as J
1416
import qualified Language.Haskell.LSP.Types.Lens as J
1517
import Ide.PluginUtils
1618
import Ide.Types
1719

1820
import System.FilePath
19-
import Data.Maybe (maybeToList)
21+
import System.Environment (setEnv, unsetEnv)
2022

2123
descriptor :: PluginId -> PluginDescriptor IdeState
2224
descriptor plId = (defaultPluginDescriptor plId)
@@ -28,14 +30,17 @@ descriptor plId = (defaultPluginDescriptor plId)
2830
-- If the provider fails an error is returned that can be displayed to the user.
2931
provider
3032
:: FormattingProvider IdeState IO
31-
provider _lf _ideState typ contents fp opts = do
33+
provider _lf ide typ contents nfp opts = do
3234
-- text uri formatType opts = pluginGetFile "brittanyCmd: " uri $ \fp -> do
33-
confFile <- liftIO $ getConfFile fp
35+
confFile <- liftIO $ getConfFile nfp
3436
let (range, selectedContents) = case typ of
3537
FormatText -> (fullRange contents, contents)
3638
FormatRange r -> (normalize r, extractRange r contents)
37-
38-
res <- formatText confFile opts selectedContents
39+
(modsum, _) <- runAction "brittany" ide $ use_ GetModSummary nfp
40+
let dflags = ms_hspp_opts modsum
41+
let withRuntimeLibdir = bracket_ (setEnv key $ topDir dflags) (unsetEnv key)
42+
where key = "GHC_EXACTPRINT_GHC_LIBDIR"
43+
res <- withRuntimeLibdir $ formatText confFile opts selectedContents
3944
case res of
4045
Left err -> return $ Left $ responseError (T.pack $ "brittanyCmd: " ++ unlines (map showErr err))
4146
Right newText -> return $ Right $ J.List [TextEdit range newText]

plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs

+14-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ import Development.IDE.Core.Shake (getDiagnostics)
3838
import Data.List (nub)
3939
import "ghc-lib" GHC hiding (DynFlags(..), ms_hspp_opts)
4040
import "ghc-lib-parser" GHC.LanguageExtensions (Extension)
41+
import "ghc" DynFlags as RealGHC.DynFlags (topDir)
4142
import "ghc" GHC as RealGHC (DynFlags(..))
4243
import "ghc" HscTypes as RealGHC.HscTypes (hsc_dflags, ms_hspp_opts)
4344
import qualified "ghc" EnumSet as EnumSet
4445
import Language.Haskell.GhclibParserEx.GHC.Driver.Session as GhclibParserEx (readExtension)
46+
import System.Environment(setEnv, unsetEnv)
4547
import System.FilePath (takeFileName)
4648
import System.IO (hPutStr, noNewlineTranslation, hSetNewlineMode, utf8, hSetEncoding, IOMode(WriteMode), withFile, hClose)
4749
import System.IO.Temp
@@ -359,6 +361,8 @@ applyHint ide nfp mhint =
359361
let fp = fromNormalizedFilePath nfp
360362
(_, mbOldContent) <- liftIO $ runAction' $ getFileContents nfp
361363
oldContent <- maybe (liftIO $ T.readFile fp) return mbOldContent
364+
(modsum, _) <- liftIO $ runAction' $ use_ GetModSummary nfp
365+
let dflags = ms_hspp_opts modsum
362366
-- set Nothing as "position" for "applyRefactorings" because
363367
-- applyRefactorings expects the provided position to be _within_ the scope
364368
-- of each refactoring it will apply.
@@ -380,6 +384,15 @@ applyHint ide nfp mhint =
380384
hSetEncoding h utf8
381385
hSetNewlineMode h noNewlineTranslation
382386
hPutStr h (T.unpack txt)
387+
-- Setting a environment variable with the libdir used by ghc-exactprint.
388+
-- It is a workaround for an error caused by the use of a hadcoded at compile time libdir
389+
-- in ghc-exactprint that makes dependent executables non portables.
390+
-- See https://github.com/alanz/ghc-exactprint/issues/96.
391+
-- WARNING: this code is not thread safe, so if you try to apply several async refactorings
392+
-- it could fail. That case is not very likely so we assume the risk.
393+
let withRuntimeLibdir :: IO a -> IO a
394+
withRuntimeLibdir = bracket_ (setEnv key $ topDir dflags) (unsetEnv key)
395+
where key = "GHC_EXACTPRINT_GHC_LIBDIR"
383396
res <-
384397
liftIO $ withSystemTempFile (takeFileName fp) $ \temp h -> do
385398
hClose h
@@ -389,7 +402,7 @@ applyHint ide nfp mhint =
389402
-- We have to reparse extensions to remove the invalid ones
390403
let (enabled, disabled, _invalid) = parseExtensions $ map show exts
391404
let refactExts = map show $ enabled ++ disabled
392-
(Right <$> applyRefactorings Nothing commands temp refactExts)
405+
(Right <$> withRuntimeLibdir (applyRefactorings Nothing commands temp refactExts))
393406
`catches` errorHandlers
394407
#else
395408
mbParsedModule <- liftIO $ runAction' $ getParsedModuleWithComments nfp
@@ -399,8 +412,6 @@ applyHint ide nfp mhint =
399412
Just pm -> do
400413
let anns = pm_annotations pm
401414
let modu = pm_parsed_source pm
402-
(modsum, _) <- liftIO $ runAction' $ use_ GetModSummary nfp
403-
let dflags = ms_hspp_opts modsum
404415
-- apply-refact uses RigidLayout
405416
let rigidLayout = deltaOptions RigidLayout
406417
(anns', modu') <-

stack-8.10.1.yaml

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ ghc-options:
1919
"$everything": -haddock
2020

2121
extra-deps:
22-
- git: https://github.com/mpickering/apply-refact.git
23-
commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d
22+
- apply-refact-0.9.0.0
2423
- brittany-0.13.1.0
2524
- Cabal-3.0.2.0
2625
- clock-0.7.2
2726
- data-tree-print-0.1.0.2@rev:2
2827
- floskell-0.10.4
2928
- fourmolu-0.3.0.0
30-
- ghc-exactprint-0.6.3.3
29+
# - ghc-exactprint-0.6.3.3
30+
- git: https://github.com/alanz/ghc-exactprint.git
31+
commit: 6748e24da18a6cea985d20cc3e1e7920cb743795
3132
- ghc-lib-8.10.3.20201220
3233
- ghc-lib-parser-8.10.3.20201220
34+
- haskell-lsp-0.23.0.0
35+
- haskell-lsp-types-0.23.0.0
3336
- heapsize-0.3.0
3437
- hie-bios-0.7.1
3538
- hlint-3.2.3
@@ -46,8 +49,7 @@ extra-deps:
4649
- stylish-haskell-0.12.2.0
4750
- semigroups-0.18.5
4851
- temporary-1.2.1.1
49-
- haskell-lsp-0.23.0.0
50-
- haskell-lsp-types-0.23.0.0
52+
- uniplate-1.6.13
5153

5254
configure-options:
5355
ghcide:

stack-8.10.2.yaml

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ ghc-options:
1919
"$everything": -haddock
2020

2121
extra-deps:
22-
- git: https://github.com/mpickering/apply-refact.git
23-
commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d
22+
- apply-refact-0.9.0.0
2423
- brittany-0.13.1.0
2524
- Cabal-3.0.2.0
2625
- clock-0.7.2
2726
- data-tree-print-0.1.0.2@rev:2
2827
- floskell-0.10.4
2928
- fourmolu-0.3.0.0
29+
- git: https://github.com/alanz/ghc-exactprint.git
30+
commit: 6748e24da18a6cea985d20cc3e1e7920cb743795
3031
- ghc-lib-8.10.3.20201220
3132
- ghc-lib-parser-8.10.3.20201220
33+
- haskell-lsp-0.23.0.0
34+
- haskell-lsp-types-0.23.0.0
3235
- heapsize-0.3.0
3336
- implicit-hie-cradle-0.3.0.2
3437
- implicit-hie-0.1.2.5
@@ -39,8 +42,6 @@ extra-deps:
3942
- stylish-haskell-0.12.2.0
4043
- semigroups-0.18.5
4144
- temporary-1.2.1.1
42-
- haskell-lsp-0.23.0.0
43-
- haskell-lsp-types-0.23.0.0
4445

4546
configure-options:
4647
ghcide:

stack-8.10.3.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resolver: nightly-2021-01-01 # first ghc-8.10.3 nightly
1+
resolver: nightly-2021-01-17
22

33
packages:
44
- .
@@ -19,14 +19,15 @@ ghc-options:
1919
"$everything": -haddock
2020

2121
extra-deps:
22-
- git: https://github.com/mpickering/apply-refact.git
23-
commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d
22+
- apply-refact-0.9.0.0
2423
- brittany-0.13.1.0
2524
- Cabal-3.0.2.0
2625
- clock-0.7.2
2726
- data-tree-print-0.1.0.2@rev:2
2827
- floskell-0.10.4
2928
- fourmolu-0.3.0.0
29+
- git: https://github.com/alanz/ghc-exactprint.git
30+
commit: 6748e24da18a6cea985d20cc3e1e7920cb743795
3031
- heapsize-0.3.0
3132
- implicit-hie-cradle-0.3.0.2
3233
- implicit-hie-0.1.2.5

stack-8.6.4.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ ghc-options:
2121

2222
extra-deps:
2323
- aeson-1.5.2.0
24-
# - apply-refact-0.8.2.1
25-
- git: https://github.com/mpickering/apply-refact.git
26-
commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d
24+
- apply-refact-0.9.0.0
2725
- ansi-terminal-0.10.3
2826
- base-compat-0.10.5
2927
- brittany-0.13.1.0
@@ -36,10 +34,11 @@ extra-deps:
3634
- floskell-0.10.4
3735
- fourmolu-0.3.0.0
3836
- fuzzy-0.1.0.0
39-
# - ghcide-0.1.0
4037
- ghc-check-0.5.0.1
4138
- ghc-events-0.13.0
42-
- ghc-exactprint-0.6.3.3
39+
# - ghc-exactprint-0.6.3.3
40+
- git: https://github.com/alanz/ghc-exactprint.git
41+
commit: 6748e24da18a6cea985d20cc3e1e7920cb743795
4342
- ghc-lib-8.10.3.20201220
4443
- ghc-lib-parser-8.10.3.20201220
4544
- ghc-lib-parser-ex-8.10.0.17
@@ -80,6 +79,7 @@ extra-deps:
8079
- these-1.1.1.1
8180
- type-equality-1
8281
- topograph-1
82+
- uniplate-1.6.13
8383
- with-utf8-1.0.2.1@sha256:95c02fffa643ddbeb092359802a512007c3e644cd509809f4716ad54592c437b,3057
8484
- th-env-0.1.0.2@sha256:d8f1f37f42a8f1a22404d7d0579528af18f5dac7232cca6bdbd5117c115a0ad5,1370
8585

stack-8.6.5.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ ghc-options:
2020

2121
extra-deps:
2222
- aeson-1.5.2.0
23-
# - apply-refact-0.8.2.1
24-
- git: https://github.com/mpickering/apply-refact.git
25-
commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d
23+
- apply-refact-0.9.0.0
2624
- ansi-terminal-0.10.3
2725
- base-compat-0.10.5
2826
- brittany-0.13.1.0
@@ -35,10 +33,11 @@ extra-deps:
3533
- floskell-0.10.4
3634
- fourmolu-0.3.0.0
3735
- fuzzy-0.1.0.0
38-
# - ghcide-0.1.0
3936
- ghc-check-0.5.0.1
4037
- ghc-events-0.13.0
41-
- ghc-exactprint-0.6.3.3
38+
# - ghc-exactprint-0.6.3.3
39+
- git: https://github.com/alanz/ghc-exactprint.git
40+
commit: 6748e24da18a6cea985d20cc3e1e7920cb743795
4241
- ghc-lib-8.10.3.20201220
4342
- ghc-lib-parser-8.10.3.20201220
4443
- ghc-lib-parser-ex-8.10.0.17
@@ -79,6 +78,7 @@ extra-deps:
7978
- these-1.1.1.1
8079
- type-equality-1
8180
- topograph-1
81+
- uniplate-1.6.13
8282
- with-utf8-1.0.2.1@sha256:95c02fffa643ddbeb092359802a512007c3e644cd509809f4716ad54592c437b,3057
8383
- th-env-0.1.0.2@sha256:d8f1f37f42a8f1a22404d7d0579528af18f5dac7232cca6bdbd5117c115a0ad5,1370
8484

stack-8.8.2.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ ghc-options:
2020

2121
extra-deps:
2222
- aeson-1.5.2.0
23-
# - apply-refact-0.8.2.1
24-
- git: https://github.com/mpickering/apply-refact.git
25-
commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d
23+
- apply-refact-0.9.0.0
2624
- brittany-0.13.1.0
2725
- butcher-1.3.3.2
2826
- bytestring-trie-0.2.5.0
@@ -31,10 +29,11 @@ extra-deps:
3129
- extra-1.7.3
3230
- floskell-0.10.4
3331
- fourmolu-0.3.0.0
34-
# - ghcide-0.6.0
3532
- ghc-check-0.5.0.1
3633
- ghc-events-0.13.0
37-
- ghc-exactprint-0.6.3.3
34+
# - ghc-exactprint-0.6.3.3
35+
- git: https://github.com/alanz/ghc-exactprint.git
36+
commit: 6748e24da18a6cea985d20cc3e1e7920cb743795
3837
- ghc-lib-8.10.3.20201220
3938
- ghc-lib-parser-8.10.3.20201220
4039
- ghc-lib-parser-ex-8.10.0.17
@@ -64,6 +63,7 @@ extra-deps:
6463
- stylish-haskell-0.12.2.0
6564
- temporary-1.2.1.1
6665
- these-1.1.1.1
66+
- uniplate-1.6.13
6767
- with-utf8-1.0.2.1@sha256:95c02fffa643ddbeb092359802a512007c3e644cd509809f4716ad54592c437b,3057
6868
- th-env-0.1.0.2@sha256:d8f1f37f42a8f1a22404d7d0579528af18f5dac7232cca6bdbd5117c115a0ad5,1370
6969

stack-8.8.3.yaml

+7-9
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ ghc-options:
2020

2121
extra-deps:
2222
- aeson-1.5.2.0
23-
# - apply-refact-0.8.2.1
24-
- git: https://github.com/mpickering/apply-refact.git
25-
commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d
23+
- apply-refact-0.9.0.0
2624
- brittany-0.13.1.0
2725
- bytestring-trie-0.2.5.0
2826
- cabal-plan-0.6.2.0
@@ -31,11 +29,14 @@ extra-deps:
3129
- extra-1.7.3
3230
- floskell-0.10.4
3331
- fourmolu-0.3.0.0
34-
# - ghcide-0.6.0
35-
- ghc-exactprint-0.6.3.3
32+
# - ghc-exactprint-0.6.3.3
33+
- git: https://github.com/alanz/ghc-exactprint.git
34+
commit: 6748e24da18a6cea985d20cc3e1e7920cb743795
3635
- ghc-lib-8.10.3.20201220
3736
- ghc-lib-parser-8.10.3.20201220
3837
- ghc-trace-events-0.1.2.1
38+
- haskell-lsp-0.23.0.0
39+
- haskell-lsp-types-0.23.0.0
3940
- haskell-src-exts-1.21.1
4041
- heapsize-0.3.0
4142
- hie-bios-0.7.1
@@ -54,12 +55,9 @@ extra-deps:
5455
- refinery-0.3.0.0
5556
- retrie-0.1.1.1
5657
- semigroups-0.18.5
57-
# - github: wz1000/shake
58-
# commit: fb3859dca2e54d1bbb2c873e68ed225fa179fbef
5958
- stylish-haskell-0.12.2.0
6059
- temporary-1.2.1.1
61-
- haskell-lsp-0.23.0.0
62-
- haskell-lsp-types-0.23.0.0
60+
- uniplate-1.6.13
6361

6462
configure-options:
6563
ghcide:

stack-8.8.4.yaml

+7-9
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,22 @@ ghc-options:
2020

2121
extra-deps:
2222
- aeson-1.5.2.0
23-
# - apply-refact-0.8.2.1
24-
- git: https://github.com/mpickering/apply-refact.git
25-
commit: 4fbd3a3a9b408bd31080848feb6b78e13c3eeb6d
23+
- apply-refact-0.9.0.0
2624
- brittany-0.13.1.0
2725
- bytestring-trie-0.2.5.0
2826
- cabal-plan-0.6.2.0
2927
- clock-0.7.2
3028
- constrained-dynamic-0.1.0.0
3129
- floskell-0.10.4
3230
- fourmolu-0.3.0.0
33-
# - ghcide-0.6.0
34-
- ghc-exactprint-0.6.3.3
31+
# - ghc-exactprint-0.6.3.3
32+
- git: https://github.com/alanz/ghc-exactprint.git
33+
commit: 6748e24da18a6cea985d20cc3e1e7920cb743795
3534
- ghc-lib-8.10.3.20201220
3635
- ghc-lib-parser-8.10.3.20201220
3736
- ghc-trace-events-0.1.2.1
37+
- haskell-lsp-0.23.0.0
38+
- haskell-lsp-types-0.23.0.0
3839
- haskell-src-exts-1.21.1
3940
- heapsize-0.3.0
4041
- hie-bios-0.7.1
@@ -52,12 +53,9 @@ extra-deps:
5253
- refinery-0.3.0.0
5354
- retrie-0.1.1.1
5455
- semigroups-0.18.5
55-
# - github: wz1000/shake
56-
# commit: fb3859dca2e54d1bbb2c873e68ed225fa179fbef
5756
- stylish-haskell-0.12.2.0
5857
- temporary-1.2.1.1
59-
- haskell-lsp-0.23.0.0
60-
- haskell-lsp-types-0.23.0.0
58+
- uniplate-1.6.13
6159

6260
configure-options:
6361
ghcide:

0 commit comments

Comments
 (0)