Skip to content

Commit efb5adf

Browse files
authored
Merge pull request #415 from LebJe/docCommentSyntaxHighlighting
Add syntax highlighting to the code blocks in the markdown returned by SourceKit.
2 parents 13d3d93 + 06d8627 commit efb5adf

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

Sources/SourceKitLSP/Swift/CommentXML.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private struct XMLToMarkdown {
7575
switch node.name {
7676
case "Declaration":
7777
newlineIfNeeded(count: 2)
78-
out += "```\n"
78+
out += "```swift\n"
7979
toMarkdown(node.children)
8080
out += "\n```\n\n---\n"
8181

@@ -125,7 +125,7 @@ private struct XMLToMarkdown {
125125
case "CodeListing":
126126
lineNumber = 0
127127
newlineIfNeeded(count: 2)
128-
out += "```\n"
128+
out += "```\(node.attributes?.first(where: { $0.name == "language" })?.stringValue ?? "")\n"
129129
toMarkdown(node.children, separator: "\n")
130130
out += "```"
131131

Tests/SourceKitLSPTests/LocalSwiftTests.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ final class LocalSwiftTests: XCTestCase {
802802
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
803803
<Declaration>func foo(_ bar: <Type usr="fake">Baz</Type>)</Declaration>
804804
"""), """
805-
```
805+
```swift
806806
func foo(_ bar: Baz)
807807
```
808808
@@ -812,7 +812,7 @@ final class LocalSwiftTests: XCTestCase {
812812
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
813813
<Declaration>func foo() -&gt; <Type>Bar</Type></Declaration>
814814
"""), """
815-
```
815+
```swift
816816
func foo() -> Bar
817817
```
818818
@@ -822,7 +822,7 @@ final class LocalSwiftTests: XCTestCase {
822822
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
823823
<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>
824824
"""), """
825-
```
825+
```swift
826826
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
827827
```
828828
@@ -835,7 +835,7 @@ final class LocalSwiftTests: XCTestCase {
835835
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
836836
<Class><Declaration>var foo</Declaration></Class>
837837
"""), """
838-
```
838+
```swift
839839
var foo
840840
```
841841
@@ -846,7 +846,7 @@ final class LocalSwiftTests: XCTestCase {
846846
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
847847
<Class><Name>foo</Name><Declaration>var foo</Declaration></Class>
848848
"""), """
849-
```
849+
```swift
850850
var foo
851851
```
852852
@@ -856,7 +856,7 @@ final class LocalSwiftTests: XCTestCase {
856856
XCTAssertEqual(try! xmlDocumentationToMarkdown("""
857857
<Class><USR>asdf</USR><Declaration>var foo</Declaration><Name>foo</Name></Class>
858858
"""), """
859-
```
859+
```swift
860860
var foo
861861
```
862862
@@ -874,7 +874,7 @@ final class LocalSwiftTests: XCTestCase {
874874
"""), """
875875
FOO
876876
877-
```
877+
```swift
878878
var foo
879879
```
880880
@@ -1005,7 +1005,7 @@ final class LocalSwiftTests: XCTestCase {
10051005
"</CommentParts>" +
10061006
"</Class>"
10071007
), """
1008-
```
1008+
```swift
10091009
struct String
10101010
```
10111011
@@ -1018,14 +1018,14 @@ final class LocalSwiftTests: XCTestCase {
10181018
10191019
You can create new strings A *string literal* i
10201020
1021-
```
1021+
```swift
10221022
1.\tlet greeting = "Welcome!"
10231023
2.\t
10241024
```
10251025
10261026
...
10271027
1028-
```
1028+
```swift
10291029
1.\tlet greeting = "Welcome!"
10301030
2.\t
10311031
```
@@ -1176,7 +1176,7 @@ final class LocalSwiftTests: XCTestCase {
11761176
XCTAssertEqual(content.kind, .markdown)
11771177
XCTAssertEqual(content.value, """
11781178
S
1179-
```
1179+
```swift
11801180
struct S
11811181
```
11821182
@@ -1228,7 +1228,7 @@ final class LocalSwiftTests: XCTestCase {
12281228
XCTAssertEqual(content.kind, .markdown)
12291229
XCTAssertEqual(content.value, ##"""
12301230
test(\_:\_:)
1231-
```
1231+
```swift
12321232
func test(_ a: Int, _ b: Int)
12331233
```
12341234
@@ -1253,7 +1253,7 @@ final class LocalSwiftTests: XCTestCase {
12531253
XCTAssertEqual(content.kind, .markdown)
12541254
XCTAssertEqual(content.value, ##"""
12551255
\*%\*(\_:\_:)
1256-
```
1256+
```swift
12571257
func *%* (lhs: String, rhs: String)
12581258
```
12591259

0 commit comments

Comments
 (0)