Added null-ls plugin.This enables certain tools to act as LSPs

(formatters, linters, etc)
This commit is contained in:
Afonso Franco 2022-12-15 04:18:13 +00:00
parent 0baee67ded
commit 13b0b340f9
Signed by: afonso
GPG key ID: C459E0BB3DCEE899
3 changed files with 69 additions and 46 deletions

View file

@ -1,12 +1,11 @@
local mason_lspconfig = require "mason-lspconfig" local mason_lspconfig = require "mason-lspconfig"
mason_lspconfig.setup({ mason_lspconfig.setup({
ensure_installed = { "sumneko_lua", "rust_analyzer" , "texlab", "hls"}, ensure_installed = { "sumneko_lua", "rust_analyzer", "texlab", "hls", "yamlls" },
automatic_installation = true automatic_installation = true
}) })
local opts = { noremap=true, silent=true } local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts) vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
@ -20,7 +19,7 @@ local on_attach = function(client, bufnr)
-- Mappings. -- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions -- 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.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, 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', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts) vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wl', function() vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts) end, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<space>ge', function () vim.diagnostic.goto_next() end, bufopts) vim.keymap.set('n', '<space>ge', function() vim.diagnostic.goto_next() end, bufopts)
vim.keymap.set('n', '<space>gE', function () vim.diagnostic.goto_prev() end, bufopts) vim.keymap.set('n', '<space>gE', function() vim.diagnostic.goto_prev() end, bufopts)
vim.keymap.set('n', '<space>fo', function() vim.lsp.buf.format { async = true } end, bufopts) vim.keymap.set('n', '<space>fo', function() vim.lsp.buf.format { async = true } end, bufopts)
-- vim.api.nvim_create_autocmd('BufWritePre', { -- vim.api.nvim_create_autocmd('BufWritePre', {
-- pattern = '<buffer>', -- pattern = '<buffer>',
-- callback = function() vim.lsp.buf.format({ async = true }) end -- callback = function() vim.lsp.buf.format({ async = true }) end
-- }) -- })
if client.name == "yamlls" then
client.server_capabilities.document_formatting = true
end
end end
local lspconfig = require "lspconfig" local lspconfig = require "lspconfig"
mason_lspconfig.setup_handlers { 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) -- 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) function(server_name)
lspconfig[server_name].setup { lspconfig[server_name].setup {
on_attach = on_attach, on_attach = on_attach,
flags = lsp_flags, flags = lsp_flags,
} }
end, end,
} }

View file

@ -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" },
}),
}
})

View file

@ -1,62 +1,73 @@
local packer = require("packer") local packer = require("packer")
local plugins = packer.startup({function(use) local plugins = packer.startup({ function(use)
use { use {
"wbthomason/packer.nvim", "wbthomason/packer.nvim",
config = [[require("plugins.packer")]] config = [[require("plugins.packer")]]
} }
use{ "lewis6991/impatient.nvim"} use { "lewis6991/impatient.nvim" }
use{ "lervag/vimtex", use { "lervag/vimtex",
config = function () config = function()
require "plugins.vimtex" require "plugins.vimtex"
end end
} }
-------------------------------------------------------QOL---------------------------------------------- -------------------------------------------------------QOL----------------------------------------------
use { "ggandor/leap.nvim", use { "ggandor/leap.nvim",
config = function () config = function()
require('leap').add_default_mappings() require('leap').add_default_mappings()
end end
} }
use {'stevearc/dressing.nvim'} -- Rename variable pop up use { 'stevearc/dressing.nvim' } -- Rename variable pop up
use {"windwp/nvim-autopairs", use { "windwp/nvim-autopairs",
config = function() require("nvim-autopairs").setup {} config = function() require("nvim-autopairs").setup {}
end end
} }
use {'kyazdani42/nvim-web-devicons'} use { 'kyazdani42/nvim-web-devicons' }
use { use {
'nvim-lualine/lualine.nvim', 'nvim-lualine/lualine.nvim',
requires = { 'kyazdani42/nvim-web-devicons', opt = true }, requires = { 'kyazdani42/nvim-web-devicons', opt = true },
config = function () config = function()
require 'plugins.lualine' require 'plugins.lualine'
end end
} }
use { 'rcarriga/nvim-notify',
config = function()
vim.notify = require("notify")
end
}
-------------------------------------------------------LSP---------------------------------------------- -------------------------------------------------------LSP----------------------------------------------
use { "williamboman/mason.nvim", use { "williamboman/mason.nvim",
config = function () config = function()
require "plugins.mason" require "plugins.mason"
end end
} }
use {"williamboman/mason-lspconfig.nvim"} use { "williamboman/mason-lspconfig.nvim" }
use { "neovim/nvim-lspconfig", use { "neovim/nvim-lspconfig",
config = function () config = function()
require "plugins.lspconfig" require "plugins.lspconfig"
end end
} }
use { "jose-elias-alvarez/null-ls.nvim",
config = function()
require "plugins.null-ls"
end
}
use { "L3MON4D3/LuaSnip", use { "L3MON4D3/LuaSnip",
requires = { requires = {
"rafamadriz/friendly-snippets", "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 = { requires = {
'nvim-tree/nvim-web-devicons', -- optional, for file icons 'nvim-tree/nvim-web-devicons', -- optional, for file icons
}, },
@ -85,28 +96,28 @@ local plugins = packer.startup({function(use)
require("nvim-tree").setup() require("nvim-tree").setup()
end end
} }
use { "feline-nvim/feline.nvim" } use { "feline-nvim/feline.nvim" }
-------------------------------------------THEMES------------------------------------------ -------------------------------------------THEMES------------------------------------------
use {"joshdick/onedark.vim" } use { "joshdick/onedark.vim" }
use {"catppuccin/nvim"} use { "catppuccin/nvim" }
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
use {"nvim-treesitter/nvim-treesitter", use { "nvim-treesitter/nvim-treesitter",
config = function() config = function()
require "plugins.treesitter" require "plugins.treesitter"
end end
} }
use {"nvim-treesitter/nvim-treesitter-context", use { "nvim-treesitter/nvim-treesitter-context",
config = function() config = function()
require "plugins.treesitter-context" require "plugins.treesitter-context"
end end
} }
--Tabs --Tabs
use {'romgrk/barbar.nvim', use { 'romgrk/barbar.nvim',
requires = 'kyazdani42/nvim-web-devicons', requires = 'kyazdani42/nvim-web-devicons',
config = function () config = function()
require "plugins.barbar" require "plugins.barbar"
end end
} }
@ -115,20 +126,20 @@ local plugins = packer.startup({function(use)
use { use {
'nvim-telescope/telescope.nvim', tag = '0.1.0', 'nvim-telescope/telescope.nvim', tag = '0.1.0',
-- or , branch = '0.1.x', -- or , branch = '0.1.x',
requires = { {'nvim-lua/plenary.nvim'} }, requires = { { 'nvim-lua/plenary.nvim' } },
config = function() require('plugins.telescope') end config = function() require('plugins.telescope') end
} }
use {"tpope/vim-surround"} use { "tpope/vim-surround" }
use {"startup-nvim/startup.nvim", use { "startup-nvim/startup.nvim",
requires = {"nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim"}, requires = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" },
config = function() config = function()
require("startup").setup { theme = "dashboard" } require("startup").setup { theme = "dashboard" }
end, end,
} }
end, end,
config = { config = {
auto_clean = true, auto_clean = true,
@ -140,6 +151,6 @@ local plugins = packer.startup({function(use)
done_sym = "", done_sym = "",
removed_sym = "", removed_sym = "",
moved_sym = "", moved_sym = "",
}, },
} }
}) })