From fb07fbdefd9cbe7d3d8a185812d0a930d7ddc4ab Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Sun, 7 Jul 2024 17:54:36 +0300 Subject: [PATCH] Neovim: reworked lsp setup, along with some minor tweaks --- .config/nvim/.luarc.json | 5 +- .config/nvim/init.lua | 1 - .config/nvim/lazy-lock.json | 2 +- .config/nvim/lua/custom/completion.lua | 0 .config/nvim/lua/custom/lsp.lua | 99 +++++++++++++++++++ ...DO-completions.lua => TODO-completion.lua} | 0 .config/nvim/lua/custom/plugins/TODO-lsp.lua | 48 --------- .config/nvim/lua/custom/plugins/lsp.lua | 30 ++++++ .config/nvim/lua/custom/plugins/utility.lua | 6 -- 9 files changed, 131 insertions(+), 60 deletions(-) create mode 100644 .config/nvim/lua/custom/completion.lua create mode 100644 .config/nvim/lua/custom/lsp.lua rename .config/nvim/lua/custom/plugins/{TODO-completions.lua => TODO-completion.lua} (100%) delete mode 100644 .config/nvim/lua/custom/plugins/TODO-lsp.lua create mode 100644 .config/nvim/lua/custom/plugins/lsp.lua diff --git a/.config/nvim/.luarc.json b/.config/nvim/.luarc.json index 1e1765c..2c63c08 100644 --- a/.config/nvim/.luarc.json +++ b/.config/nvim/.luarc.json @@ -1,5 +1,2 @@ { - "diagnostics.globals": [ - "vim" - ] -} \ No newline at end of file +} diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 8e8d744..ad6df15 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -2,4 +2,3 @@ require('options') require('keymaps') require('autocmds') require('plugin-manager') - diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index 8f2bc73..c9ebcd2 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -13,6 +13,7 @@ "darkstorm.nvim": { "branch": "master", "commit": "bab84a698e5a7bec92bd9d24acbd54554502e35e" }, "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, "edgy.nvim": { "branch": "main", "commit": "a8bc1d24798c80a391f1a5d898a50c41a7f93883" }, + "fidget.nvim": { "branch": "main", "commit": "c12f8a58ee472ce5983c3a3f3aad0ff6c49a6a83" }, "friendly-snippets": { "branch": "main", "commit": "682157939e57bd6a2c86277dfd4d6fbfce63dbac" }, "ftFT.nvim": { "branch": "master", "commit": "f3e43c9584e14b27f04c27a95a9d9f0e58dfec02" }, "github-nvim-theme": { "branch": "main", "commit": "4f44a5c930372c85483d02700f332d34417e50b2" }, @@ -26,7 +27,6 @@ "lspsaga.nvim": { "branch": "main", "commit": "6f920cfabddb9b7de5a3a4d0b7cd4f0774ae23e2" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, "lush.nvim": { "branch": "main", "commit": "7c0e27f50901481fe83b974493c4ea67a4296aeb" }, - "luvit-meta": { "branch": "main", "commit": "ce76f6f6cdc9201523a5875a4471dcfe0186eb60" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "37a336b653f8594df75c827ed589f1c91d91ff6c" }, "mason.nvim": { "branch": "main", "commit": "0950b15060067f752fde13a779a994f59516ce3d" }, "material.nvim": { "branch": "main", "commit": "b5d0ff3ad37ba00cea3dc3dce0b0f555b481c6f4" }, diff --git a/.config/nvim/lua/custom/completion.lua b/.config/nvim/lua/custom/completion.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/lua/custom/lsp.lua b/.config/nvim/lua/custom/lsp.lua new file mode 100644 index 0000000..1238001 --- /dev/null +++ b/.config/nvim/lua/custom/lsp.lua @@ -0,0 +1,99 @@ +-- NOTE: A list of language servers (and potentially their config) +-- Accepts either true to enable, false to disable or a table with settings +local servers = { + lua_ls = true, -- lua + clangd = true, -- C/C++ + gradle_ls = true, -- java package manager + jdtls = true, -- java eclipse lsp + kotlin_language_server = true, -- kotlin + pyright = true, -- python + rust_analyzer = true, -- rust + bashls = true, -- bash + taplo = true, -- toml + lemminx = true, -- xml + yamlls = true, -- yaml + jsonls = true, -- json +} + +-- NOTE: Not language servers but still make sure mason installs them +local ensure_installed = { + stylua = true, -- lua formatting +} + +local capabilities = nil +if pcall(require, 'cmp_nvim_lsp') then + capabilities = require('cmp_nvim_lsp').default_capabilities() +end + +local servers_to_install = vim.tbl_filter(function(key) + local server = servers[key] + if type(server) == 'table' then + return true + else + return server + end +end, vim.tbl_keys(servers)) + +require('mason').setup() +vim.list_extend(ensure_installed, servers_to_install) +require('mason-lspconfig').setup({ ensure_installed = servers_to_install }) + +local lspconfig = require('lspconfig') +for name, config in pairs(servers) do + if config == true then + ---@diagnostic disable-next-line: cast-local-type + config = {} + end + config = vim.tbl_deep_extend('force', {}, { + capabilities = capabilities, + }, config) + + lspconfig[name].setup(config) +end + +vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + local bufnr = args.buf + local client = assert(vim.lsp.get_client_by_id(args.data.client_id), 'must have valid client') + + -- TODO: Check if I need this line + -- vim.opt_local.omnifunc = "v:lua.vim.lsp.omnifunc" + + local settings = servers[client.name] + if type(settings) ~= 'table' then + ---@diagnostic disable-next-line: cast-local-type + settings = {} + end + + -- Override server capabilities + if settings.server_capabilities then + for k, v in pairs(settings.server_capabilities) do + if v == vim.NIL then + v = nil + end + client.server_capabilities[k] = v + end + end + end, +}) + +-- TODO: Understand what this is +-- -- Autoformatting Setup +-- require('conform').setup({ +-- formatters_by_ft = { +-- lua = { 'stylua' }, +-- }, +-- }) +-- +-- vim.api.nvim_create_autocmd('BufWritePre', { +-- callback = function(args) +-- require('conform').format({ +-- bufnr = args.buf, +-- lsp_fallback = true, +-- quiet = true, +-- }) +-- end, +-- }) +-- +-- require('lsp_lines').setup() +-- vim.diagnostic.config({ virtual_text = false }) diff --git a/.config/nvim/lua/custom/plugins/TODO-completions.lua b/.config/nvim/lua/custom/plugins/TODO-completion.lua similarity index 100% rename from .config/nvim/lua/custom/plugins/TODO-completions.lua rename to .config/nvim/lua/custom/plugins/TODO-completion.lua diff --git a/.config/nvim/lua/custom/plugins/TODO-lsp.lua b/.config/nvim/lua/custom/plugins/TODO-lsp.lua deleted file mode 100644 index 74b9ed4..0000000 --- a/.config/nvim/lua/custom/plugins/TODO-lsp.lua +++ /dev/null @@ -1,48 +0,0 @@ -return { - { - 'williamboman/mason.nvim', - lazy = false, - config = function() - require('mason').setup() - end, - }, - { - 'williamboman/mason-lspconfig.nvim', - lazy = false, - config = function() - require('mason-lspconfig').setup({ - ensure_installed = { - 'lua_ls', - 'clangd', - 'gradle_ls', - 'jdtls', - 'kotlin_language_server', - 'pyright', - 'rust_analyzer', - 'taplo', - 'bashls', - 'lemminx', - 'yamlls', - }, - }) - end, - }, - { - 'neovim/nvim-lspconfig', - lazy = false, - config = function() - local lspconfig = require('lspconfig') - lspconfig.lua_ls.setup({}) - lspconfig.clangd.setup({}) - lspconfig.gradle_ls.setup({}) - lspconfig.jdtls.setup({}) - lspconfig.kotlin_language_server.setup({}) - lspconfig.pyright.setup({}) - lspconfig.rust_analyzer.setup({}) - lspconfig.taplo.setup({}) - lspconfig.bashls.setup({}) - lspconfig.lemminx.setup({}) - lspconfig.yamlls.setup({}) - end, - }, -} diff --git a/.config/nvim/lua/custom/plugins/lsp.lua b/.config/nvim/lua/custom/plugins/lsp.lua new file mode 100644 index 0000000..e555ace --- /dev/null +++ b/.config/nvim/lua/custom/plugins/lsp.lua @@ -0,0 +1,30 @@ +return { + { + 'neovim/nvim-lspconfig', + lazy = false, + dependencies = { + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig.nvim', + + { + 'folke/lazydev.nvim', + ft = 'lua', + opts = { library = { { path = 'luvit-meta/library', words = { 'vim%.uv' } } } }, + }, + + -- FIXME: Starts with a black blackground + -- Desired behaviour is same color as background or transparent + -- Progress ui + { 'j-hui/fidget.nvim', opts = {} }, + + -- AUtoformatting + -- 'stevear/conform.nvim', + + -- Schema info + -- 'b0o/SchemaStore.nvim', + }, + config = function() + require('custom.lsp') + end, + }, +} diff --git a/.config/nvim/lua/custom/plugins/utility.lua b/.config/nvim/lua/custom/plugins/utility.lua index 41f2925..79eac83 100644 --- a/.config/nvim/lua/custom/plugins/utility.lua +++ b/.config/nvim/lua/custom/plugins/utility.lua @@ -37,12 +37,6 @@ return { vim.keymap.set('n', 'nc', ':Telescope neoclip plus', { desc = '[N]eo[c]lip History' }) end, }, - { 'Bilal2453/luvit-meta', lazy = true }, - { - 'folke/lazydev.nvim', - ft = 'lua', - opts = { library = { { path = 'luvit-meta/library', words = { 'vim%.uv' } } } }, - }, { 'mbbill/undotree', config = function()