From 796db1e83d41d25a277c46c968a168702c1f3eb8 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sun, 21 Jan 2024 04:04:42 -0500 Subject: New lsp config start --- lua/ben/lazy.lua | 1 - lua/ben/plugins/fugitive.lua | 28 ++--- lua/ben/plugins/lf.lua | 2 +- lua/ben/plugins/lsp.lua | 246 ++++++++++++++++++++++++++++++++++++++++++ lua/ben/plugins/lsp/mason.lua | 72 ------------- 5 files changed, 261 insertions(+), 88 deletions(-) create mode 100644 lua/ben/plugins/lsp.lua delete mode 100644 lua/ben/plugins/lsp/mason.lua (limited to 'lua') diff --git a/lua/ben/lazy.lua b/lua/ben/lazy.lua index e363abb..46668e4 100644 --- a/lua/ben/lazy.lua +++ b/lua/ben/lazy.lua @@ -12,7 +12,6 @@ end vim.opt.rtp:prepend(lazypath) require("lazy").setup({ { import = "ben.plugins" }, - { import = "ben.plugins.lsp" }, }, { install = { colorscheme = { "everforest" }, diff --git a/lua/ben/plugins/fugitive.lua b/lua/ben/plugins/fugitive.lua index 4b73c42..051a983 100644 --- a/lua/ben/plugins/fugitive.lua +++ b/lua/ben/plugins/fugitive.lua @@ -17,20 +17,20 @@ return { }, config = function() -- Use > and < to fix merge conflicts (keep the cursor in the middle of the screen) - vim.api.nvim_set_keymap("n", ">", "diffg //2diffupdate", { noremap = true, silent = true }) - vim.api.nvim_set_keymap("n", "<", "diffg //3diffupdate", { noremap = true, silent = true }) + -- vim.api.nvim_set_keymap("n", ">", "diffg //2diffupdate", { noremap = true, silent = true }) + -- vim.api.nvim_set_keymap("n", "<", "diffg //3diffupdate", { noremap = true, silent = true }) -- Use } and { to force the entire file - vim.api.nvim_set_keymap( - "n", - "}", - "hGwrite!diffupdate", - { noremap = true, silent = true } - ) - vim.api.nvim_set_keymap( - "n", - "{", - "lGwrite!diffupdate", - { noremap = true, silent = true } - ) + -- vim.api.nvim_set_keymap( + -- "n", + -- "}", + -- "hGwrite!diffupdate", + -- { noremap = true, silent = true } + -- ) + -- vim.api.nvim_set_keymap( + -- "n", + -- "{", + -- "lGwrite!diffupdate", + -- { noremap = true, silent = true } + -- ) end, } diff --git a/lua/ben/plugins/lf.lua b/lua/ben/plugins/lf.lua index 2e28de2..5c95197 100644 --- a/lua/ben/plugins/lf.lua +++ b/lua/ben/plugins/lf.lua @@ -6,7 +6,7 @@ return { }, config = function() vim.g.lf_netrw = 1 - require("lf").setup({ + local lf = require("lf").setup({ border = "rounded", focus_on_open = true, }) diff --git a/lua/ben/plugins/lsp.lua b/lua/ben/plugins/lsp.lua new file mode 100644 index 0000000..251a459 --- /dev/null +++ b/lua/ben/plugins/lsp.lua @@ -0,0 +1,246 @@ +return { + + { + "williamboman/mason.nvim", + dependencies = { + "williamboman/mason-lspconfig.nvim", + "WhoIsSethDaniel/mason-tool-installer.nvim", + }, + config = function() + -- import mason + local mason = require("mason") + + -- import mason-lspconfig + local mason_lspconfig = require("mason-lspconfig") + local mason_tool_installer = require("mason-tool-installer") + + -- enable mason and configure icons + mason.setup({ + ui = { + icons = { + package_installed = "", + package_pending = "", + package_uninstalled = "", + }, + }, + }) + + mason_lspconfig.setup({ + -- list of servers for mason to install + ensure_installed = { + "ast_grep", -- fallback + "lua_ls", -- lua + "autotools_ls", -- Makefile + "dockerls", -- dockerfiles + "docker_compose_language_service", -- docker-compose + "marksman", -- markdown + "gopls", -- go + "texlab", -- latex + "pyre", -- python + "r_language_server", -- r + "rust_analyzer", -- rust + "mutt_ls", -- mutt + "taplo", -- toml + "yamlls", -- yaml + }, + -- auto-install configured servers (with lspconfig) + automatic_installation = true, + }) + + -- configure mason tool installer + mason_tool_installer.setup({ + ensure_installed = { + "isort", -- python import formatter + "goimports", -- go import formatter + "doctoc", -- markdown table of contents generator + "go-debug-adapter", -- go debugger + "codelldb", -- c/c++ debugger + }, + }) + end, + }, + + { + "neovim/nvim-lspconfig", + dependencies = { "hrsh7th/cmp-nvim-lsp" }, + event = { "BufReadPre", "BufNewFile" }, + config = function() + -- import lspconfig plugin + local lspconfig = require("lspconfig") + + -- import cmp-nvim-lsp plugin + local cmp_nvim_lsp = require("cmp_nvim_lsp") + + local keymap = vim.keymap + + local opts = { noremap = true, silent = true } + local on_attach = function(client, bufnr) + opts.buffer = bufnr + + -- set keybinds + opts.desc = "Show LSP references" + keymap.set("n", "gR", "Telescope lsp_references", opts) -- show definition, references + + opts.desc = "Go to declaration" + keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration + + opts.desc = "Show LSP definitions" + keymap.set("n", "gd", "Telescope lsp_definitions", opts) -- show lsp definitions + + opts.desc = "Show LSP implementations" + keymap.set("n", "gi", "Telescope lsp_implementations", opts) -- show lsp implementations + + opts.desc = "Show LSP type definitions" + keymap.set("n", "gt", "Telescope lsp_type_definitions", opts) -- show lsp type definitions + + opts.desc = "See available code actions" + keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection + + opts.desc = "Smart rename" + keymap.set("n", "rn", vim.lsp.buf.rename, opts) -- smart rename + + opts.desc = "Show buffer diagnostics" + keymap.set("n", "D", "Telescope diagnostics bufnr=0", opts) -- show diagnostics for file + + opts.desc = "Show line diagnostics" + keymap.set("n", "d", vim.diagnostic.open_float, opts) -- show diagnostics for line + + opts.desc = "Go to previous diagnostic" + keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer + + opts.desc = "Go to next diagnostic" + keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagostic in buffer + + opts.desc = "Show documentation for what is under cursor" + keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor + + opts.desc = "Restart LSP" + keymap.set("n", "rs", ":LspRestart", opts) -- mapping to restart lsp if necessary + end + + -- used to enable autocompletion (assign to every lsp server config) + local capabilities = cmp_nvim_lsp.default_capabilities() + + -- change diagnostic symbols in sign column + local signs = { Error = " ", Warn = " ", Hint = "󰠠 ", Info = " " } + for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) + end + + -- configure lua server (with special settings) + lspconfig["lua_ls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { -- custom settings for lua + Lua = { + -- make the language server recognize "vim" global + diagnostics = { + globals = { "vim" }, + }, + workspace = { + -- make language server aware of runtime files + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + }, + }, + }, + }) + + -- configure dockerfile server + lspconfig["dockerls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure docker-compose server + lspconfig["docker_compose_language_service"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure markdown server + lspconfig["marksman"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure golang server + lspconfig["gopls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure LaTeX server + lspconfig["texlab"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure LaTeX server + lspconfig["texlab"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure python server + lspconfig["pyre"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure R server + lspconfig["r_language_server"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure R server + lspconfig["r_language_server"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure mutt server + lspconfig["mutt_ls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure toml server + lspconfig["taplo"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure Makefile server + lspconfig["autotools_ls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure fallback server + lspconfig["ast_grep"].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + + -- configure yaml server + lspconfig["yamlls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { + yaml = { + schemas = { + ["https://json.schemastore.org/github-workflow.json"] = "/.github/workflows/*", + ["../path/relative/to/file.yml"] = "/.github/workflows/*", + ["/path/from/root/of/project"] = "/.github/workflows/*", + }, + }, + }, + }) + end, + }, +} diff --git a/lua/ben/plugins/lsp/mason.lua b/lua/ben/plugins/lsp/mason.lua deleted file mode 100644 index 121509d..0000000 --- a/lua/ben/plugins/lsp/mason.lua +++ /dev/null @@ -1,72 +0,0 @@ -return { - "williamboman/mason.nvim", - dependencies = { - "williamboman/mason-lspconfig.nvim", - "WhoIsSethDaniel/mason-tool-installer.nvim", - }, - config = function() - --import mason - local mason = require("mason") - -- import mason-lspconfig - local mason_lspconfig = require("mason-lspconfig") - - local mason_tool_installer = require("mason-tool-installer") - - -- enable mason and configure icons - mason.setup({ - ui = { - icons = { - package_installed = "", - package_pending = "", - package_uninstalled = "", - }, - }, - }) - mason_lspconfig.setup({ - -- list of servers for mason to install - ensure_installed = { - "bashls", - "cssls", - "diagnosticls", - "dockerls", - "docker_compose_language_service", - "gopls", - "lua_ls", - "texlab", - "zk", - "pyright", - "r_language_server", - "sqls", - }, - -- auto-install configured servers (with lspconfig) - automatic_installation = true, -- not the same as ensure_installed - }) - - mason_tool_installer.setup({ - ensure_installed = { - "mutt-language-server", - "emmet-ls", - -- Linters: - "prettier", - "bibtex-tidy", - "goimports", - "gci", - "golines", - "shfmt", - "latexindent", - "sql-formatter", - "isort", - "black", - "yamlfix", - "stylua", - -- Formatters: - "stylelint", - "markdownlint", - "pylint", - "golangci-lint", - "shellcheck", - }, - }) - - end, -} -- cgit v1.2.3