Skip to content

[SourceKit] for cursor-info request, printing underlying types instead of namelias type. rdar://28216890 #5339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 18, 2016
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
4 changes: 4 additions & 0 deletions include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ struct PrintOptions {
/// formatting.
bool PrintOriginalSourceText = false;

/// When printing a name alias type, whether print the underlying type instead
/// of the alias.
bool PrintNameAliasUnderlyingType = false;

/// \brief Print dependent types as references into this generic environment.
GenericEnvironment *GenericEnv = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3496,7 +3496,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
}

void visitNameAliasType(NameAliasType *T) {
if (Options.PrintForSIL) {
if (Options.PrintForSIL || Options.PrintNameAliasUnderlyingType) {
visit(T->getSinglyDesugaredType());
return;
}
Expand Down
44 changes: 44 additions & 0 deletions test/SourceKit/CursorInfo/cursor_info_type.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
protocol FancyProtocol {
associatedtype Thing
func holdPinkyUp(x: Thing)
}

struct Dashing: FancyProtocol {
func holdPinkyUp(x: String) { print("Dashing: \(x)") }
}
class AnyFancyBoxBase<T>: FancyProtocol {
func holdPinkyUp(x: T) {
//never called
fatalError()
}
}

final class _FancyBox<Base: FancyProtocol>: AnyFancyBoxBase<Base.Thing> {
var base: Base
init(_ base: Base) {
self.base = base
}
override func holdPinkyUp(x: Base.Thing) {
base.holdPinkyUp(x: x)
}
}

struct AnyFancy<T>: FancyProtocol {
var _box: AnyFancyBoxBase<T>
func holdPinkyUp(x: T) {
_box.holdPinkyUp(x: x)
}

init<U: FancyProtocol>(_ base: U) where U.Thing == T {
_box = _FancyBox(base)
}
}

let dashing = Dashing()
var anyFancy = AnyFancy(dashing)
print("\(type(of: anyFancy))")
anyFancy.holdPinkyUp(x: "")

// RUN: %sourcekitd-test -req=cursor -pos=40:3 %s -- %s | %FileCheck %s -check-prefix=CASE1

// CASE1: AnyFancy<String>
2 changes: 1 addition & 1 deletion test/SourceKit/Mixed/cursor_mixed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ func test(_ b : Base) {
// CHECK: source.lang.swift.ref.function.method.instance ({{.*}}Mixed.framework/Headers/Mixed.h:5:9-5:23)
// CHECK: doIt(_:)
// CHECK: c:objc(cs)Base(im)doIt:
// CHECK: (Base) -> (Int32) -> Void
// CHECK: (Base) -> (Int32) -> ()
// CHECK: Mixed
// CHECK: <Declaration>func doIt(_ arg: <Type usr="s:Vs5Int32">Int32</Type>)</Declaration>
2 changes: 1 addition & 1 deletion test/SourceKit/Mixed/cursor_mixed_header.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func test(_ b : BaseInHead) {
// CHECK: source.lang.swift.ref.function.method.instance ({{.*}}Inputs/header.h:4:9-4:23)
// CHECK: doIt(_:)
// CHECK: c:objc(cs)BaseInHead(im)doIt:
// CHECK: (BaseInHead) -> (Int32) -> Void
// CHECK: (BaseInHead) -> (Int32) -> ()
// CHECK: <Declaration>func doIt(_ arg: <Type usr="s:Vs5Int32">Int32</Type>)</Declaration>
4 changes: 3 additions & 1 deletion tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,9 @@ static bool passCursorInfoForDecl(const ValueDecl *VD,
unsigned TypenameBegin = SS.size();
if (VD->hasType()) {
llvm::raw_svector_ostream OS(SS);
VD->getInterfaceType().print(OS);
PrintOptions Options;
Options.PrintNameAliasUnderlyingType = true;
VD->getInterfaceType().print(OS, Options);
}
unsigned TypenameEnd = SS.size();

Expand Down