Skip to content

Commit 87a92ff

Browse files
committed
Extract code actions into an HLS plugin
1 parent b85e6eb commit 87a92ff

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

ghcide/src/Development/IDE/Plugin/CodeAction.hs

+13-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
-- | Go to the definition of a variable.
99
module Development.IDE.Plugin.CodeAction
10-
(
11-
-- * For haskell-language-server
12-
codeAction
13-
, rulePackageExports
10+
( descriptor
1411

1512
-- * For testing
1613
, matchRegExMultipleImports
@@ -55,16 +52,25 @@ import qualified Data.HashSet as Set
5552
import Control.Concurrent.Extra (readVar)
5653
import Development.IDE.GHC.Util (printRdrName)
5754
import Ide.PluginUtils (subRange)
55+
import Ide.Types
56+
57+
descriptor :: PluginId -> PluginDescriptor IdeState
58+
descriptor plId =
59+
(defaultPluginDescriptor plId)
60+
{ pluginRules = rulePackageExports,
61+
pluginCodeActionProvider = Just codeAction
62+
}
5863

5964
-- | Generate code actions.
6065
codeAction
6166
:: LSP.LspFuncs c
6267
-> IdeState
68+
-> PluginId
6369
-> TextDocumentIdentifier
6470
-> Range
6571
-> CodeActionContext
66-
-> IO (Either ResponseError [CAResult])
67-
codeAction lsp state (TextDocumentIdentifier uri) _range CodeActionContext{_diagnostics=List xs} = do
72+
-> IO (Either ResponseError (List CAResult))
73+
codeAction lsp state _ (TextDocumentIdentifier uri) _range CodeActionContext{_diagnostics=List xs} = do
6874
contents <- LSP.getVirtualFileFunc lsp $ toNormalizedUri uri
6975
let text = Rope.toText . (_text :: VirtualFile -> Rope.Rope) <$> contents
7076
mbFile = toNormalizedFilePath' <$> uriToFilePath uri
@@ -98,7 +104,7 @@ codeAction lsp state (TextDocumentIdentifier uri) _range CodeActionContext{_diag
98104
<> actions
99105
<> actions'
100106
<> caRemoveInvalidExports parsedModule text diag xs uri
101-
pure $ Right actions''
107+
pure $ Right $ List actions''
102108

103109
mkCA :: T.Text -> [Diagnostic] -> WorkspaceEdit -> CAResult
104110
mkCA title diags edit =

ghcide/src/Development/IDE/Plugin/HLS/GhcIde.hs

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module Development.IDE.Plugin.HLS.GhcIde
77
descriptor
88
) where
99
import Development.IDE
10-
import Development.IDE.Plugin.CodeAction as CodeAction
1110
import Development.IDE.LSP.HoverDefinition
1211
import Development.IDE.LSP.Outline
1312
import Ide.PluginUtils
@@ -19,10 +18,8 @@ import Text.Regex.TDFA.Text()
1918

2019
descriptor :: PluginId -> PluginDescriptor IdeState
2120
descriptor plId = (defaultPluginDescriptor plId)
22-
{ pluginCodeActionProvider = Just codeAction'
23-
, pluginHoverProvider = Just hover'
21+
{ pluginHoverProvider = Just hover'
2422
, pluginSymbolsProvider = Just symbolsProvider
25-
, pluginRules = rulePackageExports
2623
}
2724

2825
-- ---------------------------------------------------------------------
@@ -32,9 +29,6 @@ hover' ideState params = do
3229
logDebug (ideLogger ideState) "GhcIde.hover entered (ideLogger)" -- AZ
3330
hover ideState params
3431

35-
codeAction' :: CodeActionProvider IdeState
36-
codeAction' lf ide _ doc range context = fmap List <$> codeAction lf ide doc range context
37-
3832
-- ---------------------------------------------------------------------
3933
symbolsProvider :: SymbolsProvider IdeState
4034
symbolsProvider ls ide params = do

0 commit comments

Comments
 (0)