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
22
21
#define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc_lib_parser(x,y,z)
23
- #else
24
- #define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc(x,y,z)
25
- #endif
26
22
27
23
module Ide.Plugin.Hlint
28
24
(
@@ -61,7 +57,6 @@ import Development.IDE.Core.Shake (getDiagnost
61
57
import qualified Refact.Apply as Refact
62
58
import qualified Refact.Types as Refact
63
59
64
- #ifdef HLINT_ON_GHC_LIB
65
60
import Development.IDE.GHC.Compat (DynFlags ,
66
61
WarningFlag (Opt_WarnUnrecognisedPragmas ),
67
62
extensionFlags ,
@@ -71,18 +66,18 @@ import Development.IDE.GHC.Compat (DynFlags,
71
66
import qualified Development.IDE.GHC.Compat.Util as EnumSet
72
67
73
68
#if MIN_GHC_API_VERSION(9,4,0)
74
- import qualified "ghc-lib-parser" GHC.Data.Strict as Strict
69
+ import qualified GHC.Data.Strict as Strict
75
70
#endif
76
71
#if MIN_GHC_API_VERSION(9,0,0)
77
- import "ghc-lib-parser" GHC.Types.SrcLoc hiding
72
+ import GHC.Types.SrcLoc hiding
78
73
(RealSrcSpan )
79
- import qualified "ghc-lib-parser" GHC.Types.SrcLoc as GHC
74
+ import qualified GHC.Types.SrcLoc as GHC
80
75
#else
81
- import "ghc-lib-parser" SrcLoc hiding
76
+ import qualified SrcLoc as GHC
77
+ import SrcLoc hiding
82
78
(RealSrcSpan )
83
- import qualified "ghc-lib-parser" SrcLoc as GHC
84
79
#endif
85
- import "ghc-lib-parser" GHC.LanguageExtensions (Extension )
80
+ import GHC.LanguageExtensions (Extension )
86
81
import Language.Haskell.GhclibParserEx.GHC.Driver.Session as GhclibParserEx (readExtension )
87
82
import System.FilePath (takeFileName )
88
83
import System.IO (IOMode (WriteMode ),
@@ -94,21 +89,7 @@ import System.IO (IOMode (Wri
94
89
utf8 ,
95
90
withFile )
96
91
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
92
+
112
93
import Ide.Plugin.Config hiding
113
94
(Config )
114
95
import Ide.Plugin.Error
@@ -159,7 +140,6 @@ instance Pretty Log where
159
140
LogGetIdeas fp -> " Getting hlint ideas for " <+> viaShow fp
160
141
LogResolve msg -> pretty msg
161
142
162
- #ifdef HLINT_ON_GHC_LIB
163
143
-- Reimplementing this, since the one in Development.IDE.GHC.Compat isn't for ghc-lib
164
144
#if !MIN_GHC_API_VERSION(9,0,0)
165
145
type BufSpan = ()
@@ -173,7 +153,6 @@ pattern RealSrcSpan x y = GHC.RealSrcSpan x y
173
153
pattern RealSrcSpan x y <- ((,Nothing ) -> (GHC. RealSrcSpan x, y))
174
154
#endif
175
155
{-# COMPLETE RealSrcSpan, UnhelpfulSpan #-}
176
- #endif
177
156
178
157
#if MIN_GHC_API_VERSION(9,4,0)
179
158
fromStrictMaybe :: Strict. Maybe a -> Maybe a
@@ -316,28 +295,6 @@ getIdeas recorder nfp = do
316
295
fmap applyHints' (moduleEx flags)
317
296
318
297
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
298
moduleEx flags = do
342
299
mbpm <- getParsedModuleWithComments nfp
343
300
-- If ghc was not able to parse the module, we disable hlint diagnostics
@@ -360,11 +317,6 @@ getIdeas recorder nfp = do
360
317
-- and the ModSummary dynflags. However using the parsedFlags extensions
361
318
-- can sometimes interfere with the hlint parsing of the file.
362
319
-- 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
320
getExtensions :: NormalizedFilePath -> Action [Extension ]
369
321
getExtensions nfp = do
370
322
dflags <- getFlags
@@ -375,7 +327,6 @@ getExtensions nfp = do
375
327
getFlags = do
376
328
modsum <- use_ GetModSummary nfp
377
329
return $ ms_hspp_opts $ msrModSummary modsum
378
- #endif
379
330
380
331
-- ---------------------------------------------------------------------
381
332
@@ -573,7 +524,6 @@ applyHint recorder ide nfp mhint verTxtDocId =
573
524
-- But "Idea"s returned by HLint point to starting position of the expressions
574
525
-- that contain refactorings, so they are often outside the refactorings' boundaries.
575
526
let position = Nothing
576
- #ifdef HLINT_ON_GHC_LIB
577
527
let writeFileUTF8NoNewLineTranslation file txt =
578
528
withFile file WriteMode $ \ h -> do
579
529
hSetEncoding h utf8
@@ -589,22 +539,6 @@ applyHint recorder ide nfp mhint verTxtDocId =
589
539
let refactExts = map show $ enabled ++ disabled
590
540
(Right <$> applyRefactorings (topDir dflags) position commands temp refactExts)
591
541
`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
542
case res of
609
543
Right appliedFile -> do
610
544
let wsEdit = diffText' True (verTxtDocId, oldContent) (T. pack appliedFile) IncludeDeletions
0 commit comments