-
Hello! Just diving into the snippets and learned the basics. Thank you for the amazing plugin! I have a question. How do I make snippets for different methods of a class. For example let's say I have a class named data\parse!
data\get!
data\commit! So when I type How difficult is this to achieve? Is there an easy way that even a beginner me can do? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hm, to be honest this doesn't sound quite like an application for snippets. More like something which should/can be achieved by using a Language Server. This will also (try to) track of what type a variable is and can therefore suggest the right methods for it. At least the latter is out of scope for a snippet plugin. For neovim, you can easily use https://github.com/neovim/nvim-lspconfig (configures the by now in nvim builtin language server client) in combination with the right language server and something like https://github.com/hrsh7th/nvim-cmp (for the completion menu) this should work. If you want to stick with doing this via snippets (the string |
Beta Was this translation helpful? Give feedback.
-
Oh, this could be done by writing a custom Alternatively, you can use |
Beta Was this translation helpful? Give feedback.
Oh, this could be done by writing a custom
nvim-cmp
-source (actually not that hard!!). Probably way too overkill, but it seems like a perfect solution.But for practical purposes, using snippets with the same prefix, as @atticus-sullivan suggests, makes more sense since it will most likely work just as well with the regular snippet-completion from
cmp_luasnip
Alternatively, you can use
condition
andshow_condition
to check whether the characters before the trigger match"data\"
, and then allow or prevent expansion/completion.