Move LSP config to dedicated lua file

This commit is contained in:
Edward Litherland-Smith 2022-08-04 15:16:20 +01:00
parent b683dc9045
commit c5c05bfd40
2 changed files with 63 additions and 64 deletions

View file

@ -37,64 +37,7 @@ call plug#end()
set mouse=nv
let g:python3_host_prog = '~/.pyenv/versions/neovim3/bin/python'
lua << EOF
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
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)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
-- 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)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap=true, silent=true, buffer=bufnr }
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>wa', vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, 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)
vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
end
local lsp_flags = {
-- This is the default in Nvim 0.7+
debounce_text_changes = 150,
}
require('lspconfig')['pylsp'].setup{
cmd = {"/home/elitherl/.pyenv/versions/neovim3/bin/pylsp"},
on_attach = on_attach,
flags = lsp_flags,
settings = {
pylsp = {
plugins = {
pycodestyle = {maxLineLength = 88},
flake8 = {maxLineLength = 88}
}
}
}
}
require('lspconfig')['fortls'].setup{
cmd = {"/home/elitherl/.pyenv/versions/neovim3/bin/fortls"},
on_attach = on_attach,
flags = lsp_flags,
}
EOF
luafile ~/.vim/lsp_config.lua
map ; :Files<CR>
if executable('ag')
@ -157,16 +100,16 @@ autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTr
set splitbelow
set splitright
function! GitStatus()
let [a,m,r] = GitGutterGetHunkSummary()
return printf('%s +%d ~%d -%d', FugitiveHead(), a, m, r)
endfunction
let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
" function! GitStatus()
" let [a,m,r] = GitGutterGetHunkSummary()
" return printf('%s +%d ~%d -%d', FugitiveHead(), a, m, r)
" endfunction
"
" let g:slime_target = "tmux"
" let g:slime_default_config = {"socket_name": get(split($TMUX, ","), 0), "target_pane": "{last}"}
"
" let g:lightline = { 'colorscheme': 'onehalfdark' }
" let g:lightline.component_expand = {
" \ 'linter_checking': 'lightline#ale#checking',

56
lsp_config.lua Normal file
View file

@ -0,0 +1,56 @@
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
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)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
-- 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)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap=true, silent=true, buffer=bufnr }
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>wa', vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, 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)
vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
end
local lsp_flags = {
-- This is the default in Nvim 0.7+
debounce_text_changes = 150,
}
require('lspconfig')['pylsp'].setup{
cmd = {"/home/elitherl/.pyenv/versions/neovim3/bin/pylsp"},
on_attach = on_attach,
flags = lsp_flags,
settings = {
pylsp = {
plugins = {
pycodestyle = {maxLineLength = 88},
flake8 = {maxLineLength = 88}
}
}
}
}
require('lspconfig')['fortls'].setup{
cmd = {"/home/elitherl/.pyenv/versions/neovim3/bin/fortls"},
on_attach = on_attach,
flags = lsp_flags,
}