Skip to content

Commit 4b7ef7d

Browse files
author
Ary Borenszweig
committedDec 4, 2016
Docs: show T | NIl as T? for types in addition to nodes
1 parent ecf01be commit 4b7ef7d

File tree

1 file changed

+16
-2
lines changed
  • src/compiler/crystal/tools/doc

1 file changed

+16
-2
lines changed
 

‎src/compiler/crystal/tools/doc/type.cr

+16-2
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,17 @@ class Crystal::Doc::Type
547547
end
548548
end
549549

550-
private def nilable_type_to_html(node, io, links)
550+
private def nilable_type_to_html(node : ASTNode, io, links)
551551
node_to_html node, io, links: links
552552
io << "?"
553553
end
554554

555-
private def nil_type?(node)
555+
private def nilable_type_to_html(type : Crystal::Type, io, text, links)
556+
type_to_html(type, io, text, links: links)
557+
io << "?"
558+
end
559+
560+
private def nil_type?(node : ASTNode)
556561
return false unless node.is_a?(Path)
557562

558563
match = lookup_path(node)
@@ -570,6 +575,15 @@ class Crystal::Doc::Type
570575

571576
def type_to_html(type : Crystal::UnionType, io, text = nil, links = true)
572577
has_type_splat = type.union_types.any? &.is_a?(TypeSplat)
578+
579+
if !has_type_splat && type.union_types.size == 2
580+
if type.union_types[0].nil_type?
581+
return nilable_type_to_html(type.union_types[1], io, text, links)
582+
elsif type.union_types[1].nil_type?
583+
return nilable_type_to_html(type.union_types[0], io, text, links)
584+
end
585+
end
586+
573587
if has_type_splat
574588
io << "Union("
575589
separator = ", "

0 commit comments

Comments
 (0)