@@ -115,6 +115,11 @@ prettyName n =
115
115
let root = nameRoot n in
116
116
if isOpName n then parens (pretty root) else pretty root
117
117
118
+ prettyKindedName : Maybe String -> Doc IdrisDocAnn -> Doc IdrisDocAnn
119
+ prettyKindedName Nothing nm = nm
120
+ prettyKindedName (Just kw) nm
121
+ = annotate (Syntax $ SynDecor Keyword ) (pretty kw) <++> nm
122
+
118
123
export
119
124
getDocsForPrimitive : {auto c : Ref Ctxt Defs} ->
120
125
{auto s : Ref Syn SyntaxInfo} ->
@@ -284,61 +289,76 @@ getDocsForName fc n
284
289
]
285
290
_ => pure projDecl
286
291
287
- getFieldsDoc : Name -> Core (List (Doc IdrisDocAnn))
292
+ getFieldsDoc : Name -> Core (Maybe (Doc IdrisDocAnn))
288
293
getFieldsDoc recName
289
294
= do let (Just ns, n) = displayName recName
290
- | _ => pure []
295
+ | _ => pure Nothing
291
296
let recNS = ns <.> mkNamespace n
292
297
defs <- get Ctxt
293
298
let fields = getFieldNames (gamma defs) recNS
294
299
syn <- get Syn
295
300
case fields of
296
- [] => pure []
297
- [proj] => pure [header " Projection" <++> annotate Declarations ! (getFieldDoc proj)]
298
- projs => pure [vcat [header " Projections"
299
- , annotate Declarations $
300
- vcat $ map (indent 2 ) $ ! (traverse getFieldDoc projs)]]
301
-
302
- getExtra : Name -> GlobalDef -> Core (List (Doc IdrisDocAnn))
301
+ [] => pure Nothing
302
+ [proj] => pure $ Just $ header " Projection" <++> annotate Declarations ! (getFieldDoc proj)
303
+ projs => pure $ Just $ vcat
304
+ [ header " Projections"
305
+ , annotate Declarations $ vcat $
306
+ map (indent 2 ) $ ! (traverse getFieldDoc projs)
307
+ ]
308
+
309
+ getExtra : Name -> GlobalDef -> Core (Maybe String, List (Doc IdrisDocAnn))
303
310
getExtra n d = do
304
311
do syn <- get Syn
305
312
let [] = lookupName n (ifaces syn)
306
- | [ifacedata] => pure <$> getIFaceDoc ifacedata
307
- | _ => pure [] -- shouldn't happen, we've resolved ambiguity by now
313
+ | [ifacedata] => ( Just " interface " ,) . pure <$> getIFaceDoc ifacedata
314
+ | _ => pure ( Nothing , []) -- shouldn't happen, we've resolved ambiguity by now
308
315
case definition d of
309
- PMDef _ _ _ _ _ => pure [showTotal n (totality d)]
316
+ PMDef _ _ _ _ _ => pure ( Nothing , [showTotal n (totality d)])
310
317
TCon _ _ _ _ _ _ cons _ =>
311
318
do let tot = [showTotal n (totality d)]
312
319
cdocs <- traverse (getDConDoc <=< toFullNames) cons
313
320
cdoc <- case cdocs of
314
- [] => pure []
315
- [doc] => pure
316
- $ (header " Constructor" <++> annotate Declarations doc)
317
- :: ! (getFieldsDoc n)
318
- docs => pure [vcat [header " Constructors"
319
- , annotate Declarations $
320
- vcat $ map (indent 2 ) docs]]
321
- pure (tot ++ cdoc)
322
- _ => pure []
321
+ [] => pure (Just " data" , [])
322
+ [doc] =>
323
+ let cdoc = header " Constructor" <++> annotate Declarations doc in
324
+ case ! (getFieldsDoc n) of
325
+ Nothing => pure (Just " data" , [cdoc])
326
+ Just fs => pure (Just " record" , cdoc :: [fs])
327
+ docs => pure (Just " data"
328
+ , [vcat [header " Constructors"
329
+ , annotate Declarations $
330
+ vcat $ map (indent 2 ) docs]])
331
+ pure (map (tot ++ ) cdoc)
332
+ _ => pure (Nothing , [])
323
333
324
334
showDoc (MkConfig {longNames, dropFirst, getTotality}) (n, str)
325
335
= do defs <- get Ctxt
326
336
Just def <- lookupCtxtExact n (gamma defs)
327
337
| Nothing => undefinedName fc n
338
+ -- First get the extra stuff because this also tells us whether a
339
+ -- definition is `data`, `record`, or `interface`.
340
+ (typ, extra) <- ifThenElse getTotality
341
+ (getExtra n def)
342
+ (pure (Nothing , []))
343
+
344
+ -- Then form the type declaration
328
345
ty <- resugar [] =<< normaliseHoles defs [] (type def)
329
346
-- when printing e.g. interface methods there is no point in
330
347
-- repeating the interface's name
331
348
let ty = ifThenElse (not dropFirst) ty $ case ty of
332
349
PPi _ _ AutoImplicit _ _ sc => sc
333
350
_ => ty
334
- let cat = showCategory def
335
351
nm <- aliasName n
336
352
-- when printing e.g. interface methods there is no point in
337
353
-- repeating the namespace the interface lives in
338
- let nm = if longNames then pretty (show nm) else prettyName nm
339
- let docDecl = annotate (Decl n) (hsep [cat nm, colon, prettyTerm ty])
354
+ let cat = showCategory def
355
+ let nm = ifThenElse longNames
356
+ (prettyKindedName typ $ cat $ pretty (show nm))
357
+ (cat $ prettyName nm)
358
+ let docDecl = annotate (Decl n) (hsep [nm, colon, prettyTerm ty])
359
+
360
+ -- Finally add the user-provided docstring
340
361
let docText = reflowDoc str
341
- extra <- ifThenElse getTotality (getExtra n def) (pure [])
342
362
fixes <- getFixityDoc n
343
363
let docBody = annotate DocStringBody $ vcat $ docText ++ (map (indent 2 ) (extra ++ fixes))
344
364
pure (vcat [docDecl, docBody])
0 commit comments