1
- {-# LANGUAGE RecordWildCards #-}
2
- {-# LANGUAGE OverloadedStrings #-}
1
+ {-# LANGUAGE OverloadedStrings #-}
2
+ {-# LANGUAGE RecordWildCards #-}
3
3
{-# LANGUAGE ScopedTypeVariables #-}
4
- {-# LANGUAGE TypeApplications #-}
5
- {-# LANGUAGE ViewPatterns #-}
4
+ {-# LANGUAGE TypeApplications #-}
6
5
7
6
module Ide.Plugin.Ormolu
8
7
(
@@ -12,20 +11,24 @@ module Ide.Plugin.Ormolu
12
11
where
13
12
14
13
import Control.Exception
15
- import qualified Data.Text as T
14
+ import qualified Data.Text as T
16
15
import Development.IDE.Core.Rules
16
+ import Development.IDE.Core.RuleTypes (GhcSession (GhcSession ))
17
+ import Development.IDE.Core.Shake (use )
18
+ import Development.IDE.GHC.Util (hscEnv )
17
19
import Development.IDE.Types.Diagnostics as D
18
20
import Development.IDE.Types.Location
19
- import qualified DynFlags as D
20
- import qualified EnumSet as S
21
+ import qualified DynFlags as D
22
+ import qualified EnumSet as S
21
23
import GHC
22
24
import GHC.LanguageExtensions.Type
23
- import Ide.Types
24
- import Ide.PluginUtils
25
+ import GhcPlugins (HscEnv (hsc_dflags ))
25
26
import Ide.Plugin.Formatter
27
+ import Ide.PluginUtils
28
+ import Ide.Types
26
29
import Language.Haskell.LSP.Types
27
30
import Ormolu
28
- import Text.Regex.TDFA.Text ()
31
+ import Text.Regex.TDFA.Text ()
29
32
30
33
-- ---------------------------------------------------------------------
31
34
@@ -39,10 +42,9 @@ descriptor plId = (defaultPluginDescriptor plId)
39
42
provider :: FormattingProvider IO
40
43
provider _lf ideState typ contents fp _ = do
41
44
let
42
- fromDyn :: ParsedModule -> IO [DynOption ]
43
- fromDyn pmod =
45
+ fromDyn :: DynFlags -> IO [DynOption ]
46
+ fromDyn df =
44
47
let
45
- df = ms_hspp_opts $ pm_mod_summary pmod
46
48
pp =
47
49
let p = D. sPgm_F $ D. settings df
48
50
in if null p then [] else [" -pgmF=" <> p]
@@ -51,10 +53,11 @@ provider _lf ideState typ contents fp _ = do
51
53
in
52
54
return $ map DynOption $ pp <> pm <> ex
53
55
54
- m_parsed <- runAction " Ormolu" ideState $ getParsedModule fp
55
- fileOpts <- case m_parsed of
56
+ ghc <- runAction " Ormolu" ideState $ use GhcSession fp
57
+ let df = hsc_dflags . hscEnv <$> ghc
58
+ fileOpts <- case df of
56
59
Nothing -> return []
57
- Just pm -> fromDyn pm
60
+ Just df -> fromDyn df
58
61
59
62
let
60
63
fullRegion = RegionIndices Nothing Nothing
@@ -78,5 +81,5 @@ provider _lf ideState typ contents fp _ = do
78
81
ret (Right new) = Right (makeDiffTextEdit contents new)
79
82
80
83
showExtension :: Extension -> String
81
- showExtension Cpp = " -XCPP"
84
+ showExtension Cpp = " -XCPP"
82
85
showExtension other = " -X" ++ show other
0 commit comments