Skip to content

Commit

Permalink
Make LSP method names more consistent
Browse files Browse the repository at this point in the history
Both internally and against the spec
Also add missing linkedEditingRange and moniker methods
  • Loading branch information
koliyo committed Oct 20, 2023
1 parent 1191a6d commit 8a00cc9
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 47 deletions.
22 changes: 12 additions & 10 deletions Sources/LanguageServerProtocol/Additions/JSONRPCServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,23 @@ public actor JSONRPCServer: Server {

public func sendNotification(_ notif: ClientNotification) async throws {
let method = notif.method.rawValue

switch notif {
case .initialized(let params):
try await session.sendNotification(params, method: method)
case .exit:
try await session.sendNotification(method: method)
case .textDocumentDidChange(let params):
try await session.sendNotification(params, method: method)
case .didOpenTextDocument(let params):
try await session.sendNotification(params, method: method)
case .didChangeTextDocument(let params):
case .textDocumentDidOpen(let params):
try await session.sendNotification(params, method: method)
case .didCloseTextDocument(let params):
case .textDocumentDidClose(let params):
try await session.sendNotification(params, method: method)
case .willSaveTextDocument(let params):
case .textDocumentWillSave(let params):
try await session.sendNotification(params, method: method)
case .didSaveTextDocument(let params):
case .textDocumentDidSave(let params):
try await session.sendNotification(params, method: method)
case .didChangeWatchedFiles(let params):
case .workspaceDidChangeWatchedFiles(let params):
try await session.sendNotification(params, method: method)
case .protocolCancelRequest(let params):
try await session.sendNotification(params, method: method)
Expand Down Expand Up @@ -137,7 +135,7 @@ public actor JSONRPCServer: Server {
return try await session.response(to: method, params: params)
case .workspaceSymbolResolve(let params):
return try await session.response(to: method, params: params)
case .willSaveWaitUntilTextDocument(let params):
case .textDocumentWillSaveWaitUntil(let params):
return try await session.response(to: method, params: params)
case .completion(let params):
return try await session.response(to: method, params: params)
Expand Down Expand Up @@ -169,6 +167,10 @@ public actor JSONRPCServer: Server {
return try await session.response(to: method, params: params)
case .selectionRange(let params):
return try await session.response(to: method, params: params)
case .linkedEditingRange(let params):
return try await session.response(to: method, params: params)
case .moniker(let params):
return try await session.response(to: method, params: params)
case .prepareCallHierarchy(let params):
return try await session.response(to: method, params: params)
case .prepareRename(let params):
Expand Down Expand Up @@ -231,7 +233,7 @@ public actor JSONRPCServer: Server {
switch method {
case .windowLogMessage:
let params = try decodeNotificationParams(LogMessageParams.self, from: data)

notificationContinuation.yield(.windowLogMessage(params))
case .windowShowMessage:
let params = try decodeNotificationParams(ShowMessageParams.self, from: data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension ClientRequest {
return true
case .workspaceWillDeleteFiles:
return true
case .willSaveWaitUntilTextDocument:
case .textDocumentWillSaveWaitUntil:
return true
case .custom:
return true
Expand Down
30 changes: 15 additions & 15 deletions Sources/LanguageServerProtocol/Additions/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,32 @@ public extension Server {
try await sendNotification(.protocolSetTrace(params))
}

func didOpenTextDocument(params: DidOpenTextDocumentParams) async throws {
try await sendNotification(.didOpenTextDocument(params))
func textDocumentDidOpen(params: TextDocumentDidOpenParams) async throws {
try await sendNotification(.textDocumentDidOpen(params))
}

func didChangeTextDocument(params: DidChangeTextDocumentParams) async throws {
try await sendNotification(.didChangeTextDocument(params))
func textDocumentDidChange(params: TextDocumentDidChangeParams) async throws {
try await sendNotification(.textDocumentDidChange(params))
}

func didCloseTextDocument(params: DidCloseTextDocumentParams) async throws {
try await sendNotification(.didCloseTextDocument(params))
func textDocumentDidClose(params: TextDocumentDidCloseParams) async throws {
try await sendNotification(.textDocumentDidClose(params))
}

func willSaveTextDocument(params: WillSaveTextDocumentParams) async throws {
try await sendNotification(.willSaveTextDocument(params))
func textDocumentWillSave(params: TextDocumentWillSaveParams) async throws {
try await sendNotification(.textDocumentWillSave(params))
}

func willSaveWaitUntilTextDocument(params: WillSaveTextDocumentParams) async throws -> WillSaveWaitUntilResponse {
try await sendRequest(.willSaveWaitUntilTextDocument(params))
func textDocumentWillSaveWaitUntil(params: TextDocumentWillSaveParams) async throws -> WillSaveWaitUntilResponse {
try await sendRequest(.textDocumentWillSaveWaitUntil(params))
}

func didSaveTextDocument(params: DidSaveTextDocumentParams) async throws {
try await sendNotification(.didSaveTextDocument(params))
func textDocumentDidSave(params: TextDocumentDidSaveParams) async throws {
try await sendNotification(.textDocumentDidSave(params))
}

func didChangeWatchedFiles(params: DidChangeWatchedFilesParams) async throws {
try await sendNotification(.didChangeWatchedFiles(params))
func workspaceDidChangeWatchedFiles(params: DidChangeWatchedFilesParams) async throws {
try await sendNotification(.workspaceDidChangeWatchedFiles(params))
}

func callHierarchyIncomingCalls(params: CallHierarchyIncomingCallsParams) async throws -> CallHierarchyIncomingCallsResponse {
Expand Down Expand Up @@ -238,7 +238,7 @@ public extension Server {
func diagnostics(params: DocumentDiagnosticParams) async throws -> DocumentDiagnosticReport {
try await sendRequest(.diagnostics(params))
}

func selectionRange(params: SelectionRangeParams) async throws -> SelectionRangeResponse {
try await sendRequest(.selectionRange(params))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
import Foundation

public typealias LinkedEditingRangeClientCapabilities = DynamicRegistrationClientCapabilities

public struct LinkedEditingRangeParams: Codable, Hashable, Sendable {
public let workDoneToken: ProgressToken?
public let partialResultToken: ProgressToken?

public let textDocument: TextDocumentIdentifier
public let position: Position

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

public struct LinkedEditingRanges : Codable, Sendable {
public let ranges: [LSPRange]
public let wordPattern: String?
}


public typealias LinkedEditingRangeResponse = LinkedEditingRanges?
47 changes: 47 additions & 0 deletions Sources/LanguageServerProtocol/LanguageFeatures/Moniker.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
import Foundation

public typealias MonikerClientCapabilities = DynamicRegistrationClientCapabilities

public struct MonikerParams: Codable, Hashable, Sendable {
public let workDoneToken: ProgressToken?
public let partialResultToken: ProgressToken?

public let textDocument: TextDocumentIdentifier
public let position: Position

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

public enum UniquenessLevel: Codable, Sendable {
case document
case project
case group
case scheme
case global
// public static let document = "document"
// public static let project = "project"
// public static let group = "group"
// public static let scheme = "scheme"
// public static let global = "global"
}

public enum MonikerKind : Codable, Sendable{
case _import
case export
case local
// public static let _import = "import"
// public static let export = "export"
// public static let local = "local"
}

public struct Moniker : Codable, Sendable {
public let scheme: String
public let identifier: String
public let unique: UniquenessLevel
public let kind: MonikerKind?
}


public typealias MonikerResponse = [Moniker]?
35 changes: 19 additions & 16 deletions Sources/LanguageServerProtocol/LanguageServerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ public enum ClientNotification: Sendable, Hashable {

case initialized(InitializedParams)
case exit
case textDocumentDidChange(DidChangeTextDocumentParams)
case didOpenTextDocument(DidOpenTextDocumentParams)
case didChangeTextDocument(DidChangeTextDocumentParams)
case didCloseTextDocument(DidCloseTextDocumentParams)
case willSaveTextDocument(WillSaveTextDocumentParams)
case didSaveTextDocument(DidSaveTextDocumentParams)
case didChangeWatchedFiles(DidChangeWatchedFilesParams)
case textDocumentDidChange(TextDocumentDidChangeParams)
case textDocumentDidOpen(TextDocumentDidOpenParams)
case textDocumentDidClose(TextDocumentDidCloseParams)
case textDocumentWillSave(TextDocumentWillSaveParams)
case textDocumentDidSave(TextDocumentDidSaveParams)
case protocolCancelRequest(CancelParams)
case protocolSetTrace(SetTraceParams)
case windowWorkDoneProgressCancel(WorkDoneProgressCancelParams)
case workspaceDidChangeWatchedFiles(DidChangeWatchedFilesParams)
case workspaceDidChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams)
case workspaceDidChangeConfiguration(DidChangeConfigurationParams)
case workspaceDidCreateFiles(CreateFilesParams)
Expand All @@ -49,17 +48,15 @@ public enum ClientNotification: Sendable, Hashable {
return .exit
case .textDocumentDidChange:
return .textDocumentDidChange
case .didOpenTextDocument:
case .textDocumentDidOpen:
return .textDocumentDidOpen
case .didCloseTextDocument:
case .textDocumentDidClose:
return .textDocumentDidClose
case .willSaveTextDocument:
case .textDocumentWillSave:
return .textDocumentWillSave
case .didChangeTextDocument:
return .textDocumentDidChange
case .didSaveTextDocument:
case .textDocumentDidSave:
return .textDocumentDidSave
case .didChangeWatchedFiles:
case .workspaceDidChangeWatchedFiles:
return .workspaceDidChangeWatchedFiles
case .protocolCancelRequest:
return .protocolCancelRequest
Expand Down Expand Up @@ -139,7 +136,7 @@ public enum ClientRequest: Sendable, Hashable {
case workspaceWillDeleteFiles(DeleteFilesParams)
case workspaceSymbol(WorkspaceSymbolParams)
case workspaceSymbolResolve(WorkspaceSymbol)
case willSaveWaitUntilTextDocument(WillSaveTextDocumentParams)
case textDocumentWillSaveWaitUntil(TextDocumentWillSaveParams)
case completion(CompletionParams)
case completionItemResolve(CompletionItem)
case hover(TextDocumentPositionParams)
Expand All @@ -156,6 +153,8 @@ public enum ClientRequest: Sendable, Hashable {
case codeLens(CodeLensParams)
case codeLensResolve(CodeLens)
case selectionRange(SelectionRangeParams)
case linkedEditingRange(LinkedEditingRangeParams)
case moniker(MonikerParams)
case prepareCallHierarchy(CallHierarchyPrepareParams)
case prepareRename(PrepareRenameParams)
case rename(RenameParams)
Expand Down Expand Up @@ -193,7 +192,7 @@ public enum ClientRequest: Sendable, Hashable {
return .workspaceSymbol
case .workspaceSymbolResolve:
return .workspaceSymbolResolve
case .willSaveWaitUntilTextDocument:
case .textDocumentWillSaveWaitUntil:
return .textDocumentWillSaveWaitUntil
case .completion:
return .textDocumentCompletion
Expand Down Expand Up @@ -225,6 +224,10 @@ public enum ClientRequest: Sendable, Hashable {
return .codeLensResolve
case .selectionRange:
return .textDocumentSelectionRange
case .linkedEditingRange:
return .textDocumentLinkedEditingRange
case .moniker:
return .textDocumentMoniker
case .prepareCallHierarchy:
return .textDocumentPrepareCallHierarchy
case .prepareRename:
Expand Down
10 changes: 5 additions & 5 deletions Sources/LanguageServerProtocol/TextSynchronization.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public struct DidOpenTextDocumentParams: Codable, Hashable, Sendable {
public struct TextDocumentDidOpenParams: Codable, Hashable, Sendable {
public let textDocument: TextDocumentItem

public init(textDocument: TextDocumentItem) {
Expand All @@ -20,7 +20,7 @@ public struct TextDocumentContentChangeEvent: Codable, Hashable, Sendable {
}
}

public struct DidChangeTextDocumentParams: Codable, Hashable, Sendable {
public struct TextDocumentDidChangeParams: Codable, Hashable, Sendable {
public let textDocument: VersionedTextDocumentIdentifier
public let contentChanges: [TextDocumentContentChangeEvent]

Expand All @@ -45,7 +45,7 @@ public struct TextDocumentChangeRegistrationOptions: Codable, Hashable, Sendable
public let syncKind: TextDocumentSyncKind
}

public struct DidSaveTextDocumentParams: Codable, Hashable, Sendable {
public struct TextDocumentDidSaveParams: Codable, Hashable, Sendable {
public let textDocument: TextDocumentIdentifier
public let text: String?

Expand All @@ -67,7 +67,7 @@ public struct TextDocumentSaveRegistrationOptions: Codable, Hashable, Sendable {
public let includeText: Bool?
}

public struct DidCloseTextDocumentParams: Codable, Hashable, Sendable {
public struct TextDocumentDidCloseParams: Codable, Hashable, Sendable {
public let textDocument: TextDocumentIdentifier

public init(textDocument: TextDocumentIdentifier) {
Expand All @@ -87,7 +87,7 @@ public enum TextDocumentSaveReason: Int, Codable, Hashable, Sendable {
case focusOut = 3
}

public struct WillSaveTextDocumentParams: Codable, Hashable, Sendable {
public struct TextDocumentWillSaveParams: Codable, Hashable, Sendable {
public let textDocument: TextDocumentIdentifier
public let reason: TextDocumentSaveReason

Expand Down

0 comments on commit 8a00cc9

Please sign in to comment.