mirror of
https://codeberg.org/qwjyh/dotfiles.git
synced 2025-06-27 03:39:20 +09:00
refactor(nvim): separate lsp on_attach func to module
to share the same config between general lspconfig & lean config
This commit is contained in:
parent
47b4fc83bc
commit
5f6e107b41
4 changed files with 41 additions and 48 deletions
37
dotfiles/neovim/lua/lsp_config.lua
Normal file
37
dotfiles/neovim/lua/lsp_config.lua
Normal file
|
@ -0,0 +1,37 @@
|
|||
local M = {}
|
||||
|
||||
---Add `desc` to bufopts table.
|
||||
---@param bufopts vim.keymap.set.Opts
|
||||
---@param desc string
|
||||
---@return vim.keymap.set.Opts
|
||||
local function with_desc(bufopts, desc)
|
||||
return vim.tbl_extend("error", bufopts, { desc = desc })
|
||||
end
|
||||
|
||||
M.on_attach = function(client, bufnr)
|
||||
-- Enable completion triggered by <c-x><c-o>
|
||||
--vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
|
||||
-- Mappings
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below function
|
||||
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
||||
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, with_desc(bufopts, "goto declaration"))
|
||||
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, with_desc(bufopts, "goto definition"))
|
||||
vim.keymap.set('n', 'gT', vim.lsp.buf.type_definition, with_desc(bufopts, "goto type definition"))
|
||||
vim.keymap.set('n', 'K', vim.lsp.buf.hover, with_desc(bufopts, "lsp hover"))
|
||||
vim.keymap.set('n', 'g1', vim.lsp.buf.implementation, with_desc(bufopts, "lsp implementations"))
|
||||
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, with_desc(bufopts, "lsp signature help"))
|
||||
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, with_desc(bufopts, "lsp add_workspace_folder"))
|
||||
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder,
|
||||
with_desc(bufopts, "lsp remove_workspace_folder"))
|
||||
vim.keymap.set('n', '<space>wl', function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, with_desc(bufopts, "lsp list_workspace_folders"))
|
||||
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, with_desc(bufopts, "lsp type definition"))
|
||||
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, with_desc(bufopts, "lsp rename"))
|
||||
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, with_desc(bufopts, "lsp code_action"))
|
||||
vim.keymap.set('n', 'grf', vim.lsp.buf.references, with_desc(bufopts, "lsp references"))
|
||||
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, with_desc(bufopts, "lsp format"))
|
||||
end
|
||||
|
||||
return M
|
Loading…
Add table
Add a link
Reference in a new issue