From f94ba6234b026ca032da333638ab40e2ed979fc2 Mon Sep 17 00:00:00 2001 From: juan Date: Fri, 16 Sep 2022 17:36:17 +0800 Subject: [PATCH] Use null-ls and mason --- lua/mappings.lua | 49 +++--- lua/plugins.lua | 346 +++++++++++++++++++------------------ lua/plugins/lsp.lua | 15 ++ lua/plugins/lspinstall.lua | 17 -- lua/plugins/null-ls.lua | 18 ++ 5 files changed, 236 insertions(+), 209 deletions(-) create mode 100644 lua/plugins/lsp.lua delete mode 100644 lua/plugins/lspinstall.lua create mode 100644 lua/plugins/null-ls.lua diff --git a/lua/mappings.lua b/lua/mappings.lua index 06be8a1..143837d 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -1,11 +1,11 @@ local map = vim.api.nvim_set_keymap -- generic mappings -map('v', '<', '', '>gv', {noremap = true}) -map('n', 'Y', 'y$', {noremap = true}) -map('n', 'n', 'nzzzv', {noremap = true}) -map('n', 'N', 'Nzzzv', {noremap = true}) +map('v', '<', '', '>gv', { noremap = true }) +map('n', 'Y', 'y$', { noremap = true }) +map('n', 'n', 'nzzzv', { noremap = true }) +map('n', 'N', 'Nzzzv', { noremap = true }) -- Shortcutting split navigation map('', '', 'h', {}) @@ -23,38 +23,41 @@ map('', '', '-', {}) map('', '', 'T', {}) -- undo to the last , . or ! -map('i', ',', ',u', {noremap = true}) -map('i', '.', '.u', {noremap = true}) -map('i', '!', '!u', {noremap = true}) -map('i', '?', '?u', {noremap = true}) +map('i', ',', ',u', { noremap = true }) +map('i', '.', '.u', { noremap = true }) +map('i', '!', '!u', { noremap = true }) +map('i', '?', '?u', { noremap = true }) -- plugin mappings -- gitsigns -map('', 'gs', ':Gitsigns toggle_signs', {silent = true}) +map('', 'gs', ':Gitsigns toggle_signs', { silent = true }) -- lsp stuff map('n', 'gd', 'lua vim.lsp.buf.definition()', - {silent = false, noremap = true}) -map('n', 'K', 'lua vim.lsp.buf.hover()', {noremap = true}) + { silent = false, noremap = true }) +map('n', 'K', 'lua vim.lsp.buf.hover()', { noremap = true }) map('', 'K', 'lua vim.diagnostic.open_float()', - {noremap = true}) + { noremap = true }) map('', 'qf', - 'lua vim.diagnostic.setqflist({open = false})Telescope quickfix', - {silent = true}) + 'lua vim.diagnostic.setqflist({open = false})Telescope quickfix', + { silent = true }) -- toggle tagbar -map('', 'tt', ':TagbarToggle', {silent = true}) +map('', 'tt', ':TagbarToggle', { silent = true }) -- toggle NvimTree -map('', '', ':NvimTreeToggle', {silent = true}) +map('', '', ':NvimTreeToggle', { silent = true }) -- toggle formatter -map('', 'fm', ':Neoformat', {silent = true}) +map('', 'fm', ':lua vim.lsp.buf.formatting()', { silent = true }) -- toggle Hop -map('', 'b', ':HopWordBC', {silent = true}) -map('', 'w', ':HopWordAC', {silent = true}) -map('', 'l', ':HopWordCurrentLine', {silent = true}) +map('', 'b', ':HopWordBC', { silent = true }) +map('', 'w', ':HopWordAC', { silent = true }) +map('', 'l', ':HopWordCurrentLine', { silent = true }) -- telescope stuff -map('', 'fd', ':Telescope fd', {silent = true}) -map('', 'tb', ':Telescope buffers', {silent = true}) +map('', 'fd', ':Telescope fd', + + + { silent = true }) +map('', 'tb', ':Telescope buffers', { silent = true }) diff --git a/lua/plugins.lua b/lua/plugins.lua index 416aa5e..65fd9c7 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,182 +1,190 @@ return require('packer').startup(function(use) - use {'wbthomason/packer.nvim'} + use { 'wbthomason/packer.nvim' } - -- core UI - use({ - 'juancldcmt/sere-forest', - config = function() - vim.g.everforest_better_performance = 1 - vim.g.everforest_enable_italic = 1 - vim.g.everforest_transparent_background = 1 - vim.cmd('colorscheme everforest') - end - }) - use {'kyazdani42/nvim-web-devicons'} - use { - 'nvim-lualine/lualine.nvim', - after = {'nvim-web-devicons'}, - config = function() require 'plugins.statusline' end - } - -- use { - -- 'romgrk/barbar.nvim', - -- requires = {'kyazdani42/nvim-web-devicons'}, - -- event = 'BufAdd', - -- after = {'nvim-web-devicons'}, - -- config = function() require 'plugins.barbar' end - -- } + -- core UI + use({ + 'juancldcmt/sere-forest', + config = function() + vim.g.everforest_better_performance = 1 + vim.g.everforest_enable_italic = 1 + vim.g.everforest_transparent_background = 1 + vim.cmd('colorscheme everforest') + end + }) + use { 'kyazdani42/nvim-web-devicons' } + use { + 'nvim-lualine/lualine.nvim', + after = { 'nvim-web-devicons' }, + config = function() require 'plugins.statusline' end + } + -- use { + -- 'romgrk/barbar.nvim', + -- requires = {'kyazdani42/nvim-web-devicons'}, + -- event = 'BufAdd', + -- after = {'nvim-web-devicons'}, + -- config = function() require 'plugins.barbar' end + -- } - -- lsp stuff - use {'neovim/nvim-lspconfig', event = 'UIEnter'} - use { - 'williamboman/nvim-lsp-installer', - after = 'nvim-lspconfig', - config = function() require 'plugins.lspinstall' end - } - use {'hrsh7th/cmp-nvim-lsp', after = 'nvim-lsp-installer'} - use { - 'ray-x/lsp_signature.nvim', - after = 'nvim-lsp-installer', - config = function() require 'plugins.lsp-signature' end - } + -- lsp stuff + use { + 'neovim/nvim-lspconfig', + after = "mason-lspconfig.nvim", + config = function() require 'plugins.lsp' end + } + use { 'williamboman/mason-lspconfig.nvim', after = 'mason.nvim' } + use { 'hrsh7th/cmp-nvim-lsp', after = 'nvim-lspconfig' } + use { + 'ray-x/lsp_signature.nvim', + after = 'nvim-lspconfig', + config = function() require 'plugins.lsp-signature' end + } - -- tree sitter - use { - 'nvim-treesitter/nvim-treesitter', - event = 'UIEnter', - config = function() require 'plugins.treesitter' end, - run = ':TSUpdate' - } + -- tree sitter + use { + 'nvim-treesitter/nvim-treesitter', + event = 'UIEnter', + config = function() require 'plugins.treesitter' end, + run = ':TSUpdate' + } - -- completer - use {'L3MON4D3/LuaSnip', event = 'UIEnter'} - use { - 'hrsh7th/nvim-cmp', - event = 'InsertEnter', - after = {'LuaSnip', 'cmp-nvim-lsp', 'nvim-treesitter'}, - config = function() require 'plugins.cmp' end, - requires = { - -- local - {'hrsh7th/cmp-cmdline', after = 'nvim-cmp'}, - {'hrsh7th/cmp-buffer', after = 'nvim-cmp'}, - {'hrsh7th/cmp-path', after = 'nvim-cmp'}, { - 'petertriho/cmp-git', - after = 'nvim-cmp', - config = function() require("cmp_git").setup() end - }, {'delphinus/cmp-ctags', after = 'nvim-cmp'}, -- end - -- lsp - {'hrsh7th/cmp-nvim-lsp-document-symbol', after = 'nvim-cmp'}, -- TS - {'ray-x/cmp-treesitter', after = 'nvim-cmp'}, -- end - -- Snip - {'saadparwaiz1/cmp_luasnip', after = {'nvim-cmp', 'LuaSnip'}} - } - } + -- completer + use { 'L3MON4D3/LuaSnip', event = 'UIEnter' } + use { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + after = { 'LuaSnip', 'cmp-nvim-lsp', 'nvim-treesitter' }, + config = function() require 'plugins.cmp' end, + requires = { + -- local + { 'hrsh7th/cmp-cmdline', after = 'nvim-cmp' }, + { 'hrsh7th/cmp-buffer', after = 'nvim-cmp' }, + { 'hrsh7th/cmp-path', after = 'nvim-cmp' }, { + 'petertriho/cmp-git', + after = 'nvim-cmp', + config = function() require("cmp_git").setup() end + }, { 'delphinus/cmp-ctags', after = 'nvim-cmp' }, -- end + -- lsp + { 'hrsh7th/cmp-nvim-lsp-document-symbol', after = 'nvim-cmp' }, -- TS + { 'ray-x/cmp-treesitter', after = 'nvim-cmp' }, -- end + -- Snip + { 'saadparwaiz1/cmp_luasnip', after = { 'nvim-cmp', 'LuaSnip' } } + } + } - -- formating and editing - use { - 'windwp/nvim-autopairs', - after = 'nvim-cmp', - config = function() require('plugins.nvim-autopairs') end - } - use {'sbdchd/neoformat', cmd = 'Neoformat'} - use { - 'mattn/emmet-vim', - ft = {'html', 'htmldjango', 'css', 'markdown'}, - setup = function() require 'plugins.emmet' end - } - use {'machakann/vim-sandwich', event = 'UIEnter'} + -- formating and editing + use { "williamboman/mason.nvim", event = "UIEnter" } + use { + 'windwp/nvim-autopairs', + after = 'nvim-cmp', + config = function() require('plugins.nvim-autopairs') end + } + use { + "jose-elias-alvarez/null-ls.nvim", + config = function() + require('plugins.null-ls') + end, + requires = { "nvim-lua/plenary.nvim" }, + event = "CmdlineEnter" + } + use { + 'mattn/emmet-vim', + ft = { 'html', 'htmldjango', 'css', 'markdown' }, + setup = function() require 'plugins.emmet' end + } + use { 'machakann/vim-sandwich', event = 'UIEnter' } - use { - 'numToStr/Comment.nvim', - event = 'UIEnter', - config = function() require('Comment').setup() end - } + use { + 'numToStr/Comment.nvim', + event = 'UIEnter', + config = function() require('Comment').setup() end + } - -- navigation - use { - 'kyazdani42/nvim-tree.lua', - cmd = 'NvimTreeToggle', - requires = 'kyazdani42/nvim-web-devicons', - config = function() require('plugins.nvim-tree') end - } - use { - 'andymass/vim-matchup', - after = 'nvim-treesitter', - config = function() require 'plugins.matchup' end - } - use { - 'abecodes/tabout.nvim', - config = function() require('tabout').setup {} end, - after = {'nvim-treesitter', 'nvim-autopairs', 'nvim-cmp'} -- if a completion plugin is using tabs load it before - } - use { - 'nvim-telescope/telescope.nvim', - event = 'UIEnter', - requires = {'nvim-lua/plenary.nvim'}, - config = function() require 'plugins.telescope' end - } - use {'preservim/tagbar', cmd = 'TagbarToggle'} - use { - 'phaazon/hop.nvim', - event = 'UIEnter', - as = 'hop', - config = function() - require'hop'.setup {keys = 'etovxqpdygfblzhckisuran'} - end - } + -- navigation + use { + 'kyazdani42/nvim-tree.lua', + cmd = 'NvimTreeToggle', + requires = 'kyazdani42/nvim-web-devicons', + config = function() require('plugins.nvim-tree') end + } + use { + 'andymass/vim-matchup', + after = 'nvim-treesitter', + config = function() require 'plugins.matchup' end + } + use { + 'abecodes/tabout.nvim', + config = function() require('tabout').setup {} end, + after = { 'nvim-treesitter', 'nvim-autopairs', 'nvim-cmp' } -- if a completion plugin is using tabs load it before + } + use { + 'nvim-telescope/telescope.nvim', + event = 'UIEnter', + requires = { 'nvim-lua/plenary.nvim' }, + config = function() require 'plugins.telescope' end + } + use { 'preservim/tagbar', cmd = 'TagbarToggle' } + use { + 'phaazon/hop.nvim', + event = 'UIEnter', + as = 'hop', + config = function() + require 'hop'.setup { keys = 'etovxqpdygfblzhckisuran' } + end + } - -- eye-candy - use { - 'lukas-reineke/indent-blankline.nvim', - after = {'nvim-treesitter'}, - config = function() require 'plugins.indent-blankline' end - } - use { - 'lewis6991/gitsigns.nvim', - event = 'UIEnter', - requires = {'nvim-lua/plenary.nvim'}, - config = function() require 'plugins.gitsigns' end - } - use { - 'p00f/nvim-ts-rainbow', - after = 'nvim-treesitter', - config = function() require 'plugins.nvim-ts-rainbow' end - } - use { - 'nvim-treesitter/nvim-treesitter-context', - after = 'nvim-treesitter', - config = function() - require'treesitter-context'.setup { - enable = true, -- Enable this plugin (Can be enabled/disabled later via commands) - max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit. - patterns = { -- Match patterns for TS nodes. These get wrapped to match at word boundaries. - -- For all filetypes - -- Note that setting an entry here replaces all other patterns for this entry. - -- By setting the 'default' entry below, you can control which nodes you want to - -- appear in the context window. - default = { - 'class', 'function', 'method', 'for', -- These won't appear in the context - 'while', 'if', 'switch', 'case' - } - } - } - end - } - use { - 'winston0410/range-highlight.nvim', - event = 'CmdlineEnter', - config = function() require('range-highlight').setup {} end, - requires = 'winston0410/cmd-parser.nvim' - } - use { - 'norcalli/nvim-colorizer.lua', - event = 'BufEnter', - config = function() require 'plugins.nvim-colorizer' end - } + -- eye-candy + use { + 'lukas-reineke/indent-blankline.nvim', + after = { 'nvim-treesitter' }, + config = function() require 'plugins.indent-blankline' end + } + use { + 'lewis6991/gitsigns.nvim', + event = 'UIEnter', + requires = { 'nvim-lua/plenary.nvim' }, + config = function() require 'plugins.gitsigns' end + } + use { + 'p00f/nvim-ts-rainbow', + after = 'nvim-treesitter', + config = function() require 'plugins.nvim-ts-rainbow' end + } + use { + 'nvim-treesitter/nvim-treesitter-context', + after = 'nvim-treesitter', + config = function() + require 'treesitter-context'.setup { + enable = true, -- Enable this plugin (Can be enabled/disabled later via commands) + max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit. + patterns = { -- Match patterns for TS nodes. These get wrapped to match at word boundaries. + -- For all filetypes + -- Note that setting an entry here replaces all other patterns for this entry. + -- By setting the 'default' entry below, you can control which nodes you want to + -- appear in the context window. + default = { + 'class', 'function', 'method', 'for', -- These won't appear in the context + 'while', 'if', 'switch', 'case' + } + } + } + end + } + use { + 'winston0410/range-highlight.nvim', + event = 'CmdlineEnter', + config = function() require('range-highlight').setup {} end, + requires = 'winston0410/cmd-parser.nvim' + } + use { + 'norcalli/nvim-colorizer.lua', + event = 'BufEnter', + config = function() require 'plugins.nvim-colorizer' end + } - -- integrations - use {'tpope/vim-fugitive', cmd = 'G'} + -- integrations + use { 'tpope/vim-fugitive', cmd = 'G' } - -- fixes and misc. stuff - use {'antoinemadec/FixCursorHold.nvim', event = 'UIEnter'} + -- fixes and misc. stuff + use { 'antoinemadec/FixCursorHold.nvim', event = 'UIEnter' } end) -- vim:set shiftwidth=4 tabstop=4: diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..63c81d0 --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,15 @@ +require("mason").setup {ui = {icons = {package_installed = "✓"}}} +require("mason-lspconfig").setup {ensure_installed = {"sumneko_lua"}} +-- Dynamic loading of lsp servers +require("mason-lspconfig").setup_handlers { + -- The first entry (without a key) will be the default handler + -- and will be called for each installed server that doesn't have + -- a dedicated handler. + function(server_name) -- default handler (optional) + require("lspconfig")[server_name].setup {} + end, + -- Next, you can provide targeted overrides for specific servers. + -- For example, a handler override for the `rust_analyzer`: + ["rust_analyzer"] = function() require("rust-tools").setup {} end +} + diff --git a/lua/plugins/lspinstall.lua b/lua/plugins/lspinstall.lua deleted file mode 100644 index 081807c..0000000 --- a/lua/plugins/lspinstall.lua +++ /dev/null @@ -1,17 +0,0 @@ -local lsp_installer = require("nvim-lsp-installer") - --- Register a handler that will be called for all installed servers. --- Alternatively, you may also register handlers on specific server instances instead (see example below). -lsp_installer.on_server_ready(function(server) - local opts = {} - - -- (optional) Customize the options passed to the server - -- if server.name == "tsserver" then - -- opts.root_dir = function() ... end - -- end - - -- This setup() function is exactly the same as lspconfig's setup function. - -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md - server:setup(opts) -end) - diff --git a/lua/plugins/null-ls.lua b/lua/plugins/null-ls.lua new file mode 100644 index 0000000..7790227 --- /dev/null +++ b/lua/plugins/null-ls.lua @@ -0,0 +1,18 @@ +local null_ls = require("null-ls") + +-- builtins +-- local code_actions = null_ls.builtins.code_actions +local diagnostics = null_ls.builtins.diagnostics +local formatting = null_ls.builtins.formatting +local hover = null_ls.builtins.hover +local completion = null_ls.builtins.completion + +local sources = { + code_actions, + diagnostics, + formatting, + hover, + completion +} + +null_ls.setup({ sources = sources })