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 " refresh time
set updatetime=500 set updatetime=500
" keybinds " CtrlSF
" code actions let g:ctrlsf_default_root = "project"
nnoremap <C-c><C-a> :lua vim.lsp.buf.code_action()<CR>
" ale " Lightline
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',
\ }
let g:lightline.component_function = { let g:lightline.component_function = {
\ 'gitbranch': 'FugitiveHead' \ '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 " lightline modules
let g:lightline.active = { let g:lightline.active = {
\ 'left' : [ \ 'left' : [
@ -76,16 +35,21 @@ let g:lightline.active = {
\ ['gitbranch', 'readonly', 'filename', 'modified'] \ ['gitbranch', 'readonly', 'filename', 'modified']
\ ], \ ],
\ 'right': [ \ 'right': [
\ ['linter_checking', 'linter_errors', 'linter_warnings'], \ ['lsp_errors', 'lsp_warnings'],
\ ['lineinfo'], \ ['lineinfo'],
\ ['percent'], \ ['percent'],
\ ['fileformat', 'fileencoding', 'filetype'] \ ['fileformat', 'fileencoding', 'filetype']
\ ] \ ]
\} \}
" CtrlSF " lightline symbols
let g:ctrlsf_default_root = "project" 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 lua << EOF
@ -113,21 +77,94 @@ local nvim_lsp = require 'lspconfig'
local cmp = require'cmp' local cmp = require'cmp'
lsp_installer.setup { lsp_installer.setup {
automatic_installation = true automatic_installation = true
} }
for _, server in ipairs(lsp_installer.get_installed_servers()) do for _, server in ipairs(lsp_installer.get_installed_servers()) do
nvim_lsp[server.name].setup {} nvim_lsp[server.name].setup {}
end 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 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 for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup { nvim_lsp[lsp].setup {
on_attach = on_attach,
capabilities = capabilities, capabilities = capabilities,
} }
end 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({ vim.diagnostic.config({
virtual_text = { virtual_text = {

15
.vimrc
View File

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