From a83a53c7241840876ec552e3021ed03bdff36c55 Mon Sep 17 00:00:00 2001 From: Ian Hanken Date: Tue, 2 Aug 2022 10:09:22 -0700 Subject: [PATCH] Empty TextEdits now return nil This adds a check when creating a `TextEdit` to return `nil` if both the fixit and the replacement being used to create a `TextEdit` are empty. A `TextEdit` being created like this can cause a crash. --- Sources/SourceKitLSP/Swift/Diagnostic.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/SourceKitLSP/Swift/Diagnostic.swift b/Sources/SourceKitLSP/Swift/Diagnostic.swift index 99b8f8d5..12683be2 100644 --- a/Sources/SourceKitLSP/Swift/Diagnostic.swift +++ b/Sources/SourceKitLSP/Swift/Diagnostic.swift @@ -100,6 +100,12 @@ extension TextEdit { // Snippets are only suppored in code completion. // Remove SourceKit placeholders from Fix-Its because they can't be represented in the editor properly. let replacementWithoutPlaceholders = rewriteSourceKitPlaceholders(inString: replacement, clientSupportsSnippets: false) + + // If both the replacement without placeholders and the fixit are empty, no TextEdit should be created. + if (replacementWithoutPlaceholders.isEmpty && length == 0) { + return nil + } + self.init(range: position..