Skip to content
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

Adjustment of omnicomplete #2606

Closed
wgmzbl opened this issue Dec 25, 2022 · 20 comments
Closed

Adjustment of omnicomplete #2606

wgmzbl opened this issue Dec 25, 2022 · 20 comments

Comments

@wgmzbl
Copy link

wgmzbl commented Dec 25, 2022

I want to show extra information about the currently selected completion in a popup window by put :set completeopt+=popup. But I found it did not work. I run the function vimtex#complete#omnifunc manually and found a lot of things are contained in "menu" item. According to the help doc of "complete-functions", the "menu" item is used in the popup menu and may be truncated, thus it should be relatively short. Hence it is hard to see the detailed info about the selected completion, especially I want to cite papers since the "menu" item is quite long. It is better that I can view them in a popup menu. This is extremely helpful if it can provide us detailed info in a popup menu about the referenced equations and citations, especially when writing a long paper with a large bib file.

@lervag
Copy link
Owner

lervag commented Dec 25, 2022

I want to show extra information about the currently selected completion in a popup window by put :set completeopt+=popup.

I can see why you would want this. This is currently not supported. The completion items provided by VimTeX only includes a "fancy" completion menu, not any additional information that would be displayed in a preview or extra popup window.

PS! The popup value for 'completeopt' is only available on Vim (just in case neovim users read this). It works similar to preview.

According to the help doc of "complete-functions", the "menu" item is used in the popup menu and may be truncated,

Yes, but you are reading this wrong. The popup menu here refers to the actual completion menu. Instead, the "info" item is the one we want in this particular case.

I will look into if this is a quick win. If it is, I may implement it. If it turns out to be hard, then I may not have the time.

@lervag
Copy link
Owner

lervag commented Dec 25, 2022

For citation completion, it is quite easy to add information in such a popup window. However, I'm not sure I see a very big value of it compared to simply adjusting the menu as it is displayed with g:vimtex_complete_bib. Could you provide a simple, minimal example configuration that would make sense and where the popup window will be clearly useful compared to the current completion menu for citations?

For reference completion for equations and similar, it is harder. Perhaps not impossible, but still, I don't think I have the time to follow that up right now. I would not mind getting a PR or similar for this, but I'll not spend time on it myself. Sorry.

@wgmzbl
Copy link
Author

wgmzbl commented Dec 25, 2022

Here is a picture when I try it with .py file. I have set completeopt=menuone,popup,popuphidden. When I select the first function, it will popup another window which shows all the detailed definition of this function.
image

But if I set completeopt=menuone, preview, it looks all the information is contained in one single line and it is truncated. Here is a picture of that.
image

What I want to know if it is possible that we can see the detailed info of the selected completion like title, years, and so on in a new popup window instead of one line information.

For reference completion, it would be better if it could show a few surrounding lines around that label.

One typical situation I met is when \cite{} is close to the right boundary of vim, all other information is truncated. Here is a picture of it.
image

In this case, I need to check my bib file manually since it is quite hard to remember all these items if the bib file is quite large. It would be very helpful if it could show the full title of the paper.

Thank you for your help.

@lervag
Copy link
Owner

lervag commented Dec 25, 2022

Here is a picture when I try it with .py file. I have set completeopt=menuone,popup,popuphidden. When I select the first function, it will popup another window which shows all the detailed definition of this function.

Ok. The popup is positioned to the right of the completion menu, and in my tests, it seems hard to place the popup more dynamically. One idea then might be to simplify the contents of the completion menu, which would make it less wide. With let g:vimtex_complete_bib = #{menu_fmt: '[@type]'} and with popup in the completeopt, I get something like this:

image

I could create a PR with necessary changes to VimTeX for something like this.

But if I set completeopt=menuone, preview

With the preview option, Vim should open a preview split where the same information is displayed. That seems to work as expected for me, at least:

image

For reference completion, it would be better if it could show a few surrounding lines around that label.

Yes, that would make sense. But reference completion is based on parsing the aux file. The aux file does not contain the source position, only the output position. Thus, we do not immediately know where a particular reference is located in the source files, and so showing surrounding lines is non-trivial.

Of course, we can parse the entire LaTeX source, but that is much more expensive. It could work, though, but I'm not really tempted to try it. Sorry!

One typical situation I met is when \cite{} is close to the right boundary of vim, all other information is truncated.

Yes, adding the info popup for cite completion can be a viably feature request as mentioned above.

lervag added a commit that referenced this issue Dec 25, 2022
@lervag
Copy link
Owner

lervag commented Dec 25, 2022

Ok, I believe the changes for citation completion are not going to be intrusive, so I've pushed a first version of it directly now. Please update and test and let me know what you think.

@wgmzbl
Copy link
Author

wgmzbl commented Dec 26, 2022

The citation completion looks great to me. Thank you for your work. That is exactly what I expect. One more thing is, could we control which information showed in the popup window? Like the way we set up the value of menu_fmt to change the content of completion menu.

By the way, for the reference completion, I might want to know if we could also setup the values of menu_fmt and info_fmt if possible to adjust the content of completion menu and popup. I prefer to add some contents in the popup once the menu items are truncated, even they might have same information. Right now, I notice a black popup coming out for reference completion. Here is a picture of my test.

image

It may helps us when \ref{} is closed to right boundary of vim.

lervag added a commit that referenced this issue Dec 26, 2022
@lervag
Copy link
Owner

lervag commented Dec 26, 2022

The citation completion looks great to me. Thank you for your work. That is exactly what I expect. One more thing is, could we control which information showed in the popup window? Like the way we set up the value of menu_fmt to change the content of completion menu.

Yes, good idea. I've implemented that now, please see :help vimtex_complete_bib and the info_fmt key. The default setting should be the same as the initial version.

By the way, for the reference completion, I might want to know if we could also setup the values of menu_fmt and info_fmt if possible to adjust the content of completion menu and popup. I prefer to add some contents in the popup once the menu items are truncated, even they might have same information. Right now, I notice a black popup coming out for reference completion. Here is a picture of my test.

I think you are mixing two different things here:

  1. Reference completion leads to an empty popup window.

  2. You want a popup window for reference completion because the standard completion menu is not good when you are close to the right edge.

Do I understand you correctly? If so, can we please focus on one of these at a time?

@wgmzbl
Copy link
Author

wgmzbl commented Dec 26, 2022

Thank you very much. That's wonderful.

Reference completion leads to an empty popup window.

If it is empty, it seems useless to show an empty popup. Is there a way to hide it?

You want a popup window for reference completion because the standard completion menu is not good when you are close to the right edge.

Yes, this is what I want. What I'm thinking about is, we can adjust the value of menu_fmt and info_fmt so that if info_fmt key is not empty, then there is a popup coming out showing the information described by info_fmt. If info_fmt is empty, we just hide the popup.

@lervag
Copy link
Owner

lervag commented Dec 26, 2022

Thank you very much. That's wonderful.

Glad to hear it!

Reference completion leads to an empty popup window.

If it is empty, it seems useless to show an empty popup. Is there a way to hide it?

Well, for me, there is no such empty popup. Can you explain how to reproduce this?

You want a popup window for reference completion because the standard completion menu is not good when you are close to the right edge.

Yes, this is what I want. What I'm thinking about is, we can adjust the value of menu_fmt and info_fmt so that if info_fmt key is not empty, then there is a popup coming out showing the information described by info_fmt. If info_fmt is empty, we just hide the popup.

Ok, so: menu_fmt and info_fmt only apply to citation completion, not to reference completion. And there are no equivalents for reference completion. Currently, reference completion do not provide any "info" items and so there should not be any popup window. And this is the behaviour I'm observing on my end.

@wgmzbl
Copy link
Author

wgmzbl commented Dec 26, 2022

Well, for me, there is no such empty popup. Can you explain how to reproduce this?

After trying other languages, I guess this is not directly related to vimtex. The way to reproduce is, after we insert a citation by selecting one item in the completion menu (which will have a popup window by setting set completeopt=menuone,popup,popuphidden), we will find that there will be an empty popup for any other type of completion, too. Of course the empty popup would not appear if we just try the reference completion at first.

@lervag
Copy link
Owner

lervag commented Dec 27, 2022

Ah, yes, that may explain it. It seems like a bug. Not sure. Do you need popuphidden, by the way - do you see the same problem if you remove it?

@wgmzbl
Copy link
Author

wgmzbl commented Dec 27, 2022

Yes, the same thing happens if I remove popuphidden. Indeed, I do not know the role of popuphidden. I only set completeopt=menuone,popup in my .vimrc. After starting the vim, I found popuphidden was added and I needed to remove it manually.

@lervag
Copy link
Owner

lervag commented Dec 27, 2022

After you start Vim, you can use :verbose set completeopt to see where it was last changed.

But OK, I have to admit I don't quite know how to solve the case of the empty popup. Sorry!

@wgmzbl
Copy link
Author

wgmzbl commented Dec 27, 2022

After you start Vim, you can use :verbose set completeopt to see where it was last changed.

I see. It showed the plug youcompleteme modified it. I guess this is a bug of youcompleteme. The popup was hidden at first and when CompleteChanged happened, this plug would change the visibility of the popup even if it is empty.

But OK, I have to admit I don't quite know how to solve the case of the empty popup. Sorry!

That's fine. Thank you for your work. I can set completepopup=border:off to make it less obvious.

@wgmzbl
Copy link
Author

wgmzbl commented Dec 27, 2022

One more thing I would like to mention. I'm not sure if you would like to add it into vimtex. As I noticed, we can change the options of the popup to make it more fancy. Here, I added the following code in my .vimrc and set info_fmt using markdown.

function! UpdatePopup()
  let popid=popup_findinfo()
  if popid!=0
    call setwinvar(popid,'&conceallevel', 3)
    call setbufvar(winbufnr(popid),'&filetype', 'markdown')
  endif
endfunction

au CompleteChanged * call UpdatePopup()

With syntax highlight, it is easier for us to identify the important information. It is also good for us to add syntax highlight for the popup.

@lervag
Copy link
Owner

lervag commented Dec 28, 2022

function! UpdatePopup()
  let popid=popup_findinfo()
  if popid!=0
    call setwinvar(popid,'&conceallevel', 3)
    call setbufvar(winbufnr(popid),'&filetype', 'markdown')
  endif
endfunction

au CompleteChanged * call UpdatePopup()

Ah, yes, I agree that this is useful and can improve the popup. Notice, though, that you may want to restrict the autocommand for this particular UpdatePopup to .tex files. E.g. with au CompleteChanged *.tex ….

@wgmzbl
Copy link
Author

wgmzbl commented Dec 28, 2022

Notice, though, that you may want to restrict the autocommand for this particular UpdatePopup to .tex files. E.g. with au CompleteChanged *.tex ….

Yes, that's right. Thank you.

@wgmzbl
Copy link
Author

wgmzbl commented Jan 2, 2023

Here is one more thing we can do to improve the reference completion. As I have checked the content of a .aux file, there is one more piece of information we can take advantage of is the "title" of that item. I modify the auxiliary.vim by myself and put extra things to the info popup. In particular, the title is quite suitable to be put in the popup. Here is a picture of it and it shows the name of this theorem if it has one.

image

So here are two improvements for the reference completion.

The first one is, it would be better to support the custom content for the "menu" item and "info" item. For me, I prefer a very short "menu" item only containing key information.

The second one is, it would be great if we could include the "title" information in the completion as it was already provided by the .aux file.

@lervag
Copy link
Owner

lervag commented Jan 2, 2023

For this, it would be better if you open a new issue where you provide an example file with which I can test while implementing. The example file should not be too long, but it should be long enough to make a good example. When I compile it, it should contain the mentioned information in the aux file.

It would also be nice if you can explain slightly more the "before" and "after" of both proposed suggestions.

@lervag
Copy link
Owner

lervag commented Jan 2, 2023

I'll take the liberty of closing this issue.

@lervag lervag closed this as completed Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants