mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-29 14:28:18 +02:00
[Feature] better code action prompt and auto show codelens actions (#1698)
This commit is contained in:
parent
5fe7b7ad4d
commit
0ad60e90a9
4 changed files with 43 additions and 1 deletions
|
@ -159,6 +159,26 @@ function M.view_lunarvim_changelog()
|
||||||
}):find()
|
}):find()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.code_actions()
|
||||||
|
local opts = {
|
||||||
|
winblend = 15,
|
||||||
|
layout_config = {
|
||||||
|
prompt_position = "top",
|
||||||
|
width = 80,
|
||||||
|
height = 12,
|
||||||
|
},
|
||||||
|
borderchars = {
|
||||||
|
prompt = { "─", "│", " ", "│", "╭", "╮", "│", "│" },
|
||||||
|
results = { "─", "│", "─", "│", "├", "┤", "╯", "╰" },
|
||||||
|
preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
|
||||||
|
},
|
||||||
|
border = {},
|
||||||
|
previewer = false,
|
||||||
|
shorten_path = false,
|
||||||
|
}
|
||||||
|
require("telescope.builtin").lsp_code_actions(require("telescope.themes").get_dropdown(opts))
|
||||||
|
end
|
||||||
|
|
||||||
function M.setup()
|
function M.setup()
|
||||||
local telescope = require "telescope"
|
local telescope = require "telescope"
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ M.config = function()
|
||||||
|
|
||||||
l = {
|
l = {
|
||||||
name = "LSP",
|
name = "LSP",
|
||||||
a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
|
a = { "<cmd>lua require('core.telescope').code_actions()<cr>", "Code Action" },
|
||||||
d = {
|
d = {
|
||||||
"<cmd>Telescope lsp_document_diagnostics<cr>",
|
"<cmd>Telescope lsp_document_diagnostics<cr>",
|
||||||
"Document Diagnostics",
|
"Document Diagnostics",
|
||||||
|
@ -159,6 +159,7 @@ M.config = function()
|
||||||
"<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<cr>",
|
"<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<cr>",
|
||||||
"Prev Diagnostic",
|
"Prev Diagnostic",
|
||||||
},
|
},
|
||||||
|
l = { "<cmd>lua vim.lsp.codelens.run()<cr>", "CodeLens Action" },
|
||||||
p = {
|
p = {
|
||||||
name = "Peek",
|
name = "Peek",
|
||||||
d = { "<cmd>lua require('lsp.peek').Peek('definition')<cr>", "Definition" },
|
d = { "<cmd>lua require('lsp.peek').Peek('definition')<cr>", "Definition" },
|
||||||
|
|
|
@ -17,6 +17,7 @@ return {
|
||||||
},
|
},
|
||||||
override = {},
|
override = {},
|
||||||
document_highlight = true,
|
document_highlight = true,
|
||||||
|
code_lens_refresh = true,
|
||||||
popup_border = "single",
|
popup_border = "single",
|
||||||
on_attach_callback = nil,
|
on_attach_callback = nil,
|
||||||
on_init_callback = nil,
|
on_init_callback = nil,
|
||||||
|
|
|
@ -21,6 +21,25 @@ local function lsp_highlight_document(client)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function lsp_code_lens_refresh(client)
|
||||||
|
if lvim.lsp.code_lens_refresh == false then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if client.resolved_capabilities.code_lens then
|
||||||
|
vim.api.nvim_exec(
|
||||||
|
[[
|
||||||
|
augroup lsp_code_lens_refresh
|
||||||
|
autocmd! * <buffer>
|
||||||
|
autocmd InsertLeave <buffer> lua vim.lsp.codelens.refresh()
|
||||||
|
autocmd InsertLeave <buffer> lua vim.lsp.codelens.display()
|
||||||
|
augroup END
|
||||||
|
]],
|
||||||
|
false
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function add_lsp_buffer_keybindings(bufnr)
|
local function add_lsp_buffer_keybindings(bufnr)
|
||||||
local mappings = {
|
local mappings = {
|
||||||
normal_mode = "n",
|
normal_mode = "n",
|
||||||
|
@ -99,6 +118,7 @@ function M.common_on_attach(client, bufnr)
|
||||||
Log:debug "Called lsp.on_attach_callback"
|
Log:debug "Called lsp.on_attach_callback"
|
||||||
end
|
end
|
||||||
lsp_highlight_document(client)
|
lsp_highlight_document(client)
|
||||||
|
lsp_code_lens_refresh(client)
|
||||||
add_lsp_buffer_keybindings(bufnr)
|
add_lsp_buffer_keybindings(bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue