Skip to content
Closed
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
12 changes: 12 additions & 0 deletions Sources/App/Controllers/LanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ final class LanguageServer {
}
}

func sendSignatureHelpRequest(documentPath: String, line: Int, character: Int, completion: @escaping (Result<SignatureHelpRequest.Response, ResponseError>) -> 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<DefinitionRequest.Response, ResponseError>) -> Void) {
let identifier = URL(fileURLWithPath: documentPath)

Expand Down
28 changes: 28 additions & 0 deletions Sources/App/routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down