From 57c01848ca9f3ffce91f8d0ea90d131292498ada Mon Sep 17 00:00:00 2001 From: kokobd Date: Mon, 24 Oct 2022 19:05:13 +0800 Subject: [PATCH 1/2] support haddock-library 1.11 --- ghcide/ghcide.cabal | 2 +- ghcide/src/Development/IDE/Spans/Common.hs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ghcide/ghcide.cabal b/ghcide/ghcide.cabal index 2b3ac1dbba..5d0b50b921 100644 --- a/ghcide/ghcide.cabal +++ b/ghcide/ghcide.cabal @@ -62,7 +62,7 @@ library focus, ghc-trace-events, Glob, - haddock-library >= 1.8 && < 1.11, + haddock-library >= 1.8 && < 1.12, hashable, hie-compat ^>= 0.3.0.0, hls-plugin-api ^>= 1.5, diff --git a/ghcide/src/Development/IDE/Spans/Common.hs b/ghcide/src/Development/IDE/Spans/Common.hs index 00b98ded2a..9ae0665998 100644 --- a/ghcide/src/Development/IDE/Spans/Common.hs +++ b/ghcide/src/Development/IDE/Spans/Common.hs @@ -23,6 +23,7 @@ import GHC.Generics import GHC +import Data.Bifunctor (second) import Development.IDE.GHC.Compat import Development.IDE.GHC.Orphans () import Development.IDE.GHC.Util @@ -179,8 +180,12 @@ haddockToMarkdown (H.DocHeader (H.Header level title)) haddockToMarkdown (H.DocUnorderedList things) = '\n' : (unlines $ map (("+ " ++) . trimStart . splitForList . haddockToMarkdown) things) -haddockToMarkdown (H.DocOrderedList things) - = '\n' : (unlines $ map (("1. " ++) . trimStart . splitForList . haddockToMarkdown) things) +haddockToMarkdown (H.DocOrderedList things) = +#if MIN_VERSION_haddock_library(1,11,0) + '\n' : (unlines $ map ((\(num, str) -> show num ++ ". " ++ str) . second (trimStart . splitForList . haddockToMarkdown)) things) +#else + '\n' : (unlines $ map (("1. " ++) . trimStart . splitForList . haddockToMarkdown) things) +#endif haddockToMarkdown (H.DocDefList things) = '\n' : (unlines $ map (\(term, defn) -> "+ **" ++ haddockToMarkdown term ++ "**: " ++ haddockToMarkdown defn) things) From 0d80365b1cdd8bbc15bb24c3683ddea338aeb81b Mon Sep 17 00:00:00 2001 From: kokobd Date: Mon, 24 Oct 2022 20:01:45 +0800 Subject: [PATCH 2/2] add test case --- ghcide/test/exe/Main.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ghcide/test/exe/Main.hs b/ghcide/test/exe/Main.hs index 81597e1efd..accfade90e 100644 --- a/ghcide/test/exe/Main.hs +++ b/ghcide/test/exe/Main.hs @@ -2393,6 +2393,34 @@ haddockTests , "" ] ) + , testCase "ordered list" $ checkHaddock + (unlines + [ "may require" + , "different precautions:" + , "" + , " 1. Use @{\\-\\# NOINLINE foo \\#-\\}@ as a pragma on any function @foo@" + , " that calls 'unsafePerformIO'. If the call is inlined," + , " the I\\/O may be performed more than once." + , "" + , " 2. Use the compiler flag @-fno-cse@ to prevent common sub-expression" + , " elimination being performed on the module." + , "" + ] + ) + (unlines + [ "" + , "" + , "may require" + , "different precautions: " + , "1. Use `{-# NOINLINE foo #-}` as a pragma on any function `foo` " + , " that calls `unsafePerformIO` . If the call is inlined," + , " the I/O may be performed more than once." + , "" + , "2. Use the compiler flag `-fno-cse` to prevent common sub-expression" + , " elimination being performed on the module." + , "" + ] + ) ] where checkHaddock s txt = spanDocToMarkdownForTest s @?= txt