Skip to content

Commit a1f0155

Browse files
author
Nathan Hawes
committed
[SourceKit/CursorInfo] Still print implicit decls in cursorinfo to handle compiler synthesized decls
We weren't printing memberwise inits, shorthand arguments (e.g. $0, $1), and other implicit decls, so cursor info would give empty annotated decl and fully annotated decl fields for them. Resolves rdar://problem/58929991
1 parent 01e6cb3 commit a1f0155

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
struct Foo {
2+
let x: Int
3+
let y: String
4+
func perform(_ action: (Int, Int) -> ()) {}
5+
}
6+
7+
func test() {
8+
let x = Foo.init(x: 2, y: "hello")
9+
x.perform {
10+
print($0 + $1)
11+
}
12+
}
13+
14+
// RUN: %sourcekitd-test -req=cursor -pos=8:17 %s -- %s | %FileCheck -check-prefix=CHECK1 %s
15+
// CHECK1: <Declaration>init(x: <Type usr="s:Si">Int</Type>, y: <Type usr="s:SS">String</Type>)</Declaration>
16+
17+
// RUN: %sourcekitd-test -req=cursor -pos=10:15 %s -- %s | %FileCheck -check-prefix=CHECK2 %s
18+
// CHECK2: <Declaration>let $0: <Type usr="s:Si">Int</Type></Declaration>

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,13 @@ static void printAnnotatedDeclaration(const ValueDecl *VD,
415415
while (VD->isImplicit() && VD->getOverriddenDecl())
416416
VD = VD->getOverriddenDecl();
417417

418-
// If this is a property wrapper backing property (_foo) or projected value
419-
// ($foo) and the wrapped property is not implicit, still print it.
420-
if (auto *VarD = dyn_cast<VarDecl>(VD)) {
421-
if (auto *Wrapped = VarD->getOriginalWrappedProperty()) {
422-
if (!Wrapped->isImplicit())
423-
PO.TreatAsExplicitDeclList.push_back(VD);
424-
}
425-
}
418+
// VD may be a compiler synthesized member, constructor, or shorthand argument
419+
// so always print it even if it's implicit.
420+
//
421+
// FIXME: Update PrintOptions::printQuickHelpDeclaration to print implicit
422+
// decls by default. That causes issues due to newlines being printed before
423+
// implicit OpaqueTypeDecls at time of writing.
424+
PO.TreatAsExplicitDeclList.push_back(VD);
426425

427426
// Wrap this up in XML, as that's what we'll use for documentation comments.
428427
OS<<"<Declaration>";
@@ -446,14 +445,14 @@ void SwiftLangSupport::printFullyAnnotatedDeclaration(const ValueDecl *VD,
446445
while (VD->isImplicit() && VD->getOverriddenDecl())
447446
VD = VD->getOverriddenDecl();
448447

449-
// If this is a property wrapper backing property (_foo) or projected value
450-
// ($foo) and the wrapped property is not implicit, still print it.
451-
if (auto *VarD = dyn_cast<VarDecl>(VD)) {
452-
if (auto *Wrapped = VarD->getOriginalWrappedProperty()) {
453-
if (!Wrapped->isImplicit())
454-
PO.TreatAsExplicitDeclList.push_back(VD);
455-
}
456-
}
448+
// VD may be a compiler synthesized member, constructor, or shorthand argument
449+
// so always print it even if it's implicit.
450+
//
451+
// FIXME: Update PrintOptions::printQuickHelpDeclaration to print implicit
452+
// decls by default. That causes issues due to newlines being printed before
453+
// implicit OpaqueTypeDecls at time of writing.
454+
PO.TreatAsExplicitDeclList.push_back(VD);
455+
457456
VD->print(Printer, PO);
458457
}
459458

0 commit comments

Comments
 (0)