Skip to content

Commit b0d2f94

Browse files
authored
Fix some doc inconsistencies for macros (#16561)
1 parent b1b016a commit b0d2f94

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

spec/compiler/crystal/tools/doc/directives_spec.cr

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ describe Crystal::Doc::Generator do
4747
a_def.visibility.should eq("private")
4848
end
4949

50+
it "shows documentation for private macros" do
51+
program = top_level_semantic(<<-CRYSTAL, wants_doc: true).program
52+
class Foo
53+
# :showdoc:
54+
#
55+
# Some docs
56+
private macro foo
57+
end
58+
end
59+
CRYSTAL
60+
61+
generator = Doc::Generator.new program, [""]
62+
a_macro = generator.type(program.types["Foo"]).lookup_macro("foo").not_nil!
63+
a_macro.doc.should eq("Some docs")
64+
a_macro.visibility.should eq("private")
65+
end
66+
5067
it "shows documentation for nested objects if a lib is marked with :showdoc:" do
5168
program = top_level_semantic(<<-CRYSTAL, wants_doc: true).program
5269
# :showdoc:

src/compiler/crystal/tools/doc/macro.cr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Crystal::Doc::Macro
2020
end
2121

2222
def doc
23-
@macro.doc
23+
@macro.doc.try &.strip.lchop(":showdoc:").strip
2424
end
2525

2626
def doc_copied_from
@@ -55,7 +55,13 @@ class Crystal::Doc::Macro
5555
end
5656

5757
def visibility
58-
@type.visibility
58+
case @macro.visibility
59+
in .public?
60+
in .protected?
61+
"protected"
62+
in .private?
63+
"private"
64+
end
5965
end
6066

6167
def real_name

0 commit comments

Comments
 (0)