Skip to content

Commit f6ec3fb

Browse files
committed
Fix hover format
1 parent b1bf549 commit f6ec3fb

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import Development.IDE.Core.PositionMapping
3232
import Development.IDE.Core.RuleTypes
3333
import Development.IDE.GHC.Compat
3434
import qualified Development.IDE.GHC.Compat.Util as Util
35+
import Development.IDE.GHC.Util (printOutputable)
3536
import Development.IDE.Spans.Common
3637
import Development.IDE.Types.Options
37-
import Development.IDE.GHC.Util (printOutputable)
3838

3939
import Control.Applicative
4040
import Control.Monad.Extra
@@ -231,11 +231,14 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p
231231
prettyNames = map prettyName names
232232
prettyName (Right n, dets) = T.unlines $
233233
wrapHaskell (printOutputable n <> maybe "" (" :: " <>) ((prettyType <$> identType dets) <|> maybeKind))
234-
: definedAt n
235-
++ maybeToList (prettyPackageName n)
234+
: maybeToList (pretty (definedAt n) (prettyPackageName n))
236235
++ catMaybes [ T.unlines . spanDocToMarkdown <$> lookupNameEnv dm n
237236
]
238237
where maybeKind = fmap printOutputable $ safeTyThingType =<< lookupNameEnv km n
238+
pretty Nothing Nothing = Nothing
239+
pretty (Just define) Nothing = Just $ define <> "\n"
240+
pretty Nothing (Just pkgName) = Just $ pkgName <> "\n"
241+
pretty (Just define) (Just pkgName) = Just $ define <> " " <> pkgName <> "\n"
239242
prettyName (Left m,_) = printOutputable m
240243

241244
prettyPackageName n = do
@@ -255,8 +258,8 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p
255258
-- do not show "at <no location info>" and similar messages
256259
-- see the code of 'pprNameDefnLoc' for more information
257260
case nameSrcLoc name of
258-
UnhelpfulLoc {} | isInternalName name || isSystemName name -> []
259-
_ -> ["*Defined " <> printOutputable (pprNameDefnLoc name) <> "*"]
261+
UnhelpfulLoc {} | isInternalName name || isSystemName name -> Nothing
262+
_ -> Just $ "*Defined " <> printOutputable (pprNameDefnLoc name) <> "*"
260263

261264
typeLocationsAtPoint
262265
:: forall m

ghcide/test/exe/Main.hs

+2
Original file line numberDiff line numberDiff line change
@@ -4348,6 +4348,7 @@ findDefinitionAndHoverTests = let
43484348
imported = Position 56 13 ; importedSig = getDocUri "Foo.hs" >>= \foo -> return [ExpectHoverText ["foo", "Foo", "Haddock"], mkL foo 5 0 5 3]
43494349
reexported = Position 55 14 ; reexportedSig = getDocUri "Bar.hs" >>= \bar -> return [ExpectHoverText ["Bar", "Bar", "Haddock"], mkL bar 3 0 3 14]
43504350
thLocL57 = Position 59 10 ; thLoc = [ExpectHoverText ["Identity"]]
4351+
doc36 = Position 36 20; multiDoc = [ExpectHoverText ["\n\n[Documentation](file:///"]]
43514352
in
43524353
mkFindTests
43534354
-- def hover look expect
@@ -4410,6 +4411,7 @@ findDefinitionAndHoverTests = let
44104411
test no broken thLocL57 thLoc "TH Splice Hover"
44114412
| otherwise ->
44124413
test no yes thLocL57 thLoc "TH Splice Hover"
4414+
, test yes yes doc36 multiDoc "two newlines before document"
44134415
]
44144416
where yes, broken :: (TestTree -> Maybe TestTree)
44154417
yes = Just -- test should run and pass

0 commit comments

Comments
 (0)