Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 98e8c6595cc9
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 28a6f06a4b5b
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Nov 22, 2016

  1. Fixed #3568: Doc generator doesn't take :: prefix into account

    Ary Borenszweig committed Nov 22, 2016
    4
    Copy the full SHA
    3797ef5 View commit details
  2. Docs: show T | Nil as T?

    Ary Borenszweig committed Nov 22, 2016
    4
    Copy the full SHA
    28a6f06 View commit details
Showing with 39 additions and 12 deletions.
  1. +39 −12 src/compiler/crystal/tools/doc/type.cr
51 changes: 39 additions & 12 deletions src/compiler/crystal/tools/doc/type.cr
Original file line number Diff line number Diff line change
@@ -469,19 +469,22 @@ class Crystal::Doc::Type
end

def node_to_html(node : Path, io, links = true)
# We don't want "::" prefixed in from of paths in the docs
old_global = node.global?
node.global = false

begin
match = lookup_path(node)
if match
type_to_html match, io, node.to_s, links: links
else
io << node
match = lookup_path(node)
if match
# If the path is global, search a local path and
# see if there's a different match. If not, we can safely
# remove the `::` as a prefix (harder to read)
remove_colons = false
if node.global?
node.global = false
remove_colons = lookup_path(node) == match
node.global = true unless remove_colons
end
ensure
node.global = old_global

type_to_html match, io, node.to_s, links: links
node.global = true if remove_colons
else
io << node
end
end

@@ -524,11 +527,33 @@ class Crystal::Doc::Type
end

def node_to_html(node : Union, io, links = true)
# See if it's a nilable type
if node.types.size == 2
# See if first type is Nil
if nil_type?(node.types[0])
return nilable_type_to_html node.types[1], io, links: links
elsif nil_type?(node.types[1])
return nilable_type_to_html node.types[0], io, links: links
end
end

node.types.join(" | ", io) do |elem|
node_to_html elem, io, links: links
end
end

private def nilable_type_to_html(node, io, links)
node_to_html node, io, links: links
io << "?"
end

private def nil_type?(node)
return false unless node.is_a?(Path)

match = lookup_path(node)
match && match.type == @generator.program.nil_type
end

def node_to_html(node, io, links = true)
io << node
end
@@ -685,4 +710,6 @@ class Crystal::Doc::Type
end
)
end

delegate to_s, inspect, to: @type
end