Skip to content

Commit 93a8f91

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

File tree

68 files changed

+3503
-193
lines changed

Some content is hidden

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

68 files changed

+3503
-193
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.

Sources/LanguageServerProtocol/Messages.swift

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,70 @@
1616
/// If you are adding a message for testing only, you can register it dynamically using
1717
/// `MessageRegistry._register()` which allows you to avoid bloating the real server implementation.
1818
public let builtinRequests: [_RequestType.Type] = [
19-
InitializeRequest.self,
20-
ShutdownRequest.self,
21-
WorkspaceFoldersRequest.self,
22-
CompletionRequest.self,
23-
HoverRequest.self,
24-
WorkspaceSemanticTokensRefreshRequest.self,
25-
WorkspaceSymbolsRequest.self,
19+
ApplyEditRequest.self,
2620
CallHierarchyIncomingCallsRequest.self,
2721
CallHierarchyOutgoingCallsRequest.self,
2822
CallHierarchyPrepareRequest.self,
29-
TypeHierarchyPrepareRequest.self,
30-
TypeHierarchySupertypesRequest.self,
31-
TypeHierarchySubtypesRequest.self,
23+
CodeActionRequest.self,
24+
CodeActionResolveRequest.self,
25+
CodeLensRefreshRequest.self,
26+
CodeLensRequest.self,
27+
CodeLensResolveRequest.self,
28+
ColorPresentationRequest.self,
29+
CompletionItemResolveRequest.self,
30+
CompletionRequest.self,
31+
CreateWorkDoneProgressRequest.self,
3232
DeclarationRequest.self,
3333
DefinitionRequest.self,
34-
ImplementationRequest.self,
35-
ReferencesRequest.self,
36-
DocumentHighlightRequest.self,
34+
DiagnosticsRefreshRequest.self,
35+
DocumentColorRequest.self,
36+
DocumentDiagnosticsRequest.self,
3737
DocumentFormattingRequest.self,
38+
DocumentHighlightRequest.self,
39+
DocumentLinkRequest.self,
40+
DocumentLinkResolveRequest.self,
41+
DocumentOnTypeFormattingRequest.self,
3842
DocumentRangeFormattingRequest.self,
3943
DocumentSemanticTokensDeltaRequest.self,
4044
DocumentSemanticTokensRangeRequest.self,
4145
DocumentSemanticTokensRequest.self,
42-
DocumentOnTypeFormattingRequest.self,
43-
FoldingRangeRequest.self,
4446
DocumentSymbolRequest.self,
45-
DocumentColorRequest.self,
46-
ColorPresentationRequest.self,
47-
CodeActionRequest.self,
4847
ExecuteCommandRequest.self,
49-
ApplyEditRequest.self,
48+
FoldingRangeRequest.self,
49+
HoverRequest.self,
50+
ImplementationRequest.self,
51+
InitializeRequest.self,
52+
InlayHintRefreshRequest.self,
53+
InlayHintRequest.self,
54+
InlayHintResolveRequest.self,
55+
InlineValueRefreshRequest.self,
56+
InlineValueRequest.self,
57+
LinkedEditingRangeRequest.self,
58+
MonikersRequest.self,
59+
PollIndexRequest.self,
5060
PrepareRenameRequest.self,
51-
RenameRequest.self,
61+
ReferencesRequest.self,
5262
RegisterCapabilityRequest.self,
63+
RenameRequest.self,
64+
SelectionRangeRequest.self,
65+
ShowMessageRequest.self,
66+
ShutdownRequest.self,
67+
SignatureHelpRequest.self,
68+
SymbolInfoRequest.self,
5369
TypeDefinitionRequest.self,
70+
TypeHierarchyPrepareRequest.self,
71+
TypeHierarchySubtypesRequest.self,
72+
TypeHierarchySupertypesRequest.self,
5473
UnregisterCapabilityRequest.self,
55-
InlayHintRequest.self,
56-
57-
// MARK: LSP Extension Requests
58-
59-
SymbolInfoRequest.self,
60-
PollIndexRequest.self,
74+
WillCreateFilesRequest.self,
75+
WillDeleteFilesRequest.self,
76+
WillRenameFilesRequest.self,
77+
WillSaveWaitUntilTextDocumentRequest.self,
78+
WorkspaceDiagnosticsRequest.self,
79+
WorkspaceFoldersRequest.self,
80+
WorkspaceSemanticTokensRefreshRequest.self,
81+
WorkspaceSymbolResolveRequest.self,
82+
WorkspaceSymbolsRequest.self,
6183
]
6284

6385
/// The set of known notifications.
@@ -66,19 +88,29 @@ public let builtinRequests: [_RequestType.Type] = [
6688
/// here. If you are adding a message for testing only, you can register it dynamically using
6789
/// `MessageRegistry._register()` which allows you to avoid bloating the real server implementation.
6890
public let builtinNotifications: [NotificationType.Type] = [
69-
InitializedNotification.self,
70-
ExitNotification.self,
7191
CancelRequestNotification.self,
72-
LogMessageNotification.self,
92+
CancelWorkDoneProgressNotification.self,
7393
DidChangeConfigurationNotification.self,
94+
DidChangeNotebookDocumentNotification.self,
95+
DidChangeTextDocumentNotification.self,
7496
DidChangeWatchedFilesNotification.self,
7597
DidChangeWorkspaceFoldersNotification.self,
76-
DidOpenTextDocumentNotification.self,
98+
DidCloseNotebookDocumentNotification.self,
7799
DidCloseTextDocumentNotification.self,
78-
DidChangeTextDocumentNotification.self,
79-
DidSaveTextDocumentNotification.self,
80-
WillSaveTextDocumentNotification.self,
100+
DidCreateFilesNotification.self,
101+
DidDeleteFilesNotification.self,
102+
DidOpenNotebookDocumentNotification.self,
103+
DidOpenTextDocumentNotification.self,
104+
DidRenameFilesNotification.self,
105+
DidSaveNotebookDocumentNotification.self,
106+
ExitNotification.self,
107+
InitializedNotification.self,
108+
LogMessageNotification.self,
109+
LogTraceNotification.self,
81110
PublishDiagnosticsNotification.self,
111+
SetTraceNotification.self,
112+
ShowMessageNotification.self,
113+
WorkDoneProgress.self,
82114
]
83115

84116
// MARK: Miscellaneous Message Types
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 CancelWorkDoneProgressNotification: NotificationType {
14+
public static var method: String = "window/workDoneProgress/cancel"
15+
16+
public var token: ProgressToken
17+
18+
public init(token: ProgressToken) {
19+
self.token = token
20+
}
21+
}
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: [FileCreate]
18+
19+
public init(files: [FileCreate]) {
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+
}

0 commit comments

Comments
 (0)