Skip to content

Commit

Permalink
Update behavior of :showdoc: directive
Browse files Browse the repository at this point in the history
Using :showdoc: on a namespace does not apply to child methods / objects
  • Loading branch information
nobodywasishere committed Jan 21, 2025
1 parent d0d9ffd commit d9fa3d6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
16 changes: 5 additions & 11 deletions spec/compiler/crystal/tools/doc/directives_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe Crystal::Doc::Generator do
generator.must_include?(program.types["Foo"]).should be_false
end

it "shows all private and protected methods in a :showdoc: namespace" do
it "does not include documentation for private and protected methods and objects in a :showdoc: namespace" do
program = top_level_semantic(<<-CRYSTAL, wants_doc: true).program
# :showdoc:
class Foo
Expand All @@ -84,17 +84,11 @@ describe Crystal::Doc::Generator do
CRYSTAL

generator = Doc::Generator.new program, [""]
foo_def = generator.type(program.types["Foo"]).lookup_method("foo").not_nil!
foo_def.doc.should eq("Some docs for `foo`")
foo_def.visibility.should eq("private")

bar_def = generator.type(program.types["Foo"]).lookup_method("bar").not_nil!
bar_def.doc.should eq("Some docs for `bar`")
bar_def.visibility.should eq("protected")
generator.type(program.types["Foo"]).lookup_method("foo").should be_nil
generator.type(program.types["Foo"]).lookup_method("bar").should be_nil

baz_class = generator.type(program.types["Foo"]).lookup_path("Baz").not_nil!
baz_class.doc.should eq("Some docs for `Baz`")
baz_class.visibility.should eq("private")
generator.must_include?(generator.type(program.types["Foo"]).lookup_path("Baz")).should be_false
end

it "doesn't show a method marked :nodoc: within a :showdoc: namespace" do
Expand All @@ -103,7 +97,7 @@ describe Crystal::Doc::Generator do
class Foo
# :nodoc:
# Some docs for `foo`
private def foo
def foo
end
end
CRYSTAL
Expand Down
12 changes: 1 addition & 11 deletions src/compiler/crystal/tools/doc/generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,7 @@ class Crystal::Doc::Generator
end

def showdoc?(obj : Crystal::Type)
return false if !@program.wants_doc?

if showdoc?(obj.doc.try &.strip)
return true
end

obj.each_namespace do |ns|
return true if showdoc?(ns.doc.try &.strip)
end

false
showdoc?(obj.doc.try &.strip)
end

def crystal_builtin?(type)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/tools/doc/type.cr
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class Crystal::Doc::Type
end

private def showdoc?(adef)
@generator.showdoc?(adef.doc.try &.strip) || @generator.showdoc?(@type)
@generator.showdoc?(adef.doc.try &.strip)
end

private def sort_order(item)
Expand Down

0 comments on commit d9fa3d6

Please sign in to comment.