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

diff --git a/include/swift/AST/PrintOptions.h b/include/swift/AST/PrintOptions.h
index 7f8425c..10a29f8 100644
--- a/include/swift/AST/PrintOptions.h
+++ b/include/swift/AST/PrintOptions.h
@@ -327,6 +327,10 @@
   /// 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;
 
diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp
index 4cdb4e7..5c3654d 100644
--- a/lib/AST/ASTPrinter.cpp
+++ b/lib/AST/ASTPrinter.cpp
@@ -3496,7 +3496,7 @@
   }
 
   void visitNameAliasType(NameAliasType *T) {
-    if (Options.PrintForSIL) {
+    if (Options.PrintForSIL || Options.PrintNameAliasUnderlyingType) {
       visit(T->getSinglyDesugaredType());
       return;
     }
diff --git a/test/SourceKit/CursorInfo/cursor_info_type.swift b/test/SourceKit/CursorInfo/cursor_info_type.swift
new file mode 100644
index 0000000..f9e6b38
--- /dev/null
+++ b/test/SourceKit/CursorInfo/cursor_info_type.swift
@@ -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>
diff --git a/test/SourceKit/Mixed/cursor_mixed.swift b/test/SourceKit/Mixed/cursor_mixed.swift
index c159494..021178d 100644
--- a/test/SourceKit/Mixed/cursor_mixed.swift
+++ b/test/SourceKit/Mixed/cursor_mixed.swift
@@ -9,6 +9,6 @@
 // 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>
diff --git a/test/SourceKit/Mixed/cursor_mixed_header.swift b/test/SourceKit/Mixed/cursor_mixed_header.swift
index 30fde8c..add758e 100644
--- a/test/SourceKit/Mixed/cursor_mixed_header.swift
+++ b/test/SourceKit/Mixed/cursor_mixed_header.swift
@@ -13,5 +13,5 @@
 // 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>
diff --git a/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp b/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
index a7464d0..8e37dd2 100644
--- a/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
+++ b/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
@@ -644,7 +644,9 @@
   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();