]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/vim-lsp/autoload/vital/_lsp/VS/LSP/MarkupContent.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 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / vim-lsp / autoload / vital / _lsp / VS / LSP / MarkupContent.vim
1 " ___vital___
2 " NOTE: lines between '" ___vital___' is generated by :Vitalize.
3 " Do not modify the code nor insert new lines before '" ___vital___'
4 function! s:_SID() abort
5   return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
6 endfunction
7 execute join(['function! vital#_lsp#VS#LSP#MarkupContent#import() abort', printf("return map({'_vital_depends': '', 'normalize': '', '_vital_loaded': ''}, \"vital#_lsp#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
8 delfunction s:_SID
9 " ___vital___
10 "
11 " _vital_loaded
12 "
13 function! s:_vital_loaded(V) abort
14   let s:Text = a:V.import('VS.LSP.Text')
15 endfunction
16
17 "
18 " _vital_depends
19 "
20 function! s:_vital_depends() abort
21   return ['VS.LSP.Text']
22 endfunction
23
24 "
25 " normalize
26 "
27 function! s:normalize(markup_content, ...) abort
28   let l:option = get(a:000, 0, {})
29   let l:option.compact = get(l:option, 'compact', v:true)
30
31   let l:normalized = ''
32   if type(a:markup_content) == type('')
33     let l:normalized = a:markup_content
34   elseif type(a:markup_content) == type([])
35     let l:normalized = join(a:markup_content, "\n")
36   elseif type(a:markup_content) == type({})
37     let l:normalized = a:markup_content.value
38     if has_key(a:markup_content, 'language')
39       let l:normalized = join([
40       \   '```' . a:markup_content.language,
41       \   l:normalized,
42       \   '```'
43       \ ], "\n")
44     endif
45   endif
46   let l:normalized = s:Text.normalize_eol(l:normalized)
47   let l:normalized = s:_format(l:normalized, l:option.compact)
48   return l:normalized
49 endfunction
50
51 "
52 " _format
53 "
54 function! s:_format(string, compact) abort
55   let l:string = a:string
56   if a:compact
57     let l:string = substitute(l:string, "\\%(\\s\\|\n\\)*```\\s*\\(\\w\\+\\)\\%(\\s\\|\n\\)\\+", "\n\n```\\1 ", 'g')
58     let l:string = substitute(l:string, "\\%(\\s\\|\n\\)\\+```\\%(\\s*\\%(\\%$\\|\n\\)\\)\\+", " ```\n\n", 'g')
59   else
60     let l:string = substitute(l:string, "```\n\\zs\\%(\\s\\|\n\\)\\+", "", 'g')
61   endif
62   let l:string = substitute(l:string, "\\%^\\%(\\s\\|\n\\)*", '', 'g')
63   let l:string = substitute(l:string, "\\%(\\s\\|\n\\)*\\%$", '', 'g')
64   return l:string
65 endfunction
66