Skip to content

Commit

Permalink
Extract dflags from ModSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
jneira committed Dec 22, 2020
1 parent 9c74869 commit a671a0e
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module Ide.Plugin.Hlint
import Refact.Apply
import Control.Arrow ((&&&))
import Control.DeepSeq
import Control.Exception
import Control.Lens ((^.))
import Control.Monad
import Control.Monad.IO.Class
Expand All @@ -38,18 +37,21 @@ import Development.IDE.Core.Rules (defineNoFile)
import Development.IDE.Core.Shake (getDiagnostics)

#ifdef HLINT_ON_GHC_LIB
import Control.Exception
import Data.List (nub)
import "ghc-lib" GHC hiding (DynFlags(..))
import "ghc-lib" GHC hiding (DynFlags(..), ModSummary)
import "ghc-lib-parser" GHC.LanguageExtensions (Extension)
import "ghc" GHC as RealGHC (DynFlags(..))
import "ghc" GHC as RealGHC (DynFlags(..), ModSummary)
import "ghc" HscTypes as RealGHC.HscTypes (hsc_dflags)
import qualified "ghc" EnumSet as EnumSet
import Language.Haskell.GhclibParserEx.GHC.Driver.Session as GhclibParserEx (readExtension)
import System.FilePath (takeFileName)
import System.IO (hPutStr, noNewlineTranslation, hSetNewlineMode, utf8, hSetEncoding, IOMode(WriteMode), withFile, hClose)
import System.IO.Temp
#else
import Development.IDE.GHC.Compat hiding (DynFlags(..))
import HscTypes (hsc_dflags)
import Language.Haskell.GHC.ExactPrint.Parsers (postParseTransform)
import Language.Haskell.GHC.ExactPrint.Delta (normalLayout)
import Language.Haskell.GHC.ExactPrint.Delta (rigidLayout)
#endif

import Ide.Logger
Expand All @@ -59,12 +61,12 @@ import Ide.Plugin.Config
import Ide.PluginUtils
import Language.Haskell.HLint as Hlint
import Language.Haskell.LSP.Core
( LspFuncs(withIndefiniteProgress),
ProgressCancellable(Cancellable) )
import Language.Haskell.LSP.Types
import qualified Language.Haskell.LSP.Types as LSP
import qualified Language.Haskell.LSP.Types.Lens as LSP
import System.FilePath (takeFileName)
import System.IO (hPutStr, noNewlineTranslation, hSetNewlineMode, utf8, hSetEncoding, IOMode(WriteMode), withFile, hClose)
import System.IO.Temp

import Text.Regex.TDFA.Text()
import GHC.Generics (Generic)

Expand Down Expand Up @@ -207,12 +209,15 @@ getIdeas nfp = do

getExtensions :: ParseFlags -> NormalizedFilePath -> Action [Extension]
getExtensions pflags nfp = do
hsc <- hscEnv <$> use_ GhcSession nfp
let dflags = hsc_dflags hsc
dflags <- getFlags
let hscExts = EnumSet.toList (extensionFlags dflags)
let hscExts' = mapMaybe (GhclibParserEx.readExtension . show) hscExts
let hlintExts = nub $ enabledExtensions pflags ++ hscExts'
return hlintExts
where getFlags :: Action DynFlags
getFlags = do
(modsum, _) <- use_ GetModSummary nfp
return $ _ms_hspp_opts modsum
#endif

-- ---------------------------------------------------------------------
Expand Down Expand Up @@ -394,8 +399,8 @@ applyHint ide nfp mhint =
Just pm -> do
let anns = pm_annotations pm
let modu = pm_parsed_source pm
hsc <- liftIO $ runAction' $ hscEnv <$> use_ GhcSession nfp
let dflags = hsc_dflags hsc
(modsum, _) <- liftIO $ runAction' $ use_ GetModSummary nfp
let dflags = ms_hspp_opts modsum
(anns', modu') <-
ExceptT $ return $ postParseTransform (Right (anns, [], dflags, modu)) normalLayout
liftIO (Right <$> applyRefactorings' Nothing commands anns' modu')
Expand Down

0 comments on commit a671a0e

Please sign in to comment.