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

Erorr when using keyword_pattern #1170

Closed
2 tasks done
Eternex49 opened this issue Sep 1, 2022 · 2 comments
Closed
2 tasks done

Erorr when using keyword_pattern #1170

Eternex49 opened this issue Sep 1, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@Eternex49
Copy link

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'

Plug 'hrsh7th/cmp-omni'
Plug 'lervag/vimtex'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true })
  },

  sources = cmp.config.sources({
    { name = "omni", keyword_pattern = { vim.g["vimtex#re#neocomplete"] } },
    { name = "nvim_lsp" },
    { name = "buffer" },
  }),
}
EOF

lua << EOF
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())

require'lspconfig'.cssls.setup {
  capabilities = capabilities,
}
EOF

Description

The cmp-omni source is used to get suggestions provided by vimtex.

Ideally, after typing a \cite{ statement, the completion menu should appear with a list of possible bibliographical citations (provided, obviously, by vimtex).
Instead to get the completion menu to appear one has to type at least one character after the \cite{ statement, ie: \cite{a.

To make the completion menu appear without having to type at least one character I've added a keyword pattern to the source. I've used the one provided by vimtex for neocomplete ( vimtex doesn't provide one for cmp, but I think it should work the same):

let g:vimtex#re#neocomplete =
      \ '\v\\%('
      \ .  '%(\a*cite|Cite)\a*\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
      \ . '|%(\a*cites|Cites)%(\s*\([^)]*\)){0,2}'
      \     . '%(%(\s*\[[^]]*\]){0,2}\s*\{[^}]*\})*'
      \     . '%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
      \ . '|bibentry\s*\{[^}]*'
      \ . '|%(text|block)cquote\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
      \ . '|%(for|hy)\w*cquote\*?\{[^}]*}%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
      \ . '|defbibentryset\{[^}]*}\{[^}]*'
      \ . '|\a*ref%(\s*\{[^}]*|range\s*\{[^,}]*%(}\{)?)'
      \ . '|hyperref\s*\[[^]]*'
      \ . '|includegraphics\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*'
      \ . '|%(include%(only)?|input|subfile)\s*\{[^}]*'
      \ . '|([cpdr]?(gls|Gls|GLS)|acr|Acr|ACR)\a*\s*\{[^}]*'
      \ . '|(ac|Ac|AC)\s*\{[^}]*'
      \ . '|includepdf%(\s*\[[^]]*\])?\s*\{[^}]*'
      \ . '|includestandalone%(\s*\[[^]]*\])?\s*\{[^}]*'
      \ . '|%(usepackage|RequirePackage|PassOptionsToPackage)%(\s*\[[^]]*\])?\s*\{[^}]*'
      \ . '|documentclass%(\s*\[[^]]*\])?\s*\{[^}]*'
      \ . '|begin%(\s*\[[^]]*\])?\s*\{[^}]*'
      \ . '|end%(\s*\[[^]]*\])?\s*\{[^}]*'
      \ . '|\a*'
      \ . ')'

Steps to reproduce

  1. Put the following files in a folder:
    test.bib
@article{foo11,
    author={Author A.},
    title={Example article}
}

@book{bar11,
    author={Author B.},
    title={Example book}
}

test.tex

\documentclass{article}
\bibliographystyle{plain}

\begin{document}

This is a citation:
\cite{

\bibliography{./test.bib}
\end{document}
  1. Download vimrc.vim
  2. nvim -u vimrc.vim test.tex
  3. Enter insert mode at the end of the \cite{ line

Expected behavior

After a \cite{ statement, the completion menu should appear suggesting the possible bibliographical citations.

Actual behavior

After positioning at the end of the \cite{ line the completion menu doesn't appear. Typing a letter results in a bunch of errors.

Additional context

No response

@Eternex49 Eternex49 added the bug Something isn't working label Sep 1, 2022
@Shougo
Copy link

Shougo commented Sep 2, 2022

I think neocompletion pattern does not work.
Please see both.

#258
lervag/vimtex#2215

@hrsh7th
Copy link
Owner

hrsh7th commented Sep 2, 2022

Your specified value is wrong.
The keyword_pattern should be string but you specified array.

You should paste error message if you sent bug report.

I think @Shougo's suggestion is correct. In my knowledge, vimtex#re#neocomplete wont work. (but I don't know the reason)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants