diff --git a/test/SourceKit/CursorInfo/cursor_info_synthesized_refs.swift b/test/SourceKit/CursorInfo/cursor_info_synthesized_refs.swift new file mode 100644 index 0000000000000..bc13d438183d3 --- /dev/null +++ b/test/SourceKit/CursorInfo/cursor_info_synthesized_refs.swift @@ -0,0 +1,18 @@ +struct Foo { + let x: Int + let y: String + func perform(_ action: (Int, Int) -> ()) {} +} + +func test() { + let x = Foo.init(x: 2, y: "hello") + x.perform { + print($0 + $1) + } +} + +// RUN: %sourcekitd-test -req=cursor -pos=8:17 %s -- %s | %FileCheck -check-prefix=CHECK1 %s +// CHECK1: init(x: Int, y: String) + +// RUN: %sourcekitd-test -req=cursor -pos=10:15 %s -- %s | %FileCheck -check-prefix=CHECK2 %s +// CHECK2: let $0: Int diff --git a/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp b/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp index 0b24a343de4ec..96fcdf0b203f9 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp @@ -415,14 +415,13 @@ static void printAnnotatedDeclaration(const ValueDecl *VD, while (VD->isImplicit() && VD->getOverriddenDecl()) VD = VD->getOverriddenDecl(); - // If this is a property wrapper backing property (_foo) or projected value - // ($foo) and the wrapped property is not implicit, still print it. - if (auto *VarD = dyn_cast(VD)) { - if (auto *Wrapped = VarD->getOriginalWrappedProperty()) { - if (!Wrapped->isImplicit()) - PO.TreatAsExplicitDeclList.push_back(VD); - } - } + // VD may be a compiler synthesized member, constructor, or shorthand argument + // so always print it even if it's implicit. + // + // FIXME: Update PrintOptions::printQuickHelpDeclaration to print implicit + // decls by default. That causes issues due to newlines being printed before + // implicit OpaqueTypeDecls at time of writing. + PO.TreatAsExplicitDeclList.push_back(VD); // Wrap this up in XML, as that's what we'll use for documentation comments. OS<<""; @@ -446,14 +445,14 @@ void SwiftLangSupport::printFullyAnnotatedDeclaration(const ValueDecl *VD, while (VD->isImplicit() && VD->getOverriddenDecl()) VD = VD->getOverriddenDecl(); - // If this is a property wrapper backing property (_foo) or projected value - // ($foo) and the wrapped property is not implicit, still print it. - if (auto *VarD = dyn_cast(VD)) { - if (auto *Wrapped = VarD->getOriginalWrappedProperty()) { - if (!Wrapped->isImplicit()) - PO.TreatAsExplicitDeclList.push_back(VD); - } - } + // VD may be a compiler synthesized member, constructor, or shorthand argument + // so always print it even if it's implicit. + // + // FIXME: Update PrintOptions::printQuickHelpDeclaration to print implicit + // decls by default. That causes issues due to newlines being printed before + // implicit OpaqueTypeDecls at time of writing. + PO.TreatAsExplicitDeclList.push_back(VD); + VD->print(Printer, PO); }