Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 2 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 (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-24T13:35:18.000Z (over 1 year ago)
- Last Synced: 2024-08-06T18:24:38.382Z (5 months ago)
- Topics: nvim-cmp
- Language: Lua
- Homepage:
- Size: 22.5 KB
- Stars: 38
- 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
![image](https://user-images.githubusercontent.com/82267684/197586670-7b3c4794-54c1-4f2d-864a-1abfab1d4d3c.png)
Press \
![image](https://user-images.githubusercontent.com/82267684/197586711-d6d889af-66d7-43c9-b397-7b4f5d2b6e9c.png)
- resolve = false
![image](https://user-images.githubusercontent.com/82267684/197586575-18a94501-5462-4a2b-b7eb-d70391f9e0d3.png)