1
1
module Ide.Plugin.CabalFmt where
2
2
3
- import Control.Exception (bracket_ )
3
+ import CabalFmt
4
+ import CabalFmt.Error
5
+ import CabalFmt.Monad
6
+ import CabalFmt.Options
7
+ import Control.Exception (bracket_ )
4
8
import Control.Monad.IO.Class
5
- import Control.Monad.Trans.Maybe (MaybeT , runMaybeT )
6
- import Data.Maybe (mapMaybe , maybeToList )
9
+ import Control.Monad.Trans.Maybe (MaybeT , runMaybeT )
10
+ import Data.Maybe (mapMaybe , maybeToList )
7
11
import Data.Semigroup
8
- import Data.Text (Text )
9
- import qualified Data.Text as T
10
- import Development.IDE hiding (pluginHandlers )
11
- import Development.IDE.GHC.Compat (ModSummary (ms_hspp_opts ), topDir )
12
+ import Data.Text (Text )
13
+ import qualified Data.Text as T
14
+ import Data.Text.Encoding
15
+ import Development.IDE hiding (pluginHandlers )
16
+ import Development.IDE.GHC.Compat (ModSummary (ms_hspp_opts ), topDir )
12
17
import Ide.PluginUtils
13
18
import Ide.Types
14
- import Language.LSP.Types as J
15
- import qualified Language.LSP.Types.Lens as J
16
- import System.Environment (setEnv , unsetEnv )
19
+ import Language.LSP.Types as J
20
+ import qualified Language.LSP.Types.Lens as J
21
+ import System.Environment (setEnv , unsetEnv )
17
22
import System.FilePath
18
- import CabalFmt.Monad
19
- import CabalFmt
20
- import Data.Text.Encoding
21
- import CabalFmt.Options
22
- import CabalFmt.Error
23
23
24
24
descriptor :: PluginId -> PluginDescriptor IdeState
25
- descriptor plId = (defaultPluginDescriptor plId)
25
+ descriptor plId = (defaultCabalPluginDescriptor plId)
26
26
{ pluginHandlers = mkFormattingHandlers provider
27
27
}
28
28
@@ -32,19 +32,19 @@ descriptor plId = (defaultPluginDescriptor plId)
32
32
provider :: FormattingHandler IdeState
33
33
provider ide typ contents nfp opts = liftIO $ do
34
34
cabalFmtOutput <- runCabalFmtIO (Just $ takeDirectory fp) cabalFmtOpts (cabalFmt fp (encodeUtf8 contents))
35
- case cabalFmtOutput of
35
+ case cabalFmtOutput of
36
36
Left err -> pure $ Left (cabalErrToRespErr err)
37
- Right out -> do
37
+ Right out -> do
38
38
let fmtDiff = makeDiffTextEdit contents (T. pack out)
39
39
pure $ Right fmtDiff
40
40
where
41
41
fp = fromNormalizedFilePath nfp
42
42
cabalFmtOpts = defaultOptions {
43
- optIndent = _tabSize opts,
43
+ optIndent = _tabSize opts,
44
44
optTabular = not $ _insertSpaces opts
45
45
}
46
46
cabalErrToRespErr :: Error -> ResponseError
47
47
cabalErrToRespErr (SomeError err) = ResponseError UnknownErrorCode (T. pack err) Nothing
48
48
cabalErrToRespErr (CabalParseError _ _ _ _ _) = ResponseError ParseError (T. pack " Failed to parse cabal file." ) Nothing
49
49
cabalErrToRespErr (PanicCannotParseInput _) = ResponseError ParseError (T. pack " Failed to parse cabal file." ) Nothing
50
- cabalErrToRespErr (WarningError err) = ResponseError ParseError (T. pack err) Nothing
50
+ cabalErrToRespErr (WarningError err) = ResponseError ParseError (T. pack err) Nothing
0 commit comments