Skip to content

Commit

Permalink
add actions preview
Browse files Browse the repository at this point in the history
  • Loading branch information
ucpr committed Oct 13, 2024
1 parent 4a183ab commit 6aa8e52
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions nvim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"FTerm.nvim": { "branch": "master", "commit": "d1320892cc2ebab472935242d9d992a2c9570180" },
"actions-preview.nvim": { "branch": "master", "commit": "9f52a01c374318e91337697ebed51c6fae57f8a4" },
"aerial.nvim": { "branch": "master", "commit": "603156d4fd58963a05f221e76b1a25bc79ed55b0" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
Expand Down
57 changes: 57 additions & 0 deletions nvim/lua/plugins/actions-preview.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
return {
"aznhe21/actions-preview.nvim",
keys = { "<space>ca" },
depends = { "nvim-telescope/telescope.nvim", },
config = function()
require("actions-preview").setup {
-- options for vim.diff(): https://neovim.io/doc/user/lua.html#vim.diff()
diff = {
ctxlen = 3,
},

-- priority list of external command to highlight diff
-- disabled by defalt, must be set by yourself
highlight_command = {
require("actions-preview.highlight").delta(),
-- require("actions-preview.highlight").diff_so_fancy(),
-- require("actions-preview.highlight").diff_highlight(),
},

-- priority list of preferred backend
backend = { "telescope" },

-- options related to telescope.nvim
telescope = vim.tbl_extend(
"force",
-- telescope theme: https://github.com/nvim-telescope/telescope.nvim#themes
require("telescope.themes").get_dropdown(),
-- a table for customizing content
{
-- a function to make a table containing the values to be displayed.
-- fun(action: Action): { title: string, client_name: string|nil }
make_value = nil,

-- a function to make a function to be used in `display` of a entry.
-- see also `:h telescope.make_entry` and `:h telescope.pickers.entry_display`.
-- fun(values: { index: integer, action: Action, title: string, client_name: string }[]): function
make_make_display = nil,

-- window
sorting_strategy = "ascending",
layout_strategy = "vertical",
layout_config = {
width = 0.8,
height = 0.9,
prompt_position = "top",
preview_cutoff = 20,
preview_height = function(_, _, max_lines)
return max_lines - 15
end,
},
}
),
}

vim.keymap.set({ "v", "n" }, "<space>ca", require("actions-preview").code_actions)
end,
}
3 changes: 2 additions & 1 deletion nvim/lua/plugins/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ return {
buf_set_keymap("n", "<space>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
buf_set_keymap("n", "<space>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts)
buf_set_keymap("n", "<space>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
buf_set_keymap("n", "<space>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
-- use actions-preview
-- buf_set_keymap("n", "<space>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
buf_set_keymap("n", "<space>e", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts)
buf_set_keymap("n", "[d", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)
buf_set_keymap("n", "]d", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
Expand Down

0 comments on commit 6aa8e52

Please sign in to comment.