diff --git a/cabal-ghc901.project b/cabal-ghc901.project index 18e63db8f3..19e75ebffe 100644 --- a/cabal-ghc901.project +++ b/cabal-ghc901.project @@ -37,7 +37,7 @@ package * write-ghc-environment-files: never -index-state: 2021-11-29T08:11:07Z +index-state: 2021-11-29T12:30:07Z constraints: -- These plugins don't work on GHC9 yet diff --git a/cabal-ghc921.project b/cabal-ghc921.project index 5706da094e..21c1833847 100644 --- a/cabal-ghc921.project +++ b/cabal-ghc921.project @@ -36,7 +36,7 @@ package * write-ghc-environment-files: never -index-state: 2021-11-29T08:11:07Z +index-state: 2021-11-29T12:30:07Z constraints: -- These plugins doesn't work on GHC92 yet diff --git a/cabal.project b/cabal.project index 90c322cc4f..366f8781b3 100644 --- a/cabal.project +++ b/cabal.project @@ -40,7 +40,7 @@ package * write-ghc-environment-files: never -index-state: 2021-11-29T08:11:07Z +index-state: 2021-11-29T12:30:07Z constraints: hyphenation +embed diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 2360caf4d1..75acdc4fe6 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -36,15 +36,11 @@ An usual symptom is the presence of errors containing `unknown symbol` and it is The workaround is to use a version of haskell-language-server compiled from source with the ghc option `-dynamic` enabled. See more details [here](https://github.com/haskell/haskell-language-server/issues/1160#issuecomment-756566273). -### Problems with Template Haskell +### Support for Template Haskell -Due to how Template Haskell code is evaluated at compile time and some limitations in the interaction between HLS and GHC, the loading of modules using TH can be problematic. +Template Haskell should work fine in Linux and Windows with the distributed binaries. In Mac Os a dynamically linked binary of HLS is required to avoid segmentation faults. The easiest way to obtain a dynamically linked HLS binary is to build it locally. With cabal install this can be done as follows: -The errors thrown are usually related to linking and usually make HLS crash: `Segmentation fault`, `GHC runtime linker: fatal error`, etc - -A workaround which has helped in some cases is to compile HLS from source with the ghc option `-dynamic` enabled, as in the previous issue. - -We have a [dedicated label](https://github.com/haskell/haskell-language-server/issues?q=is%3Aissue+is%3Aopen+label%3A%22type%3A+template+haskell+related%22) in the issue tracker and an [general issue](https://github.com/haskell/haskell-language-server/issues/1431) tracking support for TH. + cabal update && cabal install haskell-language-server --enable-executable-dynamic ## Troubleshooting the server diff --git a/ghcide/ghcide.cabal b/ghcide/ghcide.cabal index 6eba5640ac..d90b3dff43 100644 --- a/ghcide/ghcide.cabal +++ b/ghcide/ghcide.cabal @@ -106,7 +106,7 @@ library ghc-check >=0.5.0.4, ghc-paths, cryptohash-sha1 >=0.11.100 && <0.12, - hie-bios >= 0.7.1 && < 0.9.0, + hie-bios >= 0.8 && < 0.9.0, implicit-hie-cradle >= 0.3.0.5 && < 0.4, base16-bytestring >=0.1.1 && <1.1 if os(windows) diff --git a/ghcide/src/Development/IDE/Core/Rules.hs b/ghcide/src/Development/IDE/Core/Rules.hs index 91932459be..756edad54c 100644 --- a/ghcide/src/Development/IDE/Core/Rules.hs +++ b/ghcide/src/Development/IDE/Core/Rules.hs @@ -136,7 +136,7 @@ import qualified GHC.LanguageExtensions as LangExt import qualified HieDb import Ide.Plugin.Config import qualified Language.LSP.Server as LSP -import Language.LSP.Types (SMethod (SCustomMethod)) +import Language.LSP.Types (SMethod (SCustomMethod, SWindowShowMessage), ShowMessageParams (ShowMessageParams), MessageType (MtInfo)) import Language.LSP.VFS import System.Directory (makeAbsolute) import Data.Default (def, Default) @@ -149,6 +149,15 @@ import Ide.PluginUtils (configForPlugin) import Ide.Types (DynFlagsModifications (dynFlagsModifyGlobal, dynFlagsModifyParser), PluginId) import Control.Concurrent.STM.Stats (atomically) +import Language.LSP.Server (LspT) +import System.Environment (getExecutablePath) +import System.Process.Extra (readProcessWithExitCode) +import Text.Read (readMaybe) +import System.Info.Extra (isMac) +import HIE.Bios.Ghc.Gap (hostIsDynamic) + +templateHaskellInstructions :: T.Text +templateHaskellInstructions = "https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#support-for-template-haskell" -- | This is useful for rules to convert rules that can only produce errors or -- a result into the more general IdeResult type that supports producing @@ -820,8 +829,26 @@ isHiFileStableRule = defineEarlyCutoff $ RuleNoDiagnostics $ \IsHiFileStable f - summarize SourceUnmodified = BS.singleton 2 summarize SourceUnmodifiedAndStable = BS.singleton 3 +displayTHWarning :: LspT c IO () +displayTHWarning + | isMac && not hostIsDynamic = do + LSP.sendNotification SWindowShowMessage $ + ShowMessageParams MtInfo $ T.unwords + [ "This HLS binary does not support Template Haskell." + , "Follow the [instructions](" <> templateHaskellInstructions <> ")" + , "to build an HLS binary with support for Template Haskell." + ] + | otherwise = return () + +newtype DisplayTHWarning = DisplayTHWarning (IO ()) +instance IsIdeGlobal DisplayTHWarning + getModSummaryRule :: Rules () getModSummaryRule = do + env <- lspEnv <$> getShakeExtrasRules + displayItOnce <- liftIO $ once $ LSP.runLspT (fromJust env) displayTHWarning + addIdeGlobal (DisplayTHWarning displayItOnce) + defineEarlyCutoff $ Rule $ \GetModSummary f -> do session' <- hscEnv <$> use_ GhcSession f modify_dflags <- getModifyDynFlags dynFlagsModifyGlobal @@ -832,6 +859,10 @@ getModSummaryRule = do getModSummaryFromImports session fp modTime (textToStringBuffer <$> mFileContent) case modS of Right res -> do + -- Check for Template Haskell + when (uses_th_qq $ msrModSummary res) $ do + DisplayTHWarning act <- getIdeGlobalAction + liftIO act bufFingerPrint <- liftIO $ fingerprintFromStringBuffer $ fromJust $ ms_hspp_buf $ msrModSummary res let fingerPrint = Util.fingerprintFingerprints @@ -1027,9 +1058,6 @@ needsCompilationRule file = do pure (Just $ encodeLinkableType res, Just res) where - uses_th_qq (ms_hspp_opts -> dflags) = - xopt LangExt.TemplateHaskell dflags || xopt LangExt.QuasiQuotes dflags - computeLinkableType :: ModSummary -> [Maybe ModSummary] -> [Maybe LinkableType] -> Maybe LinkableType computeLinkableType this deps xs | Just ObjectLinkable `elem` xs = Just ObjectLinkable -- If any dependent needs object code, so do we @@ -1039,6 +1067,10 @@ needsCompilationRule file = do where this_type = computeLinkableTypeForDynFlags (ms_hspp_opts this) +uses_th_qq :: ModSummary -> Bool +uses_th_qq (ms_hspp_opts -> dflags) = + xopt LangExt.TemplateHaskell dflags || xopt LangExt.QuasiQuotes dflags + -- | How should we compile this module? -- (assuming we do in fact need to compile it). -- Depends on whether it uses unboxed tuples or sums diff --git a/stack-8.10.6.yaml b/stack-8.10.6.yaml index 0119547d22..4832965575 100644 --- a/stack-8.10.6.yaml +++ b/stack-8.10.6.yaml @@ -37,6 +37,7 @@ extra-deps: - data-tree-print-0.1.0.2@sha256:d845e99f322df70e0c06d6743bf80336f5918d5423498528beb0593a2afc1703,1620 - floskell-0.10.5@sha256:77f0bc1569573d9666b10975a5357fef631d32266c071733739393ccae521dab,3803 - heapsize-0.3.0.1@sha256:0b69aa97a46d819b700ac7b145f3b5493c3565cf2c5b8298682238d405d0326e,1417 + - hie-bios-0.8.0 - hiedb-0.4.1.0 - implicit-hie-0.1.2.6@sha256:f50a908979a574a881f753c0f9a5224f023f438b30fdefc5b7fa01803b07a280,2998 - implicit-hie-cradle-0.3.0.5@sha256:5f5e575f549b2a9db664be7650b5c3c9226e313bddc46c79e2e83eb349f8e692,2610 diff --git a/stack-8.10.7.yaml b/stack-8.10.7.yaml index 91ea6ee7eb..24779b9462 100644 --- a/stack-8.10.7.yaml +++ b/stack-8.10.7.yaml @@ -37,6 +37,7 @@ extra-deps: - data-tree-print-0.1.0.2@sha256:d845e99f322df70e0c06d6743bf80336f5918d5423498528beb0593a2afc1703,1620 - floskell-0.10.5@sha256:77f0bc1569573d9666b10975a5357fef631d32266c071733739393ccae521dab,3803 - heapsize-0.3.0.1@sha256:0b69aa97a46d819b700ac7b145f3b5493c3565cf2c5b8298682238d405d0326e,1417 + - hie-bios-0.8.0 - hiedb-0.4.1.0 - implicit-hie-0.1.2.6@sha256:f50a908979a574a881f753c0f9a5224f023f438b30fdefc5b7fa01803b07a280,2998 - implicit-hie-cradle-0.3.0.5@sha256:5f5e575f549b2a9db664be7650b5c3c9226e313bddc46c79e2e83eb349f8e692,2610 diff --git a/stack-8.6.5.yaml b/stack-8.6.5.yaml index 0c7bdc0564..bf6c913636 100644 --- a/stack-8.6.5.yaml +++ b/stack-8.6.5.yaml @@ -60,7 +60,7 @@ extra-deps: - haddock-library-1.10.0 - hashable-1.3.0.0 - heapsize-0.3.0 - - hie-bios-0.7.5 + - hie-bios-0.8.0 - hlint-3.2.3 - HsYAML-0.2.1.0@rev:1 - HsYAML-aeson-0.2.0.0@rev:2 diff --git a/stack-8.8.4.yaml b/stack-8.8.4.yaml index ae69125b10..f4caf8b6b2 100644 --- a/stack-8.8.4.yaml +++ b/stack-8.8.4.yaml @@ -50,7 +50,7 @@ extra-deps: - ghc-trace-events-0.1.2.1 - haskell-src-exts-1.21.1 - heapsize-0.3.0 - - hie-bios-0.7.5 + - hie-bios-0.8.0 - hlint-3.2.3 - HsYAML-aeson-0.2.0.0@rev:2 - hoogle-5.0.17.11 diff --git a/stack.yaml b/stack.yaml index 2fb75adca6..428c80404b 100644 --- a/stack.yaml +++ b/stack.yaml @@ -37,6 +37,7 @@ extra-deps: - data-tree-print-0.1.0.2@sha256:d845e99f322df70e0c06d6743bf80336f5918d5423498528beb0593a2afc1703,1620 - floskell-0.10.5@sha256:77f0bc1569573d9666b10975a5357fef631d32266c071733739393ccae521dab,3803 - heapsize-0.3.0.1@sha256:0b69aa97a46d819b700ac7b145f3b5493c3565cf2c5b8298682238d405d0326e,1417 + - hie-bios-0.8.0 - hiedb-0.4.1.0 - implicit-hie-0.1.2.6@sha256:f50a908979a574a881f753c0f9a5224f023f438b30fdefc5b7fa01803b07a280,2998 - implicit-hie-cradle-0.3.0.5@sha256:5f5e575f549b2a9db664be7650b5c3c9226e313bddc46c79e2e83eb349f8e692,2610