]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/vim-lsp/autoload/lsp/internal/show_message.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:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / vim-lsp / autoload / lsp / internal / show_message.vim
1 let s:ErrorType = 1
2 let s:WarningType = 2
3 let s:InfoType = 3
4 let s:LogType = 4
5
6 function! lsp#internal#show_message#_enable() abort
7     if g:lsp_show_message_log_level ==# 'none' | return | endif
8     let s:Dispose = lsp#callbag#pipe(
9             \ lsp#stream(),
10             \ lsp#callbag#filter({x->
11             \   g:lsp_show_message_log_level !=# 'none' &&
12             \   has_key(x, 'response') && has_key(x['response'], 'method')
13             \   && x['response']['method'] ==# 'window/showMessage'
14             \ }),
15             \ lsp#callbag#tap({x->s:handle_show_message(x['server'], x['response']['params'])}),
16             \ lsp#callbag#subscribe({ 'error': function('s:on_error') }),
17             \ )
18 endfunction
19
20 function! lsp#internal#show_message#_disable() abort
21     if exists('s:Dispose')
22         call s:Dispose()
23         unlet s:Dispose
24     endif
25 endfunction
26
27 function! s:on_error(e) abort
28     call lsp#log('lsp#internal#show_message error', a:e)
29     if exists('s:Dispose')
30         call s:Dispose()
31         unlet s:Dispose
32     endif
33 endfunction
34
35 function! s:handle_show_message(server, params) abort
36     let l:level = s:name_to_level(g:lsp_show_message_log_level)
37     let l:type = a:params['type']
38     if l:level < l:type
39         return
40     endif
41
42     let l:message = a:params['message']
43     try
44         if l:type == s:ErrorType
45             echohl ErrorMsg
46         elseif l:type == s:WarningType
47             echohl WarningMsg
48         endif
49         echom printf('%s: %s: %s', a:server, s:type_to_name(l:type), l:message)
50     finally
51         echohl None
52     endtry
53 endfunction
54
55 function! s:name_to_level(name) abort
56     if a:name ==# 'none'
57         return 0
58     elseif a:name ==# 'error'
59         return s:ErrorType
60     elseif a:name ==# 'warn' || a:name ==# 'warning'
61         return s:WarningType
62     elseif a:name ==# 'info'
63         return s:InfoType
64     elseif a:name ==# 'log'
65         return s:LogType
66     else
67         return 0
68     endif
69 endfunction
70
71 function! s:type_to_name(type) abort
72     return get(['unknown', 'error', 'warning', 'info', 'log'], a:type, 'unknown')
73 endfunction
74