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

@ -1,16 +1,13 @@
require("bufferline").setup{
require("bufferline").setup {
options = {
diagnostics = 'nvim_lsp',
diagnostics_indicator = function(count, level, diagnostics_dict, context)
local icon = level:match("error") and "" or ""
return " " .. icon .. count
local icon = level:match("error") and "" or ""
return " " .. icon .. count
end,
separator_style = "slant",
hover = {
enabled = true,
reveal = {'close'},
},
},
hover = {enabled = true, reveal = {'close'}}
}
}
vim.keymap.set('n', '<leader>ft', ":BufferLinePick<CR>", {})

View file

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

View file

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

View file

@ -1,33 +1,55 @@
local on_attach = function(_, bufnr)
require("lsp-format").setup {}
local bufmap = function(keys, func)
vim.keymap.set('n', keys, func, { buffer = bufnr })
end
local on_attach = function(client, bufnr)
local bufmap = function(keys, func)
vim.keymap.set('n', keys, func, {buffer = bufnr})
end
bufmap('<leader>r', vim.lsp.buf.rename)
bufmap('<leader>a', vim.lsp.buf.code_action)
bufmap('<leader>r', vim.lsp.buf.rename)
bufmap('<leader>a', vim.lsp.buf.code_action)
bufmap('gd', vim.lsp.buf.definition)
bufmap('gD', vim.lsp.buf.declaration)
bufmap('gI', vim.lsp.buf.implementation)
bufmap('<leader>D', vim.lsp.buf.type_definition)
bufmap('gd', vim.lsp.buf.definition)
bufmap('gD', vim.lsp.buf.declaration)
bufmap('gI', vim.lsp.buf.implementation)
bufmap('<leader>D', vim.lsp.buf.type_definition)
bufmap('gr', require('telescope.builtin').lsp_references)
bufmap('<leader>s', require('telescope.builtin').lsp_document_symbols)
bufmap('<leader>S', require('telescope.builtin').lsp_dynamic_workspace_symbols)
bufmap('gr', require('telescope.builtin').lsp_references)
bufmap('<leader>s', require('telescope.builtin').lsp_document_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.lsp.buf.format()
end, {})
vim.api.nvim_buf_create_user_command(bufnr, 'Format',
function(_) vim.lsp.buf.format() end,
{})
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
require('neodev').setup()
require'lspconfig'.nil_ls.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 }
require'lspconfig'.nil_ls.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

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

View file

@ -3,7 +3,8 @@ require('nvim-treesitter.configs').setup {
auto_install = false,
highlight = { enable = true },
highlight = {enable = true},
indent = { enable = true },
indent = {enable = true}
}