diff options
author | Ashkan Kiani <ashkan.k.kiani@gmail.com> | 2019-12-20 22:49:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-20 22:49:29 -0800 |
commit | ee7ac469c6f0f15a2d75991ef053a18d93e01756 (patch) | |
tree | fb01f246fffa2d0e6d8539a8af3e2e2aae716b6f /runtime/lua/vim/lsp.lua | |
parent | b2443361ca3074c37bdf4112ca8f22efebdcbd23 (diff) | |
download | rneovim-ee7ac469c6f0f15a2d75991ef053a18d93e01756.tar.gz rneovim-ee7ac469c6f0f15a2d75991ef053a18d93e01756.tar.bz2 rneovim-ee7ac469c6f0f15a2d75991ef053a18d93e01756.zip |
LSP: Use async completion for omnifunc. (#11578)
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r-- | runtime/lua/vim/lsp.lua | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 501cc6f670..0ecf57f50c 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -858,39 +858,30 @@ function lsp.omnifunc(findstart, base) end end - if findstart == 1 then - -- First, just return the current cursor column, we only really need that - return vim.fn.col('.') - else - -- Then, perform standard completion request - log.info("base ", base) - - local pos = vim.api.nvim_win_get_cursor(0) - local line = vim.api.nvim_get_current_line() - local line_to_cursor = line:sub(1, pos[2]) - local _ = log.trace() and log.trace("omnifunc.line", pos, line) - - -- Get the start postion of the current keyword - local textMatch = vim.fn.match(line_to_cursor, '\\k*$') - local params = util.make_position_params() - - -- TODO handle timeout error differently? Like via an error? - local client_responses = lsp.buf_request_sync(bufnr, 'textDocument/completion', params) or {} - local matches = {} - for _, response in pairs(client_responses) do - -- TODO how to handle errors? - if not response.error then - local data = response.result - local completion_items = util.text_document_completion_list_to_complete_items(data or {}) - local _ = log.trace() and log.trace("omnifunc.completion_items", completion_items) - vim.list_extend(matches, completion_items) - end - end + -- Then, perform standard completion request + local _ = log.info() and log.info("base ", base) + + local pos = vim.api.nvim_win_get_cursor(0) + local line = vim.api.nvim_get_current_line() + local line_to_cursor = line:sub(1, pos[2]) + local _ = log.trace() and log.trace("omnifunc.line", pos, line) + + -- Get the start postion of the current keyword + local textMatch = vim.fn.match(line_to_cursor, '\\k*$') + local params = util.make_position_params() + + local items = {} + lsp.buf_request(bufnr, 'textDocument/completion', params, function(err, _, result) + if err or not result then return end + local matches = util.text_document_completion_list_to_complete_items(result) + -- TODO(ashkan): is this the best way to do this? + vim.list_extend(items, matches) + vim.fn.complete(textMatch+1, items) + end) - -- Instead of returning matches call complete instead - vim.fn.complete(textMatch+1, matches) - return {} - end + -- Return -2 to signal that we should continue completion so that we can + -- async complete. + return -2 end function lsp.client_is_stopped(client_id) |