]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/lsp_window.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / lsp_window.vim
1 " Author: suoto <andre820@gmail.com>
2 " Description: Handling of window/* LSP methods, although right now only
3 " handles window/showMessage
4
5 " Constants for message type codes
6 let s:LSP_MESSAGE_TYPE_DISABLED = 0
7 let s:LSP_MESSAGE_TYPE_ERROR = 1
8 let s:LSP_MESSAGE_TYPE_WARNING = 2
9 let s:LSP_MESSAGE_TYPE_INFORMATION = 3
10 let s:LSP_MESSAGE_TYPE_LOG = 4
11
12 " Translate strings from the user config to a number so we can check
13 " severities
14 let s:CFG_TO_LSP_SEVERITY = {
15 \   'disabled': s:LSP_MESSAGE_TYPE_DISABLED,
16 \   'error': s:LSP_MESSAGE_TYPE_ERROR,
17 \   'warning': s:LSP_MESSAGE_TYPE_WARNING,
18 \   'information': s:LSP_MESSAGE_TYPE_INFORMATION,
19 \   'info': s:LSP_MESSAGE_TYPE_INFORMATION,
20 \   'log': s:LSP_MESSAGE_TYPE_LOG
21 \}
22
23 " Handle window/showMessage response.
24 " - details: dict containing linter name and format (g:ale_lsp_show_message_format)
25 " - params: dict with the params for the call in the form of {type: number, message: string}
26 function! ale#lsp_window#HandleShowMessage(linter_name, format, params) abort
27     let l:message = a:params.message
28     let l:type = a:params.type
29
30     " Get the configured severity level threshold and check if the message
31     " should be displayed or not
32     let l:configured_severity = tolower(get(g:, 'ale_lsp_show_message_severity', 'error'))
33     " If the user has configured with a value we can't find on the conversion
34     " dict, fall back to warning
35     let l:cfg_severity_threshold = get(s:CFG_TO_LSP_SEVERITY, l:configured_severity, s:LSP_MESSAGE_TYPE_WARNING)
36
37     if l:type > l:cfg_severity_threshold
38         return
39     endif
40
41     " Severity will depend on the message type
42     if l:type is# s:LSP_MESSAGE_TYPE_ERROR
43         let l:severity = g:ale_echo_msg_error_str
44     elseif l:type is# s:LSP_MESSAGE_TYPE_INFORMATION
45         let l:severity = g:ale_echo_msg_info_str
46     elseif l:type is# s:LSP_MESSAGE_TYPE_LOG
47         let l:severity = g:ale_echo_msg_log_str
48     else
49         " Default to warning just in case
50         let l:severity = g:ale_echo_msg_warning_str
51     endif
52
53     let l:string = substitute(a:format, '\V%severity%', l:severity, 'g')
54     let l:string = substitute(l:string, '\V%linter%', a:linter_name, 'g')
55     let l:string = substitute(l:string, '\V%s\>', l:message, 'g')
56
57     call ale#util#ShowMessage(l:string)
58 endfunction