add lsp-format and efm-langserver to autoformat files
autoformat lua files on save
This commit is contained in:
parent
2d785a86a6
commit
8772f38aed
6 changed files with 66 additions and 60 deletions
|
@ -1,16 +1,13 @@
|
||||||
require("bufferline").setup{
|
require("bufferline").setup {
|
||||||
options = {
|
options = {
|
||||||
diagnostics = 'nvim_lsp',
|
diagnostics = 'nvim_lsp',
|
||||||
diagnostics_indicator = function(count, level, diagnostics_dict, context)
|
diagnostics_indicator = function(count, level, diagnostics_dict, context)
|
||||||
local icon = level:match("error") and " " or " "
|
local icon = level:match("error") and " " or " "
|
||||||
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>", {})
|
||||||
|
|
|
@ -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
|
||||||
|
@ -28,7 +24,7 @@ cmp.setup {
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
end, { 'i', 's' }),
|
end, {'i', 's'}),
|
||||||
['<S-Tab>'] = cmp.mapping(function(fallback)
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_prev_item()
|
cmp.select_prev_item()
|
||||||
|
@ -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'}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,33 +1,55 @@
|
||||||
local on_attach = function(_, bufnr)
|
require("lsp-format").setup {}
|
||||||
|
|
||||||
local bufmap = function(keys, func)
|
local on_attach = function(client, bufnr)
|
||||||
vim.keymap.set('n', keys, func, { buffer = bufnr })
|
local bufmap = function(keys, func)
|
||||||
end
|
vim.keymap.set('n', keys, func, {buffer = bufnr})
|
||||||
|
end
|
||||||
|
|
||||||
bufmap('<leader>r', vim.lsp.buf.rename)
|
bufmap('<leader>r', vim.lsp.buf.rename)
|
||||||
bufmap('<leader>a', vim.lsp.buf.code_action)
|
bufmap('<leader>a', vim.lsp.buf.code_action)
|
||||||
|
|
||||||
bufmap('gd', vim.lsp.buf.definition)
|
bufmap('gd', vim.lsp.buf.definition)
|
||||||
bufmap('gD', vim.lsp.buf.declaration)
|
bufmap('gD', vim.lsp.buf.declaration)
|
||||||
bufmap('gI', vim.lsp.buf.implementation)
|
bufmap('gI', vim.lsp.buf.implementation)
|
||||||
bufmap('<leader>D', vim.lsp.buf.type_definition)
|
bufmap('<leader>D', vim.lsp.buf.type_definition)
|
||||||
|
|
||||||
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"}
|
||||||
|
}
|
||||||
|
|
|
@ -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>fr', builtin.lsp_references, {})
|
||||||
vim.keymap.set('n', '<leader>fs', builtin.lsp_document_symbols, {})
|
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"
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,8 @@ require('nvim-treesitter.configs').setup {
|
||||||
|
|
||||||
auto_install = false,
|
auto_install = false,
|
||||||
|
|
||||||
highlight = { enable = true },
|
highlight = {enable = true},
|
||||||
|
|
||||||
indent = { enable = true },
|
indent = {enable = true}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue