File: TextSynchronizationNotifications.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (224 lines) | stat: -rw-r--r-- 9,782 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 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
//
//===----------------------------------------------------------------------===//

/// Notification from the client that a new document is open and its content should be managed by
/// the text synchronization notifications until it has been closed.
///
/// The `didOpen` notification provides the initial contents of the document. Thereafter, any
/// queries that need the content of this document should use the contents provided here (or updated
/// via subsequent `didChange` notifications) and should ignore the contents on disk.
///
/// An open document can be modified using the `didChange` notification, and when done closed using
/// the `didClose` notification. Once closed, the server can use the contents on disk, if needed.
/// A document can only be opened once at a time, and must be balanced by a `didClose` before being
/// opened again.
///
/// Servers that provide document synchronization should set the `textDocumentSync` server
/// capability.
///
/// - Parameter textDocument: The document identifier and initial contents.
public struct DidOpenTextDocumentNotification: NotificationType, Hashable {
  public static let method: String = "textDocument/didOpen"

  /// The document identifier and initial contents.
  public var textDocument: TextDocumentItem

  public init(textDocument: TextDocumentItem) {
    self.textDocument = textDocument
  }
}

/// Notification that the given document is closed and no longer managed by the text synchronization
/// notifications.
///
/// The document must have previously been opened with `didOpen`. Closing the document returns
/// management of the document contents to disk, if appropriate.
///
/// - Parameter textDocument: The document to close, which must be currently open.
public struct DidCloseTextDocumentNotification: NotificationType, Hashable {
  public static let method: String = "textDocument/didClose"

  /// The document to close, which must be currently open.
  public var textDocument: TextDocumentIdentifier

  public init(textDocument: TextDocumentIdentifier) {
    self.textDocument = textDocument
  }
}

/// Notification that the contents of the given document have been changed.
///
/// Updates the content of a document previously opened with `didOpen` by applying a list of
/// changes, which may either be full document replacements, or incremental edits.
///
/// Servers that support incremental edits should set the `change` text document sync option.
///
/// - Parameters:
///   - textDocument: The document to change and its current version identifier.
///   - contentChanges: Edits to the document.
public struct DidChangeTextDocumentNotification: NotificationType, Hashable {
  public static let method: String = "textDocument/didChange"

  /// The document that did change. The version number points
  /// to the version after all provided content changes have
  /// been applied.
  public var textDocument: VersionedTextDocumentIdentifier

  /// The actual content changes. The content changes describe single state
  /// changes to the document. So if there are two content changes c1 (at
  /// array index 0) and c2 (at array index 1) for a document in state S then
  /// c1 moves the document from S to S' and c2 from S' to S''. So c1 is
  /// computed on the state S and c2 is computed on the state S'.
  ///
  /// To mirror the content of a document using change events use the following
  /// approach:
  /// - start with the same initial content
  /// - apply the 'textDocument/didChange' notifications in the order you
  ///   receive them.
  /// - apply the `TextDocumentContentChangeEvent`s in a single notification
  ///   in the order you receive them.
  public var contentChanges: [TextDocumentContentChangeEvent]

  /// Force the LSP to rebuild its AST for the given file. This is useful for clangd to workaround clangd's assumption that
  /// missing header files will stay missing.
  /// **LSP Extension from clangd**.
  public var forceRebuild: Bool? = nil

  public init(
    textDocument: VersionedTextDocumentIdentifier,
    contentChanges: [TextDocumentContentChangeEvent],
    forceRebuild: Bool? = nil
  ) {
    self.textDocument = textDocument
    self.contentChanges = contentChanges
    self.forceRebuild = forceRebuild
  }
}

/// Notification that the given document will be saved.
///
/// - Parameters:
///   - textDocument: The document that will be saved.
///   - reason: Whether this was user-initiated, auto-saved, etc.
///
/// Servers that support willSave should set the `willSave` text document sync option.
public struct WillSaveTextDocumentNotification: TextDocumentNotification, Hashable {
  public static let method: String = "textDocument/willSave"

  /// The document that will be saved.
  public var textDocument: TextDocumentIdentifier

  /// Whether this is user-initiated save, auto-saved, etc.
  public var reason: TextDocumentSaveReason

  public init(textDocument: TextDocumentIdentifier, reason: TextDocumentSaveReason) {
    self.textDocument = textDocument
    self.reason = reason
  }
}

/// Notification that the given document was saved.
///
/// - Parameters:
///   - textDocument: The document that was saved.
///   - text: The content of the document at the time of save.
///
/// Servers that support didSave should set the `save` text document sync option.
public struct DidSaveTextDocumentNotification: TextDocumentNotification, Hashable {
  public static let method: String = "textDocument/didSave"

  /// The document that was saved.
  public var textDocument: TextDocumentIdentifier

  /// The content of the document at the time of save.
  ///
  /// Only provided if the server specified `includeText == true`.
  public var text: String?

  public init(textDocument: TextDocumentIdentifier, text: String? = nil) {
    self.textDocument = textDocument
    self.text = text
  }
}

/// The open notification is sent from the client to the server when a notebook document is opened. It is only sent by a client if the server requested the synchronization mode `notebook` in its `notebookDocumentSync` capability.
public struct DidOpenNotebookDocumentNotification: NotificationType, Hashable {
  public static let method: String = "notebookDocument/didOpen"

  /// The notebook document that got opened.
  public var notebookDocument: NotebookDocument

  /// The text documents that represent the content
  /// of a notebook cell.
  public var cellTextDocuments: [TextDocumentItem]

  public init(notebookDocument: NotebookDocument, cellTextDocuments: [TextDocumentItem]) {
    self.notebookDocument = notebookDocument
    self.cellTextDocuments = cellTextDocuments
  }
}

/// The change notification is sent from the client to the server when a notebook document changes. It is only sent by a client if the server requested the synchronization mode `notebook` in its `notebookDocumentSync` capability.
public struct DidChangeNotebookDocumentNotification: NotificationType, Hashable {
  public static let method: String = "notebookDocument/didChange"

  /// The notebook document that did change. The version number points
  /// to the version after all provided changes have been applied.
  public var notebookDocument: VersionedNotebookDocumentIdentifier

  /// The actual changes to the notebook document.
  ///
  /// The change describes single state change to the notebook document.
  /// So it moves a notebook document, its cells and its cell text document
  /// contents from state S to S'.
  ///
  /// To mirror the content of a notebook using change events use the
  /// following approach:
  /// - start with the same initial content
  /// - apply the 'notebookDocument/didChange' notifications in the order
  ///   you receive them.
  public var change: NotebookDocumentChangeEvent

  public init(notebookDocument: VersionedNotebookDocumentIdentifier, change: NotebookDocumentChangeEvent) {
    self.notebookDocument = notebookDocument
    self.change = change
  }
}

/// The save notification is sent from the client to the server when a notebook document is saved. It is only sent by a client if the server requested the synchronization mode `notebook` in its `notebookDocumentSync` capability.
public struct DidSaveNotebookDocumentNotification: NotificationType {
  public static let method: String = "notebookDocument/didSave"

  /// The notebook document that got saved.
  public var notebookDocument: NotebookDocumentIdentifier

  public init(notebookDocument: NotebookDocumentIdentifier) {
    self.notebookDocument = notebookDocument
  }
}

/// The close notification is sent from the client to the server when a notebook document is closed. It is only sent by a client if the server requested the synchronization mode `notebook` in its `notebookDocumentSync` capability.
public struct DidCloseNotebookDocumentNotification: NotificationType {
  public static let method: String = "notebookDocument/didClose"

  /// The notebook document that got closed.
  public var notebookDocument: NotebookDocumentIdentifier

  /// The text documents that represent the content
  /// of a notebook cell that got closed.
  public var cellTextDocuments: [TextDocumentIdentifier]

  public init(notebookDocument: NotebookDocumentIdentifier, cellTextDocuments: [TextDocumentIdentifier]) {
    self.notebookDocument = notebookDocument
    self.cellTextDocuments = cellTextDocuments
  }
}