Skip to content

Commit 9165b46

Browse files
committed
feat(lua): add vim-related snippets
1 parent 086a9ce commit 9165b46

File tree

11 files changed

+576
-166
lines changed

11 files changed

+576
-166
lines changed

README.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ ls.setup({
2626
})
2727
```
2828

29+
# Configuration
30+
31+
```lua
32+
---@type LSSnippets.Config
33+
{
34+
user = {
35+
-- user's name, used in todo-related snippets now
36+
name = nil,
37+
},
38+
snippet = {
39+
lua = {
40+
-- enable neovim related snippets in lua
41+
vim_snippet = false,
42+
}
43+
}
44+
}
45+
```
46+
2947
## Snippets
3048

3149
<details>
@@ -44,12 +62,15 @@ ls.setup({
4462
<details>
4563
<summary>Lua</summary>
4664

65+
Snippets with `*` are available only when `vim_snippet` is enabled.
66+
4767
#### Normal Snippets
4868

49-
| Trig | Desc | Context Required |
50-
| :---: | ------------------------------------ | :--------------: |
51-
| `fn` | Expands to function definition. | No |
52-
| `req` | Expands to `require(...)` statement. | No |
69+
| Trig | Desc | Context Required |
70+
| :-----: | ------------------------------------------ | :--------------: |
71+
| `fn` | Expands to function definition. | No |
72+
| `req` | Expands to `require(...)` statement. | No |
73+
| `ifn`\* | Expand to `vim.F.if_nil(...)` expresstion. | No |
5374

5475
#### Postfix Snippets
5576

@@ -58,14 +79,21 @@ ls.setup({
5879
(function_call)
5980
(identifier)
6081
(expression_list)
82+
(dot_index_expression)
83+
(bracket_index_expression)
6184
] @any_expr
85+
[
86+
(dot_index_expression)
87+
(bracket_index_expression)
88+
] @index_expr
6289
```
6390

64-
| Trig | Desc (placehoder: `?`) | Expr before cursor |
65-
| :-------: | ---------------------------------------- | :----------------: |
66-
| `.ipairs` | Expands to `ipairs(?)` for-loop. | `any_expr` |
67-
| `.pairs` | Expands to `pairs(?)` for-loop. | `any_expr` |
68-
| `.isnil` | Expands to `if ? == nil then` statement. | `any_expr` |
91+
| Trig | Desc (placehoder: `?`) | Expr before cursor |
92+
| :-------: | ----------------------------------------- | :----------------: |
93+
| `.ipairs` | Expands to `ipairs(?)` for-loop. | `any_expr` |
94+
| `.pairs` | Expands to `pairs(?)` for-loop. | `any_expr` |
95+
| `.isnil` | Expands to `if ? == nil then` statement. | `any_expr` |
96+
| `.tget`\* | Expands to `vim.tbl_get(...)` expression. | `index_expr` |
6997

7098
</details>
7199

lua/luasnip-snippets/config.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
---@field name? string
33
---@field email? string
44

5+
---@class LSSnippets.Config.Snippet.Lua
6+
---@field vim_snippet? boolean
7+
---@field cond? fun():boolean
8+
9+
---@class LSSnippets.Config.Snippet
10+
---@field lua LSSnippets.Config.Snippet.Lua
11+
512
---@class LSSnippets.Config
613
---@field copyright_header? string
714
---@field user? LSSnippets.Config.User
15+
---@field snippet? LSSnippets.Config.Snippet
816
local config = {}
917

1018
---@param opts? LSSnippets.Config
@@ -29,7 +37,10 @@ local function get(key)
2937
return value
3038
end
3139

32-
return {
40+
---@class luasnip-snippets.config
41+
local M = {
3342
setup = setup,
3443
get = get,
3544
}
45+
46+
return M

lua/luasnip-snippets/nodes.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ local function word_expand(word, expand, mode)
118118
}
119119
end
120120

121-
return {
121+
---@class luasnip-snippets.nodes
122+
local M = {
122123
insert_node = insert_node,
123124
choice_node = choice_node,
124125
construct_snippet = construct_snippet,
125126
word_expand = word_expand,
126127
}
128+
129+
return M

lua/luasnip-snippets/snippets/lua.lua

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)