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