6 files changed,
99 insertions(+),
8 deletions(-)
Author:
Smirnov Oleksandr
ss2316544@gmail.com
Committed at:
2022-09-07 19:08:36 +0300
Parent:
bdeff63
M
lua/configs/cmp.lua
@@ -1,12 +1,6 @@
local cmp = require "cmp" local luasnip = require "luasnip" -require("luasnip.loaders.from_vscode").load { - paths = { - "~/.local/share/nvim/site/pack/packer/opt/friendly-snippets", - }, -} - cmp.event:on( "confirm_done", require("nvim-autopairs.completion.cmp").on_confirm_done {@@ -66,7 +60,7 @@ ["<C-j>"] = cmp.mapping.select_next_item(),
["<C-k>"] = cmp.mapping.select_prev_item(), ["<C-d>"] = cmp.mapping.scroll_docs(-4), ["<C-f>"] = cmp.mapping.scroll_docs(4), - ["<C-Space>"] = cmp.mapping.complete(), + ["<C-Space>"] = cmp.mapping.complete {}, ["<C-e>"] = cmp.mapping.close(), ["<CR>"] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace,
A
lua/configs/luasnip.lua
@@ -0,0 +1,45 @@
+local map = require("core.utils").map +local ls = require "luasnip" +local types = require "luasnip.util.types" +local fmt = require("luasnip.extras.fmt").fmt +local extras = require "luasnip.extras" + +ls.config.set_config { + history = true, + updateevents = "TextChanged,TextChangedI", + region_check_events = "CursorMoved,CursorHold,InsertEnter", + delete_check_events = "InsertLeave", + snip_env = { + fmt = fmt, + m = extras.match, + l = extras.lamda, + s = ls.snippet, + t = ls.text_node, + f = ls.function_node, + c = ls.choice_node, + d = ls.dynamic_node, + i = ls.insert_node, + }, + ext_opts = { + [types.choiceNode] = { + passive = { + virt_text = { { "●", "Operator" } }, + hl_group = "LuaSnipChoiceNode", + }, + }, + [types.insertNode] = { + active = { + virt_text = { { "●", "Type" } }, + hl_group = "LuaSnipInsertNode", + }, + }, + }, +} + +require("luasnip.loaders.from_lua").lazy_load() + +map({ "s", "i" }, "<c-l>", function() + if ls.choice_active() then + ls.change_choice(1) + end +end)
M
lua/plugins.lua
@@ -155,6 +155,6 @@
use { "L3MON4D3/LuaSnip", module = "luasnip", - requires = { { "rafamadriz/friendly-snippets", after = "nvim-cmp" } }, + config = u.get.config "luasnip", } end)
A
luasnippets/all.lua
@@ -0,0 +1,20 @@
+---@diagnostic disable: undefined-global +-- selene: allow(undefined_variable) +return { + s({ trig = "td", name = "TODO" }, { + d(1, function() + local function with_cmt(cmt) + return string.format(vim.bo.commentstring, " " .. cmt) + end + return s("", { + c(1, { + t(with_cmt "TODO: "), + t(with_cmt "FIXME: "), + t(with_cmt "HACK: "), + t(with_cmt "BUG: "), + }), + }) + end), + i(0), + }), +}
A
luasnippets/go.lua
@@ -0,0 +1,27 @@
+---@diagnostic disable: undefined-global +-- selene: allow(undefined_variable) +return { + s("in", { t "interface{}" }), + s({ trig = "err", name = "if err" }, { + t "if err != nil", + t { " {", "\t" }, + i(0), + t { "", "}" }, + }), + s({ trig = "type", name = "type def", decr = "define a type" }, { + t "type ", + i(1, "Name"), + c(2, { + t " struct", + t " interface", + }), + t { " {", "\t" }, + i(0), + t { "", "}" }, + }), + s(":", { + i(1, "name"), + t " := ", + i(2, "value"), + }), +}
A
luasnippets/lua.lua
@@ -0,0 +1,5 @@
+---@diagnostic disable: undefined-global +-- selene: allow(undefined_variable) +return { + s("req", fmt('local {} = require "{}"', { i(1, "name"), i(2, "module") })), +}