add lsp-format and efm-langserver to autoformat files

autoformat lua files on save
This commit is contained in:
Pim Kunis 2023-11-10 11:20:35 +01:00
parent 2d785a86a6
commit 8772f38aed
6 changed files with 66 additions and 60 deletions

View file

@ -6,11 +6,8 @@ require("bufferline").setup{
return " " .. icon .. count return " " .. icon .. count
end, end,
separator_style = "slant", separator_style = "slant",
hover = { hover = {enabled = true, reveal = {'close'}}
enabled = true, }
reveal = {'close'},
},
},
} }
vim.keymap.set('n', '<leader>ft', ":BufferLinePick<CR>", {}) vim.keymap.set('n', '<leader>ft', ":BufferLinePick<CR>", {})

View file

@ -5,11 +5,7 @@ require('luasnip.loaders.from_vscode').lazy_load()
luasnip.config.setup {} luasnip.config.setup {}
cmp.setup { cmp.setup {
snippet = { snippet = {expand = function(args) luasnip.lsp_expand(args.body) end},
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert { mapping = cmp.mapping.preset.insert {
['<C-n>'] = cmp.mapping.select_next_item(), ['<C-n>'] = cmp.mapping.select_next_item(),
['<C-p>'] = cmp.mapping.select_prev_item(), ['<C-p>'] = cmp.mapping.select_prev_item(),
@ -18,7 +14,7 @@ cmp.setup {
['<C-Space>'] = cmp.mapping.complete {}, ['<C-Space>'] = cmp.mapping.complete {},
['<CR>'] = cmp.mapping.confirm { ['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace, behavior = cmp.ConfirmBehavior.Replace,
select = true, select = true
}, },
['<Tab>'] = cmp.mapping(function(fallback) ['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
@ -37,10 +33,7 @@ cmp.setup {
else else
fallback() fallback()
end end
end, { 'i', 's' }), end, {'i', 's'})
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}, },
sources = {{name = 'nvim_lsp'}, {name = 'luasnip'}}
} }

View file

@ -14,6 +14,8 @@
neofetch neofetch
gopls gopls
terraform-ls terraform-ls
luaformatter
efm-langserver
]; ];
plugins = with pkgs.vimPlugins; [ plugins = with pkgs.vimPlugins; [
@ -65,6 +67,7 @@
config = builtins.readFile ./bufferline.lua; config = builtins.readFile ./bufferline.lua;
} }
nvim-web-devicons nvim-web-devicons
lsp-format-nvim
]; ];
}; };

View file

@ -1,5 +1,6 @@
local on_attach = function(_, bufnr) require("lsp-format").setup {}
local on_attach = function(client, bufnr)
local bufmap = function(keys, func) local bufmap = function(keys, func)
vim.keymap.set('n', keys, func, {buffer = bufnr}) vim.keymap.set('n', keys, func, {buffer = bufnr})
end end
@ -14,20 +15,41 @@ local on_attach = function(_, bufnr)
bufmap('gr', require('telescope.builtin').lsp_references) bufmap('gr', require('telescope.builtin').lsp_references)
bufmap('<leader>s', require('telescope.builtin').lsp_document_symbols) bufmap('<leader>s', require('telescope.builtin').lsp_document_symbols)
bufmap('<leader>S', require('telescope.builtin').lsp_dynamic_workspace_symbols) bufmap('<leader>S',
require('telescope.builtin').lsp_dynamic_workspace_symbols)
bufmap('K', vim.lsp.buf.hover) bufmap('K', vim.lsp.buf.hover)
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) vim.api.nvim_buf_create_user_command(bufnr, 'Format',
vim.lsp.buf.format() function(_) vim.lsp.buf.format() end,
end, {}) {})
end end
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
require('neodev').setup() require('neodev').setup()
require'lspconfig'.nil_ls.setup{ on_attach = on_attach, capabilities = capabilities } require'lspconfig'.nil_ls.setup {
require'lspconfig'.pyright.setup{ on_attach = on_attach, capabilities = capabilities } on_attach = on_attach,
require'lspconfig'.gopls.setup{ on_attach = on_attach, capabilities = capabilities } capabilities = capabilities
require'lspconfig'.terraformls.setup{ on_attach = on_attach, capabilities = capabilities } }
require'lspconfig'.pyright.setup {
on_attach = on_attach,
capabilities = capabilities
}
require'lspconfig'.gopls.setup {
on_attach = on_attach,
capabilities = capabilities
}
require'lspconfig'.terraformls.setup {
on_attach = on_attach,
capabilities = capabilities
}
local luaformat = {formatCommand = "lua-format -i", formatStdin = true}
require'lspconfig'.efm.setup {
on_attach = require("lsp-format").on_attach,
init_options = {documentFormatting = true},
settings = {languages = {lua = {luaformat}}},
filetypes = {"lua"}
}

View file

@ -8,20 +8,10 @@ vim.keymap.set('n', '<leader>fs', builtin.lsp_document_symbols, {})
require('telescope').setup { require('telescope').setup {
pickers = { pickers = {
find_files = { find_files = {theme = "dropdown"},
theme = "dropdown" live_grep = {theme = "dropdown"},
}, buffers = {theme = "dropdown"},
live_grep = { lsp_references = {theme = "dropdown"},
theme = "dropdown" lsp_document_symbols = {theme = "dropdown"}
},
buffers = {
theme = "dropdown"
},
lsp_references = {
theme = "dropdown"
},
lsp_document_symbols = {
theme = "dropdown"
}
} }
} }

View file

@ -5,5 +5,6 @@ require('nvim-treesitter.configs').setup {
highlight = {enable = true}, highlight = {enable = true},
indent = { enable = true }, indent = {enable = true}
} }