Skip to content

Commit 5329b47

Browse files
Tone down on what is escaped to prevent Sublime Text from showing wrong name
1 parent 0d15fdf commit 5329b47

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

Sources/SourceKit/sourcekitd/SwiftLanguageServer.swift

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -444,22 +444,13 @@ extension SwiftLanguageServer {
444444
return
445445
}
446446

447-
/// Prepend backslash to all ASCII punctuation, to prevent it
447+
/// Prepend backslash to `*` and `_`, to prevent them
448448
/// from being interpreted as markdown.
449-
///
450-
/// Any ASCII punctuation character may be backslash-escaped.
451-
/// https://spec.commonmark.org/0.29/#backslash-escapes
452-
func escapeMarkdown(_ str: String) -> String {
453-
func isAsciiPunctuation(_ char: Character) -> Bool {
454-
let asciiPunctuation = Set<Character>(##"""
455-
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
456-
"""##)
457-
return asciiPunctuation.contains(char)
458-
}
459-
return String(str.flatMap({ isAsciiPunctuation($0) ? ["\\", $0] : [$0] }))
449+
func escapeNameMarkdown(_ str: String) -> String {
450+
return String(str.flatMap({ ($0 == "*" || $0 == "_") ? ["\\", $0] : [$0] }))
460451
}
461452

462-
var result = "# \(escapeMarkdown(name))"
453+
var result = "# \(escapeNameMarkdown(name))"
463454
if let doc = cursorInfo.documentationXML {
464455
result += """
465456

Tests/SourceKitTests/LocalSwiftTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ final class LocalSwiftTests: XCTestCase {
648648
XCTAssertNil(hover.range)
649649
XCTAssertEqual(hover.contents.kind, .markdown)
650650
XCTAssertEqual(hover.contents.value, ##"""
651-
# test\(\_\:\_\:\)
651+
# test(\_:\_:)
652652
```
653653
func test(_ a: Int, _ b: Int)
654654
```
@@ -668,7 +668,7 @@ final class LocalSwiftTests: XCTestCase {
668668
XCTAssertNil(hover.range)
669669
XCTAssertEqual(hover.contents.kind, .markdown)
670670
XCTAssertEqual(hover.contents.value, ##"""
671-
# \*\%\*\(\_\:\_\:\)
671+
# \*%\*(\_:\_:)
672672
```
673673
func *%* (lhs: String, rhs: String)
674674
```

0 commit comments

Comments
 (0)