@@ -6,13 +6,11 @@
6#include "ghc-api-version.h"
6#include "ghc-api-version.h"
8-- | Go to the definition of a variable.
8-- | Go to the definition of a variable.
9−module Development.IDE.Plugin.CodeAction
9+module Development.IDE.Plugin.CodeAction(plugin) where
10− ( setHandlersCodeAction
11− , setHandlersCodeLens
14import Language.Haskell.LSP.Types
11import Language.Haskell.LSP.Types
15import Control.Monad (join)
12import Control.Monad (join)
13+import Development.IDE.Plugin
16import Development.IDE.GHC.Compat
14import Development.IDE.GHC.Compat
17import Development.IDE.Core.Rules
15import Development.IDE.Core.Rules
18import Development.IDE.Core.RuleTypes
16import Development.IDE.Core.RuleTypes
@@ -38,13 +36,18 @@ import Text.Regex.TDFA ((=~), (=~~))
38import Text.Regex.TDFA.Text()
36import Text.Regex.TDFA.Text()
39import Outputable (ppr, showSDocUnsafe)
37import Outputable (ppr, showSDocUnsafe)
40+plugin = codeActionPlugin codeAction <> Plugin mempty setHandlersCodeLens
41-- | Generate code actions.
42-- | Generate code actions.
43 :: LSP.LspFuncs ()
44 :: LSP.LspFuncs ()
44 -> IdeState
45 -> IdeState
45− -> CodeActionParams
46+ -> TextDocumentIdentifier
46− -> IO (List CAResult)
49+ -> IO [CAResult]
47−codeAction lsp state CodeActionParams{_textDocument=TextDocumentIdentifier uri,_context=CodeActionContext{_diagnostics=List xs}} = do
50+codeAction lsp state (TextDocumentIdentifier uri) _range CodeActionContext{_diagnostics=List xs} = do
48 -- disable logging as its quite verbose
51 -- disable logging as its quite verbose
49 -- logInfo (ideLogger ide) $ T.pack $ "Code action req: " ++ show arg
52 -- logInfo (ideLogger ide) $ T.pack $ "Code action req: " ++ show arg
50 contents <- LSP.getVirtualFileFunc lsp $ toNormalizedUri uri
53 contents <- LSP.getVirtualFileFunc lsp $ toNormalizedUri uri
@@ -52,7 +55,7 @@ codeAction lsp state CodeActionParams{_textDocument=TextDocumentIdentifier uri,_
52 (ideOptions, parsedModule) <- runAction state $
55 (ideOptions, parsedModule) <- runAction state $
53 (,) <$> getIdeOptions
56 (,) <$> getIdeOptions
54 <*> (getParsedModule . toNormalizedFilePath) `traverse` uriToFilePath uri
57 <*> (getParsedModule . toNormalizedFilePath) `traverse` uriToFilePath uri
56 [ CACodeAction $ CodeAction title (Just CodeActionQuickFix) (Just $ List [x]) (Just edit) Nothing
59 [ CACodeAction $ CodeAction title (Just CodeActionQuickFix) (Just $ List [x]) (Just edit) Nothing
57 | x <- xs, (title, tedit) <- suggestAction ideOptions ( join parsedModule ) text x
60 | x <- xs, (title, tedit) <- suggestAction ideOptions ( join parsedModule ) text x
58 , let edit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing
61 , let edit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing
@@ -439,11 +442,6 @@ matchRegex message regex = case unifySpaces message =~~ regex of
439 Just (_ :: T.Text, _ :: T.Text, _ :: T.Text, bindings) -> Just bindings
442 Just (_ :: T.Text, _ :: T.Text, _ :: T.Text, bindings) -> Just bindings
440 Nothing -> Nothing
443 Nothing -> Nothing
442−setHandlersCodeAction :: PartialHandlers
443−setHandlersCodeAction = PartialHandlers $ \WithMessage{..} x -> return x{
444− LSP.codeActionHandler = withResponse RspCodeAction codeAction
447setHandlersCodeLens :: PartialHandlers
445setHandlersCodeLens :: PartialHandlers
448setHandlersCodeLens = PartialHandlers $ \WithMessage{..} x -> return x{
446setHandlersCodeLens = PartialHandlers $ \WithMessage{..} x -> return x{
449 LSP.codeLensHandler = withResponse RspCodeLens codeLens,
447 LSP.codeLensHandler = withResponse RspCodeLens codeLens,