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

Omni Completion (offset?) issues #652

Closed
2 tasks done
zacmar opened this issue Dec 17, 2021 · 8 comments
Closed
2 tasks done

Omni Completion (offset?) issues #652

zacmar opened this issue Dec 17, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@zacmar
Copy link

zacmar commented Dec 17, 2021

FAQ

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

Issues

  • I have checked existing issues and there are no open or closed issues with the same problem.

Neovim Version

NVIM v0.7.0-dev+717-gf37c5f180a

Minimal reproducible config

init.vim

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-omni'
Plug 'hrsh7th/vim-vsnip'
call plug#end()
PlugInstall | quit

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 = {
    { name = "omni" },
  },
}
EOF

Description

Using the omni source doesn't work as intended.
Consider

import numpy
n|

where | denotes the cursor. This results in
2021-12-17-113249_119x61_scrot
Pressing <C-n> results in

import numpy
umpy.

2021-12-17-113429_135x62_scrot

Steps to reproduce

cat > minimal.py << EOF
import numpy
EOF
nvim -u init.vim minimal.py
on<C-n>

Expected behavior

import numpy
numpy

Actual behavior

import numpy
umpy.

Additional context

I came across this issue when adding the omni source for vimtex. There has been some discussion about offset issues here and here, which might be somehow related.

On a side-note, I have noticed that sometimes (neo)vims built-in omni completion for python outperforms the nvim-lsp source. For instance, when completing function calls, it inserts the ( without me having to type this. Is this in nvim-cmps control, or does this depend entirely on the completion the language server provides?

@zacmar zacmar added the bug Something isn't working label Dec 17, 2021
@hrsh7th
Copy link
Owner

hrsh7th commented Dec 23, 2021

@zacmar Hm... I can't get numpy results from omni source. How to get it?

@jhossbach
Copy link

Here is a working minimal vimrc:
minimal.vim:

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-omni'
call plug#end()
PlugInstall | quit

lua << EOF
local cmp = require "cmp"
cmp.setup {
  mapping = {
    ['<CR>'] = cmp.mapping.confirm(),
    ['<Tab>'] = cmp.mapping(function(callback)
	    if cmp.visible() then
		    cmp.select_next_item()
	    else
		callback()
	    end
	end)
  },

  sources = {
    { name = "omni" },
  },
}
EOF
  • Start writing a .py file with nvim -u minimal.vim test.py.
  • Make sure that :echo &omnifunc returns python3complete#Complete which is located in /usr/share/nvim/runtime/autoload/python3complete.vim
  • try import numpy<Cr>n as shown above, if that doesn't work try import math<Cr>m if numpy is not installed

@jhossbach
Copy link

Here is a small Dockerfile to reproduce this issue:

FROM archlinux

RUN pacman -Syu --noconfirm git python neovim python-neovim

WORKDIR /src/cmp_bug2

COPY ./minimal.vim ./

@jhossbach
Copy link

FYI @hrsh7th: Check out the Deepl Translator for Japanese->English translation, in my experience this provides better translations than the Google translator :)

@hrsh7th
Copy link
Owner

hrsh7th commented Jan 8, 2022

I can reproduce with math|<C-n>.

@jhossbach
Copy link

This fixes the truncation at the beginning, but still adds a dot(.) at the end. Is that intentional?

@hrsh7th
Copy link
Owner

hrsh7th commented Jan 8, 2022

It's specified by python's omnicomplete. I can't fix this sorry.

@jhossbach
Copy link

I see, thanks for the answer!

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