From 13b0b340f9f11b534b386153dc6082f4ee171d71 Mon Sep 17 00:00:00 2001 From: afonsofrancof Date: Thu, 15 Dec 2022 04:18:13 +0000 Subject: [PATCH] Added null-ls plugin.This enables certain tools to act as LSPs (formatters, linters, etc) --- .config/nvim/lua/plugins/lspconfig.lua | 32 +++++------ .config/nvim/lua/plugins/null-ls.lua | 10 ++++ .config/nvim/lua/plugins/packer.lua | 73 +++++++++++++++----------- 3 files changed, 69 insertions(+), 46 deletions(-) create mode 100644 .config/nvim/lua/plugins/null-ls.lua diff --git a/.config/nvim/lua/plugins/lspconfig.lua b/.config/nvim/lua/plugins/lspconfig.lua index 0dce482..f81048b 100644 --- a/.config/nvim/lua/plugins/lspconfig.lua +++ b/.config/nvim/lua/plugins/lspconfig.lua @@ -1,12 +1,11 @@ - local mason_lspconfig = require "mason-lspconfig" mason_lspconfig.setup({ - ensure_installed = { "sumneko_lua", "rust_analyzer" , "texlab", "hls"}, - automatic_installation = true + ensure_installed = { "sumneko_lua", "rust_analyzer", "texlab", "hls", "yamlls" }, + automatic_installation = true }) -local opts = { noremap=true, silent=true } +local opts = { noremap = true, silent = true } vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) @@ -20,7 +19,7 @@ local on_attach = function(client, bufnr) -- Mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions - local bufopts = { noremap=true, silent=true, buffer=bufnr } + local bufopts = { noremap = true, silent = true, buffer = bufnr } vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) @@ -30,29 +29,32 @@ local on_attach = function(client, bufnr) vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) vim.keymap.set('n', 'wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, bufopts) + end, bufopts) vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) - vim.keymap.set('n', 'ge', function () vim.diagnostic.goto_next() end, bufopts) - vim.keymap.set('n', 'gE', function () vim.diagnostic.goto_prev() end, bufopts) + vim.keymap.set('n', 'ge', function() vim.diagnostic.goto_next() end, bufopts) + vim.keymap.set('n', 'gE', function() vim.diagnostic.goto_prev() end, bufopts) vim.keymap.set('n', 'fo', function() vim.lsp.buf.format { async = true } end, bufopts) -- vim.api.nvim_create_autocmd('BufWritePre', { -- pattern = '', -- callback = function() vim.lsp.buf.format({ async = true }) end -- }) + if client.name == "yamlls" then + client.server_capabilities.document_formatting = true + end end local lspconfig = require "lspconfig" mason_lspconfig.setup_handlers { - -- This is a default handler that will be called for each installed server (also for new servers that are installed during a session) - function (server_name) - lspconfig[server_name].setup { - on_attach = on_attach, - flags = lsp_flags, - } - end, + -- This is a default handler that will be called for each installed server (also for new servers that are installed during a session) + function(server_name) + lspconfig[server_name].setup { + on_attach = on_attach, + flags = lsp_flags, + } + end, } diff --git a/.config/nvim/lua/plugins/null-ls.lua b/.config/nvim/lua/plugins/null-ls.lua new file mode 100644 index 0000000..490e371 --- /dev/null +++ b/.config/nvim/lua/plugins/null-ls.lua @@ -0,0 +1,10 @@ +local null_ls = require("null-ls") + +null_ls.setup({ + sources = { + null_ls.builtins.formatting.rustfmt, + null_ls.builtins.formatting.prettierd.with({ + filetypes = { "html", "json", "yaml", "markdown" }, + }), + } +}) diff --git a/.config/nvim/lua/plugins/packer.lua b/.config/nvim/lua/plugins/packer.lua index 44fd8ec..ee35a8a 100644 --- a/.config/nvim/lua/plugins/packer.lua +++ b/.config/nvim/lua/plugins/packer.lua @@ -1,62 +1,73 @@ - local packer = require("packer") -local plugins = packer.startup({function(use) +local plugins = packer.startup({ function(use) use { "wbthomason/packer.nvim", config = [[require("plugins.packer")]] } - use{ "lewis6991/impatient.nvim"} + use { "lewis6991/impatient.nvim" } - use{ "lervag/vimtex", - config = function () + use { "lervag/vimtex", + config = function() require "plugins.vimtex" end } -------------------------------------------------------QOL---------------------------------------------- - use { "ggandor/leap.nvim", - config = function () + use { "ggandor/leap.nvim", + config = function() require('leap').add_default_mappings() end } - use {'stevearc/dressing.nvim'} -- Rename variable pop up + use { 'stevearc/dressing.nvim' } -- Rename variable pop up - use {"windwp/nvim-autopairs", - config = function() require("nvim-autopairs").setup {} + use { "windwp/nvim-autopairs", + config = function() require("nvim-autopairs").setup {} end } - use {'kyazdani42/nvim-web-devicons'} + use { 'kyazdani42/nvim-web-devicons' } use { 'nvim-lualine/lualine.nvim', requires = { 'kyazdani42/nvim-web-devicons', opt = true }, - config = function () + config = function() require 'plugins.lualine' end } + + use { 'rcarriga/nvim-notify', + config = function() + vim.notify = require("notify") + end + } -------------------------------------------------------LSP---------------------------------------------- - use { "williamboman/mason.nvim", - config = function () + use { "williamboman/mason.nvim", + config = function() require "plugins.mason" end } - use {"williamboman/mason-lspconfig.nvim"} + use { "williamboman/mason-lspconfig.nvim" } - use { "neovim/nvim-lspconfig", - config = function () + use { "neovim/nvim-lspconfig", + config = function() require "plugins.lspconfig" end } + use { "jose-elias-alvarez/null-ls.nvim", + config = function() + require "plugins.null-ls" + end + } + use { "L3MON4D3/LuaSnip", requires = { "rafamadriz/friendly-snippets", @@ -77,7 +88,7 @@ local plugins = packer.startup({function(use) } - use {'nvim-tree/nvim-tree.lua', + use { 'nvim-tree/nvim-tree.lua', requires = { 'nvim-tree/nvim-web-devicons', -- optional, for file icons }, @@ -85,28 +96,28 @@ local plugins = packer.startup({function(use) require("nvim-tree").setup() end } - use { "feline-nvim/feline.nvim" } + use { "feline-nvim/feline.nvim" } -------------------------------------------THEMES------------------------------------------ - use {"joshdick/onedark.vim" } - use {"catppuccin/nvim"} + use { "joshdick/onedark.vim" } + use { "catppuccin/nvim" } ------------------------------------------------------------------------------------------- - use {"nvim-treesitter/nvim-treesitter", + use { "nvim-treesitter/nvim-treesitter", config = function() require "plugins.treesitter" end } - use {"nvim-treesitter/nvim-treesitter-context", + use { "nvim-treesitter/nvim-treesitter-context", config = function() require "plugins.treesitter-context" end } --Tabs - use {'romgrk/barbar.nvim', + use { 'romgrk/barbar.nvim', requires = 'kyazdani42/nvim-web-devicons', - config = function () + config = function() require "plugins.barbar" end } @@ -115,20 +126,20 @@ local plugins = packer.startup({function(use) use { 'nvim-telescope/telescope.nvim', tag = '0.1.0', -- or , branch = '0.1.x', - requires = { {'nvim-lua/plenary.nvim'} }, + requires = { { 'nvim-lua/plenary.nvim' } }, config = function() require('plugins.telescope') end } - use {"tpope/vim-surround"} + use { "tpope/vim-surround" } - use {"startup-nvim/startup.nvim", - requires = {"nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim"}, + use { "startup-nvim/startup.nvim", + requires = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" }, config = function() require("startup").setup { theme = "dashboard" } end, } - end, +end, config = { auto_clean = true, @@ -140,6 +151,6 @@ local plugins = packer.startup({function(use) done_sym = " ", removed_sym = " ", moved_sym = "", - }, + }, } })