Replace ale with nvim-lsp, other tweaks

This commit is contained in:
Agatha Lovelace 2022-06-27 22:12:09 +02:00
parent 80b357db09
commit b334a19ee4
Signed by: sorceress
GPG Key ID: 11BBCFC65FC9F401
2 changed files with 99 additions and 51 deletions

View File

@ -19,56 +19,15 @@ highlight Pmenu guibg=black
" refresh time
set updatetime=500
" keybinds
" code actions
nnoremap <C-c><C-a> :lua vim.lsp.buf.code_action()<CR>
" CtrlSF
let g:ctrlsf_default_root = "project"
" ale
let g:ale_linters = {'rust': ['analyzer'], 'css': ['csslint']}
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'html': ['prettier'],
\ 'css': ['prettier'],
\ }
let g:ale_fix_on_save = 1
let g:ale_javascript_prettier_options = '--tab-width 4'
let g:ale_rust_analyzer_config = {
\ 'cargo': { 'loadOutDirsFromCheck': v:true },
\ 'procMacro': { 'enable': v:true },
\ 'checkOnSave': { 'command': 'clippy', 'enable': v:true }
\ }
let g:lightline.component_expand = {
\ 'linter_checking': 'lightline#ale#checking',
\ 'linter_infos': 'lightline#ale#infos',
\ 'linter_warnings': 'lightline#ale#warnings',
\ 'linter_errors': 'lightline#ale#errors',
\ 'linter_ok': 'lightline#ale#ok',
\ }
" Lightline
let g:lightline.component_function = {
\ 'gitbranch': 'FugitiveHead'
\ }
let g:lightline.component_type = {
\ 'linter_checking': 'right',
\ 'linter_infos': 'right',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error',
\ 'linter_ok': 'right',
\ }
" lightline symbols
let g:lightline#ale#indicator_checking = "\uf110"
let g:lightline#ale#indicator_infos = "\uf129"
let g:lightline#ale#indicator_warnings = "\uf071"
let g:lightline#ale#indicator_errors = "\uf05e"
let g:lightline#ale#indicator_ok = "\uf00c"
" lightline modules
let g:lightline.active = {
\ 'left' : [
@ -76,16 +35,21 @@ let g:lightline.active = {
\ ['gitbranch', 'readonly', 'filename', 'modified']
\ ],
\ 'right': [
\ ['linter_checking', 'linter_errors', 'linter_warnings'],
\ ['lsp_errors', 'lsp_warnings'],
\ ['lineinfo'],
\ ['percent'],
\ ['fileformat', 'fileencoding', 'filetype']
\ ]
\}
" CtrlSF
let g:ctrlsf_default_root = "project"
" lightline symbols
let g:lightline#lsp#indicator_errors = "\uf05e"
let g:lightline#lsp#indicator_info = "\uf129"
let g:lightline#lsp#indicator_ok = "\uf00c"
let g:lightline#lsp#indicator_warnings = "\uf071"
" register compoments:
call lightline#lsp#register()
lua << EOF
@ -120,14 +84,87 @@ for _, server in ipairs(lsp_installer.get_installed_servers()) do
nvim_lsp[server.name].setup {}
end
local lsp_formatting = function(bufnr)
vim.lsp.buf.format({
filter = function(client)
if vim.bo.filetype == "rust" then
return client.name ~= "null-ls"
else
return true
end
end,
bufnr = bufnr,
})
end
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
-- 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)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
lsp_formatting(bufnr)
end,
})
end
-- 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.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)
vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
end
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
local servers = { 'rust_analyzer', 'emmet_ls', 'cssls' }
local servers = { 'emmet_ls', 'cssls' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
capabilities = capabilities,
}
end
nvim_lsp['rust_analyzer'].setup {
on_attach = on_attach,
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
rustfmt = {
extraArgs = {"+nightly"},
},
checkOnSave = {
command = "clippy"
}
},
}
}
local null_ls = require("null-ls")
null_ls.setup({
on_attach = on_attach,
sources = {
null_ls.builtins.completion.spell,
null_ls.builtins.formatting.fixjson,
null_ls.builtins.formatting.nginx_beautifier,
null_ls.builtins.formatting.prettier,
null_ls.builtins.formatting.trim_newlines,
null_ls.builtins.formatting.trim_whitespace,
null_ls.builtins.code_actions.eslint,
null_ls.builtins.diagnostics.fish,
},
})
vim.diagnostic.config({
virtual_text = {

15
.vimrc
View File

@ -32,6 +32,7 @@ Plug 'lilydjwg/colorizer'
Plug 'mg979/vim-visual-multi'
Plug 'owickstrom/vim-colors-paramount'
Plug 'raimondi/delimitmate'
Plug 'rust-lang/rust.vim', {'for': 'rust'}
Plug 'tpope/vim-commentary'
Plug 'vim-scripts/nginx.vim', {'for': 'nginx'}
Plug 'yuttie/comfortable-motion.vim'
@ -45,8 +46,11 @@ if has('nvim')
Plug 'dyng/ctrlsf.vim'
Plug 'folke/todo-comments.nvim'
Plug 'hrsh7th/cmp-calc'
Plug 'https://github.com/josa42/nvim-lightline-lsp'
Plug 'https://github.com/mfussenegger/nvim-lint'
Plug 'j-hui/fidget.nvim'
Plug 'jghauser/mkdir.nvim'
Plug 'jose-elias-alvarez/null-ls.nvim'
Plug 'stevearc/dressing.nvim'
Plug 'williamboman/nvim-lsp-installer'
Plug 'antoinemadec/FixCursorHold.nvim'
@ -61,13 +65,11 @@ if has('nvim')
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/vim-vsnip'
Plug 'kyazdani42/nvim-web-devicons'
Plug 'maximbaz/lightline-ale'
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'tpope/vim-fugitive'
Plug 'w0rp/ale'
endif
call plug#end()
@ -162,6 +164,9 @@ set ts=4 sw=4
set autoindent
set smartindent
set breakindent
set scrolloff=5
set laststatus=2
set noshowmode
@ -176,6 +181,12 @@ set clipboard=unnamedplus
nnoremap d "_d
vnoremap d "_d
" Preserve undo history across editing sessions.
if has('persistent_undo')
set undodir=~/.vim/undo
set undofile
endif
set ignorecase
set smartcase
set hlsearch