File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
Sources/SourceKitLSP/Swift Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -513,10 +513,9 @@ extension SwiftLanguageServer {
513
513
let keys = self . keys
514
514
515
515
self . queue. async {
516
- let uri = note. textDocument. uri
517
516
var lastResponse : SKDResponseDictionary ? = nil
518
517
519
- self . documentManager. edit ( note) { ( before: DocumentSnapshot , edit: TextDocumentContentChangeEvent ) in
518
+ let snapshot = self . documentManager. edit ( note) { ( before: DocumentSnapshot , edit: TextDocumentContentChangeEvent ) in
520
519
let req = SKDRequestDictionary ( sourcekitd: self . sourcekitd)
521
520
req [ keys. request] = self . requests. editor_replacetext
522
521
req [ keys. name] = note. textDocument. uri. pseudoPath
@@ -545,7 +544,7 @@ extension SwiftLanguageServer {
545
544
}
546
545
}
547
546
548
- if let dict = lastResponse, let snapshot = self . documentManager . latestSnapshot ( uri ) {
547
+ if let dict = lastResponse, let snapshot = snapshot {
549
548
let compileCommand = self . commandsByFile [ note. textDocument. uri]
550
549
self . publishDiagnostics ( response: dict, for: snapshot, compileCommand: compileCommand)
551
550
}
Original file line number Diff line number Diff line change @@ -235,14 +235,21 @@ extension Array where Element == SyntaxHighlightingToken {
235
235
236
236
extension Range where Bound == Position {
237
237
/// Splits a potentially multi-line range to multiple single-line ranges.
238
- fileprivate func splitToSingleLineRanges( in snapshot: DocumentSnapshot ) -> [ Self ] {
238
+ fileprivate func splitToSingleLineRanges(
239
+ in snapshot: DocumentSnapshot ,
240
+ omittingEmptyRanges: Bool = true
241
+ ) -> [ Self ] {
242
+ if lowerBound. line == upperBound. line {
243
+ return omittingEmptyRanges && isEmpty ? [ ] : [ self ]
244
+ }
245
+
239
246
guard let startIndex = snapshot. index ( of: lowerBound) ,
240
247
let endIndex = snapshot. index ( of: upperBound) else {
241
248
fatalError ( " Range \( self ) reaches outside of the document " )
242
249
}
243
250
244
251
let text = snapshot. text [ startIndex..< endIndex]
245
- let lines = text. split ( separator: " \n " )
252
+ let lines = text. split ( separator: " \n " , omittingEmptySubsequences : omittingEmptyRanges )
246
253
247
254
return lines
248
255
. enumerated ( )
You can’t perform that action at this time.
0 commit comments