Skip to content

Commit 8da5fb8

Browse files
committed
Unify the naming of request and notification types
Request types should always have the suffix Request and notifications should end with Notification. Also moved all request and notification types into separate folders to reduce the number of files in the LanguageServerProtocol folder.
1 parent 47148eb commit 8da5fb8

File tree

73 files changed

+232
-188
lines changed

Some content is hidden

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

73 files changed

+232
-188
lines changed

Sources/LanguageServerProtocol/Messages.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public let builtinRequests: [_RequestType.Type] = [
2626
ImplementationRequest.self,
2727
ReferencesRequest.self,
2828
DocumentHighlightRequest.self,
29-
DocumentFormatting.self,
30-
DocumentRangeFormatting.self,
31-
DocumentOnTypeFormatting.self,
29+
DocumentFormattingRequest.self,
30+
DocumentRangeFormattingRequest.self,
31+
DocumentOnTypeFormattingRequest.self,
3232
FoldingRangeRequest.self,
3333
DocumentSymbolRequest.self,
3434
DocumentColorRequest.self,
@@ -39,7 +39,7 @@ public let builtinRequests: [_RequestType.Type] = [
3939
// MARK: LSP Extension Requests
4040

4141
SymbolInfoRequest.self,
42-
PollIndex.self,
42+
PollIndexRequest.self,
4343
]
4444

4545
/// The set of known notifications.
@@ -49,17 +49,17 @@ public let builtinRequests: [_RequestType.Type] = [
4949
/// `MessageRegistry._register()` which allows you to avoid bloating the real server implementation.
5050
public let builtinNotifications: [NotificationType.Type] = [
5151
InitializedNotification.self,
52-
Exit.self,
53-
CancelRequest.self,
54-
LogMessage.self,
55-
DidChangeConfiguration.self,
56-
DidChangeWorkspaceFolders.self,
57-
DidOpenTextDocument.self,
58-
DidCloseTextDocument.self,
59-
DidChangeTextDocument.self,
60-
DidSaveTextDocument.self,
61-
WillSaveTextDocument.self,
62-
PublishDiagnostics.self,
52+
ExitNotification.self,
53+
CancelRequestNotification.self,
54+
LogMessageNotification.self,
55+
DidChangeConfigurationNotification.self,
56+
DidChangeWorkspaceFoldersNotification.self,
57+
DidOpenTextDocumentNotification.self,
58+
DidCloseTextDocumentNotification.self,
59+
DidChangeTextDocumentNotification.self,
60+
DidSaveTextDocumentNotification.self,
61+
WillSaveTextDocumentNotification.self,
62+
PublishDiagnosticsNotification.self,
6363
]
6464

6565
// MARK: Miscellaneous Message Types

Sources/LanguageServerProtocol/CancelRequest.swift renamed to Sources/LanguageServerProtocol/Notifications/CancelRequestNotification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/// As with any `$` requests, the server is free to ignore this notification.
1919
///
2020
/// - Parameter id: The request to cancel.
21-
public struct CancelRequest: NotificationType, Hashable {
21+
public struct CancelRequestNotification: NotificationType, Hashable {
2222
public static let method: String = "$/cancelRequest"
2323

2424
/// The request to cancel.

Sources/LanguageServerProtocol/Configuration.swift renamed to Sources/LanguageServerProtocol/Notifications/ConfigurationNotification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/// - Note: the format of the settings is implementation-defined.
1616
///
1717
/// - Parameter settings: The changed workspace settings.
18-
public struct DidChangeConfiguration: NotificationType {
18+
public struct DidChangeConfigurationNotification: NotificationType {
1919
public static let method: String = "workspace/didChangeConfiguration"
2020

2121
/// The changed workspace settings.

Sources/LanguageServerProtocol/WorkspaceFolders.swift renamed to Sources/LanguageServerProtocol/Notifications/DidChangeWorkspaceFoldersNotification.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,12 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// Request from the server for the set of currently open workspace folders.
14-
///
15-
///
16-
/// Clients that support workspace folders should set the `workspaceFolders` client capability.
17-
///
18-
/// - Returns: The set of currently open workspace folders. Returns nil if only a single file is
19-
/// open. Returns an empty array if a workspace is open but no folders are configured.
20-
public struct WorkspaceFoldersRequest: RequestType, Hashable {
21-
public static let method: String = "workspace/workspaceFolders"
22-
public typealias Response = [WorkspaceFolder]?
23-
}
24-
2513
/// Notification from the client that the set of open workspace folders has changed.
2614
///
2715
/// - Parameter event: The set of changes.
2816
///
2917
/// Requires the `workspaceFolders` capability on both the client and server.
30-
public struct DidChangeWorkspaceFolders: NotificationType {
18+
public struct DidChangeWorkspaceFoldersNotification: NotificationType {
3119
public static let method: String = "workspace/didChangeWorkspaceFolders"
3220

3321
/// The set of changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 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+
/// Notification that the server process should exit.
14+
///
15+
/// This notification will come after the shutdown request finishes.
16+
public struct ExitNotification: NotificationType, Hashable {
17+
public static let method: String = "exit"
18+
public init() { }
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 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+
/// Notification from the client that its own initialization of the language server has finished.
14+
public struct InitializedNotification: NotificationType, Hashable {
15+
public static let method: String = "initialized"
16+
17+
public init() {}
18+
}

Sources/LanguageServerProtocol/LogMessage.swift renamed to Sources/LanguageServerProtocol/Notifications/LogMessageNotification.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/// - Parameters:
1616
/// - type: The kind of log message.
1717
/// - message: The contents of the message.
18-
public struct LogMessage: NotificationType, Hashable {
18+
public struct LogMessageNotification: NotificationType, Hashable {
1919
public static let method: String = "window/logMessage"
2020

2121
/// The kind of log message.
@@ -28,4 +28,4 @@ public struct LogMessage: NotificationType, Hashable {
2828
self.type = type
2929
self.message = message
3030
}
31-
}
31+
}

Sources/LanguageServerProtocol/PublishDiagnostics.swift renamed to Sources/LanguageServerProtocol/Notifications/PublishDiagnosticsNotification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/// - Parameters:
2525
/// - uri: The document in which the diagnostics should be shown.
2626
/// - diagnostics: The complete list of diagnostics in the document, if any.
27-
public struct PublishDiagnostics: NotificationType, Hashable, Codable {
27+
public struct PublishDiagnosticsNotification: NotificationType, Hashable, Codable {
2828
public static let method: String = "textDocument/publishDiagnostics"
2929

3030
/// The document in which the diagnostics should be shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 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+
/// Notification from the server containing a message for the client to display.
14+
///
15+
/// - Parameters:
16+
/// - type: The kind of message.
17+
/// - message: The contents of the message.
18+
public struct ShowMessageNotification: NotificationType, Hashable {
19+
public static let method: String = "window/showMessage"
20+
21+
/// The kind of message.
22+
public var type: WindowMessageType
23+
24+
/// The contents of the message.
25+
public var message: String
26+
27+
public init(type: WindowMessageType, message: String) {
28+
self.type = type
29+
self.message = message
30+
}
31+
}

Sources/LanguageServerProtocol/TextSynchronization.swift renamed to Sources/LanguageServerProtocol/Notifications/TextSynchronizationNotifications.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/// capability.
2727
///
2828
/// - Parameter textDocument: The document identifier and initial contents.
29-
public struct DidOpenTextDocument: NotificationType, Hashable {
29+
public struct DidOpenTextDocumentNotification: NotificationType, Hashable {
3030
public static let method: String = "textDocument/didOpen"
3131

3232
/// The document identifier and initial contents.
@@ -44,7 +44,7 @@ public struct DidOpenTextDocument: NotificationType, Hashable {
4444
/// management of the document contents to disk, if appropriate.
4545
///
4646
/// - Parameter textDocument: The document to close, which must be currently open.
47-
public struct DidCloseTextDocument: NotificationType, Hashable {
47+
public struct DidCloseTextDocumentNotification: NotificationType, Hashable {
4848
public static let method: String = "textDocument/didClose"
4949

5050
/// The document to close, which must be currently open.
@@ -65,7 +65,7 @@ public struct DidCloseTextDocument: NotificationType, Hashable {
6565
/// - Parameters:
6666
/// - textDocument: The document to change and its current version identifier.
6767
/// - contentChanges: Edits to the document.
68-
public struct DidChangeTextDocument: NotificationType, Hashable {
68+
public struct DidChangeTextDocumentNotification: NotificationType, Hashable {
6969
public static let method: String = "textDocument/didChange"
7070

7171
/// The document to change and its current version identifier.
@@ -90,7 +90,7 @@ public struct DidChangeTextDocument: NotificationType, Hashable {
9090
/// - reason: Whether this was user-initiated, auto-saved, etc.
9191
///
9292
/// Servers that support willSave should set the `willSave` text document sync option.
93-
public struct WillSaveTextDocument: NotificationType, Hashable {
93+
public struct WillSaveTextDocumentNotification: NotificationType, Hashable {
9494
public static let method: String = "textDocument/willSave"
9595

9696
/// The document that will be saved.
@@ -107,7 +107,7 @@ public struct WillSaveTextDocument: NotificationType, Hashable {
107107
/// - text: The content of the document at the time of save.
108108
///
109109
/// Servers that support didSave should set the `save` text document sync option.
110-
public struct DidSaveTextDocument: NotificationType, Hashable {
110+
public struct DidSaveTextDocumentNotification: NotificationType, Hashable {
111111
public static let method: String = "textDocument/didSave"
112112

113113
/// The document that was saved.

Sources/LanguageServerProtocol/CodeAction.swift renamed to Sources/LanguageServerProtocol/Requests/CodeActionRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public struct CodeActionContext: Codable, Hashable {
111111
}
112112
}
113113

114-
public struct CodeAction: Codable, Equatable, ResponseType {
114+
public struct CodeAction: Codable, Equatable {
115115

116116
/// A short, human-readable, title for this code action.
117117
public var title: String

Sources/LanguageServerProtocol/DocumentSymbol.swift renamed to Sources/LanguageServerProtocol/Requests/DocumentSymbolRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public enum DocumentSymbolResponse: ResponseType, Hashable {
6262
/// Represents programming constructs like variables, classes, interfaces etc. that appear
6363
/// in a document. Document symbols can be hierarchical and they have two ranges: one that encloses
6464
/// its definition and one that points to its most interesting range, e.g. the range of an identifier.
65-
public struct DocumentSymbol: Hashable, Codable, ResponseType {
65+
public struct DocumentSymbol: Hashable, Codable {
6666

6767
/// The name of this symbol. Will be displayed in the user interface and therefore must not be
6868
/// an empty string or a string only consisting of white spaces.

Sources/LanguageServerProtocol/Formatting.swift renamed to Sources/LanguageServerProtocol/Requests/FormattingRequests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/// - options: Options to customize the formatting.
2020
///
2121
/// - Returns: An array of of text edits describing the formatting changes to the document, if any.
22-
public struct DocumentFormatting: TextDocumentRequest, Hashable {
22+
public struct DocumentFormattingRequest: TextDocumentRequest, Hashable {
2323
public static let method: String = "textDocument/formatting"
2424
public typealias Response = [TextEdit]?
2525

@@ -41,7 +41,7 @@ public struct DocumentFormatting: TextDocumentRequest, Hashable {
4141
/// - options: Options to customize the formatting.
4242
///
4343
/// - Returns: An array of of text edits describing the formatting changes to the document, if any.
44-
public struct DocumentRangeFormatting: TextDocumentRequest, Hashable {
44+
public struct DocumentRangeFormattingRequest: TextDocumentRequest, Hashable {
4545
public static let method: String = "textDocument/rangeFormatting"
4646
public typealias Response = [TextEdit]?
4747

@@ -72,7 +72,7 @@ public struct DocumentRangeFormatting: TextDocumentRequest, Hashable {
7272
/// - options: Options to customize the formatting.
7373
///
7474
/// - Returns: An array of of text edits describing the formatting changes to the document, if any.
75-
public struct DocumentOnTypeFormatting: TextDocumentRequest, Hashable {
75+
public struct DocumentOnTypeFormattingRequest: TextDocumentRequest, Hashable {
7676
public static let method: String = "textDocument/onTypeFormatting"
7777
public typealias Response = [TextEdit]?
7878

Sources/LanguageServerProtocol/InitializeRequest.swift renamed to Sources/LanguageServerProtocol/Requests/InitializeRequest.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,3 @@ public struct InitializeResult: ResponseType, Hashable {
106106
self.capabilities = capabilities
107107
}
108108
}
109-
110-
/// Notification from the client that its own initialization of the language server has finished.
111-
public struct InitializedNotification: NotificationType, Hashable {
112-
public static let method: String = "initialized"
113-
114-
public init() {}
115-
}

Sources/LanguageServerProtocol/PollIndex.swift renamed to Sources/LanguageServerProtocol/Requests/PollIndexRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
///
1616
/// Users of PollIndex should set `"initializationOptions": { "listenToUnitEvents": false }` during
1717
/// the `initialize` request.
18-
public struct PollIndex: RequestType {
18+
public struct PollIndexRequest: RequestType {
1919
public static var method: String = "workspace/_pollIndex"
2020
public typealias Response = VoidResponse
2121
}

Sources/LanguageServerProtocol/ShowMessageRequest.swift renamed to Sources/LanguageServerProtocol/Requests/ShowMessageRequest.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,3 @@ public struct MessageActionItem: ResponseType, Hashable {
5252
self.title = title
5353
}
5454
}
55-
56-
/// Notification from the server containing a message for the client to display.
57-
///
58-
/// - Parameters:
59-
/// - type: The kind of message.
60-
/// - message: The contents of the message.
61-
public struct ShowMessage: NotificationType, Hashable {
62-
public static let method: String = "window/showMessage"
63-
64-
/// The kind of message.
65-
public var type: WindowMessageType
66-
67-
/// The contents of the message.
68-
public var message: String
69-
70-
public init(type: WindowMessageType, message: String) {
71-
self.type = type
72-
self.message = message
73-
}
74-
}

Sources/LanguageServerProtocol/Shutdown.swift renamed to Sources/LanguageServerProtocol/Requests/ShutdownRequest.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,3 @@ public struct Shutdown: RequestType, Hashable {
2222

2323
public init() { }
2424
}
25-
26-
/// Notification that the server process should exit.
27-
///
28-
/// This notification will come after the shutdown request finishes.
29-
public struct Exit: NotificationType, Hashable {
30-
public static let method: String = "exit"
31-
public init() { }
32-
}
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 - 2019 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+
/// Request from the server for the set of currently open workspace folders.
14+
///
15+
///
16+
/// Clients that support workspace folders should set the `workspaceFolders` client capability.
17+
///
18+
/// - Returns: The set of currently open workspace folders. Returns nil if only a single file is
19+
/// open. Returns an empty array if a workspace is open but no folders are configured.
20+
public struct WorkspaceFoldersRequest: RequestType, Hashable {
21+
public static let method: String = "workspace/workspaceFolders"
22+
public typealias Response = [WorkspaceFolder]?
23+
}

Sources/SKTestSupport/SKSwiftPMTestWorkspace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ extension SKSwiftPMTestWorkspace {
120120

121121
extension SKSwiftPMTestWorkspace {
122122
public func openDocument(_ url: URL, language: Language) throws {
123-
sk.send(DidOpenTextDocument(textDocument: TextDocumentItem(
123+
sk.send(DidOpenTextDocumentNotification(textDocument: TextDocumentItem(
124124
uri: DocumentURI(url),
125125
language: language,
126126
version: 1,

Sources/SKTestSupport/SKTibsTestWorkspace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ extension SKTibsTestWorkspace {
8383

8484
extension SKTibsTestWorkspace {
8585
public func openDocument(_ url: URL, language: Language) throws {
86-
sk.send(DidOpenTextDocument(textDocument: TextDocumentItem(
86+
sk.send(DidOpenTextDocumentNotification(textDocument: TextDocumentItem(
8787
uri: DocumentURI(url),
8888
language: language,
8989
version: 1,

0 commit comments

Comments
 (0)