Skip to content

Commit a15bd61

Browse files
authored
Merge pull request #602 from ianhanken/texteditfix
Empty TextEdits now return nil to avoid diagnostic crashes
2 parents d5eac0d + e36eb50 commit a15bd61

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/SourceKitLSP/Swift/Diagnostic.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ extension TextEdit {
100100
// Snippets are only suppored in code completion.
101101
// Remove SourceKit placeholders from Fix-Its because they can't be represented in the editor properly.
102102
let replacementWithoutPlaceholders = rewriteSourceKitPlaceholders(inString: replacement, clientSupportsSnippets: false)
103+
104+
// If both the replacement without placeholders and the fixit are empty, no TextEdit should be created.
105+
if (replacementWithoutPlaceholders.isEmpty && length == 0) {
106+
return nil
107+
}
108+
103109
self.init(range: position..<endPosition, newText: replacementWithoutPlaceholders)
104110
} else {
105111
return nil

0 commit comments

Comments
 (0)