diff --git a/init.lua b/init.lua index f63c4ca3..9af8960d 100644 --- a/init.lua +++ b/init.lua @@ -301,7 +301,7 @@ require('lazy').setup({ -- Then, because we use the `opts` key (recommended), the configuration runs -- after the plugin has been loaded as `require(MODULE).setup(opts)`. - { -- Useful plugin to show you pending keybinds. + { -- Useful plugin to show you pending keybinds. 'folke/which-key.nvim', event = 'VimEnter', -- Sets the loading event to 'VimEnter' opts = { @@ -382,7 +382,7 @@ require('lazy').setup({ { 'nvim-telescope/telescope-ui-select.nvim' }, -- Useful for getting pretty icons, but requires a Nerd Font. - { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, + { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, }, config = function() -- Telescope is a fuzzy finder that comes with a lot of different things that @@ -482,13 +482,6 @@ require('lazy').setup({ -- Main LSP Configuration 'neovim/nvim-lspconfig', dependencies = { - -- Automatically install LSPs and related tools to stdpath for Neovim - -- Mason must be loaded before its dependents so we need to set it up here. - -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})` - { 'mason-org/mason.nvim', opts = {} }, - 'mason-org/mason-lspconfig.nvim', - 'WhoIsSethDaniel/mason-tool-installer.nvim', - -- Useful status updates for LSP. { 'j-hui/fidget.nvim', opts = {} }, @@ -515,9 +508,6 @@ require('lazy').setup({ -- - Symbol Search -- - and more! -- - -- Thus, Language Servers are external tools that must be installed separately from - -- Neovim. This is where `mason` and related plugins come into play. - -- -- If you're wondering about lsp vs treesitter, you can check out the wonderfully -- and elegantly composed help section, `:help lsp-vs-treesitter` @@ -702,40 +692,6 @@ require('lazy').setup({ }, }, } - - -- Ensure the servers and tools above are installed - -- - -- To check the current status of installed tools and/or manually install - -- other tools, you can run - -- :Mason - -- - -- You can press `g?` for help in this menu. - -- - -- `mason` had to be setup earlier: to configure its options see the - -- `dependencies` table for `nvim-lspconfig` above. - -- - -- You can add other tools here that you want Mason to install - -- for you, so that they are available from within Neovim. - local ensure_installed = vim.tbl_keys(servers or {}) - vim.list_extend(ensure_installed, { - 'stylua', -- Used to format Lua code - }) - require('mason-tool-installer').setup { ensure_installed = ensure_installed } - - require('mason-lspconfig').setup { - ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) - 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, - }, - } end, }, diff --git a/lua/custom/plugins/formatting.lua b/lua/custom/plugins/formatting.lua index af803017..047980de 100644 --- a/lua/custom/plugins/formatting.lua +++ b/lua/custom/plugins/formatting.lua @@ -1,40 +1,40 @@ -- Formatter configuration return { - -- ======================================== - -- Formatter Configuration (conform.nvim) - -- ======================================== - { - 'stevearc/conform.nvim', - event = 'BufWritePre', -- Format on save - -- cmd = { 'ConformInfo' }, -- Optional: If you want the command available - -- keys = { ... } -- Optional: Define keys if needed - opts = { - formatters_by_ft = { - lua = { 'stylua' }, - c = { 'clang_format' }, - cpp = { 'clang_format' }, - -- Use ruff for Python formatting (includes isort and is faster than black - -- Ensure 'ruff' is installed via Home Manager (pkgs.ruff) - python = { 'ruff_format', 'ruff_fix' }, - -- python = { 'isort', 'black' }, - nix = { 'alejandra' }, -- Add nix formatter - -- Add other filetypes and formatters, e.g.: - -- javascript = { "prettier" }, - -- typescript = { "prettier" }, - -- css = { "prettier" }, - -- html = { "prettier" }, - -- json = { "prettier" }, - -- yaml = { "prettier" }, - -- markdown = { "prettier" }, - -- bash = { "shfmt" }, - }, - -- Configure format_on_save behavior - format_on_save = { - -- I recommend these options, but adjust to your liking - timeout_ms = 500, -- Stop formatting if it takes too long - lsp_fallback = true, -- Fallback to LSP formatting if conform fails - }, + -- ======================================== + -- Formatter Configuration (conform.nvim) + -- ======================================== + { + 'stevearc/conform.nvim', + event = 'BufWritePre', -- Format on save + -- cmd = { 'ConformInfo' }, -- Optional: If you want the command available + -- keys = { ... } -- Optional: Define keys if needed + opts = { + formatters_by_ft = { + lua = { 'stylua' }, + c = { 'clang_format' }, + cpp = { 'clang_format' }, + -- Use ruff for Python formatting (includes isort and is faster than black + -- Ensure 'ruff' is installed via Home Manager (pkgs.ruff) + python = { 'ruff_format', 'ruff_fix' }, + -- python = { 'isort', 'black' }, + nix = { 'alejandra' }, -- Add nix formatter + -- Add other filetypes and formatters, e.g.: + -- javascript = { "prettier" }, + -- typescript = { "prettier" }, + -- css = { "prettier" }, + -- html = { "prettier" }, + -- json = { "prettier" }, + -- yaml = { "prettier" }, + -- markdown = { "prettier" }, + -- bash = { "shfmt" }, + }, + -- Configure format_on_save behavior + format_on_save = { + -- I recommend these options, but adjust to your liking + timeout_ms = 500, -- Stop formatting if it takes too long + lsp_fallback = true, -- Fallback to LSP formatting if conform fails + }, + }, }, - }, } diff --git a/lua/custom/plugins/lsp.lua b/lua/custom/plugins/lsp.lua index 54cd7c5c..b3c5249f 100644 --- a/lua/custom/plugins/lsp.lua +++ b/lua/custom/plugins/lsp.lua @@ -1,154 +1,122 @@ return { - -- ======================================== - -- LSP Configuration Override (via mason-lspconfig) - -- ======================================== - { - 'neovim/nvim-lspconfig', - -- Define dependencies required by lspconfig and related features - dependencies = { - -- Mason must be loaded before mason-lspconfig - { 'williamboman/mason.nvim', opts = {} }, -- Basic setup for mason - { - 'williamboman/mason-lspconfig.nvim', - -- This table defines the options for mason-lspconfig - -- It tells mason-lspconfig which servers Mason should install. - opts = { - ensure_installed = { - 'lua_ls', - 'clangd', - 'pyright', - 'nil_ls', - -- Add others like 'bashls', 'yamlls', 'nixd', 'gopls', 'rust_analyzer' etc. if needed - }, - }, - }, - -- Optional: Tool installer for linters/formatters not handled by LSP - -- 'WhoIsSethDaniel/mason-tool-installer.nvim', + -- ======================================== + -- LSP Configuration Override + -- ======================================== + { + -- Status updates for LSP + { 'j-hui/fidget.nvim', opts = {} }, - -- Status updates for LSP - { 'j-hui/fidget.nvim', opts = {} }, - - -- LSP source for nvim-cmp (ensure this is also listed as dep for nvim-cmp) - 'hrsh7th/cmp-nvim-lsp', + -- LSP source for nvim-cmp (ensure this is also listed as dep for nvim-cmp) + 'hrsh7th/cmp-nvim-lsp', }, config = function(_, opts) - -- This config function runs AFTER the plugin and its dependencies are loaded. - -- It sets up the LSP servers based on the configurations provided. + -- Get LSP capabilities, augmented by nvim-cmp + local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) - -- Get LSP capabilities, augmented by nvim-cmp - local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) + local servers_to_setup = { 'lua_ls', 'clangd', 'pyright' } -- <-- EXPLICIT LIST HERE - -- Call mason-lspconfig's setup function. This primarily ensures that the - -- ensure_installed list above is processed by Mason for installation. - -- We don't rely on this setup call to configure the servers below anymore. - -- require('mason-lspconfig').setup(opts) -- This might not even be needed if opts are passed automatically - - -- Manually define the list of servers we want lspconfig to setup. - -- This list should match the 'ensure_installed' list for mason-lspconfig above. - local servers_to_setup = { 'lua_ls', 'clangd', 'pyright' } -- <-- EXPLICIT LIST HERE - - -- Iterate through the defined servers list and set them up with lspconfig - for _, server_name in ipairs(servers_to_setup) do - -- print('Setting up LSP server: ' .. server_name) -- Debug print - require('lspconfig')[server_name].setup { - capabilities = capabilities, -- Pass augmented capabilities - -- Add any server-specific overrides here if needed - } - end - - -- Setup keymaps and diagnostics based on kickstart's original init.lua LSP section - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-attach-override', { clear = true }), - callback = function(event) - local map = function(keys, func, desc, mode) - mode = mode or 'n' - vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) - end - - -- Standard LSP keymaps - map('grn', vim.lsp.buf.rename, '[R]e[n]ame') - map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' }) - map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') - map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols') - map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols') - map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition') - - -- Highlight references - local client = vim.lsp.get_client_by_id(event.data.client_id) - local function client_supports_method(client, method, bufnr) - if vim.fn.has 'nvim-0.11' == 1 then - return client:supports_method(method, { bufnr = bufnr }) - else - return client.supports_method(method, { bufnr = bufnr }) - end - end - if client and client_supports_method(client, 'textDocument/documentHighlight', event.buf) then - local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight-override', { clear = false }) - vim.api.nvim_create_autocmd( - { 'CursorHold', 'CursorHoldI' }, - { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.document_highlight } - ) - vim.api.nvim_create_autocmd( - { 'CursorMoved', 'CursorMovedI' }, - { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.clear_references } - ) - vim.api.nvim_create_autocmd('LspDetach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-detach-override', { clear = true }), - callback = function(event2) - vim.lsp.buf.clear_references() - vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight-override', buffer = event2.buf } - end, - }) - end - - -- Inlay hints toggle - if client and client_supports_method(client, 'textDocument/inlayHint', event.buf) then - map('th', function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) - end, '[T]oggle Inlay [H]ints') - end - end, - }) - - -- Diagnostic configuration - 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] = '󰋽 ', - [vim.diagnostic.severity.HINT] = '󰌶 ', - }, - } 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, + -- Iterate through the defined servers list and set them up with lspconfig + for _, server_name in ipairs(servers_to_setup) do + require('lspconfig')[server_name].setup { + capabilities = capabilities, -- Pass augmented capabilities + -- Add any server-specific overrides here if needed } - return diagnostic_message[diagnostic.severity] - end, - }, - } - end, -- End of config function - }, + end - -- lazydev setup - { - 'folke/lazydev.nvim', - ft = 'lua', - opts = { - library = { { path = 'luvit-meta/library', words = { 'vim%.uv' } } }, + -- Setup keymaps and diagnostics based on kickstart's original init.lua LSP section + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-attach-override', { clear = true }), + callback = function(event) + local map = function(keys, func, desc, mode) + mode = mode or 'n' + vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) + end + + -- Standard LSP keymaps + map('grn', vim.lsp.buf.rename, '[R]e[n]ame') + map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' }) + map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols') + map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols') + map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition') + + -- Highlight references + local client = vim.lsp.get_client_by_id(event.data.client_id) + local function client_supports_method(client, method, bufnr) + if vim.fn.has 'nvim-0.11' == 1 then + return client:supports_method(method, { bufnr = bufnr }) + else + return client.supports_method(method, { bufnr = bufnr }) + end + end + + if client and client_supports_method(client, 'textDocument/documentHighlight', event.buf) then + local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight-override', + { clear = false }) + vim.api.nvim_create_autocmd( + { 'CursorHold', 'CursorHoldI' }, + { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.document_highlight } + ) + vim.api.nvim_create_autocmd( + { 'CursorMoved', 'CursorMovedI' }, + { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.clear_references } + ) + vim.api.nvim_create_autocmd('LspDetach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-detach-override', { clear = true }), + callback = function(event2) + vim.lsp.buf.clear_references() + vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight-override', buffer = event2.buf } + end, + }) + end + + -- Inlay hints toggle + if client and client_supports_method(client, 'textDocument/inlayHint', event.buf) then + map('th', function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) + end, '[T]oggle Inlay [H]ints') + end + end, + }) + + -- Diagnostic configuration + 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] = '󰋽 ', + [vim.diagnostic.severity.HINT] = '󰌶 ', + }, + } 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, -- End of config function + + -- lazydev setup + { + 'folke/lazydev.nvim', + ft = 'lua', + opts = { + library = { { path = 'luvit-meta/library', words = { 'vim%.uv' } } }, + }, }, - }, } diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 8e332bf2..77880880 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -17,10 +17,6 @@ return { -- Required dependency for nvim-dap-ui 'nvim-neotest/nvim-nio', - -- Installs the debug adapters for you - 'mason-org/mason.nvim', - 'jay-babu/mason-nvim-dap.nvim', - -- Add your own debuggers here 'leoluz/nvim-dap-go', }, @@ -81,23 +77,6 @@ return { local dap = require 'dap' local dapui = require 'dapui' - require('mason-nvim-dap').setup { - -- Makes a best effort to setup the various debuggers with - -- reasonable debug configurations - automatic_installation = true, - - -- You can provide additional configuration to the handlers, - -- see mason-nvim-dap README for more information - handlers = {}, - - -- You'll need to check that you have the required things installed - -- online, please don't ask me how to install them :) - ensure_installed = { - -- Update this to ensure that you have the debuggers for the langs you want - 'delve', - }, - } - -- Dap UI setup -- For more information, see |:help nvim-dap-ui| dapui.setup {