From 93d7b1a4720c57132252e004b5fc5cba6547bcb7 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Fri, 24 Jan 2020 09:40:57 +0100 Subject: [PATCH] Bump ghcide to fix GHC panics in LSP tests (#4176) fixes #4152 changelog_begin changelog_end --- bazel-haskell-deps.bzl | 4 ++-- bazel_tools/haskell-ghcide-expose-compat.patch | 3 ++- compiler/damlc/BUILD.bazel | 1 + compiler/damlc/daml-doc/BUILD.bazel | 1 + compiler/damlc/daml-doc/src/DA/Daml/Doc/Extract.hs | 3 ++- compiler/damlc/daml-ide-core/BUILD.bazel | 1 + .../src/Development/IDE/Core/Service/Daml.hs | 7 +++++-- .../test/Development/IDE/State/API/Testing.hs | 3 ++- compiler/damlc/lib/DA/Cli/Damlc.hs | 2 +- compiler/damlc/lib/DA/Cli/Damlc/IdeState.hs | 9 ++++++--- compiler/damlc/tests/BUILD.bazel | 1 + compiler/damlc/tests/src/DA/Test/DamlDocTest.hs | 3 ++- .../damlc/tests/src/DA/Test/DamlcIntegration.hs | 5 +++-- compiler/damlc/tests/src/DA/Test/ShakeIdeClient.hs | 6 ++---- compiler/damlc/tests/util.bzl | 1 + compiler/lsp-tests/BUILD.bazel | 2 -- compiler/lsp-tests/src/Main.hs | 13 ++++--------- 17 files changed, 36 insertions(+), 29 deletions(-) diff --git a/bazel-haskell-deps.bzl b/bazel-haskell-deps.bzl index ede5e3f629eb..da374b8ec705 100644 --- a/bazel-haskell-deps.bzl +++ b/bazel-haskell-deps.bzl @@ -17,8 +17,8 @@ load("@os_info//:os_info.bzl", "is_windows") load("@dadew//:dadew.bzl", "dadew_tool_home") load("@rules_haskell//haskell:cabal.bzl", "stack_snapshot") -GHCIDE_REV = "e180a626eb05aca2a0c1602022459a7c2633d6f4" -GHCIDE_SHA256 = "9d6e1f125faf7e52647513bf9cf0a874975e2c035ca879466944ad66c51b59d7" +GHCIDE_REV = "8f74783835324ee6dad7faf83b7a62143a48e8c6" +GHCIDE_SHA256 = "36bed2b197dfc296488ed2e994b82193e4505051ffa3050d4844a6c66fab2baa" GHCIDE_VERSION = "0.0.6" def daml_haskell_deps(): diff --git a/bazel_tools/haskell-ghcide-expose-compat.patch b/bazel_tools/haskell-ghcide-expose-compat.patch index 03b85c3a842a..4749132b71ef 100644 --- a/bazel_tools/haskell-ghcide-expose-compat.patch +++ b/bazel_tools/haskell-ghcide-expose-compat.patch @@ -21,12 +21,13 @@ index 930b387..73f4b51 100644 Development.IDE.Import.DependencyInformation Development.IDE.LSP.LanguageServer Development.IDE.LSP.Protocol -@@ -118,13 +122,9 @@ library +@@ -118,14 +122,10 @@ library Development.IDE.Types.Options other-modules: Development.IDE.Core.Debouncer - Development.IDE.Core.Compile Development.IDE.Core.Preprocessor + Development.IDE.Core.FileExists - Development.IDE.GHC.Compat Development.IDE.GHC.CPP - Development.IDE.GHC.Error diff --git a/compiler/damlc/BUILD.bazel b/compiler/damlc/BUILD.bazel index 3113d0acc290..32efeff35157 100644 --- a/compiler/damlc/BUILD.bazel +++ b/compiler/damlc/BUILD.bazel @@ -114,6 +114,7 @@ da_haskell_library( "//compiler/daml-licenses/licenses:licensing.md", ], hackage_deps = [ + "data-default", "aeson-pretty", "aeson", "ansi-wl-pprint", diff --git a/compiler/damlc/daml-doc/BUILD.bazel b/compiler/damlc/daml-doc/BUILD.bazel index 340870df000d..ee116d7877f9 100644 --- a/compiler/damlc/daml-doc/BUILD.bazel +++ b/compiler/damlc/daml-doc/BUILD.bazel @@ -19,6 +19,7 @@ da_haskell_library( "bytestring", "cmark-gfm", "containers", + "data-default", "directory", "extra", "filepath", diff --git a/compiler/damlc/daml-doc/src/DA/Daml/Doc/Extract.hs b/compiler/damlc/daml-doc/src/DA/Daml/Doc/Extract.hs index 53669731e9c9..fa62477b4f08 100644 --- a/compiler/damlc/daml-doc/src/DA/Daml/Doc/Extract.hs +++ b/compiler/damlc/daml-doc/src/DA/Daml/Doc/Extract.hs @@ -42,6 +42,7 @@ import "ghc-lib-parser" Bag (bagToList) import Control.Monad import Control.Monad.Trans.Maybe +import Data.Default import Data.List.Extra import Data.List.Extended (spanMaybe) import Data.Maybe @@ -180,7 +181,7 @@ haddockParse :: (LSP.FromServerMessage -> IO ()) -> MaybeT IO [Service.TcModuleResult] haddockParse diagsLogger opts f = MaybeT $ do vfs <- makeVFSHandle - service <- Service.initialise Service.mainRule (pure $ LSP.IdInt 0) diagsLogger noLogging opts vfs + service <- Service.initialise def Service.mainRule (pure $ LSP.IdInt 0) diagsLogger noLogging opts vfs Service.setFilesOfInterest service (Set.fromList f) Service.runAction service $ runMaybeT $ diff --git a/compiler/damlc/daml-ide-core/BUILD.bazel b/compiler/damlc/daml-ide-core/BUILD.bazel index 574c7d5f30c1..7ba1fae8d2d8 100644 --- a/compiler/damlc/daml-ide-core/BUILD.bazel +++ b/compiler/damlc/daml-ide-core/BUILD.bazel @@ -70,6 +70,7 @@ da_haskell_library( "aeson", "base", "containers", + "data-default", "directory", "extra", "filepath", diff --git a/compiler/damlc/daml-ide-core/src/Development/IDE/Core/Service/Daml.hs b/compiler/damlc/daml-ide-core/src/Development/IDE/Core/Service/Daml.hs index 44e56e431dd7..918f6cb051fa 100644 --- a/compiler/damlc/daml-ide-core/src/Development/IDE/Core/Service/Daml.hs +++ b/compiler/damlc/daml-ide-core/src/Development/IDE/Core/Service/Daml.hs @@ -35,6 +35,7 @@ import Development.IDE.Core.OfInterest import Development.IDE.Core.Shake import Development.IDE.Types.Location import Development.IDE.Types.Options +import qualified Language.Haskell.LSP.Types.Capabilities as LSP import qualified Language.Haskell.LSP.Messages as LSP import qualified Language.Haskell.LSP.Types as LSP @@ -102,7 +103,8 @@ modifyOpenVirtualResources state f = do void $ shakeRun state [] initialise - :: Rules () + :: LSP.ClientCapabilities + -> Rules () -> IO LSP.LspId -> (LSP.FromServerMessage -> IO ()) -> Logger @@ -110,8 +112,9 @@ initialise -> IdeOptions -> VFSHandle -> IO IdeState -initialise mainRule getLspId toDiags logger damlEnv options vfs = +initialise caps mainRule getLspId toDiags logger damlEnv options vfs = IDE.initialise + caps (do addIdeGlobal damlEnv mainRule) getLspId diff --git a/compiler/damlc/daml-ide-core/test/Development/IDE/State/API/Testing.hs b/compiler/damlc/daml-ide-core/test/Development/IDE/State/API/Testing.hs index f2d8a7e5ad3c..8c4e18547854 100644 --- a/compiler/damlc/daml-ide-core/test/Development/IDE/State/API/Testing.hs +++ b/compiler/damlc/daml-ide-core/test/Development/IDE/State/API/Testing.hs @@ -66,6 +66,7 @@ import qualified DA.Daml.LF.Ast as LF import Control.Concurrent.STM import Control.Exception.Extra import qualified Control.Monad.Reader as Reader +import Data.Default import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map import qualified Data.Aeson as Aeson @@ -179,7 +180,7 @@ runShakeTest mbScenarioService (ShakeTest m) = do eventLogger _ = pure () vfs <- API.makeVFSHandle damlEnv <- mkDamlEnv options mbScenarioService - service <- API.initialise (mainRule options) (pure $ IdInt 0) (atomically . eventLogger) noLogging damlEnv (toCompileOpts options (IdeReportProgress False)) vfs + service <- API.initialise def (mainRule options) (pure $ IdInt 0) (atomically . eventLogger) noLogging damlEnv (toCompileOpts options (IdeReportProgress False)) vfs result <- withSystemTempDirectory "shake-api-test" $ \testDirPath -> do let ste = ShakeTestEnv { steService = service diff --git a/compiler/damlc/lib/DA/Cli/Damlc.hs b/compiler/damlc/lib/DA/Cli/Damlc.hs index 003ad7cecb49..40f23797f905 100644 --- a/compiler/damlc/lib/DA/Cli/Damlc.hs +++ b/compiler/damlc/lib/DA/Cli/Damlc.hs @@ -399,7 +399,7 @@ execIde telemetry (Debug debug) enableScenarioService ghcOpts mbProfileDir (from sdkVersion <- getSdkVersion `catchIO` const (pure "Unknown (not started via the assistant)") Logger.logInfo loggerH (T.pack $ "SDK version: " <> sdkVersion) runLanguageServer loggerH $ \getLspId sendMsg vfs caps -> - getDamlIdeState opts mbScenarioService loggerH getLspId sendMsg vfs (clientSupportsProgress caps) + getDamlIdeState opts mbScenarioService loggerH caps getLspId sendMsg vfs (clientSupportsProgress caps) -- | Whether we should write interface files during `damlc compile`. diff --git a/compiler/damlc/lib/DA/Cli/Damlc/IdeState.hs b/compiler/damlc/lib/DA/Cli/Damlc/IdeState.hs index e301cb08393c..84a323e042a7 100644 --- a/compiler/damlc/lib/DA/Cli/Damlc/IdeState.hs +++ b/compiler/damlc/lib/DA/Cli/Damlc/IdeState.hs @@ -7,6 +7,7 @@ module DA.Cli.Damlc.IdeState , withDamlIdeState ) where +import Data.Default import qualified Language.Haskell.LSP.Messages as LSP import Control.Exception @@ -19,20 +20,22 @@ import Development.IDE.Core.API import qualified Development.IDE.Types.Logger as IdeLogger import Development.IDE.Types.Options import qualified Language.Haskell.LSP.Types as LSP +import qualified Language.Haskell.LSP.Types.Capabilities as LSP getDamlIdeState :: Options -> Maybe Scenario.Handle -> Logger.Handle IO + -> LSP.ClientCapabilities -> IO LSP.LspId -> (LSP.FromServerMessage -> IO ()) -> VFSHandle -> IdeReportProgress -> IO IdeState -getDamlIdeState compilerOpts mbScenarioService loggerH getLspId eventHandler vfs reportProgress = do +getDamlIdeState compilerOpts mbScenarioService loggerH caps getLspId eventHandler vfs reportProgress = do let rule = mainRule compilerOpts damlEnv <- mkDamlEnv compilerOpts mbScenarioService - initialise rule getLspId eventHandler (toIdeLogger loggerH) damlEnv (toCompileOpts compilerOpts reportProgress) vfs + initialise caps rule getLspId eventHandler (toIdeLogger loggerH) damlEnv (toCompileOpts compilerOpts reportProgress) vfs -- Wrapper for the common case where the scenario service will be started automatically (if enabled) -- and we use the builtin VFSHandle. @@ -49,7 +52,7 @@ withDamlIdeState opts@Options{..} loggerH eventHandler f = do -- We only use withDamlIdeState outside of the IDE where we do not care about -- progress reporting. bracket - (getDamlIdeState opts mbScenarioService loggerH (pure $ LSP.IdInt 0) eventHandler vfs (IdeReportProgress False)) + (getDamlIdeState opts mbScenarioService loggerH def (pure $ LSP.IdInt 0) eventHandler vfs (IdeReportProgress False)) shutdown f diff --git a/compiler/damlc/tests/BUILD.bazel b/compiler/damlc/tests/BUILD.bazel index 93f8c73c5b15..da2ea42c364d 100644 --- a/compiler/damlc/tests/BUILD.bazel +++ b/compiler/damlc/tests/BUILD.bazel @@ -102,6 +102,7 @@ da_haskell_test( data = ["//compiler/damlc/pkg-db"], hackage_deps = [ "base", + "data-default", "extra", "ghcide", "haskell-lsp-types", diff --git a/compiler/damlc/tests/src/DA/Test/DamlDocTest.hs b/compiler/damlc/tests/src/DA/Test/DamlDocTest.hs index acc66b28b85d..7d97e4e7e1fb 100644 --- a/compiler/damlc/tests/src/DA/Test/DamlDocTest.hs +++ b/compiler/damlc/tests/src/DA/Test/DamlDocTest.hs @@ -3,6 +3,7 @@ module DA.Test.DamlDocTest (main) where +import Data.Default import qualified Data.Text.Extended as T import System.IO.Extra import Test.Tasty @@ -108,6 +109,6 @@ shouldGenerate input expected = withTempFile $ \tmpFile -> do T.writeFileUtf8 tmpFile $ T.unlines $ testModuleHeader <> input opts <- fmap (\opts -> opts{optHaddock=Haddock True}) $ defaultOptionsIO Nothing vfs <- makeVFSHandle - ideState <- initialise mainRule (pure $ LSP.IdInt 0) (const $ pure ()) noLogging (toCompileOpts opts (IdeReportProgress False)) vfs + ideState <- initialise def mainRule (pure $ LSP.IdInt 0) (const $ pure ()) noLogging (toCompileOpts opts (IdeReportProgress False)) vfs Just pm <- runAction ideState $ use GetParsedModule $ toNormalizedFilePath tmpFile genModuleContent (getDocTestModule pm) @?= T.unlines (doctestHeader <> expected) diff --git a/compiler/damlc/tests/src/DA/Test/DamlcIntegration.hs b/compiler/damlc/tests/src/DA/Test/DamlcIntegration.hs index d09bcac19ee2..506fd91a9e7c 100644 --- a/compiler/damlc/tests/src/DA/Test/DamlcIntegration.hs +++ b/compiler/damlc/tests/src/DA/Test/DamlcIntegration.hs @@ -36,6 +36,7 @@ import Development.IDE.Types.Options(IdeReportProgress(..)) import qualified Data.Aeson.Encode.Pretty as A import qualified Data.ByteString.Lazy.Char8 as BSL import Data.Char +import Data.Default import qualified Data.DList as DList import Data.Foldable import Data.List.Extra @@ -138,10 +139,10 @@ getIntegrationTests registerTODO scenarioService version = do -- We use a separate service for generated files so that we can test files containing internal imports. pure $ withResource - (initialise (mainRule opts) (pure $ LSP.IdInt 0) (const $ pure ()) IdeLogger.noLogging damlEnv (toCompileOpts opts (IdeReportProgress False)) vfs) + (initialise def (mainRule opts) (pure $ LSP.IdInt 0) (const $ pure ()) IdeLogger.noLogging damlEnv (toCompileOpts opts (IdeReportProgress False)) vfs) shutdown $ \service -> withResource - (initialise (mainRule opts) (pure $ LSP.IdInt 0) (const $ pure ()) IdeLogger.noLogging damlEnv (toCompileOpts opts { optIsGenerated = True } (IdeReportProgress False)) vfs) + (initialise def (mainRule opts) (pure $ LSP.IdInt 0) (const $ pure ()) IdeLogger.noLogging damlEnv (toCompileOpts opts { optIsGenerated = True } (IdeReportProgress False)) vfs) shutdown $ \serviceGenerated -> withTestArguments $ \args -> testGroup ("Tests for DAML-LF " ++ renderPretty version) $ map (testCase args version service outdir registerTODO) nongeneratedFiles <> diff --git a/compiler/damlc/tests/src/DA/Test/ShakeIdeClient.hs b/compiler/damlc/tests/src/DA/Test/ShakeIdeClient.hs index 2a71b65f7cb9..d4b370fa1d31 100644 --- a/compiler/damlc/tests/src/DA/Test/ShakeIdeClient.hs +++ b/compiler/damlc/tests/src/DA/Test/ShakeIdeClient.hs @@ -839,10 +839,8 @@ onHoverTests mbScenarioService = Tasty.testGroup "On hover tests" , "show b = 2" ] setFilesOfInterest [f] - expectTextOnHover (f,3,[0..3]) $ Contains "```daml\n==\n```" - expectTextOnHover (f,3,[0..3]) $ Contains "```daml\n: Text -> Bool\n```" - expectTextOnHover (f,5,[0..3]) $ Contains "```daml\nshow\n```" - expectTextOnHover (f,5,[0..3]) $ Contains "```daml\n: Bool -> Int\n```" + expectTextOnHover (f,3,[0..3]) $ Contains "```daml\n==\n: Text -> Bool\n```\n" + expectTextOnHover (f,5,[0..3]) $ Contains "```daml\nshow\n: Bool -> Int\n```\n" , testCaseFails' "Type of choice" $ do f <- makeModule "F" diff --git a/compiler/damlc/tests/util.bzl b/compiler/damlc/tests/util.bzl index 97bebb651a7d..c00c15dbb659 100644 --- a/compiler/damlc/tests/util.bzl +++ b/compiler/damlc/tests/util.bzl @@ -92,6 +92,7 @@ def damlc_integration_test(name, main_function): "base", "bytestring", "containers", + "data-default", "deepseq", "directory", "dlist", diff --git a/compiler/lsp-tests/BUILD.bazel b/compiler/lsp-tests/BUILD.bazel index 86594d17a8ea..1762b0992d6b 100644 --- a/compiler/lsp-tests/BUILD.bazel +++ b/compiler/lsp-tests/BUILD.bazel @@ -11,8 +11,6 @@ da_haskell_test( data = [ "//compiler/damlc", ], - # see https://github.com/digital-asset/daml/issues/4152 - flaky = True, hackage_deps = [ "aeson", "base", diff --git a/compiler/lsp-tests/src/Main.hs b/compiler/lsp-tests/src/Main.hs index 6e8463fb161e..32630514ff7e 100644 --- a/compiler/lsp-tests/src/Main.hs +++ b/compiler/lsp-tests/src/Main.hs @@ -344,13 +344,10 @@ requestTests run _runScenarios = testGroup "requests" { _contents = HoverContents $ MarkupContent MkMarkdown $ T.unlines [ "```daml" , "Main.add" - , "```" - , "*\t*\t*" - , "```daml" , ": Int -> Int -> Int" , "```" , "*\t*\t*" - , "**Defined at " <> T.pack fp <> ":4:1**" + , "*Defined at " <> T.pack fp <> ":4:1*" ] , _range = Just $ Range (Position 9 17) (Position 9 20) } @@ -366,11 +363,9 @@ requestTests run _runScenarios = testGroup "requests" liftIO $ r @?= Just Hover { _contents = HoverContents $ MarkupContent MkMarkdown $ T.unlines [ "```daml" - , "" - , "```" - , "*\t*\t*" - , "```daml" - , ": Numeric n" + , "1.0" + , ": NumericScale n" + , "=> Numeric n" , "```" , "*\t*\t*" ]