aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp.lua
diff options
context:
space:
mode:
authorKarim Abou Zeid <karim23697@gmail.com>2021-04-30 13:40:20 +0200
committerKarim Abou Zeid <karim23697@gmail.com>2021-05-01 21:12:40 +0200
commit48a59f8f4f3eced84b21a473527b00ef1b9b5bd2 (patch)
treed51718506182dbe8f0098173a48c3ab08cb58083 /runtime/lua/vim/lsp.lua
parent59eae3b38fc98ba8c14e681b6d231e9821a11d52 (diff)
downloadrneovim-48a59f8f4f3eced84b21a473527b00ef1b9b5bd2.tar.gz
rneovim-48a59f8f4f3eced84b21a473527b00ef1b9b5bd2.tar.bz2
rneovim-48a59f8f4f3eced84b21a473527b00ef1b9b5bd2.zip
Add formatting_seq_sync, change formatting and formatting_sync
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r--runtime/lua/vim/lsp.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index 26700288af..d54420844e 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -891,6 +891,42 @@ function lsp.start_client(config)
end
--@private
+ --- Sends a request to the server and synchronously waits for the response.
+ ---
+ --- This is a wrapper around {client.request}
+ ---
+ --@param method (string) LSP method name.
+ --@param params (table) LSP request params.
+ --@param timeout_ms (number, optional, default=100) Maximum time in
+ ---milliseconds to wait for a result.
+ --@param bufnr (number) Buffer handle (0 for current).
+ --@returns { err, result }, where `err` and `result` come from the |lsp-handler|.
+ ---On timeout, cancel or error, returns `(nil, err)` where `err` is a
+ ---string describing the failure reason. If the request was unsuccessful
+ ---returns `nil`.
+ --@see |vim.lsp.buf_request_sync()|
+ function client.request_sync(method, params, timeout_ms, bufnr)
+ local request_result = nil
+ local function _sync_handler(err, _, result)
+ request_result = { error = err, result = result }
+ end
+
+ local success, request_id = client.request(method, params, _sync_handler,
+ bufnr)
+ if not success then return nil end
+
+ local wait_result, reason = vim.wait(timeout_ms or 100, function()
+ return request_result ~= nil
+ end, 10)
+
+ if not wait_result then
+ client.cancel_request(request_id)
+ return nil, wait_result_reason[reason]
+ end
+ return request_result
+ end
+
+ --@private
--- Sends a notification to an LSP server.
---
--@param method (string) LSP method name.