Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 39bc399

Browse files
authored
Merge pull request #1181 from alanz/hover-reply
Use LSP MarkupContent for generated documentation
2 parents 93718bd + 650e1d7 commit 39bc399

19 files changed

+92
-87
lines changed

haskell-ide-engine.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ library
7070
, gitrev >= 1.1
7171
, haddock-api
7272
, haddock-library
73-
, haskell-lsp >= 0.8.2
74-
, haskell-lsp-types >= 0.8.2
73+
, haskell-lsp == 0.9.*
74+
, haskell-lsp-types == 0.9.*
7575
, haskell-src-exts
7676
, hie-plugin-api
7777
, hlint >= 2.0.11
@@ -275,7 +275,7 @@ test-suite func-test
275275
, data-default
276276
, directory
277277
, filepath
278-
, lsp-test == 0.5.*
278+
, lsp-test >= 0.5.1.1 && < 0.5.2
279279
, haskell-ide-engine
280280
, haskell-lsp-types >= 0.4
281281
, hie-test-utils

hie-plugin-api/hie-plugin-api.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ library
4141
, free
4242
, ghc
4343
, ghc-mod-core >= 5.9.0.0
44-
, haskell-lsp >= 0.8
44+
, haskell-lsp == 0.9.*
4545
, hslogger
4646
, monad-control
4747
, mtl

src/Haskell/Ide/Engine/Plugin/GhcMod.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,17 +594,17 @@ hoverProvider doc pos = runIdeResultT $ do
594594
((r,typ):_) ->
595595
case find ((r ==) . fst) names of
596596
Nothing ->
597-
(Just $ LSP.CodeString $ LSP.LanguageString "haskell" $ "_ :: " <> typ, Just r)
597+
(Just $ LSP.markedUpContent "haskell" $ "_ :: " <> typ, Just r)
598598
Just (_,name)
599599
| nnames == 1 ->
600-
(Just $ LSP.CodeString $ LSP.LanguageString "haskell" $ Hie.showName name <> " :: " <> typ, Just r)
600+
(Just $ LSP.markedUpContent "haskell" $ Hie.showName name <> " :: " <> typ, Just r)
601601
| otherwise ->
602-
(Just $ LSP.CodeString $ LSP.LanguageString "haskell" $ "_ :: " <> typ, Just r)
602+
(Just $ LSP.markedUpContent "haskell" $ "_ :: " <> typ, Just r)
603603
[] -> case names of
604604
[] -> (Nothing, Nothing)
605605
((r,_):_) -> (Nothing, Just r)
606606
return $ case mrange of
607-
Just r -> [LSP.Hover (LSP.List $ catMaybes [info]) (Just r)]
607+
Just r -> [LSP.Hover (LSP.HoverContents $ mconcat $ catMaybes [info]) (Just r)]
608608
Nothing -> []
609609

610610
-- ---------------------------------------------------------------------

src/Haskell/Ide/Engine/Plugin/Haddock.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ hoverProvider doc pos = pluginGetFile "haddock:hoverProvider" doc $ \fp ->
223223
return $ case mdocu of
224224
Nothing -> mname <> minfo
225225
Just docu -> docu <> "\n\n" <> minfo
226-
return [J.Hover (J.List $ fmap J.PlainString docs) Nothing]
226+
return [J.Hover (J.HoverContents $ J.MarkupContent J.MkMarkdown (T.intercalate J.sectionSeparator docs)) Nothing]
227227
where
228228
pickName [] = Nothing
229229
pickName [x] = Just x

src/Haskell/Ide/Engine/Plugin/Hoogle.hs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ instance ExtensionClass HoogleDb where
6060
-- | Initialise the Hoogle Database.
6161
-- Search for the Hoogle Database and set it in the global config if found.
6262
-- Looks first into custom hoogle database locations, then in the default location.
63-
-- Note, that the FilePath must be an absolute path, otherwise Hoogle can not
63+
-- Note, that the FilePath must be an absolute path, otherwise Hoogle can not
6464
-- find the database.
65-
--
65+
--
6666
-- If no hoogle database has been found, Nothing is returned
6767
-- and we will have no access to the hoogle database.
68-
-- However, it is still safe to use the hoogle API,
68+
-- However, it is still safe to use the hoogle API,
6969
-- e.g. either error or default values are returned.
7070
initializeHoogleDb :: IdeGhcM (Maybe FilePath)
7171
initializeHoogleDb = do
@@ -100,9 +100,9 @@ infoCmd' expr = do
100100
-- If documentation can be found for it, the result will be rendered
101101
-- in markdown for the lsp-client. If multiple results have been found,
102102
-- only the first result will be shown.
103-
--
104-
-- If no result can be found for the identifier, a hoogle error is returned
105-
-- that can be shown to the client by converting it
103+
--
104+
-- If no result can be found for the identifier, a hoogle error is returned
105+
-- that can be shown to the client by converting it
106106
-- to an IdeError with 'hoogleErrorToIdeError'.
107107
infoCmdFancyRender :: T.Text -> IdeM (Either HoogleError T.Text)
108108
infoCmdFancyRender expr = do
@@ -116,7 +116,8 @@ infoCmdFancyRender expr = do
116116
-- | Render the target in valid markdown.
117117
-- Transform haddock documentation into markdown.
118118
renderTarget :: Target -> T.Text
119-
renderTarget t = T.intercalate "\n\n" $
119+
-- renderTarget t = T.intercalate "\n\n" $
120+
renderTarget t = T.intercalate "\n" $
120121
["```haskell\n" <> unHTML (T.pack $ targetItem t) <> "```"]
121122
++ [T.pack $ unwords mdl | not $ null mdl]
122123
++ [renderDocs $ targetDocs t]
@@ -154,8 +155,8 @@ searchPackages :: T.Text -> IdeM [T.Text]
154155
searchPackages = fmap (nub . take 5) . searchTargets (fmap (T.pack . fst) . targetPackage)
155156

156157
-- | Search for Targets that fit to the given Text and satisfy the given predicate.
157-
-- Limits the amount of matches to at most ten.
158-
-- Applies the predicate to the first ten matches. May also return zero matches,
158+
-- Limits the amount of matches to at most ten.
159+
-- Applies the predicate to the first ten matches. May also return zero matches,
159160
-- although there are matches, if none of the first ten matches
160161
-- satisfies the predicate.
161162
--
@@ -192,7 +193,7 @@ lookupCmd' n term = do
192193

193194
------------------------------------------------------------------------
194195

195-
-- | Run a query for Hoogle on the given Hoogle database.
196+
-- | Run a query for Hoogle on the given Hoogle database.
196197
-- If no Database is given, no search is executed.
197198
-- If the Database cannot be found at the given location, an IOException will be thrown.
198199
-- Note, that the database file must be an absolute path.
@@ -201,15 +202,15 @@ lookupCmd' n term = do
201202
-- Found targets can be consumed with the given callback function.
202203
-- You can limit the amount of results, by taking only the first ten results.
203204
-- Example call:
204-
--
205-
-- @
206-
-- runHoogleQuery
207-
-- (Just "/home/user/.hoogle/default-haskell-5.0.17.hoo")
208-
-- (Data.Text.pack "take :: Int -> [a] -> [a]")
205+
--
206+
-- @
207+
-- runHoogleQuery
208+
-- (Just "/home/user/.hoogle/default-haskell-5.0.17.hoo")
209+
-- (Data.Text.pack "take :: Int -> [a] -> [a]")
209210
-- (Right . Prelude.take 10)
210211
-- @
211212
-- This limits the results to ten and looks for a function `take` that has the given signature.
212-
--
213+
--
213214
-- HoogleError's can be translated to IdeErrors with @hoogleErrorToIdeError@
214215
-- and shown to the client.
215216
runHoogleQuery :: Maybe FilePath -> T.Text -> ([Target] -> Either HoogleError a) -> IO (Either HoogleError a)
@@ -219,7 +220,7 @@ runHoogleQuery (Just db) quer f = do
219220
return (f res)
220221

221222

222-
-- | Run a query for Hoogle on the given Hoogle database.
223+
-- | Run a query for Hoogle on the given Hoogle database.
223224
-- If the database can not be found, an IOException is thrown.
224225
-- The target may be of the form: `take`, `take :: Int -> [a] -> [a]`
225226
searchHoogle :: FilePath -> T.Text -> IO [Target]

src/Haskell/Ide/Engine/Plugin/Liquid.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ hoverProvider uri pos =
258258
ls = getThingsAtPos info pos perrs
259259
hs <- forM ls $ \(r,LE _s _e msg) -> do
260260
let msgs = T.splitOn "\\n" msg
261-
msg' = J.CodeString (J.LanguageString "haskell" (T.unlines msgs))
262-
return $ J.Hover (J.List [msg']) (Just r)
261+
msgm = J.markedUpContent "haskell" (T.unlines msgs)
262+
return $ J.Hover (J.HoverContents msgm) (Just r)
263263
return (IdeResultOk hs)
264264

265265
-- ---------------------------------------------------------------------

src/Haskell/Ide/Engine/Transport/LspStdio.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ reactor inp diagIn = do
553553
-- TODO: maybe only have provider give MarkedString and
554554
-- work out range here?
555555
let hs = concat hhs
556-
h = case (fold (map (^. J.contents) hs) :: List J.MarkedString) of
557-
List [] -> Nothing
558-
hh -> Just $ J.Hover hh r
556+
h = case mconcat ((map (^. J.contents) hs) :: [J.HoverContents]) of
557+
J.HoverContentsMS (List []) -> Nothing
558+
hh -> Just $ J.Hover hh r
559559
r = listToMaybe $ mapMaybe (^. J.range) hs
560560
in reactorSend $ RspHover $ Core.makeResponseMessage req h
561561

stack-8.2.1.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ packages:
44
- hie-plugin-api
55

66
extra-deps:
7-
- ./submodules/brittany
87
- ./submodules/HaRe
9-
- ./submodules/ghc-mod
10-
- ./submodules/ghc-mod/core
8+
- ./submodules/brittany
119
- ./submodules/cabal-helper
1210
- ./submodules/floskell
11+
- ./submodules/ghc-mod
12+
- ./submodules/ghc-mod/core
1313

1414
# - brittany-0.11.0.0
1515
- butcher-1.3.1.1
@@ -19,11 +19,11 @@ extra-deps:
1919
- ghc-exactprint-0.5.8.2
2020
- haddock-api-2.18.1
2121
- haddock-library-1.4.4
22-
- haskell-lsp-0.8.2.0
23-
- haskell-lsp-types-0.8.2.0
22+
- haskell-lsp-0.9.0.0
23+
- haskell-lsp-types-0.9.0.0
2424
- hlint-2.0.11
2525
- hsimport-0.8.6
26-
- lsp-test-0.5.1.0
26+
- lsp-test-0.5.1.1
2727
- monad-dijkstra-0.1.1.2
2828
- mtl-2.2.2
2929
- pretty-show-1.8.2

stack-8.2.2.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ packages:
44
- hie-plugin-api
55

66
extra-deps:
7-
- ./submodules/brittany
87
- ./submodules/HaRe
9-
- ./submodules/ghc-mod
10-
- ./submodules/ghc-mod/core
8+
- ./submodules/brittany
119
- ./submodules/cabal-helper
1210
- ./submodules/floskell
11+
- ./submodules/ghc-mod
12+
- ./submodules/ghc-mod/core
1313

1414
# - brittany-0.11.0.0
1515
- butcher-1.3.1.1
@@ -20,14 +20,14 @@ extra-deps:
2020
- ghc-exactprint-0.5.8.2
2121
- haddock-api-2.18.1
2222
- haddock-library-1.4.4
23-
- haskell-lsp-0.8.2.0
24-
- haskell-lsp-types-0.8.2.0
23+
- haskell-lsp-0.9.0.0
24+
- haskell-lsp-types-0.9.0.0
2525
- haskell-src-exts-1.21.0
2626
- haskell-src-exts-util-0.2.5
2727
- hlint-2.1.16
2828
- hoogle-5.0.17.6
2929
- hsimport-0.8.8
30-
- lsp-test-0.5.1.0
30+
- lsp-test-0.5.1.1
3131
- monad-dijkstra-0.1.1.2
3232
- pretty-show-1.8.2
3333
- sorted-list-0.2.1.0

stack-8.4.2.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ packages:
44
- hie-plugin-api
55

66
extra-deps:
7-
- ./submodules/brittany
87
- ./submodules/HaRe
9-
- ./submodules/ghc-mod
10-
- ./submodules/ghc-mod/core
8+
- ./submodules/brittany
119
- ./submodules/cabal-helper
1210
- ./submodules/floskell
11+
- ./submodules/ghc-mod
12+
- ./submodules/ghc-mod/core
1313

1414
# - brittany-0.11.0.0
1515
- base-compat-0.9.3
@@ -18,14 +18,14 @@ extra-deps:
1818
- ghc-exactprint-0.5.8.2
1919
- haddock-api-2.20.0
2020
- haddock-library-1.6.0
21-
- haskell-lsp-0.8.2.0
22-
- haskell-lsp-types-0.8.2.0
21+
- haskell-lsp-0.9.0.0
22+
- haskell-lsp-types-0.9.0.0
2323
- haskell-src-exts-1.21.0
2424
- haskell-src-exts-util-0.2.5
2525
- hlint-2.1.16
2626
- hoogle-5.0.17.6
2727
- hsimport-0.8.8
28-
- lsp-test-0.5.1.0
28+
- lsp-test-0.5.1.1
2929
- monad-dijkstra-0.1.1.2
3030
- pretty-show-1.8.2
3131
- syz-0.2.0.0

stack-8.4.3.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ packages:
44
- hie-plugin-api
55

66
extra-deps:
7-
- ./submodules/brittany
87
- ./submodules/HaRe
9-
- ./submodules/ghc-mod
10-
- ./submodules/ghc-mod/core
8+
- ./submodules/brittany
119
- ./submodules/cabal-helper
1210
- ./submodules/floskell
11+
- ./submodules/ghc-mod
12+
- ./submodules/ghc-mod/core
1313

1414
- base-compat-0.9.3
1515
- cabal-plan-0.3.0.0
1616
- constrained-dynamic-0.1.0.0
1717
- ghc-exactprint-0.5.8.2
1818
- haddock-api-2.20.0
1919
- haddock-library-1.6.0
20-
- haskell-lsp-0.8.2.0
21-
- haskell-lsp-types-0.8.2.0
20+
- haskell-lsp-0.9.0.0
21+
- haskell-lsp-types-0.9.0.0
2222
- haskell-src-exts-1.21.0
2323
- haskell-src-exts-util-0.2.5
2424
- hlint-2.1.16
2525
- hoogle-5.0.17.6
2626
- hsimport-0.8.8
27-
- lsp-test-0.5.1.0
27+
- lsp-test-0.5.1.1
2828
- monad-dijkstra-0.1.1.2
2929
- pretty-show-1.8.2
3030
- syz-0.2.0.0

stack-8.4.4.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ packages:
44
- hie-plugin-api
55

66
extra-deps:
7-
- ./submodules/brittany
87
- ./submodules/HaRe
9-
- ./submodules/ghc-mod
10-
- ./submodules/ghc-mod/core
8+
- ./submodules/brittany
119
- ./submodules/cabal-helper
1210
- ./submodules/floskell
11+
- ./submodules/ghc-mod
12+
- ./submodules/ghc-mod/core
1313

1414
# - brittany-0.11.0.0
1515
- cabal-plan-0.4.0.0
1616
- constrained-dynamic-0.1.0.0
1717
- ghc-exactprint-0.5.8.2
1818
- haddock-api-2.20.0
1919
- haddock-library-1.6.0
20-
- haskell-lsp-0.8.2.0
21-
- haskell-lsp-types-0.8.2.0
20+
- haskell-lsp-0.9.0.0
21+
- haskell-lsp-types-0.9.0.0
2222
- haskell-src-exts-1.21.0
2323
- haskell-src-exts-util-0.2.5
2424
- hlint-2.1.16
2525
- hoogle-5.0.17.6
2626
- hsimport-0.8.8
27-
- lsp-test-0.5.1.0
27+
- lsp-test-0.5.1.1
2828
- monad-dijkstra-0.1.1.2
2929
- optparse-simple-0.1.0
3030
- pretty-show-1.9.5

stack-8.6.1.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ extra-deps:
77
- ./submodules/HaRe
88
- ./submodules/brittany
99
- ./submodules/cabal-helper
10+
- ./submodules/floskell
1011
- ./submodules/ghc-mod
1112
- ./submodules/ghc-mod/core
12-
- ./submodules/floskell
1313

1414
- apply-refact-0.6.0.0
1515
- butcher-1.3.2.1
@@ -19,14 +19,14 @@ extra-deps:
1919
- czipwith-1.0.1.1
2020
- data-tree-print-0.1.0.2
2121
- haddock-api-2.21.0
22-
- haskell-lsp-0.8.2.0
23-
- haskell-lsp-types-0.8.2.0
22+
- haskell-lsp-0.9.0.0
23+
- haskell-lsp-types-0.9.0.0
2424
- haskell-src-exts-1.21.0
2525
- haskell-src-exts-util-0.2.5
2626
- hlint-2.1.16
2727
- hoogle-5.0.17.6
2828
- hsimport-0.8.8
29-
- lsp-test-0.5.1.0
29+
- lsp-test-0.5.1.1
3030
- monad-dijkstra-0.1.1.2
3131
- monad-memo-0.4.1
3232
- monoid-subclasses-0.4.6.1

stack-8.6.2.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ extra-deps:
77
- ./submodules/HaRe
88
- ./submodules/brittany
99
- ./submodules/cabal-helper
10+
- ./submodules/floskell
1011
- ./submodules/ghc-mod
1112
- ./submodules/ghc-mod/core
12-
- ./submodules/floskell
1313

1414
- butcher-1.3.2.1
1515
- cabal-plan-0.4.0.0
1616
- constrained-dynamic-0.1.0.0
1717
- haddock-api-2.21.0
18-
- haskell-lsp-0.8.2.0
19-
- haskell-lsp-types-0.8.2.0
18+
- haskell-lsp-0.9.0.0
19+
- haskell-lsp-types-0.9.0.0
2020
- haskell-src-exts-1.21.0
2121
- haskell-src-exts-util-0.2.5
2222
- hlint-2.1.16
2323
- hoogle-5.0.17.6
2424
- hsimport-0.8.8
25-
- lsp-test-0.5.1.0
25+
- lsp-test-0.5.1.1
2626
- monad-dijkstra-0.1.1.2
2727
- monad-memo-0.4.1
2828
- multistate-0.8.0.1

0 commit comments

Comments
 (0)