add base snippets config
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
--- [[ LSP setup]]
|
||||
---
|
||||
|
||||
vim.lsp.enable("luals")
|
||||
vim.lsp.enable("rust")
|
||||
vim.lsp.enable("bashls")
|
||||
|
||||
vim.lsp.config("*", {
|
||||
capabilities = {
|
||||
textDocument = {
|
||||
@@ -9,10 +15,6 @@ vim.lsp.config("*", {
|
||||
},
|
||||
})
|
||||
|
||||
vim.lsp.enable("luals")
|
||||
vim.lsp.enable("rust")
|
||||
vim.lsp.enable("bashls")
|
||||
|
||||
-- [[FOLDING SETUP
|
||||
-- Prefer LSP folding if client supports it
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
@@ -83,4 +85,33 @@ vim.api.nvim_create_autocmd("LspAttach", {
|
||||
---]]
|
||||
end,
|
||||
})
|
||||
|
||||
-- Expanding multiline snippets
|
||||
vim.api.nvim_create_augroup("user-snippet-expand", {})
|
||||
vim.api.nvim_create_autocmd("CompleteDone", {
|
||||
group = "user-snippet-expand",
|
||||
desc = "Expand LSP snippet",
|
||||
pattern = "*",
|
||||
callback = function(opts)
|
||||
local comp = vim.v.completed_item
|
||||
local item = vim.tbl_get(comp, "user_data", "nvim", "lsp", "completion_item")
|
||||
|
||||
-- check that we were given a snippet
|
||||
if not item or not item.insertTextFormat or item.insertTextFormat == 1 then
|
||||
return
|
||||
end
|
||||
|
||||
-- remove the inserted text
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local line = vim.api.nvim_get_current_line()
|
||||
local lnum = cursor[1] - 1
|
||||
local start_char = cursor[2] - #comp.word
|
||||
vim.api.nvim_buf_set_text(opts.buf, lnum, start_char, lnum, #line, { "" })
|
||||
|
||||
-- insert snippet
|
||||
local snip_text = vim.tbl_get(item, "textEdit", "newText") or item.insertText
|
||||
assert(snip_text, "Language server indicated it had a snippet, but no snippet text could be found!")
|
||||
require("luasnip").lsp_expand(snip_text)
|
||||
end,
|
||||
})
|
||||
---AUTOCOMPLETION SETUP END]]
|
||||
|
||||
9
nvim/.config/nvim/lua/plugins/snippets.lua
Normal file
9
nvim/.config/nvim/lua/plugins/snippets.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
return {
|
||||
{
|
||||
"L3MON4D3/LuaSnip",
|
||||
-- follow latest release.
|
||||
version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
|
||||
-- install jsregexp (optional!).
|
||||
build = "make install_jsregexp",
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user