Skip to content

Commit c3ce8a4

Browse files
committed
really enable Test plugin
1 parent 1d4eaa7 commit c3ce8a4

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

ghcide/exe/Main.hs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ main = do
5151

5252
whenJust argsCwd IO.setCurrentDirectory
5353

54-
Main.defaultMain def
54+
let arguments = if argsTesting then Main.testing else def
55+
56+
Main.defaultMain arguments
5557
{Main.argCommand = argsCommand
5658

5759
,Main.argsRules = do
@@ -62,20 +64,13 @@ main = do
6264
unless argsDisableKick $
6365
action kick
6466

65-
,Main.argsHlsPlugins =
66-
pluginDescToIdePlugins $
67-
GhcIde.descriptors
68-
++ [Test.blockCommandDescriptor "block-command" | argsTesting]
69-
++ [Test.plugin | argsTesting]
70-
7167
,Main.argsThreads = case argsThreads of 0 -> Nothing ; i -> Just (fromIntegral i)
7268

73-
,Main.argsIdeOptions = \config sessionLoader ->
74-
let defOptions = defaultIdeOptions sessionLoader
69+
,Main.argsIdeOptions = \config sessionLoader ->
70+
let defOptions = Main.argsIdeOptions arguments config sessionLoader
7571
in defOptions
7672
{ optShakeProfiling = argsShakeProfiling
7773
, optOTMemoryProfiling = IdeOTMemoryProfiling argsOTMemoryProfiling
78-
, optTesting = IdeTesting argsTesting
7974
, optShakeOptions = (optShakeOptions defOptions){shakeThreads = argsThreads}
8075
, optCheckParents = pure $ checkParents config
8176
, optCheckProject = pure $ checkProject config

ghcide/src/Development/IDE/Main.hs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Development.IDE.Main
66
,isLSP
77
,commandP
88
,defaultMain
9-
) where
9+
,testing) where
1010
import Control.Concurrent.Extra (newLock, readVar,
1111
withLock,
1212
withNumCapabilities)
@@ -55,6 +55,7 @@ import Development.IDE.LSP.LanguageServer (runLanguageServer)
5555
import Development.IDE.Plugin (Plugin (pluginHandlers, pluginModifyDynflags, pluginRules))
5656
import Development.IDE.Plugin.HLS (asGhcIdePlugin)
5757
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
58+
import qualified Development.IDE.Plugin.Test as Test
5859
import Development.IDE.Session (SessionLoadingOptions,
5960
getHieDbLoc,
6061
loadSessionWithOptions,
@@ -65,9 +66,11 @@ import Development.IDE.Types.Location (NormalizedUri,
6566
import Development.IDE.Types.Logger (Logger (Logger))
6667
import Development.IDE.Types.Options (IdeGhcSession,
6768
IdeOptions (optCheckParents, optCheckProject, optReportProgress, optRunSubset),
69+
IdeTesting (IdeTesting),
6870
clientSupportsProgress,
6971
defaultIdeOptions,
70-
optModifyDynFlags)
72+
optModifyDynFlags,
73+
optTesting)
7174
import Development.IDE.Types.Shake (Key (Key))
7275
import GHC.Conc (getNumProcessors)
7376
import GHC.IO.Encoding (setLocaleEncoding)
@@ -81,6 +84,7 @@ import Ide.Plugin.ConfigUtils (pluginsToDefaultConfig,
8184
pluginsToVSCodeExtensionSchema)
8285
import Ide.PluginUtils (allLspCmdIds',
8386
getProcessID,
87+
idePluginsToPluginDesc,
8488
pluginDescToIdePlugins)
8589
import Ide.Types (IdeCommand (IdeCommand),
8690
IdePlugins,
@@ -201,6 +205,18 @@ instance Default Arguments where
201205
return newStdout
202206
}
203207

208+
testing :: Arguments
209+
testing = def {
210+
argsHlsPlugins = pluginDescToIdePlugins $
211+
idePluginsToPluginDesc (argsHlsPlugins def)
212+
++ [Test.blockCommandDescriptor "block-command", Test.plugin],
213+
argsIdeOptions = \config sessionLoader ->
214+
let defOptions = argsIdeOptions def config sessionLoader
215+
in defOptions {
216+
optTesting = IdeTesting True
217+
}
218+
}
219+
204220
-- | Cheap stderr logger that relies on LineBuffering
205221
stderrLogger :: IO Logger
206222
stderrLogger = do

ghcide/test/exe/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4627,7 +4627,7 @@ projectCompletionTests =
46274627
<- compls
46284628
, _label == "anidentifier"
46294629
]
4630-
liftIO $ compls' @?= ["Defined in 'A"],
4630+
liftIO $ compls' @?= ["Defined in 'A"],
46314631
testSession' "auto complete project imports" $ \dir-> do
46324632
liftIO $ writeFile (dir </> "hie.yaml")
46334633
"cradle: {direct: {arguments: [\"-Wmissing-signatures\", \"ALocalModule\", \"B\"]}}"
@@ -5822,7 +5822,7 @@ unitTests = do
58225822
| i <- [(1::Int)..20]
58235823
] ++ Ghcide.descriptors
58245824

5825-
testIde def{IDE.argsHlsPlugins = plugins} $ do
5825+
testIde IDE.testing{IDE.argsHlsPlugins = plugins} $ do
58265826
_ <- createDoc "haskell" "A.hs" "module A where"
58275827
waitForProgressDone
58285828
actualOrder <- liftIO $ readIORef orderRef

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Ide.PluginUtils
1010
diffText,
1111
diffText',
1212
pluginDescToIdePlugins,
13+
idePluginsToPluginDesc,
1314
responseError,
1415
getClientConfig,
1516
getPluginConfig,
@@ -24,7 +25,8 @@ module Ide.PluginUtils
2425
allLspCmdIds',
2526
installSigUsr1Handler,
2627
subRange,
27-
usePropertyLsp)
28+
usePropertyLsp,
29+
)
2830
where
2931

3032

@@ -149,6 +151,8 @@ pluginDescToIdePlugins :: [PluginDescriptor ideState] -> IdePlugins ideState
149151
pluginDescToIdePlugins plugins =
150152
IdePlugins $ map (\p -> (pluginId p, p)) $ nubOrdOn pluginId plugins
151153

154+
idePluginsToPluginDesc :: IdePlugins ideState -> [PluginDescriptor ideState]
155+
idePluginsToPluginDesc (IdePlugins pp) = map snd pp
152156

153157
-- ---------------------------------------------------------------------
154158
-- | Returns the current client configuration. It is not wise to permanently

hls-test-utils/src/Test/Hls.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ import Development.IDE.Plugin.Test (TestRequest (WaitForShakeQue
4848
import Development.IDE.Types.Options
4949
import GHC.IO.Handle
5050
import Ide.Plugin.Config (Config, formattingProvider)
51-
import Ide.PluginUtils (pluginDescToIdePlugins)
51+
import Ide.PluginUtils (idePluginsToPluginDesc,
52+
pluginDescToIdePlugins)
5253
import Ide.Types
5354
import Language.LSP.Test
5455
import Language.LSP.Types hiding
@@ -170,15 +171,15 @@ runSessionWithServer' plugin conf sconf caps root s = withLock lock $ keepCurren
170171
server <-
171172
async $
172173
Ghcide.defaultMain
173-
def
174+
testing
174175
{ argsHandleIn = pure inR,
175176
argsHandleOut = pure outW,
176177
argsDefaultHlsConfig = conf,
177178
argsLogger = pure noLogging,
178179
argsIdeOptions = \config sessionLoader ->
179180
let ideOptions = (argsIdeOptions def config sessionLoader) {optTesting = IdeTesting True}
180181
in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2}},
181-
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide.descriptors
182+
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ idePluginsToPluginDesc (argsHlsPlugins testing)
182183
}
183184
x <- runSessionWithHandles inW outR sconf caps root s
184185
hClose inW

0 commit comments

Comments
 (0)