diff --git a/config/nvim/lua/autogroups.lua b/config/nvim/lua/autogroups.lua index 85e565c..add83eb 100644 --- a/config/nvim/lua/autogroups.lua +++ b/config/nvim/lua/autogroups.lua @@ -104,15 +104,4 @@ autocmd({ 'BufRead', 'BufNewFile' }, { command = 'set filetype=sshconfig', }) --- Format on save, unless disabled -autocmd('BufWritePre', { - group = augroup('Format', { clear = true }), - pattern = '*', -- All files - callback = function() - if not vim.g.disable_autoformat then - vim.lsp.buf.format({ async = false }) - end - end, -}) - -- vim: ts=2 sts=2 sw=2 et diff --git a/config/nvim/lua/keymaps.lua b/config/nvim/lua/keymaps.lua index 83b8d41..d108c2c 100644 --- a/config/nvim/lua/keymaps.lua +++ b/config/nvim/lua/keymaps.lua @@ -20,8 +20,16 @@ K.n('+', ':resize +10', { desc = 'H Resize +' }) K.n('=', '=', { desc = 'Equal Size Splits' }) -- ── Deal with word wrap ───────────────────────────────────────────── -K.n('k', "v:count == 0 ? 'gk' : 'k'", { desc = 'Move up', noremap = true, expr = true }) -K.n('j', "v:count == 0 ? 'gj' : 'j'", { desc = 'Move down', noremap = true, expr = true }) +K.n( + 'k', + "v:count == 0 ? 'gk' : 'k'", + { desc = 'Move up', noremap = true, expr = true } +) +K.n( + 'j', + "v:count == 0 ? 'gj' : 'j'", + { desc = 'Move down', noremap = true, expr = true } +) -- ── Text manipulation ─────────────────────────────────────────────── K.d('<', { 'n', 'v' }, '', 'Code Action') K.ld('cci', 'n', ':Lspsaga incoming_calls', 'Incoming Calls') K.ld('cco', 'n', ':Lspsaga outgoing_calls', 'Outgoing Calls') K.ld('cd', 'n', ':Lspsaga show_line_diagnostics', 'Line Diagnostics') -K.ld('cf', { 'n', 'x' }, ':lua vim.lsp.buf.format()', 'Format') +-- K.ld('cf', { 'n', 'x' }, ':lua vim.lsp.buf.format()', 'Format') K.ld('cg', 'n', ':lua require("neogen").generate()', 'Generate annotations') K.ld('ci', 'n', ':Lspsaga implement', 'Implementations') K.ld('cl', 'n', ':Lspsaga show_cursor_diagnostics', 'Cursor Diagnostics') @@ -84,14 +92,18 @@ K.nl('cbt', 'CBllline', 'CB: Titled Line') -- unless it's a generic operation like searching or finding buffers K.nl('f', ':Telescope find_files', 'Find Files') K.nl(',', ':Telescope buffers', 'Find existing buffers') -K.nl('/', function() - require('telescope.builtin').current_buffer_fuzzy_find( - require('telescope.themes').get_dropdown { - winblend = 20, - previewer = true, - } - ) -end, 'Fuzzily search in current buffer') +K.nl( + '/', + function() + require('telescope.builtin').current_buffer_fuzzy_find( + require('telescope.themes').get_dropdown { + winblend = 20, + previewer = true, + } + ) + end, + 'Fuzzily search in current buffer' +) K.nl('sc', ':Telescope commands', 'Commands') K.nl('sd', ':Telescope diagnostics', 'Search Diagnostics') @@ -100,7 +112,11 @@ K.nl('sh', ':Telescope help_tags', 'Help tags') K.nl('sk', ':Telescope keymaps', 'Search Keymaps') K.nl('sl', ':Telescope luasnip', 'Search LuaSnip') K.nl('so', ':Telescope oldfiles', 'Old Files') -K.nl('sp', ':lua require("telescope").extensions.lazy_plugins.lazy_plugins()', 'Lazy Plugins') +K.nl( + 'sp', + ':lua require("telescope").extensions.lazy_plugins.lazy_plugins()', + 'Lazy Plugins' +) K.nl('sq', ':Telescope quickfix', 'Quickfix') K.nl('ss', ':Telescope treesitter', 'Treesitter') K.nl('st', ':TodoTelescope', 'Search Todos') diff --git a/config/nvim/lua/plugins/lsp.lua b/config/nvim/lua/plugins/lsp.lua index 386dafb..dd285d8 100644 --- a/config/nvim/lua/plugins/lsp.lua +++ b/config/nvim/lua/plugins/lsp.lua @@ -1,4 +1,129 @@ +-- ╭─────────────────────────────────────────────────────────╮ +-- │ LSP Setup and configuration │ +-- ╰─────────────────────────────────────────────────────────╯ + +-- LSP Servers are installed and configured by lsp-setup.nvim +-- Mason formatters Conform uses to format files +-- These are automatically configured by zapling/mason-conform.nvim + +local lsp_servers = { + bashls = {}, + -- csharp_ls = {}, + diagnosticls = {}, + gopls = { + settings = { + gopls = { + hints = { + rangeVariableTypes = true, + parameterNames = true, + constantValues = true, + assignVariableTypes = true, + compositeLiteralFields = true, + compositeLiteralTypes = true, + functionTypeParameters = true, + }, + }, + }, + }, + html = {}, + intelephense = {}, + jsonls = {}, + lua_ls = { + settings = { + Lua = { + completion = { + callSnippet = 'Replace', + }, + diagnostics = { + globals = { + 'vim', + -- busted + 'describe', + 'it', + 'before_each', + 'after_each', + 'assert', + }, + disable = { + -- Ignore lua_ls noisy `missing-fields` warnings + 'missing-fields', + }, + }, + hint = { + enable = false, + arrayIndex = 'Auto', + await = true, + paramName = 'All', + paramType = true, + semicolon = 'SameLine', + setType = false, + }, + }, + }, + }, + tailwindcss = {}, + ts_ls = { + settings = { + typescript = { + inlayHints = { + includeInlayParameterNameHints = 'all', + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayVariableTypeHintsWhenTypeMatchesName = false, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + }, + }, + vimls = {}, + volar = { + settings = { + typescript = { + inlayHints = { + enumMemberValues = { + enabled = true, + }, + functionLikeReturnTypes = { + enabled = true, + }, + propertyDeclarationTypes = { + enabled = true, + }, + parameterTypes = { + enabled = true, + suppressWhenArgumentMatchesName = true, + }, + variableTypes = { + enabled = true, + }, + }, + }, + }, + }, +} + return { + -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins + -- used for completion, annotations and signatures of Neovim apis + -- https://github.com/folke/lazydev.nvim + { + 'folke/lazydev.nvim', + ft = 'lua', + opts = { + library = { + -- Load luvit types when the `vim.uv` word is found + { path = 'luvit-meta/library', words = { 'vim%.uv' } }, + }, + }, + }, + + -- Meta type definitions for the Lua platform Luvit. + -- https://github.com/Bilal2453/luvit-meta + { 'Bilal2453/luvit-meta', lazy = true }, + -- improve neovim lsp experience -- https://github.com/nvimdev/lspsaga.nvim -- https://nvimdev.github.io/lspsaga/ @@ -24,21 +149,72 @@ return { }, }, }, + -- A simple wrapper for nvim-lspconfig and mason-lspconfig -- to easily setup LSP servers. -- https://github.com/junnplus/lsp-setup.nvim { 'junnplus/lsp-setup.nvim', dependencies = { + -- Quickstart configs for Nvim LSP + -- https://github.com/neovim/nvim-lspconfig { 'neovim/nvim-lspconfig' }, + + -- Portable package manager for Neovim that runs everywhere Neovim runs. + -- Easily install and manage LSP servers, DAP servers, linters, and formatters. + -- https://github.com/williamboman/mason.nvim { 'williamboman/mason.nvim', + version = '*', cmd = 'Mason', - run = ':MasonUpdate' + run = ':MasonUpdate', + opts = {}, }, + + -- Extensible UI for Neovim notifications and LSP progress messages. + -- https://github.com/j-hui/fidget.nvim + { + 'j-hui/fidget.nvim', + version = '*', + opts = {}, + }, + + -- Extension to mason.nvim that makes it easier to use lspconfig with mason.nvim. + -- https://github.com/williamboman/mason-lspconfig.nvim { 'williamboman/mason-lspconfig.nvim' }, - { 'folke/neodev.nvim' }, + + -- Install and upgrade third party tools automatically + -- https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim + { + 'WhoIsSethDaniel/mason-tool-installer.nvim', + version = '*', + opts = { + auto_install = true, + auto_update = true, + ensure_installed = { + 'editorconfig-checker', + 'goimports', + 'gotests', + 'phpcbf', + 'pint', + 'prettierd', + 'shellcheck', + 'shfmt', + 'staticcheck', + 'stylua', + 'vint', + 'yamlfmt', + }, + }, + }, + + -- JSON schemas for Neovim + -- https://github.com/b0o/SchemaStore.nvim { 'b0o/schemastore.nvim' }, + + -- Performant, batteries-included completion plugin for Neovim + -- https://github.com/saghen/blink.cmp + -- See lua/plugins/blink.lua for configs { 'saghen/blink.cmp' }, }, opts = { @@ -51,126 +227,45 @@ return { inlay_hints = { enabled = true, }, - servers = { - bashls = {}, - -- csharp_ls = {}, - diagnosticls = {}, - gopls = { - settings = { - gopls = { - hints = { - rangeVariableTypes = true, - parameterNames = true, - constantValues = true, - assignVariableTypes = true, - compositeLiteralFields = true, - compositeLiteralTypes = true, - functionTypeParameters = true, - }, - }, - }, - }, - html = {}, - intelephense = {}, - jsonls = {}, - lua_ls = { - settings = { - Lua = { - diagnostics = { - globals = { 'vim' }, - disable = { - -- Ignore lua_ls noisy `missing-fields` warnings - 'missing-fields', - }, - }, - hint = { - enable = false, - arrayIndex = 'Auto', - await = true, - paramName = 'All', - paramType = true, - semicolon = 'SameLine', - setType = false, - }, - }, - }, - }, - tailwindcss = {}, - ts_ls = { - settings = { - typescript = { - inlayHints = { - includeInlayParameterNameHints = 'all', - includeInlayParameterNameHintsWhenArgumentMatchesName = false, - includeInlayFunctionParameterTypeHints = true, - includeInlayVariableTypeHints = true, - includeInlayVariableTypeHintsWhenTypeMatchesName = false, - includeInlayPropertyDeclarationTypeHints = true, - includeInlayFunctionLikeReturnTypeHints = true, - includeInlayEnumMemberValueHints = true, - }, - }, - }, - }, - vimls = {}, - volar = { - settings = { - typescript = { - inlayHints = { - enumMemberValues = { - enabled = true, - }, - functionLikeReturnTypes = { - enabled = true, - }, - propertyDeclarationTypes = { - enabled = true, - }, - parameterTypes = { - enabled = true, - suppressWhenArgumentMatchesName = true, - }, - variableTypes = { - enabled = true, - }, - }, - }, - }, - }, - }, + servers = lsp_servers, }, config = function(_, opts) - require('neodev').setup() + require('lazydev').setup() require('lsp-setup').setup(opts) - local lspconfig = require('lspconfig') + local lspconfig = require 'lspconfig' for server, config in pairs(opts.servers) do -- passing config.capabilities to blink.cmp merges with the capabilities in your -- `opts[server].capabilities, if you've defined it - config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities) + config.capabilities = + require('blink.cmp').get_lsp_capabilities(config.capabilities) lspconfig[server].setup(config) end lspconfig.lua_ls.on_init = function(client) if client.workspace_folders then local path = client.workspace_folders[1].name - if vim.loop.fs_stat(path .. '/.luarc.json') or vim.loop.fs_stat(path .. '/.luarc.jsonc') then + if + vim.loop.fs_stat(path .. '/.luarc.json') + or vim.loop.fs_stat(path .. '/.luarc.jsonc') + then return end end - client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { - runtime = { - -- Tell the language server which version of Lua you're using - -- (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT' - }, - -- Make the server aware of Neovim runtime files - workspace = { - checkThirdParty = false, - library = { - vim.env.VIMRUNTIME - } - } - }) + client.config.settings.Lua = + vim.tbl_deep_extend('force', client.config.settings.Lua, { + runtime = { + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + -- Make the server aware of Neovim runtime files + workspace = { + checkThirdParty = false, + library = { + vim.env.VIMRUNTIME, + }, + }, + }) end lspconfig.jsonls.settings = { json = { @@ -191,4 +286,53 @@ return { } end, }, + + -- Lightweight yet powerful formatter plugin for Neovim + -- https://github.com/stevearc/conform.nvim + { + 'stevearc/conform.nvim', + event = { 'BufWritePre' }, + cmd = { 'ConformInfo' }, + keys = { + { + 'cf', + function() + require('conform').format { async = true, lsp_format = 'fallback' } + end, + mode = '', + desc = 'Format buffer', + }, + }, + opts = { + notify_on_error = false, + ---@type nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts + format_on_save = function(bufnr) + -- Disable "format_on_save lsp_fallback" for languages that don't + -- have a well standardized coding style. You can add additional + -- languages here or re-enable it for the disabled ones. + local disable_filetypes = { c = true, cpp = true } + local lsp_format_opt + if disable_filetypes[vim.bo[bufnr].filetype] then + lsp_format_opt = 'never' + else + lsp_format_opt = 'fallback' + end + return { + timeout_ms = 500, + lsp_format = lsp_format_opt, + } + end, + formatters_by_ft = { + lua = { 'stylua' }, + -- Conform can also run multiple formatters sequentially + -- python = { "isort", "black" }, + -- + -- You can use 'stop_after_first' to run the first available formatter from the list + -- javascript = { "prettierd", "prettier", stop_after_first = true }, + }, + }, + }, + -- Automatically install formatters registered with conform.nvim via mason.nvim + -- https://github.com/zapling/mason-conform.nvim + { 'zapling/mason-conform.nvim', opts = {} }, }