From 7a1550c2d0d76535c0c02cbd196cbc28ec0d30e2 Mon Sep 17 00:00:00 2001 From: Kishikawa Katsumi Date: Fri, 12 Jun 2026 04:45:18 +0900 Subject: [PATCH] Add signatureHelp (parameter hints) over the WebSocket API sourcekit-lsp (main) now implements textDocument/signatureHelp, so expose it: a `signatureHelp` method that forwards the cursor position and returns the SignatureHelp response (signatures, parameters, activeParameter) to the client. This backs Xcode-style parameter hints in the editor. Co-Authored-By: Claude Opus 4.8 (1M context) --- Sources/App/Controllers/LanguageServer.swift | 12 +++++++++ Sources/App/routes.swift | 28 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Sources/App/Controllers/LanguageServer.swift b/Sources/App/Controllers/LanguageServer.swift index 6ab1bf8..654644a 100644 --- a/Sources/App/Controllers/LanguageServer.swift +++ b/Sources/App/Controllers/LanguageServer.swift @@ -196,6 +196,18 @@ final class LanguageServer { } } + func sendSignatureHelpRequest(documentPath: String, line: Int, character: Int, completion: @escaping (Result) -> Void) { + let identifier = URL(fileURLWithPath: documentPath) + + let signatureHelpRequest = SignatureHelpRequest( + textDocument: TextDocumentIdentifier(DocumentURI(identifier)), + position: Position(line: line, utf16index: character) + ) + _ = connection.send(signatureHelpRequest) { + completion($0) + } + } + func sendDefinitionRequest(documentPath: String, line: Int, character: Int, completion: @escaping (Result) -> Void) { let identifier = URL(fileURLWithPath: documentPath) diff --git a/Sources/App/routes.swift b/Sources/App/routes.swift index 0cc4799..8524fde 100644 --- a/Sources/App/routes.swift +++ b/Sources/App/routes.swift @@ -53,6 +53,13 @@ func routes(_ app: Application) throws { let value: LanguageServerProtocol.CompletionRequest.Response? } + typealias SignatureHelpRequestMessage = HoverRequest + struct SignatureHelpResponse: Codable { + let method: String + let id: Int + let value: LanguageServerProtocol.SignatureHelpRequest.Response + } + struct DiagnosticsNotification: Codable { let method: String let value: PublishDiagnosticsNotification @@ -206,6 +213,27 @@ func routes(_ app: Application) throws { guard let json = String(data: data, encoding: .utf8) else { return } ws.send(json) } + case _ where text.hasPrefix(#"{"method":"signatureHelp""#): + guard let request = try? decoder.decode(SignatureHelpRequestMessage.self, from: data) else { return } + languageServer?.sendSignatureHelpRequest( + documentPath: documentPath, line: request.row, character: request.column + ) { (result) in + let value: LanguageServerProtocol.SignatureHelpRequest.Response + switch result { + case .success(let response): + value = response + case .failure: + value = nil + } + let signatureHelpResponse = SignatureHelpResponse( + method: "signatureHelp", + id: request.id, + value: value + ) + guard let data = try? encoder.encode(signatureHelpResponse) else { return } + guard let json = String(data: data, encoding: .utf8) else { return } + ws.send(json) + } case _ where text.hasPrefix(#"{"method":"format""#): guard let request = try? decoder.decode(FormatRequest.self, from: data) else { return } let source = request.code