Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Sources/LanguageServerProtocol/BaseProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ public struct CancelParams: Hashable, Codable, Sendable {
public struct ProgressParams: Hashable, Codable, Sendable {
public var token: ProgressToken
public var value: LSPAny?

public init(token: ProgressToken, value: LSPAny? = nil) {
self.token = token
self.value = value
}
}

public struct LogTraceParams: Hashable, Codable, Sendable {
public var string: String
public var verbose: String?

public init(string: String, verbose: String? = nil) {
self.string = string
self.verbose = verbose
}
}

public enum TraceValue: String, Hashable, Codable, Sendable {
Expand Down
16 changes: 16 additions & 0 deletions Sources/LanguageServerProtocol/BasicStructures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ public struct Command: Codable, Hashable, Sendable {
public let title: String
public let command: String
public let arguments: [LSPAny]?

public init(title: String, command: String, arguments: [LSPAny]? = nil) {
self.title = title
self.command = command
self.arguments = arguments
}
}

public enum SymbolKind: Int, CaseIterable, Hashable, Codable, Sendable {
Expand Down Expand Up @@ -191,6 +197,11 @@ public struct TextDocumentPositionParams: Codable, Hashable, Sendable {
public struct LanguageStringPair: Codable, Hashable, Sendable {
public let language: LanguageIdentifier
public let value: String

public init(language: LanguageIdentifier, value: String) {
self.language = language
self.value = value
}
}

public typealias MarkedString = TwoTypeOption<String, LanguageStringPair>
Expand All @@ -209,6 +220,11 @@ extension MarkedString {
public struct MarkupContent: Codable, Hashable, Sendable {
public let kind: MarkupKind
public let value: String

public init(kind: MarkupKind, value: String) {
self.kind = kind
self.value = value
}
}

public struct LocationLink: Codable, Hashable, Sendable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public actor JSONRPCServerConnection: ServerConnection {
case .custom:
let params = try decodeRequestParams(LSPAny.self, from: data)
let reqHandler: ServerRequest.Handler<LSPAny> = makeHandler(handler)

yield(id: id, request: ServerRequest.custom(methodName, params, reqHandler))

}
Expand Down
28 changes: 18 additions & 10 deletions Sources/LanguageServerProtocol/Client/ServerConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ extension ServerConnection {
try await sendRequest(.completion(params, ClientRequest.NullHandler))
}

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

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

public func declaration(_ params: TextDocumentPositionParams) async throws -> DeclarationResponse
public func declaration(_ params: TextDocumentPositionParams) async throws
-> DeclarationResponse
{
try await sendRequest(.declaration(params, ClientRequest.NullHandler))
}
Expand All @@ -273,7 +274,8 @@ extension ServerConnection {
try await definition(params)
}

public func definition(_ params: TextDocumentPositionParams) async throws -> DefinitionResponse {
public func definition(_ params: TextDocumentPositionParams) async throws -> DefinitionResponse
{
try await sendRequest(.definition(params, ClientRequest.NullHandler))
}

Expand Down Expand Up @@ -309,7 +311,8 @@ extension ServerConnection {
try await documentSymbol(params)
}

public func documentSymbol(_ params: DocumentSymbolParams) async throws -> DocumentSymbolResponse
public func documentSymbol(_ params: DocumentSymbolParams) async throws
-> DocumentSymbolResponse
{
try await sendRequest(.documentSymbol(params, ClientRequest.NullHandler))
}
Expand Down Expand Up @@ -557,7 +560,8 @@ extension ServerConnection {
try await executeCommand(params)
}

public func executeCommand(_ params: ExecuteCommandParams) async throws -> ExecuteCommandResponse
public func executeCommand(_ params: ExecuteCommandParams) async throws
-> ExecuteCommandResponse
{
try await sendRequest(.workspaceExecuteCommand(params, ClientRequest.NullHandler))
}
Expand Down Expand Up @@ -659,7 +663,8 @@ extension ServerConnection {
try await selectionRange(params)
}

public func selectionRange(_ params: SelectionRangeParams) async throws -> SelectionRangeResponse
public func selectionRange(_ params: SelectionRangeParams) async throws
-> SelectionRangeResponse
{
try await sendRequest(.selectionRange(params, ClientRequest.NullHandler))
}
Expand Down Expand Up @@ -722,11 +727,14 @@ extension ServerConnection {
try await sendRequest(.inlayHintResolve(params, ClientRequest.NullHandler))
}

public func typeHierarchySubtypes(_ params: TypeHierarchySubtypesParams) async throws -> TypeHierarchySubtypesResponse {
public func typeHierarchySubtypes(_ params: TypeHierarchySubtypesParams) async throws
-> TypeHierarchySubtypesResponse
{
try await sendRequest(.typeHierarchySubtypes(params, ClientRequest.NullHandler))
}

public func typeHierarchySupertypes(_ params: TypeHierarchySupertypesParams) async throws -> TypeHierarchySupertypesResponse
public func typeHierarchySupertypes(_ params: TypeHierarchySupertypesParams) async throws
-> TypeHierarchySupertypesResponse
{
try await sendRequest(.typeHierarchySupertypes(params, ClientRequest.NullHandler))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public struct CallHierarchyIncomingCallsParams: Codable, Hashable, Sendable {
public struct CallHierarchyIncomingCall: Codable, Hashable, Sendable {
public let from: CallHierarchyItem
public let fromRanges: [LSPRange]

public init(
from: CallHierarchyItem, fromRanges: [LSPRange]
) {
self.from = from
self.fromRanges = fromRanges
}
}

public typealias CallHierarchyIncomingCallsResponse = [CallHierarchyIncomingCall]?
Expand All @@ -83,6 +90,11 @@ public typealias CallHierarchyOutgoingCallsParams = CallHierarchyIncomingCallsPa
public struct CallHierarchyOutgoingCall: Codable, Hashable, Sendable {
public let to: CallHierarchyItem
public let fromRanges: [LSPRange]

public init(to: CallHierarchyItem, fromRanges: [LSPRange]) {
self.to = to
self.fromRanges = fromRanges
}
}

public typealias CallHierarchyOutgoingCallsResponse = [CallHierarchyOutgoingCall]?
20 changes: 20 additions & 0 deletions Sources/LanguageServerProtocol/LanguageFeatures/CodeLens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@ public struct CodeLensWorkspaceClientCapabilities: Codable, Hashable, Sendable {
public struct CodeLensOptions: Codable, Hashable, Sendable {
public var workDoneProgress: Bool?
public var resolveProvider: Bool?

public init(workDoneProgress: Bool? = nil, resolveProvider: Bool? = nil) {
self.workDoneProgress = workDoneProgress
self.resolveProvider = resolveProvider
}
}

public struct CodeLensRegistrationOptions: Codable, Hashable, Sendable {
public var documentSelector: DocumentSelector?
public var workDoneProgress: Bool?
public var resolveProvider: Bool?

public init(
documentSelector: DocumentSelector? = nil, workDoneProgress: Bool? = nil,
resolveProvider: Bool? = nil
) {
self.documentSelector = documentSelector
self.workDoneProgress = workDoneProgress
self.resolveProvider = resolveProvider
}
}

public struct CodeLensParams: Codable, Hashable, Sendable {
Expand All @@ -40,6 +54,12 @@ public struct CodeLens: Codable, Hashable, Sendable {
public var range: LSPRange
public var command: Command?
public var data: LSPAny?

public init(range: LSPRange, command: Command? = nil, data: LSPAny? = nil) {
self.range = range
self.command = command
self.data = data
}
}

public typealias CodeLensResponse = [CodeLens]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public struct ColorPresentation: Codable, Hashable, Sendable {
public let label: String
public let textEdit: TextEdit?
public let additionalTextEdits: [TextEdit]?

public init(
label: String, textEdit: TextEdit? = nil, additionalTextEdits: [TextEdit]? = nil
) {
self.label = label
self.textEdit = textEdit
self.additionalTextEdits = additionalTextEdits
}
}

public typealias ColorPresentationResponse = [ColorPresentation]
10 changes: 10 additions & 0 deletions Sources/LanguageServerProtocol/LanguageFeatures/Completion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ public struct CompletionRegistrationOptions: Codable {
public let documentSelector: DocumentSelector?
public let triggerCharacters: [String]?
public let resolveProvider: Bool?

public init(
documentSelector: DocumentSelector? = nil,
triggerCharacters: [String]? = nil,
resolveProvider: Bool? = nil
) {
self.documentSelector = documentSelector
self.triggerCharacters = triggerCharacters
self.resolveProvider = resolveProvider
}
}

public enum InsertTextMode: Int, CaseIterable, Codable, Hashable, Sendable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@ public struct Color: Codable, Hashable, Sendable {
public let green: Float
public let blue: Float
public let alpha: Float

public init(red: Float, green: Float, blue: Float, alpha: Float) {
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
}
}

public struct ColorInformation: Codable, Hashable, Sendable {
public let range: LSPRange
public let color: Color

public init(range: LSPRange, color: Color) {
self.range = range
self.color = color
}
}

public typealias DocumentColorResponse = [ColorInformation]
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ public typealias DocumentHighlightOptions = WorkDoneProgressOptions
public struct DocumentHighlightRegistrationOptions: Codable, Hashable, Sendable {
public var documentSelector: DocumentSelector?
public var workDoneProgress: Bool?

public init(
documentSelector: DocumentSelector? = nil, workDoneProgress: Bool? = nil
) {
self.documentSelector = documentSelector
self.workDoneProgress = workDoneProgress
}
}

public struct DocumentHighlightParams: Codable, Hashable, Sendable {
Expand Down Expand Up @@ -35,6 +42,13 @@ public enum DocumentHighlightKind: Int, CaseIterable, Codable, Hashable, Sendabl
public struct DocumentHighlight: Codable, Hashable, Sendable {
public var range: LSPRange
public var kind: DocumentHighlightKind?

public init(
range: LSPRange, kind: DocumentHighlightKind? = nil
) {
self.range = range
self.kind = kind
}
}

public typealias DocumentHighlightResponse = [DocumentHighlight]?
12 changes: 12 additions & 0 deletions Sources/LanguageServerProtocol/LanguageFeatures/DocumentLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public struct DocumentLinkClientCapabilities: Codable, Hashable, Sendable {
public struct DocumentLinkOptions: Codable, Hashable, Sendable {
public var workDoneProgress: Bool?
public var resolveProvider: Bool?

public init(workDoneProgress: Bool? = nil, resolveProvider: Bool? = nil) {
self.workDoneProgress = workDoneProgress
self.resolveProvider = resolveProvider
}
}

public struct DocumentLinkRegistrationOptions: Codable, Hashable, Sendable {
Expand All @@ -40,6 +45,13 @@ public struct DocumentLinkRegistrationOptions: Codable, Hashable, Sendable {
public struct DocumentLinkParams: Codable, Hashable, Sendable {
public var workDoneToken: ProgressToken?
public var partialResultToken: ProgressToken?

public init(
workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil
) {
self.workDoneToken = workDoneToken
self.partialResultToken = partialResultToken
}
}

public struct DocumentLink: Codable, Hashable, Sendable {
Expand Down
11 changes: 11 additions & 0 deletions Sources/LanguageServerProtocol/LanguageFeatures/FoldingRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public struct FoldingRange: Codable, Hashable, Sendable {
public let endLine: Int
public let endCharacter: Int?
public let kind: FoldingRangeKind?

public init(
startLine: Int, startCharacter: Int? = nil, endLine: Int,
endCharacter: Int? = nil, kind: FoldingRangeKind? = nil
) {
self.startLine = startLine
self.startCharacter = startCharacter
self.endLine = endLine
self.endCharacter = endCharacter
self.kind = kind
}
}

public typealias FoldingRangeResponse = [FoldingRange]?
14 changes: 14 additions & 0 deletions Sources/LanguageServerProtocol/LanguageFeatures/Rename.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public struct RenameClientCapabilities: Codable, Hashable, Sendable {
public struct RenameOptions: Codable, Hashable, Sendable {
public var workDoneProgress: Bool?
public var prepareProvider: Bool?

public init(workDoneProgress: Bool? = nil, prepareProvider: Bool? = nil) {
self.workDoneProgress = workDoneProgress
self.prepareProvider = prepareProvider
}
}

public typealias PrepareRenameParams = TextDocumentPositionParams
Expand All @@ -44,10 +49,19 @@ public struct RenameParams: Codable, Hashable, Sendable {
public struct RangeWithPlaceholder: Codable, Hashable, Sendable {
public let range: LSPRange
public let placeholder: String

public init(range: LSPRange, placeholder: String) {
self.range = range
self.placeholder = placeholder
}
}

public struct PrepareRenameDefaultBehavior: Codable, Hashable, Sendable {
public let defaultBehavior: Bool

public init(defaultBehavior: Bool) {
self.defaultBehavior = defaultBehavior
}
}

public typealias PrepareRenameResponse = ThreeTypeOption<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public struct SelectionRangeParams: Codable, Hashable, Sendable {
public final class SelectionRange: Codable, Sendable {
public let range: LSPRange
public let parent: SelectionRange?

public init(range: LSPRange, parent: SelectionRange?) {
self.range = range
self.parent = parent
}
}

extension SelectionRange: Equatable {
Expand Down
Loading