Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Generate doc file URL via LSP (to fix it for Windows) #721

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Development/IDE/Spans/Documentation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import SrcLoc (RealLocated)
import GhcMonad
import Packages
import Name
import Language.Haskell.LSP.Types (getUri, filePathToUri)

getDocumentationTryGhc :: GhcMonad m => Module -> [ParsedModule] -> Name -> m SpanDoc
getDocumentationTryGhc mod deps n = head <$> getDocumentationsTryGhc mod deps [n]
Expand All @@ -55,24 +56,25 @@ getDocumentationsTryGhc _ sources names = mapM mkSpanDocText names
#endif
mkSpanDocText name =
pure (SpanDocText (getDocumentation sources name)) <*> getUris name

-- Get the uris to the documentation and source html pages if they exist
getUris name = do
df <- getSessionDynFlags
(docFp, srcFp) <-
(docFu, srcFu) <-
case nameModule_maybe name of
Just mod -> liftIO $ do
doc <- fmap (fmap T.pack) $ lookupDocHtmlForModule df mod
src <- fmap (fmap T.pack) $ lookupSrcHtmlForModule df mod
doc <- toFileUriText $ lookupDocHtmlForModule df mod
src <- toFileUriText $ lookupSrcHtmlForModule df mod
return (doc, src)
Nothing -> pure (Nothing, Nothing)
let docUri = docFp >>= \fp -> pure $ "file://" <> fp <> "#" <> selector <> showName name
srcUri = srcFp >>= \fp -> pure $ "file://" <> fp <> "#" <> showName name
let docUri = (<> "#" <> selector <> showName name) <$> docFu
srcUri = (<> "#" <> showName name) <$> srcFu
selector
| isValName name = "v:"
| otherwise = "t:"
return $ SpanDocUris docUri srcUri

toFileUriText = (fmap . fmap) (getUri . filePathToUri)

getDocumentation
:: HasSrcSpan name
Expand Down
2 changes: 1 addition & 1 deletion test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ findDefinitionAndHoverTests = let
lstL43 = Position 47 12 ; litL = [ExpectHoverText ["[8391 :: Int, 6268]"]]
outL45 = Position 49 3 ; outSig = [ExpectHoverText ["outer", "Bool"], mkR 46 0 46 5]
innL48 = Position 52 5 ; innSig = [ExpectHoverText ["inner", "Char"], mkR 49 2 49 7]
cccL17 = Position 17 11 ; docLink = [ExpectHoverText ["[Documentation](file://"]]
cccL17 = Position 17 11 ; docLink = [ExpectHoverText ["[Documentation](file:///"]]
#if MIN_GHC_API_VERSION(8,6,0)
imported = Position 56 13 ; importedSig = getDocUri "Foo.hs" >>= \foo -> return [ExpectHoverText ["foo", "Foo", "Haddock"], mkL foo 5 0 5 3]
reexported = Position 55 14 ; reexportedSig = getDocUri "Bar.hs" >>= \bar -> return [ExpectHoverText ["Bar", "Bar", "Haddock"], mkL bar 3 0 3 14]
Expand Down