Skip to content

Commit 3443a4d

Browse files
authored
Add missing public initializers for LSP entities (#27)
* add initializers for public LSP protocol entities * run swift-format
1 parent 9ab3a08 commit 3443a4d

22 files changed

+341
-19
lines changed

Sources/LanguageServerProtocol/BaseProtocol.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,21 @@ public struct CancelParams: Hashable, Codable, Sendable {
2424
public struct ProgressParams: Hashable, Codable, Sendable {
2525
public var token: ProgressToken
2626
public var value: LSPAny?
27+
28+
public init(token: ProgressToken, value: LSPAny? = nil) {
29+
self.token = token
30+
self.value = value
31+
}
2732
}
2833

2934
public struct LogTraceParams: Hashable, Codable, Sendable {
3035
public var string: String
3136
public var verbose: String?
37+
38+
public init(string: String, verbose: String? = nil) {
39+
self.string = string
40+
self.verbose = verbose
41+
}
3242
}
3343

3444
public enum TraceValue: String, Hashable, Codable, Sendable {

Sources/LanguageServerProtocol/BasicStructures.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ public struct Command: Codable, Hashable, Sendable {
136136
public let title: String
137137
public let command: String
138138
public let arguments: [LSPAny]?
139+
140+
public init(title: String, command: String, arguments: [LSPAny]? = nil) {
141+
self.title = title
142+
self.command = command
143+
self.arguments = arguments
144+
}
139145
}
140146

141147
public enum SymbolKind: Int, CaseIterable, Hashable, Codable, Sendable {
@@ -191,6 +197,11 @@ public struct TextDocumentPositionParams: Codable, Hashable, Sendable {
191197
public struct LanguageStringPair: Codable, Hashable, Sendable {
192198
public let language: LanguageIdentifier
193199
public let value: String
200+
201+
public init(language: LanguageIdentifier, value: String) {
202+
self.language = language
203+
self.value = value
204+
}
194205
}
195206

196207
public typealias MarkedString = TwoTypeOption<String, LanguageStringPair>
@@ -209,6 +220,11 @@ extension MarkedString {
209220
public struct MarkupContent: Codable, Hashable, Sendable {
210221
public let kind: MarkupKind
211222
public let value: String
223+
224+
public init(kind: MarkupKind, value: String) {
225+
self.kind = kind
226+
self.value = value
227+
}
212228
}
213229

214230
public struct LocationLink: Codable, Hashable, Sendable {

Sources/LanguageServerProtocol/Client/JSONRPCServerConnection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public actor JSONRPCServerConnection: ServerConnection {
353353
case .custom:
354354
let params = try decodeRequestParams(LSPAny.self, from: data)
355355
let reqHandler: ServerRequest.Handler<LSPAny> = makeHandler(handler)
356-
356+
357357
yield(id: id, request: ServerRequest.custom(methodName, params, reqHandler))
358358

359359
}

Sources/LanguageServerProtocol/Client/ServerConnection.swift

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ extension ServerConnection {
231231
try await sendRequest(.completion(params, ClientRequest.NullHandler))
232232
}
233233

234-
public func completeItemResolve(_ params: CompletionItem) async throws -> CompletionItem {
235-
try await sendRequest(.completionItemResolve(params, ClientRequest.NullHandler))
236-
}
234+
public func completeItemResolve(_ params: CompletionItem) async throws -> CompletionItem {
235+
try await sendRequest(.completionItemResolve(params, ClientRequest.NullHandler))
236+
}
237237

238238
@available(*, deprecated, renamed: "hover(_:)")
239239
public func hover(params: TextDocumentPositionParams) async throws -> HoverResponse {
@@ -263,7 +263,8 @@ extension ServerConnection {
263263
try await declaration(params)
264264
}
265265

266-
public func declaration(_ params: TextDocumentPositionParams) async throws -> DeclarationResponse
266+
public func declaration(_ params: TextDocumentPositionParams) async throws
267+
-> DeclarationResponse
267268
{
268269
try await sendRequest(.declaration(params, ClientRequest.NullHandler))
269270
}
@@ -273,7 +274,8 @@ extension ServerConnection {
273274
try await definition(params)
274275
}
275276

276-
public func definition(_ params: TextDocumentPositionParams) async throws -> DefinitionResponse {
277+
public func definition(_ params: TextDocumentPositionParams) async throws -> DefinitionResponse
278+
{
277279
try await sendRequest(.definition(params, ClientRequest.NullHandler))
278280
}
279281

@@ -309,7 +311,8 @@ extension ServerConnection {
309311
try await documentSymbol(params)
310312
}
311313

312-
public func documentSymbol(_ params: DocumentSymbolParams) async throws -> DocumentSymbolResponse
314+
public func documentSymbol(_ params: DocumentSymbolParams) async throws
315+
-> DocumentSymbolResponse
313316
{
314317
try await sendRequest(.documentSymbol(params, ClientRequest.NullHandler))
315318
}
@@ -557,7 +560,8 @@ extension ServerConnection {
557560
try await executeCommand(params)
558561
}
559562

560-
public func executeCommand(_ params: ExecuteCommandParams) async throws -> ExecuteCommandResponse
563+
public func executeCommand(_ params: ExecuteCommandParams) async throws
564+
-> ExecuteCommandResponse
561565
{
562566
try await sendRequest(.workspaceExecuteCommand(params, ClientRequest.NullHandler))
563567
}
@@ -659,7 +663,8 @@ extension ServerConnection {
659663
try await selectionRange(params)
660664
}
661665

662-
public func selectionRange(_ params: SelectionRangeParams) async throws -> SelectionRangeResponse
666+
public func selectionRange(_ params: SelectionRangeParams) async throws
667+
-> SelectionRangeResponse
663668
{
664669
try await sendRequest(.selectionRange(params, ClientRequest.NullHandler))
665670
}
@@ -722,11 +727,14 @@ extension ServerConnection {
722727
try await sendRequest(.inlayHintResolve(params, ClientRequest.NullHandler))
723728
}
724729

725-
public func typeHierarchySubtypes(_ params: TypeHierarchySubtypesParams) async throws -> TypeHierarchySubtypesResponse {
730+
public func typeHierarchySubtypes(_ params: TypeHierarchySubtypesParams) async throws
731+
-> TypeHierarchySubtypesResponse
732+
{
726733
try await sendRequest(.typeHierarchySubtypes(params, ClientRequest.NullHandler))
727734
}
728735

729-
public func typeHierarchySupertypes(_ params: TypeHierarchySupertypesParams) async throws -> TypeHierarchySupertypesResponse
736+
public func typeHierarchySupertypes(_ params: TypeHierarchySupertypesParams) async throws
737+
-> TypeHierarchySupertypesResponse
730738
{
731739
try await sendRequest(.typeHierarchySupertypes(params, ClientRequest.NullHandler))
732740
}

Sources/LanguageServerProtocol/LanguageFeatures/CallHeirarchy.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ public struct CallHierarchyIncomingCallsParams: Codable, Hashable, Sendable {
7474
public struct CallHierarchyIncomingCall: Codable, Hashable, Sendable {
7575
public let from: CallHierarchyItem
7676
public let fromRanges: [LSPRange]
77+
78+
public init(
79+
from: CallHierarchyItem, fromRanges: [LSPRange]
80+
) {
81+
self.from = from
82+
self.fromRanges = fromRanges
83+
}
7784
}
7885

7986
public typealias CallHierarchyIncomingCallsResponse = [CallHierarchyIncomingCall]?
@@ -83,6 +90,11 @@ public typealias CallHierarchyOutgoingCallsParams = CallHierarchyIncomingCallsPa
8390
public struct CallHierarchyOutgoingCall: Codable, Hashable, Sendable {
8491
public let to: CallHierarchyItem
8592
public let fromRanges: [LSPRange]
93+
94+
public init(to: CallHierarchyItem, fromRanges: [LSPRange]) {
95+
self.to = to
96+
self.fromRanges = fromRanges
97+
}
8698
}
8799

88100
public typealias CallHierarchyOutgoingCallsResponse = [CallHierarchyOutgoingCall]?

Sources/LanguageServerProtocol/LanguageFeatures/CodeLens.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,26 @@ public struct CodeLensWorkspaceClientCapabilities: Codable, Hashable, Sendable {
1313
public struct CodeLensOptions: Codable, Hashable, Sendable {
1414
public var workDoneProgress: Bool?
1515
public var resolveProvider: Bool?
16+
17+
public init(workDoneProgress: Bool? = nil, resolveProvider: Bool? = nil) {
18+
self.workDoneProgress = workDoneProgress
19+
self.resolveProvider = resolveProvider
20+
}
1621
}
1722

1823
public struct CodeLensRegistrationOptions: Codable, Hashable, Sendable {
1924
public var documentSelector: DocumentSelector?
2025
public var workDoneProgress: Bool?
2126
public var resolveProvider: Bool?
27+
28+
public init(
29+
documentSelector: DocumentSelector? = nil, workDoneProgress: Bool? = nil,
30+
resolveProvider: Bool? = nil
31+
) {
32+
self.documentSelector = documentSelector
33+
self.workDoneProgress = workDoneProgress
34+
self.resolveProvider = resolveProvider
35+
}
2236
}
2337

2438
public struct CodeLensParams: Codable, Hashable, Sendable {
@@ -40,6 +54,12 @@ public struct CodeLens: Codable, Hashable, Sendable {
4054
public var range: LSPRange
4155
public var command: Command?
4256
public var data: LSPAny?
57+
58+
public init(range: LSPRange, command: Command? = nil, data: LSPAny? = nil) {
59+
self.range = range
60+
self.command = command
61+
self.data = data
62+
}
4363
}
4464

4565
public typealias CodeLensResponse = [CodeLens]?

Sources/LanguageServerProtocol/LanguageFeatures/ColorPresentation.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ public struct ColorPresentation: Codable, Hashable, Sendable {
2323
public let label: String
2424
public let textEdit: TextEdit?
2525
public let additionalTextEdits: [TextEdit]?
26+
27+
public init(
28+
label: String, textEdit: TextEdit? = nil, additionalTextEdits: [TextEdit]? = nil
29+
) {
30+
self.label = label
31+
self.textEdit = textEdit
32+
self.additionalTextEdits = additionalTextEdits
33+
}
2634
}
2735

2836
public typealias ColorPresentationResponse = [ColorPresentation]

Sources/LanguageServerProtocol/LanguageFeatures/Completion.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ public struct CompletionRegistrationOptions: Codable {
243243
public let documentSelector: DocumentSelector?
244244
public let triggerCharacters: [String]?
245245
public let resolveProvider: Bool?
246+
247+
public init(
248+
documentSelector: DocumentSelector? = nil,
249+
triggerCharacters: [String]? = nil,
250+
resolveProvider: Bool? = nil
251+
) {
252+
self.documentSelector = documentSelector
253+
self.triggerCharacters = triggerCharacters
254+
self.resolveProvider = resolveProvider
255+
}
246256
}
247257

248258
public enum InsertTextMode: Int, CaseIterable, Codable, Hashable, Sendable {

Sources/LanguageServerProtocol/LanguageFeatures/DocumentColor.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,23 @@ public struct Color: Codable, Hashable, Sendable {
2222
public let green: Float
2323
public let blue: Float
2424
public let alpha: Float
25+
26+
public init(red: Float, green: Float, blue: Float, alpha: Float) {
27+
self.red = red
28+
self.green = green
29+
self.blue = blue
30+
self.alpha = alpha
31+
}
2532
}
2633

2734
public struct ColorInformation: Codable, Hashable, Sendable {
2835
public let range: LSPRange
2936
public let color: Color
37+
38+
public init(range: LSPRange, color: Color) {
39+
self.range = range
40+
self.color = color
41+
}
3042
}
3143

3244
public typealias DocumentColorResponse = [ColorInformation]

Sources/LanguageServerProtocol/LanguageFeatures/DocumentHighlight.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ public typealias DocumentHighlightOptions = WorkDoneProgressOptions
77
public struct DocumentHighlightRegistrationOptions: Codable, Hashable, Sendable {
88
public var documentSelector: DocumentSelector?
99
public var workDoneProgress: Bool?
10+
11+
public init(
12+
documentSelector: DocumentSelector? = nil, workDoneProgress: Bool? = nil
13+
) {
14+
self.documentSelector = documentSelector
15+
self.workDoneProgress = workDoneProgress
16+
}
1017
}
1118

1219
public struct DocumentHighlightParams: Codable, Hashable, Sendable {
@@ -35,6 +42,13 @@ public enum DocumentHighlightKind: Int, CaseIterable, Codable, Hashable, Sendabl
3542
public struct DocumentHighlight: Codable, Hashable, Sendable {
3643
public var range: LSPRange
3744
public var kind: DocumentHighlightKind?
45+
46+
public init(
47+
range: LSPRange, kind: DocumentHighlightKind? = nil
48+
) {
49+
self.range = range
50+
self.kind = kind
51+
}
3852
}
3953

4054
public typealias DocumentHighlightResponse = [DocumentHighlight]?

0 commit comments

Comments
 (0)