Skip to content

Commit 5936154

Browse files
committed
Fix doc display
1 parent 0fb01e1 commit 5936154

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

ghcide/src/Development/IDE/Spans/Common.hs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,19 @@ emptySpanDoc :: SpanDoc
7979
emptySpanDoc = SpanDocText [] (SpanDocUris Nothing Nothing)
8080

8181
spanDocToMarkdown :: SpanDoc -> [T.Text]
82-
spanDocToMarkdown (SpanDocString docs uris)
83-
= [(T.pack $ haddockToMarkdown $ H.toRegular $ H._doc $ H.parseParas Nothing $ unpackHDS docs) <> T.pack "\n"]
84-
<> spanDocUrisToMarkdown uris
85-
-- Append the extra newlines since this is markdown --- to get a visible newline,
86-
-- you need to have two newlines
87-
spanDocToMarkdown (SpanDocText txt uris) = map (<> T.pack "\n") txt <> ["\n"] <> spanDocUrisToMarkdown uris
82+
spanDocToMarkdown = \case
83+
(SpanDocString docs uris) ->
84+
let doc = T.pack $ haddockToMarkdown $ H.toRegular $ H._doc $ H.parseParas Nothing $ unpackHDS docs
85+
in go [doc] uris
86+
(SpanDocText txt uris) -> go txt uris
87+
where
88+
go [] uris = spanDocUrisToMarkdown uris
89+
go txt uris = init txt <> [render (last txt)] <> spanDocUrisToMarkdown uris
90+
-- If the doc is not end with an `'\n'`, we append it.
91+
render txt
92+
| T.null txt = txt
93+
| T.last txt == '\n' = txt
94+
| otherwise = txt <> T.pack "\n"
8895

8996
spanDocUrisToMarkdown :: SpanDocUris -> [T.Text]
9097
spanDocUrisToMarkdown (SpanDocUris mdoc msrc) = catMaybes

0 commit comments

Comments
 (0)