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

Merge commit '56df844d3c39ec494dacc69eae34272b27db185a' as '.vim/bundle/asyncomplete'
[etc/vim.git] / .vim / bundle / vim-lsp / syntax / lsp-hover.vim
1 " Converts a markdown language (```foo) to the corresponding Vim filetype
2 function! s:get_vim_filetype(lang_markdown) abort
3     " If the user hasn't customised markdown fenced languages, just return the
4     " markdown language
5     if !exists('g:markdown_fenced_languages')
6         return a:lang_markdown
7     endif
8
9     " Otherwise, check if it has an entry for the given language
10     for l:type in g:markdown_fenced_languages
11         let l:vim_type = substitute(matchstr(l:type, '[^=]*$'), '\..*', '', '')
12         let l:markdown_type = matchstr(l:type, '[^=]*')
13
14         if l:markdown_type ==# a:lang_markdown
15             " Found entry
16             return l:vim_type
17         endif
18     endfor
19
20     " Not found
21     return a:lang_markdown
22 endfunction
23
24 function! s:do_highlight() abort
25     if exists('b:lsp_syntax_highlights')
26         for l:entry in b:lsp_syntax_highlights
27             let l:line = l:entry['line']
28             let l:lang = l:entry['language']
29             let l:ft = s:get_vim_filetype(l:lang)
30
31             execute printf('syntax match markdownHighlight%s contains=@markdownHighlight%s /^\%%%sl.*$/', l:ft, l:ft, l:line)
32         endfor
33     endif
34 endfunction
35
36 function! s:cleanup_markdown() abort
37     " Don't highlight _ in words
38     syntax match markdownError "\w\@<=\w\@="
39
40     " Conceal escaped characters
41     " Workaround for: https://github.com/palantir/python-language-server/issues/386
42     if has('conceal')
43         for l:escaped_char in ['`', '*', '_', '{', '}', '(', ')', '<', '>', '#', '+', '.', '!', '-']
44             execute printf('syntax region vimLspMarkdownEscape matchgroup=Conceal start="\\\ze[%s]" end="[%s]\zs" concealends', l:escaped_char, l:escaped_char)
45         endfor
46     end
47 endfunction
48
49 call s:do_highlight()
50 call s:cleanup_markdown()