Skip to content
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

Enable the ghcide test plugin in HLS test suites #2243

Merged
merged 11 commits into from
Oct 4, 2021
5 changes: 1 addition & 4 deletions ghcide/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ main = do
pluginDescToIdePlugins $
GhcIde.descriptors
++ [Test.blockCommandDescriptor "block-command" | argsTesting]

,Main.argsGhcidePlugin = if argsTesting
then Test.plugin
else mempty
++ [Test.plugin | argsTesting]

,Main.argsThreads = case argsThreads of 0 -> Nothing ; i -> Just (fromIntegral i)

Expand Down
14 changes: 6 additions & 8 deletions ghcide/src/Development/IDE/Plugin/Test.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
-- | A plugin that adds custom messages for use in tests
module Development.IDE.Plugin.Test
( TestRequest(..)
Expand All @@ -18,7 +19,6 @@ import Data.Aeson
import Data.Aeson.Types
import Data.Bifunctor
import Data.CaseInsensitive (CI, original)
import Data.Default (def)
import Data.Maybe (isJust)
import Data.String
import Data.Text (Text, pack)
Expand All @@ -27,8 +27,6 @@ import Development.IDE.Core.Service
import Development.IDE.Core.Shake
import Development.IDE.GHC.Compat
import Development.IDE.Graph (Action)
import Development.IDE.LSP.Server
import qualified Development.IDE.Plugin as P
import Development.IDE.Types.Action
import Development.IDE.Types.HscEnvEq (HscEnvEq (hscEnv))
import Development.IDE.Types.Location (fromUri)
Expand All @@ -50,11 +48,11 @@ data TestRequest
newtype WaitForIdeRuleResult = WaitForIdeRuleResult { ideResultSuccess::Bool}
deriving newtype (FromJSON, ToJSON)

plugin :: P.Plugin c
plugin = def {
P.pluginRules = return (),
P.pluginHandlers = requestHandler (SCustomMethod "test") testRequestHandler'
}
plugin :: PluginDescriptor IdeState
plugin = (defaultPluginDescriptor "test") {
pluginHandlers = mkPluginHandler (SCustomMethod "test") $ \st _ ->
testRequestHandler' st
}
where
testRequestHandler' ide req
| Just customReq <- parseMaybe parseJSON req
Expand Down
11 changes: 8 additions & 3 deletions hls-plugin-api/src/Ide/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ import GHC.Generics
import Ide.Plugin.Config
import Ide.Plugin.Properties
import Language.LSP.Server (LspM, getVirtualFile)
import Language.LSP.Types hiding (SemanticTokenAbsolute(length, line), SemanticTokenRelative(length), SemanticTokensEdit(_start))
import Language.LSP.Types hiding
(SemanticTokenAbsolute (length, line),
SemanticTokenRelative (length),
SemanticTokensEdit (_start))
import Language.LSP.Types.Capabilities (ClientCapabilities (ClientCapabilities),
TextDocumentClientCapabilities (_codeAction, _documentSymbol))
import Language.LSP.Types.Lens as J (HasChildren (children),
Expand Down Expand Up @@ -285,6 +288,10 @@ instance PluginMethod CallHierarchyIncomingCalls where
instance PluginMethod CallHierarchyOutgoingCalls where
pluginEnabled _ = pluginEnabledConfig plcCallHierarchyOn

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

-- ---------------------------------------------------------------------

-- | Methods which have a PluginMethod instance
Expand Down Expand Up @@ -488,8 +495,6 @@ instance HasTracing CallHierarchyOutgoingCallsParams
-- ---------------------------------------------------------------------

{-# NOINLINE pROCESS_ID #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
pROCESS_ID :: T.Text
pROCESS_ID = unsafePerformIO getPid

Expand Down