https://github.com/uga-rosa/cmp-dynamic
Source of nvim-cmp to dynamically generate candidates using Lua functions.
https://github.com/uga-rosa/cmp-dynamic
nvim-cmp
Last synced: 6 months ago
JSON representation
Source of nvim-cmp to dynamically generate candidates using Lua functions.
- Host: GitHub
- URL: https://github.com/uga-rosa/cmp-dynamic
- Owner: uga-rosa
- License: mit
- Created: 2022-10-21T06:42:37.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-24T13:35:18.000Z (about 3 years ago)
- Last Synced: 2025-04-02T00:42:23.286Z (about 1 year ago)
- Topics: nvim-cmp
- Language: Lua
- Homepage:
- Size: 22.5 KB
- Stars: 41
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cmp-dynamic
Source of [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) to dynamically generate candidates using Lua functions.
# Usage
```lua
require("cmp").setup({
-- other settings
sources = {
{ name = "dynamic" },
},
})
require("cmp_dynamic").register({
-- items
})
```
# Define completion items
Here is an example of defining completion items.
```lua
local Date = require("cmp_dynamic.utils.date")
require("cmp_dynamic").register({
{
label = "today",
insertText = function()
return os.date("%Y/%m/%d")
end,
},
{
label = "next Monday",
insertText = function()
return Date.new():add_date(7):day(1):format("%Y/%m/%d")
end,
resolve = true, -- default: false
},
})
```
Basically, items conforms to [LSP's CompletionItem](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItem).
There is a special key `resolve`, and functions can be specified for any values.
By default, `resolve` is false.
Setting it to true delays to evaluate the functions until it is complete.
However, since `label` is a required field, it is evaluated first regardless of the value of `resolve`.
- resolve = true

Press \

- resolve = false
