Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions spec/compiler/semantic/doc_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -632,5 +632,47 @@ describe "Semantic: doc" do
type = program.lookup_macros("foo").as(Array(Macro)).first
type.doc.should eq("Some description")
end

it "attached to macro call" do
result = semantic %(
annotation Ann
end

macro gen_type
class Foo; end
end

# Some description
@[Ann]
gen_type
), wants_doc: true
program = result.program
type = program.types["Foo"]
type.doc.should eq("Some description")
end

it "attached to macro call that produces multiple types" do
result = semantic %(
annotation Ann
end

class Foo
macro getter(decl)
@{{decl.var.id}} : {{decl.type.id}}

def {{decl.var.id}} : {{decl.type.id}}
@{{decl.var.id}}
end
end

# Some description
@[Ann]
getter name : String?
end
), wants_doc: true
program = result.program
a_def = program.types["Foo"].lookup_defs("name").first
a_def.doc.should eq("Some description")
end
end
end
6 changes: 6 additions & 0 deletions src/compiler/crystal/semantic/semantic_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor
visibility: visibility,
)

node.doc ||= annotations_doc @annotations

if node_doc = node.doc
generated_nodes.accept PropagateDocVisitor.new(node_doc)
end
Expand Down Expand Up @@ -525,6 +527,10 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor
end
end

private def annotations_doc(annotations)
annotations.try(&.first?).try &.doc
end

def check_class_var_annotations
thread_local = false
process_annotations(@annotations) do |annotation_type, ann|
Expand Down