enc: add snippet path config

This commit is contained in:
Pojok Code 2024-11-05 06:09:08 +07:00
parent 9aebda6491
commit 5f97594d62
5 changed files with 149 additions and 148 deletions

View file

@ -1,52 +1,52 @@
_G.idxOf = function(array, value)
for i, v in ipairs(array) do
if v == value then
return i
end
end
return nil
for i, v in ipairs(array) do
if v == value then
return i
end
end
return nil
end
_G.LAZYGIT_TOGGLE = function()
local ok = pcall(require, "toggleterm")
if not ok then
require("notify")("toggleterm not found!", "error")
return
end
local Terminal = require("toggleterm.terminal").Terminal
local lazygit = Terminal:new({ cmd = "lazygit", hidden = true })
lazygit:toggle()
local ok = pcall(require, "toggleterm")
if not ok then
require("notify")("toggleterm not found!", "error")
return
end
local Terminal = require("toggleterm.terminal").Terminal
local lazygit = Terminal:new({ cmd = "lazygit", hidden = true })
lazygit:toggle()
end
_G.substring = function(text, key)
local index, _ = string.find(text, key)
if index then
return true
else
return false
end
local index, _ = string.find(text, key)
if index then
return true
else
return false
end
end
_G.all_trim = function(s)
return s:match("^%s*(.-)%s*$")
return s:match("^%s*(.-)%s*$")
end
_G.current_theme = function()
if pcode.themes then
local theme = ""
for _, value in pairs(pcode.themes or {}) do
theme = value
end
return all_trim(theme)
end
return ""
if pcode.themes then
local theme = ""
for _, value in pairs(pcode.themes or {}) do
theme = value
end
return all_trim(theme)
end
return ""
end
local function safeRequire(module)
local ok, result = pcall(require, module)
if ok then
return result
end
local ok, result = pcall(require, module)
if ok then
return result
end
end
safeRequire("pcode.user.options")

View file

@ -1,121 +1,121 @@
return {
{
"L3MON4D3/LuaSnip",
event = "InsertEnter",
opts = {
history = true,
delete_check_events = "TextChanged",
},
{
"L3MON4D3/LuaSnip",
event = "InsertEnter",
opts = {
history = true,
delete_check_events = "TextChanged",
},
-- stylua: ignore
keys = {
{ "<tab>", function() require("luasnip").jump(1) end, mode = "s" },
{ "<s-tab>", function() require("luasnip").jump(-1) end, mode = { "i", "s" } },
},
},
{
"hrsh7th/nvim-cmp",
version = false, -- last release is way too old
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lua",
},
opts = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
},
{
"hrsh7th/nvim-cmp",
version = false, -- last release is way too old
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lua",
},
opts = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
local check_backspace = function()
local col = vim.fn.col(".") - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
end
local check_backspace = function()
local col = vim.fn.col(".") - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
end
return {
completion = {
completeopt = "menu,menuone,noinsert",
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expandable() then
luasnip.expand()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif check_backspace() then
fallback()
else
fallback()
end
end, {
"i",
"s",
}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {
"i",
"s",
}),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
{ name = "nvim_lua" },
}),
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
vim_item.menu = vim.api.nvim_get_mode().mode == "c" and "" or vim_item.kind
vim_item.kind = string.format("%s", require("pcode.user.icons")["kind"][vim_item.kind])
-- vim_item.menu = ({
-- nvim_lsp = "(LSP)",
-- luasnip = "(Snippet)",
-- buffer = "(Buffer)",
-- path = "(Path)",
-- codeium = "(Codeium)",
-- })[entry.source.name]
return vim_item
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
experimental = {
ghost_text = false,
native_menu = false,
},
}
end,
},
{
"rafamadriz/friendly-snippets",
event = "InsertEnter",
lazy = true,
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
require("pcode.user.snippets")
end,
},
return {
completion = {
completeopt = "menu,menuone,noinsert",
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expandable() then
luasnip.expand()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif check_backspace() then
fallback()
else
fallback()
end
end, {
"i",
"s",
}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {
"i",
"s",
}),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
{ name = "nvim_lua" },
}),
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
vim_item.menu = vim.api.nvim_get_mode().mode == "c" and "" or vim_item.kind
vim_item.kind = string.format("%s", require("pcode.user.icons")["kind"][vim_item.kind])
-- vim_item.menu = ({
-- nvim_lsp = "(LSP)",
-- luasnip = "(Snippet)",
-- buffer = "(Buffer)",
-- path = "(Path)",
-- codeium = "(Codeium)",
-- })[entry.source.name]
return vim_item
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
experimental = {
ghost_text = false,
native_menu = false,
},
}
end,
},
{
"rafamadriz/friendly-snippets",
event = "InsertEnter",
lazy = true,
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
require("pcode.user.snippets")
end,
},
}