UI tweaks.

- Hide diagnostics on client exit
- Stop insert on popup focus.
- Hide popup on insertchar (for signature_help)
This commit is contained in:
Ashkan Kiani
2019-11-23 16:14:24 -08:00
parent 42c53d266a
commit d410812311
3 changed files with 20 additions and 5 deletions

View File

@@ -343,9 +343,19 @@ function lsp.start_client(config)
function handlers.on_exit(code, signal) function handlers.on_exit(code, signal)
active_clients[client_id] = nil active_clients[client_id] = nil
uninitialized_clients[client_id] = nil uninitialized_clients[client_id] = nil
for _, client_ids in pairs(all_buffer_active_clients) do local active_buffers = {}
for bufnr, client_ids in pairs(all_buffer_active_clients) do
if client_ids[client_id] then
table.insert(active_buffers, bufnr)
end
client_ids[client_id] = nil client_ids[client_id] = nil
end end
-- Buffer level cleanup
vim.schedule(function()
for _, bufnr in ipairs(active_buffers) do
util.buf_clear_diagnostics(bufnr)
end
end)
if config.on_exit then if config.on_exit then
pcall(config.on_exit, code, signal, client_id) pcall(config.on_exit, code, signal, client_id)
end end

View File

@@ -51,7 +51,9 @@ local function focusable_preview(method, params, fn)
do do
local win = find_window_by_var(method, bufnr) local win = find_window_by_var(method, bufnr)
if win then if win then
return api.nvim_set_current_win(win) api.nvim_set_current_win(win)
api.nvim_command("stopinsert")
return
end end
end end
return request(method, params, function(_, _, result, _) return request(method, params, function(_, _, result, _)
@@ -234,7 +236,9 @@ end
function M.signature_help() function M.signature_help()
local params = util.make_position_params() local params = util.make_position_params()
focusable_preview('textDocument/signatureHelp', params, function(result) focusable_preview('textDocument/signatureHelp', params, function(result)
if not (result and result.signatures and result.signatures[1]) then return end if not (result and result.signatures and result.signatures[1]) then
return { 'No signature available' }
end
-- TODO show empty popup when signatures is empty? -- TODO show empty popup when signatures is empty?
local lines = signature_help_to_preview_contents(result) local lines = signature_help_to_preview_contents(result)

View File

@@ -104,7 +104,7 @@ function M.apply_text_edits(text_edits, bufnr)
local e = cleaned[i] local e = cleaned[i]
local A = {e.A[1] - start_line, e.A[2]} local A = {e.A[1] - start_line, e.A[2]}
local B = {e.B[1] - start_line, e.B[2]} local B = {e.B[1] - start_line, e.B[2]}
M.set_lines(lines, A, B, e.lines) lines = M.set_lines(lines, A, B, e.lines)
end end
if set_eol and #lines[#lines] == 0 then if set_eol and #lines[#lines] == 0 then
table.remove(lines) table.remove(lines)
@@ -340,7 +340,8 @@ function M.open_floating_preview(contents, filetype, opts)
end end
api.nvim_buf_set_lines(floating_bufnr, 0, -1, true, contents) api.nvim_buf_set_lines(floating_bufnr, 0, -1, true, contents)
api.nvim_buf_set_option(floating_bufnr, 'modifiable', false) api.nvim_buf_set_option(floating_bufnr, 'modifiable', false)
api.nvim_command("autocmd CursorMoved,BufHidden <buffer> ++once lua pcall(vim.api.nvim_win_close, "..floating_winnr..", true)") -- TODO make InsertCharPre disappearing optional?
api.nvim_command("autocmd CursorMoved,BufHidden,InsertCharPre <buffer> ++once lua pcall(vim.api.nvim_win_close, "..floating_winnr..", true)")
return floating_bufnr, floating_winnr return floating_bufnr, floating_winnr
end end