<commit_before>-----------------------------------------------------------------------------
-- |
-- Module      :  Haddock.Backends.Html.Names
-- Copyright   :  (c) <NAME>   2003-2006,
--                    <NAME>    2006-2009,
--                    <NAME> 2010
-- License     :  BSD-like
--
-- Maintainer  :  <EMAIL>
-- Stability   :  experimental
-- Portability :  portable
-----------------------------------------------------------------------------
module Haddock.Backends.Xhtml.Names (
  ppName, ppDocName, ppLDocName, ppRdrName,
  ppBinder, ppBinder',
  ppModule, ppModuleRef,
  linkId
) where


import Haddock.Backends.Xhtml.Utils
import Haddock.GhcUtils
import Haddock.Types
import Haddock.Utils

import Text.XHtml hiding ( name, title, p, quote )
import qualified Data.List as List

import GHC
import Name
import RdrName


ppOccName :: OccName -> Html
ppOccName = toHtml . occNameString


ppRdrName :: RdrName -> Html
ppRdrName = ppOccName . rdrNameOcc


ppLDocName :: Qualification -> Located DocName -> Html
ppLDocName qual (L _ d) = ppDocName qual d


-- | Render a name depending on the selected qualification mode
qualifyName :: Qualification -> DocName -> Html
qualifyName qual docName@(Documented name mdl) = case qual of
    NoQual   -> ppName name
    FullQual -> ppFullQualName mdl name
    -- this is just in case, it should never happen
    LocalQual Nothing -> qualifyName FullQual docName
    LocalQual (Just localmdl)
      | moduleString mdl == moduleString localmdl -> ppName name
      | otherwise -> ppFullQualName mdl name
    -- again, this never happens
    RelativeQual Nothing -> qualifyName FullQual docName
    RelativeQual (Just localmdl) ->
        case List.stripPrefix (moduleString localmdl) (moduleString mdl) of
            -- local, A.x -> x
            Just []      -> qualifyName NoQual docName
            -- sub-module, A.B.x -> B.x
            Just ('.':m) -> toHtml $ m ++ '.' : getOccString name
            -- some module with same prefix, ABC.x -> ABC.x
            Just _       -> qualifyName FullQual docName
            -- some other module, D.x -> D.x
            Nothing      -> qualifyName FullQual docName

-- this is just for exhaustiveness, but already handled by ppDocName
qualifyName _ (Undocumented name) = ppName name


ppDocName :: Qualification -> DocName -> Html
ppDocName qual docName@(Documented name mdl) =
  linkIdOcc mdl (Just occName) << qualifyName qual docName
    where occName = nameOccName name

ppDocName _ (Undocumented name) = ppName name


ppFullQualName :: Module -> Name -> Html
ppFullQualName mdl name = toHtml $ moduleString mdl ++ '.' : getOccString name


ppName :: Name -> Html
ppName name = toHtml (getOccString name)


ppBinder :: Bool -> OccName -> Html
-- The Bool indicates whether we are generating the summary, in which case
-- the binder will be a link to the full definition.
ppBinder True n = linkedAnchor (nameAnchorId n) << ppBinder' n
ppBinder False n = namedAnchor (nameAnchorId n) ! [theclass "def"]
                        << ppBinder' n


ppBinder' :: OccName -> Html
ppBinder' n
  | isVarSym n = parens $ ppOccName n
  | otherwise  = ppOccName n


linkId :: Module -> Maybe Name -> Html -> Html
linkId mdl mbName = linkIdOcc mdl (fmap nameOccName mbName)


linkIdOcc :: Module -> Maybe OccName -> Html -> Html
linkIdOcc mdl mbName = anchor ! [href url]
  where
    url = case mbName of
      Nothing   -> moduleUrl mdl
      Just name -> moduleNameUrl mdl name


ppModule :: Module -> Html
ppModule mdl = anchor ! [href (moduleUrl mdl)]
               << toHtml (moduleString mdl)


ppModuleRef :: Module -> String -> Html
ppModuleRef mdl ref = anchor ! [href (moduleUrl mdl ++ ref)]
                      << toHtml (moduleString mdl)
    -- NB: The ref parameter already includes the '#'.
    -- This function is only called from markupModule expanding a
    -- DocModule, which doesn't seem to be ever be used.
<commit_msg>add full qualification for undocumented names<commit_after>-----------------------------------------------------------------------------
-- |
-- Module      :  Haddock.Backends.Html.Names
-- Copyright   :  (c) <NAME>   2003-2006,
--                    <NAME>    2006-2009,
--                    <NAME> 2010
-- License     :  BSD-like
--
-- Maintainer  :  <EMAIL>
-- Stability   :  experimental
-- Portability :  portable
-----------------------------------------------------------------------------
module Haddock.Backends.Xhtml.Names (
  ppName, ppDocName, ppLDocName, ppRdrName,
  ppBinder, ppBinder',
  ppModule, ppModuleRef,
  linkId
) where


import Haddock.Backends.Xhtml.Utils
import Haddock.GhcUtils
import Haddock.Types
import Haddock.Utils

import Text.XHtml hiding ( name, title, p, quote )
import qualified Data.List as List

import GHC
import Name
import RdrName


ppOccName :: OccName -> Html
ppOccName = toHtml . occNameString


ppRdrName :: RdrName -> Html
ppRdrName = ppOccName . rdrNameOcc


ppLDocName :: Qualification -> Located DocName -> Html
ppLDocName qual (L _ d) = ppDocName qual d


-- | Render a name depending on the selected qualification mode
qualifyName :: Qualification -> DocName -> Html
qualifyName qual docName@(Documented name mdl) = case qual of
    NoQual   -> ppName name
    FullQual -> ppFullQualName mdl name
    -- this is just in case, it should never happen
    LocalQual Nothing -> qualifyName FullQual docName
    LocalQual (Just localmdl)
      | moduleString mdl == moduleString localmdl -> ppName name
      | otherwise -> ppFullQualName mdl name
    -- again, this never happens
    RelativeQual Nothing -> qualifyName FullQual docName
    RelativeQual (Just localmdl) ->
        case List.stripPrefix (moduleString localmdl) (moduleString mdl) of
            -- local, A.x -> x
            Just []      -> qualifyName NoQual docName
            -- sub-module, A.B.x -> B.x
            Just ('.':m) -> toHtml $ m ++ '.' : getOccString name
            -- some module with same prefix, ABC.x -> ABC.x
            Just _       -> qualifyName FullQual docName
            -- some other module, D.x -> D.x
            Nothing      -> qualifyName FullQual docName

qualifyName qual (Undocumented name) = qualifyName qual (Documented name (nameModule name))


ppDocName :: Qualification -> DocName -> Html
ppDocName qual docName@(Documented name mdl) =
  linkIdOcc mdl (Just occName) << qualifyName qual docName
    where occName = nameOccName name

ppDocName qual docName@(Undocumented name) = qualifyName qual docName


ppFullQualName :: Module -> Name -> Html
ppFullQualName mdl name = toHtml $ moduleString mdl ++ '.' : getOccString name


ppName :: Name -> Html
ppName name = toHtml (getOccString name)


ppBinder :: Bool -> OccName -> Html
-- The Bool indicates whether we are generating the summary, in which case
-- the binder will be a link to the full definition.
ppBinder True n = linkedAnchor (nameAnchorId n) << ppBinder' n
ppBinder False n = namedAnchor (nameAnchorId n) ! [theclass "def"]
                        << ppBinder' n


ppBinder' :: OccName -> Html
ppBinder' n
  | isVarSym n = parens $ ppOccName n
  | otherwise  = ppOccName n


linkId :: Module -> Maybe Name -> Html -> Html
linkId mdl mbName = linkIdOcc mdl (fmap nameOccName mbName)


linkIdOcc :: Module -> Maybe OccName -> Html -> Html
linkIdOcc mdl mbName = anchor ! [href url]
  where
    url = case mbName of
      Nothing   -> moduleUrl mdl
      Just name -> moduleNameUrl mdl name


ppModule :: Module -> Html
ppModule mdl = anchor ! [href (moduleUrl mdl)]
               << toHtml (moduleString mdl)


ppModuleRef :: Module -> String -> Html
ppModuleRef mdl ref = anchor ! [href (moduleUrl mdl ++ ref)]
                      << toHtml (moduleString mdl)
    -- NB: The ref parameter already includes the '#'.
    -- This function is only called from markupModule expanding a
    -- DocModule, which doesn't seem to be ever be used.

{'fraction_non_alphanumeric': 0.1285913175547399, 'fraction_numerical': 0.005062650297430705, 'mean_word_length': 2.3313659359190555, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7373298', 'n_tokens_mistral': 2365, 'n_tokens_neox': 2277, 'n_words': 800}