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