Skip to content

Commit

Permalink
chore(keymap): lsp keymap should effective at LspAttach event (ayam…
Browse files Browse the repository at this point in the history
  • Loading branch information
Groveer authored and singlemancombat committed May 14, 2023
1 parent bce2f08 commit f5b7dd3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
8 changes: 8 additions & 0 deletions lua/core/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ function autocmd.nvim_create_augroups(definitions)
end
end

local mapping = require("keymap.completion")
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(event)
mapping.lsp(event.buf)
end,
})

-- auto close NvimTree
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("NvimTreeClose", { clear = true }),
Expand Down
60 changes: 28 additions & 32 deletions lua/keymap/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,32 @@ local map_cu = bind.map_cu
-- local map_cmd = bind.map_cmd
local map_callback = bind.map_callback

local plug_map = {
-- LSP-related keymaps, work only when event = { "InsertEnter", "LspStart" }
["n|gli"] = map_cr("LspInfo"):with_noremap():with_silent():with_nowait():with_desc("lsp: Info"),
["n|glr"] = map_cr("LspRestart"):with_noremap():with_silent():with_nowait():with_desc("lsp: Restart"),
["n|go"] = map_cr("Lspsaga outline"):with_noremap():with_silent():with_desc("lsp: Toggle outline"),
["n|gjp"] = map_cr("Lspsaga diagnostic_jump_prev"):with_noremap():with_silent():with_desc("lsp: Prev diagnostic"),
["n|gjn"] = map_cr("Lspsaga diagnostic_jump_next"):with_noremap():with_silent():with_desc("lsp: Next diagnostic"),
["n|gsl"] = map_cr("Lspsaga show_line_diagnostics"):with_noremap():with_silent():with_desc("lsp: Line diagnostic"),
["n|gsc"] = map_cr("Lspsaga show_cursor_diagnostics")
:with_noremap()
:with_silent()
:with_desc("lsp: Cursor diagnostic"),
["n|gsb"] = map_cr("Lspsaga show_buf_diagnostics"):with_noremap():with_silent():with_desc("lsp: Buffer diagnostic"),
["n|gss"] = map_callback(function()
vim.lsp.buf.signature_help()
end)
:with_noremap()
:with_silent()
:with_desc("lsp: Signature help"),
["n|gr"] = map_cr("Lspsaga rename"):with_noremap():with_silent():with_desc("lsp: Rename in file range"),
["n|gR"] = map_cr("Lspsaga rename ++project"):with_noremap():with_silent():with_desc("lsp: Rename in project range"),
["n|K"] = map_cr("Lspsaga hover_doc"):with_noremap():with_silent():with_desc("lsp: Show doc"),
["nv|ga"] = map_cr("Lspsaga code_action"):with_noremap():with_silent():with_desc("lsp: Code action"),
["n|gd"] = map_cr("Lspsaga peek_definition"):with_noremap():with_silent():with_desc("lsp: Preview definition"),
["n|gD"] = map_cr("Lspsaga goto_definition"):with_noremap():with_silent():with_desc("lsp: Goto definition"),
["n|gp"] = map_cr("Lspsaga preview_definition"):with_noremap():with_silent():with_desc("lsp: Preview definition"),
["n|gh"] = map_cr("Lspsaga lsp_finder"):with_noremap():with_silent():with_desc("lsp: Show reference"),
["n|gt"] = map_cr("Lspsaga term_toggle"):with_noremap():with_silent():with_desc("lsp: Toggle term"),
["n|gci"] = map_cr("Lspsaga incoming_calls"):with_noremap():with_silent():with_desc("lsp: Show incoming calls"),
["n|gco"] = map_cr("Lspsaga outgoing_calls"):with_noremap():with_silent():with_desc("lsp: Show outgoing calls"),
}
local mapping = {}

bind.nvim_load_mapping(plug_map)
function mapping.lsp(buf)
local map = {
-- LSP-related keymaps, work only when event = { "InsertEnter", "LspStart" }
["n|gli"] = map_cr("LspInfo"):with_buffer(buf):with_desc("lsp: Info"),
["n|glr"] = map_cr("LspRestart"):with_buffer(buf):with_nowait():with_desc("lsp: Restart"),
["n|go"] = map_cr("Lspsaga outline"):with_buffer(buf):with_desc("lsp: Toggle outline"),
["n|gjp"] = map_cr("Lspsaga diagnostic_jump_prev"):with_buffer(buf):with_desc("lsp: Prev diagnostic"),
["n|gjn"] = map_cr("Lspsaga diagnostic_jump_next"):with_buffer(buf):with_desc("lsp: Next diagnostic"),
["n|gsl"] = map_cr("Lspsaga show_line_diagnostics"):with_buffer(buf):with_desc("lsp: Line diagnostic"),
["n|gsc"] = map_cr("Lspsaga show_cursor_diagnostics"):with_buffer(buf):with_desc("lsp: Cursor diagnostic"),
["n|gsb"] = map_cr("Lspsaga show_buf_diagnostics"):with_buffer(buf):with_desc("lsp: Buffer diagnostic"),
["n|gr"] = map_cr("Lspsaga rename"):with_buffer(buf):with_desc("lsp: Rename in file range"),
["n|gR"] = map_cr("Lspsaga rename ++project"):with_buffer(buf):with_desc("lsp: Rename in project range"),
["n|K"] = map_cr("Lspsaga hover_doc"):with_buffer(buf):with_desc("lsp: Show doc"),
["nv|ga"] = map_cr("Lspsaga code_action"):with_buffer(buf):with_desc("lsp: Code action for cursor"),
["n|gd"] = map_cr("Lspsaga peek_definition"):with_buffer(buf):with_desc("lsp: Preview definition"),
["n|gD"] = map_cr("Lspsaga goto_definition"):with_buffer(buf):with_desc("lsp: Goto definition"),
["n|gp"] = map_cr("Lspsaga preview_definition"):with_buffer(buf):with_desc("lsp: Preview definition"),
["n|gt"] = map_cr("Lspsaga term_toggle"):with_buffer(buf):with_desc("lsp: Toggle term"),
["n|gh"] = map_cr("Lspsaga lsp_finder"):with_buffer(buf):with_desc("lsp: Show reference"),
["n|gci"] = map_cr("Lspsaga incoming_calls"):with_buffer(buf):with_desc("lsp: Show incoming calls"),
["n|gco"] = map_cr("Lspsaga outgoing_calls"):with_buffer(buf):with_desc("lsp: Show outgoing calls"),
}
bind.nvim_load_mapping(map)
end

return mapping

0 comments on commit f5b7dd3

Please sign in to comment.