hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.86k stars 393 forks source link

cmp-omni listed under unavailable source names #1943

Closed niklashaa closed 4 months ago

niklashaa commented 4 months ago

FAQ

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-omni'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
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 }),
    ["<C-y>"] = cmp.mapping.confirm({ select = true }),
  },

  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "buffer" },
    {
      name = 'omni',
      option = {
        disable_omnifuncs = { 'v:lua.vim.lsp.omnifunc' }
      }
    }
  }),
}
EOF

lua << EOF
local capabilities = require('cmp_nvim_lsp').default_capabilities()

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

Description

neovim version 0.10.0.

Adding cmp-omni results in omni listed under unavailable source names. :CmpStatus outputs the following:

# ready source names
- buffer

# unavailable source names
- omni

# unknown source names
- nvim_lsp

Only modifications to minimal config are: 1) Plug 'hrsh7th/cmp-omni' 2) { name = 'omni' } under sources.

Steps to reproduce

Run nvim with the above config, then run :CmpStatus.

Expected behavior

omni is listed under "ready source names"

Actual behavior

omni is listed under "unavailable source names"

Additional context

I am wondering what the word "unavailable" actually means. When it comes to sources the status I found were 1) ready (Ready to use source) 2) unused (installed source but maybe wrong file type, or not added to sources)? 3) unavailable? 4) unknown (Added to sources but not installed correctly)?

It would be really helpful to have some section in the documentation where those terms are described with potential debugging steps.

Shougo commented 4 months ago

cmp-omni is installed?

niklashaa commented 4 months ago

Plug 'hrsh7th/cmp-omni' should install cmp-omni, right? Is there something else that I should check to see if installation happened?

Shougo commented 4 months ago

I think it is installed under s:plug_dir.

NOTE: Why you use /tmp directory for plugins? It is removed when you reboot the machine.

niklashaa commented 4 months ago

I have pretty much copied the suggested vimrc from this link and added the two mentioned lines.

I think it should be installing all plugins everytime I start up vim with this config.

Shougo commented 4 months ago
if !filereadable(s:plug_dir .. '/plug.vim')

It must be:

if !filereadable(s:plug_dir .. '/autoload/plug.vim')
Shougo commented 4 months ago

I am wondering what the word "unavailable" actually means.

I have read the source code.

It means: the source does not work in current buffer.

Adding cmp-omni results in omni listed under unavailable source names.

Because omnifunc option is not set in current buffer.

Shougo commented 4 months ago

Please read the documentation.

*CmpStatus*
  Describes statuses and states of sources.
  Sometimes `unknown` will be printed - this is expected.
  For example, `cmp-nvim-lsp` registers itself on InsertEnter autocommand
  so the status will be shown as `unknown` when running the command.

I have read the code. The source is only registered when LSP server is configured on the buffer with InsertEnter autocmd.

So it is the feature. The issue should be closed.

niklashaa commented 4 months ago

Thank you for your help @Shougo. You are right, omnifunc is actually working even though it's shown as unavailable in CmpStatus.

Just for reference. This is the final vimrc that I was testing with:

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

if &compatible
  set nocompatible
endif

filetype plugin on
set omnifunc=syntaxcomplete#Complete

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/autoload/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-omni'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
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 }),
    ["<C-y>"] = cmp.mapping.confirm({ select = true }),
  },

  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "buffer" },
    {
      name = 'omni',
      option = {
        disable_omnifuncs = { 'v:lua.vim.lsp.omnifunc' }
      }
    }
  }),
}
EOF

lua << EOF
local capabilities = require('cmp_nvim_lsp').default_capabilities()

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