1
- {-# LANGUAGE DataKinds #-}
2
- {-# LANGUAGE DeriveGeneric #-}
3
- {-# LANGUAGE GeneralizedNewtypeDeriving #-}
4
- {-# LANGUAGE TypeFamilies #-}
5
- {-# LANGUAGE TypeOperators #-}
6
-
7
- module Ide.Plugin.AlternateNumberFormat where
8
-
9
- import Control.Lens ((^.) )
10
- import Control.Monad.Except (ExceptT , MonadIO , liftIO )
11
- import qualified Data.HashMap.Strict as HashMap
12
- import Data.Maybe (fromMaybe , isJust )
13
- import Data.Text (Text )
14
- import qualified Data.Text as T
15
- import Debug.Trace (traceM )
16
- import Development.IDE (GetParsedModule (GetParsedModule ),
17
- IdeState , RuleResult ,
18
- Rules , define , ideLogger ,
19
- realSrcSpanToRange ,
20
- runAction , use ,
21
- useWithStale )
22
- import Development.IDE.Core.PositionMapping (PositionMapping )
23
- import Development.IDE.GHC.Compat hiding (getSrcSpan )
24
- import Development.IDE.GHC.Compat.Util (toList )
25
- import Development.IDE.Graph.Classes (Hashable , NFData )
26
- import Development.IDE.Types.Logger as Logger
27
- import GHC.Generics (Generic )
28
- import Ide.Plugin.Conversion (FormatType ,
29
- alternateFormat ,
30
- toFormatTypes )
31
- import Ide.Plugin.Literals (Literal (.. ),
32
- collectLiterals ,
33
- getSrcSpan , getSrcText )
34
- import Ide.Plugin.Retrie (handleMaybe ,
35
- handleMaybeM , response )
1
+ {-# LANGUAGE DataKinds #-}
2
+ {-# LANGUAGE DeriveGeneric #-}
3
+ {-# LANGUAGE TypeFamilies #-}
4
+ {-# LANGUAGE TypeOperators #-}
5
+ module Ide.Plugin.AlternateNumberFormat (descriptor ) where
6
+
7
+ import Control.Lens ((^.) )
8
+ import Control.Monad.Except (ExceptT , MonadIO , liftIO )
9
+ import qualified Data.HashMap.Strict as HashMap
10
+ import Data.Text (Text )
11
+ import qualified Data.Text as T
12
+ import Development.IDE (GetParsedModule (GetParsedModule ),
13
+ IdeState , RuleResult , Rules ,
14
+ define , ideLogger ,
15
+ realSrcSpanToRange , runAction ,
16
+ use )
17
+ import Development.IDE.GHC.Compat hiding (getSrcSpan )
18
+ import Development.IDE.GHC.Compat.Util (toList )
19
+ import Development.IDE.Graph.Classes (Hashable , NFData )
20
+ import Development.IDE.Types.Logger as Logger
21
+ import GHC.Generics (Generic )
22
+ import Ide.Plugin.Conversion (FormatType , alternateFormat ,
23
+ toFormatTypes )
24
+ import Ide.Plugin.Literals (Literal (.. ), collectLiterals ,
25
+ getSrcSpan , getSrcText )
26
+ import Ide.Plugin.Retrie (handleMaybe , handleMaybeM ,
27
+ response )
36
28
import Ide.Types
37
29
import Language.LSP.Types
38
- import Language.LSP.Types.Lens (uri )
30
+ import Language.LSP.Types.Lens (uri )
39
31
40
32
descriptor :: PluginId -> PluginDescriptor IdeState
41
33
descriptor plId = (defaultPluginDescriptor plId)
@@ -51,8 +43,8 @@ instance NFData CollectLiterals
51
43
52
44
type instance RuleResult CollectLiterals = CollectLiteralsResult
53
45
54
- data CollectLiteralsResult = CLR {
55
- literals :: [Literal ]
46
+ data CollectLiteralsResult = CLR
47
+ { literals :: [Literal ]
56
48
, formatTypes :: [FormatType ]
57
49
} deriving (Generic )
58
50
@@ -94,10 +86,9 @@ codeActionHandler state _ (CodeActionParams _ _ docId currRange _) = response $
94
86
mkCodeAction :: NormalizedFilePath -> Literal -> Text -> Command |? CodeAction
95
87
mkCodeAction nfp lit alt = InR CodeAction {
96
88
_title = " Convert " <> getSrcText lit <> " into " <> alt
97
- -- what should this actually be?
98
- , _kind = Just $ CodeActionUnknown " alternate.style"
89
+ , _kind = Just $ CodeActionUnknown " quickfix.literals.style"
99
90
, _diagnostics = Nothing
100
- , _isPreferred = Just True
91
+ , _isPreferred = Nothing
101
92
, _disabled = Nothing
102
93
, _edit = Just $ mkWorkspaceEdit nfp lit alt
103
94
, _command = Nothing
@@ -123,12 +114,12 @@ getNormalizedFilePath docId = handleMaybe "Error: converting to NormalizedFilePa
123
114
$ toNormalizedUri (docId ^. uri)
124
115
125
116
requestLiterals :: MonadIO m => IdeState -> NormalizedFilePath -> ExceptT String m CollectLiteralsResult
126
- requestLiterals state = handleMaybeM " Error: Could not get ParsedModule "
117
+ requestLiterals state = handleMaybeM " Error: Could not Collect Literals "
127
118
. liftIO
128
119
. runAction " AlternateNumberFormat.CollectLiterals" state
129
120
. use CollectLiterals
130
121
131
122
132
123
logIO :: (MonadIO m , Show a ) => IdeState -> a -> m ()
133
- logIO state = liftIO . Logger. logInfo (ideLogger state) . T. pack . show
124
+ logIO state = liftIO . Logger. logDebug (ideLogger state) . T. pack . show
134
125
0 commit comments