this repo has no description
1-- ┌─────────────────────────┐
2-- │ Plugins outside of MINI │
3-- └─────────────────────────┘
4--
5-- This file contains installation and configuration of plugins outside of MINI.
6-- They significantly improve user experience in a way not yet possible with MINI.
7-- These are mostly plugins that provide programming language specific behavior.
8--
9-- Use this file to install and configure other such plugins.
10
11-- Make concise helpers for installing/adding plugins in two stages
12local add, later = MiniDeps.add, MiniDeps.later
13local now_if_args = Config.now_if_args
14
15-- Tree-sitter ================================================================
16
17-- Tree-sitter is a tool for fast incremental parsing. It converts text into
18-- a hierarchical structure (called tree) that can be used to implement advanced
19-- and/or more precise actions: syntax highlighting, textobjects, indent, etc.
20--
21-- Tree-sitter support is built into Neovim (see `:h treesitter`). However, it
22-- requires two extra pieces that don't come with Neovim directly:
23-- - Language parsers: programs that convert text into trees. Some are built-in
24-- (like for Lua), 'nvim-treesitter' provides many others.
25-- - Query files: definitions of how to extract information from trees in
26-- a useful manner (see `:h treesitter-query`). 'nvim-treesitter' also provides
27-- these, while 'nvim-treesitter-textobjects' provides the ones for Neovim
28-- textobjects (see `:h text-objects`, `:h MiniAi.gen_spec.treesitter()`).
29--
30-- Add these plugins now if file (and not 'mini.starter') is shown after startup.
31--
32-- -- Troubleshooting:
33-- - Run `:checkhealth vim.treesitter nvim-treesitter` to see potential issues.
34-- - In case of errors related to queries for Neovim bundled parsers (like `lua`,
35-- `vimdoc`, `markdown`, etc.), manually install them via 'nvim-treesitter'
36-- with `:TSInstall <language>`. Be sure to have necessary system dependencies
37-- (see MiniMax README section for software requirements).
38now_if_args(function()
39 add({
40 source = 'nvim-treesitter/nvim-treesitter',
41 -- Update tree-sitter parser after plugin is updated
42 hooks = { post_checkout = function() vim.cmd('TSUpdate') end },
43 })
44 add('nvim-treesitter/nvim-treesitter-textobjects')
45
46 -- Define languages which will have parsers installed and auto enabled
47 -- After changing this, restart Neovim once to install necessary parsers. Wait
48 -- for the installation to finish before opening a file for added language(s).
49 local languages = {
50 -- These are already pre-installed with Neovim. Used as an example.
51 'lua',
52 'vimdoc',
53 'markdown',
54 -- Add here more languages with which you want to use tree-sitter
55 'javascript',
56 'typescript',
57 'tsx',
58 'css',
59 'svelte',
60 'rust'
61 -- To see available languages:
62 -- - Execute `:=require('nvim-treesitter').get_available()`
63 -- - Visit 'SUPPORTED_LANGUAGES.md' file at
64 -- https://github.com/nvim-treesitter/nvim-treesitter
65 }
66 local isnt_installed = function(lang)
67 return #vim.api.nvim_get_runtime_file('parser/' .. lang .. '.*', false) == 0
68 end
69 local to_install = vim.tbl_filter(isnt_installed, languages)
70 if #to_install > 0 then require('nvim-treesitter').install(to_install) end
71
72 -- Enable tree-sitter after opening a file for a target language
73 local filetypes = {}
74 for _, lang in ipairs(languages) do
75 for _, ft in ipairs(vim.treesitter.language.get_filetypes(lang)) do
76 table.insert(filetypes, ft)
77 end
78 end
79 local ts_start = function(ev) vim.treesitter.start(ev.buf) end
80 Config.new_autocmd('FileType', filetypes, ts_start, 'Start tree-sitter')
81end)
82
83-- Language servers ===========================================================
84
85-- Language Server Protocol (LSP) is a set of conventions that power creation of
86-- language specific tools. It requires two parts:
87-- - Server - program that performs language specific computations.
88-- - Client - program that asks server for computations and shows results.
89--
90-- Here Neovim itself is a client (see `:h vim.lsp`). Language servers need to
91-- be installed separately based on your OS, CLI tools, and preferences.
92-- See note about 'mason.nvim' at the bottom of the file.
93--
94-- Neovim's team collects commonly used configurations for most language servers
95-- inside 'neovim/nvim-lspconfig' plugin.
96--
97-- Add it now if file (and not 'mini.starter') is shown after startup.
98now_if_args(function()
99 add('neovim/nvim-lspconfig')
100
101 -- Use `:h vim.lsp.enable()` to automatically enable language server based on
102 -- the rules provided by 'nvim-lspconfig'.
103 -- Use `:h vim.lsp.config()` or 'after/lsp/' directory to configure servers.
104 -- Uncomment and tweak the following `vim.lsp.enable()` call to enable servers.
105 -- vim.lsp.enable({
106 -- -- For example, if `lua-language-server` is installed, use `'lua_ls'` entry
107 -- })
108 vim.lsp.enable({
109 -- 'ts_ls',
110 'lua_ls',
111 'rust_analyzer'
112 })
113end)
114
115-- Formatting =================================================================
116
117-- Programs dedicated to text formatting (a.k.a. formatters) are very useful.
118-- Neovim has built-in tools for text formatting (see `:h gq` and `:h 'formatprg'`).
119-- They can be used to configure external programs, but it might become tedious.
120--
121-- The 'stevearc/conform.nvim' plugin is a good and maintained solution for easier
122-- formatting setup.
123later(function()
124 add('stevearc/conform.nvim')
125
126 -- See also:
127 -- - `:h Conform`
128 -- - `:h conform-options`
129 -- - `:h conform-formatters`
130 require('conform').setup({
131 default_format_opts = {
132 -- Allow formatting from LSP server if no dedicated formatter is available
133 lsp_format = 'fallback',
134 },
135 format_on_save = {
136 timeout_ms = 500,
137 lsp_format = "fallback",
138 },
139 -- Map of filetype to formatters
140 -- Make sure that necessary CLI tool is available
141 formatters_by_ft = {
142 lua = { 'stylua' },
143 javascript = { "prettier", stop_after_first = true },
144 typescript = { "prettier", stop_after_first = true },
145 css = { "prettier", "stylehint", stop_after_first = false },
146 rust = { "rustfmt" }
147 },
148 })
149end)
150-- vim.api.nvim_create_autocmd("BufWritePre", {
151-- pattern = "*",
152-- callback = function(args)
153-- require("conform").format({ bufnr = args.buf })
154-- end,
155-- })
156
157-- Snippets ===================================================================
158
159-- Although 'mini.snippets' provides functionality to manage snippet files, it
160-- deliberately doesn't come with those.
161--
162-- The 'rafamadriz/friendly-snippets' is currently the largest collection of
163-- snippet files. They are organized in 'snippets/' directory (mostly) per language.
164-- 'mini.snippets' is designed to work with it as seamlessly as possible.
165-- See `:h MiniSnippets.gen_loader.from_lang()`.
166later(function() add('rafamadriz/friendly-snippets') end)
167
168-- Honorable mentions =========================================================
169
170-- 'mason-org/mason.nvim' (a.k.a. "Mason") is a great tool (package manager) for
171-- installing external language servers, formatters, and linters. It provides
172-- a unified interface for installing, updating, and deleting such programs.
173--
174-- The caveat is that these programs will be set up to be mostly used inside Neovim.
175-- If you need them to work elsewhere, consider using other package managers.
176--
177-- You can use it like so:
178now_if_args(function()
179 add('mason-org/mason.nvim')
180 add('mason-org/mason-lspconfig.nvim')
181 require('mason').setup()
182 local mason_lspconfig = require('mason-lspconfig')
183 mason_lspconfig.setup({
184 ensure_installed = { "lua_ls", "ts_ls" }
185 })
186end)
187
188-- Beautiful, usable, well maintained color schemes outside of 'mini.nvim' and
189-- have full support of its highlight groups. Use if you don't like 'miniwinter'
190-- enabled in 'plugin/30_mini.lua' or other suggested 'mini.hues' based ones.
191-- MiniDeps.now(function()
192-- -- Install only those that you need
193-- add('sainnhe/everforest')
194-- add('Shatur/neovim-ayu')
195-- add('ellisonleao/gruvbox.nvim')
196--
197-- -- Enable only one
198-- vim.cmd('color everforest')
199-- end)
200
201
202--
203-- CUSTOM BELOW
204
205later(function()
206 add({
207 source = 'folke/snacks.nvim',
208 checkout = 'main'
209 },
210 { lazygit = {} }
211 )
212end)
213vim.keymap.set('n', '<leader>gG', function()
214 Snacks.lazygit.open()
215end, { desc = 'lazygit' })
216
217vim.keymap.set('n', '<space>d', vim.diagnostic.setloclist, { desc = "Add buffer diagnostics to the location list." })
218
219-- Use LspAttach autocommand to only map the following keys
220-- after the language server attaches to the current buffer
221vim.api.nvim_create_autocmd('LspAttach', {
222 group = vim.api.nvim_create_augroup('UserLspConfig', {}),
223 callback = function(ev)
224 -- Enable completion triggered by <c-x><c-o>
225 vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
226
227 -- Buffer local mappings.
228 -- See `:help vim.lsp.*` for documentation on any of the below functions
229 local opts = function(str)
230 return { buffer = ev.buf, desc = str }
231 end
232
233 vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts("Declaration"))
234 vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts("Definition"))
235 vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts("Implementation"))
236 vim.keymap.set('n', '<M-k>', vim.lsp.buf.signature_help, opts("Signature Help"))
237 vim.keymap.set('i', '<M-k>', vim.lsp.buf.signature_help, opts("Signature Help"))
238 vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts("Add Workspace Folder"))
239 vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts("Remove Workspace Folder"))
240 vim.keymap.set('n', '<space>wl', function()
241 print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
242 end, opts("List Workspace Folders"))
243 vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts("Type Definition"))
244 vim.keymap.set('n', '<space>r', vim.lsp.buf.rename, opts("Rename Symbol"))
245 vim.keymap.set({ 'n', 'v' }, '<space>a', vim.lsp.buf.code_action, opts("Code Action"))
246 vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts("Buffer References"))
247 vim.keymap.set('n', '<localleader>f', function()
248 vim.lsp.buf.format { async = true }
249 end, opts("Format Buffer"))
250 end,
251})
252
253
254vim.lsp.config('rust_analyzer', {
255 settings = {
256 ["rust_analyzer"] = {
257 cargo = {
258 features = { "ssr" }
259 },
260 check = {
261 command = "clippy",
262 },
263 -- Other Settings ...
264 procMacro = {
265 enable = true,
266 ignored = {
267 leptos_macro = {
268 -- optional: --
269 -- "component",
270 "server",
271 },
272 },
273 },
274 }
275 }
276})