Add <leader>dy mapping to yank diagnostic message (wip)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
local yank = require("user.utils").yank
|
||||
|
||||
function open_terminal(vertically)
|
||||
vertically = vertically or false
|
||||
|
||||
@@ -7,3 +9,20 @@ function open_terminal(vertically)
|
||||
vim.cmd(":split term://bash")
|
||||
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
|
||||
|
||||
@@ -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("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("<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
|
||||
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
|
||||
nmap("<leader>gg", ":G<CR>") -- Leader+g+g - open vim-fugitive window
|
||||
|
||||
@@ -38,4 +38,13 @@ M.list_includes_item = function(list, item)
|
||||
return false
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user