-
Notifications
You must be signed in to change notification settings - Fork 85
feat: add completionInPreview option and preview filetype handling #696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
45fe0ea to
547ffcc
Compare
|
now the preview closes after the autocompletion got selected, but it's still opened when there're no completions also the preview window's size is still too small? screen-20251103-010957.2.mp4 |
|
ok tried testing it for a bit, seems like lsp/autoload/lsp/completion.vim Line 277 in c57a261
the preview window's was initialized with 'Lazy doc', maybe this messed the window size up? also can i suggest if there can be a toggle for (not) autoclosing the preview window? if it's not hard to implement |
|
I have no idea why the preview window height is not sufficiently high; by default it should be (=12) and Vim respect it? |
772895e to
26547cd
Compare
|
the height seems to change accordingly with the documentation's length screen-20251103-215927.2.mp4 |
|
maybe resize the window after the doc is shown? This works for me *** completion.vim.old 2025-11-05 08:35:36.036497263 +1100
--- completion.vim 2025-11-05 08:36:08.768497250 +1100
***************
*** 456,461 ****
--- 456,462 ----
infoText->append(0)
[1, 1]->cursor()
exe $'setlocal ft={infoKind}'
+ exe 'resize' &previewheight
:wincmd p
catch /E441/ # No preview window
endtry |
|
Thank you! We should be good to go @yegappan |
|
Could it be related to the just added exe 'resize' &previewheight? Does it still show up without it? |
error still shows up with the line removed
same error with try ... catch, prolly caused by something else |
|
ok nvm lsp/autoload/lsp/completion.vim Lines 631 to 635 in 5ded994
screen-20251105-181844.2.mp4the error still exists after removing |
|
https://groups.google.com/g/vim_dev/c/UX9-Dgw86xA |
So with make sure that |
im unsure how it works, there's no error when im using python lsp, it only appears when using clangd |
|
Can you try to make sense of the solution justmao945/vim-clang#140 ? |
it tried to move the problematic calls away from the autocomplete function? I'm not an expert about the internals of this plugin (lsp), so i don't know if there's a way to adapt that here, not counting that this plugin is not clangd specific yet something I noticed is that in while |
Yes, could you distill which? |
|
my understanding is while lazy loading uses maybe something with the implementation or timing of those functions? I have no idea |
|
Thank you, so doing it the roundabout # autoload/lsp/completion.vim (lines 453-460)
:wincmd P
:setlocal modifiable
bufnr()->deletebufline(1, '$')
infoText->append(0)
[1, 1]->cursor()
setlocal ft=lspgfm
:wincmd p
catch /E441/ # No preview windowsolves that problem? |
won't, the error will still happen with |
|
lsp/autoload/lsp/completion.vim Lines 763 to 766 in 5ded994
actually can we even change the state of the preview window during |
I think changing means less ambiguously switching here; so we can still change, say the filetype, but have to stay inside the window |
|
Here's the corresponding fix for php complete |
How come then this doesn't give any errors ? |
|
More exactly, the file type is correctly set |
|
For short, get the popup window id and then |
It wasn't run on |
the buffer is still being changed via the markdown renderer ( tried setting the file type indirectly via |
|
The culprit is the |
This changes the how can I get the window id for |
seems like this gives the same error |
|
To get the preview window id, you can try get(filter(getwininfo(), 'getwinvar(v:val.winid, "&previewwindow")'), 0, {'winid': 0}).winidthough surely there's a more elegant way |
still E21 after |
*** completion.vim.old 2025-11-07 15:55:44.318862207 +1100
--- completion.vim 2025-11-08 12:10:36.013632178 +1100
***************
*** 612,617 ****
--- 612,627 ----
id->popup_setoptions(opt.PopupConfigure('Completion', {}))
enddef
+ def LspSetPreviewFileType(timer_id: number)
+ try
+ :wincmd P
+ setlocal modifiable
+ setlocal ft=lspgfm
+ :wincmd p
+ catch /E441/
+ endtry
+ enddef
+
# If the completion popup documentation window displays "markdown" content,
# then set the 'filetype' to "lspgfm".
def LspSetPopupFileType()
***************
*** 628,639 ****
endif
if opt.lspOptions.completionInPreview
! try
! :wincmd P
! setlocal ft=lspgfm
! :wincmd p
! catch /E441/
! endtry
else
var id = popup_findinfo()
if id > 0
--- 638,644 ----
endif
if opt.lspOptions.completionInPreview
! timer_start(0, 'LspSetPreviewFileType')
else
var id = popup_findinfo()
if id > 0
tested for a bit, seems like using some async magic works |
also an improved version of window resizing exe 'resize ' .. min([line('$') + 1, &previewheight]) |
|
Is only the latter or both patches needed? |
|
both, the latter is for resizing the preview window |
|
good to go? |
|
Yes for now, all good 👍 |
| def LspCompleteDone(bnr: number) | ||
| var lspserver: dict<any> = buf.BufLspServerGet(bnr, 'completion') | ||
| if lspserver->empty() | ||
| if opt.lspOptions.completionInPreview && opt.lspOptions.closePreviewOnComplete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe @yegappan prefers, if ever merged, a silent! one-liner as it appears thrice






A stab at #688 ; if @813ethan could test and comment