From 4a05f21b62a6d9b91d00140089f4f9841989ceee Mon Sep 17 00:00:00 2001 From: Adam <56338480+adastx@users.noreply.github.com> Date: Fri, 18 Mar 2022 15:53:37 +0100 Subject: nvim: better cmp lazy loading, lsp format on save --- .config/nvim/lua/plugins.lua | 4 ++-- .config/nvim/lua/setup/lualine.lua | 8 ++++---- .config/nvim/lua/setup/nvim-cmp.lua | 1 - .config/nvim/lua/setup/nvim-lsp-installer.lua | 7 ++++++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index 008cb78..da232d4 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -90,12 +90,12 @@ local plugins = { end }, - -- load luasnips + cmp related in insert mode only + -- load luasnips + cmp related when lsp attaches { "L3MON4D3/LuaSnip", wants = "friendly-snippets", - event = "InsertEnter", + event = "User lspAttached", config = function() require("luasnip/loaders/from_vscode").lazy_load() end, diff --git a/.config/nvim/lua/setup/lualine.lua b/.config/nvim/lua/setup/lualine.lua index 1182fce..8c8649e 100644 --- a/.config/nvim/lua/setup/lualine.lua +++ b/.config/nvim/lua/setup/lualine.lua @@ -4,7 +4,7 @@ require'lualine'.setup { theme = 'onedark', component_separators = {left = '', right = ''}, section_separators = {left = '', right = ''}, - disabled_filetypes = {'startify', 'terminal', 'netrw', 'NvimTree', 'packer'} + disabled_filetypes = {'startify', 'terminal', 'netrw', 'NvimTree', 'packer'}, }, sections = { lualine_a = {'mode'}, @@ -12,7 +12,7 @@ require'lualine'.setup { lualine_c = {'filename'}, lualine_x = {'encoding', 'filetype'}, lualine_y = {'progress'}, - lualine_z = {'location'} + lualine_z = {'location'}, }, inactive_sections = { lualine_a = {}, @@ -20,8 +20,8 @@ require'lualine'.setup { lualine_c = {'filename'}, lualine_x = {'location'}, lualine_y = {}, - lualine_z = {} + lualine_z = {}, }, tabline = {}, - extensions = {} + extensions = {}, } diff --git a/.config/nvim/lua/setup/nvim-cmp.lua b/.config/nvim/lua/setup/nvim-cmp.lua index 584da73..4f08334 100644 --- a/.config/nvim/lua/setup/nvim-cmp.lua +++ b/.config/nvim/lua/setup/nvim-cmp.lua @@ -48,4 +48,3 @@ cmp.setup { { name = 'luasnip' }, }, } -vim.cmd('autocmd FileType markdown lua require("cmp").setup.buffer { enabled = false }') diff --git a/.config/nvim/lua/setup/nvim-lsp-installer.lua b/.config/nvim/lua/setup/nvim-lsp-installer.lua index bd3496e..de086f0 100644 --- a/.config/nvim/lua/setup/nvim-lsp-installer.lua +++ b/.config/nvim/lua/setup/nvim-lsp-installer.lua @@ -3,7 +3,12 @@ local lsp_installer = require("nvim-lsp-installer") -- Register a handler that will be called for each installed server when it's ready (i.e. when installation is finished -- or if the server is already installed). lsp_installer.on_server_ready(function(server) - local opts = {} + local opts = { + on_attach = function() + vim.cmd('doautocmd User lspAttached') + vim.cmd('autocmd BufWritePre lua vim.lsp.buf.formatting_sync()') + end, + } -- (optional) Customize the options passed to the server -- if server.name == "tsserver" then -- cgit v1.2.3-70-g09d2