112 lines
3.1 KiB
Django/Jinja
112 lines
3.1 KiB
Django/Jinja
--use an on_attach function to only map the following keys
|
|
--after the language server attaches to the current buffer
|
|
local on_attach = function(client, bufnr)
|
|
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
|
|
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
|
|
|
-- enable completion triggered by <c-x><c-o>
|
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
-- mappings
|
|
local opts = { noremap=true, silent=true }
|
|
|
|
--see `:help vim.lsp.*` for documentation on any of the below functions
|
|
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
|
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
|
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
end
|
|
|
|
|
|
--enable some language servers with the additional completion capabilities
|
|
--offered by nvim-cmp
|
|
local servers = {
|
|
'ansiblels', 'yamlls', 'cssls', 'jsonls', 'tsserver', 'bashls', 'lua_ls'
|
|
}
|
|
|
|
--add additional capabilities supported by nvim-cmp
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
|
|
|
local nvim_lsp = require('lspconfig')
|
|
|
|
for _, lsp in ipairs(servers) do
|
|
nvim_lsp[lsp].setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
end
|
|
|
|
local util = require('lspconfig/util')
|
|
|
|
local python_root_dir = function(fname)
|
|
return util.root_pattern('.git', 'setup.cfg', 'requirements')(fname) or
|
|
util.path.dirname(fname)
|
|
end
|
|
|
|
nvim_lsp.pylsp.setup({
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
cmd = { 'pylsp', '--verbose' },
|
|
settings = {
|
|
pylsp = {
|
|
plugins = {
|
|
ruff = {
|
|
enabled = true
|
|
}
|
|
}
|
|
}
|
|
},
|
|
root_dir = python_root_dir
|
|
})
|
|
|
|
local pyright_capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
pyright_capabilities.textDocument.publishDiagnostics.tagSupport.valueSet = { 2 }
|
|
|
|
nvim_lsp.pyright.setup({
|
|
on_attach = on_attach,
|
|
capabilities = pyright_capabilities,
|
|
root_dir = python_root_dir
|
|
})
|
|
|
|
nvim_lsp.html.setup({
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
filetypes = { 'html', 'htmldjango' },
|
|
})
|
|
|
|
local cmp = require('cmp')
|
|
local luasnip = require('luasnip')
|
|
|
|
cmp.setup({
|
|
snippet = {
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body)
|
|
end,
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_next_item()
|
|
elseif luasnip.expand_or_jumpable() then
|
|
luasnip.expand_or_jump()
|
|
else
|
|
fallback()
|
|
end
|
|
end, { 'i', 's' }),
|
|
['S-<Tab>'] = cmp.mapping(function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_prev_item()
|
|
elseif luasnip.jumpable(-1) then
|
|
luasnip.jump(-1)
|
|
else
|
|
fallback()
|
|
end
|
|
end, { 'i', 's' }),
|
|
}),
|
|
sources = {
|
|
{ names = 'nvim_lsp', },
|
|
{ names = 'luasnip', }, -- TODO: add snippets
|
|
},
|
|
})
|