mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
This was causing a non-deterministic test failure: When target preparation finishes while a diagnostic request is in progress, it will re-open the document, which calls `DiagnosticReportManager.removeItemsFromCache` for that document’s URI. With the old implementation, we would thus cancel the diagnostics sourcekitd request and return a cancelled error to the diagnostics LSP request. While doing this, I also realized that there was a race condition: Document re-opening would happen outside of the SourceKit-LSP message handling queue and could thus run concurrently to any other request. This means that a sourcekitd request could run after `reopenDocument` had closed the document but before it was opened again. Introduce an internal reopen request that can be handled on the main message handling queue and thus doesn’t have this problem
30 lines
1.2 KiB
Swift
30 lines
1.2 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// Re-open the given document, discarding any in-memory state.
|
|
///
|
|
/// This notification is designed to be used internally in SourceKit-LSP: When build setting have changed, we re-open
|
|
/// the document in sourcekitd to re-build its AST. This needs to be handled via a notification to ensure that no other
|
|
/// request for this document is executing at the same time.
|
|
///
|
|
/// **(LSP Extension)**
|
|
public struct ReopenTextDocumentNotification: NotificationType, Hashable {
|
|
public static let method: String = "textDocument/reopen"
|
|
|
|
/// The document identifier and initial contents.
|
|
public var textDocument: TextDocumentIdentifier
|
|
|
|
public init(textDocument: TextDocumentIdentifier) {
|
|
self.textDocument = textDocument
|
|
}
|
|
}
|