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: suoto <andre820@gmail.com>
2 " Description: Handling of window/* LSP methods, although right now only
3 " handles window/showMessage
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
12 " Translate strings from the user config to a number so we can check
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
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
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)
37 if l:type > l:cfg_severity_threshold
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
49 " Default to warning just in case
50 let l:severity = g:ale_echo_msg_warning_str
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')
57 call ale#util#ShowMessage(l:string)