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

Vimtex support isn't complete #1

Closed
jfab20 opened this issue Nov 2, 2021 · 17 comments
Closed

Vimtex support isn't complete #1

jfab20 opened this issue Nov 2, 2021 · 17 comments

Comments

@jfab20
Copy link

jfab20 commented Nov 2, 2021

When I go in a .tex file, I want omni completion so I can use vimtex omni suggestions to my advantage. When I type \a for example, the suggestions are correct and I get this:

image

However with some letters, some completion is missing. For example if I type \b I get:
image

Which is missing a LOT of omni completions. For example \beta, or \backslash. If I type <c-x><c-o> with \b I get:
image
And I dont get any of that with nvim-cmp
I have noticed the same problem with \s, \e, and a lot of other letters. For example \p does include all the options from the omni completion, but this varies from time to time.

This is my init.vim:

call plug#begin()
Plug 'lervag/vimtex' 
Plug 'hrsh7th/nvim-cmp'
Plug 'SirVer/ultisnips'

"nvim-cmp sources
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-omni'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'quangnguyen30192/cmp-nvim-ultisnips'

call plug#end()
lua <<EOF
  -- Setup nvim-cmp.
  local cmp = require'cmp'

  cmp.setup({

    snippet = {
      expand = function(args)
        vim.fn["UltiSnips#Anon"](args.body) 
      end,
    },

    mapping = {
         ['<C-n>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
         ['<C-p>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
    },

    sources = cmp.config.sources({
      { name = 'ultisnips' }, 
      { name = 'omni' }, 
      { name = 'buffer' },
    })

  })

  -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
  cmp.setup.cmdline('/', {
    sources = {
      { name = 'buffer' }
    }
  })

  cmp.setup.cmdline(':', {
    sources = cmp.config.sources({
      { name = 'path' }
    }, {
      { name = 'cmdline' }
    })
  })

EOF ```
@jhossbach
Copy link

@hrsh7th The offset in this line is wrong:

local result = self:_invoke(vim.bo.omnifunc, { 0, string.sub(params.context.cursor_before_line, offset) })

offset should be offset + 1. If the current line says \b for example, only the b has to be passed to the omnifunc. For some characters it still works (e.g. \B). For @jfab-123 the results displayed are only those items from the buffer / ultisnips.

@jhossbach
Copy link

The vimtex omnifunc also provides additional data, e.g. symbols as seen in the picture above, or additional information when using \cite{.... I will try to come up with an extra source to include this as well.

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 29, 2021

I think it's keyword pattern problem. What the keyword pattern did you use?

@jhossbach

@jhossbach
Copy link

jhossbach commented Nov 29, 2021

Let me illustrate on the example \b:
I believe vimtex's omnifunc expects b to be passed, but I believe as of now, \b is passed (or maybe its an escape issue and it should be \\b?).
I tested this using

:lua print(vim.inspect(vim.api.nvim_call_function(vim.bo.omnifunc, {0, 'b'})))`

with omnifunc begin set to vimtex#complete#omnifunc.
This instead returns an empty list (for this the backslash has to be escaped):

:lua print(vim.inspect(vim.api.nvim_call_function(vim.bo.omnifunc, {0, '\\b'})))`

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 29, 2021

Oh my... The omnifunc should reutnr the number that 0-origin indexed...

OK. I think it should be +1 value. @jhossbach Is there something wrong?

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 29, 2021


function! OmniFuncTest(findstart, input) abort
  if a:findstart == 1
    return 1
  end
  return ['foo', 'bar', 'baz']
endfunction
set omnifunc=OmniFuncTest

I tested with the above example omnifunc.

If I return 0 as start position, the completion menu will be shown to 1 column.
If I return 1 as start position, the completion menu will be shown to 2 column.

@jhossbach
Copy link


function! OmniFuncTest(findstart, input) abort
  if a:findstart == 1
    return 1
  end
  return ['foo', 'bar', 'baz']
endfunction
set omnifunc=OmniFuncTest

I tested with the above example omnifunc.

If I return 0 as start position, the completion menu will be shown to 1 column. If I return 1 as start position, the completion menu will be shown to 2 column.

With cmp-omni, this works when offset is set without +1. So is this an issue with the vimtex omnifunc and not of cmp-omni?

@jhossbach
Copy link

I am unsure, seeing that vimtex seems to work flawlessly with other plugins such as deoplete etc.

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 29, 2021

I've fixed the offset problem. Thank you very much.

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 29, 2021

At least, the html omnifunc is worked fine with this fix.

@jhossbach
Copy link

Great, glad to help! On a side note, vimtex provides a lot of additional data that is currently not displayed in nvim-cmp. Can we add that to the list of items to show? Or should we add another source explicitly for vimtex? See this comment: lervag/vimtex#2215 (comment)

@jhossbach
Copy link

This is a sample output for the pattern b, we could add these entries to also display in the completion window.

image

@jfab20
Copy link
Author

jfab20 commented Nov 29, 2021

I've fixed the offset problem. Thank you very much.

I think this works for me!

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 30, 2021

@jhossbach I've added the kind and menu.

@jhossbach
Copy link

Ah, very nice, I did not know about LabelDetails, looks good to me! I think this can be closed now

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 30, 2021

@hrsh7th hrsh7th closed this as completed Nov 30, 2021
@ghost
Copy link

ghost commented Dec 11, 2021

Is it possible to format the menu of nvim-cmp, without loosing the additional information provided by vimtex?

I've followed the steps described here to customize my menu with lspicons.

At the moment my vim_item.menu looks like this:

-- set a name for each source
vim_item.menu = ({
    nvim_lsp = "[LSP]",
    luasnip = "[LuaSnip]",
    buffer = "[Buffer]",
    omni = "[Omni]",
    path = "[Path]",
    latex_symbols = "[Latex]",
})[entry.source.name]

In my menu appears [Omni] instead of the LabelDetails, e. g. [cmd: default]. But I would like to have both information. Is this possible?

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

3 participants