All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: Code for ignoring linters. Only loaded and if configured.
4 " A map for remapping lspconfig server names to linter names or aliases in
5 " ALE. We should change the names where they will conflict with names in ALE.
7 " Notes on names from nvim-lspconfig not included here.
9 " * 'rubocop' is run in a language server mode
10 " * 'eslint' is run via 'vscode-eslint-language-server'
11 let s:lspconfig_map = {
13 \ 'ansiblels': 'ansible-language-server',
14 \ 'bicep': 'bicep_language_server',
15 \ 'cmake': 'cmake_language_server',
17 \ 'erlangls': 'erlang_ls',
18 \ 'html': 'vscodehtml',
19 \ 'ocamlls': 'ocaml-language-server',
21 \ 'puppet': 'puppet_languageserver',
24 " Given a filetype and a configuration for ignoring linters, return a List of
25 " Strings for linter names to ignore.
26 function! ale#engine#ignore#GetList(filetype, config) abort
27 if type(a:config) is v:t_list
31 if type(a:config) is v:t_dict
32 let l:names_to_remove = []
34 for l:part in split(a:filetype , '\.')
35 call extend(l:names_to_remove, get(a:config, l:part, []))
38 return l:names_to_remove
44 " This function can be mocked in tests.
45 function! ale#engine#ignore#GetLSPConfigNames() abort
46 return luaeval('require ''ale.util''.configured_lspconfig_servers()')
49 function! s:GetMappedLSPConfigNames() abort
50 " Check the lspconfig flag before calling luaeval.
51 if !get(g:, 'lspconfig', 0)
55 let l:lspconfig_servers = ale#engine#ignore#GetLSPConfigNames()
58 \ !empty(l:lspconfig_servers) ? l:lspconfig_servers : [],
59 \ {_, val -> get(s:lspconfig_map, val, val) }
63 " Given a List of linter descriptions, exclude the linters to be ignored.
64 function! ale#engine#ignore#Exclude(filetype, all_linters, config, disable_lsp) abort
65 let l:names_to_remove = ale#engine#ignore#GetList(a:filetype, a:config)
67 " If configured to automatically ignore otherwise configured LSP linter
68 " names, add them to the names to remove. This could ignore linters
69 " with matching names that are not marked as LSP linters.
70 if a:disable_lsp is# 'auto'
71 call extend(l:names_to_remove, s:GetMappedLSPConfigNames())
74 let l:ignore_all_lsps = a:disable_lsp is 1 || a:disable_lsp is v:true
75 let l:filtered_linters = []
77 for l:linter in a:all_linters
78 let l:should_include = index(l:names_to_remove, l:linter.name) == -1
81 while l:should_include && l:i < len(l:linter.aliases)
82 let l:name = l:linter.aliases[l:i]
83 let l:should_include = index(l:names_to_remove, l:name) == -1
87 if l:should_include && l:ignore_all_lsps
88 let l:should_include = empty(get(l:linter, 'lsp'))
92 call add(l:filtered_linters, l:linter)
96 return l:filtered_linters