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

@ -20,7 +20,7 @@
"code_runner.nvim": { "branch": "main", "commit": "dcedccbf969a0f3bc00db446172b4966e83101dd" }, "code_runner.nvim": { "branch": "main", "commit": "dcedccbf969a0f3bc00db446172b4966e83101dd" },
"codeium.vim": { "branch": "main", "commit": "8c01979323b2b480c8bf160d3ff85bd1668baa49" }, "codeium.vim": { "branch": "main", "commit": "8c01979323b2b480c8bf160d3ff85bd1668baa49" },
"conform.nvim": { "branch": "master", "commit": "d28ccf945374edd9f1c34a82f6c22261dbd8ab98" }, "conform.nvim": { "branch": "master", "commit": "d28ccf945374edd9f1c34a82f6c22261dbd8ab98" },
"dressing.nvim": { "branch": "master", "commit": "c334ac73e031f0dc93d6d91f3658ee75b8be1d3b" }, "dressing.nvim": { "branch": "master", "commit": "6ef1ca479d37d4ff66f13eed44d08912caff483a" },
"friendly-snippets": { "branch": "main", "commit": "de8fce94985873666bd9712ea3e49ee17aadb1ed" }, "friendly-snippets": { "branch": "main", "commit": "de8fce94985873666bd9712ea3e49ee17aadb1ed" },
"gitsigns.nvim": { "branch": "main", "commit": "4daf7022f1481edf1e8fb9947df13bb07c18e89a" }, "gitsigns.nvim": { "branch": "main", "commit": "4daf7022f1481edf1e8fb9947df13bb07c18e89a" },
"indent-blankline.nvim": { "branch": "master", "commit": "04e44b09ee3ff189c69ab082edac1ef7ae2e256c" }, "indent-blankline.nvim": { "branch": "master", "commit": "04e44b09ee3ff189c69ab082edac1ef7ae2e256c" },

View file

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

View file

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

View file

@ -67,3 +67,4 @@ pcode.themes = {
-- activate config transparent_bg -- activate config transparent_bg
pcode.transparent = false pcode.transparent = false
pcode.localcode = true pcode.localcode = true
pcode.snippets_path = vim.fn.stdpath("config") .. "/mysnippets"

View file

@ -1,8 +1,8 @@
local status_ok = pcall(require, "luasnip") local status_ok = pcall(require, "luasnip")
if not status_ok then if not status_ok then
return return
end end
local lpath = vim.fn.stdpath("config") .. "/snippets" local lpath = pcode.snippets_path or vim.fn.stdpath("config") .. "/snippets"
require("luasnip.loaders.from_vscode").lazy_load({ paths = lpath }) require("luasnip.loaders.from_vscode").lazy_load({ paths = lpath })
require("luasnip.loaders.from_vscode").load({ paths = lpath }) require("luasnip.loaders.from_vscode").load({ paths = lpath })