diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 884140c4e6..b8fda76503 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -215,3 +215,7 @@ jobs: - if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test}} name: Test hls-rename-plugin test suite run: cabal test hls-rename-plugin --test-options="-j1 --rerun-update" || cabal test hls-rename-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-rename-plugin --test-options="-j1 --rerun" + + - if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test}} + name: Test hls-hlint-plugin test suite + run: cabal test hls-hlint-plugin --test-options="-j1 --rerun-update" || cabal test hls-hlint-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-hlint-plugin --test-options="-j1 --rerun" diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 032a8b699f..0002f6932b 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -21,9 +21,6 @@ extra-source-files: test/testdata/**/*.project test/testdata/**/*.cabal test/testdata/**/*.yaml - -- this one is not matched by the previous glob - test/testdata/hlint/ignore/.hlint.yaml - test/testdata/**/*.h test/testdata/**/*.hs flag pedantic diff --git a/hls-test-utils/src/Test/Hls.hs b/hls-test-utils/src/Test/Hls.hs index 512ae1b744..dec2542f7a 100644 --- a/hls-test-utils/src/Test/Hls.hs +++ b/hls-test-utils/src/Test/Hls.hs @@ -24,8 +24,10 @@ module Test.Hls waitForAllProgressDone, PluginDescriptor, IdeState, - waitForBuildQueue - ,waitForTypecheck,waitForAction) + waitForBuildQueue, + waitForTypecheck, + waitForAction, + sendConfigurationChanged) where import Control.Applicative.Combinators @@ -222,8 +224,12 @@ waitForAction key TextDocumentIdentifier{_uri} = do return $ do e <- _result case A.fromJSON e of - A.Error e -> Left $ ResponseError InternalError (T.pack e) Nothing + A.Error err -> Left $ ResponseError InternalError (T.pack err) Nothing A.Success a -> pure a waitForTypecheck :: TextDocumentIdentifier -> Session (Either ResponseError Bool) waitForTypecheck tid = fmap ideResultSuccess <$> waitForAction "typecheck" tid + +sendConfigurationChanged :: Value -> Session () +sendConfigurationChanged config = + sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams config) diff --git a/hls-test-utils/src/Test/Hls/Util.hs b/hls-test-utils/src/Test/Hls/Util.hs index 05e06b7d64..9add1ca02f 100644 --- a/hls-test-utils/src/Test/Hls/Util.hs +++ b/hls-test-utils/src/Test/Hls/Util.hs @@ -22,6 +22,7 @@ module Test.Hls.Util , ghcVersion, GhcVersion(..) , hostOS, OS(..) , matchesCurrentEnv, EnvSpec(..) + , noLiteralCaps , ignoreForGhcVersions , ignoreInEnv , inspectCodeAction @@ -74,6 +75,12 @@ import Test.Tasty.HUnit (Assertion, assertFailure, import Text.Blaze.Internal hiding (null) import Text.Blaze.Renderer.String (renderMarkup) +noLiteralCaps :: C.ClientCapabilities +noLiteralCaps = def { C._textDocument = Just textDocumentCaps } + where + textDocumentCaps = def { C._codeAction = Just codeActionCaps } + codeActionCaps = CodeActionClientCapabilities (Just True) Nothing Nothing Nothing Nothing Nothing Nothing + codeActionSupportCaps :: C.ClientCapabilities codeActionSupportCaps = def { C._textDocument = Just textDocumentCaps } where diff --git a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal index 3153e1cb33..316bdf0f36 100644 --- a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal +++ b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal @@ -1,4 +1,4 @@ -cabal-version: 2.2 +cabal-version: 2.4 name: hls-hlint-plugin version: 1.0.1.1 synopsis: Hlint integration plugin with Haskell Language Server @@ -8,10 +8,17 @@ description: license: Apache-2.0 license-file: LICENSE author: The Haskell IDE Team -maintainer: alan.zimm@gmail.com +maintainer: atreyu.bbb@gmail.com copyright: The Haskell IDE Team category: Development build-type: Simple +extra-source-files: + LICENSE + test/testdata/**/*.yaml + -- this one is not matched by the previous glob + test/testdata/ignore/.hlint.yaml + test/testdata/**/*.hs + test/testdata/**/*.h flag pedantic description: Enable -Werror @@ -101,3 +108,21 @@ library default-extensions: DataKinds TypeOperators + +test-suite tests + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: test + main-is: Main.hs + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + aeson + , base + , containers + , filepath + , hls-hlint-plugin + , hls-plugin-api + , hls-test-utils >=1.0 && <1.2 + , lens + , lsp-types + , text diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs new file mode 100644 index 0000000000..0987a5ef3b --- /dev/null +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -0,0 +1,287 @@ +{-# LANGUAGE OverloadedStrings #-} +module Main + ( main + ) where + +import Control.Lens ((^.)) +import Data.Aeson (toJSON, Value (..), object, (.=)) +import Data.List (find) +import qualified Data.Map as Map +import Data.Maybe (fromJust, isJust) +import qualified Data.Text as T +import qualified Ide.Plugin.Hlint as HLint +import Ide.Plugin.Config (hlintOn, Config (..), PluginConfig (..)) +import qualified Language.LSP.Types.Lens as L +import System.FilePath (()) +import Test.Hls +import qualified Ide.Plugin.Config as Plugin + +main :: IO () +main = defaultTestRunner tests + +hlintPlugin :: PluginDescriptor IdeState +hlintPlugin = HLint.descriptor "hlint" + +tests :: TestTree +tests = testGroup "hlint" [ + suggestionsTests + , configTests + ] + +suggestionsTests :: TestTree +suggestionsTests = + testGroup "hlint suggestions" [ + testCase "provides 3.8 code actions including apply all" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact2.hs" "haskell" + diags@(reduceDiag:_) <- waitForDiagnosticsFromSource doc "hlint" + + liftIO $ do + length diags @?= 2 -- "Eta Reduce" and "Redundant Id" + reduceDiag ^. L.range @?= Range (Position 1 0) (Position 1 12) + reduceDiag ^. L.severity @?= Just DsInfo + reduceDiag ^. L.code @?= Just (InR "refact:Eta reduce") + reduceDiag ^. L.source @?= Just "hlint" + + cas <- map fromAction <$> getAllCodeActions doc + + let applyAll = find (\ca -> "Apply all hints" `T.isSuffixOf` (ca ^. L.title)) cas + let redId = find (\ca -> "Redundant id" `T.isSuffixOf` (ca ^. L.title)) cas + let redEta = find (\ca -> "Eta reduce" `T.isSuffixOf` (ca ^. L.title)) cas + + liftIO $ isJust applyAll @? "There is 'Apply all hints' code action" + liftIO $ isJust redId @? "There is 'Redundant id' code action" + liftIO $ isJust redEta @? "There is 'Eta reduce' code action" + + executeCodeAction (fromJust redId) + + contents <- skipManyTill anyMessage $ getDocumentEdit doc + liftIO $ contents @?= "main = undefined\nfoo x = x\n" + + , testCase "falls back to pre 3.8 code actions" $ runSessionWithServer' [hlintPlugin] def def noLiteralCaps "test/testdata" $ do + doc <- openDoc "ApplyRefact2.hs" "haskell" + + _ <- waitForDiagnosticsFromSource doc "hlint" + + cars <- getAllCodeActions doc + etaReduce <- liftIO $ inspectCommand cars ["Eta reduce"] + + executeCommand etaReduce + + contents <- skipManyTill anyMessage $ getDocumentEdit doc + liftIO $ contents @?= "main = undefined\nfoo = id\n" + + , testCase "changing document contents updates hlint diagnostics" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact2.hs" "haskell" + testHlintDiagnostics doc + + let change = TextDocumentContentChangeEvent + (Just (Range (Position 1 8) (Position 1 12))) + Nothing "x" + changeDoc doc [change] + expectNoMoreDiagnostics 3 doc "hlint" + + let change' = TextDocumentContentChangeEvent + (Just (Range (Position 1 8) (Position 1 12))) + Nothing "id x" + changeDoc doc [change'] + testHlintDiagnostics doc + + , knownBrokenForGhcVersions [GHC88, GHC86] "hlint doesn't take in account cpp flag as ghc -D argument" $ + testCase "hlint diagnostics works with CPP via ghc -XCPP argument (#554)" $ runHlintSession "cpp" $ do + doc <- openDoc "ApplyRefact3.hs" "haskell" + testHlintDiagnostics doc + + , knownBrokenForGhcVersions [GHC88, GHC86] "hlint doesn't take in account cpp flag as ghc -D argument" $ + testCase "hlint diagnostics works with CPP via language pragma (#554)" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact3.hs" "haskell" + testHlintDiagnostics doc + + , testCase "hlint diagnostics works with CPP via -XCPP argument and flag via #include header (#554)" $ runHlintSession "cpp" $ do + doc <- openDoc "ApplyRefact2.hs" "haskell" + testHlintDiagnostics doc + + , testCase "apply-refact works with -XLambdaCase argument (#590)" $ runHlintSession "lambdacase" $ do + testRefactor "ApplyRefact1.hs" "Redundant bracket" + expectedLambdaCase + + , testCase "apply-refact works with -XTypeApplications argument (#1242)" $ runHlintSession "typeapps" $ do + testRefactor "ApplyRefact1.hs" "Redundant bracket" + expectedTypeApp + + , testCase "apply hints works with LambdaCase via language pragma" $ runHlintSession "" $ do + testRefactor "ApplyRefact1.hs" "Redundant bracket" + ("{-# LANGUAGE LambdaCase #-}" : expectedLambdaCase) + + , expectFailBecause "apply-refact doesn't work with cpp" $ + testCase "apply hints works with CPP via -XCPP argument" $ runHlintSession "cpp" $ do + testRefactor "ApplyRefact3.hs" "Redundant bracket" + expectedCPP + + , expectFailBecause "apply-refact doesn't work with cpp" $ + testCase "apply hints works with CPP via language pragma" $ runHlintSession "" $ do + testRefactor "ApplyRefact3.hs" "Redundant bracket" + ("{-# LANGUAGE CPP #-}" : expectedCPP) + + , testCase "hlint diagnostics ignore hints honouring .hlint.yaml" $ runHlintSession "ignore" $ do + doc <- openDoc "ApplyRefact.hs" "haskell" + expectNoMoreDiagnostics 3 doc "hlint" + + , testCase "hlint diagnostics ignore hints honouring ANN annotations" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact4.hs" "haskell" + expectNoMoreDiagnostics 3 doc "hlint" + + , knownBrokenForGhcVersions [GHC810, GHC90] "hlint plugin doesn't honour HLINT annotations (#838)" $ + testCase "hlint diagnostics ignore hints honouring HLINT annotations" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact5.hs" "haskell" + expectNoMoreDiagnostics 3 doc "hlint" + + , testCase "apply-refact preserve regular comments" $ runHlintSession "" $ do + testRefactor "ApplyRefact6.hs" "Redundant bracket" expectedComments + + , testCase "applyAll is shown only when there is at least one diagnostic in range" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact8.hs" "haskell" + _ <- waitForDiagnosticsFromSource doc "hlint" + + firstLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 0 0) + secondLine <- map fromAction <$> getCodeActions doc (mkRange 1 0 1 0) + thirdLine <- map fromAction <$> getCodeActions doc (mkRange 2 0 2 0) + multiLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 2 0) + + let hasApplyAll = isJust . find (\ca -> "Apply all hints" `T.isSuffixOf` (ca ^. L.title)) + + liftIO $ hasApplyAll firstLine @? "Missing apply all code action" + liftIO $ hasApplyAll secondLine @? "Missing apply all code action" + liftIO $ not (hasApplyAll thirdLine) @? "Unexpected apply all code action" + liftIO $ hasApplyAll multiLine @? "Missing apply all code action" + ] + where + testRefactor file caTitle expected = do + doc <- openDoc file "haskell" + testHlintDiagnostics doc + + cas <- map fromAction <$> getAllCodeActions doc + let ca = find (\ca -> caTitle `T.isSuffixOf` (ca ^. L.title)) cas + liftIO $ isJust ca @? ("There is '" ++ T.unpack caTitle ++"' code action") + + executeCodeAction (fromJust ca) + + contents <- skipManyTill anyMessage $ getDocumentEdit doc + liftIO $ contents @?= T.unlines expected + + expectedLambdaCase = [ "module ApplyRefact1 where", "" + , "f = \\case \"true\" -> True" + , " _ -> False" + ] + expectedCPP = [ "module ApplyRefact3 where", "" + , "#ifdef FLAG" + , "f = 1" + , "#else" + , "g = 2" + , "#endif", "" + ] + expectedComments = [ "-- comment before header" + , "module ApplyRefact6 where", "" + , "{-# standalone annotation #-}", "" + , "-- standalone comment", "" + , "-- | haddock comment" + , "f = {- inline comment -}{- inline comment inside refactored code -} 1 -- ending comment", "" + , "-- final comment" + ] + expectedTypeApp = [ "module ApplyRefact1 where", "" + , "a = id @Int 1" + ] + +configTests :: TestTree +configTests = testGroup "hlint plugin config" [ + + testCase "changing hlintOn configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do + let config = def { hlintOn = True } + sendConfigurationChanged (toJSON config) + + doc <- openDoc "ApplyRefact2.hs" "haskell" + testHlintDiagnostics doc + + let config' = def { hlintOn = False } + sendConfigurationChanged (toJSON config') + + diags' <- waitForDiagnosticsFrom doc + + liftIO $ noHlintDiagnostics diags' + + , testCase "changing hlint plugin configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do + let config = def { hlintOn = True } + sendConfigurationChanged (toJSON config) + + doc <- openDoc "ApplyRefact2.hs" "haskell" + testHlintDiagnostics doc + + let config' = pluginGlobalOn config "hlint" False + sendConfigurationChanged (toJSON config') + + diags' <- waitForDiagnosticsFrom doc + + liftIO $ noHlintDiagnostics diags' + + , testCase "adding hlint flags to plugin configuration removes hlint diagnostics" $ runHlintSession "" $ do + let config = def { hlintOn = True } + sendConfigurationChanged (toJSON config) + + doc <- openDoc "ApplyRefact2.hs" "haskell" + testHlintDiagnostics doc + + let config' = hlintConfigWithFlags ["--ignore=Redundant id", "--hint=test-hlint-config.yaml"] + sendConfigurationChanged (toJSON config') + + diags' <- waitForDiagnosticsFrom doc + + liftIO $ noHlintDiagnostics diags' + + , testCase "adding hlint flags to plugin configuration adds hlint diagnostics" $ runHlintSession "" $ do + let config = def { hlintOn = True } + sendConfigurationChanged (toJSON config) + + doc <- openDoc "ApplyRefact7.hs" "haskell" + + expectNoMoreDiagnostics 3 doc "hlint" + + let config' = hlintConfigWithFlags ["--with-group=generalise"] + sendConfigurationChanged (toJSON config') + + diags' <- waitForDiagnosticsFromSource doc "hlint" + d <- liftIO $ inspectDiagnostic diags' ["Use <>"] + + liftIO $ do + length diags' @?= 1 + d ^. L.range @?= Range (Position 1 10) (Position 1 21) + d ^. L.severity @?= Just DsInfo + ] + +runHlintSession :: FilePath -> Session a -> IO a +runHlintSession subdir = + failIfSessionTimeout . runSessionWithServer hlintPlugin ("test/testdata" subdir) + +noHlintDiagnostics :: [Diagnostic] -> Assertion +noHlintDiagnostics diags = + Just "hlint" `notElem` map (^. L.source) diags @? "There are no hlint diagnostics" + +testHlintDiagnostics :: TextDocumentIdentifier -> Session () +testHlintDiagnostics doc = do + diags <- waitForDiagnosticsFromSource doc "hlint" + liftIO $ length diags > 0 @? "There are hlint diagnostics" + +pluginGlobalOn :: Config -> T.Text -> Bool -> Config +pluginGlobalOn config pid state = config' + where + pluginConfig = def { plcGlobalOn = state } + config' = def { plugins = Map.insert pid pluginConfig (plugins config) } + +hlintConfigWithFlags :: [T.Text] -> Config +hlintConfigWithFlags flags = + def + { hlintOn = True + , Plugin.plugins = Map.fromList [("hlint", + def { Plugin.plcConfig = unObject $ object ["flags" .= flags] } + )] } + where + unObject (Object obj) = obj + unObject _ = undefined diff --git a/test/testdata/hlint/ApplyRefact1.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact1.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact1.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact1.hs diff --git a/test/testdata/hlint/ApplyRefact2.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact2.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact2.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact2.hs diff --git a/test/testdata/hlint/ApplyRefact3.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact3.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact3.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact3.hs diff --git a/test/testdata/hlint/ApplyRefact4.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact4.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact4.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact4.hs diff --git a/test/testdata/hlint/ApplyRefact5.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact5.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact5.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact5.hs diff --git a/test/testdata/hlint/ApplyRefact6.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact6.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact6.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact6.hs diff --git a/test/testdata/hlint/ApplyRefact7.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact7.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact7.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact7.hs diff --git a/test/testdata/hlint/ApplyRefact8.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact8.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact8.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact8.hs diff --git a/test/testdata/hlint/cpp/ApplyRefact2.hs b/plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact2.hs similarity index 100% rename from test/testdata/hlint/cpp/ApplyRefact2.hs rename to plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact2.hs diff --git a/test/testdata/hlint/cpp/ApplyRefact3.hs b/plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact3.hs similarity index 100% rename from test/testdata/hlint/cpp/ApplyRefact3.hs rename to plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact3.hs diff --git a/test/testdata/hlint/cpp/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/cpp/hie.yaml similarity index 100% rename from test/testdata/hlint/cpp/hie.yaml rename to plugins/hls-hlint-plugin/test/testdata/cpp/hie.yaml diff --git a/test/testdata/hlint/cpp/test.h b/plugins/hls-hlint-plugin/test/testdata/cpp/test.h similarity index 100% rename from test/testdata/hlint/cpp/test.h rename to plugins/hls-hlint-plugin/test/testdata/cpp/test.h diff --git a/test/testdata/hlint/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/hie.yaml similarity index 100% rename from test/testdata/hlint/hie.yaml rename to plugins/hls-hlint-plugin/test/testdata/hie.yaml diff --git a/test/testdata/hlint/ignore/.hlint.yaml b/plugins/hls-hlint-plugin/test/testdata/ignore/.hlint.yaml similarity index 100% rename from test/testdata/hlint/ignore/.hlint.yaml rename to plugins/hls-hlint-plugin/test/testdata/ignore/.hlint.yaml diff --git a/test/testdata/hlint/ignore/ApplyRefact.hs b/plugins/hls-hlint-plugin/test/testdata/ignore/ApplyRefact.hs similarity index 100% rename from test/testdata/hlint/ignore/ApplyRefact.hs rename to plugins/hls-hlint-plugin/test/testdata/ignore/ApplyRefact.hs diff --git a/test/testdata/hlint/ignore/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/ignore/hie.yaml similarity index 100% rename from test/testdata/hlint/ignore/hie.yaml rename to plugins/hls-hlint-plugin/test/testdata/ignore/hie.yaml diff --git a/test/testdata/hlint/lambdacase/ApplyRefact1.hs b/plugins/hls-hlint-plugin/test/testdata/lambdacase/ApplyRefact1.hs similarity index 100% rename from test/testdata/hlint/lambdacase/ApplyRefact1.hs rename to plugins/hls-hlint-plugin/test/testdata/lambdacase/ApplyRefact1.hs diff --git a/test/testdata/hlint/lambdacase/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/lambdacase/hie.yaml similarity index 100% rename from test/testdata/hlint/lambdacase/hie.yaml rename to plugins/hls-hlint-plugin/test/testdata/lambdacase/hie.yaml diff --git a/test/testdata/hlint/test-hlint-config.yaml b/plugins/hls-hlint-plugin/test/testdata/test-hlint-config.yaml similarity index 100% rename from test/testdata/hlint/test-hlint-config.yaml rename to plugins/hls-hlint-plugin/test/testdata/test-hlint-config.yaml diff --git a/test/testdata/hlint/typeapps/ApplyRefact1.hs b/plugins/hls-hlint-plugin/test/testdata/typeapps/ApplyRefact1.hs similarity index 100% rename from test/testdata/hlint/typeapps/ApplyRefact1.hs rename to plugins/hls-hlint-plugin/test/testdata/typeapps/ApplyRefact1.hs diff --git a/test/testdata/hlint/typeapps/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/typeapps/hie.yaml similarity index 100% rename from test/testdata/hlint/typeapps/hie.yaml rename to plugins/hls-hlint-plugin/test/testdata/typeapps/hie.yaml diff --git a/test/functional/Completion.hs b/test/functional/Completion.hs index 94faa05f1e..baabbae830 100644 --- a/test/functional/Completion.hs +++ b/test/functional/Completion.hs @@ -253,8 +253,7 @@ snippetTests = testGroup "snippets" [ let config = object ["haskell" .= object ["plugin" .= object ["ghcide-completions" .= object ["config" .= object ["snippetsOn" .= False]]]]] - sendNotification SWorkspaceDidChangeConfiguration - (DidChangeConfigurationParams config) + sendConfigurationChanged config checkNoSnippets doc diff --git a/test/functional/Config.hs b/test/functional/Config.hs index 6965ffb017..2ad8966034 100644 --- a/test/functional/Config.hs +++ b/test/functional/Config.hs @@ -5,10 +5,7 @@ module Config (tests) where import Control.Lens hiding (List, (.=)) import Control.Monad import Data.Aeson -import qualified Data.Map as Map import qualified Data.Text as T -import Ide.Plugin.Config -import qualified Ide.Plugin.Config as Plugin import Language.LSP.Test as Test import qualified Language.LSP.Types.Lens as L import System.FilePath (()) @@ -19,94 +16,16 @@ import Test.Hls.Command tests :: TestTree tests = testGroup "plugin config" [ - -- Note: because the flag is treated generically in the plugin handler, we - -- do not have to test each individual plugin - hlintTests - , configTests + -- Note: there are more comprehensive tests over config in hls-hlint-plugin + -- TODO: Add generic tests over some example plugin + configTests ] -hlintTests :: TestTree -hlintTests = testGroup "hlint plugin enables" [ - - testCase "changing hlintOn configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do - let config = def { hlintOn = True } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - let config' = def { hlintOn = False } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config')) - - diags' <- waitForDiagnosticsFrom doc - - liftIO $ noHlintDiagnostics diags' - - , testCase "changing hlint plugin configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do - let config = def { hlintOn = True } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - let config' = pluginGlobalOn config "hlint" False - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config')) - - diags' <- waitForDiagnosticsFrom doc - - liftIO $ noHlintDiagnostics diags' - - , testCase "adding hlint flags to plugin configuration removes hlint diagnostics" $ runHlintSession "" $ do - let config = def { hlintOn = True } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - let config' = hlintConfigWithFlags ["--ignore=Redundant id", "--hint=test-hlint-config.yaml"] - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config')) - - diags' <- waitForDiagnosticsFrom doc - - liftIO $ noHlintDiagnostics diags' - - , testCase "adding hlint flags to plugin configuration adds hlint diagnostics" $ runHlintSession "" $ do - let config = def { hlintOn = True } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - - doc <- openDoc "ApplyRefact7.hs" "haskell" - - expectNoMoreDiagnostics 3 doc "hlint" - - let config' = hlintConfigWithFlags ["--with-group=generalise"] - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config')) - - diags' <- waitForDiagnosticsFromSource doc "hlint" - d <- liftIO $ inspectDiagnostic diags' ["Use <>"] - - liftIO $ do - length diags' @?= 1 - d ^. L.range @?= Range (Position 1 10) (Position 1 21) - d ^. L.severity @?= Just DsInfo - ] - where - runHlintSession :: FilePath -> Session a -> IO a - runHlintSession subdir = - failIfSessionTimeout . runSession hlsCommand fullCaps ("test/testdata/hlint" subdir) - - noHlintDiagnostics :: [Diagnostic] -> Assertion - noHlintDiagnostics diags = - Just "hlint" `notElem` map (^. L.source) diags @? "There are no hlint diagnostics" - - testHlintDiagnostics doc = do - diags <- waitForDiagnosticsFromSource doc "hlint" - liftIO $ length diags > 0 @? "There are hlint diagnostics" - configTests :: TestTree configTests = testGroup "config parsing" [ testCase "empty object as user configuration should not send error logMessage" $ runConfigSession "" $ do let config = object [] - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) + sendConfigurationChanged (toJSON config) -- Send custom request so server returns a response to prevent blocking void $ sendNotification (SCustomMethod "non-existent-method") Null @@ -121,20 +40,3 @@ configTests = testGroup "config parsing" [ runConfigSession :: FilePath -> Session a -> IO a runConfigSession subdir = failIfSessionTimeout . runSession hlsCommand fullCaps ("test/testdata" subdir) - -pluginGlobalOn :: Config -> T.Text -> Bool -> Config -pluginGlobalOn config pid state = config' - where - pluginConfig = def { plcGlobalOn = state } - config' = def { plugins = Map.insert pid pluginConfig (plugins config) } - -hlintConfigWithFlags :: [T.Text] -> Config -hlintConfigWithFlags flags = - def - { hlintOn = True - , Plugin.plugins = Map.fromList [("hlint", - def { Plugin.plcConfig = unObject $ object ["flags" .= flags] } - )] } - where - unObject (Object obj) = obj - unObject _ = undefined diff --git a/test/functional/Diagnostic.hs b/test/functional/Diagnostic.hs index bfe304d99e..06d6bf5e03 100644 --- a/test/functional/Diagnostic.hs +++ b/test/functional/Diagnostic.hs @@ -21,21 +21,9 @@ tests = testGroup "diagnostics providers" [ basicTests :: TestTree basicTests = testGroup "Diagnostics work" [ - testCase "hlint produces diagnostics" $ - runSession hlsCommand fullCaps "test/testdata/hlint" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" - diags <- waitForDiagnosticsFromSource doc "hlint" - reduceDiag <- liftIO $ inspectDiagnostic diags ["Eta reduce"] - redundantID <- liftIO $ inspectDiagnostic diags ["Redundant id"] - liftIO $ do - length diags @?= 2 - reduceDiag ^. LSP.range @?= Range (Position 1 0) (Position 1 12) - reduceDiag ^. LSP.severity @?= Just DsInfo - redundantID ^. LSP.severity @?= Just DsInfo - - , testCase "example plugin produces diagnostics" $ - runSession hlsCommandExamplePlugin fullCaps "test/testdata/hlint" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" + testCase "example plugin produces diagnostics" $ + runSession hlsCommandExamplePlugin fullCaps "test/testdata/diagnostics" $ do + doc <- openDoc "Foo.hs" "haskell" diags <- waitForDiagnosticsFromSource doc "example2" reduceDiag <- liftIO $ inspectDiagnostic diags ["example2 diagnostic, hello world"] liftIO $ do @@ -58,7 +46,7 @@ saveTests = testGroup "only diagnostics on save" [ ignoreTestBecause "diagnosticsOnChange parameter is not supported right now" $ testCase "Respects diagnosticsOnChange setting" $ runSession hlsCommandExamplePlugin codeActionSupportCaps "test/testdata" $ do let config = Data.Default.def { diagnosticsOnChange = False } :: Config - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) + sendConfigurationChanged (toJSON config) doc <- openDoc "Hover.hs" "haskell" diags <- waitForDiagnosticsFrom doc diff --git a/test/functional/Format.hs b/test/functional/Format.hs index 4620f4fdd8..43e9366843 100644 --- a/test/functional/Format.hs +++ b/test/functional/Format.hs @@ -56,15 +56,15 @@ providerTests = testGroup "formatting provider" [ doc <- openDoc "Format.hs" "haskell" - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu")) + sendConfigurationChanged (formatLspConfig "ormolu") formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) documentContents doc >>= liftIO . (@?= formattedOrmolu) - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "floskell")) + sendConfigurationChanged (formatLspConfig "floskell") formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) documentContents doc >>= liftIO . (@?= formattedFloskell) - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu")) + sendConfigurationChanged (formatLspConfig "ormolu") formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) documentContents doc >>= liftIO . (@?= formattedOrmoluPostFloskell) , requiresOrmoluPlugin . requiresFloskellPlugin $ testCase "supports both new and old configuration sections" $ runSession hlsCommand fullCaps "test/testdata/format" $ do @@ -73,11 +73,11 @@ providerTests = testGroup "formatting provider" [ doc <- openDoc "Format.hs" "haskell" - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "ormolu")) + sendConfigurationChanged (formatLspConfigOld "ormolu") formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) documentContents doc >>= liftIO . (@?= formattedOrmolu) - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "floskell")) + sendConfigurationChanged (formatLspConfigOld "floskell") formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) documentContents doc >>= liftIO . (@?= formattedFloskell) ] diff --git a/test/functional/FunctionalCodeAction.hs b/test/functional/FunctionalCodeAction.hs index 6c0bd95c4a..cf368b0613 100644 --- a/test/functional/FunctionalCodeAction.hs +++ b/test/functional/FunctionalCodeAction.hs @@ -14,20 +14,17 @@ import Data.Maybe import qualified Data.Text as T import Ide.Plugin.Config import Language.LSP.Test as Test -import qualified Language.LSP.Types.Capabilities as C import qualified Language.LSP.Types.Lens as L import Test.Hls import Test.Hspec.Expectations -import System.FilePath (()) import Test.Hls.Command {-# ANN module ("HLint: ignore Reduce duplication"::String) #-} tests :: TestTree tests = testGroup "code actions" [ - hlintTests - , importTests + importTests , packageTests , redundantImportTests , renameTests @@ -36,194 +33,6 @@ tests = testGroup "code actions" [ , unusedTermTests ] - -hlintTests :: TestTree -hlintTests = testGroup "hlint suggestions" [ - testCase "provides 3.8 code actions including apply all" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" - diags@(reduceDiag:_) <- waitForDiagnosticsFromSource doc "hlint" - - liftIO $ do - length diags @?= 2 -- "Eta Reduce" and "Redundant Id" - reduceDiag ^. L.range @?= Range (Position 1 0) (Position 1 12) - reduceDiag ^. L.severity @?= Just DsInfo - reduceDiag ^. L.code @?= Just (InR "refact:Eta reduce") - reduceDiag ^. L.source @?= Just "hlint" - - cas <- map fromAction <$> getAllCodeActions doc - - let applyAll = find (\ca -> "Apply all hints" `T.isSuffixOf` (ca ^. L.title)) cas - let redId = find (\ca -> "Redundant id" `T.isSuffixOf` (ca ^. L.title)) cas - let redEta = find (\ca -> "Eta reduce" `T.isSuffixOf` (ca ^. L.title)) cas - - liftIO $ isJust applyAll @? "There is 'Apply all hints' code action" - liftIO $ isJust redId @? "There is 'Redundant id' code action" - liftIO $ isJust redEta @? "There is 'Eta reduce' code action" - - executeCodeAction (fromJust redId) - - contents <- skipManyTill anyMessage $ getDocumentEdit doc - liftIO $ contents @?= "main = undefined\nfoo x = x\n" - - , testCase "falls back to pre 3.8 code actions" $ runSession hlsCommand noLiteralCaps "test/testdata/hlint" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" - - _ <- waitForDiagnosticsFromSource doc "hlint" - - cars <- getAllCodeActions doc - etaReduce <- liftIO $ inspectCommand cars ["Eta reduce"] - - executeCommand etaReduce - - contents <- skipManyTill anyMessage $ getDocumentEdit doc - liftIO $ contents @?= "main = undefined\nfoo = id\n" - - , testCase "changing configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do - let config = def { hlintOn = True } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - let config' = def { hlintOn = False } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config')) - - diags' <- waitForDiagnosticsFrom doc - - liftIO $ noHlintDiagnostics diags' - - , testCase "changing document contents updates hlint diagnostics" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - let change = TextDocumentContentChangeEvent - (Just (Range (Position 1 8) (Position 1 12))) - Nothing "x" - changeDoc doc [change] - expectNoMoreDiagnostics 3 doc "hlint" - - let change' = TextDocumentContentChangeEvent - (Just (Range (Position 1 8) (Position 1 12))) - Nothing "id x" - changeDoc doc [change'] - testHlintDiagnostics doc - - , knownBrokenForGhcVersions [GHC88, GHC86] "hlint doesn't take in account cpp flag as ghc -D argument" $ - testCase "hlint diagnostics works with CPP via ghc -XCPP argument (#554)" $ runHlintSession "cpp" $ do - doc <- openDoc "ApplyRefact3.hs" "haskell" - testHlintDiagnostics doc - - , knownBrokenForGhcVersions [GHC88, GHC86] "hlint doesn't take in account cpp flag as ghc -D argument" $ - testCase "hlint diagnostics works with CPP via language pragma (#554)" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact3.hs" "haskell" - testHlintDiagnostics doc - - , testCase "hlint diagnostics works with CPP via -XCPP argument and flag via #include header (#554)" $ runHlintSession "cpp" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - , testCase "apply-refact works with -XLambdaCase argument (#590)" $ runHlintSession "lambdacase" $ do - testRefactor "ApplyRefact1.hs" "Redundant bracket" - expectedLambdaCase - - , testCase "apply-refact works with -XTypeApplications argument (#1242)" $ runHlintSession "typeapps" $ do - testRefactor "ApplyRefact1.hs" "Redundant bracket" - expectedTypeApp - - , testCase "apply hints works with LambdaCase via language pragma" $ runHlintSession "" $ do - testRefactor "ApplyRefact1.hs" "Redundant bracket" - ("{-# LANGUAGE LambdaCase #-}" : expectedLambdaCase) - - , expectFailBecause "apply-refact doesn't work with cpp" $ - testCase "apply hints works with CPP via -XCPP argument" $ runHlintSession "cpp" $ do - testRefactor "ApplyRefact3.hs" "Redundant bracket" - expectedCPP - - , expectFailBecause "apply-refact doesn't work with cpp" $ - testCase "apply hints works with CPP via language pragma" $ runHlintSession "" $ do - testRefactor "ApplyRefact3.hs" "Redundant bracket" - ("{-# LANGUAGE CPP #-}" : expectedCPP) - - , testCase "hlint diagnostics ignore hints honouring .hlint.yaml" $ runHlintSession "ignore" $ do - doc <- openDoc "ApplyRefact.hs" "haskell" - expectNoMoreDiagnostics 3 doc "hlint" - - , testCase "hlint diagnostics ignore hints honouring ANN annotations" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact4.hs" "haskell" - expectNoMoreDiagnostics 3 doc "hlint" - - , knownBrokenForGhcVersions [GHC810, GHC90] "hlint plugin doesn't honour HLINT annotations (#838)" $ - testCase "hlint diagnostics ignore hints honouring HLINT annotations" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact5.hs" "haskell" - expectNoMoreDiagnostics 3 doc "hlint" - - , testCase "apply-refact preserve regular comments" $ runHlintSession "" $ do - testRefactor "ApplyRefact6.hs" "Redundant bracket" expectedComments - - , testCase "applyAll is shown only when there is at least one diagnostic in range" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact8.hs" "haskell" - _ <- waitForDiagnosticsFromSource doc "hlint" - - firstLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 0 0) - secondLine <- map fromAction <$> getCodeActions doc (mkRange 1 0 1 0) - thirdLine <- map fromAction <$> getCodeActions doc (mkRange 2 0 2 0) - multiLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 2 0) - - let hasApplyAll = isJust . find (\ca -> "Apply all hints" `T.isSuffixOf` (ca ^. L.title)) - - liftIO $ hasApplyAll firstLine @? "Missing apply all code action" - liftIO $ hasApplyAll secondLine @? "Missing apply all code action" - liftIO $ not (hasApplyAll thirdLine) @? "Unexpected apply all code action" - liftIO $ hasApplyAll multiLine @? "Missing apply all code action" - ] - where - runHlintSession :: FilePath -> Session a -> IO a - runHlintSession subdir = - failIfSessionTimeout . runSession hlsCommand fullCaps ("test/testdata/hlint" subdir) - - noHlintDiagnostics :: [Diagnostic] -> Assertion - noHlintDiagnostics diags = - Just "hlint" `notElem` map (^. L.source) diags @? "There are no hlint diagnostics" - - testHlintDiagnostics doc = do - diags <- waitForDiagnosticsFromSource doc "hlint" - liftIO $ length diags > 0 @? "There are hlint diagnostics" - - testRefactor file caTitle expected = do - doc <- openDoc file "haskell" - testHlintDiagnostics doc - - cas <- map fromAction <$> getAllCodeActions doc - let ca = find (\ca -> caTitle `T.isSuffixOf` (ca ^. L.title)) cas - liftIO $ isJust ca @? ("There is '" ++ T.unpack caTitle ++"' code action") - - executeCodeAction (fromJust ca) - - contents <- skipManyTill anyMessage $ getDocumentEdit doc - liftIO $ contents @?= T.unlines expected - - expectedLambdaCase = [ "module ApplyRefact1 where", "" - , "f = \\case \"true\" -> True" - , " _ -> False" - ] - expectedCPP = [ "module ApplyRefact3 where", "" - , "#ifdef FLAG" - , "f = 1" - , "#else" - , "g = 2" - , "#endif", "" - ] - expectedComments = [ "-- comment before header" - , "module ApplyRefact6 where", "" - , "{-# standalone annotation #-}", "" - , "-- standalone comment", "" - , "-- | haddock comment" - , "f = {- inline comment -}{- inline comment inside refactored code -} 1 -- ending comment", "" - , "-- final comment" - ] - expectedTypeApp = [ "module ApplyRefact1 where", "" - , "a = id @Int 1" - ] renameTests :: TestTree renameTests = testGroup "rename suggestions" [ testCase "works" $ runSession hlsCommand noLiteralCaps "test/testdata" $ do @@ -269,7 +78,7 @@ importTests = testGroup "import suggestions" [ doc <- openDoc "CodeActionImport.hs" "haskell" -- No Formatting: let config = def { formattingProvider = "none" } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) + sendConfigurationChanged (toJSON config) (diag:_) <- waitForDiagnosticsFrom doc liftIO $ diag ^. L.message @?= "Variable not in scope: when :: Bool -> IO () -> IO ()" @@ -553,17 +362,6 @@ expectFailIfGhc9 reason = disableWingman :: Session () disableWingman = - sendConfigurationChanged $ def + sendConfigurationChanged $ toJSON $ def { plugins = M.fromList [ ("tactics", def { plcGlobalOn = False }) ] } - - -sendConfigurationChanged :: Config -> Session () -sendConfigurationChanged config = - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - -noLiteralCaps :: C.ClientCapabilities -noLiteralCaps = def { C._textDocument = Just textDocumentCaps } - where - textDocumentCaps = def { C._codeAction = Just codeActionCaps } - codeActionCaps = CodeActionClientCapabilities (Just True) Nothing Nothing Nothing Nothing Nothing Nothing diff --git a/test/functional/FunctionalLiquid.hs b/test/functional/FunctionalLiquid.hs index 77a553f7ad..06a489c523 100644 --- a/test/functional/FunctionalLiquid.hs +++ b/test/functional/FunctionalLiquid.hs @@ -19,7 +19,7 @@ tests = testGroup "liquid haskell diagnostics" [ doc <- openDoc "liquid/Evens.hs" "haskell" let config = def { liquidOn = True, hlintOn = False } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) + sendConfigurationChanged (toJSON config) diags <- waitForDiagnosticsFromSource doc "liquid" d <- liftIO $ inspectDiagnostic diags ["Liquid Type Mismatch"] diff --git a/test/functional/Progress.hs b/test/functional/Progress.hs index a4b9ac4fa1..1f8c987cf0 100644 --- a/test/functional/Progress.hs +++ b/test/functional/Progress.hs @@ -27,9 +27,9 @@ tests = "window/workDoneProgress" [ testCase "sends indefinite progress notifications" $ runSession hlsCommand progressCaps "test/testdata" $ do - let path = "hlint" "ApplyRefact2.hs" + let path = "diagnostics" "Foo.hs" _ <- openDoc path "haskell" - expectProgressReports [pack ("Setting up hlint (for " ++ path ++ ")"), "Processing", "Indexing"] + expectProgressReports [pack ("Setting up testdata (for " ++ path ++ ")"), "Processing", "Indexing"] , requiresEvalPlugin $ testCase "eval plugin sends progress reports" $ runSession hlsCommand progressCaps "plugins/hls-eval-plugin/test/testdata" $ do doc <- openDoc "T1.hs" "haskell" @@ -40,14 +40,14 @@ tests = expectProgressReports ["Evaluating"] , requiresOrmoluPlugin $ testCase "ormolu plugin sends progress notifications" $ do runSession hlsCommand progressCaps "test/testdata/format" $ do - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu")) + sendConfigurationChanged (formatLspConfig "ormolu") doc <- openDoc "Format.hs" "haskell" expectProgressReports ["Setting up testdata (for Format.hs)", "Processing", "Indexing"] _ <- sendRequest STextDocumentFormatting $ DocumentFormattingParams Nothing doc (FormattingOptions 2 True Nothing Nothing Nothing) expectProgressReports ["Formatting Format.hs"] , requiresFourmoluPlugin $ testCase "fourmolu plugin sends progress notifications" $ do runSession hlsCommand progressCaps "test/testdata/format" $ do - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "fourmolu")) + sendConfigurationChanged (formatLspConfig "fourmolu") doc <- openDoc "Format.hs" "haskell" expectProgressReports ["Setting up testdata (for Format.hs)", "Processing", "Indexing"] _ <- sendRequest STextDocumentFormatting $ DocumentFormattingParams Nothing doc (FormattingOptions 2 True Nothing Nothing Nothing) @@ -57,7 +57,7 @@ tests = runSession hlsCommand progressCaps "test/testdata" $ do doc <- openDoc "liquid/Evens.hs" "haskell" let config = def{liquidOn = True, hlintOn = False} - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) + sendConfigurationChanged (toJSON config) sendNotification STextDocumentDidSave (DidSaveTextDocumentParams doc Nothing) expectProgressReports ["Running Liquid Haskell on Evens.hs"] ] diff --git a/test/testdata/cabal-helper/implicit-exe/Setup.hs b/test/testdata/cabal-helper/implicit-exe/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/implicit-exe/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/implicit-exe/cabal.project b/test/testdata/cabal-helper/implicit-exe/cabal.project deleted file mode 100644 index bfe6289656..0000000000 --- a/test/testdata/cabal-helper/implicit-exe/cabal.project +++ /dev/null @@ -1 +0,0 @@ -packages: ./ \ No newline at end of file diff --git a/test/testdata/cabal-helper/implicit-exe/implicit-exe.cabal b/test/testdata/cabal-helper/implicit-exe/implicit-exe.cabal deleted file mode 100644 index 3aca1b42fa..0000000000 --- a/test/testdata/cabal-helper/implicit-exe/implicit-exe.cabal +++ /dev/null @@ -1,17 +0,0 @@ -cabal-version: >=1.10 -name: implicit-exe -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: Lib - hs-source-dirs: src - build-depends: base - default-language: Haskell2010 - - -executable implicit-exe - main-is: src/Exe.hs - build-depends: base, implicit-exe - default-language: Haskell2010 \ No newline at end of file diff --git a/test/testdata/cabal-helper/implicit-exe/src/Exe.hs b/test/testdata/cabal-helper/implicit-exe/src/Exe.hs deleted file mode 100644 index ed41929e78..0000000000 --- a/test/testdata/cabal-helper/implicit-exe/src/Exe.hs +++ /dev/null @@ -1,4 +0,0 @@ - -import Lib (someFunc) - -main = someFunc \ No newline at end of file diff --git a/test/testdata/cabal-helper/implicit-exe/src/Lib.hs b/test/testdata/cabal-helper/implicit-exe/src/Lib.hs deleted file mode 100644 index f51af83e20..0000000000 --- a/test/testdata/cabal-helper/implicit-exe/src/Lib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module Lib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/mono-repo/A/A.cabal b/test/testdata/cabal-helper/mono-repo/A/A.cabal deleted file mode 100644 index e70b43fc1d..0000000000 --- a/test/testdata/cabal-helper/mono-repo/A/A.cabal +++ /dev/null @@ -1,15 +0,0 @@ -cabal-version: >=1.10 -name: A -version: 0.1.0.0 -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base - default-language: Haskell2010 - -executable A - main-is: Main.hs - other-modules: MyLib - build-depends: base, A - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/mono-repo/A/Main.hs b/test/testdata/cabal-helper/mono-repo/A/Main.hs deleted file mode 100644 index 60d904e8c1..0000000000 --- a/test/testdata/cabal-helper/mono-repo/A/Main.hs +++ /dev/null @@ -1,8 +0,0 @@ -module Main where - -import qualified MyLib (someFunc) - -main :: IO () -main = do - putStrLn "Hello, Haskell!" - MyLib.someFunc diff --git a/test/testdata/cabal-helper/mono-repo/A/MyLib.hs b/test/testdata/cabal-helper/mono-repo/A/MyLib.hs deleted file mode 100644 index e657c4403f..0000000000 --- a/test/testdata/cabal-helper/mono-repo/A/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/mono-repo/A/Setup.hs b/test/testdata/cabal-helper/mono-repo/A/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/mono-repo/A/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/mono-repo/B/B.cabal b/test/testdata/cabal-helper/mono-repo/B/B.cabal deleted file mode 100644 index 4093e1d0f6..0000000000 --- a/test/testdata/cabal-helper/mono-repo/B/B.cabal +++ /dev/null @@ -1,15 +0,0 @@ -cabal-version: >=1.10 -name: B -version: 0.1.0.0 -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base - default-language: Haskell2010 - -executable B - main-is: Main.hs - other-modules: MyLib - build-depends: base, B - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/mono-repo/B/Main.hs b/test/testdata/cabal-helper/mono-repo/B/Main.hs deleted file mode 100644 index 60d904e8c1..0000000000 --- a/test/testdata/cabal-helper/mono-repo/B/Main.hs +++ /dev/null @@ -1,8 +0,0 @@ -module Main where - -import qualified MyLib (someFunc) - -main :: IO () -main = do - putStrLn "Hello, Haskell!" - MyLib.someFunc diff --git a/test/testdata/cabal-helper/mono-repo/B/MyLib.hs b/test/testdata/cabal-helper/mono-repo/B/MyLib.hs deleted file mode 100644 index e657c4403f..0000000000 --- a/test/testdata/cabal-helper/mono-repo/B/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/mono-repo/B/Setup.hs b/test/testdata/cabal-helper/mono-repo/B/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/mono-repo/B/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/mono-repo/C/C.cabal b/test/testdata/cabal-helper/mono-repo/C/C.cabal deleted file mode 100644 index db5e380f49..0000000000 --- a/test/testdata/cabal-helper/mono-repo/C/C.cabal +++ /dev/null @@ -1,9 +0,0 @@ -cabal-version: >=1.10 -name: C -version: 0.1.0.0 -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/mono-repo/C/MyLib.hs b/test/testdata/cabal-helper/mono-repo/C/MyLib.hs deleted file mode 100644 index e657c4403f..0000000000 --- a/test/testdata/cabal-helper/mono-repo/C/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/mono-repo/C/Setup.hs b/test/testdata/cabal-helper/mono-repo/C/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/mono-repo/C/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/mono-repo/cabal.project b/test/testdata/cabal-helper/mono-repo/cabal.project deleted file mode 100644 index cf2eab3e10..0000000000 --- a/test/testdata/cabal-helper/mono-repo/cabal.project +++ /dev/null @@ -1,4 +0,0 @@ -packages: - ./A/ - ./B/ - ./C/ \ No newline at end of file diff --git a/test/testdata/cabal-helper/multi-source-dirs/Setup.hs b/test/testdata/cabal-helper/multi-source-dirs/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/multi-source-dirs/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/multi-source-dirs/multi-source-dirs.cabal b/test/testdata/cabal-helper/multi-source-dirs/multi-source-dirs.cabal deleted file mode 100644 index 58568683dd..0000000000 --- a/test/testdata/cabal-helper/multi-source-dirs/multi-source-dirs.cabal +++ /dev/null @@ -1,11 +0,0 @@ -cabal-version: >=1.10 -name: multi-source-dirs -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: Lib, BetterLib - hs-source-dirs: src, src/input - build-depends: base - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/multi-source-dirs/src/BetterLib.hs b/test/testdata/cabal-helper/multi-source-dirs/src/BetterLib.hs deleted file mode 100644 index 0784c76d48..0000000000 --- a/test/testdata/cabal-helper/multi-source-dirs/src/BetterLib.hs +++ /dev/null @@ -1,5 +0,0 @@ -module BetterLib where - - -foo = 3 -bar = "String" \ No newline at end of file diff --git a/test/testdata/cabal-helper/multi-source-dirs/src/input/Lib.hs b/test/testdata/cabal-helper/multi-source-dirs/src/input/Lib.hs deleted file mode 100644 index 6c37234910..0000000000 --- a/test/testdata/cabal-helper/multi-source-dirs/src/input/Lib.hs +++ /dev/null @@ -1,6 +0,0 @@ -module Lib where - -foobar = 15 - -fizbuzz :: Int -> String -fizbuzz n = "Fizz" \ No newline at end of file diff --git a/test/testdata/cabal-helper/simple-cabal/MyLib.hs b/test/testdata/cabal-helper/simple-cabal/MyLib.hs deleted file mode 100644 index e657c4403f..0000000000 --- a/test/testdata/cabal-helper/simple-cabal/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/simple-cabal/Setup.hs b/test/testdata/cabal-helper/simple-cabal/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/simple-cabal/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/simple-cabal/simple-cabal-test.cabal b/test/testdata/cabal-helper/simple-cabal/simple-cabal-test.cabal deleted file mode 100644 index 3c8be5d868..0000000000 --- a/test/testdata/cabal-helper/simple-cabal/simple-cabal-test.cabal +++ /dev/null @@ -1,10 +0,0 @@ -cabal-version: >=1.10 -name: simple-cabal-test -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/simple-stack/MyLib.hs b/test/testdata/cabal-helper/simple-stack/MyLib.hs deleted file mode 100644 index e657c4403f..0000000000 --- a/test/testdata/cabal-helper/simple-stack/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/simple-stack/Setup.hs b/test/testdata/cabal-helper/simple-stack/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/simple-stack/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/simple-stack/simple-stack-test.cabal b/test/testdata/cabal-helper/simple-stack/simple-stack-test.cabal deleted file mode 100644 index 264baebfd1..0000000000 --- a/test/testdata/cabal-helper/simple-stack/simple-stack-test.cabal +++ /dev/null @@ -1,10 +0,0 @@ -cabal-version: >=1.10 -name: simple-stack-test -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/sub-package/Setup.hs b/test/testdata/cabal-helper/sub-package/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/sub-package/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/sub-package/app/Main.hs b/test/testdata/cabal-helper/sub-package/app/Main.hs deleted file mode 100644 index 60d904e8c1..0000000000 --- a/test/testdata/cabal-helper/sub-package/app/Main.hs +++ /dev/null @@ -1,8 +0,0 @@ -module Main where - -import qualified MyLib (someFunc) - -main :: IO () -main = do - putStrLn "Hello, Haskell!" - MyLib.someFunc diff --git a/test/testdata/cabal-helper/sub-package/plugins-api/PluginLib.hs b/test/testdata/cabal-helper/sub-package/plugins-api/PluginLib.hs deleted file mode 100644 index 55a7098c23..0000000000 --- a/test/testdata/cabal-helper/sub-package/plugins-api/PluginLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module PluginLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/sub-package/plugins-api/Setup.hs b/test/testdata/cabal-helper/sub-package/plugins-api/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/sub-package/plugins-api/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/sub-package/plugins-api/plugins-api.cabal b/test/testdata/cabal-helper/sub-package/plugins-api/plugins-api.cabal deleted file mode 100644 index 223fa73b95..0000000000 --- a/test/testdata/cabal-helper/sub-package/plugins-api/plugins-api.cabal +++ /dev/null @@ -1,10 +0,0 @@ -cabal-version: >=1.10 -name: plugins-api -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: PluginLib - build-depends: base - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/sub-package/src/MyLib.hs b/test/testdata/cabal-helper/sub-package/src/MyLib.hs deleted file mode 100644 index 53ea5c6332..0000000000 --- a/test/testdata/cabal-helper/sub-package/src/MyLib.hs +++ /dev/null @@ -1,6 +0,0 @@ -module MyLib (someFunc) where - -import qualified PluginLib as L - -someFunc :: IO () -someFunc = L.someFunc diff --git a/test/testdata/cabal-helper/sub-package/sub-package.cabal b/test/testdata/cabal-helper/sub-package/sub-package.cabal deleted file mode 100644 index ba36f1b4d1..0000000000 --- a/test/testdata/cabal-helper/sub-package/sub-package.cabal +++ /dev/null @@ -1,17 +0,0 @@ -cabal-version: >=1.10 -name: sub-package -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base, plugins-api - hs-source-dirs: src - default-language: Haskell2010 - -executable sub-package - main-is: Main.hs - build-depends: base, sub-package - hs-source-dirs: app - default-language: Haskell2010 diff --git a/test/testdata/diagnostics/Foo.hs b/test/testdata/diagnostics/Foo.hs new file mode 100644 index 0000000000..d83992f387 --- /dev/null +++ b/test/testdata/diagnostics/Foo.hs @@ -0,0 +1,2 @@ +main = undefined +foo x = id x