Skip to content

Commit 43b33a5

Browse files
jneiraAilrun
andauthored
Use runtime ghc libdir for ghc-exactprint and ghc-8.10 (#1451)
* Use las ghc-lib-8.10 * Use runtime libdir for ghc-8.10 * Use ghc-lib-8.10.4 Co-authored-by: Junyoung/Clare Jang <jjc9310@gmail.com>
1 parent 3aa8da3 commit 43b33a5

10 files changed

+32
-37
lines changed

plugins/hls-hlint-plugin/hls-hlint-plugin.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ library
5353
, transformers
5454
, unordered-containers
5555

56-
if ((!flag(ghc-lib) && impl(ghc >=8.10.1)) && impl(ghc <8.11.0))
56+
if (!flag(ghc-lib) && impl(ghc >=8.10.1) && impl(ghc <9.0.0))
5757
build-depends: ghc ^>= 8.10
5858

5959
else
6060
build-depends:
6161
, ghc
62-
, ghc-lib ^>= 8.10.2.20200916
62+
, ghc-lib ^>= 8.10.4.20210206
6363
, ghc-lib-parser-ex ^>= 8.10
6464

6565
cpp-options: -DHLINT_ON_GHC_LIB

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

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ import "ghc-lib-parser" GHC.LanguageExtensions (Extension)
5151
import "ghc" HscTypes as RealGHC.HscTypes (hsc_dflags,
5252
ms_hspp_opts)
5353
import Language.Haskell.GhclibParserEx.GHC.Driver.Session as GhclibParserEx (readExtension)
54-
import System.Environment (setEnv,
55-
unsetEnv)
5654
import System.FilePath (takeFileName)
5755
import System.IO (IOMode (WriteMode),
5856
hClose,
@@ -86,6 +84,8 @@ import qualified Language.LSP.Types.Lens as LSP
8684
import GHC.Generics (Generic)
8785
import Text.Regex.TDFA.Text ()
8886

87+
import System.Environment (setEnv,
88+
unsetEnv)
8989
-- ---------------------------------------------------------------------
9090

9191
descriptor :: PluginId -> PluginDescriptor IdeState
@@ -380,36 +380,27 @@ applyHint ide nfp mhint =
380380
oldContent <- maybe (liftIO $ T.readFile fp) return mbOldContent
381381
(modsum, _) <- liftIO $ runAction' $ use_ GetModSummary nfp
382382
let dflags = ms_hspp_opts modsum
383+
-- Setting a environment variable with the libdir used by ghc-exactprint.
384+
-- It is a workaround for an error caused by the use of a hadcoded at compile time libdir
385+
-- in ghc-exactprint that makes dependent executables non portables.
386+
-- See https://github.com/alanz/ghc-exactprint/issues/96.
387+
-- WARNING: this code is not thread safe, so if you try to apply several async refactorings
388+
-- it could fail. That case is not very likely so we assume the risk.
389+
let withRuntimeLibdir :: IO a -> IO a
390+
withRuntimeLibdir = bracket_ (setEnv key $ topDir dflags) (unsetEnv key)
391+
where key = "GHC_EXACTPRINT_GHC_LIBDIR"
383392
-- set Nothing as "position" for "applyRefactorings" because
384393
-- applyRefactorings expects the provided position to be _within_ the scope
385394
-- of each refactoring it will apply.
386395
-- But "Idea"s returned by HLint point to starting position of the expressions
387396
-- that contain refactorings, so they are often outside the refactorings' boundaries.
388-
-- Example:
389-
-- Given an expression "hlintTest = reid $ (myid ())"
390-
-- Hlint returns an idea at the position (1,13)
391-
-- That contains "Redundant brackets" refactoring at position (1,20):
392-
--
393-
-- [("src/App/Test.hs:5:13: Warning: Redundant bracket\nFound:\n reid $ (myid ())\nWhy not:\n reid $ myid ()\n",[Replace {rtype = Expr, pos = SrcSpan {startLine = 5, startCol = 20, endLine = 5, endCol = 29}, subts = [("x",SrcSpan {startLine = 5, startCol = 21, endLine = 5, endCol = 28})], orig = "x"}])]
394-
--
395-
-- If we provide "applyRefactorings" with "Just (1,13)" then
396-
-- the "Redundant bracket" hint will never be executed
397-
-- because SrcSpan (1,20,??,??) doesn't contain position (1,13).
397+
let position = Nothing
398398
#ifdef HLINT_ON_GHC_LIB
399399
let writeFileUTF8NoNewLineTranslation file txt =
400400
withFile file WriteMode $ \h -> do
401401
hSetEncoding h utf8
402402
hSetNewlineMode h noNewlineTranslation
403403
hPutStr h (T.unpack txt)
404-
-- Setting a environment variable with the libdir used by ghc-exactprint.
405-
-- It is a workaround for an error caused by the use of a hadcoded at compile time libdir
406-
-- in ghc-exactprint that makes dependent executables non portables.
407-
-- See https://github.com/alanz/ghc-exactprint/issues/96.
408-
-- WARNING: this code is not thread safe, so if you try to apply several async refactorings
409-
-- it could fail. That case is not very likely so we assume the risk.
410-
let withRuntimeLibdir :: IO a -> IO a
411-
withRuntimeLibdir = bracket_ (setEnv key $ topDir dflags) (unsetEnv key)
412-
where key = "GHC_EXACTPRINT_GHC_LIBDIR"
413404
res <-
414405
liftIO $ withSystemTempFile (takeFileName fp) $ \temp h -> do
415406
hClose h
@@ -419,7 +410,7 @@ applyHint ide nfp mhint =
419410
-- We have to reparse extensions to remove the invalid ones
420411
let (enabled, disabled, _invalid) = parseExtensions $ map show exts
421412
let refactExts = map show $ enabled ++ disabled
422-
(Right <$> withRuntimeLibdir (applyRefactorings Nothing commands temp refactExts))
413+
(Right <$> withRuntimeLibdir (applyRefactorings position commands temp refactExts))
423414
`catches` errorHandlers
424415
#else
425416
mbParsedModule <- liftIO $ runAction' $ getParsedModuleWithComments nfp
@@ -433,7 +424,7 @@ applyHint ide nfp mhint =
433424
let rigidLayout = deltaOptions RigidLayout
434425
(anns', modu') <-
435426
ExceptT $ return $ postParseTransform (Right (anns, [], dflags, modu)) rigidLayout
436-
liftIO $ (Right <$> applyRefactorings' Nothing commands anns' modu')
427+
liftIO $ (Right <$> withRuntimeLibdir (applyRefactorings' position commands anns' modu'))
437428
`catches` errorHandlers
438429
#endif
439430
case res of

stack-8.10.2.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ extra-deps:
2727
- floskell-0.10.4
2828
- fourmolu-0.3.0.0
2929
- ghc-exactprint-0.6.3.4
30-
- ghc-lib-8.10.3.20201220
31-
- ghc-lib-parser-8.10.3.20201220
30+
- ghc-lib-8.10.4.20210206
31+
- ghc-lib-parser-8.10.4.20210206
3232
- lsp-1.1.1.0
3333
- lsp-types-1.1.0.0
3434
- lsp-test-0.13.0.0

stack-8.10.3.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extra-deps:
2525
- data-tree-print-0.1.0.2@rev:2
2626
- floskell-0.10.4
2727
- fourmolu-0.3.0.0
28+
- ghc-lib-8.10.4.20210206
29+
- ghc-lib-parser-8.10.4.20210206
2830
- heapsize-0.3.0
2931
- hie-bios-0.7.4
3032
- implicit-hie-cradle-0.3.0.2

stack-8.6.4.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ extra-deps:
3636
- ghc-check-0.5.0.1
3737
- ghc-events-0.13.0
3838
- ghc-exactprint-0.6.3.4
39-
- ghc-lib-8.10.3.20201220
40-
- ghc-lib-parser-8.10.3.20201220
39+
- ghc-lib-8.10.4.20210206
40+
- ghc-lib-parser-8.10.4.20210206
4141
- ghc-lib-parser-ex-8.10.0.17
4242
- ghc-source-gen-0.4.0.0
4343
- ghc-trace-events-0.1.2.1

stack-8.6.5.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ extra-deps:
3535
- ghc-check-0.5.0.1
3636
- ghc-events-0.13.0
3737
- ghc-exactprint-0.6.3.4
38-
- ghc-lib-8.10.3.20201220
39-
- ghc-lib-parser-8.10.3.20201220
38+
- ghc-lib-8.10.4.20210206
39+
- ghc-lib-parser-8.10.4.20210206
4040
- ghc-lib-parser-ex-8.10.0.17
4141
- ghc-source-gen-0.4.0.0
4242
- ghc-trace-events-0.1.2.1

stack-8.8.2.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ extra-deps:
3131
- ghc-check-0.5.0.1
3232
- ghc-events-0.13.0
3333
- ghc-exactprint-0.6.3.4
34-
- ghc-lib-8.10.3.20201220
35-
- ghc-lib-parser-8.10.3.20201220
34+
- ghc-lib-8.10.4.20210206
35+
- ghc-lib-parser-8.10.4.20210206
3636
- ghc-lib-parser-ex-8.10.0.17
3737
- ghc-trace-events-0.1.2.1
3838
- haddock-library-1.8.0

stack-8.8.3.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ extra-deps:
2929
- floskell-0.10.4
3030
- fourmolu-0.3.0.0
3131
- ghc-exactprint-0.6.3.4
32-
- ghc-lib-8.10.3.20201220
33-
- ghc-lib-parser-8.10.3.20201220
32+
- ghc-lib-8.10.4.20210206
33+
- ghc-lib-parser-8.10.4.20210206
3434
- ghc-trace-events-0.1.2.1
3535
- haskell-src-exts-1.21.1
3636
- heapsize-0.3.0

stack-8.8.4.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ extra-deps:
2929
- floskell-0.10.4
3030
- fourmolu-0.3.0.0
3131
- ghc-exactprint-0.6.3.4
32+
- ghc-lib-8.10.4.20210206
33+
- ghc-lib-parser-8.10.4.20210206
3234
- ghc-trace-events-0.1.2.1
3335
- haskell-src-exts-1.21.1
3436
- heapsize-0.3.0

stack.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ extra-deps:
3737
- ghc-check-0.5.0.1
3838
- ghc-events-0.13.0
3939
- ghc-exactprint-0.6.3.4
40-
- ghc-lib-8.10.3.20201220
41-
- ghc-lib-parser-8.10.3.20201220
40+
- ghc-lib-8.10.4.20210206
41+
- ghc-lib-parser-8.10.4.20210206
4242
- ghc-lib-parser-ex-8.10.0.17
4343
- ghc-source-gen-0.4.0.0
4444
- ghc-trace-events-0.1.2.1

0 commit comments

Comments
 (0)