5
5
-- | Provides code actions to add missing pragmas (whenever GHC suggests to)
6
6
module Ide.Plugin.Pragmas
7
7
(
8
- codeAction
8
+ descriptor
9
+ , codeAction
9
10
, commands
10
11
) where
11
12
@@ -18,19 +19,16 @@ import Ide.Types
18
19
import qualified GHC.Generics as Generics
19
20
import qualified Language.Haskell.LSP.Types as J
20
21
import qualified Language.Haskell.LSP.Types.Lens as J
21
-
22
22
import Development.IDE.Types.Diagnostics as D
23
23
import Language.Haskell.LSP.Types
24
24
25
25
-- ---------------------------------------------------------------------
26
26
27
- _pragmasDescriptor :: PluginId -> PluginDescriptor
28
- _pragmasDescriptor plId = PluginDescriptor
27
+ descriptor :: PluginId -> PluginDescriptor
28
+ descriptor plId = PluginDescriptor
29
29
{ pluginId = plId
30
30
, pluginRules = mempty
31
- , pluginCommands =
32
- [ PluginCommand " addPragma" " add the given pragma" addPragmaCmd
33
- ]
31
+ , pluginCommands = commands
34
32
, pluginCodeActionProvider = Just codeActionProvider
35
33
, pluginDiagnosticProvider = Nothing
36
34
, pluginHoverProvider = Nothing
@@ -58,7 +56,9 @@ data AddPragmaParams = AddPragmaParams
58
56
-- Pragma is added to the first line of the Uri.
59
57
-- It is assumed that the pragma name is a valid pragma,
60
58
-- thus, not validated.
61
- addPragmaCmd :: AddPragmaParams -> IO (Either ResponseError J. WorkspaceEdit )
59
+ -- addPragmaCmd :: AddPragmaParams -> IO (Either ResponseError J.WorkspaceEdit)
60
+ addPragmaCmd :: AddPragmaParams -> IO (Either ResponseError Value ,
61
+ Maybe (ServerMethod , ApplyWorkspaceEditParams ))
62
62
addPragmaCmd (AddPragmaParams uri pragmaName) = do
63
63
let
64
64
pos = J. Position 0 0
@@ -69,7 +69,7 @@ addPragmaCmd (AddPragmaParams uri pragmaName) = do
69
69
res = J. WorkspaceEdit
70
70
(Just $ H. singleton uri textEdits)
71
71
Nothing
72
- return $ Right res
72
+ return $ ( Right Null , Just ( WorkspaceApplyEdit , ApplyWorkspaceEditParams res))
73
73
74
74
-- ---------------------------------------------------------------------
75
75
@@ -80,11 +80,12 @@ codeAction = codeActionProvider
80
80
-- Pragmas are defined by a curated list of known pragmas, see 'possiblePragmas'.
81
81
codeActionProvider :: CodeActionProvider
82
82
codeActionProvider _ plId docId _ (J. CodeActionContext (J. List diags) _monly) = do
83
- cmds <- mapM mkCommand pragmas
83
+ -- cmds <- mapM mkCommand pragmas
84
+ cmds <- mapM mkCommand (" FooPragma" : pragmas)
84
85
return $ Right $ List cmds
85
86
where
86
87
-- Filter diagnostics that are from ghcmod
87
- ghcDiags = filter (\ d -> d ^. J. source == Just " bios " ) diags
88
+ ghcDiags = filter (\ d -> d ^. J. source == Just " typecheck " ) diags
88
89
-- Get all potential Pragmas for all diagnostics.
89
90
pragmas = concatMap (\ d -> findPragma (d ^. J. message)) ghcDiags
90
91
mkCommand pragmaName = do
0 commit comments