diff --git a/.config/nvim/lua/plugin/backup b/.config/nvim/lua/plugin/backup new file mode 100644 index 0000000..3a051ee --- /dev/null +++ b/.config/nvim/lua/plugin/backup @@ -0,0 +1,130 @@ +-- Author : swytch +-- Created : Saturday Sept. 11, 2021 22:12:33 CET +-- License : GPLv3 +-- Description : nvim-lsp-installer plugin config file + +local lsp_installer = require("nvim-lsp-installer") + +lsp_installer.settings { + ui = { + icons = { + server_installed = "✓", + server_pending = "o", + server_uninstalled = "x" + } + } +} + +local servers = { + "clangd", + "sumneko_lua", +} + +for _, name in ipairs(servers) do + local ok, server = lsp_installer.get_server(name) + -- Check that the server is supported in nvim-lsp-installer + if ok then + if not server:is_installed() then + print("Installing " .. name) + server:install() + end + end +end + +local lsp_root_path = vim.fn.stdpath("data") .. "/lsp_servers/" +local runtime_path = vim.split(package.path, ';') +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") +local enhance_server_opts = { + ["clangd"] = function(opts) + opts.settings = { + cmd = { lsp_root_path .. "clangd/clangd/bin/clangd", + "--background-index", + "--suggest-missing-includes", + "--clang-tidy", + "--header-insertion=iwyu" + }, + } + end, + ["sumneko_lua"] = function(opts) + opts.settings = { + cmd = { lsp_root_path + .. "sumneko_lua/extension/server/bin/" + .. "lua-language-server", + "-E", + lsp_root_path + .. "sumneko_lua/extension/server/main.lua" + }, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { + "vim", + "use", + "globals", + "utils" + }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = + vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, + } + end, +} + +local on_attach = function(_, bufnr) + local opts = { buffer = bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', 'wa', + vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', 'wr', + vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set('n', 'wl', function() + vim.inspect(vim.lsp.buf.list_workspace_folders()) + end, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'so', + require('telescope.builtin').lsp_document_symbols, opts) + vim.api.nvim_create_user_command("Format", vim.lsp.buf.formatting, {}) +end + +-- nvim-cmp supports additional completion capabilities +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) + +lsp_installer.on_server_ready(function(server) + -- Specify the default options which we'll use to setup all servers + local opts = { + on_attach = on_attach, + capabilities = capabilities, + } + + if enhance_server_opts[server.name] then + -- Enhance the default opts with the server-specific ones + enhance_server_opts[server.name](opts) + end + + server:setup(opts) +end) diff --git a/.config/nvim/lua/plugin/lsp/clangd.lua b/.config/nvim/lua/plugin/lsp/clangd.lua new file mode 100644 index 0000000..5996b05 --- /dev/null +++ b/.config/nvim/lua/plugin/lsp/clangd.lua @@ -0,0 +1,23 @@ +-- Author : swytch +-- Created : Monday May 2, 2022 21:00:24 CET +-- License : GPLv3 +-- Description : neovim lsp config file for clangd + + +local M = {} + +local lsp_root_path = vim.fn.stdpath("data") .. "/lsp_servers/" +local clangd_binary = lsp_root_path .. "clangd/clangd/bin/clangd" + +M.setup = function(opts) + opts.settings = { + cmd = { clangd_binary, + "--background-index", + "--suggest-missing-includes", + "--clang-tidy", + "--header-insertion=iwyu" + }, + } +end + +return M diff --git a/.config/nvim/lua/plugin/lsp/init.lua b/.config/nvim/lua/plugin/lsp/init.lua new file mode 100644 index 0000000..468a445 --- /dev/null +++ b/.config/nvim/lua/plugin/lsp/init.lua @@ -0,0 +1,100 @@ +-- Author : swytch +-- Created : Monday May 2, 2022 21:02:02 CET +-- License : GPLv3 +-- Description : neovim global lsp config file + + +local lspconfig = require("lspconfig") +local lsp_installer = require("nvim-lsp-installer") + +local globals = require("globals") +local signs = { + Error = globals.sign_error, + Warn = globals.sign_warn, + Hint = globals.sign_hint, + Info = globals.sign_info, +} + +for type, icon in ipairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { + text = icon, + texthl = hl, + numhl = hl + }) +end + +vim.diagnostic.config({ + update_in_insert = true +}) + + +local enhance_server_opts = { + ["clangd"] = function(opts) + require("plugin.lsp.clangd").setup(opts) + end, + ["sumneko_lua"] = function(opts) + require("plugin.lsp.sumneko_lua").setup(opts) + end, +} + +local on_attach = function(_, bufnr) + local opts = { buffer = bufnr } + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) + vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) + vim.keymap.set("n", "ln", vim.diagnostic.goto_next, opts) + vim.keymap.set("n", "lp", vim.diagnostic.goto_prev, opts) + vim.keymap.set("n", "lf", vim.lsp.buf.formatting, opts) + vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) + vim.keymap.set("n", "wa", + vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set("n", "wr", + vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set("n", "wl", function() + vim.inspect(vim.lsp.buf.list_workspace_folders()) + end, opts) + vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) + vim.keymap.set("n", "so", + require("telescope.builtin").lsp_document_symbols, opts) +end + +-- nvim-cmp supports additional completion capabilities +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) + +-- Enable the following language servers +local servers = { "clangd", "sumneko_lua" } +lsp_installer.setup { + ensure_installed = servers +} + +-- Setup nvim-lsp-installer +lsp_installer.settings { + ui = { + icons = { + server_installed = "✓", + server_pending = "o", + server_uninstalled = "x" + } + } +} + + +for _, server in ipairs(servers) do + local opts = { + on_attach = on_attach, + capabilities = capabilities, + } + + if enhance_server_opts[server] then + -- Enhance the default opts with the server-specific ones + enhance_server_opts[server](opts) + end + + lspconfig[server].setup(opts) +end diff --git a/.config/nvim/lua/plugin/lsp/sumneko_lua.lua b/.config/nvim/lua/plugin/lsp/sumneko_lua.lua new file mode 100644 index 0000000..931db91 --- /dev/null +++ b/.config/nvim/lua/plugin/lsp/sumneko_lua.lua @@ -0,0 +1,47 @@ +-- Author : swytch +-- Created : Monday May 2, 2022 21:00:07 CET +-- License : GPLv3 +-- Description : neovim lsp config file for sumneko_lua + + +local M = {} + +local runtime_path = vim.split(package.path, ';') + +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") + + +M.setup = function(opts) + opts.settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're + -- using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { + "vim", + "globals", + "utils" + }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = + vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but + -- unique identifier + telemetry = { + enable = false, + }, + }, + } +end + +return M diff --git a/.config/nvim/lua/plugin/lsp_config.lua b/.config/nvim/lua/plugin/lsp_config.lua deleted file mode 100644 index e593c90..0000000 --- a/.config/nvim/lua/plugin/lsp_config.lua +++ /dev/null @@ -1,37 +0,0 @@ --- Author : swytch --- Created : Tuesday May 18, 2021 12:08:51 CET --- License : GPLv3 --- Description : neovim lsp config file - -vim.fn.sign_define( - "DiagnosticSignError", - { - texthl = "DiagnosticVirtualTextError", - text = globals.sign_error, - numhl = "DiagnosticSignError" - } -) -vim.fn.sign_define( - "DiagnosticSignWarn", - { - texthl = "DiagnosticVirtualTextWarn", - text = globals.sign_warning, - numhl = "DiagnosticSignWarn" - } -) -vim.fn.sign_define( - "DiagnosticSignHint", - { - texthl = "DiagnosticVirtualTextHint", - text = globals.sign_hint, - numhl = "DiagnosticSignHint" - } -) -vim.fn.sign_define( - "DiagnosticSignInfo", - { - texthl = "DiagnosticVirtualTextInfo", - text = globals.sign_info, - numhl = "DiagnosticSignInfo" - } -) diff --git a/.config/nvim/lua/plugin/lsp_installer.lua b/.config/nvim/lua/plugin/lsp_installer.lua deleted file mode 100644 index ab3b51c..0000000 --- a/.config/nvim/lua/plugin/lsp_installer.lua +++ /dev/null @@ -1,129 +0,0 @@ --- Author : swytch --- Created : Saturday Sept. 11, 2021 22:12:33 CET --- License : GPLv3 --- Description : nvim-lsp-installer plugin config file - -local lsp_installer = require("nvim-lsp-installer") - -lsp_installer.settings { - ui = { - icons = { - server_installed = "✓", - server_pending = "o", - server_uninstalled = "x" - } - } -} - -local servers = { - "clangd", - "sumneko_lua", -} - -for _, name in ipairs(servers) do - local ok, server = lsp_installer.get_server(name) - -- Check that the server is supported in nvim-lsp-installer - if ok then - if not server:is_installed() then - print("Installing " .. name) - server:install() - end - end -end - -local lsp_root_path = vim.fn.stdpath("data") .. "/lsp_servers/" -local runtime_path = vim.split(package.path, ';') - - -local clangd_binary = lsp_root_path .. "clangd/clangd/bin/clangd" - -table.insert(runtime_path, "lua/?.lua") -table.insert(runtime_path, "lua/?/init.lua") - -local enhance_server_opts = { - ["clangd"] = function(opts) - opts.settings = { - cmd = { clangd_binary, - "--background-index", - "--suggest-missing-includes", - "--clang-tidy", - "--header-insertion=iwyu" - }, - } - end, - ["sumneko_lua"] = function(opts) - opts.settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're - -- using (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT', - -- Setup your lua path - path = runtime_path, - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { - "vim", - "globals", - "utils" - }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = - vim.api.nvim_get_runtime_file("", true), - }, - -- Do not send telemetry data containing a randomized but - -- unique identifier - telemetry = { - enable = false, - }, - }, - } - end, -} - -local on_attach = function(_, bufnr) - local opts = { buffer = bufnr } - vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) - vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) - vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) - vim.keymap.set("n", "ln", vim.diagnostic.goto_next, opts) - vim.keymap.set("n", "lp", vim.diagnostic.goto_prev, opts) - vim.keymap.set("n", "lf", vim.lsp.buf.formatting, opts) - vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) - vim.keymap.set("n", "wa", - vim.lsp.buf.add_workspace_folder, opts) - vim.keymap.set("n", "wr", - vim.lsp.buf.remove_workspace_folder, opts) - vim.keymap.set("n", "wl", function() - vim.inspect(vim.lsp.buf.list_workspace_folders()) - end, opts) - vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) - vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) - vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) - vim.keymap.set("n", "so", - require("telescope.builtin").lsp_document_symbols, opts) -end - --- nvim-cmp supports additional completion capabilities -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) - -lsp_installer.on_server_ready(function(server) - -- Specify the default options which we'll use to setup all servers - local opts = { - on_attach = on_attach, - capabilities = capabilities, - } - - if enhance_server_opts[server.name] then - -- Enhance the default opts with the server-specific ones - enhance_server_opts[server.name](opts) - end - - server:setup(opts) -end) diff --git a/.config/nvim/lua/plugin/packer.lua b/.config/nvim/lua/plugin/packer.lua index 9ab4a3b..fc3f020 100644 --- a/.config/nvim/lua/plugin/packer.lua +++ b/.config/nvim/lua/plugin/packer.lua @@ -54,13 +54,11 @@ return require("packer").startup(function() -- LSP use { - "williamboman/nvim-lsp-installer", + "neovim/nvim-lspconfig", requires = { - "neovim/nvim-lspconfig", - config = function() - require("plugin.lsp_config") end + "williamboman/nvim-lsp-installer", }, - config = function() require("plugin.lsp_installer") end + config = function() require("plugin.lsp") end } -- auto completion