Skip to content

Commit 44be741

Browse files
authored
Implement PluginMethod for hard-wired in handlers (#2977)
Don't hard-wire handlers, but make sure all handlers are associated to a PluginDescriptor, s.t. we can check that the handler is actually enabled for a given request.
1 parent 2121495 commit 44be741

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

ghcide/src/Development/IDE/LSP/HoverDefinition.hs

+5-15
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55

66
-- | Display information on hover.
77
module Development.IDE.LSP.HoverDefinition
8-
( setIdeHandlers
8+
(
99
-- * For haskell-language-server
10-
, hover
10+
hover
1111
, gotoDefinition
1212
, gotoTypeDefinition
13+
, documentHighlight
14+
, references
15+
, wsSymbols
1316
) where
1417

1518
import Control.Monad.IO.Class
1619
import Development.IDE.Core.Actions
1720
import Development.IDE.Core.Rules
1821
import Development.IDE.Core.Shake
19-
import Development.IDE.LSP.Server
2022
import Development.IDE.Types.Location
2123
import Development.IDE.Types.Logger
2224
import qualified Language.LSP.Server as LSP
@@ -53,18 +55,6 @@ foundHover :: (Maybe Range, [T.Text]) -> Maybe Hover
5355
foundHover (mbRange, contents) =
5456
Just $ Hover (HoverContents $ MarkupContent MkMarkdown $ T.intercalate sectionSeparator contents) mbRange
5557

56-
setIdeHandlers :: LSP.Handlers (ServerM c)
57-
setIdeHandlers = mconcat
58-
[ requestHandler STextDocumentDefinition $ \ide DefinitionParams{..} ->
59-
gotoDefinition ide TextDocumentPositionParams{..}
60-
, requestHandler STextDocumentTypeDefinition $ \ide TypeDefinitionParams{..} ->
61-
gotoTypeDefinition ide TextDocumentPositionParams{..}
62-
, requestHandler STextDocumentDocumentHighlight $ \ide DocumentHighlightParams{..} ->
63-
documentHighlight ide TextDocumentPositionParams{..}
64-
, requestHandler STextDocumentReferences references
65-
, requestHandler SWorkspaceSymbol wsSymbols
66-
]
67-
6858
-- | Respond to and log a hover or go-to-definition request
6959
request
7060
:: T.Text

ghcide/src/Development/IDE/LSP/LanguageServer.hs

+1-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import UnliftIO.Exception
3535
import Development.IDE.Core.IdeConfiguration
3636
import Development.IDE.Core.Shake hiding (Log)
3737
import Development.IDE.Core.Tracing
38-
import Development.IDE.LSP.HoverDefinition
3938
import Development.IDE.Types.Logger
4039

4140
import Control.Monad.IO.Unlift (MonadUnliftIO)
@@ -120,17 +119,12 @@ runLanguageServer recorder options inH outH getHieDbLoc defaultConfig onConfigur
120119
cancelled <- readTVar cancelledRequests
121120
unless (reqId `Set.member` cancelled) retry
122121

123-
let ideHandlers = mconcat
124-
[ setIdeHandlers
125-
, userHandlers
126-
]
127-
128122
-- Send everything over a channel, since you need to wait until after initialise before
129123
-- LspFuncs is available
130124
clientMsgChan :: Chan ReactorMessage <- newChan
131125

132126
let asyncHandlers = mconcat
133-
[ ideHandlers
127+
[ userHandlers
134128
, cancelHandler cancelRequest
135129
, exitHandler exit
136130
, shutdownHandler stopReactorLoop

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@ descriptors recorder =
4949
descriptor :: PluginId -> PluginDescriptor IdeState
5050
descriptor plId = (defaultPluginDescriptor plId)
5151
{ pluginHandlers = mkPluginHandler STextDocumentHover hover'
52-
<> mkPluginHandler STextDocumentDocumentSymbol symbolsProvider,
52+
<> mkPluginHandler STextDocumentDocumentSymbol symbolsProvider
53+
<> mkPluginHandler STextDocumentDefinition (\ide _ DefinitionParams{..} ->
54+
gotoDefinition ide TextDocumentPositionParams{..})
55+
<> mkPluginHandler STextDocumentTypeDefinition (\ide _ TypeDefinitionParams{..} ->
56+
gotoTypeDefinition ide TextDocumentPositionParams{..})
57+
<> mkPluginHandler STextDocumentDocumentHighlight (\ide _ DocumentHighlightParams{..} ->
58+
documentHighlight ide TextDocumentPositionParams{..})
59+
<> mkPluginHandler STextDocumentReferences (\ide _ params -> references ide params)
60+
<> mkPluginHandler SWorkspaceSymbol (\ide _ params -> wsSymbols ide params),
61+
5362
pluginConfigDescriptor = defaultConfigDescriptor {configEnableGenericConfig = False}
5463
}
5564

hls-plugin-api/src/Ide/Types.hs

+19
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,25 @@ instance PluginMethod TextDocumentCodeAction where
205205
, Just caKind <- ca ^. kind = any (\k -> k `codeActionKindSubsumes` caKind) allowed
206206
| otherwise = False
207207

208+
instance PluginMethod TextDocumentDefinition where
209+
pluginEnabled _ _ _ = True
210+
combineResponses _ _ _ _ (x :| _) = x
211+
212+
instance PluginMethod TextDocumentTypeDefinition where
213+
pluginEnabled _ _ _ = True
214+
combineResponses _ _ _ _ (x :| _) = x
215+
216+
instance PluginMethod TextDocumentDocumentHighlight where
217+
pluginEnabled _ _ _ = True
218+
combineResponses _ _ _ _ (x :| _) = x
219+
220+
instance PluginMethod TextDocumentReferences where
221+
pluginEnabled _ _ _ = True
222+
combineResponses _ _ _ _ (x :| _) = x
223+
224+
instance PluginMethod WorkspaceSymbol where
225+
pluginEnabled _ _ _ = True
226+
208227
instance PluginMethod TextDocumentCodeLens where
209228
pluginEnabled _ = pluginEnabledConfig plcCodeLensOn
210229
instance PluginMethod TextDocumentRename where

0 commit comments

Comments
 (0)