... |
... |
@@ -15,7 +15,7 @@ import GHC.Iface.Ext.Utils (emptyNodeInfo, isEvidenceContext) |
15
|
15
|
import GHC.Types.Name (Name, getOccString, isInternalName, nameModule, nameUnique)
|
16
|
16
|
import GHC.Types.SrcLoc
|
17
|
17
|
import GHC.Types.Unique (getKey)
|
18
|
|
-import GHC.Unit.Module (ModuleName, moduleNameString)
|
|
18
|
+import GHC.Unit.Module (Module, ModuleName, moduleNameString)
|
19
|
19
|
import GHC.Utils.Encoding (utf8DecodeByteString)
|
20
|
20
|
import System.FilePath.Posix ((</>))
|
21
|
21
|
import Text.XHtml (Html, HtmlAttr, (!))
|
... |
... |
@@ -28,7 +28,9 @@ type StyleClass = String |
28
|
28
|
|
29
|
29
|
-- | Produce the HTML corresponding to a hyperlinked Haskell source
|
30
|
30
|
render
|
31
|
|
- :: Maybe FilePath
|
|
31
|
+ :: Module
|
|
32
|
+ -- ^ this module
|
|
33
|
+ -> Maybe FilePath
|
32
|
34
|
-- ^ path to the CSS file
|
33
|
35
|
-> Maybe FilePath
|
34
|
36
|
-- ^ path to the JS file
|
... |
... |
@@ -39,12 +41,12 @@ render |
39
|
41
|
-> [Token]
|
40
|
42
|
-- ^ tokens to render
|
41
|
43
|
-> Html
|
42
|
|
-render mcss mjs srcs ast tokens = header mcss mjs <> body srcs ast tokens
|
|
44
|
+render thisModule mcss mjs srcs ast tokens = header mcss mjs <> body thisModule srcs ast tokens
|
43
|
45
|
|
44
|
|
-body :: SrcMaps -> HieAST PrintedType -> [Token] -> Html
|
45
|
|
-body srcs ast tokens = Html.body . Html.pre $ hypsrc
|
|
46
|
+body :: Module -> SrcMaps -> HieAST PrintedType -> [Token] -> Html
|
|
47
|
+body thisModule srcs ast tokens = Html.body . Html.pre $ hypsrc
|
46
|
48
|
where
|
47
|
|
- hypsrc = renderWithAst srcs ast tokens
|
|
49
|
+ hypsrc = renderWithAst thisModule srcs ast tokens
|
48
|
50
|
|
49
|
51
|
header :: Maybe FilePath -> Maybe FilePath -> Html
|
50
|
52
|
header Nothing Nothing = Html.noHtml
|
... |
... |
@@ -75,9 +77,9 @@ splitTokens ast toks = (before, during, after) |
75
|
77
|
|
76
|
78
|
-- | Turn a list of tokens into hyperlinked sources, threading in relevant link
|
77
|
79
|
-- information from the 'HieAST'.
|
78
|
|
-renderWithAst :: SrcMaps -> HieAST PrintedType -> [Token] -> Html
|
79
|
|
-renderWithAst srcs Node{..} toks = anchored $ case toks of
|
80
|
|
- [tok] | nodeSpan == tkSpan tok -> richToken srcs nodeInfo tok
|
|
80
|
+renderWithAst :: Module -> SrcMaps -> HieAST PrintedType -> [Token] -> Html
|
|
81
|
+renderWithAst thisModule srcs Node{..} toks = anchored $ case toks of
|
|
82
|
+ [tok] | nodeSpan == tkSpan tok -> richToken thisModule srcs nodeInfo tok
|
81
|
83
|
-- NB: the GHC lexer lexes backquoted identifiers and parenthesized operators
|
82
|
84
|
-- as multiple tokens.
|
83
|
85
|
--
|
... |
... |
@@ -92,6 +94,7 @@ renderWithAst srcs Node{..} toks = anchored $ case toks of |
92
|
94
|
| realSrcSpanStart s1 == realSrcSpanStart nodeSpan
|
93
|
95
|
, realSrcSpanEnd s2 == realSrcSpanEnd nodeSpan ->
|
94
|
96
|
richToken
|
|
97
|
+ thisModule
|
95
|
98
|
srcs
|
96
|
99
|
nodeInfo
|
97
|
100
|
( Token
|
... |
... |
@@ -104,6 +107,7 @@ renderWithAst srcs Node{..} toks = anchored $ case toks of |
104
|
107
|
| realSrcSpanStart s1 == realSrcSpanStart nodeSpan
|
105
|
108
|
, realSrcSpanEnd s2 == realSrcSpanEnd nodeSpan ->
|
106
|
109
|
richToken
|
|
110
|
+ thisModule
|
107
|
111
|
srcs
|
108
|
112
|
nodeInfo
|
109
|
113
|
( Token
|
... |
... |
@@ -118,7 +122,7 @@ renderWithAst srcs Node{..} toks = anchored $ case toks of |
118
|
122
|
go _ [] = mempty
|
119
|
123
|
go [] xs = foldMap renderToken xs
|
120
|
124
|
go (cur : rest) xs =
|
121
|
|
- foldMap renderToken before <> renderWithAst srcs cur during <> go rest after
|
|
125
|
+ foldMap renderToken before <> renderWithAst thisModule srcs cur during <> go rest after
|
122
|
126
|
where
|
123
|
127
|
(before, during, after) = splitTokens cur xs
|
124
|
128
|
anchored c = Map.foldrWithKey anchorOne c (nodeIdentifiers nodeInfo)
|
... |
... |
@@ -137,8 +141,8 @@ renderToken Token{..} |
137
|
141
|
tokenSpan = Html.thespan (Html.toHtml tkValue')
|
138
|
142
|
|
139
|
143
|
-- | Given information about the source position of definitions, render a token
|
140
|
|
-richToken :: SrcMaps -> NodeInfo PrintedType -> Token -> Html
|
141
|
|
-richToken srcs details Token{..}
|
|
144
|
+richToken :: Module -> SrcMaps -> NodeInfo PrintedType -> Token -> Html
|
|
145
|
+richToken thisModule srcs details Token{..}
|
142
|
146
|
| tkType == TkSpace = renderSpace (srcSpanStartLine tkSpan) tkValue'
|
143
|
147
|
| otherwise = annotate details $ linked content
|
144
|
148
|
where
|
... |
... |
@@ -155,7 +159,7 @@ richToken srcs details Token{..} |
155
|
159
|
|
156
|
160
|
-- If we have name information, we can make links
|
157
|
161
|
linked = case identDet of
|
158
|
|
- Just (n, _) -> hyperlink srcs n
|
|
162
|
+ Just (n, _) -> hyperlink thisModule srcs n
|
159
|
163
|
Nothing -> id
|
160
|
164
|
|
161
|
165
|
-- | Remove CRLFs from source
|
... |
... |
@@ -253,8 +257,8 @@ internalAnchorIdent :: Name -> String |
253
|
257
|
internalAnchorIdent = ("local-" ++) . show . getKey . nameUnique
|
254
|
258
|
|
255
|
259
|
-- | Generate the HTML hyperlink for an identifier
|
256
|
|
-hyperlink :: SrcMaps -> Identifier -> Html -> Html
|
257
|
|
-hyperlink (srcs, srcs') ident = case ident of
|
|
260
|
+hyperlink :: Module -> SrcMaps -> Identifier -> Html -> Html
|
|
261
|
+hyperlink thisModule (srcs, srcs') ident = case ident of
|
258
|
262
|
Right name
|
259
|
263
|
| isInternalName name -> internalHyperlink name
|
260
|
264
|
| otherwise -> externalNameHyperlink name
|
... |
... |
@@ -270,7 +274,7 @@ hyperlink (srcs, srcs') ident = case ident of |
270
|
274
|
externalNameHyperlink name content = case Map.lookup mdl srcs of
|
271
|
275
|
Just SrcLocal ->
|
272
|
276
|
Html.anchor content
|
273
|
|
- ! [Html.href $ hypSrcModuleNameUrl mdl name]
|
|
277
|
+ ! [Html.href $ hypSrcModuleNameUrl' thisModule mdl name]
|
274
|
278
|
Just (SrcExternal path) ->
|
275
|
279
|
let hyperlinkUrl = hypSrcModuleUrlToNameFormat $ makeHyperlinkUrl path
|
276
|
280
|
in Html.anchor content
|