Skip to content

Commit 9a00d5a

Browse files
authored
Allow specifying max width for floating windows (#1336)
1 parent 52240c3 commit 9a00d5a

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

autoload/lsp/internal/completion/documentation.vim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,15 @@ function! s:show_floating_window(event, managed_user_data) abort
109109
call setbufline(l:doc_win.get_bufnr(), 1, lsp#utils#_split_by_eol(join(l:contents, "\n\n")))
110110

111111
" Calculate layout.
112+
if g:lsp_float_max_width >= 1
113+
let l:maxwidth = g:lsp_float_max_width
114+
elseif g:lsp_float_max_width == 0
115+
let l:maxwidth = &columns
116+
else
117+
let l:maxwidth = float2nr(&columns * 0.4)
118+
endif
112119
let l:size = l:doc_win.get_size({
113-
\ 'maxwidth': float2nr(&columns * 0.4),
120+
\ 'maxwidth': l:maxwidth,
114121
\ 'maxheight': float2nr(&lines * 0.4),
115122
\ })
116123
let l:margin_right = &columns - 1 - (float2nr(a:event.col) + float2nr(a:event.width) + 1 + (a:event.scrollbar ? 1 : 0))

autoload/lsp/internal/diagnostics/float.vim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ function! s:show_float(diagnostic) abort
4646
call setbufline(l:doc_win.get_bufnr(), 1, lsp#utils#_split_by_eol(a:diagnostic['message']))
4747

4848
" Compute size.
49+
if g:lsp_float_max_width >= 1
50+
let l:maxwidth = g:lsp_float_max_width
51+
elseif g:lsp_float_max_width == 0
52+
let l:maxwidth = &columns
53+
else
54+
let l:maxwidth = float2nr(&columns * 0.4)
55+
endif
4956
let l:size = l:doc_win.get_size({
50-
\ 'maxwidth': float2nr(&columns * 0.4),
57+
\ 'maxwidth': l:maxwidth,
5158
\ 'maxheight': float2nr(&lines * 0.4),
5259
\ })
5360

autoload/lsp/internal/document_hover/under_cursor.vim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,15 @@ function! s:show_floating_window(server_name, request, response) abort
142142
call setbufline(l:doc_win.get_bufnr(), 1, lsp#utils#_split_by_eol(join(l:contents, "\n\n")))
143143

144144
" Calculate layout.
145+
if g:lsp_float_max_width >= 1
146+
let l:maxwidth = g:lsp_float_max_width
147+
elseif g:lsp_float_max_width == 0
148+
let l:maxwidth = &columns
149+
else
150+
let l:maxwidth = float2nr(&columns * 0.4)
151+
endif
145152
let l:size = l:doc_win.get_size({
146-
\ 'maxwidth': float2nr(&columns * 0.4),
153+
\ 'maxwidth': l:maxwidth,
147154
\ 'maxheight': float2nr(&lines * 0.4),
148155
\ })
149156
let l:pos = s:compute_position(l:size)

doc/vim-lsp.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ CONTENTS *vim-lsp-contents*
7272
g:lsp_preview_max_width |g:lsp_preview_max_width|
7373
g:lsp_preview_max_height |g:lsp_preview_max_height|
7474
g:lsp_preview_fixup_conceal |g:lsp_preview_fixup_conceal|
75+
g:lsp_float_max_width |g:lsp_preview_max_width|
7576
g:lsp_signature_help_enabled |g:lsp_signature_help_enabled|
7677
g:lsp_fold_enabled |g:lsp_fold_enabled|
7778
g:lsp_hover_conceal |g:lsp_hover_conceal|
@@ -920,6 +921,17 @@ g:lsp_preview_fixup_conceal *g:lsp_preview_fixup_conceal*
920921
That's useful in vim. vim's popup doesn't shrink correctly if the
921922
buffer content uses conceals.
922923

924+
g:lsp_float_max_width *g:lsp_preview_max_width*
925+
Type: |Number|
926+
Default: `-1`
927+
928+
If positive, determines the maximum width of the float windows in
929+
characters. Lines longer than `g:lsp_float_max_width` will be wrapped to fit
930+
in the float window.
931+
If set to 0, float windows can stretch to the width of the screen.
932+
Otherwise, the maximum width of the floating windows is set to 40% of the
933+
screen.
934+
923935
g:lsp_signature_help_enabled *g:lsp_signature_help_enabled*
924936
Type: |Number|
925937
Default: `1`

plugin/lsp.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ let g:lsp_preview_fixup_conceal = get(g:, 'lsp_preview_fixup_conceal', 0)
5858
let g:lsp_peek_alignment = get(g:, 'lsp_peek_alignment', 'center')
5959
let g:lsp_preview_max_width = get(g:, 'lsp_preview_max_width', -1)
6060
let g:lsp_preview_max_height = get(g:, 'lsp_preview_max_height', -1)
61+
let g:lsp_float_max_width = get(g:, 'lsp_float_max_width', -1)
6162
let g:lsp_signature_help_enabled = get(g:, 'lsp_signature_help_enabled', 1)
6263
let g:lsp_signature_help_delay = get(g:, 'lsp_signature_help_delay', 200)
6364
let g:lsp_show_workspace_edits = get(g:, 'lsp_show_workspace_edits', 0)

0 commit comments

Comments
 (0)