Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Compatibility with GHC < 8.8
Browse files Browse the repository at this point in the history
  • Loading branch information
pepeiborra committed Jun 27, 2020
1 parent 05c18c3 commit f9968b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
- default: false
- {name: [-Wno-missing-signatures, -Wno-orphans, -Wno-overlapping-patterns, -Wno-incomplete-patterns, -Wno-missing-fields, -Wno-unused-matches]}
- {name: [-Wno-dodgy-imports], within: Main}
- {name: [-Wno-dodgy-imports], within: Development.IDE.GHC.Compat}
# - modules:
# - {name: [Data.Set, Data.HashSet], as: Set} # if you import Data.Set qualified, it must be as 'Set'
# - {name: Control.Arrow, within: []} # Certain modules are banned entirely
Expand Down
25 changes: 23 additions & 2 deletions src/Development/IDE/GHC/Compat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
-- SPDX-License-Identifier: Apache-2.0

{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PatternSynonyms #-}
{-# OPTIONS -Wno-dodgy-imports #-}
#include "ghc-api-version.h"

-- | Attempt at hiding the GHC version differences we can.
Expand Down Expand Up @@ -43,6 +46,9 @@ module Development.IDE.GHC.Compat(
pattern ModLocation,
getConArgs,

HasSrcSpan,
getLoc,

module GHC
) where

Expand All @@ -66,7 +72,9 @@ import GHC hiding (
SigD,
TypeSig,
VarPat,
ModLocation
ModLocation,
HasSrcSpan,
getLoc
#if MIN_GHC_API_VERSION(8,6,0)
, getConArgs
#endif
Expand Down Expand Up @@ -104,7 +112,7 @@ import System.IO.Error
import Binary
import Control.Exception (catch)
import Data.ByteString (ByteString)
import GhcPlugins hiding (ModLocation)
import GhcPlugins (Hsc, srcErrorMessages)
import NameCache
import TcRnTypes
import System.IO
Expand Down Expand Up @@ -325,7 +333,20 @@ getHeaderImports
)
#if MIN_GHC_API_VERSION(8,8,0)
getHeaderImports = Hdr.getImports

type HasSrcSpan = GHC.HasSrcSpan
getLoc :: HasSrcSpan a => a -> SrcSpan
getLoc = GHC.getLoc

#else

class HasSrcSpan a where
getLoc :: a -> SrcSpan
instance HasSrcSpan Name where
getLoc = nameSrcSpan
instance HasSrcSpan (GenLocated SrcSpan a) where
getLoc = GHC.getLoc

getHeaderImports a b c d =
catch (Right <$> Hdr.getImports a b c d)
(return . Left . srcErrorMessages)
Expand Down
2 changes: 1 addition & 1 deletion src/Development/IDE/Spans/Documentation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Development.IDE.GHC.Compat
import Development.IDE.GHC.Error
import Development.IDE.Spans.Common
import FastString
import SrcLoc
import SrcLoc (RealLocated)


getDocumentationTryGhc
Expand Down

0 comments on commit f9968b8

Please sign in to comment.