Skip to content

Implement PluginMethod for hard-wired in handlers #2977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions ghcide/src/Development/IDE/LSP/HoverDefinition.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@

-- | Display information on hover.
module Development.IDE.LSP.HoverDefinition
( setIdeHandlers
(
-- * For haskell-language-server
, hover
hover
, gotoDefinition
, gotoTypeDefinition
, documentHighlight
, references
, wsSymbols
) where

import Control.Monad.IO.Class
import Development.IDE.Core.Actions
import Development.IDE.Core.Rules
import Development.IDE.Core.Shake
import Development.IDE.LSP.Server
import Development.IDE.Types.Location
import Development.IDE.Types.Logger
import qualified Language.LSP.Server as LSP
Expand Down Expand Up @@ -53,18 +55,6 @@ foundHover :: (Maybe Range, [T.Text]) -> Maybe Hover
foundHover (mbRange, contents) =
Just $ Hover (HoverContents $ MarkupContent MkMarkdown $ T.intercalate sectionSeparator contents) mbRange

setIdeHandlers :: LSP.Handlers (ServerM c)
setIdeHandlers = mconcat
[ requestHandler STextDocumentDefinition $ \ide DefinitionParams{..} ->
gotoDefinition ide TextDocumentPositionParams{..}
, requestHandler STextDocumentTypeDefinition $ \ide TypeDefinitionParams{..} ->
gotoTypeDefinition ide TextDocumentPositionParams{..}
, requestHandler STextDocumentDocumentHighlight $ \ide DocumentHighlightParams{..} ->
documentHighlight ide TextDocumentPositionParams{..}
, requestHandler STextDocumentReferences references
, requestHandler SWorkspaceSymbol wsSymbols
]

-- | Respond to and log a hover or go-to-definition request
request
:: T.Text
Expand Down
8 changes: 1 addition & 7 deletions ghcide/src/Development/IDE/LSP/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import UnliftIO.Exception
import Development.IDE.Core.IdeConfiguration
import Development.IDE.Core.Shake hiding (Log)
import Development.IDE.Core.Tracing
import Development.IDE.LSP.HoverDefinition
import Development.IDE.Types.Logger

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

let ideHandlers = mconcat
[ setIdeHandlers
, userHandlers
]

-- Send everything over a channel, since you need to wait until after initialise before
-- LspFuncs is available
clientMsgChan :: Chan ReactorMessage <- newChan

let asyncHandlers = mconcat
[ ideHandlers
[ userHandlers
, cancelHandler cancelRequest
, exitHandler exit
, shutdownHandler stopReactorLoop
Expand Down
11 changes: 10 additions & 1 deletion ghcide/src/Development/IDE/Plugin/HLS/GhcIde.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ descriptors recorder =
descriptor :: PluginId -> PluginDescriptor IdeState
descriptor plId = (defaultPluginDescriptor plId)
{ pluginHandlers = mkPluginHandler STextDocumentHover hover'
<> mkPluginHandler STextDocumentDocumentSymbol symbolsProvider,
<> mkPluginHandler STextDocumentDocumentSymbol symbolsProvider
<> mkPluginHandler STextDocumentDefinition (\ide _ DefinitionParams{..} ->
gotoDefinition ide TextDocumentPositionParams{..})
<> mkPluginHandler STextDocumentTypeDefinition (\ide _ TypeDefinitionParams{..} ->
gotoTypeDefinition ide TextDocumentPositionParams{..})
<> mkPluginHandler STextDocumentDocumentHighlight (\ide _ DocumentHighlightParams{..} ->
documentHighlight ide TextDocumentPositionParams{..})
<> mkPluginHandler STextDocumentReferences (\ide _ params -> references ide params)
<> mkPluginHandler SWorkspaceSymbol (\ide _ params -> wsSymbols ide params),

pluginConfigDescriptor = defaultConfigDescriptor {configEnableGenericConfig = False}
}

Expand Down
19 changes: 19 additions & 0 deletions hls-plugin-api/src/Ide/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,25 @@ instance PluginMethod TextDocumentCodeAction where
, Just caKind <- ca ^. kind = any (\k -> k `codeActionKindSubsumes` caKind) allowed
| otherwise = False

instance PluginMethod TextDocumentDefinition where
pluginEnabled _ _ _ = True
combineResponses _ _ _ _ (x :| _) = x

instance PluginMethod TextDocumentTypeDefinition where
pluginEnabled _ _ _ = True
combineResponses _ _ _ _ (x :| _) = x

instance PluginMethod TextDocumentDocumentHighlight where
pluginEnabled _ _ _ = True
combineResponses _ _ _ _ (x :| _) = x

instance PluginMethod TextDocumentReferences where
pluginEnabled _ _ _ = True
combineResponses _ _ _ _ (x :| _) = x

instance PluginMethod WorkspaceSymbol where
pluginEnabled _ _ _ = True

instance PluginMethod TextDocumentCodeLens where
pluginEnabled _ = pluginEnabledConfig plcCodeLensOn
instance PluginMethod TextDocumentRename where
Expand Down