Skip to content

Commit 827a89d

Browse files
committed
Initial implement
0 parents  commit 827a89d

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

.stylua.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
column_width = 120
2+
line_endings = 'Unix'
3+
indent_type = 'Spaces'
4+
indent_width = 2
5+
quote_style = 'ForceSingle'
6+
call_parentheses = 'None'
7+
collapse_simple_statement = 'Never'

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# cmp-tsnip
2+
3+
[tsnip.nvim](https://github.com/yuki-yano/tsnip.nvim) source for [nvim-cmp](https://github.com/hrsh7th/nvim-cmp).
4+
5+
## Requirements
6+
7+
- `nvim-cmp`
8+
- `denops.vim`
9+
- `tsnip.nvim`
10+
11+
## Setup
12+
13+
```lua
14+
require 'cmp'.setup {
15+
sources = {
16+
{ name = 'tsnip' }
17+
}
18+
}
19+
```
20+

lua/cmp-tsnip/init.lua

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
local source = {}
2+
3+
function source.new()
4+
return setmetatable({}, { __index = source })
5+
end
6+
7+
function source.is_available()
8+
return vim.fn['denops#plugin#is_loaded'] 'tsnip' == 1
9+
end
10+
11+
function source.get_debug_name()
12+
return 'tsnip'
13+
end
14+
15+
function source.get_keyword_pattern()
16+
return '.'
17+
end
18+
19+
---@class tsnip.Item
20+
---@field public word string
21+
---@field public info string
22+
23+
function source:complete(_, callback)
24+
---@type tsnip.Item[]
25+
local items = vim.fn['tsnip#items']()
26+
27+
local completion_items = {}
28+
29+
for _, item in ipairs(items) do
30+
table.insert(completion_items, {
31+
label = item.word,
32+
filterText = item.word,
33+
documentation = item.info,
34+
})
35+
end
36+
37+
callback(completion_items)
38+
end
39+
40+
---@param completion_item lsp.CompletionItem
41+
---@param callback fun(completion_item: lsp.CompletedItem|nil)
42+
function source:execute(completion_item, callback)
43+
vim.fn['tsnip#remove_suffix_word'](completion_item.label)
44+
vim.cmd.TSnip { completion_item.label }
45+
callback(completion_item)
46+
end
47+
48+
return source

plugin/cmp-tsnip.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('cmp').register_source('tsnip', require('cmp-tsnip').new())

0 commit comments

Comments
 (0)