Skip to content

[Migrate diagnosticTests] part of #4173 Migrate ghcide tests to hls test utils #4207

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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
361131e
migrate diagnosticTests
soulomoon May 4, 2024
fa0e4de
Merge branch 'master' into soulomoon/update-ghcide-tests-hls-test-uti…
soulomoon May 9, 2024
ef077d2
add test no kick to hls-test-utils
soulomoon May 9, 2024
cc7d3cb
clean up ghcide config
soulomoon May 9, 2024
b887243
use fs
soulomoon May 9, 2024
158caa9
reduce write file
soulomoon May 9, 2024
56195f5
fix up
soulomoon May 10, 2024
b8c6ca9
fix ide log
soulomoon May 10, 2024
46b5f04
fix
soulomoon May 10, 2024
1554f87
Update ghcide/src/Development/IDE/Main.hs
soulomoon May 10, 2024
4388ac0
Update ghcide/test/exe/DiagnosticTests.hs
soulomoon May 10, 2024
f6a7f48
Update hls-test-utils/src/Test/Hls.hs
soulomoon May 10, 2024
aee5c53
Update plugins/hls-refactor-plugin/test/Main.hs
soulomoon May 10, 2024
8aa41f3
Update plugins/hls-refactor-plugin/test/Main.hs
soulomoon May 10, 2024
7d22fb7
Update ghcide/test/exe/DiagnosticTests.hs
soulomoon May 10, 2024
cfd3f53
update recorder
soulomoon May 10, 2024
d40c643
fix
soulomoon May 10, 2024
a03aa22
cleanup
soulomoon May 10, 2024
e2a50f2
Merge branch 'master' into soulomoon/update-ghcide-tests-hls-test-uti…
soulomoon May 10, 2024
5ffbf2f
Merge branch 'master' into soulomoon/update-ghcide-tests-hls-test-uti…
soulomoon May 10, 2024
c8aa5ca
fix
soulomoon May 11, 2024
1f7f49f
Merge branch 'master' into soulomoon/update-ghcide-tests-hls-test-uti…
soulomoon May 12, 2024
d08228d
nitpick
soulomoon May 12, 2024
354854e
Update hls-test-utils/src/Test/Hls.hs
soulomoon May 12, 2024
726a88d
add variable
soulomoon May 12, 2024
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
5 changes: 0 additions & 5 deletions ghcide/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ main = withTelemetryRecorder $ \telemetryRecorder -> do
, IDEMain.argsHlsPlugins = IDEMain.argsHlsPlugins arguments <> pluginDescToIdePlugins [lspRecorderPlugin]

, IDEMain.argsRules = do
-- install the main and ghcide-plugin rules
mainRule (cmapWithPrio LogRules recorder) def
-- install the kick action, which triggers a typecheck on every
-- Shake database restart, i.e. on every user edit.
unless argsDisableKick $
action kick

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

Expand Down
12 changes: 10 additions & 2 deletions ghcide/src/Development/IDE/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,14 @@ data Arguments = Arguments
, argsHandleOut :: IO Handle
, argsThreads :: Maybe Natural
, argsMonitoring :: IO Monitoring
, argsDisableKick :: Bool -- ^ flag to disable kick used for testing
}

defaultArguments :: Recorder (WithPriority Log) -> IdePlugins IdeState -> Arguments
defaultArguments recorder plugins = Arguments
{ argsProjectRoot = Nothing
, argCommand = LSP
, argsRules = mainRule (cmapWithPrio LogRules recorder) def >> action kick
, argsRules = mainRule (cmapWithPrio LogRules recorder) def
, argsGhcidePlugin = mempty
, argsHlsPlugins = pluginDescToIdePlugins (GhcIde.descriptors (cmapWithPrio LogGhcIde recorder)) <> plugins
, argsSessionLoadingOptions = def
Expand Down Expand Up @@ -258,6 +259,7 @@ defaultArguments recorder plugins = Arguments
putStr " " >> hFlush stdout
return newStdout
, argsMonitoring = OpenTelemetry.monitoring
, argsDisableKick = False
}


Expand Down Expand Up @@ -293,7 +295,13 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
plugins = hlsPlugin <> argsGhcidePlugin
options = argsLspOptions { LSP.optExecuteCommandCommands = LSP.optExecuteCommandCommands argsLspOptions <> Just hlsCommands }
argsParseConfig = getConfigFromNotification argsHlsPlugins
rules = argsRules >> pluginRules plugins
rules = do
argsRules
unless argsDisableKick $ action kick
pluginRules plugins
-- install the main and ghcide-plugin rules
-- install the kick action, which triggers a typecheck on every
-- Shake database restart, i.e. on every user edit.

debouncer <- argsDebouncer
inH <- argsHandleIn
Expand Down
1 change: 1 addition & 0 deletions ghcide/test/exe/ClientSettingsTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Language.LSP.Protocol.Types hiding
SemanticTokensEdit (..),
mkRange)
import Language.LSP.Test
import Test.Hls (waitForProgressDone)
import Test.Tasty
import TestUtils

Expand Down
1 change: 1 addition & 0 deletions ghcide/test/exe/CodeLensTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Language.LSP.Protocol.Types hiding
SemanticTokensEdit (..),
mkRange)
import Language.LSP.Test
import Test.Hls (waitForProgressDone)
import Test.Tasty
import Test.Tasty.HUnit
import TestUtils
Expand Down
4 changes: 2 additions & 2 deletions ghcide/test/exe/CompletionTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ tests
]

testSessionEmpty :: TestName -> Session () -> TestTree
testSessionEmpty name = testCase name . runWithDummyPlugin (mkIdeTestFs [FS.directCradle ["A.hs"]])
testSessionEmpty name = testWithDummyPlugin name (mkIdeTestFs [FS.directCradle ["A.hs"]])

testSessionEmptyWithCradle :: TestName -> T.Text -> Session () -> TestTree
testSessionEmptyWithCradle name cradle = testCase name . runWithDummyPlugin (mkIdeTestFs [file "hie.yaml" (text cradle)])
testSessionEmptyWithCradle name cradle = testWithDummyPlugin name (mkIdeTestFs [file "hie.yaml" (text cradle)])

testSessionSingleFile :: TestName -> FilePath -> T.Text -> Session () -> TestTree
testSessionSingleFile testName fp txt session =
Expand Down
50 changes: 39 additions & 11 deletions ghcide/test/exe/Config.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
{-# LANGUAGE PatternSynonyms #-}

module Config where

module Config(
-- * basic config for ghcIde testing
mkIdeTestFs
, dummyPlugin

-- * runners for testing with dummy plugin
, runWithDummyPlugin
, testWithDummyPlugin
, testWithDummyPluginEmpty
, testWithDummyPlugin'
, testWithDummyPluginEmpty'
, testWithDummyPluginAndCap'
, runWithExtraFiles
, testWithExtraFiles

-- * utilities for testing definition and hover
, Expect(..)
, pattern R
, mkR
, checkDefs
, mkL
, lspTestCaps
, lspTestCapsNoFileWatches
) where

import Control.Lens.Setter ((.~))
import Data.Foldable (traverse_)
import Data.Function ((&))
import qualified Data.Text as T
import Development.IDE.Test (canonicalizeUri)
import Ide.Types (defaultPluginDescriptor)
import qualified Language.LSP.Protocol.Lens as L
import Language.LSP.Protocol.Types (Null (..))
import System.FilePath ((</>))
import Test.Hls
Expand All @@ -28,22 +54,18 @@ runWithDummyPlugin = runSessionWithServerInTmpDir def dummyPlugin
runWithDummyPlugin' :: FS.VirtualFileTree -> (FileSystem -> Session a) -> IO a
runWithDummyPlugin' = runSessionWithServerInTmpDirCont' def dummyPlugin

runWithDummyPluginAndCap :: ClientCapabilities -> Session () -> IO ()
runWithDummyPluginAndCap cap = runSessionWithServerAndCapsInTmpDir def dummyPlugin cap (mkIdeTestFs [])
runWithDummyPluginAndCap' :: ClientCapabilities -> (FileSystem -> Session ()) -> IO ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I'm not sure all these functions are necessarily worth it. How bad would it be to just have the FileSystem -> Session () variants and then write _ -> whatever at the use sites?

Copy link
Collaborator Author

@soulomoon soulomoon May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emm, we are at somewhat funny situation, that the one without the extra FileSystem are the most used.
Sure, for not frequent used ones, it would be fine we write _ -> whatever.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'm wondering how bad it would be. Otherwise we have a lot of very similar variant functions 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, anyway

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I mean since we have a lot of test that does not need the FileSystem ,
adding a tons of _ -> whatever is visually bad and and not convenient for us to do the migration.

That is why I want to either do the typeclass polymorphic or just duplicate the test runner function variant.

runWithDummyPluginAndCap' cap = runSessionWithServerAndCapsInTmpDirCont def dummyPlugin cap (mkIdeTestFs [])

testWithDummyPluginAndCap :: String -> ClientCapabilities -> Session () -> TestTree
testWithDummyPluginAndCap caseName cap = testCase caseName . runWithDummyPluginAndCap cap
testWithDummyPluginAndCap' :: String -> ClientCapabilities -> (FileSystem -> Session ()) -> TestTree
testWithDummyPluginAndCap' caseName cap = testCase caseName . runWithDummyPluginAndCap' cap

-- testSessionWithCorePlugin ::(TestRunner cont ()) => TestName -> FS.VirtualFileTree -> cont -> TestTree
testWithDummyPlugin :: String -> FS.VirtualFileTree -> Session () -> TestTree
testWithDummyPlugin caseName vfs = testCase caseName . runWithDummyPlugin vfs
testWithDummyPlugin caseName vfs = testWithDummyPlugin' caseName vfs . const

testWithDummyPlugin' :: String -> FS.VirtualFileTree -> (FileSystem -> Session ()) -> TestTree
testWithDummyPlugin' caseName vfs = testCase caseName . runWithDummyPlugin' vfs

runWithDummyPluginEmpty :: Session a -> IO a
runWithDummyPluginEmpty = runWithDummyPlugin $ mkIdeTestFs []

testWithDummyPluginEmpty :: String -> Session () -> TestTree
testWithDummyPluginEmpty caseName = testWithDummyPlugin caseName $ mkIdeTestFs []

Expand Down Expand Up @@ -114,3 +136,9 @@ defToLocation (InL (Definition (InL l))) = [l]
defToLocation (InL (Definition (InR ls))) = ls
defToLocation (InR (InL defLink)) = (\(DefinitionLink LocationLink{_targetUri,_targetRange}) -> Location _targetUri _targetRange) <$> defLink
defToLocation (InR (InR Null)) = []

lspTestCaps :: ClientCapabilities
lspTestCaps = fullCaps { _window = Just $ WindowClientCapabilities (Just True) Nothing Nothing }

lspTestCapsNoFileWatches :: ClientCapabilities
lspTestCapsNoFileWatches = lspTestCaps & L.workspace . traverse . L.didChangeWatchedFiles .~ Nothing
Loading
Loading