Skip to content

Commit b3a508d

Browse files
Prettify hover response
Makes symbol name the same size as the rest of text, and puts a dividing line between declaration and the rest of the documentation. It makes the output similar to other language servers (dart, typescript, C)
1 parent bf8a1c2 commit b3a508d

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

Sources/SourceKit/sourcekitd/CommentXML.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ private struct XMLToMarkdown {
7777
newlineIfNeeded(count: 2)
7878
out += "```\n"
7979
toMarkdown(node.children)
80-
out += "\n```"
81-
80+
out += "\n```\n\n---\n"
81+
8282
case "Name", "USR", "Direction":
8383
break
8484

Sources/SourceKit/sourcekitd/SwiftLanguageServer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ extension SwiftLanguageServer {
624624
return String(str.flatMap({ ($0 == "*" || $0 == "_") ? ["\\", $0] : [$0] }))
625625
}
626626

627-
var result = "# \(escapeNameMarkdown(name))"
627+
var result = escapeNameMarkdown(name)
628628
if let doc = cursorInfo.documentationXML {
629629
result += """
630630

Tests/SourceKitTests/LocalSwiftTests.swift

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,20 +787,29 @@ final class LocalSwiftTests: XCTestCase {
787787
```
788788
func foo(_ bar: Baz)
789789
```
790+
791+
---
792+
790793
""")
791794
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
792795
<Declaration>func foo() -&gt; <Type>Bar</Type></Declaration>
793796
"""), """
794797
```
795798
func foo() -> Bar
796799
```
800+
801+
---
802+
797803
""")
798804
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
799805
<Declaration>func replacingOccurrences&lt;Target, Replacement&gt;(of target: Target, with replacement: Replacement, options: <Type usr="s:SS">String</Type>.<Type usr="s:SS10FoundationE14CompareOptionsa">CompareOptions</Type> = default, range searchRange: <Type usr="s:Sn">Range</Type>&lt;<Type usr="s:SS">String</Type>.<Type usr="s:SS5IndexV">Index</Type>&gt;? = default) -&gt; <Type usr="s:SS">String</Type> where Target : <Type usr="s:Sy">StringProtocol</Type>, Replacement : <Type usr="s:Sy">StringProtocol</Type></Declaration>
800806
"""), """
801807
```
802808
func replacingOccurrences<Target, Replacement>(of target: Target, with replacement: Replacement, options: String.CompareOptions = default, range searchRange: Range<String.Index>? = default) -> String where Target : StringProtocol, Replacement : StringProtocol
803809
```
810+
811+
---
812+
804813
""")
805814
}
806815

@@ -811,6 +820,9 @@ final class LocalSwiftTests: XCTestCase {
811820
```
812821
var foo
813822
```
823+
824+
---
825+
814826
""")
815827

816828
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
@@ -819,13 +831,19 @@ final class LocalSwiftTests: XCTestCase {
819831
```
820832
var foo
821833
```
834+
835+
---
836+
822837
""")
823838
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
824839
<Class><USR>asdf</USR><Declaration>var foo</Declaration><Name>foo</Name></Class>
825840
"""), """
826841
```
827842
var foo
828843
```
844+
845+
---
846+
829847
""")
830848

831849
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
@@ -841,6 +859,9 @@ final class LocalSwiftTests: XCTestCase {
841859
```
842860
var foo
843861
```
862+
863+
---
864+
844865
""")
845866

846867
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
@@ -970,6 +991,7 @@ final class LocalSwiftTests: XCTestCase {
970991
struct String
971992
```
972993
994+
---
973995
A Unicode s
974996
975997
### Discussion
@@ -1135,11 +1157,12 @@ final class LocalSwiftTests: XCTestCase {
11351157
}
11361158
XCTAssertEqual(content.kind, .markdown)
11371159
XCTAssertEqual(content.value, """
1138-
# S
1160+
S
11391161
```
11401162
struct S
11411163
```
11421164
1165+
---
11431166
This is a doc comment for S.
11441167
11451168
### Discussion
@@ -1186,11 +1209,12 @@ final class LocalSwiftTests: XCTestCase {
11861209
}
11871210
XCTAssertEqual(content.kind, .markdown)
11881211
XCTAssertEqual(content.value, ##"""
1189-
# test(\_:\_:)
1212+
test(\_:\_:)
11901213
```
11911214
func test(_ a: Int, _ b: Int)
11921215
```
11931216
1217+
---
11941218
this is **bold** documentation
11951219
"""##)
11961220
}
@@ -1210,11 +1234,12 @@ final class LocalSwiftTests: XCTestCase {
12101234
}
12111235
XCTAssertEqual(content.kind, .markdown)
12121236
XCTAssertEqual(content.value, ##"""
1213-
# \*%\*(\_:\_:)
1237+
\*%\*(\_:\_:)
12141238
```
12151239
func *%* (lhs: String, rhs: String)
12161240
```
12171241
1242+
---
12181243
this is *italic* documentation
12191244
"""##)
12201245
}

0 commit comments

Comments
 (0)