diff --git a/init.lua b/init.lua index f19b921a..1fa11a50 100644 --- a/init.lua +++ b/init.lua @@ -133,6 +133,24 @@ vim.api.nvim_create_autocmd('TextYankPost', { end, }) +local formatting = require 'custom.formatting' + +vim.api.nvim_create_autocmd('FileType', { + desc = 'Apply per-filetype indentation settings', + group = vim.api.nvim_create_augroup('kickstart-indent-rules', { clear = true }), + callback = function() + local width = formatting.indent_by_ft[vim.bo.filetype] + if not width then + return + end + + vim.opt_local.expandtab = true + vim.opt_local.tabstop = width + vim.opt_local.softtabstop = width + vim.opt_local.shiftwidth = width + end, +}) + -- [[ Install `lazy.nvim` plugin manager ]] -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' @@ -405,6 +423,7 @@ require('lazy').setup({ -- Allows extra capabilities provided by blink.cmp 'saghen/blink.cmp', + { 'AstroNvim/astrolsp', opts = {} }, }, config = function() -- Brief aside: **What is LSP?** @@ -648,12 +667,18 @@ require('lazy').setup({ local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { 'stylua', -- Used to format Lua code + 'prettierd', -- Used to format JavaScript and TypeScript + 'prettier', -- Fallback formatter when prettierd is unavailable + 'astro', + 'html', + 'cssls', + 'tailwindcss', }) 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, + automatic_installation = true, handlers = { function(server_name) local server = servers[server_name] or {} @@ -698,21 +723,7 @@ require('lazy').setup({ } end end, - formatters_by_ft = { - lua = { 'stylua' }, - -- Conform can also run multiple formatters sequentially - python = { - -- To fix auto-fixable lint errors. - 'ruff_fix', - -- To run the Ruff formatter. - 'ruff_format', - -- To organize the imports. - 'ruff_organize_imports', - }, - -- - -- You can use 'stop_after_first' to run the first available formatter from the list - -- javascript = { "prettierd", "prettier", stop_after_first = true }, - }, + formatters_by_ft = formatting.formatters_by_ft, }, }, @@ -883,7 +894,7 @@ require('lazy').setup({ main = 'nvim-treesitter.configs', -- Sets main module to use for opts -- [[ Configure Treesitter ]] See `:help nvim-treesitter` opts = { - ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, + ensure_installed = { 'astro', 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, -- Autoinstall languages that are not installed auto_install = true, highlight = { diff --git a/lua/custom/formatting.lua b/lua/custom/formatting.lua new file mode 100644 index 00000000..40703187 --- /dev/null +++ b/lua/custom/formatting.lua @@ -0,0 +1,26 @@ +local M = {} + +M.indent_by_ft = { + javascript = 2, + javascriptreact = 2, + typescript = 2, + typescriptreact = 2, + json = 2, + html = 2, + css = 2, + scss = 2, +} + +M.formatters_by_ft = { + html = { 'prettier' }, + lua = { 'stylua' }, + python = { + 'ruff_fix', + 'ruff_format', + 'ruff_organize_imports', + }, + javascript = { 'prettierd', 'prettier', stop_after_first = true }, + typescript = { 'prettierd', 'prettier', stop_after_first = true }, +} + +return M diff --git a/lua/custom/plugins/lsp_overrides.lua b/lua/custom/plugins/lsp_overrides.lua deleted file mode 100644 index b1458a1d..00000000 --- a/lua/custom/plugins/lsp_overrides.lua +++ /dev/null @@ -1,26 +0,0 @@ -return { - { - 'neovim/nvim-lspconfig', - opts = { - setup = { - ruff = function(_, _) - -- This runs when ruff is being set up - -- We can return true to skip default setup, but we don't want that - -- Instead we hook later - end, - }, - }, - config = function() - -- Hook into existing LspAttach (kickstart already created the group) - vim.api.nvim_create_autocmd('LspAttach', { - callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - if client and client.name == 'ruff' then - client.server_capabilities.diagnosticProvider = false - end - end, - group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = false }), - }) - end, - }, -} diff --git a/lua/custom/plugins/refactoring.lua b/lua/custom/plugins/refactoring.lua deleted file mode 100644 index 8b200fea..00000000 --- a/lua/custom/plugins/refactoring.lua +++ /dev/null @@ -1,10 +0,0 @@ -return { - 'ThePrimeagen/refactoring.nvim', - dependencies = { - 'nvim-lua/plenary.nvim', - 'nvim-treesitter/nvim-treesitter', - }, - config = function() - require('refactoring').setup {} - end, -}