Skip to content

Commit 065957e

Browse files
authored
Use apply-refact 0.12.0 (#3469)
* Use apply-refact 0.12.0 * Limit ormolu version to < 0.5.3
1 parent 2b691b6 commit 065957e

File tree

4 files changed

+60
-17
lines changed

4 files changed

+60
-17
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ package *
5050

5151
write-ghc-environment-files: never
5252

53-
index-state: 2023-01-10T00:00:00Z
53+
index-state: 2023-01-27T00:00:00Z
5454

5555
constraints:
5656
-- For GHC 9.4, older versions of entropy fail to build on Windows

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ library
6161
, unordered-containers
6262
, ghc-lib-parser
6363
, ghc-lib-parser-ex
64-
if impl(ghc >= 9.2)
65-
build-depends: apply-refact ^>= 0.11.0.0
66-
else
67-
build-depends: apply-refact ^>= 0.9.0.0
64+
, apply-refact
6865

6966
cpp-options: -DHLINT_ON_GHC_LIB
7067
ghc-options:

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

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -565,15 +565,7 @@ applyHint recorder ide nfp mhint =
565565
oldContent <- maybe (liftIO $ fmap T.decodeUtf8 (BS.readFile fp)) return mbOldContent
566566
modsum <- liftIO $ runAction' $ use_ GetModSummary nfp
567567
let dflags = ms_hspp_opts $ msrModSummary modsum
568-
-- Setting a environment variable with the libdir used by ghc-exactprint.
569-
-- It is a workaround for an error caused by the use of a hardcoded at compile time libdir
570-
-- in ghc-exactprint that makes dependent executables non portables.
571-
-- See https://github.com/alanz/ghc-exactprint/issues/96.
572-
-- WARNING: this code is not thread safe, so if you try to apply several async refactorings
573-
-- it could fail. That case is not very likely so we assume the risk.
574-
let withRuntimeLibdir :: IO a -> IO a
575-
withRuntimeLibdir = bracket_ (setEnv key $ topDir dflags) (unsetEnv key)
576-
where key = "GHC_EXACTPRINT_GHC_LIBDIR"
568+
577569
-- set Nothing as "position" for "applyRefactorings" because
578570
-- applyRefactorings expects the provided position to be _within_ the scope
579571
-- of each refactoring it will apply.
@@ -594,7 +586,7 @@ applyHint recorder ide nfp mhint =
594586
-- We have to reparse extensions to remove the invalid ones
595587
let (enabled, disabled, _invalid) = Refact.parseExtensions $ map show exts
596588
let refactExts = map show $ enabled ++ disabled
597-
(Right <$> withRuntimeLibdir (Refact.applyRefactorings position commands temp refactExts))
589+
(Right <$> applyRefactorings (topDir dflags) position commands temp refactExts)
598590
`catches` errorHandlers
599591
#else
600592
mbParsedModule <- liftIO $ runAction' $ getParsedModuleWithComments nfp
@@ -609,7 +601,7 @@ applyHint recorder ide nfp mhint =
609601
(anns', modu') <-
610602
ExceptT $ mapM (uncurry Refact.applyFixities)
611603
$ postParseTransform (Right (anns, [], dflags, modu)) rigidLayout
612-
liftIO $ (Right <$> withRuntimeLibdir (Refact.applyRefactorings' position commands anns' modu'))
604+
liftIO $ (Right <$> Refact.applyRefactorings' position commands anns' modu')
613605
`catches` errorHandlers
614606
#endif
615607
case res of
@@ -641,3 +633,55 @@ bimapExceptT f g (ExceptT m) = ExceptT (fmap h m) where
641633
h (Left e) = Left (f e)
642634
h (Right a) = Right (g a)
643635
{-# INLINE bimapExceptT #-}
636+
637+
-- ---------------------------------------------------------------------------
638+
-- Apply-refact compatability, documentation copied from upstream apply-refact
639+
-- ---------------------------------------------------------------------------
640+
641+
-- | Apply a set of refactorings as supplied by HLint
642+
--
643+
-- This compatibility function abstracts over https://github.com/mpickering/apply-refact/issues/133
644+
-- for backwards compatability.
645+
applyRefactorings ::
646+
-- | FilePath to [GHC's libdir](https://downloads.haskell.org/ghc/latest/docs/users_guide/using.html#ghc-flag---print-libdir).
647+
--
648+
-- It is possible to use @libdir@ from [ghc-paths package](https://hackage.haskell.org/package/ghc-paths), but note
649+
-- this will make it difficult to provide a binary distribution of your program.
650+
FilePath ->
651+
-- | Apply hints relevant to a specific position
652+
Maybe (Int, Int) ->
653+
-- | 'Refactoring's to apply. Each inner list corresponds to an HLint
654+
-- <https://hackage.haskell.org/package/hlint/docs/Language-Haskell-HLint.html#t:Idea Idea>.
655+
-- An @Idea@ may have more than one 'Refactoring'.
656+
--
657+
-- The @Idea@s are sorted in ascending order of starting location, and are applied
658+
-- in that order. If two @Idea@s start at the same location, the one with the larger
659+
-- source span comes first. An @Idea@ is filtered out (ignored) if there is an @Idea@
660+
-- prior to it which has an overlapping source span and is not filtered out.
661+
[[Refact.Refactoring Refact.SrcSpan]] ->
662+
-- | Target file
663+
FilePath ->
664+
-- | GHC extensions, e.g., @LambdaCase@, @NoStarIsType@. The list is processed from left
665+
-- to right. An extension (e.g., @StarIsType@) may be overridden later (e.g., by @NoStarIsType@).
666+
--
667+
-- These are in addition to the @LANGUAGE@ pragmas in the target file. When they conflict
668+
-- with the @LANGUAGE@ pragmas, pragmas win.
669+
[String] ->
670+
IO String
671+
applyRefactorings =
672+
#if MIN_VERSION_apply_refact(0,12,0)
673+
Refact.applyRefactorings
674+
#else
675+
\libdir pos refacts fp exts -> withRuntimeLibdir libdir (Refact.applyRefactorings pos refacts fp exts)
676+
677+
where
678+
-- Setting a environment variable with the libdir used by ghc-exactprint.
679+
-- It is a workaround for an error caused by the use of a hardcoded at compile time libdir
680+
-- in ghc-exactprint that makes dependent executables non portables.
681+
-- See https://github.com/alanz/ghc-exactprint/issues/96.
682+
-- WARNING: this code is not thread safe, so if you try to apply several async refactorings
683+
-- it could fail. That case is not very likely so we assume the risk.
684+
withRuntimeLibdir :: FilePath -> IO a -> IO a
685+
withRuntimeLibdir libdir = bracket_ (setEnv key libdir) (unsetEnv key)
686+
where key = "GHC_EXACTPRINT_GHC_LIBDIR"
687+
#endif

plugins/hls-ormolu-plugin/hls-ormolu-plugin.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ library
3232
, hls-plugin-api ^>=1.3 || ^>=1.4 || ^>= 1.5 || ^>= 1.6
3333
, lens
3434
, lsp
35-
, ormolu ^>=0.1.2 || ^>= 0.2 || ^>= 0.3 || ^>= 0.5
35+
-- we are incompatible with 0.5.3.
36+
-- See upstream ticket: https://github.com/tweag/ormolu/issues/981
37+
, ormolu ^>=0.1.2 || ^>= 0.2 || ^>= 0.3 || (>= 0.5 && < 0.5.3)
3638
, text
3739

3840
default-language: Haskell2010

0 commit comments

Comments
 (0)