diff --git a/.config/nvim/.luarc.json b/.config/nvim/.luarc.json index 2c63c08..0967ef4 100644 --- a/.config/nvim/.luarc.json +++ b/.config/nvim/.luarc.json @@ -1,2 +1 @@ -{ -} +{} diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index 274d732..bad9a6e 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -31,6 +31,7 @@ "lualine.nvim": { "branch": "master", "commit": "544dd1583f9bb27b393f598475c89809c4d5e86b" }, "lush.nvim": { "branch": "main", "commit": "1b66ab197b177aabc2270a2c9cb8019fa5a367df" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "58bc9119ca273c0ce5a66fad1927ef0f617bd81b" }, + "mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" }, "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, "material.nvim": { "branch": "main", "commit": "b5d0ff3ad37ba00cea3dc3dce0b0f555b481c6f4" }, "min-theme.nvim": { "branch": "main", "commit": "23ea3e1dd9e281973b4732cea0968f6d2ab72c47" }, @@ -44,6 +45,7 @@ "nvim": { "branch": "main", "commit": "0b5df9c9e641b1212b21a0762ccad4434fd41322" }, "nvim-autopairs": { "branch": "master", "commit": "78a4507bb9ffc9b00f11ae0ac48243d00cb9194d" }, "nvim-cmp": { "branch": "main", "commit": "d818fd0624205b34e14888358037fb6f5dc51234" }, + "nvim-lsp-file-operations": { "branch": "master", "commit": "92a673de7ecaa157dd230d0128def10beb56d103" }, "nvim-lspconfig": { "branch": "master", "commit": "e26da408cf955afa8e9ddbadd510e84ea8976cd7" }, "nvim-spectre": { "branch": "master", "commit": "9a28f926d3371b7ef02243cbbb653a0478d06e31" }, "nvim-surround": { "branch": "main", "commit": "ec2dc7671067e0086cdf29c2f5df2dd909d5f71f" }, diff --git a/.config/nvim/lua/custom/configs/language-servers.lua b/.config/nvim/lua/custom/configs/language-servers.lua new file mode 100644 index 0000000..78dd6e5 --- /dev/null +++ b/.config/nvim/lua/custom/configs/language-servers.lua @@ -0,0 +1,16 @@ +-- NOTE: A list of language servers (and potentially their config) +-- Accepts either true to enable, false to disable or a table with settings +return { + 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 +} diff --git a/.config/nvim/lua/custom/configs/lsp-keymaps.lua b/.config/nvim/lua/custom/configs/lsp-keymaps.lua new file mode 100644 index 0000000..f43a03e --- /dev/null +++ b/.config/nvim/lua/custom/configs/lsp-keymaps.lua @@ -0,0 +1,58 @@ +local severity = vim.diagnostic.severity +local function next_diagnostic(diagnostic_severity) + return function() + require('lspsaga.diagnostic'):goto_next({ severity = diagnostic_severity }) + end +end +local function prev_diagnostic(diagnostic_severity) + return function() + require('lspsaga.diagnostic'):goto_prev({ severity = diagnostic_severity }) + end +end +local function cursor_diagnostics() + vim.diagnostic.open_float({ + scope = 'cursor', + border = 'single', + }) +end + +local keymaps = { + { 'n', 'gd', 'Telescope lsp_definitions', { desc = '[G]oto [D]efinition' } }, + { 'n', 'gu', 'Telescope lsp_references', { desc = '[G]oto [U]sages' } }, + { 'n', 'gi', 'Telescope lsp_implementations', { desc = '[G]oto [I]mplementations' } }, + { 'n', 'gt', 'Telescope lsp_type_definitions', { desc = '[G]oto [T]ype Definitions' } }, + { 'n', 'ds', 'Telescope lsp_document_symbols', { desc = '[D]ocument [S]symbols' } }, + { 'n', 'ps', 'Telescope lsp_workspace_symbols', { desc = '[P]roject [S]ymbols' } }, + { { 'n', 'i' }, '', vim.lsp.buf.signature_help, { desc = 'Show [P]arameters' } }, + { 'n', 'K', 'Lspsaga hover_doc', { desc = 'Documentation' } }, + { 'n', 'R', 'Lspsaga rename', { desc = '[R]ename' } }, + { { 'n', 'i' }, '', 'Lspsaga code_action', { desc = 'Code Actions' } }, + { 'n', 'ca', 'Lspsaga code_action', { desc = '[C]ode [A]ctions' } }, + { 'n', 'ge', next_diagnostic(severity.ERROR), { desc = '[G]oto [E]rror' } }, + { 'n', 'gE', prev_diagnostic(severity.ERROR), { desc = '[G]oto [E]rror (prev)' } }, + { 'n', 'gw', next_diagnostic(severity.ERROR), { desc = '[G]oto [W]arning' } }, + { 'n', 'gW', prev_diagnostic(severity.ERROR), { desc = '[G]oto [W]arning (prev)' } }, + { 'n', 'D', cursor_diagnostics, { desc = '[D]iagnostics under cursor' } }, +} + +local M = {} + +--- Registers LSP keymaps for the given buffer +---@param bufnr number: the id of the buffer +M.setup = function(bufnr) + for _, keymap in ipairs(keymaps) do + local mode = keymap[1] + local lhs = keymap[2] + local rhs = keymap[3] + local opts = keymap[4] + + if not opts then + opts = {} + end + + opts.buffer = bufnr + vim.keymap.set(mode, lhs, rhs, opts) + end +end + +return M diff --git a/.config/nvim/lua/custom/configs/lsp.lua b/.config/nvim/lua/custom/configs/lsp.lua new file mode 100644 index 0000000..afae5af --- /dev/null +++ b/.config/nvim/lua/custom/configs/lsp.lua @@ -0,0 +1,63 @@ +local capabilities = require('cmp_nvim_lsp').default_capabilities() +local servers = require('custom.configs.language-servers') + +local lspconfig = require('lspconfig') +for name, config in pairs(servers) do + if config == true then + ---@diagnostic disable-next-line: cast-local-type + config = {} + end + ---@diagnostic disable-next-line: cast-local-type + 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') + + 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 + + -- Register LSP keymaps local to buffer + require('custom.configs.lsp-keymaps').setup(bufnr) + end, +}) + +-- TODO: Decide if you want to use conform or not +-- +-- -- 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, +-- }) + +vim.diagnostic.config({ virtual_text = false }) diff --git a/.config/nvim/lua/custom/configs/mason.lua b/.config/nvim/lua/custom/configs/mason.lua new file mode 100644 index 0000000..d7a537b --- /dev/null +++ b/.config/nvim/lua/custom/configs/mason.lua @@ -0,0 +1,33 @@ +-- NOTE: Not language servers but still make sure mason installs them +local ensure_installed = { + stylua = true, -- lua formatting +} +local servers = require('custom.configs.language-servers') + +require('mason').setup({ + ui = { + icons = { + package_installed = '✓', + package_pending = '➜', + package_uninstalled = '✗', + }, + }, +}) + +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)) + +vim.list_extend(ensure_installed, servers_to_install) +require('mason-lspconfig').setup({ ensure_installed = servers_to_install }) + +require('mason-tool-installer').setup({ + ensure_installed = { + 'stylua', -- lua formatter + }, +}) diff --git a/.config/nvim/lua/custom/lsp.lua b/.config/nvim/lua/custom/lsp.lua deleted file mode 100644 index 77bbe07..0000000 --- a/.config/nvim/lua/custom/lsp.lua +++ /dev/null @@ -1,183 +0,0 @@ --- Setup null-ls -local null_ls = require('null-ls') -null_ls.setup({ - sources = { - null_ls.builtins.formatting.stylua, - }, -}) - --- Setup lsp signature --- FIXME: fork the repo and fix the following issues --- Remove documentation, show just the signature (in insert AND normal) --- Make both insert and normal be toggelable rather than insert always showing and normal toggleable -require('lsp_signature').setup({ - bind = true, -- This is mandatory, otherwise border config won't get registered. - handler_opts = { border = 'single' }, - doc_lines = 0, - hint_enable = false, -}) - -require('lspsaga').setup({ - lightbulb = { - enable = false, - sign = false, - virtual_text = true, - }, - implement = { - sign = false, - virtual_text = true, - }, - floaterm = { - height = 0.7, - width = 0.7, - }, - outline = { - layout = 'float', - }, - -- TODO: Change in rename to smthing else - -- bcz I am using for moving between windows - -- Maybe for abort, for confirm -}) - --- 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') - - 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: Decide if you want to use conform or not --- --- -- 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 }) -vim.keymap.set('', 'dt', require('lsp_lines').toggle, { desc = '[D]iagnostics [T]oggle inline' }) - -local lspsaga_diagnostic = require('lspsaga.diagnostic') -local builtin = require('telescope.builtin') -local severity = vim.diagnostic.severity -local show_workspace_diagnostics = 'Lspsaga show_workspace_diagnostics ++normal' -local function next_diagnostic(diagnostic_severity) - return function() - lspsaga_diagnostic:goto_next({ severity = diagnostic_severity }) - end -end -local function prev_diagnostic(diagnostic_severity) - return function() - lspsaga_diagnostic:goto_prev({ severity = diagnostic_severity }) - end -end -local function cursor_diagnostics() - vim.diagnostic.open_float({ - scope = 'cursor', - border = 'single', - }) -end - --- LSP Keybindings -vim.keymap.set('n', 'gd', builtin.lsp_definitions, { desc = '[G]oto [D]efinition' }) -vim.keymap.set('n', 'gu', builtin.lsp_references, { desc = '[G]oto [U]sages' }) -vim.keymap.set('n', 'gi', builtin.lsp_implementations, { desc = '[G]oto [I]mplementations' }) --- vim.keymap.set('n', 'gt', builtin.lsp_type_definitions, { desc = '[G]oto [T]ype Definitions' }) --- vim.keymap.set('n', 'gw', builtin.diagnostics, { desc = '[G]oto [W]arnings' }) -vim.keymap.set('n', 'ds', builtin.lsp_document_symbols, { desc = '[D]ocument [S]symbols' }) -vim.keymap.set('n', 'ps', builtin.lsp_workspace_symbols, { desc = '[P]roject [S]ymbols' }) -vim.keymap.set({ 'n', 'i' }, '', vim.lsp.buf.signature_help, { desc = 'List [P]arameters' }) -vim.keymap.set('n', 'K', 'Lspsaga hover_doc', { desc = 'Documentation' }) -vim.keymap.set('n', 'R', 'Lspsaga rename', { desc = '[R]ename' }) --- vim.keymap.set('n', 'os', 'Lspsaga outline', { desc = '[T]erminal' }) -vim.keymap.set({ 'n', 'i' }, '', 'Lspsaga code_action', { desc = 'Code Actions' }) -vim.keymap.set('n', 'ca', 'Lspsaga code_action', { desc = '[C]ode [A]ctions' }) -vim.keymap.set('n', 'ge', next_diagnostic(severity.ERROR), { desc = '[G]oto [E]rror' }) -vim.keymap.set('n', 'gE', prev_diagnostic(severity.ERROR), { desc = '[G]oto [E]rror (prev)' }) -vim.keymap.set('n', 'gw', next_diagnostic(severity.ERROR), { desc = '[G]oto [W]arning' }) -vim.keymap.set('n', 'gW', prev_diagnostic(severity.ERROR), { desc = '[G]oto [W]arning (prev)' }) -vim.keymap.set('n', 'dw', show_workspace_diagnostics, { desc = '[D]iagnostics for [W]orkspace' }) -vim.keymap.set('n', 'D', cursor_diagnostics, { desc = '[D]iagnostics under cursor' }) - -vim.keymap.set({ 'n', 't' }, '', 'Lspsaga term_toggle', { desc = '[T]erminal' }) diff --git a/.config/nvim/lua/custom/plugins/lsp-plugins.lua b/.config/nvim/lua/custom/plugins/lsp-plugins.lua new file mode 100644 index 0000000..5a6f275 --- /dev/null +++ b/.config/nvim/lua/custom/plugins/lsp-plugins.lua @@ -0,0 +1,72 @@ +return { + { + 'nvimtools/none-ls.nvim', + config = function() + local null_ls = require('null-ls') + null_ls.setup({ + sources = { + null_ls.builtins.formatting.stylua, + }, + }) + end, + }, + -- NOTE: [Good alternative](https://github.com/rachartier/tiny-inline-diagnostic.nvim) + -- although, this plugin is amazing, so I wouldn't switch it most likely + { + 'https://git.sr.ht/~whynothugo/lsp_lines.nvim', + event = 'BufEnter', + config = function() + require('lsp_lines').setup() + vim.keymap.set('n', 'dt', require('lsp_lines').toggle, { desc = '[D]iagnostics [T]oggle inline' }) + end, + }, + { + -- FIXME: fork the repo and fix the following issues + -- Make both insert and normal be toggelable rather than insert always showing and normal toggleable + 'ray-x/lsp_signature.nvim', + event = 'VeryLazy', + opts = { + bind = true, -- This is mandatory, otherwise border config won't get registered. + handler_opts = { border = 'single' }, + doc_lines = 0, + hint_enable = false, + }, + }, + { + 'folke/lazydev.nvim', + ft = 'lua', + opts = { library = { { path = 'luvit-meta/library', words = { 'vim%.uv' } } } }, + }, + { + 'nvimdev/lspsaga.nvim', + dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' }, + event = 'LspAttach', + opts = { + lightbulb = { + enable = false, + sign = false, + virtual_text = true, + }, + implement = { + sign = false, + virtual_text = true, + }, + floaterm = { + height = 0.7, + width = 0.7, + }, + outline = { + layout = 'float', + }, + -- TODO: Change in rename to smthing else + -- bcz I am using for moving between windows + -- Maybe for abort, for confirm + }, + }, + + -- AUtoformatting + -- 'stevear/conform.nvim', + + -- Schema info + -- 'b0o/SchemaStore.nvim', +} diff --git a/.config/nvim/lua/custom/plugins/lsp.lua b/.config/nvim/lua/custom/plugins/lsp.lua index 3f12e9a..f6b8b28 100644 --- a/.config/nvim/lua/custom/plugins/lsp.lua +++ b/.config/nvim/lua/custom/plugins/lsp.lua @@ -1,36 +1,24 @@ return { - { - 'neovim/nvim-lspconfig', - lazy = false, - dependencies = { - 'williamboman/mason.nvim', + -- NOTE: Make sure the order is as follows: + -- Mason loads -> Mason lspconfig loads -> Lspconfig loads + 'neovim/nvim-lspconfig', + event = { 'BufReadPre', 'BufNewFile' }, + dependencies = { + 'hrsh7th/cmp-nvim-lsp', + { 'antosha417/nvim-lsp-file-operations', conifg = true }, + { 'williamboman/mason-lspconfig.nvim', - - 'nvimtools/none-ls.nvim', - - -- NOTE: [Good alternative](https://github.com/rachartier/tiny-inline-diagnostic.nvim) - -- although, this plugin is amazing, so I wouldn't switch it most likely - { 'https://git.sr.ht/~whynothugo/lsp_lines.nvim' }, - - { - 'nvimdev/lspsaga.nvim', - dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' }, + dependencies = { + { 'williamboman/mason.nvim', cmd = 'Mason' }, + 'WhoIsSethDaniel/mason-tool-installer.nvim', }, - { - 'folke/lazydev.nvim', - ft = 'lua', - opts = { library = { { path = 'luvit-meta/library', words = { 'vim%.uv' } } } }, - }, - { 'ray-x/lsp_signature.nvim', event = 'VeryLazy' }, - - -- AUtoformatting - -- 'stevear/conform.nvim', - - -- Schema info - -- 'b0o/SchemaStore.nvim', + build = ':MasonUpdate', + config = function() + require('custom.configs.mason') + end, }, - config = function() - require('custom.lsp') - end, }, + config = function() + require('custom.configs.lsp') + end, } diff --git a/.config/nvim/lua/custom/plugins/telescope.lua b/.config/nvim/lua/custom/plugins/telescope.lua index 6de07d5..1d8f49c 100644 --- a/.config/nvim/lua/custom/plugins/telescope.lua +++ b/.config/nvim/lua/custom/plugins/telescope.lua @@ -6,6 +6,7 @@ return { { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' }, 'nvim-telescope/telescope-ui-select.nvim', }, + cmd = 'Telescope', config = function() require('custom.telescope') end,