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

add CmpItemKindNpm for source naming and icon #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,39 @@ e.g. `ignore = { 'beta', 'rc' }`.
the `major.minor.patch` schema.
- `only_latest_version` (Boolean): If `true`, will only show latest release version.

### Highlighting & Icon

Npm's cmp source creates highlight group `CmpItemKindNpm`. To add an icon for lspkind, add the icon to your lspkind symbol map.

#### Option 1

```lua
-- lspkind.lua
local lspkind = require("lspkind")
lspkind.init({
symbol_map = {
Npm = " ",
},
})

vim.api.nvim_set_hl(0, "CmpItemKindNpm", {fg ="#BD93F9"})
```

#### Option 2

```lua
-- cmp.lua
cmp.setup {
...
formatting = {
format = lspkind.cmp_format({
mode = "symbol",
symbol_map = { Npm = " " }
})
}
...
}
```

## Limitations

Expand Down
8 changes: 7 additions & 1 deletion lua/cmp-npm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ function source:complete(params, callback)
end
end

table.insert(items, { label = version })
table.insert(items, {
label = version,
cmp = {
kind_hl_group = "CmpItemKindNpm",
kind_text = "Npm",
},
})

::continue::
end
Expand Down