Code Monkey home page Code Monkey logo

cmp-nvim-lsp's Introduction

cmp-nvim-lsp

nvim-cmp source for neovim's built-in language server client.

Capabilities

Language servers provide different completion results depending on the capabilities of the client. Neovim's default omnifunc has basic support for serving completion candidates. nvim-cmp supports more types of completion candidates, so users must override the capabilities sent to the server such that it can provide these candidates during a completion request. These capabilities are provided via the helper function require('cmp_nvim_lsp').default_capabilities

As these candidates are sent on each request, adding these capabilities will break the built-in omnifunc support for neovim's language server client. nvim-cmp provides manually triggered completion that can replace omnifunc. See :help cmp-faq for more details.

Setup

require'cmp'.setup {
  sources = {
    { name = 'nvim_lsp' }
  }
}

-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
local capabilities = require('cmp_nvim_lsp').default_capabilities()

-- An example for configuring `clangd` LSP to use nvim-cmp as a completion engine
require('lspconfig').clangd.setup {
  capabilities = capabilities,
  ...  -- other lspconfig configs
}

Option

[%LSPCONFIG-NAME%].keyword_pattern

You can override keyword_pattern for specific language-server like this.

cmp.setup {
  ...
  sources = {
    {
      name = 'nvim_lsp',
      option = {
        php = {
          keyword_pattern = [=[[\%(\$\k*\)\|\k\+]]=],
        }
      }
    }
  }
  ...
}

Readme!

  1. There is a Github issue that documents breaking changes for cmp-nvim-lsp. Subscribe to the issue to be notified of upcoming breaking changes.
  2. This is my hobby project. You can support me via GitHub sponsors.
  3. Bug reports are welcome, but don't expect a fix unless you provide minimal configuration and steps to reproduce your issue.

cmp-nvim-lsp's People

Contributors

afonsocarlos avatar alxhnr avatar hrsh7th avatar jesse-bakker avatar mjlbach avatar numtostr avatar ofseed avatar tjdevries avatar tvercruyssen avatar wookayin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmp-nvim-lsp's Issues

Filter out suggestion based on current typing characters

I'm currently using latest release version of neovim (0.9.0)

I'm follow up this channel to setup lsp servers and completion with nvim-lspconfig, mason-lspconfig.nvim, mason.nvim and nvim-cmp comes up with cmp-nvim-lsp.

The LSP server i've setup is pyright. Current behavior is, when i type down isin, expected by isinstance builtin function in python. but the completion item suggest the np.isinf in the first place in completion menu.

Expected behavior is how to filter out the completion item depends on which user typed, such as the completion items start with isin in the previous examples.

lsp completion items not updating unless I restart the server

I don't think the languages matter and it's probably a general issue, but describing the scenario probably helps you understand.

  1. importing a TypeScript function (translate(key:TranslationKey)) from a Svelte file. TranslationKey being defined like so:type TranslationKey = 'foo' | 'bar'
  2. Trigger completion in svelte file by typing translate('b
  3. cmp correctly suggests bar
  4. update type to type TranslationKey = 'foo' | 'bar'| 'baz'
  5. Trigger completion in svelte file again by typing translate('b
  6. cmp still only suggests 'bar' and not 'baz'
  7. :LspRestart svelte
  8. Trigger completion in svelte file again by typing translate('b
  9. cmp correctly suggests 'bar' and 'baz'

I get the same behavior importing the translation file from an Astro component (*.astro).
So it's not a problem with the Svelte LS.

`#` symbol doesn't start the cmp menu in a CSS property

I'm not 100% sure this is the right place to report this.

Using a minimal configuration nvim-minimal/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/vim-vsnip'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'neovim/nvim-lspconfig'
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 = "nvim_lsp" },
  },
}

local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
local lspconfig = require('lspconfig')
lspconfig.cssls.setup {
  capabilities = capabilities
}
EOF

If I edit a css file with nvim -u nvim-minimal/init.vim style.css, and I'm writing hex colours, previously used colours show as suggestions in the cmp menu. However, I would expect the cmp menu to show up when I type #, but it doesn't:

Screenshot 2023-05-26 at 8 50 12 PM

If I begin writing the colour though, it shows up.

Screenshot 2023-05-26 at 8 50 18 PM

I would expect the # symbol to behave similarly to typing any other matchable character, for example a:

Screenshot 2023-05-26 at 8 58 25 PM
$ nvim --version
NVIM v0.9.0
Build type: Release
LuaJIT 2.1.0-beta3

CmpStatus returns unknown source names: nvim-lsp

When running :CmpStatus, it returns the following:

# ready source names
- emoji
- buffer
- calc
- nvim_lua
- luasnip
- path

# unknown source names
- nvim_lsp <-----------------

I'm wondering why nvim_lsp isn't being registered as a source? I first thought it had something to do with the latest commit on cmp-nvim-lsp but I don't think that's the issue. (I installed the previous commit and got the same error.)

Not sure what I'm doing wrong as the other sources are installed and registered just fine (buffer, luasnip, ...)
I'm happy to provide more details if needed!

Here's some small parts of my config just in case:

-- file: lua/plugins.lua

-- cmp
use({ "hrsh7th/nvim-cmp" })
use({ "hrsh7th/cmp-buffer" })
use({ "hrsh7th/cmp-nvim-lsp" })
use({ "hrsh7th/cmp-nvim-lua" })
use({ "hrsh7th/cmp-path" })
use({ "hrsh7th/cmp-calc" })
use({ "hrsh7th/cmp-emoji" })
use({ "saadparwaiz1/cmp_luasnip" })

-- LSP
use("neovim/nvim-lspconfig")
use("kabouzeid/nvim-lspinstall")
-- file: plugin/nvim-cmp.lua

local luasnip = require("luasnip")
local cmp = require("cmp")

cmp.setup({
	snippet = {
		expand = function(args)
			require("luasnip").lsp_expand(args.body)
		end,
	},
	mapping = {
		["<C-p>"] = cmp.mapping.select_prev_item(),
		["<C-n>"] = cmp.mapping.select_next_item(),
		["<C-d>"] = cmp.mapping.scroll_docs(-4),
		["<C-f>"] = cmp.mapping.scroll_docs(4),
		["<C-Space>"] = cmp.mapping.complete(),
		["<C-e>"] = cmp.mapping.close(),
		["<CR>"] = cmp.mapping.confirm({
			behavior = cmp.ConfirmBehavior.Replace,
			select = true,
		}),
		["<Tab>"] = function(fallback)
			if vim.fn.pumvisible() == 1 then
				vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<C-n>", true, true, true), "n")
			elseif luasnip.expand_or_jumpable() then
				vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "")
			else
				fallback()
			end
		end,
		["<S-Tab>"] = function(fallback)
			if vim.fn.pumvisible() == 1 then
				vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<C-p>", true, true, true), "n")
			elseif luasnip.jumpable(-1) then
				vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-jump-prev", true, true, true), "")
			else
				fallback()
			end
		end,
	},
	sources = {
		{ name = "nvim_lsp" },
		{ name = "nvim_lua" },
		{ name = "luasnip" },
		{ name = "buffer" },
		{ name = "path" },
		{ name = "calc" },
		{ name = "emoji" },
	},
})

Option to exclude a client completely

As the title says. The specific use case for me is that I don't want emmet_ls to be in the suggestions. I'm already communicating with it directly with a custom trigger.

Of course it would be possible to just filter results via entry_filter option, but I think it will be slightly better to not send requests to the server at all.

Example config would be:

require("cmp_nvim_lsp").setup({ exclude_client = { "emmet_ls" } })

Cause lags / delay with Telescope & UI

Hi,

I just figured out cmp-nvim-lsp is causing some lags / delay when closing telescope or some UI components.
I tried to disable all of my plugins, and the only one I need to disable for the lags to disappear is cmp-nvim-lsp. So with all of my plugins except cmp-nvim-lsp I have no lags / delay.

Please see :

With cmp-nvim-lsp :
Screencast from 05-01-2023 15_04_28

Without cmp-nvim-lsp :
Screencast from 05-01-2023 15_06_25

Neovim version :

NVIM v0.9.0-dev-620+g19591e991
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

CMP config :

local cmp = require("cmp")

if not cmp then
	return
end

local luasnip = require("luasnip")

if not luasnip then
	return
end

local lspkind = require("lspkind")

if not lspkind then
	return
end

local luasnip_vscode_loader = require("luasnip/loaders/from_vscode")

if not luasnip_vscode_loader then
	return
end

luasnip_vscode_loader.lazy_load()

local check_backspace = function()
	local col = vim.fn.col(".") - 1
	return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
end

cmp.setup({
	sorting = {
		comparators = {
			cmp.config.compare.offset,
			cmp.config.compare.exact,
			cmp.config.compare.recently_used,
			require("clangd_extensions.cmp_scores"),
			cmp.config.compare.kind,
			cmp.config.compare.sort_text,
			cmp.config.compare.length,
			cmp.config.compare.order,
		},
	},
	snippet = {
		expand = function(args)
			luasnip.lsp_expand(args.body)
		end,
	},
	mapping = {
		["<C-k>"] = cmp.mapping.select_prev_item(),
		["<C-j>"] = cmp.mapping.select_next_item(),
		["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
		["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
		["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
		["<C-y>"] = cmp.config.disable,
		["<C-e>"] = cmp.mapping({
			i = cmp.mapping.abort(),
			c = cmp.mapping.close(),
		}),
		["<CR>"] = cmp.mapping.confirm({ select = true }),
		["<Tab>"] = cmp.mapping(function(fallback)
			if cmp.visible() then
				cmp.select_next_item()
			elseif luasnip.expandable() then
				luasnip.expand()
			elseif luasnip.expand_or_jumpable() then
				luasnip.expand_or_jump()
			elseif check_backspace() then
				fallback()
			else
				fallback()
			end
		end, {
			"i",
			"s",
		}),
		["<S-Tab>"] = cmp.mapping(function(fallback)
			if cmp.visible() then
				cmp.select_prev_item()
			elseif luasnip.jumpable(-1) then
				luasnip.jump(-1)
			else
				fallback()
			end
		end, {
			"i",
			"s",
		}),
	},
	formatting = {
		fields = { "kind", "abbr", "menu" },
		format = lspkind.cmp_format({
			mode = "symbol", -- show only symbol annotations
			maxwidth = 50,
			before = function(entry, vim_item)
				vim_item.menu = ({
					nvim_lsp = "[LSP]",
					luasnip = "[Snippet]",
					buffer = "[Buffer]",
					path = "[Path]",
				})[entry.source.name]
				return vim_item
			end,
		}),
	},
	sources = {
		{ name = "nvim_lsp" },
		{ name = "luasnip" },
		{ name = "buffer" },
		{ name = "path" },
	},
	confirm_opts = {
		behavior = cmp.ConfirmBehavior.Replace,
		select = false,
	},
	window = {
		completion = cmp.config.window.bordered(),
		documentation = cmp.config.window.bordered(),
	},
	experimental = {
		ghost_text = false,
		native_menu = false,
	},
})

cmp.setup.cmdline("/", {
	mapping = cmp.mapping.preset.cmdline(),
	sources = {
		{ name = "buffer" },
	},
})

-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(":", {
	mapping = cmp.mapping.preset.cmdline(),
	sources = cmp.config.sources({
		{ name = "path" },
	}, {
		{ name = "cmdline" },
	}),
})

Plugins :

local fn = vim.fn

-- Automatically install packer
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
	--luacheck: ignore PACKER_BOOTSTRAP
	PACKER_BOOTSTRAP = fn.system({
		"git",
		"clone",
		"--depth",
		"1",
		"https://github.com/wbthomason/packer.nvim",
		install_path,
	})
	print("Installing packer close and reopen Neovim...")
	vim.cmd([[packadd packer.nvim]])
end

-- Autocommand that reloads neovim whenever you save the packer.lua file
vim.cmd([[
 augroup packer_user_config
 autocmd!
 autocmd BufWritePost packer.lua source <afile> | PackerSync
 augroup end
 ]])

local packer = require("packer")

-- Have packer use a popup window
packer.init({
	display = {
		open_fn = function()
			return require("packer.util").float({ border = "rounded" })
		end,
	},
})

return packer.startup(function(use)
	-- Package manager
	use("wbthomason/packer.nvim")

	-- Performance
	use("lewis6991/impatient.nvim")

	-- Lsp & Dap Managers
	use("williamboman/mason.nvim")
	use({ "jayp0521/mason-nvim-dap.nvim" })
	use("williamboman/mason-lspconfig.nvim")

	-- Colorscheme
	use({ "catppuccin/nvim", as = "catppuccin" })

	-- File explorer
	use({ "kyazdani42/nvim-tree.lua", requires = { { "kyazdani42/nvim-web-devicons" } }, tag = "nightly" })

	-- Buffer and status lines
	use({ "nvim-lualine/lualine.nvim", requires = { { "nvim-tree/nvim-web-devicons" } } })

	-- Fidget
	use("j-hui/fidget.nvim")

	use({
		"utilyre/barbecue.nvim",
		branch = "dev", -- omit this if you only want stable updates ]]
		requires = {
			"neovim/nvim-lspconfig",
			"smiteshp/nvim-navic",
			"nvim-tree/nvim-web-devicons", -- optional dependency
		},
		after = { "catppuccin", "nvim-web-devicons" }, -- keep this if you're using NvChad
	})

	-- Treesitter
	use({
		"nvim-treesitter/nvim-treesitter",
		requires = {
			{ "windwp/nvim-ts-autotag" },
			{ "nvim-treesitter/nvim-treesitter-textobjects" },
			{ "p00f/nvim-ts-rainbow" },
		},
		run = ":TSUpdate",
	})

	-- Telescope
	use({ "nvim-telescope/telescope.nvim", requires = { { "nvim-lua/plenary.nvim" } } })
	use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make" })

	-- UI
	use("stevearc/dressing.nvim")

	--Formatter
	use("jayp0521/mason-null-ls.nvim")
	use("jose-elias-alvarez/null-ls.nvim")
	use({
		"ThePrimeagen/refactoring.nvim",
		requires = {
			{ "nvim-lua/plenary.nvim" },
			{ "nvim-treesitter/nvim-treesitter" },
		},
		ft = { "lua", "python " },
	})

	-- Easy jump
	use({ "phaazon/hop.nvim", branch = "v2" })

	-- Http client
	use({ "rest-nvim/rest.nvim", requires = { { "nvim-lua/plenary.nvim" } } })

	-- Terminal toggle
	use({ "akinsho/toggleterm.nvim", tag = "*" })

	-- Auto close pairs
	use("windwp/nvim-autopairs")

	-- Surround
	use("kylechui/nvim-surround")

	-- Comments
	use("numToStr/Comment.nvim")
	use("JoosepAlviste/nvim-ts-context-commentstring")

	-- Debugger
	use({ "rcarriga/nvim-dap-ui", requires = { "mfussenegger/nvim-dap" } })
	use("theHamsta/nvim-dap-virtual-text")

	-- Rust tools
	use({
		"simrat39/rust-tools.nvim",
		requires = { { "nvim-lua/plenary.nvim" } },
	})

	-- Python
	use({ "luk400/vim-jukit" })

	-- Clang extensions
	use("p00f/clangd_extensions.nvim")

	-- Git
	use("lewis6991/gitsigns.nvim")
	use("sindrets/diffview.nvim")
	use("tpope/vim-fugitive")

	-- Completion
	use("hrsh7th/nvim-cmp")
	use("hrsh7th/cmp-buffer")
	use("hrsh7th/cmp-path")
	use("hrsh7th/cmp-cmdline")
	use("saadparwaiz1/cmp_luasnip")
	use("hrsh7th/cmp-nvim-lsp")
	use("hrsh7th/cmp-nvim-lua")
	use("rafamadriz/friendly-snippets")
	use({ "L3MON4D3/LuaSnip", tag = "v1.*" })
	use("onsails/lspkind.nvim")

	-- LSP
	use({
		"ray-x/lsp_signature.nvim",
	})
	use("neovim/nvim-lspconfig")
	use({ "b0o/schemastore.nvim", ft = { "json" } })
	use("jose-elias-alvarez/typescript.nvim")
	use("lvimuser/lsp-inlayhints.nvim")

	-- Utils
	use("lukas-reineke/indent-blankline.nvim")
	use("abecodes/tabout.nvim")
	use("max397574/better-escape.nvim")
	use({ "ellisonleao/glow.nvim", ft = { "md" } })
	use("sitiom/nvim-numbertoggle")
	use("rcarriga/nvim-notify")
	use("ethanholz/nvim-lastplace")
	use("dstein64/vim-startuptime")
	use("chrisbra/Colorizer")

	-- Screenshot
	use({ "krivahtoo/silicon.nvim", run = "./install.sh build" })

	if PACKER_BOOTSTRAP then
		require("packer").sync()
	end
end)

I don't know how to provide more usefull logs / trace but if you tell me I'll try to.

Confirmation behavior `Insert` does not work

Hi,

Whatever the value for beavior otption of cmp.mapping.confirm the text under the cursor is replaced.

require'cmp'.setup {
...
  mapping = {
    ['<C-p>'] = cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Select}),
    ['<C-n>'] = cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Select}),
    ['<CR>'] = cmp.mapping.confirm({select = false, behavior=cmp.ConfirmBehavior.Insert}),
  }
}

This seems conform to the documentation

Thank you very much

cmp_nvim_lsp module not found

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

Can't find cmp_nvim_lsp module, error coming from the require method.

I have cmp installed with all relevant extensions, yet it yields the same result wherever I try to place these lines (lspconfig.lua file or in seperate lsp configuration files).

Cannot disable completion for a specified client

I use a language server for which I want to disable the most of capabilities (it's too slow on some projects). Currently it does not disable any capability given restricted set of capabilities on initialization.

I noticed that restricting client.resolved_capabilities within on_attach can also prevent from using some method of client but completion is an exception.

Shouldn't source:is_available() return false if self.client.resolved_capabilities.completion is false?

entry_filter has no effect

The entry_filter has been incorporated into the configuration to facilitate Text data filtering.
image
The thing is, text data still pops up while using it.
image

  • Windows
  • powershell7/neovide
  • neovim version: 0.9.2

keyword_length option for other sources

Hi there,

Again, thank you for all your work on this plugin. A while ago you kindly fixed an issue I raised here

hrsh7th/nvim-cmp#444

I was wondering how difficult it would be to add this sort of feature to other sources? Like nvim-lsp or latex-symbols for example?

Thanks again!

Error thrown when using omnicompletion

With the following plugins installed:

  • L3MON4D3/LuaSnip
  • hrsh7th/cmp-nvim-lsp
  • hrsh7th/nvim-cmp
  • neovim/nvim-lspconfig
  • saadparwaiz1/cmp_luasnip

And an init.lua of:

local cmp = require("cmp")
local lspconfig = require("lspconfig")

-- set only to present the error unobscured
vim.opt.pumheight = 10

cmp.setup({
  snippet = {
    expand = function(args)
      require("luasnip").lsp_expand(args.body)
    end,
  },
  mapping = cmp.mapping.preset.insert(),
  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "luasnip" },
  }),
})

local capabilities = require("cmp_nvim_lsp").default_capabilities()

lspconfig.tsserver.setup({ capabilities = capabilities })

I can trigger an error by running this sequence:

  • nvim a.js
  • id<C-x><C-o>

In other words, open a JavaScript file and type id to go to insert mode and add 'd' to the buffer. This triggers nvim-cmp's completion menu to appear. If you follow up with Ctrl-x Ctrl-o to trigger omnicompletion then the error throws like below. It seems to be triggered by passing on capabilities to the client from cmp-nvim-lsp.

Screenshot 2023-04-15 at 17 52 24

And in text to help for searching issues:

Error executing vim.schedule lua callback: /opt/local/share/nvim/runtime/lua/vim/lsp.lua:2087: attempt to in
dex field 'range' (a nil value)
stack traceback:
        /opt/local/share/nvim/runtime/lua/vim/lsp.lua:2087: in function 'adjust_start_col'
        /opt/local/share/nvim/runtime/lua/vim/lsp.lua:2163: in function 'handler'
        /opt/local/share/nvim/runtime/lua/vim/lsp.lua:1394: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
$ nvim --version
NVIM v0.9.0
Build type: Release
LuaJIT 2.1.0-beta3

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/local/share/nvim"

Run :checkhealth for more info

How to cycle through autocompletion options?

I have this config:

require'cmp'.setup {
  sources = {
    { name = 'nvim_lsp' }
  }
}

local custom_attach = function(client, bufnr)
 -- this code gets executed when a language server is attached to a buffer
 -- you can add your keybindings and commands here.
end

-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

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


vim.cmd [[packadd packer.nvim]]
require('packer').startup(function(use)
	use 'wbthomason/packer.nvim'
	use 'neovim/nvim-lspconfig'
end)

require'lspconfig'.pyright.setup {
  on_attach = custom_attach,
  capabilities = capabilities
}

require'lspconfig'.pyright.setup {
  on_attach = custom_attach,
  capabilities = capabilities
}
require'lspconfig'.rust_analyzer.setup {
  on_attach = custom_attach,
  capabilities = capabilities
}

it's using lspconfig. I can see the lsp autocompletion options but I'm not able to cycle through or select them. Hitting tab inserts a space character and ctrl-n or ctrl-p opens the vim autocomplete.

Lazy loading II

Hey @hrsh7th,

sorry to continue on this thread hrsh7th/nvim-cmp#65 (comment) I know you're not a huge fan, but I was looking through the code base and it looks like if you defer requiring cmp till it's needed in the insert_enter function then actually this plugins dependency on cmp will be delayed.

So rather than requiring cmp here

local cmp = require('cmp')

You can move the require to

M._on_insert_enter = function()

and this will defer the require till insert enter which will allow lazy loading to work.

Tbh is seems to be good practice to delay deferring requires till the point where they are needed so that just requiring a module doesn't immediately trigger a bunch of requires anyway

LSP suggestions don't appear in certain files, although LS loaded

Steps to reproduce:

In both cases :LspInfo shows that the correct clients are attached to the buffer. Tried with both vsnip and luasnip.
I'm opening the ticket here as this is my best guess, not sure how to debug further.

Help is much appreciated!

:LspInfo output

Error detected: ...attempt to call field 'is_closing'

Hey! I'm using the basic template setup from https://github.com/LunarVim/Neovim-from-scratch which uses cmp-nvim-lsp and sumneko_lua LSP-server. I have not modified anything else from the template other than pinned some newer versions for nvim-treesitter and some other plugins. I am getting this error with every single inserted character in lua files:

neovim_error2

Running command ":lua =vim.lsp.get_active_clients({ filter = { name = "sumneko_lua " }})[1].is_stopped()" returns false so I guess the LSP-server should be working fine. Using newest pre-release NeoVim v0.8.0-1183-ge6c214033 on Windows and newest cmp-nvim-lsp.

Any ideas what this could be caused by?

<CR> issues on some servers

  • On pylsp, pressing enter on selected option didn't autocomplete the parentheses or any function snippets
recording.mp4
  • On dartls, pressing enter inside parentheses trigger the first completion item even if no option is selected, instead of creating a new line
recording.mp4

Both are working on compe

Please explain 'The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..'

-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

-- The following example advertise capabilities to `clangd`.
require'lspconfig'.clangd.setup {
  capabilities = capabilities,
}

I don't think the user should be expected to understand exactly how the LSP server in Neovim works to use it. Please could you add a paragraph to explain what is going on here and more detail on how and where to add this code?

For example, what if I don't have a snippet plugin installed and this tells the server that nvim-cmp accepts snippets? Is that a problem, or is all that automated in the latest feat: Make setup easier patch?

  • Why is it needed? nvim-cmp seems to be working in all LSP servers I have tried without this setting, it is very mysterious. Will I be missing certain features not using it?
  • How about if my nvim-cmp settings are in a different file to my general LSP settings, where should the above code go?

Sorry, please assume that users are just coming from VS Code and want things to work with as few settings as possible :) Thanks!

lspconfig default_capabilities not working

-- Setup lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilites()
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
require('lspconfig')['clangd'].setup {
capabilities = capabilities
}

This is the code used to setup clangd for c++, and when I open up neovim, I get error loading chunk message with that block of code, but without it I don't get any error.

CSS (cssls) AutoCompletion not working

Hi there,
first of all thank you for work! I love your plugins, but recently I ran into a problem.
The completion in .css or .scss files stopped working. The linting works, but the completion does not.
In comparison everything works fine with .ts files. Linting and completion.

I spent some hours now trying to figure out whats wrong, but to no success.

I should provide some context.
Also, I am not totally new to NeoVim configuration, but far from an expert.

What I tried without success

  • Updating NeoVim (Currently I am at 0.6)
  • Looked for similiar issues from other people
  • Removed and ReSynced Packer packages
  • Various re-ordering and refactoring of code lines related to this issue

Context

  • For the example here I used a scss file, but the same problem remains with css files
  • For LSP installation I use lsp-installer
Config

Screenshots

tsserver

:CmpStatus

nvim_tsserver_cmp-status

:LspInfo

nvim_tsserver_lspinfo

cssls

:CmpStatus

nvim_css_cmpstatus

:LspInfo

nvim_css_lspinfo

Lsp server complain errors when use cmp-nvim-lsp

I'm getting a lot of the errors when complete from lsp. I don't know if it is normal phenomenon, but it not appears when I was using nvim-compe.

rust.mp4

When I complete from cmp-nvim-lsp in Rust, it complains

[ ERROR ] 2021-08-26T16:44:14+0800 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"rust-analyzer"	"stderr"	'[ERROR rust_analyzer::dispatch] unknown request: Request { id: RequestId(I32(18)), method: "workspace/executeCommand", params: Null }\n'
clangd.mp4

Same situation with clangd, but more frequent.

lua.mp4

Same situation with lua-language-server.

Here are my environment and config

  • Archlinux 5.13.12-arch1-1
  • NVIM v0.5.0 Build type: Release
  • nvim-cmp config:
    use {
        'hrsh7th/nvim-cmp', -- Autocompletion plugin
        requires = {
            -- LSP source for nvim-cmp
            {'hrsh7th/cmp-nvim-lsp', after = 'nvim-cmp'},
            -- path source for nvim-cmp
            {'hrsh7th/cmp-path', after = 'nvim-cmp'},
            -- Snippets source for nvim-cmp
            {'saadparwaiz1/cmp_luasnip', after = 'nvim-cmp'},
            -- lua source for nvim-cmp
            {'hrsh7th/cmp-nvim-lua', after = 'nvim-cmp'},

            {'hrsh7th/cmp-buffer', after = 'nvim-cmp'}, -- buffer source for nvim-cmp
            -- {'tzachar/cmp-tabnine', run = './install.sh', after = 'nvim-cmp'}
        },
        config = function()
            local cmp = require('cmp')
            local luasnip = require('luasnip')
            local lspkind = require('lspkind')
            cmp.setup {
                snippet = {
                    expand = function(args)
                        require('luasnip').lsp_expand(args.body)
                    end
                },

                -- You must set mapping if you want.
                mapping = {
                    ['<C-n>'] = cmp.mapping.select_next_item(),
                    ['<C-p>'] = cmp.mapping.select_prev_item(),
                    ['<C-d>'] = cmp.mapping.scroll_docs(4),
                    ['<C-f>'] = cmp.mapping.scroll_docs(-4),
                    ['<Tab>'] = cmp.mapping(function(fallback)
                        if vim.fn.pumvisible() == 1 then
                            vim.fn.feedkeys(
                                vim.api.nvim_replace_termcodes('<C-n>', true,
                                                               true, true), 'n')
                        elseif luasnip.expand_or_jumpable() then
                            vim.fn.feedkeys(
                                vim.api.nvim_replace_termcodes(
                                    '<Plug>luasnip-expand-or-jump', true, true,
                                    true), '')
                        else
                            fallback()
                        end
                    end, {'i', 's'}),
                    ['<S-Tab>'] = cmp.mapping(function(fallback)
                        if vim.fn.pumvisible() == 1 then
                            vim.fn.feedkeys(
                                vim.api.nvim_replace_termcodes('<C-p>', true,
                                                               true, true), 'n')
                        elseif luasnip.jumpable(-1) then
                            vim.fn.feedkeys(
                                vim.api.nvim_replace_termcodes(
                                    '<Plug>luasnip-jump-prev', true, true, true),
                                '')
                        else
                            fallback()
                        end
                    end, {'i', 's'})
                },

                -- You should specify your *installed* sources.
                sources = {
                    {name = 'buffer'}, --
                    -- {name = 'cmp-tabnine'}, --
                    {name = 'luasnip'}, --
                    {name = 'nvim_lsp'}, --
                    {name = 'nvim_lua'}, --
                    {name = 'path'} --
                },
                completion = {completeopt = 'menu,menuone,noinsert'},
                formatting = {
                    format = function(entry, vim_item)
                        vim_item.kind =
                            lspkind.presets.default[vim_item.kind] .. ' ' ..
                                vim_item.kind
                        return vim_item
                    end
                }
            }
        end
    } -- }}}
    use {'L3MON4D3/LuaSnip'} -- Snippets plugin
    use {'onsails/lspkind-nvim'}
  • lspconfig:
    use {
        'neovim/nvim-lspconfig',
        after = 'cmp-nvim-lsp',
        config = function()
            local config = require("lspconfig")

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

            config.sumneko_lua.setup({
                cmd = {"lua-language-server"},
                settings = {
                    Lua = {
                        diagnostics = {
                            -- Get the language server to recognize the `vim` global
                            globals = {"vim"}
                        },
                        workspace = {
                            -- Make the server aware of Neovim runtime files
                            library = vim.api.nvim_get_runtime_file("", true)
                        },
                        -- Do not send telemetry data containing a randomized but unique identifier
                        telemetry = {enable = false}
                    }
                }
            })

            local servers = {'clangd', 'rust_analyzer', 'vimls'}
            for _, lsp in ipairs(servers) do
                config[lsp].setup {
                    -- on_attach = my_custom_on_attach,
                    capabilities = capabilities
                }
            end
        end
    } -- }}}

more verbose is here.

Sometimes autocompletion not triggered on rust-analyzer

nvim-cmp doesn't trigger autocompletion properly on rust-analyzer. Forcing it manually using cmp.mapping.complete() also didn't work

recording.mp4

I think this is nvim-cmp fault because, for example, here's on nvim-compe

recording.mp4

Does not show the full list.

Hi.
Sorry, but I do not know if this bug belongs here.
Using C++, sometimes does not show the full list, so I have to press Ctrl + spacebar and then shows everything.

Does not show "SDL_GetTicks()"
image

Then I press Ctrl + Spacebar
image

Won't send more requests if **one** character no completions.

Some LSPs do not autocomplete when typing a single character because it would generate too much noise. They only autocomplete when there are two characters, which causes issues for cmp. When cmp detects an empty table for autocompletion of a character, it does not send more requests after the document has been changed.

For example:

When I type S, LSP has no completions, so I continue typing t, normally cmp should send a new request, but it won't, so no completions too.

How to install cmp-nvim-lsp

hey, i seem to cant be installing cmp_nvim_lsp
here is the error
Error detected while processing InsertEnter Autocommands for "*": Error executing lua callback: ...pack\packer\start\cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:96: module 'cmp' not found: no field package.preload['cmp'] no file '.\cmp.lua' no file 'C:\ProgramData\Scoop\apps\neovim\current\bin\lua\cmp.lua' no file 'C:\ProgramData\Scoop\apps\neovim\current\bin\lua\cmp\init.lua' no file '.\cmp.dll' no file 'C:\ProgramData\Scoop\apps\neovim\current\bin\cmp.dll' no file 'C:\ProgramData\Scoop\apps\neovim\current\bin\loadall.dll' stack traceback: [C]: in function 'require' ...pack\packer\start\cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:96: in function <...pack\packer\start\cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:95>

If You Need my config files like init.lua and stuff comment here

gopls lsp not happy with completionList.itemDefaults

completionList.itemDefaults appears to have been added in commit 91050df7b3.

This change is causing the following error when using gopls lsp:

Error executing vim.schedule lua callback: ...w/Cellar/neovim/0.8.1/share/nvim/runtime/lua/vim/lsp.lua:1278:
RPC[Error] code_name = ParseError, message = "JSON RPC parse error: json: cannot unmarshal object into Go struct field PCompletionListPCompletion.capabilities.textDocument.completion.completionList.itemDefaults of type []string"
stack traceback:
        [C]: in function 'assert'
        ...w/Cellar/neovim/0.8.1/share/nvim/runtime/lua/vim/lsp.lua:1278: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

nvim-cmp selection jumps to options with this source enabled (only with rust-analyzer?)

Current Behavior

When the nvim_lsp nvim-cmp source is enabled, the selection in the nvim-cmp menu will jump to options supplied by rust-analyzer server. If this source isn't enabled, nothing is selected until trigger cmp.select_next_item().

Expected behavior

Nothing is selected in the nvim-cmp menu until I trigger cmp.select_next_item() or cmp.select_prev_item().

Steps to reproduce

  1. Enable nvim_lsp source:
cmp.setup({
    sources = {
        { name = "nvim_lsp" },
    },
})
  1. Install rust-anaylzer and set up Neovim to use it
  2. Open a Rust file
  3. Start typing

Additional information

I'm not having this problem with other language servers. I've tested sumneko_lua and pyright. This what I have for setting up my LSP servers, and I install them with nvim-lsp-installer:

lsp_installer.setup({})

lspconfig.util.default_config = vim.tbl_extend("force", lspconfig.util.default_config, {
    on_attach = on_attach,
})

for _, server in ipairs(lsp_installer.get_installed_servers()) do
    lspconfig[server.name].setup({})
end

I've managed to reproduce this with a very minimal nvim-cmp configuration:

local cmp = require("cmp")
cmp.setup({
    sources = {
        { name = "nvim_lsp" },
})

Videos

With nvim_lsp source:

with_nvim_lsp_source.mp4

Without nvim_lsp source:

without_nvim_lsp_source.mp4

How to install cmp-nvim-lsp

Hi,

I am using the pack approach to installing plugins. I've cloned this repo in

$XDG_CONFIG_HOME/nvim/pack/utils/start/cmp-nvim-lsp

However, importing the plugin in init.lua fails

lua << EOF
...
local capabilities = require('cmp-nvim-lsp')
...
EOF

with

Error detected while processing $XDG_CONFIG_HOME/nvim/init.vim:
line   68:
E5108: Error executing lua [string ":lua"]:4: module 'cmp-nvim-lsp' not found:
        no field package.preload['cmp-nvim-lsp']
        no file './cmp-nvim-lsp.lua'
        no file '/usr/share/lua/5.1/cmp-nvim-lsp.lua'
        no file '/usr/share/lua/5.1/cmp-nvim-lsp/init.lua'
        no file '/usr/lib64/lua/5.1/cmp-nvim-lsp.lua'
        no file '/usr/lib64/lua/5.1/cmp-nvim-lsp/init.lua'
        no file '/usr/share/lua/5.1/cmp-nvim-lsp.lua'
        no file '/usr/share/lua/5.1/cmp-nvim-lsp/init.lua'
        no file './cmp-nvim-lsp.so'
        no file '/usr/lib64/lua/5.1/cmp-nvim-lsp.so'
        no file '/usr/lib64/lua/5.1/cmp-nvim-lsp.so'
        no file '/usr/lib64/lua/5.1/loadall.so'

Question about default_capabilities

Hello ๐Ÿ‘‹ Just upgraded my setup and found the change about client capabilities.

All examples look like this:

-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
local capabilities = require('cmp_nvim_lsp').default_capabilities()

-- The following example advertise capabilities to `clangd`.
require'lspconfig'.clangd.setup {
  capabilities = capabilities,
}

Doesn't that mean that I not consider all other capabilities, that nvim has?

Maybe something like this would be better:

local capabilities = vim.lsp.protocol.make_client_capabilities()
local cmp_capabilities = require("cmp_nvim_lsp").default_capabilities()
capabilities.textDocument.completion = cmp_capabilities.textDocument.completion

How to show "Auto import from ..." in the documentation window?

Hi!

The problem

I remember that some time ago (a long time ago), with the typescript-language-server, I could see the auto import source in the documentation window when selecting a completion item, kinda like this:

image

But now, the floating documentation window isn't even shown if there is no documentation part and the "Auto import from ..." text is also not shown:

image

image

So if I have multiple items with the same name that I could import, I don't know exactly which one I should choose.

Workaround

I did some digging and found that the importing text comes from the detail field whereas the documentation comes from documentation.value and documentation.value is the only field used in the documentation window:

image

I found that I could modify the source.resolve function in this plugin here: https://github.com/hrsh7th/cmp-nvim-lsp/blob/main/lua/cmp_nvim_lsp/source.lua#L85 in a dumb way like so:

  self:_request('completionItem/resolve', completion_item, function(_, response)
    response.documentation = response.documentation or {
      kind = 'markdown',
      value = '',
    }
    local auto_import, rest = string.match(response.detail, "(Auto import from '[^']+')\n(.*)")
    if auto_import and rest then
      response.documentation.value = auto_import .. '\n\n' .. rest .. '\n\n' .. response.documentation.value
    end
    callback(response or completion_item)
  end)

Resulting in pretty much exactly what I'd like to have (it would be cool to have syntax highlighting for the TypeScript type information):

image

image

Question

I was wondering if there was a way to accomplish this without modifying the source code of this plugin by some configuration option? Maybe I'm missing something from the docs?

Sorry if this is a very TypeScript language server specific issue, I wasn't really sure where to post this. Please let me know if there is a more suitable place for me to ask this question.

Using 'update_capabilities' function in neovim 7.2 is a breaking change

Hi!

Firstly, thanks to all your hard work making these cmp plugins. They are a huge boost to developer workflow in Neovim!

So, I just did PackerSync (because it's the weekend) and got the latest updates. I am still on neovim 0.7.2, but I imagine this works fine on 0.8.0.

Before updating my config to use the new default_capabilities function, I get this error:

E5113: Error while calling lua chunk: ...pack/packer/start/cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:51: attempt to call field 'deprecate' (a nil value)
stack traceback:
        ...pack/packer/start/cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:51: in function 'update_capabilities'

It might be worth mentioning this in a breaking changes section somewhere, or using a backwards compatible way of telling the use that this function is deprecated.

Error no file found although it should be installed

Although my init.lua (attached as txt) contains the require('cmp_nvim_lsp') I get the following error

no file './cmp_nvim_lsp.lua' no file '/home/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1.0-beta3/cmp_nvim_lsp.lua' no file '/usr/local/share/lua/5.1/cmp_nvim_lsp.lua' no file '/usr/local/share/lua/5.1/cmp_nvim_lsp/init.lua' no file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/cmp_nvim_lsp.lua' no file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/cmp_nvim_lsp/init.lua' no file './cmp_nvim_lsp.so' no file '/usr/local/lib/lua/5.1/cmp_nvim_lsp.so' no file '/home/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/cmp_nvim_lsp.so' no file '/usr/local/lib/lua/5.1/loadall.so'
init.lua.txt

Disable default LSP snippets

Screenshot from 2022-07-26 22-44-53

I can't seem to disable default LSP snippets.
I've tried using the config below to no avail

  for _,server in ipairs(lspinstaller.get_installed_servers()) do
    local opts = {
      on_attach = on_attach,
      capabilities = cmp_nvim_lsp.update_capabilities(
        vim.lsp.protocol.make_client_capabilities(),
        { snippetSupport = false }
      ),
      flags = {
        debounce_text_changes = 150
      }
    }

    local ok,config = pcall(require, 'lsp.config' .. '.' .. server.name)
    if not ok then
      config = {}
      print(server.name .. ' not found in lsp/config. Setting up defaults.')
    else
      print(' - ' .. server.name .. ' has been configuredl!')
    end

    lspconfig[server.name].setup( vim.tbl_deep_extend('force', config, opts) )
  end

But if I inspect server capability I can see that snippetSupport is definitely have been set to false

{
  capabilities = {
    callHierarchy = {
      dynamicRegistration = false
    },
    textDocument = {
      codeAction = {
        codeActionLiteralSupport = {
          codeActionKind = {
            valueSet = { "", "Empty", "QuickFix", "Refactor", "RefactorExtract", "RefactorInline", "RefactorRewrite", "Source", "SourceOrganizeImports", "quickfix", "refactor", "refactor.extract
", "refactor.inline", "refactor.rewrite", "source", "source.organizeImports" }
          }
        },
        dataSupport = true,
        dynamicRegistration = false,
        isPreferredSupport = true,
        resolveSupport = {
          properties = { "edit" }
        }
      },
      completion = {
        completionItem = {
          commitCharactersSupport = true,
          deprecatedSupport = true,
          documentationFormat = { "markdown", "plaintext" },
          insertReplaceSupport = true,
          labelDetailsSupport = true,
          preselectSupport = true,
          resolveSupport = {
            properties = { "documentation", "detail", "additionalTextEdits" }
          },
          snippetSupport = false,
          tagSupport = {
            valueSet = { 1 }
          }
        },
        completionItemKind = {
          valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }
        },
        contextSupport = false,
        dynamicRegistration = false
      },
      declaration = {
        linkSupport = true
      },
      definition = {
        linkSupport = true

Unknown Source Names - nvim_lsp

Hi there, I am struggling to install the plugin and have tried a few differnet ways. Each time if I run :CmpStatus the nvim_lsp plugin is listed as an unknown source.

local on_windows = vim.loop.os_uname().version:match 'Windows'

local function join_paths(...)
  local path_sep = on_windows and '\\' or '/'
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.cmd [[set runtimepath=$VIMRUNTIME]]

local temp_dir = vim.loop.os_getenv 'TEMP' or '/tmp'

vim.cmd('set packpath=' .. join_paths(temp_dir, 'nvim', 'site'))

local package_root = join_paths(temp_dir, 'nvim', 'site', 'pack')
local install_path = join_paths(package_root, 'packer', 'start', 'packer.nvim')
local compile_path = join_paths(install_path, 'plugin', 'packer_compiled.lua')

local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      'neovim/nvim-lspconfig',
      'hrsh7th/cmp-nvim-lsp',
      'hrsh7th/nvim-cmp',
      'hrsh7th/cmp-buffer'
    },
    config = {
      package_root = package_root,
      compile_path = compile_path,
    },
  }
end


local cmp = require 'cmp'

cmp.setup {
  sources = cmp.config.sources({
    { name = 'nvim_lsp' },
  }, {
    { name = 'buffer' },
  })
}

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

if vim.fn.isdirectory(install_path) == 0 then
  vim.fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path }
  load_plugins()
  require('packer').sync()
  vim.cmd [[autocmd User PackerComplete ++once lua load_config()]]
else
  load_plugins()
  require('packer').sync()
end

I can see that the plugin is in the folder. and that it successfully discovers the buffer one, so I am at a loss.

 Directory of C:\Users\<USER>\AppData\Local\Temp\nvim\site\pack\packer\start

27/05/2022  12:10    <DIR>          .
27/05/2022  12:10    <DIR>          ..
27/05/2022  12:10    <DIR>          cmp-buffer
27/05/2022  12:10    <DIR>          cmp-nvim-lsp
27/05/2022  11:53    <DIR>          nvim-cmp
27/05/2022  11:29    <DIR>          nvim-lspconfig
27/05/2022  11:29    <DIR>          packer.nvim
               0 File(s)              0 bytes
               7 Dir(s)  209,480,146,944 bytes free

I am running on Windows NVIM version 7.

The complete menu is not aligned

Repetition steps

nivm -u mini.vim mini.c

minimal vimrc

if &compatible
  set nocompatible               " Be iMproved
endif

" Disable Vim's native pack feature
set packpath=

let $CACHE = expand('~/.cache/nvim')
if !isdirectory(expand($CACHE))
    call mkdir(expand($CACHE), 'p')
endif
let s:dein_dir = expand('$CACHE/dein')
let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'
if &runtimepath !~# '/dein.vim'
    if !isdirectory(s:dein_repo_dir)
        execute '!git clone https://github.com/Shougo/dein.vim' s:dein_repo_dir
    endif
    execute 'set runtimepath^=' . s:dein_repo_dir
endif

let g:dein#auto_recache = 1
if dein#load_state(s:dein_dir, expand('<sfile>'))
  call dein#begin(s:dein_dir, expand('<sfile>'))
  " Required:
  call dein#add('neovim/nvim-lspconfig')
  call dein#add('hrsh7th/nvim-cmp')
  call dein#add('hrsh7th/cmp-buffer')
  call dein#add('hrsh7th/cmp-nvim-lsp')
  " Required:
  call dein#end()
  call dein#save_state()
endif

call dein#call_hook('source')
call dein#call_hook('post_source')
if has('vim_starting') && dein#check_install()
    call dein#install()
endif
filetype plugin indent on
syntax enable
set termguicolors

lua << EOF
require'lspconfig'.clangd.setup{}
local cmp = require("cmp")
    cmp.setup({
        snippet = {
            expand = function(args)
               vim.fn["vsnip#anonymous"](args.body)
             -- require 'snippy'.expand_snippet(args.body)
        end,
    },
    sources = {
        { name = "nvim_lsp" },
        { name = "buffer" },
        -- { name = "vsnip" },
       -- { name = 'snippy' }
    },
    mapping = {
        ["<S-TAB>"] = cmp.mapping.select_prev_item(),
        ["<TAB>"] = cmp.mapping.select_next_item(),
        ["<C-Space>"] = cmp.mapping.complete(),
        ["<C-e>"] = cmp.mapping.close(),
        ['<CR>'] = cmp.mapping.confirm()
    },
})
EOF

screenshots

Snipaste_2022-01-30_22-44-12

Use of after directory, antipattern.

This plugin uses after directory to run a script.
But if you don't use any plugin manager and rely on pack/*/opt directory and packadd command to load plugin. The script in after directory is not sourced. Causing the plugin to not function.

After directory was supposed to be used by system admins and not plugins. I know now plugin managers source the scripts in after directory, but is it really needed here.

If someone is using plugin manager they should ensure that this plugin's autocmd is run correctly. Instead of authors using the after dir.

Thanks.

lazy-loading on InsertEnter

I lazy-load nvim-cmp on the InsertEnter event.

I also use cmp-nvim-lsp with nvim-lspconfig as

capabilities = require 'cmp_nvim_lsp'.default_capabilities(vim.lsp.protocol.make_client_capabilities()),

When I enter Insert mode, sometimes I receive the error message:

Error detected while processing InsertEnter Autocommands for "*":
E5108: Error executing lua ...pack/packer/start/cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:60: module 'cmp' not found:
        no field package.preload['cmp']
        no file './cmp/lua'
        no file '/usr/share/luajit-2.1.0-beta3/cmp.lua'
        no file '/usr/local/share/lua/5.1/cmp.lua'
        no file '/usr/local/share/lua/5.1/cmp/init.lua'
        no file '/usr/share/lua/5.1/cmp.lua'
        no file '/usr/share/lua/5.1/cmp/init.lua'
        no file '/home/sicro/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/cmp.lua'
        no file '/home/sicro/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/cmp/init.lua'
        no file '/home/sicro/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/cmp.lua'
        no file '/home/sicro/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/cmp/init.lua'
        no file './cmp.so'
        no file '/usr/local/lib/lua/5.1/cmp.so'
        no file '/usr/lib64/lua/5.1/cmp.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file '/home/sicro/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/cmp.so'
stack traceback:
        [C]: in function 'require'
        ...pack/packer/start/cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:60: in function '_on_insert_enter'
        [string: ":lua"]:1: in main chunk

This is my config:

return require 'packer'.startup(function ()
	use {
		'hrsh7th/nvim-cmp',
		config = function () ... end,
		event = 'InsertEnter',
		setup = function ()
			vim.cmd [[PackerLoad LuaSnip]]
			vim.cmd [[PackerLoad nvim-autopairs]]
			vim.cmd [[PackerLoad lspkind-nvim]]
		end
	}
end)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.