on master help sign in
GHC 8.10 support (#360)
commitad43ad9f19ee35f62840ce0777e8d30a6cedd04d authorsheaf <sam.derbyshire@gmail.com> dateMon 10 Feb 2020, 10:07 (7 years ago) parent9e984b5
7 files changed+62−13
src/Development/IDE/Core/Compile.hs+16−1 src/Development/IDE/Core/Rules.hs+1−1 src/Development/IDE/GHC/CPP.hs+4 src/Development/IDE/GHC/Util.hs+14−4 src/Development/IDE/LSP/Outline.hs+4 src/Development/IDE/Plugin/CodeAction.hs+7−7 src/Development/IDE/Plugin/Completions/Logic.hs+16
src/Development/IDE/Core/Compile.hs+16−1
@@ -37,7 +37,10 @@ import DynamicLoading (initializePlugins)
3737import GHC hiding (parseModule, typecheckModule)
3838import qualified Parser
3939import Lexer
40+#if MIN_GHC_API_VERSION(8,10,0)
41+#else
4042import ErrUtils
43+#endif
4144
4245import qualified GHC
4346import GhcMonad
@@ -157,7 +160,11 @@ generateByteCode hscEnv deps tmr guts =
157160 setupEnv (deps ++ [tmr])
158161 session <- getSession
159162 (warnings, (_, bytecode, sptEntries)) <- withWarnings "bytecode" $ \tweak ->
160− liftIO $ hscInteractive session guts (tweak $ GHC.pm_mod_summary $ GHC.tm_parsed_module $ tmrModule tmr)
163+#if MIN_GHC_API_VERSION(8,10,0)
164+ liftIO $ hscInteractive session guts (GHC.ms_location $ tweak $ GHC.pm_mod_summary $ GHC.tm_parsed_module $ tmrModule tmr)
165+#else
166+ liftIO $ hscInteractive session guts (tweak $ GHC.pm_mod_summary $ GHC.tm_parsed_module $ tmrModule tmr)
167+#endif
161168 let summary = pm_mod_summary $ tm_parsed_module $ tmrModule tmr
162169 let unlinked = BCOs bytecode sptEntries
163170 let linkable = LM (ms_hs_date summary) (ms_mod summary) [unlinked]
@@ -217,7 +224,11 @@ mkTcModuleResult
217224 -> m TcModuleResult
218225mkTcModuleResult tcm = do
219226 session <- getSession
227+#if MIN_GHC_API_VERSION(8,10,0)
228+ iface <- liftIO $ mkIfaceTc session Sf_None details tcGblEnv
229+#else
220230 (iface, _) <- liftIO $ mkIfaceTc session Nothing Sf_None details tcGblEnv
231+#endif
221232 let mod_info = HomeModInfo iface details Nothing
222233 return $ TcModuleResult tcm mod_info
223234 where
@@ -361,8 +372,12 @@ parseFileContents
361372parseFileContents customPreprocessor dflags filename contents = do
362373 let loc = mkRealSrcLoc (mkFastString filename) 1 1
363374 case unP Parser.parseModule (mkPState dflags contents loc) of
375+#if MIN_GHC_API_VERSION(8,10,0)
376+ PFailed pst -> throwE $ diagFromErrMsgs "parser" dflags $ getErrorMessages pst dflags
377+#else
364378 PFailed _ locErr msgErr ->
365379 throwE $ diagFromErrMsg "parser" dflags $ mkPlainErrMsg dflags locErr msgErr
380+#endif
366381 POk pst rdr_module ->
367382 let hpm_annotations =
368383 (Map.fromListWith (++) $ annotations pst,
src/Development/IDE/Core/Rules.hs+1−1
@@ -253,7 +253,7 @@ reportImportCyclesRule =
253253getDependenciesRule :: Rules ()
254254getDependenciesRule =
255255 defineEarlyCutoff $ \GetDependencies file -> do
256− depInfo@DependencyInformation{..} <- use_ GetDependencyInformation file
256+ depInfo <- use_ GetDependencyInformation file
257257 let allFiles = reachableModules depInfo
258258 _ <- uses_ ReportImportCycles allFiles
259259 opts <- getIdeOptions
src/Development/IDE/GHC/CPP.hs+4
@@ -59,7 +59,11 @@ doCpp dflags raw input_fn output_fn = do
5959 let verbFlags = getVerbFlags dflags
6060
6161 let cpp_prog args | raw = SysTools.runCpp dflags args
62+#if MIN_GHC_API_VERSION(8,10,0)
63+ | otherwise = SysTools.runCc Nothing
64+#else
6265 | otherwise = SysTools.runCc
66+#endif
6367 dflags (SysTools.Option "-E" : args)
6468
6569 let target_defs =
src/Development/IDE/GHC/Util.hs+14−4
@@ -25,7 +25,7 @@ module Development.IDE.GHC.Util(
2525 hDuplicateTo',
2626 ) where
2727
28−import Config
28+
2929import Control.Concurrent
3030import Data.List.Extra
3131import Data.Maybe
@@ -47,7 +47,11 @@ import GHC.IO.Encoding
4747import GHC.IO.Exception
4848import GHC.IO.Handle.Types
4949import GHC.IO.Handle.Internals
50+#if MIN_GHC_API_VERSION(8,10,0)
51+#else
52+import Config
5053import Platform
54+#endif
5155import Data.Unique
5256import Development.Shake.Classes
5357import qualified Data.Text as T
@@ -109,7 +113,12 @@ runGhcEnv env act = do
109113-- | A 'DynFlags' value where most things are undefined. It's sufficient to call pretty printing,
110114-- but not much else.
111115fakeDynFlags :: DynFlags
112−fakeDynFlags = defaultDynFlags settings mempty
116+#if MIN_GHC_API_VERSION(8,10,0)
117+fakeDynFlags = unsafeGlobalDynFlags
118+#else
119+fakeDynFlags = defaultDynFlags
120+ settings
121+ mempty
113122 where
114123 settings = Settings
115124 { sTargetPlatform = platform
@@ -117,9 +126,9 @@ fakeDynFlags = defaultDynFlags settings mempty
117126 , sProgramName = "ghc"
118127 , sProjectVersion = cProjectVersion
119128#if MIN_GHC_API_VERSION(8,6,0)
120− , sOpt_P_fingerprint = fingerprint0
129+ , sOpt_P_fingerprint = fingerprint0
121130#endif
122− }
131+ }
123132 platform = Platform
124133 { platformWordSize=8
125134 , platformOS=OSUnknown
@@ -129,6 +138,7 @@ fakeDynFlags = defaultDynFlags settings mempty
129138 { pc_DYNAMIC_BY_DEFAULT=False
130139 , pc_WORD_SIZE=8
131140 }
141+#endif
132142
133143-- | Given a module location, and its parse tree, figure out what is the include directory implied by it.
134144-- For example, given the file @\/usr\/\Test\/Foo\/Bar.hs@ with the module name @Foo.Bar@ the directory
src/Development/IDE/LSP/Outline.hs+4
@@ -172,7 +172,11 @@ documentSymbolForImport (L l ImportDecl { ideclName, ideclQualified }) = Just
172172 (defDocumentSymbol l :: DocumentSymbol)
173173 { _name = "import " <> pprText ideclName
174174 , _kind = SkModule
175+#if MIN_GHC_API_VERSION(8,10,0)
176+ , _detail = case ideclQualified of { NotQualified -> Nothing; _ -> Just "qualified" }
177+#else
175178 , _detail = if ideclQualified then Just "qualified" else Nothing
179+#endif
176180 }
177181#if MIN_GHC_API_VERSION(8,6,0)
178182documentSymbolForImport (L _ XImportDecl {}) = Nothing
src/Development/IDE/Plugin/CodeAction.hs+7−7
@@ -77,7 +77,7 @@ codeLens _lsp ideState CodeLensParams{_textDocument=TextDocumentIdentifier uri}
7777 hDiag <- getHiddenDiagnostics ideState
7878 pure
7979 [ CodeLens _range (Just (Command title "typesignature.add" (Just $ List [toJSON edit]))) Nothing
80− | (dFile, _, dDiag@Diagnostic{_range=_range@Range{..},..}) <- diag ++ hDiag
80+ | (dFile, _, dDiag@Diagnostic{_range=_range}) <- diag ++ hDiag
8181 , dFile == filePath
8282 , (title, tedit) <- suggestSignature False dDiag
8383 , let edit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing
@@ -115,7 +115,7 @@ suggestAction ideOptions parsedModule text diag = concat
115115
116116
117117suggestRemoveRedundantImport :: ParsedModule -> Maybe T.Text -> Diagnostic -> [(T.Text, [TextEdit])]
118−suggestRemoveRedundantImport ParsedModule{pm_parsed_source = L _ HsModule{hsmodImports}} contents Diagnostic{_range=_range@Range{..},..}
118+suggestRemoveRedundantImport ParsedModule{pm_parsed_source = L _ HsModule{hsmodImports}} contents Diagnostic{_range=_range,..}
119119-- The qualified import of ‘many’ from module ‘Control.Applicative’ is redundant
120120 | Just [_, bindings] <- matchRegex _message "The( qualified)? import of ‘([^’]*)’ from module [^ ]* is redundant"
121121 , Just (L _ impDecl) <- find (\(L l _) -> srcSpanToRange l == _range ) hsmodImports
@@ -133,7 +133,7 @@ suggestRemoveRedundantImport ParsedModule{pm_parsed_source = L _ HsModule{hsmod
133133 | otherwise = []
134134
135135suggestReplaceIdentifier :: Maybe T.Text -> Diagnostic -> [(T.Text, [TextEdit])]
136−suggestReplaceIdentifier contents Diagnostic{_range=_range@Range{..},..}
136+suggestReplaceIdentifier contents Diagnostic{_range=_range,..}
137137-- File.hs:52:41: error:
138138-- * Variable not in scope:
139139-- suggestAcion :: Maybe T.Text -> Range -> Range
@@ -180,7 +180,7 @@ newDefinitionAction IdeOptions{..} parsedModule Range{_start} name typ
180180
181181
182182suggestFillTypeWildcard :: Diagnostic -> [(T.Text, [TextEdit])]
183−suggestFillTypeWildcard Diagnostic{_range=_range@Range{..},..}
183+suggestFillTypeWildcard Diagnostic{_range=_range,..}
184184-- Foo.hs:3:8: error:
185185-- * Found type wildcard `_' standing for `p -> p1 -> p'
186186
@@ -191,7 +191,7 @@ suggestFillTypeWildcard Diagnostic{_range=_range@Range{..},..}
191191 | otherwise = []
192192
193193suggestAddExtension :: Diagnostic -> [(T.Text, [TextEdit])]
194−suggestAddExtension Diagnostic{_range=_range@Range{..},..}
194+suggestAddExtension Diagnostic{_range=_range,..}
195195-- File.hs:22:8: error:
196196-- Illegal lambda-case (use -XLambdaCase)
197197-- File.hs:22:6: error:
@@ -221,7 +221,7 @@ ghcExtensions :: Map.HashMap T.Text Extension
221221ghcExtensions = Map.fromList . map ( ( T.pack . flagSpecName ) &&& flagSpecFlag ) $ xFlags
222222
223223suggestModuleTypo :: Diagnostic -> [(T.Text, [TextEdit])]
224−suggestModuleTypo Diagnostic{_range=_range@Range{..},..}
224+suggestModuleTypo Diagnostic{_range=_range,..}
225225-- src/Development/IDE/Core/Compile.hs:58:1: error:
226226-- Could not find module ‘Data.Cha’
227227-- Perhaps you meant Data.Char (from base-4.12.0.0)
@@ -233,7 +233,7 @@ suggestModuleTypo Diagnostic{_range=_range@Range{..},..}
233233 | otherwise = []
234234
235235suggestFillHole :: Diagnostic -> [(T.Text, [TextEdit])]
236−suggestFillHole Diagnostic{_range=_range@Range{..},..}
236+suggestFillHole Diagnostic{_range=_range,..}
237237-- ...Development/IDE/LSP/CodeAction.hs:103:9: warning:
238238-- * Found hole: _ :: Int -> String
239239-- * In the expression: _
src/Development/IDE/Plugin/Completions/Logic.hs+16
@@ -1,4 +1,5 @@
11{-# LANGUAGE CPP #-}
2+#include "ghc-api-version.h"
23-- Mostly taken from "haskell-ide-engine"
34module Development.IDE.Plugin.Completions.Logic (
45 CachedCompletions
@@ -25,6 +26,12 @@ import Type
2526import Var
2627import Packages
2728import DynFlags
29+#if MIN_GHC_API_VERSION(8,10,0)
30+import Predicate (isDictTy)
31+import GHC.Platform
32+import Pair
33+import Coercion
34+#endif
2835
2936import Language.Haskell.LSP.Types
3037import Language.Haskell.LSP.Types.Capabilities
@@ -169,7 +176,12 @@ getArgText typ = argText
169176 then getArgs ret
170177 else Prelude.filter (not . isDictTy) args
171178 | isPiTy t = getArgs $ snd (splitPiTys t)
179+#if MIN_GHC_API_VERSION(8,10,0)
180+ | Just (Pair _ t) <- coercionKind <$> isCoercionTy_maybe t
181+ = getArgs t
182+#else
172183 | isCoercionTy t = maybe [] (getArgs . snd) (splitCoercionType_maybe t)
184+#endif
173185 | otherwise = []
174186
175187mkModCompl :: T.Text -> CompletionItem
@@ -387,7 +399,11 @@ getCompletions ideOpts CC { allModNamesAsNS, unqualCompls, qualCompls, importabl
387399
388400-- The supported languages and extensions
389401languagesAndExts :: [T.Text]
402+#if MIN_GHC_API_VERSION(8,10,0)
403+languagesAndExts = map T.pack $ DynFlags.supportedLanguagesAndExtensions ( PlatformMini ArchUnknown OSUnknown )
404+#else
390405languagesAndExts = map T.pack DynFlags.supportedLanguagesAndExtensions
406+#endif
391407
392408-- ---------------------------------------------------------------------
393409-- helper functions for pragmas