From 8e0fda4d81aa8f3ac419a41f0599291dda9d1c44 Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Tue, 15 Dec 2020 16:11:54 +0800 Subject: [PATCH] Add CPP --- .../hls-haddock-comments-plugin.cabal | 4 +++- .../include/ghc-api-version.h | 10 ++++++++++ .../src/Ide/Plugin/HaddockComments.hs | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 plugins/hls-haddock-comments-plugin/include/ghc-api-version.h diff --git a/plugins/hls-haddock-comments-plugin/hls-haddock-comments-plugin.cabal b/plugins/hls-haddock-comments-plugin/hls-haddock-comments-plugin.cabal index 94c97e5d5cd..317345ecef4 100644 --- a/plugins/hls-haddock-comments-plugin/hls-haddock-comments-plugin.cabal +++ b/plugins/hls-haddock-comments-plugin/hls-haddock-comments-plugin.cabal @@ -10,7 +10,9 @@ author: Potato Hatsue maintainer: berberman@yandex.com category: Development build-type: Simple -extra-source-files: LICENSE +extra-source-files: + include/ghc-api-version.h + LICENSE library exposed-modules: Ide.Plugin.HaddockComments diff --git a/plugins/hls-haddock-comments-plugin/include/ghc-api-version.h b/plugins/hls-haddock-comments-plugin/include/ghc-api-version.h new file mode 100644 index 00000000000..11cabb3dc90 --- /dev/null +++ b/plugins/hls-haddock-comments-plugin/include/ghc-api-version.h @@ -0,0 +1,10 @@ +#ifndef GHC_API_VERSION_H +#define GHC_API_VERSION_H + +#ifdef GHC_LIB +#define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc_lib(x,y,z) +#else +#define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc(x,y,z) +#endif + +#endif diff --git a/plugins/hls-haddock-comments-plugin/src/Ide/Plugin/HaddockComments.hs b/plugins/hls-haddock-comments-plugin/src/Ide/Plugin/HaddockComments.hs index 812d2c8c50b..dd5db92a8b8 100644 --- a/plugins/hls-haddock-comments-plugin/src/Ide/Plugin/HaddockComments.hs +++ b/plugins/hls-haddock-comments-plugin/src/Ide/Plugin/HaddockComments.hs @@ -1,8 +1,11 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ViewPatterns #-} +#include "ghc-api-version.h" + module Ide.Plugin.HaddockComments where import Control.Monad (join) @@ -93,7 +96,11 @@ keyFromTyVar :: Int -> LHsType GhcPs -> [AnnKey] keyFromTyVar dep c@(L _ (HsFunTy _ x y)) | dep <= 1 = mkAnnKey c : (keyFromTyVar (succ dep) x <> keyFromTyVar (succ dep) y) | otherwise = [] +#if MIN_GHC_API_VERSION(8,10,0) keyFromTyVar dep (L _ (HsForAllTy _ _ _ x)) = keyFromTyVar dep x +#else +keyFromTyVar dep (L _ (HsForAllTy _ _ x)) = keyFromTyVar dep x +#endif keyFromTyVar dep (L _ (HsQualTy _ _ x)) = keyFromTyVar dep x keyFromTyVar dep (L _ (HsParTy _ x)) = keyFromTyVar (succ dep) x keyFromTyVar dep (L _ (HsBangTy _ _ x)) = keyFromTyVar dep x