Skip to content

Commit

Permalink
Custom requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed May 6, 2022
1 parent 3275cfa commit c294061
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ The LSP [specification](https://microsoft.github.io/language-server-protocol/spe
| ------|:---------:|
| $/cancelRequest ||
| $/progress ||
| server-defined ||

## Suggestions or Feedback

Expand Down
2 changes: 2 additions & 0 deletions Sources/LanguageServerProtocol/JSONRPCLanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ extension JSONRPCLanguageServer {
sendRequestWithHandler(params, method: method, handler: completionHandler)
case .workspaceWillDeleteFiles(let params):
sendRequestWithHandler(params, method: method, handler: completionHandler)
case .custom(let method, let params):
sendRequestWithHandler(params, method: method, handler: completionHandler)
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/LanguageServerProtocol/LanguageServerProtocol.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import JSONRPC
import AnyCodable

typealias UnusedResult = String?
typealias UnusedParam = String?
Expand Down Expand Up @@ -117,6 +118,7 @@ public enum ClientRequest {
case textDocumentSemanticTokensFull = "textDocument/semanticTokens/full"
case textDocumentSemanticTokensFullDelta = "textDocument/semanticTokens/full/delta"
case textDocumentMoniker = "textDocument/moniker"
case custom
}

case initialize(InitializeParams)
Expand Down Expand Up @@ -154,6 +156,7 @@ public enum ClientRequest {
case semanticTokensFull(SemanticTokensParams)
case semanticTokensFullDelta(SemanticTokensDeltaParams)
case semanticTokensRange(SemanticTokensRangeParams)
case custom(String, AnyCodable)

public var method: Method {
switch self {
Expand Down Expand Up @@ -227,6 +230,8 @@ public enum ClientRequest {
return .textDocumentSemanticTokensFullDelta
case .semanticTokensRange:
return .textDocumentSemanticTokensRange
case .custom:
return .custom
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/LanguageServerProtocol/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ public extension Server {
func semanticTokensRange(params: SemanticTokensRangeParams, block: @escaping (ServerResult<SemanticTokensResponse>) -> Void) {
sendRequest(.semanticTokensRange(params), completionHandler: block)
}

func customRequest<Response: Codable>(method: String, params: AnyCodable, block: @escaping (ServerResult<Response>) -> Void) {
sendRequest(.custom(method, params), completionHandler: block)
}
}

// Workspace notifications
Expand Down

0 comments on commit c294061

Please sign in to comment.