Skip to content

Commit e6293e2

Browse files
committed
Update request and notification definitions to LSP 3.17
1 parent f05ac4b commit e6293e2

File tree

67 files changed

+2973
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2973
-164
lines changed

Sources/LanguageServerProtocol/Error.swift

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,68 @@ public struct ErrorCode: RawRepresentable, Codable, Hashable {
2222
self.rawValue = rawValue
2323
}
2424

25-
// JSON RPC
25+
// MARK: JSON RPC
2626
public static let parseError: ErrorCode = ErrorCode(rawValue: -32700)
2727
public static let invalidRequest: ErrorCode = ErrorCode(rawValue: -32600)
2828
public static let methodNotFound: ErrorCode = ErrorCode(rawValue: -32601)
2929
public static let invalidParams: ErrorCode = ErrorCode(rawValue: -32602)
3030
public static let internalError: ErrorCode = ErrorCode(rawValue: -32603)
31-
public static let serverErrorStart: ErrorCode = ErrorCode(rawValue: -32099)
32-
public static let serverErrorEnd: ErrorCode = ErrorCode(rawValue: -32000)
33-
public static let workspaceNotOpen: ErrorCode = ErrorCode(rawValue: -32003)
34-
public static let unknownErrorCode: ErrorCode = ErrorCode(rawValue: -32001)
3531

36-
// LSP
32+
33+
/// This is the start range of JSON-RPC reserved error codes.
34+
/// It doesn't denote a real error code. No LSP error codes should
35+
/// be defined between the start and end range. For backwards
36+
/// compatibility the `ServerNotInitialized` and the `UnknownErrorCode`
37+
/// are left in the range.
38+
public static let jsonrpcReservedErrorRangeStart = ErrorCode(rawValue: -32099)
39+
public static let serverErrorStart: ErrorCode = jsonrpcReservedErrorRangeStart
40+
41+
/// Error code indicating that a server received a notification or
42+
/// request before the server has received the `initialize` request.
43+
public static let serverNotInitialized = ErrorCode(rawValue: -32002)
44+
public static let unknownErrorCode = ErrorCode(rawValue: -32001)
45+
46+
/// This is the end range of JSON-RPC reserved error codes.
47+
/// It doesn't denote a real error code.
48+
public static let jsonrpcReservedErrorRangeEnd = ErrorCode(rawValue: -32000)
49+
/// Deprecated, use jsonrpcReservedErrorRangeEnd
50+
public static let serverErrorEnd = jsonrpcReservedErrorRangeEnd
51+
52+
/// This is the start range of LSP reserved error codes.
53+
/// It doesn't denote a real error code.
54+
public static let lspReservedErrorRangeStart = ErrorCode(rawValue: -32899)
55+
56+
/// A request failed but it was syntactically correct, e.g the
57+
/// method name was known and the parameters were valid. The error
58+
/// message should contain human readable information about why
59+
/// the request failed.
60+
public static let RequestFailed = ErrorCode(rawValue: -32803)
61+
62+
/// The server cancelled the request. This error code should
63+
/// only be used for requests that explicitly support being
64+
/// server cancellable.
65+
public static let ServerCancelled = ErrorCode(rawValue: -32802)
66+
67+
/// The server detected that the content of a document got
68+
/// modified outside normal conditions. A server should
69+
/// NOT send this error code if it detects a content change
70+
/// in it unprocessed messages. The result even computed
71+
/// on an older state might still be useful for the client.
72+
///
73+
/// If a client decides that a result is not of any use anymore
74+
/// the client should cancel the request.
75+
public static let ContentModified = ErrorCode(rawValue: -32801)
76+
77+
/// The client has canceled a request and a server as detected
78+
/// the cancel.
3779
public static let cancelled: ErrorCode = ErrorCode(rawValue: -32800)
80+
81+
/// This is the end range of LSP reserved error codes.
82+
/// It doesn't denote a real error code.
83+
public static let lspReservedErrorRangeEnd = ErrorCode(rawValue: -32800)
84+
85+
// MARK: SourceKit-LSP specifiic eror codes
86+
public static let workspaceNotOpen: ErrorCode = ErrorCode(rawValue: -32003)
3887
}
3988

4089
/// An error response represented by a code and message.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
public struct DidCreateFilesNotification: NotificationType {
14+
public static var method: String = "workspace/didCreateFiles"
15+
16+
/// An array of all files/folders created in this operation.
17+
public var files: [FileDelete]
18+
19+
public init(files: [FileDelete]) {
20+
self.files = files
21+
}
22+
}
23+
24+
public struct DidRenameFilesNotification: NotificationType {
25+
public static var method: String = "workspace/didRenameFiles"
26+
27+
/// An array of all files/folders renamed in this operation. When a folder
28+
/// is renamed, only the folder will be included, and not its children.
29+
public var files: [FileRename]
30+
31+
public init(files: [FileRename]) {
32+
self.files = files
33+
}
34+
}
35+
36+
public struct DidDeleteFilesNotification: NotificationType {
37+
public static var method: String = "workspace/didDeleteFiles"
38+
39+
/// An array of all files/folders created in this operation.
40+
public var files: [FileDelete]
41+
42+
public init(files: [FileDelete]) {
43+
self.files = files
44+
}
45+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
/// A notification to log the trace of the server’s execution. The amount and content of these notifications depends on the current trace configuration. If trace is 'off', the server should not send any logTrace notification. If trace is 'messages', the server should not add the 'verbose' field in the LogTraceParams.
14+
///
15+
/// $/logTrace should be used for systematic trace reporting. For single debugging messages, the server should send window/logMessage notifications.
16+
public struct LogTraceNotification: NotificationType, Hashable, Codable {
17+
public static let method: String = "$/logTrace"
18+
19+
/// The message to be logged.
20+
public var message: String
21+
22+
/// Additional information that can be computed if the `trace` configuration
23+
/// is set to `'verbose'`
24+
public var verbose: String
25+
26+
public init(message: String, verbose: String) {
27+
self.message = message
28+
self.verbose = verbose
29+
}
30+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
/// A notification that should be used by the client to modify the trace setting of the server.
14+
public struct SetTraceNotification: NotificationType, Hashable, Codable {
15+
public static let method: String = "$/setTrace"
16+
17+
/// The new value that should be assigned to the trace setting.
18+
public var value: Tracing
19+
20+
public init(value: Tracing) {
21+
self.value = value
22+
}
23+
}

Sources/LanguageServerProtocol/Notifications/TextSynchronizationNotifications.swift

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,24 @@ public struct DidCloseTextDocumentNotification: NotificationType, Hashable {
6868
public struct DidChangeTextDocumentNotification: NotificationType, Hashable {
6969
public static let method: String = "textDocument/didChange"
7070

71-
/// The document to change and its current version identifier.
71+
/// The document that did change. The version number points
72+
/// to the version after all provided content changes have
73+
/// been applied.
7274
public var textDocument: VersionedTextDocumentIdentifier
7375

74-
/// Edits to the document.
76+
/// The actual content changes. The content changes describe single state
77+
/// changes to the document. So if there are two content changes c1 (at
78+
/// array index 0) and c2 (at array index 1) for a document in state S then
79+
/// c1 moves the document from S to S' and c2 from S' to S''. So c1 is
80+
/// computed on the state S and c2 is computed on the state S'.
81+
///
82+
/// To mirror the content of a document using change events use the following
83+
/// approach:
84+
/// - start with the same initial content
85+
/// - apply the 'textDocument/didChange' notifications in the order you
86+
/// receive them.
87+
/// - apply the `TextDocumentContentChangeEvent`s in a single notification
88+
/// in the order you receive them.
7589
public var contentChanges: [TextDocumentContentChangeEvent]
7690

7791
/// Force the LSP to rebuild its AST for the given file. This is useful for clangd to workaround clangd's assumption that
@@ -125,3 +139,76 @@ public struct DidSaveTextDocumentNotification: TextDocumentNotification, Hashabl
125139
/// Only provided if the server specified `includeText == true`.
126140
public var text: String?
127141
}
142+
143+
/// 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.
144+
public struct DidOpenNotebookDocumentNotification: NotificationType, Hashable {
145+
public static let method: String = "notebookDocument/didOpen"
146+
147+
/// The notebook document that got opened.
148+
public var notebookDocument: NotebookDocument
149+
150+
/// The text documents that represent the content
151+
/// of a notebook cell.
152+
public var cellTextDocuments: [TextDocumentItem]
153+
154+
public init(notebookDocument: NotebookDocument, cellTextDocuments: [TextDocumentItem]) {
155+
self.notebookDocument = notebookDocument
156+
self.cellTextDocuments = cellTextDocuments
157+
}
158+
}
159+
160+
/// 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.
161+
public struct DidChangeNotebookDocumentNotification: NotificationType, Hashable {
162+
public static var method: String = "notebookDocument/didChange"
163+
164+
/// The notebook document that did change. The version number points
165+
/// to the version after all provided changes have been applied.
166+
public var notebookDocument: VersionedNotebookDocumentIdentifier
167+
168+
/// The actual changes to the notebook document.
169+
///
170+
/// The change describes single state change to the notebook document.
171+
/// So it moves a notebook document, its cells and its cell text document
172+
/// contents from state S to S'.
173+
///
174+
/// To mirror the content of a notebook using change events use the
175+
/// following approach:
176+
/// - start with the same initial content
177+
/// - apply the 'notebookDocument/didChange' notifications in the order
178+
/// you receive them.
179+
public var change: NotebookDocumentChangeEvent
180+
181+
public init(notebookDocument: VersionedNotebookDocumentIdentifier, change: NotebookDocumentChangeEvent) {
182+
self.notebookDocument = notebookDocument
183+
self.change = change
184+
}
185+
}
186+
187+
/// 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.
188+
public struct DidSaveNotebookDocumentNotification: NotificationType {
189+
public static var method: String = "notebookDocument/didSave"
190+
191+
/// The notebook document that got saved.
192+
public var notebookDocument: NotebookDocumentIdentifier
193+
194+
public init(notebookDocument: NotebookDocumentIdentifier) {
195+
self.notebookDocument = notebookDocument
196+
}
197+
}
198+
199+
/// 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.
200+
public struct DidCloseNotebookDocumentNotification: NotificationType {
201+
public static var method: String = "notebookDocument/didClose"
202+
203+
/// The notebook document that got closed.
204+
public var notebookDocument: NotebookDocumentIdentifier
205+
206+
/// The text documents that represent the content
207+
/// of a notebook cell that got closed.
208+
public var cellTextDocuments: [TextDocumentIdentifier]
209+
210+
public init(notebookDocument: NotebookDocumentIdentifier, cellTextDocuments: [TextDocumentIdentifier]) {
211+
self.notebookDocument = notebookDocument
212+
self.cellTextDocuments = cellTextDocuments
213+
}
214+
}

0 commit comments

Comments
 (0)