Skip to content

Commit

Permalink
Merge pull request #13 from koliyo/feature/consistent-lsp-naming
Browse files Browse the repository at this point in the history
Make LSP method names more consistent
  • Loading branch information
mattmassicotte authored Oct 27, 2023
2 parents 480508d + c85bae0 commit 9bfef73
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 41 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 @@ -139,7 +137,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 @@ -171,6 +169,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 @@ -237,7 +239,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: DidOpenTextDocumentParams) async throws {
try await sendNotification(.textDocumentDidOpen(params))
}

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

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

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

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

func didSaveTextDocument(params: DidSaveTextDocumentParams) async throws {
try await sendNotification(.didSaveTextDocument(params))
func textDocumentDidSave(params: DidSaveTextDocumentParams) 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 @@ -242,7 +242,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,31 @@
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 init(ranges: [LSPRange], wordPattern: String? = nil) {
self.ranges = ranges
self.wordPattern = wordPattern
}
}


public typealias LinkedEditingRangeResponse = LinkedEditingRanges?
39 changes: 39 additions & 0 deletions Sources/LanguageServerProtocol/LanguageFeatures/Moniker.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
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 enum MonikerKind : Codable, Sendable{
case _import
case export
case 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]?
33 changes: 18 additions & 15 deletions Sources/LanguageServerProtocol/LanguageServerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ 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 textDocumentDidOpen(DidOpenTextDocumentParams)
case textDocumentDidClose(DidCloseTextDocumentParams)
case textDocumentWillSave(WillSaveTextDocumentParams)
case textDocumentDidSave(DidSaveTextDocumentParams)
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 @@ -143,7 +140,7 @@ public enum ClientRequest: Sendable, Hashable {
case workspaceWillDeleteFiles(DeleteFilesParams)
case workspaceSymbol(WorkspaceSymbolParams)
case workspaceSymbolResolve(WorkspaceSymbol)
case willSaveWaitUntilTextDocument(WillSaveTextDocumentParams)
case textDocumentWillSaveWaitUntil(WillSaveTextDocumentParams)
case completion(CompletionParams)
case completionItemResolve(CompletionItem)
case hover(TextDocumentPositionParams)
Expand All @@ -160,6 +157,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 @@ -201,7 +200,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 @@ -233,6 +232,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

0 comments on commit 9bfef73

Please sign in to comment.