18
18
-- lots of CPP, we just disable the warning until later.
19
19
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
20
20
21
- #ifdef HLINT_ON_GHC_LIB
21
+ #ifdef GHC_LIB
22
22
#define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc_lib_parser(x,y,z)
23
23
#else
24
24
#define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc(x,y,z)
@@ -61,7 +61,6 @@ import Development.IDE.Core.Shake (getDiagnost
61
61
import qualified Refact.Apply as Refact
62
62
import qualified Refact.Types as Refact
63
63
64
- #ifdef HLINT_ON_GHC_LIB
65
64
import Development.IDE.GHC.Compat (DynFlags ,
66
65
WarningFlag (Opt_WarnUnrecognisedPragmas ),
67
66
extensionFlags ,
@@ -71,18 +70,18 @@ import Development.IDE.GHC.Compat (DynFlags,
71
70
import qualified Development.IDE.GHC.Compat.Util as EnumSet
72
71
73
72
#if MIN_GHC_API_VERSION(9,4,0)
74
- import qualified "ghc-lib-parser" GHC.Data.Strict as Strict
73
+ import qualified GHC.Data.Strict as Strict
75
74
#endif
76
75
#if MIN_GHC_API_VERSION(9,0,0)
77
- import "ghc-lib-parser" GHC.Types.SrcLoc hiding
76
+ import GHC.Types.SrcLoc hiding
78
77
(RealSrcSpan )
79
- import qualified "ghc-lib-parser" GHC.Types.SrcLoc as GHC
78
+ import qualified GHC.Types.SrcLoc as GHC
80
79
#else
81
- import "ghc-lib-parser" SrcLoc hiding
80
+ import qualified SrcLoc as GHC
81
+ import SrcLoc hiding
82
82
(RealSrcSpan )
83
- import qualified "ghc-lib-parser" SrcLoc as GHC
84
83
#endif
85
- import "ghc-lib-parser" GHC.LanguageExtensions (Extension )
84
+ import GHC.LanguageExtensions (Extension )
86
85
import Language.Haskell.GhclibParserEx.GHC.Driver.Session as GhclibParserEx (readExtension )
87
86
import System.FilePath (takeFileName )
88
87
import System.IO (IOMode (WriteMode ),
@@ -94,21 +93,7 @@ import System.IO (IOMode (Wri
94
93
utf8 ,
95
94
withFile )
96
95
import System.IO.Temp
97
- #else
98
- import Development.IDE.GHC.Compat hiding
99
- (setEnv ,
100
- (<+>) )
101
- import GHC.Generics (Associativity (LeftAssociative , NotAssociative , RightAssociative ))
102
- #if MIN_GHC_API_VERSION(9,2,0)
103
- import Language.Haskell.GHC.ExactPrint.ExactPrint (deltaOptions )
104
- #else
105
- import Language.Haskell.GHC.ExactPrint.Delta (deltaOptions )
106
- #endif
107
- import Language.Haskell.GHC.ExactPrint.Parsers (postParseTransform )
108
- import Language.Haskell.GHC.ExactPrint.Types (Rigidity (.. ))
109
- import Language.Haskell.GhclibParserEx.Fixity as GhclibParserEx (applyFixities )
110
- import qualified Refact.Fixity as Refact
111
- #endif
96
+
112
97
import Ide.Plugin.Config hiding
113
98
(Config )
114
99
import Ide.Plugin.Error
@@ -159,7 +144,6 @@ instance Pretty Log where
159
144
LogGetIdeas fp -> " Getting hlint ideas for " <+> viaShow fp
160
145
LogResolve msg -> pretty msg
161
146
162
- #ifdef HLINT_ON_GHC_LIB
163
147
-- Reimplementing this, since the one in Development.IDE.GHC.Compat isn't for ghc-lib
164
148
#if !MIN_GHC_API_VERSION(9,0,0)
165
149
type BufSpan = ()
@@ -173,7 +157,6 @@ pattern RealSrcSpan x y = GHC.RealSrcSpan x y
173
157
pattern RealSrcSpan x y <- ((,Nothing ) -> (GHC. RealSrcSpan x, y))
174
158
#endif
175
159
{-# COMPLETE RealSrcSpan, UnhelpfulSpan #-}
176
- #endif
177
160
178
161
#if MIN_GHC_API_VERSION(9,4,0)
179
162
fromStrictMaybe :: Strict. Maybe a -> Maybe a
@@ -316,28 +299,6 @@ getIdeas recorder nfp = do
316
299
fmap applyHints' (moduleEx flags)
317
300
318
301
where moduleEx :: ParseFlags -> Action (Maybe (Either ParseError ModuleEx ))
319
- #ifndef HLINT_ON_GHC_LIB
320
- moduleEx _flags = do
321
- mbpm <- getParsedModuleWithComments nfp
322
- return $ createModule <$> mbpm
323
- where
324
- createModule pm = Right (createModuleEx anns (applyParseFlagsFixities modu))
325
- where anns = pm_annotations pm
326
- modu = pm_parsed_source pm
327
-
328
- applyParseFlagsFixities :: ParsedSource -> ParsedSource
329
- applyParseFlagsFixities modul = GhclibParserEx. applyFixities (parseFlagsToFixities _flags) modul
330
-
331
- parseFlagsToFixities :: ParseFlags -> [(String , Fixity )]
332
- parseFlagsToFixities = map toFixity . Hlint. fixities
333
-
334
- toFixity :: FixityInfo -> (String , Fixity )
335
- toFixity (name, dir, i) = (name, Fixity NoSourceText i $ f dir)
336
- where
337
- f LeftAssociative = InfixL
338
- f RightAssociative = InfixR
339
- f NotAssociative = InfixN
340
- #else
341
302
moduleEx flags = do
342
303
mbpm <- getParsedModuleWithComments nfp
343
304
-- If ghc was not able to parse the module, we disable hlint diagnostics
@@ -360,11 +321,6 @@ getIdeas recorder nfp = do
360
321
-- and the ModSummary dynflags. However using the parsedFlags extensions
361
322
-- can sometimes interfere with the hlint parsing of the file.
362
323
-- See https://github.com/haskell/haskell-language-server/issues/1279
363
- --
364
- -- Note: this is used when HLINT_ON_GHC_LIB is defined. We seem to need
365
- -- these extensions to construct dynflags to parse the file again. Therefore
366
- -- using hlint default extensions doesn't seem to be a problem when
367
- -- HLINT_ON_GHC_LIB is not defined because we don't parse the file again.
368
324
getExtensions :: NormalizedFilePath -> Action [Extension ]
369
325
getExtensions nfp = do
370
326
dflags <- getFlags
@@ -375,7 +331,6 @@ getExtensions nfp = do
375
331
getFlags = do
376
332
modsum <- use_ GetModSummary nfp
377
333
return $ ms_hspp_opts $ msrModSummary modsum
378
- #endif
379
334
380
335
-- ---------------------------------------------------------------------
381
336
@@ -573,7 +528,6 @@ applyHint recorder ide nfp mhint verTxtDocId =
573
528
-- But "Idea"s returned by HLint point to starting position of the expressions
574
529
-- that contain refactorings, so they are often outside the refactorings' boundaries.
575
530
let position = Nothing
576
- #ifdef HLINT_ON_GHC_LIB
577
531
let writeFileUTF8NoNewLineTranslation file txt =
578
532
withFile file WriteMode $ \ h -> do
579
533
hSetEncoding h utf8
@@ -589,22 +543,6 @@ applyHint recorder ide nfp mhint verTxtDocId =
589
543
let refactExts = map show $ enabled ++ disabled
590
544
(Right <$> applyRefactorings (topDir dflags) position commands temp refactExts)
591
545
`catches` errorHandlers
592
- #else
593
- mbParsedModule <- liftIO $ runAction' $ getParsedModuleWithComments nfp
594
- res <-
595
- case mbParsedModule of
596
- Nothing -> throwError " Apply hint: error parsing the module"
597
- Just pm -> do
598
- let anns = pm_annotations pm
599
- let modu = pm_parsed_source pm
600
- -- apply-refact uses RigidLayout
601
- let rigidLayout = deltaOptions RigidLayout
602
- (anns', modu') <-
603
- ExceptT $ mapM (uncurry Refact. applyFixities)
604
- $ postParseTransform (Right (anns, [] , dflags, modu)) rigidLayout
605
- liftIO $ (Right <$> Refact. applyRefactorings' position commands anns' modu')
606
- `catches` errorHandlers
607
- #endif
608
546
case res of
609
547
Right appliedFile -> do
610
548
let wsEdit = diffText' True (verTxtDocId, oldContent) (T. pack appliedFile) IncludeDeletions
0 commit comments