Skip to content

Commit

Permalink
Generate doc file URL via LSP (to fix it for Windows) (haskell/ghcide…
Browse files Browse the repository at this point in the history
…#721)

* use three slashes in doc file URLs to fix it for Windows

* generate normalized doc file URL using LSP
  • Loading branch information
DunetsNM authored Sep 2, 2020
1 parent 17455d1 commit ff6a355
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions ghcide/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 ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,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

0 comments on commit ff6a355

Please sign in to comment.