]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/balloon.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 / balloon.vim
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: balloonexpr support for ALE.
3
4 function! ale#balloon#MessageForPos(bufnr, lnum, col) abort
5     let l:set_balloons = ale#Var(a:bufnr, 'set_balloons')
6     let l:show_problems = 0
7     let l:show_hover = 0
8
9     if l:set_balloons is 1
10         let l:show_problems = 1
11         let l:show_hover = 1
12     elseif l:set_balloons is# 'hover'
13         let l:show_hover = 1
14     endif
15
16     " Don't show balloons if they are disabled, or linting is disabled.
17     if !(l:show_problems || l:show_hover)
18     \|| !g:ale_enabled
19     \|| !getbufvar(a:bufnr, 'ale_enabled', 1)
20         return ''
21     endif
22
23     if l:show_problems
24         let l:loclist = get(g:ale_buffer_info, a:bufnr, {'loclist': []}).loclist
25         let l:index = ale#util#BinarySearch(l:loclist, a:bufnr, a:lnum, a:col)
26     endif
27
28     " Show the diagnostics message if found, 'Hover' output otherwise
29     if l:show_problems && l:index >= 0
30         return l:loclist[l:index].text
31     elseif l:show_hover && (
32     \   exists('*balloon_show')
33     \   || getbufvar(
34     \       a:bufnr,
35     \       'ale_set_balloons_legacy_echo',
36     \       get(g:, 'ale_set_balloons_legacy_echo', 0)
37     \   )
38     \)
39         " Request LSP/tsserver hover information, but only if this version of
40         " Vim supports the balloon_show function, or if we turned a legacy
41         " setting on.
42         call ale#hover#Show(a:bufnr, a:lnum, a:col, {'called_from_balloonexpr': 1})
43     endif
44
45     return ''
46 endfunction
47
48 function! ale#balloon#Expr() abort
49     return ale#balloon#MessageForPos(v:beval_bufnr, v:beval_lnum, v:beval_col)
50 endfunction
51
52 function! ale#balloon#Disable() abort
53     if has('balloon_eval')
54         set noballooneval
55         set balloonexpr=
56     endif
57
58     if has('balloon_eval_term')
59         set noballoonevalterm
60         set balloonexpr=
61     endif
62 endfunction
63
64 function! ale#balloon#Enable() abort
65     if has('balloon_eval')
66         set ballooneval
67         set balloonexpr=ale#balloon#Expr()
68     endif
69
70     if has('balloon_eval_term')
71         set balloonevalterm
72         set balloonexpr=ale#balloon#Expr()
73     endif
74 endfunction