-- ┌─────────────────────────┐ -- │ Plugins outside of MINI │ -- └─────────────────────────┘ -- -- This file contains installation and configuration of plugins outside of MINI. -- They significantly improve user experience in a way not yet possible with MINI. -- These are mostly plugins that provide programming language specific behavior. -- -- Use this file to install and configure other such plugins. -- Make concise helpers for installing/adding plugins in two stages local add, later = MiniDeps.add, MiniDeps.later local now_if_args = Config.now_if_args -- Tree-sitter ================================================================ -- Tree-sitter is a tool for fast incremental parsing. It converts text into -- a hierarchical structure (called tree) that can be used to implement advanced -- and/or more precise actions: syntax highlighting, textobjects, indent, etc. -- -- Tree-sitter support is built into Neovim (see `:h treesitter`). However, it -- requires two extra pieces that don't come with Neovim directly: -- - Language parsers: programs that convert text into trees. Some are built-in -- (like for Lua), 'nvim-treesitter' provides many others. -- - Query files: definitions of how to extract information from trees in -- a useful manner (see `:h treesitter-query`). 'nvim-treesitter' also provides -- these, while 'nvim-treesitter-textobjects' provides the ones for Neovim -- textobjects (see `:h text-objects`, `:h MiniAi.gen_spec.treesitter()`). -- -- Add these plugins now if file (and not 'mini.starter') is shown after startup. -- -- -- Troubleshooting: -- - Run `:checkhealth vim.treesitter nvim-treesitter` to see potential issues. -- - In case of errors related to queries for Neovim bundled parsers (like `lua`, -- `vimdoc`, `markdown`, etc.), manually install them via 'nvim-treesitter' -- with `:TSInstall `. Be sure to have necessary system dependencies -- (see MiniMax README section for software requirements). now_if_args(function() add({ source = 'nvim-treesitter/nvim-treesitter', -- Update tree-sitter parser after plugin is updated hooks = { post_checkout = function() vim.cmd('TSUpdate') end }, }) add('nvim-treesitter/nvim-treesitter-textobjects') -- Define languages which will have parsers installed and auto enabled -- After changing this, restart Neovim once to install necessary parsers. Wait -- for the installation to finish before opening a file for added language(s). local languages = { -- These are already pre-installed with Neovim. Used as an example. 'lua', 'vimdoc', 'markdown', -- Add here more languages with which you want to use tree-sitter 'javascript', 'typescript', 'tsx', 'css', 'svelte', 'rust' -- To see available languages: -- - Execute `:=require('nvim-treesitter').get_available()` -- - Visit 'SUPPORTED_LANGUAGES.md' file at -- https://github.com/nvim-treesitter/nvim-treesitter } local isnt_installed = function(lang) return #vim.api.nvim_get_runtime_file('parser/' .. lang .. '.*', false) == 0 end local to_install = vim.tbl_filter(isnt_installed, languages) if #to_install > 0 then require('nvim-treesitter').install(to_install) end -- Enable tree-sitter after opening a file for a target language local filetypes = {} for _, lang in ipairs(languages) do for _, ft in ipairs(vim.treesitter.language.get_filetypes(lang)) do table.insert(filetypes, ft) end end local ts_start = function(ev) vim.treesitter.start(ev.buf) end Config.new_autocmd('FileType', filetypes, ts_start, 'Start tree-sitter') end) -- Language servers =========================================================== -- Language Server Protocol (LSP) is a set of conventions that power creation of -- language specific tools. It requires two parts: -- - Server - program that performs language specific computations. -- - Client - program that asks server for computations and shows results. -- -- Here Neovim itself is a client (see `:h vim.lsp`). Language servers need to -- be installed separately based on your OS, CLI tools, and preferences. -- See note about 'mason.nvim' at the bottom of the file. -- -- Neovim's team collects commonly used configurations for most language servers -- inside 'neovim/nvim-lspconfig' plugin. -- -- Add it now if file (and not 'mini.starter') is shown after startup. now_if_args(function() add('neovim/nvim-lspconfig') -- Use `:h vim.lsp.enable()` to automatically enable language server based on -- the rules provided by 'nvim-lspconfig'. -- Use `:h vim.lsp.config()` or 'after/lsp/' directory to configure servers. -- Uncomment and tweak the following `vim.lsp.enable()` call to enable servers. -- vim.lsp.enable({ -- -- For example, if `lua-language-server` is installed, use `'lua_ls'` entry -- }) vim.lsp.enable({ -- 'ts_ls', 'lua_ls', 'rust_analyzer' }) end) -- Formatting ================================================================= -- Programs dedicated to text formatting (a.k.a. formatters) are very useful. -- Neovim has built-in tools for text formatting (see `:h gq` and `:h 'formatprg'`). -- They can be used to configure external programs, but it might become tedious. -- -- The 'stevearc/conform.nvim' plugin is a good and maintained solution for easier -- formatting setup. later(function() add('stevearc/conform.nvim') -- See also: -- - `:h Conform` -- - `:h conform-options` -- - `:h conform-formatters` require('conform').setup({ default_format_opts = { -- Allow formatting from LSP server if no dedicated formatter is available lsp_format = 'fallback', }, format_on_save = { timeout_ms = 500, lsp_format = "fallback", }, -- Map of filetype to formatters -- Make sure that necessary CLI tool is available formatters_by_ft = { lua = { 'stylua' }, javascript = { "prettier", stop_after_first = true }, typescript = { "prettier", stop_after_first = true }, css = { "prettier", "stylehint", stop_after_first = false }, rust = { "rustfmt" } }, }) end) -- vim.api.nvim_create_autocmd("BufWritePre", { -- pattern = "*", -- callback = function(args) -- require("conform").format({ bufnr = args.buf }) -- end, -- }) -- Snippets =================================================================== -- Although 'mini.snippets' provides functionality to manage snippet files, it -- deliberately doesn't come with those. -- -- The 'rafamadriz/friendly-snippets' is currently the largest collection of -- snippet files. They are organized in 'snippets/' directory (mostly) per language. -- 'mini.snippets' is designed to work with it as seamlessly as possible. -- See `:h MiniSnippets.gen_loader.from_lang()`. later(function() add('rafamadriz/friendly-snippets') end) -- Honorable mentions ========================================================= -- 'mason-org/mason.nvim' (a.k.a. "Mason") is a great tool (package manager) for -- installing external language servers, formatters, and linters. It provides -- a unified interface for installing, updating, and deleting such programs. -- -- The caveat is that these programs will be set up to be mostly used inside Neovim. -- If you need them to work elsewhere, consider using other package managers. -- -- You can use it like so: now_if_args(function() add('mason-org/mason.nvim') add('mason-org/mason-lspconfig.nvim') require('mason').setup() local mason_lspconfig = require('mason-lspconfig') mason_lspconfig.setup({ ensure_installed = { "lua_ls", "ts_ls" } }) end) -- Beautiful, usable, well maintained color schemes outside of 'mini.nvim' and -- have full support of its highlight groups. Use if you don't like 'miniwinter' -- enabled in 'plugin/30_mini.lua' or other suggested 'mini.hues' based ones. -- MiniDeps.now(function() -- -- Install only those that you need -- add('sainnhe/everforest') -- add('Shatur/neovim-ayu') -- add('ellisonleao/gruvbox.nvim') -- -- -- Enable only one -- vim.cmd('color everforest') -- end) -- -- CUSTOM BELOW later(function() add({ source = 'folke/snacks.nvim', checkout = 'main' }, { lazygit = {} } ) end) vim.keymap.set('n', 'gG', function() Snacks.lazygit.open() end, { desc = 'lazygit' }) vim.keymap.set('n', 'd', vim.diagnostic.setloclist, { desc = "Add buffer diagnostics to the location list." }) -- Use LspAttach autocommand to only map the following keys -- after the language server attaches to the current buffer vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('UserLspConfig', {}), callback = function(ev) -- Enable completion triggered by vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' -- Buffer local mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local opts = function(str) return { buffer = ev.buf, desc = str } end vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts("Declaration")) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts("Definition")) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts("Implementation")) vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts("Signature Help")) vim.keymap.set('i', '', vim.lsp.buf.signature_help, opts("Signature Help")) vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts("Add Workspace Folder")) vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts("Remove Workspace Folder")) vim.keymap.set('n', 'wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, opts("List Workspace Folders")) vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts("Type Definition")) vim.keymap.set('n', 'r', vim.lsp.buf.rename, opts("Rename Symbol")) vim.keymap.set({ 'n', 'v' }, 'a', vim.lsp.buf.code_action, opts("Code Action")) vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts("Buffer References")) vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, opts("Format Buffer")) end, }) vim.lsp.config('rust_analyzer', { settings = { ["rust_analyzer"] = { cargo = { features = { "ssr" } }, check = { command = "clippy", }, -- Other Settings ... procMacro = { enable = true, ignored = { leptos_macro = { -- optional: -- -- "component", "server", }, }, }, } } })