Skip to content

Commit 9baef1f

Browse files
authored
Add an option to fixup vim popup with conceal problems (#1376)
* Fix vim's popup and conceals * Add lsp_preview_fixup_conceal * Fix CI
1 parent e42203b commit 9baef1f

File tree

14 files changed

+108
-32
lines changed

14 files changed

+108
-32
lines changed

.github/workflows/linux_neovim.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ jobs:
3636
runs-on: ${{matrix.os}}
3737
continue-on-error: ${{matrix.allow_failure}}
3838
steps:
39+
- name: Install dependencies
40+
shell: bash
41+
run: |
42+
# https://github.com/Zettlr/Zettlr/issues/3517
43+
sudo apt-get install libfuse2
3944
- uses: actions/checkout@v2
4045
- name: Download neovim
4146
shell: bash

.github/workflows/linux_vim.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ jobs:
3131
glibc_version: 2.15
3232
runs-on: ${{matrix.os}}
3333
steps:
34+
- name: Install dependencies
35+
shell: bash
36+
run: |
37+
# https://github.com/Zettlr/Zettlr/issues/3517
38+
sudo apt-get install libfuse2
3439
- uses: actions/checkout@v2
3540
- name: Download vim
3641
shell: bash
@@ -72,5 +77,8 @@ jobs:
7277
export PATH=./vim-themis/bin:$PATH
7378
export PATH=./bin:$PATH
7479
export THEMIS_VIM=vim
75-
vim --version
76-
themis
80+
# https://github.com/project-slippi/Ishiiruka/issues/323
81+
# It was needed to detect the actual path of `libgmodule` via `ldconfig -p | grep libg`.
82+
LD_PRELOAD=/lib/x86_64-linux-gnu/libgmodule-2.0.so vim --version
83+
LD_PRELOAD=/lib/x86_64-linux-gnu/libgmodule-2.0.so themis
84+

autoload/lsp/internal/completion/documentation.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,17 @@ function! s:show_floating_window(event, managed_user_data) abort
8383
let l:detail = s:MarkupContent.normalize({
8484
\ 'language': &filetype,
8585
\ 'value': l:completion_item['detail'],
86+
\ }, {
87+
\ 'compact': !g:lsp_preview_fixup_conceal
8688
\ })
8789
let l:contents += [l:detail]
8890
endif
8991
endif
9092

9193
" Add documentation filed if provided.
92-
let l:documentation = s:MarkupContent.normalize(get(l:completion_item, 'documentation', ''))
94+
let l:documentation = s:MarkupContent.normalize(get(l:completion_item, 'documentation', ''), {
95+
\ 'compact': !g:lsp_preview_fixup_conceal
96+
\ })
9397
if !empty(l:documentation)
9498
let l:contents += [l:documentation]
9599
endif

autoload/lsp/internal/document_hover/under_cursor.vim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,17 @@ function! s:get_contents(contents) abort
189189
if has_key(a:contents, 'value')
190190
if has_key(a:contents, 'kind')
191191
if a:contents['kind'] ==? 'markdown'
192-
let l:detail = s:MarkupContent.normalize(a:contents['value'])
192+
let l:detail = s:MarkupContent.normalize(a:contents['value'], {
193+
\ 'compact': !g:lsp_preview_fixup_conceal
194+
\ })
193195
return [l:detail]
194196
else
195197
return [a:contents['value']]
196198
endif
197199
elseif has_key(a:contents, 'language')
198-
let l:detail = s:MarkupContent.normalize(a:contents)
200+
let l:detail = s:MarkupContent.normalize(a:contents, {
201+
\ 'compact': !g:lsp_preview_fixup_conceal
202+
\ })
199203
return [l:detail]
200204
else
201205
return ''

autoload/lsp/ui/vim/output.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,9 @@ function! lsp#ui#vim#output#append(data, lines, syntax_lines) abort
434434
elseif type(a:data) ==# type({}) && has_key(a:data, 'kind')
435435
if a:data.kind ==? 'markdown'
436436
call s:import_modules()
437-
let l:detail = s:MarkupContent.normalize(a:data.value)
437+
let l:detail = s:MarkupContent.normalize(a:data.value, {
438+
\ 'compact': !g:lsp_preview_fixup_conceal
439+
\ })
438440
call extend(a:lines, s:Text.split_by_eol(l:detail))
439441
else
440442
call extend(a:lines, split(s:escape_string_for_display(a:data.value), '\n', v:true))

autoload/vital/_lsp/VS/LSP/MarkupContent.vim

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,31 @@ function! s:normalize(markup_content, ...) abort
3636
elseif type(a:markup_content) == type({})
3737
let l:normalized = a:markup_content.value
3838
if has_key(a:markup_content, 'language')
39-
let l:normalized = '```' . a:markup_content.language . ' ' . l:normalized . ' ```'
39+
let l:normalized = join([
40+
\ '```' . a:markup_content.language,
41+
\ l:normalized,
42+
\ '```'
43+
\ ], "\n")
4044
endif
4145
endif
42-
if l:option.compact
43-
return s:_compact(l:normalized)
44-
endif
46+
let l:normalized = s:Text.normalize_eol(l:normalized)
47+
let l:normalized = s:_format(l:normalized, l:option.compact)
4548
return l:normalized
4649
endfunction
4750

4851
"
49-
" _compact
52+
" _format
5053
"
51-
function! s:_compact(string) abort
52-
" normalize eol.
53-
let l:string = s:Text.normalize_eol(a:string)
54-
55-
let l:string = substitute(l:string, "\\%(\\s\\|\n\\)*```\\s*\\(\\w\\+\\)\\%(\\s\\|\n\\)\\+", "\n\n```\\1 ", 'g')
56-
let l:string = substitute(l:string, "\\%(\\s\\|\n\\)\\+```\\%(\\s*\\%(\\%$\\|\n\\)\\)\\+", " ```\n\n", 'g')
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
5762
let l:string = substitute(l:string, "\\%^\\%(\\s\\|\n\\)*", '', 'g')
5863
let l:string = substitute(l:string, "\\%(\\s\\|\n\\)*\\%$", '', 'g')
59-
6064
return l:string
6165
endfunction
6266

autoload/vital/_lsp/VS/Vim/Buffer.vim

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
function! s:_SID() abort
55
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
66
endfunction
7-
execute join(['function! vital#_lsp#VS#Vim#Buffer#import() abort', printf("return map({'get_line_count': '', 'do': '', 'create': '', 'pseudo': '', 'ensure': '', 'load': ''}, \"vital#_lsp#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
7+
execute join(['function! vital#_lsp#VS#Vim#Buffer#import() abort', printf("return map({'add': '', 'do': '', 'create': '', 'get_line_count': '', 'pseudo': '', 'ensure': '', 'load': ''}, \"vital#_lsp#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
88
delfunction s:_SID
99
" ___vital___
1010
let s:Do = { -> {} }
@@ -51,11 +51,25 @@ function! s:ensure(expr) abort
5151
if type(a:expr) == type(0)
5252
throw printf('VS.Vim.Buffer: `%s` is not valid expr.', a:expr)
5353
endif
54-
badd `=a:expr`
54+
call s:add(a:expr)
5555
endif
5656
return bufnr(a:expr)
5757
endfunction
5858

59+
"
60+
" add
61+
"
62+
if exists('*bufadd')
63+
function! s:add(name) abort
64+
let l:bufnr = bufadd(a:name)
65+
call setbufvar(l:bufnr, '&buflisted', 1)
66+
endfunction
67+
else
68+
function! s:add(name) abort
69+
badd `=a:name`
70+
endfunction
71+
endif
72+
5973
"
6074
" load
6175
"

autoload/vital/_lsp/VS/Vim/Syntax/Markdown.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function! s:apply(...) abort
7474
\ l:filetype_group
7575
\ )
7676
catch /.*/
77-
unsilent echomsg string({ 'exception': v:exception, 'throwpoint': v:throwpoint })
77+
unsilent echomsg printf('Fail to apply "syntax/%s.vim". Add "let g:markdown_fenced_languages = ["%s=$FILETYPE"]" to enable syntax', l:filetype, l:filetype)
7878
endtry
7979
endfor
8080
endfunction

autoload/vital/_lsp/VS/Vim/Window.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function! s:scroll(winid, topline) abort
106106
function! l:ctx.callback(winid, topline) abort
107107
let l:wininfo = s:info(a:winid)
108108
let l:topline = a:topline
109-
let l:topline = min([l:topline, line('$') - l:wininfo.height + 3])
109+
let l:topline = min([l:topline, line('$') - l:wininfo.height + 1])
110110
let l:topline = max([l:topline, 1])
111111

112112
if l:topline == l:wininfo.topline

autoload/vital/_lsp/VS/Vim/Window/FloatingWindow.vim

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ endfunction
198198
" @param {number} args.col 0-based indexing
199199
" @param {number} args.width
200200
" @param {number} args.height
201-
" @param {boolean?} args.border
201+
" @param {boolean|[string]?} args.border - boolean, or list of characters
202+
" clockwise from top-left (same as nvim_open_win() in neovim)
202203
" @param {number?} args.topline
203204
" @param {string?} args.origin - topleft/topright/botleft/botright
204205
"
@@ -450,11 +451,14 @@ endfunction
450451

451452
if has('nvim')
452453
function! s:_resolve_border(style) abort
453-
if !empty(get(a:style, 'border', v:null))
454-
if &ambiwidth ==# 'single'
455-
let a:style.border = ['', '', '', '', '', '', '', '']
456-
else
457-
let a:style.border = ['+', '-', '+', '|', '+', '-', '+', '|']
454+
let l:border = get(a:style, 'border', v:null)
455+
if !empty(l:border)
456+
if type(l:border) != type([])
457+
if &ambiwidth ==# 'single'
458+
let a:style.border = ['', '', '', '', '', '', '', '']
459+
else
460+
let a:style.border = ['+', '-', '+', '|', '+', '-', '+', '|']
461+
endif
458462
endif
459463
elseif has_key(a:style, 'border')
460464
unlet a:style.border
@@ -463,11 +467,28 @@ if has('nvim')
463467
endfunction
464468
else
465469
function! s:_resolve_border(style) abort
470+
let l:border = get(a:style, 'border', v:null)
466471
if !empty(get(a:style, 'border', v:null))
467-
if &ambiwidth ==# 'single'
468-
let a:style.border = ['', '', '', '', '', '', '', '']
472+
if type(l:border) != type([])
473+
if &ambiwidth ==# 'single'
474+
let a:style.border = ['', '', '', '', '', '', '', '']
475+
else
476+
let a:style.border = ['-', '|', '-', '|', '+', '+', '+', '+']
477+
endif
469478
else
470-
let a:style.border = ['-', '|', '-', '|', '+', '+', '+', '+']
479+
" Emulate nvim behavior for lists of 1/2/4 elements
480+
let l:topleft = l:border[0]
481+
let l:top = get(l:border, 1, l:topleft)
482+
let l:topright = get(l:border, 2, l:topleft)
483+
let l:right = get(l:border, 3, l:top)
484+
let l:bottomright = get(l:border, 4, l:topleft)
485+
let l:bottom = get(l:border, 5, l:top)
486+
let l:bottomleft = get(l:border, 6, l:topright)
487+
let l:left = get(l:border, 7, l:right)
488+
let a:style.border = [
489+
\ l:top, l:right, l:bottom, l:left,
490+
\ l:topleft, l:topright, l:bottomright, l:bottomleft,
491+
\ ]
471492
endif
472493
elseif has_key(a:style, 'border')
473494
unlet a:style.border

0 commit comments

Comments
 (0)