vimtex icon indicating copy to clipboard operation
vimtex copied to clipboard

Vimtex + nvim-cmp not working.

Open Pyrole-2002 opened this issue 3 years ago • 3 comments

Description

I was trying to get vimtex working with nvim-cmp, I found similar issues which were solved using omni (idk what that is).

Here are my configs:

vimtex.lua: http://ix.io/46HO cmp.lua: http://ix.io/46HP

my directory structure

/home/pyrole/.config/nvim
├── init.lua
├── lua
│   └── pyrole
│       ├── autopairs.lua
│       ├── bufferline.lua
│       ├── cmp.lua
│       ├── colorizer.lua
│       ├── colorscheme.lua
│       ├── comment.lua
│       ├── gitsigns.lua
│       ├── indent.lua
│       ├── kanagawa.lua
│       ├── keymaps.lua
│       ├── lspconfig.lua
│       ├── luasnip.lua
│       ├── nvim-tree.lua
│       ├── options.lua
│       ├── plugins.lua
│       ├── tabnine.lua
│       ├── telescope.lua
│       ├── toggleterm.lua
│       ├── treesitter.lua
│       └── vimtex.lua
├── oldinit.vim
└── plugin
    └── packer_compiled.lua

3 directories, 23 files

Steps to reproduce

No response

Expected behavior

No response

Actual behavior

No response

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: Arch Linux
  Vim version: NVIM v0.7.2
  Has clientserver: true
  Servername: /tmp/nvimTn11aS/0

VimTeX project: main
  base: main.tex
  root: /home/pyrole/Programming/Latex
  tex: /home/pyrole/Programming/Latex/main.tex
  main parser: current file verified
  document class: article
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Zathura
    xwin id: 0

Pyrole-2002 avatar Aug 05 '22 05:08 Pyrole-2002

I was trying to get vimtex working with nvim-cmp, I found similar issues which were solved using omni (idk what that is).

Did you read the documentation?

Hint: :help vimtex-complete-nvim-cmp

lervag avatar Aug 05 '22 08:08 lervag

Yes, later I did install cmp-omni also which I had forgotten earlier still I see no difference.

Pyrole-2002 avatar Aug 05 '22 18:08 Pyrole-2002

Ok. If you've read the docs and still can't make it work, then, please, create a minimal working example. I am sure the problem is with your configuration, but it is impossible to tell without having it available. The pastebins of vimtex.lua and cmp.lua are not enough.

The issue template explains how to create a minimal example and how to describe an issue properly.

You can use lua if you want, in which case you probably want something like this minimal.lua:

-- Ensure that all neccessary plugins are available in runtimepath
vim.opt.runtimepath:prepend "~/.local/plugged/cmp-omni"
vim.opt.runtimepath:prepend "~/.local/plugged/nvim-cmp"
vim.opt.runtimepath:prepend "~/.local/plugged/vimtex"
vim.opt.runtimepath:append "~/.local/plugged/cmp-omni/after"
vim.opt.runtimepath:append "~/.local/plugged/vimtex/after"

-- Adjust VimTeX config
vim.g.vimtex_view_method = "zathura"
vim.g.vimtex_syntax_enabled = 0
vim.g.vimtex_quickfix_enabled = 0

-- Setup nvim-cmp
cmp = require("cmp")
cmp.setup {
  sources = cmp.config.sources {
    { name = "omni", },
  },
}

To be clear, the above is a minimal minimal.lua file. You will need to adjust it accordingly, e.g. fix the plugin paths (you probably do not use .local/plugged). If you do, then run nvim --clean -u minimal.lua test.tex, then I believe things should work. Can you check on your side?

lervag avatar Aug 07 '22 09:08 lervag

The problem is you load both nvim_lsp and omni sources which don't play well together (in most cases nvim_lsp prevents omni completions from being shown). I believe this is mentioned in the cmp documentation. For tex files I'd therefore either disable the lsp completions (if you want completions provided by vimtex), or use the completions from the texlab lsp server (which are very good and will give you a similar experience).

HawkinsT avatar Nov 11 '22 01:11 HawkinsT

If @HawkinsT is right, then we either just have to be satisfied with the current behaivour, or possible open an issue for nvim-cmp or cmp-omni to ask if it is possible to make adjustment on that end to allow both omni completion and lsp to work together. In any case, it seems there is nothing I can do on VimTeX side.

lervag avatar Nov 11 '22 07:11 lervag

Relevant issue: https://github.com/hrsh7th/nvim-cmp/issues/833

HawkinsT avatar Nov 11 '22 14:11 HawkinsT

Related, but not directly relevant to the context you provided: "in most cases nvim_lsp prevents omni completions from being shown". Or am I wrong?

lervag avatar Nov 11 '22 14:11 lervag

From what I can see the issue posted here is vimtex omni completions are not working within cmp using the provided config (which has lsp as a completion source), which is the same situation as the linked issue (omni and lsp not working properly together via cmp). With lsp completions through cmp you can still c-x c-o to get the regular omni completion menu with vimtex-provided suggestions in it.

What I realise now though is I don't believe I've tested this outside of omni completions provided by vimtex, so I'm sorry if I was misleading there. Since the issue I linked was closed as lying elsewhere, perhaps it could be an issue with vimtex? I don't have the time to test now, but maybe next week I can see if other omni completions work together with lsp via cmp which would establish if the issue is specific to vimtex or more general.

HawkinsT avatar Nov 11 '22 14:11 HawkinsT

I don't have the time to test now, but maybe next week I can see if other omni completions work together with lsp via cmp which would establish if the issue is specific to vimtex or more general.

I would appreciate if someone (like you) would take the time to do some more thorough testing here. I don't think there is anything wrong with VimTeX's omni completion, but of course, I might be wrong.

lervag avatar Nov 11 '22 18:11 lervag

I've been having related troubles trying to get VimTex + nvim-cmp + cmp-omni to work well in Lua, and have been reading everything I can find to try to sort out the problem. Here are some observations:

  • I don't get VimTex autocompletion for Bibtex sources upon writing \citet{} as expected.
  • I do get VimTex completions via Omni when writing \usepackage{}, so cmp-omni does seem to be working.
  • The VimTex menu also works great, so I can open pdfs while hovering over citations etc.
  • Upon triggering completion with <C-x><C-o> when my cursor is here \citet{|}, I get the following error:
Error detected while processing function vimtex#complete#omnifunc[31]..167[6]..<SNR>107_filter_with_options[19]..<lambda>403:
line    1:
E716: Key not present in Dictionary: "mstr"

I've followed the VimTex help docs and believe that I have it all configured in the right way, and get most of the functionality that I'm looking for, just no access to my .bib file in the autocomplete menu. Here is a MWE branch of my full config (I'm on the Lua branch until I can get full functionality out of VimTex). The same observations given above continue to apply. Any help or pointers about how to test the problem would be greatly appreciated.

NOTE: My config includes some files for tmux, alacrity, etc., so as to provide a complete package for those just starting off (i.e., academics with no experience working with the terminal etc., and so are stuck inside TexShop or Overleaf). I have not removed all of these files from the MWE since I can't imagine they are causing the problem.

benbrastmckie avatar Dec 05 '22 09:12 benbrastmckie

@benbrastmckie Please open a new issue. If you think it is related to an old issue, feel free to link it. If you read this issue and that did not help you to resolve your problem, then your problem is probably something else, in which case it will be helpful to see the standard issue content.

lervag avatar Dec 05 '22 10:12 lervag