142 lines
4.7 KiB
Lua
142 lines
4.7 KiB
Lua
local add = vim.pack.add
|
|
local now_if_args, later = Config.now_if_args, Config.later
|
|
|
|
now_if_args(function()
|
|
-- Define hook to update tree-sitter parsers after plugin is updated
|
|
local ts_update = function()
|
|
vim.cmd("TSUpdate")
|
|
end
|
|
Config.on_packchanged("nvim-treesitter", { "update" }, ts_update, ":TSUpdate")
|
|
|
|
add({
|
|
"https://github.com/nvim-treesitter/nvim-treesitter",
|
|
"https://github.com/nvim-treesitter/nvim-treesitter-textobjects",
|
|
})
|
|
|
|
local languages = {
|
|
"lua",
|
|
"vimdoc",
|
|
"markdown",
|
|
"go",
|
|
"yaml",
|
|
"html",
|
|
}
|
|
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.
|
|
--
|
|
-- Troubleshooting:
|
|
-- - Run `:checkhealth vim.lsp` to see potential issues.
|
|
now_if_args(function()
|
|
add({ "https://github.com/neovim/nvim-lspconfig" })
|
|
|
|
-- Use `:h vim.lsp.enable()` to automatically enable language server based on
|
|
-- the rules provided by 'nvim-lspconfig'.
|
|
vim.lsp.enable({
|
|
"gopls",
|
|
"lua_ls",
|
|
"yamlls",
|
|
})
|
|
|
|
-- 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.config({
|
|
-- -- For example, if `lua-language-server` is installed, use `'lua_ls'` entry
|
|
-- })
|
|
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({ "https://github.com/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 = {
|
|
lsp_format = "fallback",
|
|
timeout_ms = 500,
|
|
},
|
|
-- Map of filetype to formatters
|
|
-- Make sure that necessary CLI tool is available
|
|
-- formatters_by_ft = { lua = { 'stylua' } },
|
|
formatters_by_ft = {
|
|
go = { "gofumpt", "goimports" },
|
|
lua = { "stylua" },
|
|
},
|
|
})
|
|
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({ "https://github.com/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({ "https://github.com/mason-org/mason.nvim" })
|
|
require("mason").setup()
|
|
end)
|