· 5 years ago · Dec 18, 2020, 10:44 PM
1local lsp = require('lspconfig')
2local completion = require('completion')
3local api = vim.api
4local configs = require('lspconfig/configs')
5
6--local functi
7--" Set completeopt to have a better completion experience
8api.nvim_command('set completeopt=longest,menuone,noinsert,noselect')
9--" Use <Tab> and <S-Tab> to navigate through popup menu
10api.nvim_command('inoremap <expr> <Tab> pumvisible() ? "<C-n>" : "<Tab>"')
11api.nvim_command('inoremap <expr> <S-Tab> pumvisible() ? "<C-p>" : "<S-Tab>"')
12--" Avoid showing message extra message when using completion
13api.nvim_command('set shortmess+=c')
14--api.nvim_command('')
15
16
17local mapper = function(mode, key, result)
18 vim.api.nvim_buf_set_keymap(0, mode, key, "<cmd>lua "..result.."<cr>", {noremap = true, silent = true})
19end
20
21
22local custom_attach = function()
23 completion.on_attach()
24 -- Move cursor to the next and previous diagnostic
25 mapper('n', '<leader>dn', 'vim.lsp.diagnostic.goto_next()')
26 mapper('n', '<leader>dp', 'vim.lsp.diagnostic.goto_prev()')
27end
28
29lsp.pyls.setup{
30 on_attach = custom_attach
31}
32lsp.tsserver.setup {on_attach = custom_attach}
33lsp.jdtls.setup {on_attach = custom_attach,
34 root_dir = lsp.util.root_pattern('.git', 'pom.xml', 'build.xml')
35}
36lsp.sumneko_lua.setup {on_attach = custom_attach}
37
38--another lua config that does not work either
39--lsp.sumneko_lua.setup{
40 --on_attach=custom_attach,
41 --settings = {
42 --Lua = {
43 --runtime = { version = "LuaJIT", path = vim.split(package.path, ';'), },
44 --completion = { keywordSnippet = "Enable", },
45 --diagnostics = { enable = true, globals = {
46 --"vim", "describe", "it", "before_each", "after_each" },
47 --},
48 --workspace = {
49 --library = {
50 --[vim.fn.expand("$VIMRUNTIME/lua")] = true,
51 --[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true,
52 --}
53 --}
54 --}
55 --}
56--}
57