~gpanders/dotfiles

ref: 2da1dde5ea566f82ebe6532bc6d3b8670fd77ce8 dotfiles/vim/.vim/after/plugin/ale.vim -rw-r--r-- 2.7 KiB
2da1dde5Greg Anders Note 'open' subcommand opens editor in NOTES_DIR when no argument given 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
" ALE configuration
" This file is executed AFTER ALE is loaded
" Author: Greg Anders <greg@gpanders.com>
" Date: 2019-12-05

let s:save_cpo = &cpo
set cpo&vim

if !get(g:, 'loaded_ale')
    finish
endif

if !exists('g:ale_linters')
    let g:ale_linters = {}
endif

if get(g:, 'ale_completion_enabled')
    let cot = &completeopt
    set completeopt=menu,menuone,preview,noselect,noinsert
    if cot =~# 'popup'
        set completeopt-=preview completeopt+=popup
    endif
endif

" Python {{{
let g:ale_linters.python = ['pylint', 'flake8', 'pyls', 'mypy']
let g:ale_python_pylint_change_directory = 0
let g:ale_python_flake8_change_directory = 0
let g:ale_python_pyls_config = {
            \ 'pyls': {
            \   'configurationSources': ['flake8', 'pylint'],
            \   'plugins': {
            \     'pycodestyle': {
            \       'enabled': v:false,
            \     },
            \   },
            \ }}
" }}}

" C/C++ {{{
let g:ale_linters.c = ['clangd']
let g:ale_linters.cpp = g:ale_linters.c


let g:ale_c_clangd_options = '--clang-tidy --fallback-style=LLVM --background-index --suggest-missing-includes --header-insertion=iwyu'
let g:ale_cpp_clangd_options = g:ale_c_clangd_options . ' --clang-tidy-checks=cppcoreguidelines-*'

let g:ale_c_parse_makefile = 1
let g:ale_c_parse_compile_commands = 1

" }}}

" VHDL {{{
let g:ale_vhdl_xvhdl_options = '--2008 --nolog'
" }}}

" Rust {{{
let g:ale_linters.rust = ['cargo', 'rls']
let g:ale_rust_rls_toolchain = 'stable'
" }}}

let g:ale_fixers = {
            \ 'python': ['isort'],
            \ 'cpp': ['clang-format'],
            \ 'c': ['clang-format'],
            \ '*': ['remove_trailing_lines', 'trim_whitespace']
            \}

" Go {{{
let g:ale_linters.go = ['golint', 'gofmt', 'gopls']
" }}}

nmap <Space><C-F> <Plug>(ale_fix)

function! s:lsp_setup()
    let buf = bufnr('')
    let lsps = filter(ale#linter#Get(&filetype), {_, v -> 
                \ !empty(v.lsp) && ale#engine#IsExecutable(buf, ale#linter#GetExecutable(buf, v))})
    if empty(lsps)
        return
    endif

    let b:ale_lsp_enabled = 1
    setlocal omnifunc=ale#completion#OmniFunc
    nmap <buffer> <C-]> <Plug>(ale_go_to_definition)
    nmap <buffer> <C-W>] <Plug>(ale_go_to_definition_in_split)
    nmap <buffer> <C-W><C-]> <Plug>(ale_go_to_definition_in_split)
    nmap <buffer> <Bslash>r <Plug>(ale_find_references)
endfunction

function! s:toggle(...)
    if !&modifiable || &readonly
        silent ALEDisableBuffer
    elseif get(a:, '1', 1)
        silent ALEEnableBuffer
    endif
endfunction

augroup plugin.ale
    autocmd!
    autocmd OptionSet modifiable,readonly call <SID>toggle()
    autocmd BufWinEnter * call <SID>toggle(0)
    autocmd FileType * call <SID>lsp_setup()
augroup END

let &cpo = s:save_cpo
unlet s:save_cpo