-
-
Notifications
You must be signed in to change notification settings - Fork 430
Use Hackage for Documentation and Source links #4746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Saizan
wants to merge
4
commits into
haskell:master
Choose a base branch
from
Saizan:link-to-hackage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−19
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,15 +22,20 @@ import qualified Data.Map as M | |
| import Data.Maybe | ||
| import qualified Data.Set as S | ||
| import qualified Data.Text as T | ||
| import Data.Version (showVersion) | ||
| import Development.IDE.Core.Compile | ||
| import Development.IDE.Core.RuleTypes | ||
| import Development.IDE.GHC.Compat | ||
| import Development.IDE.GHC.Compat.Util | ||
| import Development.IDE.GHC.Error | ||
| import Development.IDE.GHC.Util (printOutputable) | ||
| import Development.IDE.Spans.Common | ||
| import Development.IDE.Types.Options (LinkTargets (..)) | ||
| import GHC.Iface.Ext.Utils (RefMap) | ||
| import Language.LSP.Protocol.Types (filePathToUri, getUri) | ||
| import GHC.Plugins (GenericUnitInfo (unitPackageName)) | ||
| import Ide.Types (OptLinkTo (..)) | ||
| import Language.LSP.Protocol.Types (Uri (..), filePathToUri, | ||
| getUri) | ||
| import Prelude hiding (mod) | ||
| import System.Directory | ||
| import System.FilePath | ||
|
|
@@ -40,8 +45,9 @@ mkDocMap | |
| :: HscEnv | ||
| -> RefMap a | ||
| -> TcGblEnv | ||
| -> LinkTargets | ||
| -> IO DocAndTyThingMap | ||
| mkDocMap env rm this_mod = | ||
| mkDocMap env rm this_mod linkTgts = | ||
| do | ||
| (Just Docs{docs_decls = UniqMap this_docs, docs_args = UniqMap this_arg_docs}) <- extractDocs (hsc_dflags env) this_mod | ||
| d <- foldrM getDocs (fmap (\(_, x) -> (map hsDocString x) `SpanDocString` SpanDocUris Nothing Nothing) this_docs) names | ||
|
|
@@ -52,7 +58,7 @@ mkDocMap env rm this_mod = | |
| getDocs n nameMap | ||
| | maybe True (mod ==) $ nameModule_maybe n = pure nameMap -- we already have the docs in this_docs, or they do not exist | ||
| | otherwise = do | ||
| (doc, _argDoc) <- getDocumentationTryGhc env n | ||
| (doc, _argDoc) <- getDocumentationTryGhc env linkTgts n | ||
| pure $ extendNameEnv nameMap n doc | ||
| getType n nameMap | ||
| | Nothing <- lookupNameEnv nameMap n | ||
|
|
@@ -62,7 +68,7 @@ mkDocMap env rm this_mod = | |
| getArgDocs n nameMap | ||
| | maybe True (mod ==) $ nameModule_maybe n = pure nameMap | ||
| | otherwise = do | ||
| (_doc, argDoc) <- getDocumentationTryGhc env n | ||
| (_doc, argDoc) <- getDocumentationTryGhc env linkTgts n | ||
| pure $ extendNameEnv nameMap n argDoc | ||
| names = rights $ S.toList idents | ||
| idents = M.keysSet rm | ||
|
|
@@ -72,13 +78,13 @@ lookupKind :: HscEnv -> Name -> IO (Maybe TyThing) | |
| lookupKind env = | ||
| fmap (fromRight Nothing) . catchSrcErrors (hsc_dflags env) "span" . lookupName env | ||
|
|
||
| getDocumentationTryGhc :: HscEnv -> Name -> IO (SpanDoc, IntMap SpanDoc) | ||
| getDocumentationTryGhc env n = | ||
| (fromMaybe (emptySpanDoc, mempty) . listToMaybe <$> getDocumentationsTryGhc env [n]) | ||
| getDocumentationTryGhc :: HscEnv -> LinkTargets -> Name -> IO (SpanDoc, IntMap SpanDoc) | ||
| getDocumentationTryGhc env l2h n = | ||
| (fromMaybe (emptySpanDoc, mempty) . listToMaybe <$> getDocumentationsTryGhc env l2h [n]) | ||
| `catch` (\(_ :: IOEnvFailure) -> pure (emptySpanDoc, mempty)) | ||
|
|
||
| getDocumentationsTryGhc :: HscEnv -> [Name] -> IO [(SpanDoc, IntMap SpanDoc)] | ||
| getDocumentationsTryGhc env names = do | ||
| getDocumentationsTryGhc :: HscEnv -> LinkTargets -> [Name] -> IO [(SpanDoc, IntMap SpanDoc)] | ||
| getDocumentationsTryGhc env linkTgts names = do | ||
| resOr <- catchSrcErrors (hsc_dflags env) "docs" $ getDocsBatch env names | ||
| case resOr of | ||
| Left _ -> return [] | ||
|
|
@@ -95,18 +101,46 @@ getDocumentationsTryGhc env names = do | |
| (docFu, srcFu) <- | ||
| case nameModule_maybe name of | ||
| Just mod -> liftIO $ do | ||
| doc <- toFileUriText $ lookupDocHtmlForModule env mod | ||
| src <- toFileUriText $ lookupSrcHtmlForModule env mod | ||
| return (doc, src) | ||
| doc <- lookupDocHtmlForModule env mod | ||
| src <- lookupSrcHtmlForModule env mod | ||
| -- If found, the local files are used as hints for the hackage links, this helps with symbols defined in an internal module but re-exported by another. | ||
| let | ||
| LinkTargets{linkDoc,linkSource} = linkTgts | ||
| doc_link = case linkDoc of | ||
| LinkToHackage -> | ||
| toHackageDocUriText env mod (takeFileName <$> doc) | ||
| LinkToLocal -> | ||
| toFileUriText doc | ||
| src_link = case linkSource of | ||
| LinkToHackage -> | ||
| toHackageSrcUriText env mod (takeFileName <$> src) | ||
| LinkToLocal -> | ||
| toFileUriText src | ||
| pure (doc_link, src_link) | ||
| Nothing -> pure (Nothing, Nothing) | ||
|
|
||
| let docUri = (<> "#" <> selector <> printOutputable name) <$> docFu | ||
| srcUri = (<> "#" <> printOutputable name) <$> srcFu | ||
| selector | ||
| | isValName name = "v:" | ||
| | otherwise = "t:" | ||
| return $ SpanDocUris docUri srcUri | ||
|
|
||
| toFileUriText = (fmap . fmap) (getUri . filePathToUri) | ||
| toFileUriText = fmap (getUri . filePathToUri) | ||
| toHackageUriText subdir sep env mod hint = do | ||
| ui <- lookupUnit env (moduleUnit mod) | ||
| let htmlFile = case hint of | ||
| Nothing -> T.intercalate sep (map T.pack $ moduleNameChunks mod) <> ".html" | ||
| Just foundFile -> T.replace "-" sep $ T.pack foundFile | ||
| pure $! | ||
| mconcat $ | ||
| [ "http://hackage.haskell.org/package/" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use |
||
| , printOutputable (unitPackageName ui), "-", T.pack $ showVersion (unitPackageVersion ui), "/" | ||
| , subdir , "/" | ||
| , htmlFile | ||
| ] | ||
| toHackageDocUriText mod = toHackageUriText "docs" "-" mod | ||
| toHackageSrcUriText mod = toHackageUriText "docs/src" "." mod | ||
|
|
||
| getDocumentation | ||
| :: HasSrcSpan name | ||
|
|
@@ -146,10 +180,13 @@ lookupHtmlForModule mkDocPath hscEnv m = do | |
| -- first Language.LSP.Types.Uri.html and Language-Haskell-LSP-Types-Uri.html | ||
| -- then Language.LSP.Types.html and Language-Haskell-LSP-Types.html etc. | ||
| mns = do | ||
| chunks <- (reverse . drop1 . inits . splitOn ".") $ (moduleNameString . moduleName) m | ||
| chunks <- (reverse . drop1 . inits) $ moduleNameChunks m | ||
| -- The file might use "." or "-" as separator | ||
| map (`intercalate` chunks) [".", "-"] | ||
|
|
||
| moduleNameChunks :: Module -> [String] | ||
| moduleNameChunks m = splitOn "." $ (moduleNameString . moduleName) m | ||
|
|
||
| lookupHtmls :: HscEnv -> Unit -> Maybe [FilePath] | ||
| lookupHtmls df ui = | ||
| -- use haddockInterfaces instead of haddockHTMLs: GHC treats haddockHTMLs as URL not path | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
( personal nitpick , this is also fine)
can make these one lines
i.e