cmp-npm
cmp-npm copied to clipboard
An additional source for nvim-cmp to autocomplete packages and its versions
cmp-npm
This is an additional source for nvim-cmp, it allows you to
autocomplete npm packages and its versions.
The source is only active if you're in a package.json file.

Requirements
It needs the Neovim plugin nvim-cmp and the npm command line tool.
Installation
For vim-plug:
Plug 'nvim-lua/plenary.nvim'
Plug 'David-Kunz/cmp-npm'
For packer:
use {
'David-Kunz/cmp-npm',
requires = {
'nvim-lua/plenary.nvim'
}
}
Run the setup function and add the source
require('cmp-npm').setup({})
cmp.setup({
...,
sources = {
{ name = 'npm', keyword_length = 4 },
...
}
})
(in Vimscript, make sure to add lua << EOF before and EOF after the lua code)
The setup function accepts an options table which defaults to:
{
ignore = {},
only_semantic_versions = false,
}
ignore(table): Allows you to filter out all versions which match one of its entries, e.g.ignore = { 'beta', 'rc' }.only_semantic_versions(Boolean): Iftrue, will filter out all versions which don't follow themajor.minor.patchschema.
Limitations
The versions are not correctly sorted (depends on nvim-cmp's sorting algorithm).