Add <leader>dy mapping to yank diagnostic message (wip)

This commit is contained in:
2022-02-01 22:51:02 +03:00
parent 317c8c720f
commit cecf188adc
3 changed files with 30 additions and 1 deletions

View File

@@ -1,3 +1,5 @@
local yank = require("user.utils").yank
function open_terminal(vertically) function open_terminal(vertically)
vertically = vertically or false vertically = vertically or false
@@ -7,3 +9,20 @@ function open_terminal(vertically)
vim.cmd(":split term://bash") vim.cmd(":split term://bash")
end end
end end
function copy_diagnostic_message()
local diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
if #diagnostics == 0 then
print("No diagnostics to yank")
return
end
-- TODO: print all messages available and prompt which one to yank
local message = diagnostics[1].message
yank(message)
print("Diagnostic message was yanked")
end

View File

@@ -52,9 +52,10 @@ nmap("gd", ":lua vim.lsp.buf.definition()<CR>") -- g+d - Go to definition
nmap("gr", ":lua vim.lsp.buf.references()<CR>") -- g+r - Show references nmap("gr", ":lua vim.lsp.buf.references()<CR>") -- g+r - Show references
nmap("K", ":lua vim.lsp.buf.hover()<CR>") -- Shift+k - Show documentation in hover window nmap("K", ":lua vim.lsp.buf.hover()<CR>") -- Shift+k - Show documentation in hover window
nmap("<F2>", ":lua vim.lsp.buf.rename()<CR>") -- F2 - Rename thing under the cursor nmap("<F2>", ":lua vim.lsp.buf.rename()<CR>") -- F2 - Rename thing under the cursor
nmap("<leader>d", ':lua vim.diagnostic.open_float(nil, {focus = false, scope = "cursor"})<CR>') -- Leader+d - show diagnostics in float window
nmap("<leader>.", ":lua vim.lsp.buf.code_action()<CR>") -- Leader+. - show code actions to run nmap("<leader>.", ":lua vim.lsp.buf.code_action()<CR>") -- Leader+. - show code actions to run
vmap("<leader>.", ":lua vim.lsp.buf.range_code_action()<CR>") -- same as above but for visual mode vmap("<leader>.", ":lua vim.lsp.buf.range_code_action()<CR>") -- same as above but for visual mode
nmap("<leader>dd", ':lua vim.diagnostic.open_float(nil, {focus = false, scope = "cursor"})<CR>') -- Leader+d - show diagnostics in float window
nmap("<leader>dy", ":lua copy_diagnostic_message()<CR>") -- Leader+d+c - copy diagnostic message
-- Git -- Git
nmap("<leader>gg", ":G<CR>") -- Leader+g+g - open vim-fugitive window nmap("<leader>gg", ":G<CR>") -- Leader+g+g - open vim-fugitive window

View File

@@ -38,4 +38,13 @@ M.list_includes_item = function(list, item)
return false return false
end end
M.yank = function(message)
if vim.fn.has("win32") == 1 then
os.execute("echo '" .. message .. "' | win32yank -i")
else
-- i use wayland, so there is no xclip for X11
os.execute("echo -n '" .. message .. "' | wl-copy")
end
end
return M return M