diff --git a/nvim/.config/nvim/lua/opdavies/plugins/lsp.lua b/nvim/.config/nvim/lua/opdavies/plugins/lsp.lua deleted file mode 100644 index 236b6fc..0000000 --- a/nvim/.config/nvim/lua/opdavies/plugins/lsp.lua +++ /dev/null @@ -1,70 +0,0 @@ -local has_lsp, lspconfig = pcall(require, "lspconfig") - -local servers = { - ansiblels = true, - bashls = true, - cssls = true, - html = true, - - intelephense = { - filetypes = { "install", "inc", "module", "php", "test", "theme" } - }, - - tsserver = { - filetypes = { "js", "jsx", "typescript", "vue" } - }, - - yamlls = true, -} - -local setup_server = function(server, config) - if not config then - return - end - - if type(config) ~= "table" then - config = {} - end - - lspconfig[server].setup(config) -end - -for server, config in pairs(servers) do - setup_server(server, config) -end - -vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, { - underline = true, - virtual_text = false, - signs = true, - update_in_insert = true, - } -) - -local key_mapper = function(mode, key, result) - vim.api.nvim_set_keymap( - mode, - key, - result, - {noremap = true, silent = true} - ) -end - -key_mapper('n', '', ':lua vim.lsp.buf.signature_help()') -key_mapper('n', 'af', ':lua vim.lsp.buf.code_action()') -key_mapper('n', 'dn', ':lua vim.lsp.diagnostic.goto_next()') -key_mapper('n', 'dp', ':lua vim.lsp.diagnostic.goto_prev()') -key_mapper('n', 'ds', ':lua vim.lsp.diagnostic.show_line_diagnostics()') -key_mapper('n', 'fb', ':lua require"telescope.builtin".buffers()') -key_mapper('n', 'fh', ':lua require"telescope.builtin".help_tags()') -key_mapper('n', 'fs', ':lua require"telescope.builtin".live_grep()') -key_mapper('n', 'rn', ':lua vim.lsp.buf.rename()') -key_mapper('n', 'K', ':lua vim.lsp.buf.hover()') -key_mapper('n', 'gD', ':lua vim.lsp.buf.declaration()') -key_mapper('n', 'gW', ':lua vim.lsp.buf.workspace_symbol()') -key_mapper('n', 'gd', ':lua vim.lsp.buf.definition()') -key_mapper('n', 'gi', ':lua vim.lsp.buf.implementation()') -key_mapper('n', 'gr', ':lua vim.lsp.buf.references()') -key_mapper('n', 'gt', ':lua vim.lsp.buf.type_definition()') -key_mapper('n', 'gw', ':lua vim.lsp.buf.document_symbol()') diff --git a/nvim/.config/nvim/lua/opdavies/plugins/lsp/init.lua b/nvim/.config/nvim/lua/opdavies/plugins/lsp/init.lua new file mode 100644 index 0000000..cd54541 --- /dev/null +++ b/nvim/.config/nvim/lua/opdavies/plugins/lsp/init.lua @@ -0,0 +1,2 @@ +require "opdavies.plugins.lsp.setup" +require "opdavies.plugins.lsp.mappings" diff --git a/nvim/.config/nvim/lua/opdavies/plugins/lsp/mappings.lua b/nvim/.config/nvim/lua/opdavies/plugins/lsp/mappings.lua new file mode 100644 index 0000000..155aca5 --- /dev/null +++ b/nvim/.config/nvim/lua/opdavies/plugins/lsp/mappings.lua @@ -0,0 +1,22 @@ +local map_options = { + noremap = true, + silent = true, +} + +vim.api.nvim_set_keymap('n', '', ':lua vim.lsp.buf.signature_help()', map_options) +vim.api.nvim_set_keymap('n', 'af', ':lua vim.lsp.buf.code_action()', map_options) +vim.api.nvim_set_keymap('n', 'dn', ':lua vim.lsp.diagnostic.goto_next()', map_options) +vim.api.nvim_set_keymap('n', 'dp', ':lua vim.lsp.diagnostic.goto_prev()', map_options) +vim.api.nvim_set_keymap('n', 'ds', ':lua vim.lsp.diagnostic.show_line_diagnostics()', map_options) +vim.api.nvim_set_keymap('n', 'fb', ':lua require"telescope.builtin".buffers()', map_options) +vim.api.nvim_set_keymap('n', 'fh', ':lua require"telescope.builtin".help_tags()', map_options) +vim.api.nvim_set_keymap('n', 'fs', ':lua require"telescope.builtin".live_grep()', map_options) +vim.api.nvim_set_keymap('n', 'rn', ':lua vim.lsp.buf.rename()', map_options) +vim.api.nvim_set_keymap('n', 'K', ':lua vim.lsp.buf.hover()', map_options) +vim.api.nvim_set_keymap('n', 'gD', ':lua vim.lsp.buf.declaration()', map_options) +vim.api.nvim_set_keymap('n', 'gW', ':lua vim.lsp.buf.workspace_symbol()', map_options) +vim.api.nvim_set_keymap('n', 'gd', ':lua vim.lsp.buf.definition()', map_options) +vim.api.nvim_set_keymap('n', 'gi', ':lua vim.lsp.buf.implementation()', map_options) +vim.api.nvim_set_keymap('n', 'gr', ':lua vim.lsp.buf.references()', map_options) +vim.api.nvim_set_keymap('n', 'gt', ':lua vim.lsp.buf.type_definition()', map_options) +vim.api.nvim_set_keymap('n', 'gw', ':lua vim.lsp.buf.document_symbol()', map_options) diff --git a/nvim/.config/nvim/lua/opdavies/plugins/lsp/setup.lua b/nvim/.config/nvim/lua/opdavies/plugins/lsp/setup.lua new file mode 100644 index 0000000..72d1829 --- /dev/null +++ b/nvim/.config/nvim/lua/opdavies/plugins/lsp/setup.lua @@ -0,0 +1,43 @@ +local has_lsp, lspconfig = pcall(require, "lspconfig") + +local servers = { + ansiblels = true, + bashls = true, + cssls = true, + html = true, + + intelephense = { + filetypes = { "install", "inc", "module", "php", "test", "theme" } + }, + + tsserver = { + filetypes = { "js", "jsx", "typescript", "vue" } + }, + + yamlls = true, +} + +local setup_server = function(server, config) + if not config then + return + end + + if type(config) ~= "table" then + config = {} + end + + lspconfig[server].setup(config) +end + +for server, config in pairs(servers) do + setup_server(server, config) +end + +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + underline = true, + virtual_text = false, + signs = true, + update_in_insert = true, + } +)