From 1874df33b58efb912d6f14c2b659b2b879518267 Mon Sep 17 00:00:00 2001 From: RafayAhmad7548 Date: Wed, 30 Jul 2025 10:59:08 +0500 Subject: [PATCH] lsp redoification update --- .config/nvim/lua/config/keymaps.lua | 1 + .config/nvim/lua/config/options.lua | 1 + .config/nvim/lua/config/plugins/blinkcmp.lua | 72 ----- .config/nvim/lua/config/plugins/init.lua | 1 - .../nvim/lua/config/plugins/languages/lsp.lua | 283 ++++++++++-------- 5 files changed, 164 insertions(+), 194 deletions(-) delete mode 100644 .config/nvim/lua/config/plugins/blinkcmp.lua diff --git a/.config/nvim/lua/config/keymaps.lua b/.config/nvim/lua/config/keymaps.lua index ea5bb49..257f858 100644 --- a/.config/nvim/lua/config/keymaps.lua +++ b/.config/nvim/lua/config/keymaps.lua @@ -80,6 +80,7 @@ vim.keymap.set('n', 'sp', 'SessionSearch', { desc = 'search ses -- INFO: LSP +vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = 'lsp hover' }) vim.keymap.set('n', 'L', vim.diagnostic.open_float, { desc = 'open floating diagnostic' }) -- This function gets run when an LSP attaches to a particular buffer. diff --git a/.config/nvim/lua/config/options.lua b/.config/nvim/lua/config/options.lua index 25dc206..977a59d 100644 --- a/.config/nvim/lua/config/options.lua +++ b/.config/nvim/lua/config/options.lua @@ -42,6 +42,7 @@ vim.opt.fillchars:append({ eob = ' ' }) vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 +vim.o.winborder = 'rounded' vim.opt.hlsearch = false vim.opt.wrap = false diff --git a/.config/nvim/lua/config/plugins/blinkcmp.lua b/.config/nvim/lua/config/plugins/blinkcmp.lua deleted file mode 100644 index 15a864f..0000000 --- a/.config/nvim/lua/config/plugins/blinkcmp.lua +++ /dev/null @@ -1,72 +0,0 @@ -return { - 'saghen/blink.cmp', - event = 'VimEnter', - version = '1.*', - dependencies = { - { - 'L3MON4D3/LuaSnip', - version = '2.*', - build = (function() - if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then - return - end - return 'make install_jsregexp' - end)(), - dependencies = { - -- `friendly-snippets` contains a variety of premade snippets. - -- See the README about individual language/framework/plugin snippets: - -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, - }, - opts = {}, - }, - 'folke/lazydev.nvim', - }, - ---@module 'blink.cmp' - ---@type blink.cmp.Config - opts = { - keymap = { - preset = 'default', - - [''] = { 'select_and_accept', 'snippet_forward', 'fallback'}, - [''] = { 'snippet_backward', 'fallback'}, - ['I'] = { 'scroll_documentation_up', 'fallback' }, - ['K'] = { 'scroll_documentation_down', 'fallback' }, - - }, - - appearance = { nerd_font_variant = 'mono' }, - - completion = { - -- By default, you may press `` to show the documentation. - -- Optionally, set `auto_show = true` to show the documentation after a delay. - documentation = { auto_show = false, auto_show_delay_ms = 500 }, - }, - - sources = { - default = { 'lsp', 'path', 'snippets', 'lazydev' }, - providers = { - lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 }, - }, - }, - - snippets = { preset = 'luasnip' }, - - -- Blink.cmp includes an optional, recommended rust fuzzy matcher, - -- which automatically downloads a prebuilt binary when enabled. - -- - -- By default, we use the Lua implementation instead, but you may enable - -- the rust implementation via `'prefer_rust_with_warning'` - -- - -- See :h blink-cmp-config-fuzzy for more information - fuzzy = { implementation = 'lua' }, - - -- Shows a signature help window while you type arguments for a function - signature = { enabled = true }, - }, -} diff --git a/.config/nvim/lua/config/plugins/init.lua b/.config/nvim/lua/config/plugins/init.lua index 292846c..c27b8aa 100644 --- a/.config/nvim/lua/config/plugins/init.lua +++ b/.config/nvim/lua/config/plugins/init.lua @@ -25,7 +25,6 @@ require('lazy').setup({ require('config.plugins.git'), require('config.plugins.ui'), -- require('config.plugins.telescope'), - require('config.plugins.blinkcmp'), require('config.plugins.languages.lsp'), require('config.plugins.languages.treesitter'), require('config.plugins.harpoon'), diff --git a/.config/nvim/lua/config/plugins/languages/lsp.lua b/.config/nvim/lua/config/plugins/languages/lsp.lua index 8672398..9f1b2fa 100644 --- a/.config/nvim/lua/config/plugins/languages/lsp.lua +++ b/.config/nvim/lua/config/plugins/languages/lsp.lua @@ -1,124 +1,165 @@ -return { - { - -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins - -- used for completion, annotations and signatures of Neovim apis - 'folke/lazydev.nvim', - ft = 'lua', - opts = { - library = { - -- Load luvit types when the `vim.uv` word is found - { path = '${3rd}/luv/library', words = { 'vim%.uv' } }, - }, +local servers = { + bashls = {}, + + clangd = {}, + rust_analyzer = {}, + pyright = {}, + + emmet_language_server = {}, + html = { filetypes = { 'html', 'htmldjango' }, }, + cssls = {}, + vtsls = {}, + + prismals = {}, + + -- kotlin_lsp = {}, + + lua_ls = { + settings = { + Lua = { + completion = { + callSnippet = 'Replace', }, - }, - - { 'williamboman/mason.nvim', opts = {} }, - - { - 'neovim/nvim-lspconfig', - dependencies = { - 'williamboman/mason.nvim', - 'williamboman/mason-lspconfig.nvim', - - -- Useful status updates for LSP. - { 'j-hui/fidget.nvim', opts = {} }, - - 'saghen/blink.cmp', - }, - config = function() - - vim.diagnostic.config { - severity_sort = true, - float = { border = 'rounded', source = 'if_many' }, - underline = { severity = vim.diagnostic.severity.ERROR }, - signs = vim.g.have_nerd_font and { - text = { - [vim.diagnostic.severity.ERROR] = '󰅚 ', - [vim.diagnostic.severity.WARN] = '󰀪 ', - [vim.diagnostic.severity.INFO] = '󰋽 ', - }, - } or {}, - virtual_text = { - source = 'if_many', - spacing = 2, - format = function(diagnostic) - local diagnostic_message = { - [vim.diagnostic.severity.ERROR] = diagnostic.message, - [vim.diagnostic.severity.WARN] = diagnostic.message, - [vim.diagnostic.severity.INFO] = diagnostic.message, - [vim.diagnostic.severity.HINT] = diagnostic.message, - } - return diagnostic_message[diagnostic.severity] - end, - }, - } - - local capabilities = require('blink.cmp').get_lsp_capabilities() - local servers = { - bashls = {}, - - clangd = {}, - rust_analyzer = {}, - pyright = {}, - - emmet_language_server = {}, - html = { filetypes = { 'html', 'htmldjango' }, }, - cssls = {}, - vtsls = {}, - - prismals = {}, - - -- kotlin_lsp = {}, - - -- kotlin_language_server = { - -- init_options = { - -- storagePath = vim.fn.stdpath('cache') .. '/kotlin_language_server', -- Explicit storage path - -- }, - -- }, - - -- -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs - -- - -- Some languages (like typescript) have entire language plugins that can be useful: - -- https://github.com/pmizio/typescript-tools.nvim - -- - -- But for many setups, the LSP (`ts_ls`) will work just fine - -- ts_ls = {}, - -- - - lua_ls = { - -- cmd = { ... }, - -- filetypes = { ... }, - -- capabilities = {}, - settings = { - Lua = { - completion = { - callSnippet = 'Replace', - }, - -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings - -- diagnostics = { disable = { 'missing-fields' } }, - }, - }, - }, - } - - local ensure_installed = vim.tbl_keys(servers or {}) - - require('mason-lspconfig').setup { - ensure_installed = ensure_installed, - automatic_installation = false, - handlers = { - function(server_name) - local server = servers[server_name] or {} - -- This handles overriding only values explicitly passed - -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for ts_ls) - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - require('lspconfig')[server_name].setup(server) - end, - } - } - -- WARN: Temoraray workaround because of naming issue i.e. djlsp and django-template-server - require('lspconfig').djlsp.setup({}) - end + }, + }, + }, +} + +local ensure_installed = vim.tbl_keys(servers or {}) + +for server, config in pairs(servers) do + vim.lsp.config(server, config) +end + +return { + { + -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins + -- used for completion, annotations and signatures of Neovim apis + 'folke/lazydev.nvim', + ft = 'lua', + opts = { + library = { + -- Load luvit types when the `vim.uv` word is found + { path = '${3rd}/luv/library', words = { 'vim%.uv' } }, + }, + }, + }, + + { + + 'saghen/blink.cmp', + event = 'VimEnter', + version = '1.*', + dependencies = { + { + 'L3MON4D3/LuaSnip', + version = '2.*', + build = (function() + if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then + return + end + return 'make install_jsregexp' + end)(), + dependencies = { + -- `friendly-snippets` contains a variety of premade snippets. + -- See the README about individual language/framework/plugin snippets: + -- https://github.com/rafamadriz/friendly-snippets + -- { + -- 'rafamadriz/friendly-snippets', + -- config = function() + -- require('luasnip.loaders.from_vscode').lazy_load() + -- end, + -- }, + }, + opts = {}, + }, + 'folke/lazydev.nvim', + }, + ---@module 'blink.cmp' + ---@type blink.cmp.Config + opts = { + keymap = { + preset = 'default', + + [''] = { 'select_and_accept', 'snippet_forward', 'fallback'}, + [''] = { 'snippet_backward', 'fallback'}, + ['I'] = { 'scroll_documentation_up', 'fallback' }, + ['K'] = { 'scroll_documentation_down', 'fallback' }, + + }, + + appearance = { nerd_font_variant = 'mono' }, + + completion = { + -- By default, you may press `` to show the documentation. + -- Optionally, set `auto_show = true` to show the documentation after a delay. + documentation = { auto_show = false, auto_show_delay_ms = 500 }, + }, + + sources = { + default = { 'lsp', 'path', 'snippets', 'lazydev' }, + providers = { + lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 }, + }, + }, + + snippets = { preset = 'luasnip' }, + + -- Blink.cmp includes an optional, recommended rust fuzzy matcher, + -- which automatically downloads a prebuilt binary when enabled. + -- + -- By default, we use the Lua implementation instead, but you may enable + -- the rust implementation via `'prefer_rust_with_warning'` + -- + -- See :h blink-cmp-config-fuzzy for more information + fuzzy = { implementation = 'lua' }, + + -- Shows a signature help window while you type arguments for a function + signature = { enabled = true }, + }, + }, + + { + 'neovim/nvim-lspconfig', + dependencies = { + -- Useful status updates for LSP. + { 'j-hui/fidget.nvim', opts = {} }, + }, + config = function() + + vim.diagnostic.config { + severity_sort = true, + float = { border = 'rounded', source = 'if_many' }, + underline = { severity = vim.diagnostic.severity.ERROR }, + signs = vim.g.have_nerd_font and { + text = { + [vim.diagnostic.severity.ERROR] = '󰅚 ', + [vim.diagnostic.severity.WARN] = '󰀪 ', + [vim.diagnostic.severity.INFO] = '󰋽 ', + }, + } or {}, + virtual_text = { + source = 'if_many', + spacing = 2, + format = function(diagnostic) + local diagnostic_message = { + [vim.diagnostic.severity.ERROR] = diagnostic.message, + [vim.diagnostic.severity.WARN] = diagnostic.message, + [vim.diagnostic.severity.INFO] = diagnostic.message, + [vim.diagnostic.severity.HINT] = diagnostic.message, + } + return diagnostic_message[diagnostic.severity] + end, + }, + } + + end + }, + + { 'mason-org/mason.nvim', opts = {} }, + + { + 'mason-org/mason-lspconfig.nvim', + opts = { ensure_installed = ensure_installed } }, }