From 8eae8a5a65c9e92b0507b8bc10237828094b9a37 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Wed, 18 Dec 2019 07:49:20 -0500 Subject: [PATCH 1/2] Ghc 8.8.1 support --- .gitmodules | 5 +++- haskell-ide-engine.cabal | 20 ++++++------- install/shake.yaml | 2 +- src/Haskell/Ide/Engine/Plugin/Haddock.hs | 25 ++++++++++++++++- src/Haskell/Ide/Engine/Plugin/Package.hs | 5 ++++ src/Haskell/Ide/Engine/Support/HieExtras.hs | 5 ++++ stack-8.6.5.yaml | 2 +- stack.yaml | 31 ++++++--------------- submodules/apply-refact | 1 + 9 files changed, 60 insertions(+), 36 deletions(-) create mode 160000 submodules/apply-refact diff --git a/.gitmodules b/.gitmodules index edbeb396b..a16cde630 100644 --- a/.gitmodules +++ b/.gitmodules @@ -18,4 +18,7 @@ [submodule "submodules/ghc-mod"] path = submodules/ghc-mod - url = https://github.com/fendor/ghc-mod.git \ No newline at end of file + url = https://github.com/fendor/ghc-mod.git +[submodule "submodules/apply-refact"] + path = submodules/apply-refact + url = https://github.com/mpickering/apply-refact.git diff --git a/haskell-ide-engine.cabal b/haskell-ide-engine.cabal index 39e8f934d..052981a47 100644 --- a/haskell-ide-engine.cabal +++ b/haskell-ide-engine.cabal @@ -14,7 +14,7 @@ build-type: Simple cabal-version: >=2.0 flag pedantic - Description: Enable -Werror + Description: Enable -Werror -Wwarn=unused-imports Default: False library @@ -103,7 +103,7 @@ library ghc-options: -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror + ghc-options: -Werror -Wwarn=unused-imports default-language: Haskell2010 executable hie @@ -122,7 +122,7 @@ executable hie ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints -with-rtsopts=-T if flag(pedantic) - ghc-options: -Werror + ghc-options: -Werror -Wwarn=unused-imports default-language: Haskell2010 @@ -143,7 +143,7 @@ executable hie-wrapper ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints -with-rtsopts=-T if flag(pedantic) - ghc-options: -Werror + ghc-options: -Werror -Wwarn=unused-imports default-language: Haskell2010 library hie-test-utils @@ -169,7 +169,7 @@ library hie-test-utils , yaml ghc-options: -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror + ghc-options: -Werror -Wwarn=unused-imports default-language: Haskell2010 test-suite unit-test @@ -213,7 +213,7 @@ test-suite unit-test ghc-options: -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror + ghc-options: -Werror -Wwarn=unused-imports default-language: Haskell2010 test-suite dispatcher-test @@ -237,7 +237,7 @@ test-suite dispatcher-test ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror + ghc-options: -Werror -Wwarn=unused-imports default-language: Haskell2010 build-tool-depends: hspec-discover:hspec-discover @@ -257,7 +257,7 @@ test-suite plugin-dispatcher-test ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror + ghc-options: -Werror -Wwarn=unused-imports default-language: Haskell2010 test-suite func-test @@ -302,7 +302,7 @@ test-suite func-test , containers ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror + ghc-options: -Werror -Wwarn=unused-imports default-language: Haskell2010 build-tool-depends: hspec-discover:hspec-discover , haskell-ide-engine:hie @@ -321,7 +321,7 @@ test-suite wrapper-test , hie-plugin-api ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror + ghc-options: -Werror -Wwarn=unused-imports default-language: Haskell2010 diff --git a/install/shake.yaml b/install/shake.yaml index 8c30114fa..22867942f 100644 --- a/install/shake.yaml +++ b/install/shake.yaml @@ -1,5 +1,5 @@ # Used to provide a different environment for the shake build script -resolver: lts-14.11 # GHC 8.6.5 +resolver: lts-14.17 # GHC 8.6.5 packages: - . diff --git a/src/Haskell/Ide/Engine/Plugin/Haddock.hs b/src/Haskell/Ide/Engine/Plugin/Haddock.hs index f3aa088c8..b89352634 100644 --- a/src/Haskell/Ide/Engine/Plugin/Haddock.hs +++ b/src/Haskell/Ide/Engine/Plugin/Haddock.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} @@ -106,7 +107,11 @@ getDocsForName df name = do case mf of Nothing -> return Nothing Just f -> do +#if __GLASGOW_HASKELL__ >= 808 + ehi <- readInterfaceFile nameCacheFromIdeM f True +#else ehi <- readInterfaceFile nameCacheFromIdeM f +#endif case ehi of Left message -> do debugm $ "Haddock docs couldn't be loaded as readInterfaceFile failed with: " ++ message @@ -151,8 +156,15 @@ prettyprintType n t = T.unlines , "```\n" ] +unwrap :: Foldable w => w a -> a +unwrap = foldl1 (const id) + renderDocs :: MDoc Name -> T.Text +#if __GLASGOW_HASKELL__ >= 808 +renderDocs = markup renderMarkDown . _doc . fmap unwrap +#else renderDocs = markup renderMarkDown . _doc +#endif renderMarkDown :: DocMarkup Name T.Text renderMarkDown = @@ -161,7 +173,11 @@ renderMarkDown = , markupParagraph = (<> "\n\n") , markupAppend = mappend , markupIdentifier = surround "`" . T.pack . getOccString +#if __GLASGOW_HASKELL__ >= 808 + , markupIdentifierUnchecked = T.pack . occNameString . snd . unwrap +#else , markupIdentifierUnchecked = T.pack . occNameString . snd +#endif , markupModule = surround "**" . T.pack , markupWarning = surround "*" , markupEmphasis = surround "*" @@ -173,9 +189,16 @@ renderMarkDown = , markupDefList = T.unlines . map (\(a, b) -> a <> " :: " <> b) , markupCodeBlock = \x -> "\n```haskell\n" <> removeInner x <> "\n```\n" , markupHyperlink = \h -> - T.pack $ maybe +#if __GLASGOW_HASKELL__ >= 808 + let url = T.pack $ hyperlinkUrl h + in maybe + url + (\l -> "["<>l<>"]("<>url<>")") +#else + T.pack $ maybe (hyperlinkUrl h) (\l -> "["<>l<>"]("<>hyperlinkUrl h<>")") +#endif (hyperlinkLabel h) , markupAName = T.pack , markupPic = const "" diff --git a/src/Haskell/Ide/Engine/Plugin/Package.hs b/src/Haskell/Ide/Engine/Plugin/Package.hs index b8e4f402e..da622263f 100644 --- a/src/Haskell/Ide/Engine/Plugin/Package.hs +++ b/src/Haskell/Ide/Engine/Plugin/Package.hs @@ -19,6 +19,7 @@ import qualified Data.ByteString as B import Data.Foldable import Data.List import qualified Data.HashMap.Strict as HM +import qualified Data.Set as S import qualified Data.Text as T import qualified Data.Text.Encoding as T import Data.Maybe @@ -301,7 +302,11 @@ editCabalPackage file modulePath pkgName fileMap = do -- Add it to the bottom of the dependencies list -- TODO: we could sort the depencies and then insert it, -- or insert it in order iff the list is already sorted. +#if __GLASGOW_HASKELL__ >= 808 + newDeps = oldDeps ++ [Dependency (mkPackageName (T.unpack dep)) anyVersion S.empty] +#else newDeps = oldDeps ++ [Dependency (mkPackageName (T.unpack dep)) anyVersion] +#endif -- | Provide a code action to add a package to the local package.yaml or cabal file. -- Reads from diagnostics the unknown import module path and searches for it on Hoogle. diff --git a/src/Haskell/Ide/Engine/Support/HieExtras.hs b/src/Haskell/Ide/Engine/Support/HieExtras.hs index 446441cfe..552e24b6b 100644 --- a/src/Haskell/Ide/Engine/Support/HieExtras.hs +++ b/src/Haskell/Ide/Engine/Support/HieExtras.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -336,7 +337,11 @@ gotoModule rfm mn = do flushFinderCaches env findImportedModule env mn Nothing case fr of +#if __GLASGOW_HASKELL__ < 808 Found (ModLocation (Just src) _ _) _ -> do +#else + Found (ModLocation (Just src) _ _ _) _ -> do +#endif fp <- reverseMapFile rfm src let r = Range (Position 0 0) (Position 0 0) diff --git a/stack-8.6.5.yaml b/stack-8.6.5.yaml index 9e572be89..f775609f7 100644 --- a/stack-8.6.5.yaml +++ b/stack-8.6.5.yaml @@ -1,4 +1,4 @@ -resolver: lts-14.16 +resolver: lts-14.17 packages: - . - hie-plugin-api diff --git a/stack.yaml b/stack.yaml index 8dc95bf01..35e202156 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: nightly-2019-09-21 # Last GHC 8.6.5 +resolver: nightly-2019-12-18 packages: - . - hie-plugin-api @@ -7,31 +7,18 @@ extra-deps: # - ./submodules/HaRe - ./submodules/cabal-helper - ./submodules/ghc-mod/ghc-project-types - -- deque-0.4.3 -- ansi-terminal-0.8.2 +- ./submodules/apply-refact +- hie-bios-0.3.2 - bytestring-trie-0.2.5.0 -- ansi-wl-pprint-0.6.8.2 -- brittany-0.12.1.0 -- cabal-plan-0.5.0.0 - constrained-dynamic-0.1.0.0 +- fclabels-2.0.3.3 - floskell-0.10.2 -- ghc-lib-parser-8.8.1 -- haddock-api-2.22.0 -- haskell-lsp-0.19.0.0 -- haskell-lsp-types-0.19.0.0 -- hie-bios-0.3.2 -- hlint-2.2.4 +- fold-debounce-0.2.0.9 +- haddock-api-2.23.0 +- haddock-library-1.8.0 +- hoogle-5.0.17.13 - hsimport-0.11.0 -- lsp-test-0.9.0.0 -- monad-dijkstra-0.1.1.2@rev:1 -- syz-0.2.0.0 -- temporary-1.2.1.1 -- clock-0.7.2 -- ghc-exactprint-0.6.2 # for HaRe -- extra-1.6.18 -- unix-compat-0.5.2 -- yaml-0.11.1.2 +- monad-dijkstra-0.1.1.2 flags: haskell-ide-engine: diff --git a/submodules/apply-refact b/submodules/apply-refact new file mode 160000 index 000000000..1acf7eb86 --- /dev/null +++ b/submodules/apply-refact @@ -0,0 +1 @@ +Subproject commit 1acf7eb860be5a446828a3a2fe3644aeb5a1b55f From 61192eae6b41e9eac34c41a4686c550d8d99b1af Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Fri, 20 Dec 2019 07:19:10 -0500 Subject: [PATCH 2/2] Use per-file pragma --- app/MainHie.hs | 1 + haskell-ide-engine.cabal | 20 +++++++++---------- hie-plugin-api/Haskell/Ide/Engine/Ghc.hs | 1 + .../Haskell/Ide/Engine/PluginsIdeMonads.hs | 1 + src/Haskell/Ide/Engine/LSP/Completions.hs | 1 + src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs | 1 + src/Haskell/Ide/Engine/Plugin/Brittany.hs | 1 + src/Haskell/Ide/Engine/Plugin/Generic.hs | 1 + src/Haskell/Ide/Engine/Plugin/HsImport.hs | 1 + src/Haskell/Ide/Engine/Plugin/Package.hs | 1 + src/Haskell/Ide/Engine/Plugin/Pragmas.hs | 1 + src/Haskell/Ide/Engine/Scheduler.hs | 1 + src/Haskell/Ide/Engine/Support/HieExtras.hs | 1 + src/Haskell/Ide/Engine/Transport/LspStdio.hs | 1 + 14 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/MainHie.hs b/app/MainHie.hs index 27e2770f3..1cb91119a 100644 --- a/app/MainHie.hs +++ b/app/MainHie.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} module Main where diff --git a/haskell-ide-engine.cabal b/haskell-ide-engine.cabal index 052981a47..39e8f934d 100644 --- a/haskell-ide-engine.cabal +++ b/haskell-ide-engine.cabal @@ -14,7 +14,7 @@ build-type: Simple cabal-version: >=2.0 flag pedantic - Description: Enable -Werror -Wwarn=unused-imports + Description: Enable -Werror Default: False library @@ -103,7 +103,7 @@ library ghc-options: -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror -Wwarn=unused-imports + ghc-options: -Werror default-language: Haskell2010 executable hie @@ -122,7 +122,7 @@ executable hie ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints -with-rtsopts=-T if flag(pedantic) - ghc-options: -Werror -Wwarn=unused-imports + ghc-options: -Werror default-language: Haskell2010 @@ -143,7 +143,7 @@ executable hie-wrapper ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints -with-rtsopts=-T if flag(pedantic) - ghc-options: -Werror -Wwarn=unused-imports + ghc-options: -Werror default-language: Haskell2010 library hie-test-utils @@ -169,7 +169,7 @@ library hie-test-utils , yaml ghc-options: -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror -Wwarn=unused-imports + ghc-options: -Werror default-language: Haskell2010 test-suite unit-test @@ -213,7 +213,7 @@ test-suite unit-test ghc-options: -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror -Wwarn=unused-imports + ghc-options: -Werror default-language: Haskell2010 test-suite dispatcher-test @@ -237,7 +237,7 @@ test-suite dispatcher-test ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror -Wwarn=unused-imports + ghc-options: -Werror default-language: Haskell2010 build-tool-depends: hspec-discover:hspec-discover @@ -257,7 +257,7 @@ test-suite plugin-dispatcher-test ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror -Wwarn=unused-imports + ghc-options: -Werror default-language: Haskell2010 test-suite func-test @@ -302,7 +302,7 @@ test-suite func-test , containers ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror -Wwarn=unused-imports + ghc-options: -Werror default-language: Haskell2010 build-tool-depends: hspec-discover:hspec-discover , haskell-ide-engine:hie @@ -321,7 +321,7 @@ test-suite wrapper-test , hie-plugin-api ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints if flag(pedantic) - ghc-options: -Werror -Wwarn=unused-imports + ghc-options: -Werror default-language: Haskell2010 diff --git a/hie-plugin-api/Haskell/Ide/Engine/Ghc.hs b/hie-plugin-api/Haskell/Ide/Engine/Ghc.hs index 81d9d6a63..d5efb5b9f 100644 --- a/hie-plugin-api/Haskell/Ide/Engine/Ghc.hs +++ b/hie-plugin-api/Haskell/Ide/Engine/Ghc.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} diff --git a/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs b/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs index 120c6776e..0506cf392 100644 --- a/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs +++ b/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveAnyClass #-} diff --git a/src/Haskell/Ide/Engine/LSP/Completions.hs b/src/Haskell/Ide/Engine/LSP/Completions.hs index ea322c768..db1f1c329 100644 --- a/src/Haskell/Ide/Engine/LSP/Completions.hs +++ b/src/Haskell/Ide/Engine/LSP/Completions.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} diff --git a/src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs b/src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs index 33fca9188..1fd12a590 100644 --- a/src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs +++ b/src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} diff --git a/src/Haskell/Ide/Engine/Plugin/Brittany.hs b/src/Haskell/Ide/Engine/Plugin/Brittany.hs index 8acd17c08..6e8464b02 100644 --- a/src/Haskell/Ide/Engine/Plugin/Brittany.hs +++ b/src/Haskell/Ide/Engine/Plugin/Brittany.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE OverloadedStrings #-} module Haskell.Ide.Engine.Plugin.Brittany where diff --git a/src/Haskell/Ide/Engine/Plugin/Generic.hs b/src/Haskell/Ide/Engine/Plugin/Generic.hs index e89f06e47..55e39d016 100644 --- a/src/Haskell/Ide/Engine/Plugin/Generic.hs +++ b/src/Haskell/Ide/Engine/Plugin/Generic.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} diff --git a/src/Haskell/Ide/Engine/Plugin/HsImport.hs b/src/Haskell/Ide/Engine/Plugin/HsImport.hs index 55d9a2b85..b20e15835 100644 --- a/src/Haskell/Ide/Engine/Plugin/HsImport.hs +++ b/src/Haskell/Ide/Engine/Plugin/HsImport.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveAnyClass #-} diff --git a/src/Haskell/Ide/Engine/Plugin/Package.hs b/src/Haskell/Ide/Engine/Plugin/Package.hs index da622263f..04b48479c 100644 --- a/src/Haskell/Ide/Engine/Plugin/Package.hs +++ b/src/Haskell/Ide/Engine/Plugin/Package.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveGeneric #-} diff --git a/src/Haskell/Ide/Engine/Plugin/Pragmas.hs b/src/Haskell/Ide/Engine/Plugin/Pragmas.hs index 57b6cccb7..61d5a7918 100644 --- a/src/Haskell/Ide/Engine/Plugin/Pragmas.hs +++ b/src/Haskell/Ide/Engine/Plugin/Pragmas.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} diff --git a/src/Haskell/Ide/Engine/Scheduler.hs b/src/Haskell/Ide/Engine/Scheduler.hs index a94787487..42f1e4520 100644 --- a/src/Haskell/Ide/Engine/Scheduler.hs +++ b/src/Haskell/Ide/Engine/Scheduler.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ExistentialQuantification #-} diff --git a/src/Haskell/Ide/Engine/Support/HieExtras.hs b/src/Haskell/Ide/Engine/Support/HieExtras.hs index 552e24b6b..ac018a393 100644 --- a/src/Haskell/Ide/Engine/Support/HieExtras.hs +++ b/src/Haskell/Ide/Engine/Support/HieExtras.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE NamedFieldPuns #-} diff --git a/src/Haskell/Ide/Engine/Transport/LspStdio.hs b/src/Haskell/Ide/Engine/Transport/LspStdio.hs index 27906e96d..a384c61c2 100644 --- a/src/Haskell/Ide/Engine/Transport/LspStdio.hs +++ b/src/Haskell/Ide/Engine/Transport/LspStdio.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE RankNTypes #-}