Moved lsp config into plugin file

This commit is contained in:
Fabian Schmidt 2023-02-26 13:20:49 +01:00
parent 717c7f09e5
commit aa72c826c0
10 changed files with 183 additions and 215 deletions

View File

@ -15,7 +15,6 @@ vim.g.mapleader = " "
require("lazy").setup("plugins")
require("maps").init()
require("commands")
require("settings").init()
vim.opt.backup = false
vim.opt.undodir = '/Users/fschmidt/.cache/nvim/undodir'

View File

@ -1,5 +1,5 @@
{
"LuaSnip": { "branch": "master", "commit": "d33cf7de14eea209b8ed4a7edaed72f0b8cedb30" },
"LuaSnip": { "branch": "master", "commit": "f7c845749aba6096f041a73a26ba64f3817bab99" },
"bufferline.nvim": { "branch": "main", "commit": "52d6acabb79c8c0942f8873a0ca7848eb2159267" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "8fcc934a52af96120fe26358985c10c035984b53" },
@ -8,22 +8,20 @@
"cmp-nvim-lua": { "branch": "main", "commit": "f3491638d123cfd2c8048aefaf66d246ff250ca6" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" },
"dashboard-nvim": { "branch": "master", "commit": "a6e3536400c79f20d23b904a89d95efc6a6ac717" },
"dashboard-nvim": { "branch": "master", "commit": "398ba8d9390c13c87a964cbca756319531fffdb7" },
"fidget.nvim": { "branch": "main", "commit": "688b4fec4517650e29c3e63cfbb6e498b3112ba1" },
"gitsigns.nvim": { "branch": "main", "commit": "f388995990aba04cfdc7c3ab870c33e280601109" },
"goyo.vim": { "branch": "master", "commit": "7f5d35a65510083ea5c2d0941797244b9963d4a9" },
"kanagawa.nvim": { "branch": "master", "commit": "4c8d48726621a7f3998c7ed35b2c2535abc22def" },
"lazy.nvim": { "branch": "main", "commit": "8077428e63feb0f3bf795d53b23ba1695b28ab0e" },
"limelight.vim": { "branch": "master", "commit": "86aaec1700b27618d33d6182f44691d84d2cb6e5" },
"lspkind-nvim": { "branch": "master", "commit": "c68b3a003483cf382428a43035079f78474cd11e" },
"lualine.nvim": { "branch": "master", "commit": "e99d733e0213ceb8f548ae6551b04ae32e590c80" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "93e58e100f37ef4fb0f897deeed20599dae9d128" },
"mason.nvim": { "branch": "main", "commit": "5b9fd3822d686092c7ee08adfcbd2c764def22c5" },
"nvim-autopairs": { "branch": "master", "commit": "bde7a1b4534e0a4c2451a738379cd628ba65eba7" },
"nvim-cmp": { "branch": "main", "commit": "ba7a53478d0726683d1597ad1e814695033dcb4b" },
"nvim-lspconfig": { "branch": "master", "commit": "91998cef4b1ae3a624901d0f9c894409db24e760" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "3f9c0ea157e88b08e2d11ec65002eeb6e421f0da" },
"mason.nvim": { "branch": "main", "commit": "63cff223169324a2e633954ac580c7c327182a97" },
"nvim-autopairs": { "branch": "master", "commit": "6a5faeabdbcc86cfbf1561ae430a451a72126e81" },
"nvim-cmp": { "branch": "main", "commit": "7a3b1e76f74934b12fda82158237c6ad8bfd3d40" },
"nvim-lspconfig": { "branch": "master", "commit": "62856b20751b748841b0f3ec5a10b1e2f6a6dbc9" },
"nvim-tree.lua": { "branch": "master", "commit": "9c97e6449b0b0269bd44e1fd4857184dfa57bb4c" },
"nvim-treesitter": { "branch": "master", "commit": "2277c0c2a7d1aca2979285621ac5c82787b25dd2" },
"nvim-treesitter": { "branch": "master", "commit": "b4d8b7e5a374b800838a13aa6829ac4d542c6f1c" },
"nvim-web-devicons": { "branch": "master", "commit": "4709a504d2cd2680fb511675e64ef2790d491d36" },
"playground": { "branch": "master", "commit": "4044b53c4d4fcd7a78eae20b8627f78ce7dc6f56" },
"plenary.nvim": { "branch": "master", "commit": "253d34830709d690f013daf2853a9d21ad7accab" },

View File

@ -42,21 +42,6 @@ function maps.centeredSearch()
map('n', 'N', 'Nzzzv')
end
function maps.moveToWindow()
map('t', 'ª', '<C-\\><C-N><C-w>h')
map('t', 'º', '<C-\\><C-N><C-w>j')
map('t', '', '<C-\\><C-N><C-w>k')
map('t', '@', '<C-\\><C-N><C-w>l')
map('i', 'ª', '<C-\\><C-N><C-w>h')
map('i', 'º', '<C-\\><C-N><C-w>j')
map('i', '', '<C-\\><C-N><C-w>k')
map('i', '@', '<C-\\><C-N><C-w>l')
map('n', 'ª', '<C-w>h')
map('n', 'º', '<C-w>j')
map('n', '', '<C-w>k')
map('n', '@', '<C-w>l')
end
function maps.init()
vim.g.mapleader = " "
@ -69,7 +54,6 @@ function maps.init()
maps.fixIndent()
maps.moveByRow()
maps.centeredSearch()
-- maps.moveToWindow()
end
return maps

View File

@ -1,14 +1,171 @@
local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', ',d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', '.d', vim.diagnostic.goto_next, opts)
local lsp_attach = function(client, buf)
vim.api.nvim_buf_set_option(buf, "formatexpr", "v:lua.vim.lsp.formatexpr()")
vim.api.nvim_buf_set_option(buf, "omnifunc", "v:lua.vim.lsp.omnifunc")
vim.api.nvim_buf_set_option(buf, "tagfunc", "v:lua.vim.lsp.tagfunc")
local bufopts = { noremap = true, silent = true, buffer = buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
end
return {
-- lsp
{ 'williamboman/mason.nvim' },
{ 'williamboman/mason-lspconfig.nvim' },
{ 'neovim/nvim-lspconfig' },
{
'williamboman/mason.nvim',
config = true
},
{
'williamboman/mason-lspconfig.nvim',
config = true
},
{
'neovim/nvim-lspconfig',
config = function()
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local lspconfig = require('lspconfig')
lspconfig.lua_ls.setup {
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
globals = { 'vim' }
}
}
},
on_attach = lsp_attach
}
lspconfig.tsserver.setup {
capabilities = capabilities,
on_attach = lsp_attach
}
lspconfig.gopls.setup {
capabilities = capabilities,
on_attach = lsp_attach
}
--lspconfig.rust_analyzer.setup {
-- capabilities = capabilities,
-- on_attach = lsp_attach
--}
require("rust-tools").setup({
server = {
capabilities = capabilities,
on_attach = lsp_attach,
standalone = false
}
})
lspconfig.bashls.setup {
capabilities = capabilities,
on_attach = lsp_attach
}
lspconfig.sqlls.setup({
capabilities = capabilities,
on_attach = lsp_attach
})
lspconfig.html.setup({
capabilities = capabilities,
on_attach = lsp_attach
})
lspconfig.cssls.setup({
capabilities = capabilities,
on_attach = lsp_attach
})
lspconfig.tailwindcss.setup({
capabilities = capabilities,
on_attach = lsp_attach
})
capabilities.textDocument.completion.completionItem.snippetSupport = true
lspconfig.emmet_ls.setup({
capabilities = capabilities,
on_attach = lsp_attach
})
end
},
{ 'simrat39/rust-tools.nvim' },
{ 'onsails/lspkind-nvim' }, -- pictograms replace (?) with lspsaga
{ 'j-hui/fidget.nvim' }, -- show lsp status
-- completion
{
'hrsh7th/nvim-cmp',
config = function()
local cmp = require('cmp')
local lspkind = require('lspkind')
vim.opt.shortmess:append 'c'
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-s>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true
}),
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
['<CR>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lua' },
{ name = 'nvim_lsp' },
{ name = 'path' },
{ name = 'luasnip' },
{ name = 'nvim_lsp_signature_help' },
}, {
{ name = 'buffer', keyword_length = 5 },
}),
formatting = {
format = lspkind.cmp_format {
with_text = true,
menu = {
buffer = "[buf]",
nvim_lsp = "[LSP]",
nvim_lua = "[api]",
path = "[path]",
luasnip = "[snip]",
}
}
}
})
-- Use buffer source for `/` (basically search words in buffer)
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':'
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
end,
event = 'InsertEnter',
dependencies = {
'hrsh7th/cmp-nvim-lsp',
@ -17,12 +174,19 @@ return {
'hrsh7th/cmp-path',
'hrsh7th/cmp-nvim-lua',
'hrsh7th/cmp-cmdline',
-- snippets needed for cmp
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
}
},
{
'L3MON4D3/LuaSnip',
config = function()
require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/snippets/" })
end
},
{
'windwp/nvim-autopairs',
}
}
config = true
},
}
-- -- Linting & formtatting
-- 'jose-elias-alvarez/null-ls.nvim';

View File

@ -6,7 +6,7 @@ return {
},
{
'nvim-tree/nvim-tree.lua',
config = function ()
config = function()
require('nvim-tree').setup {
disable_netrw = true,
hijack_netrw = true,

View File

@ -2,10 +2,11 @@ return {
-- writing
{
'vimwiki/vimwiki',
ft = { 'md', 'wiki', 'tex' },
config = function()
vim.g.vimwiki_list = { { path = '~/Documents/Buch/wiki', syntax = 'markdown', ext = '.md' } }
end
},
{ 'junegunn/goyo.vim' }, -- try raplcing these 2 at some point because they don't work that well anymore
{ 'junegunn/limelight.vim' },
--{ 'junegunn/goyo.vim' }, -- try replacing these 2 at some point because they don't work that well anymore
--{ 'junegunn/limelight.vim' },
}

View File

@ -1,73 +0,0 @@
-- Completion
local completion = {}
local cmp = require('cmp')
local lspkind = require('lspkind')
vim.opt.shortmess:append 'c'
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-s>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true
}),
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
['<CR>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lua' },
{ name = 'nvim_lsp' },
{ name = 'path' },
{ name = 'luasnip' },
{ name = 'nvim_lsp_signature_help' },
}, {
{ name = 'buffer', keyword_length = 5 },
}),
formatting = {
format = lspkind.cmp_format {
with_text = true,
menu = {
buffer = "[buf]",
nvim_lsp = "[LSP]",
nvim_lua = "[api]",
path = "[path]",
luasnip = "[snip]",
}
}
}
})
-- Use buffer source for `/` (basically search words in buffer)
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':'
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
-- autopair
require('nvim-autopairs').setup {}
return completion

View File

@ -1,11 +0,0 @@
-- settings.lua
local settings = {}
function settings.init()
require('settings.lsp').init()
require('settings.completion')
require('settings.luasnip')
end
return settings

View File

@ -1,91 +0,0 @@
-- LSP Config
local lsp = {}
local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', ',d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', '.d', vim.diagnostic.goto_next, opts)
local lsp_attach = function(client, buf)
vim.api.nvim_buf_set_option(buf, "formatexpr", "v:lua.vim.lsp.formatexpr()")
vim.api.nvim_buf_set_option(buf, "omnifunc", "v:lua.vim.lsp.omnifunc")
vim.api.nvim_buf_set_option(buf, "tagfunc", "v:lua.vim.lsp.tagfunc")
local bufopts = { noremap = true, silent = true, buffer = buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
end
function lsp.init()
require('mason').setup()
require('mason-lspconfig').setup()
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local lspconfig = require('lspconfig')
lspconfig.sumneko_lua.setup {
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
globals = { 'vim' }
}
}
},
on_attach = lsp_attach
}
lspconfig.tsserver.setup {
capabilities = capabilities,
on_attach = lsp_attach
}
lspconfig.gopls.setup {
capabilities = capabilities,
on_attach = lsp_attach
}
--lspconfig.rust_analyzer.setup {
-- capabilities = capabilities,
-- on_attach = lsp_attach
--}
require("rust-tools").setup({
server = {
capabilities = capabilities,
on_attach = lsp_attach,
standalone = false
}
})
lspconfig.bashls.setup {
capabilities = capabilities,
on_attach = lsp_attach
}
lspconfig.sqlls.setup({
capabilities = capabilities,
on_attach = lsp_attach
})
lspconfig.html.setup({
capabilities = capabilities,
on_attach = lsp_attach
})
lspconfig.cssls.setup({
capabilities = capabilities,
on_attach = lsp_attach
})
lspconfig.tailwindcss.setup({
capabilities = capabilities,
on_attach = lsp_attach
})
capabilities.textDocument.completion.completionItem.snippetSupport = true
lspconfig.emmet_ls.setup({
capabilities = capabilities,
on_attach = lsp_attach
})
end
return lsp

View File

@ -1,3 +0,0 @@
local ls = require("luasnip")
require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/snippets/" })