add custom snippets
This commit is contained in:
parent
a788ef0188
commit
c858c3f80e
|
|
@ -1,31 +1,36 @@
|
||||||
return {
|
return {
|
||||||
"hrsh7th/nvim-cmp",
|
'hrsh7th/nvim-cmp',
|
||||||
event = "InsertEnter",
|
event = 'InsertEnter',
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"hrsh7th/cmp-buffer", -- source for text in buffer
|
'hrsh7th/cmp-buffer', -- source for text in buffer
|
||||||
"hrsh7th/cmp-path", -- source for file system paths
|
'hrsh7th/cmp-path', -- source for file system paths
|
||||||
{
|
{
|
||||||
"L3MON4D3/LuaSnip",
|
'L3MON4D3/LuaSnip',
|
||||||
-- follow latest release.
|
-- follow latest release.
|
||||||
version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
|
version = 'v2.*', -- Replace <CurrentMajor> by the latest released major (first number of latest release)
|
||||||
-- install jsregexp (optional!).
|
-- install jsregexp (optional!).
|
||||||
build = "make install_jsregexp",
|
build = 'make install_jsregexp',
|
||||||
},
|
},
|
||||||
"saadparwaiz1/cmp_luasnip", -- for autocompletion
|
'saadparwaiz1/cmp_luasnip', -- for autocompletion
|
||||||
"rafamadriz/friendly-snippets", -- useful snippets
|
'rafamadriz/friendly-snippets', -- useful snippets
|
||||||
"onsails/lspkind.nvim", -- vs-code like pictograms
|
'onsails/lspkind.nvim', -- vs-code like pictograms
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local cmp = require("cmp")
|
local cmp = require 'cmp'
|
||||||
|
|
||||||
local luasnip = require("luasnip")
|
local luasnip = require 'luasnip'
|
||||||
|
|
||||||
local lspkind = require("lspkind")
|
local lspkind = require 'lspkind'
|
||||||
|
|
||||||
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
||||||
require("luasnip.loaders.from_vscode").lazy_load()
|
require('luasnip.loaders.from_vscode').lazy_load {}
|
||||||
|
|
||||||
cmp.setup({
|
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file
|
||||||
|
for _, ft_path in ipairs(vim.api.nvim_get_runtime_file('mysnippets/*.lua', true)) do
|
||||||
|
loadfile(ft_path)()
|
||||||
|
end
|
||||||
|
|
||||||
|
cmp.setup {
|
||||||
preselect = cmp.PreselectMode.None,
|
preselect = cmp.PreselectMode.None,
|
||||||
completion = {
|
completion = {
|
||||||
completeopt = 'menu,menuone,noinsert,noselect',
|
completeopt = 'menu,menuone,noinsert,noselect',
|
||||||
|
|
@ -36,9 +41,9 @@ return {
|
||||||
luasnip.lsp_expand(args.body)
|
luasnip.lsp_expand(args.body)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
mapping = cmp.mapping.preset.insert({
|
mapping = cmp.mapping.preset.insert {
|
||||||
["<C-e>"] = cmp.mapping.abort(), -- close completion window
|
['<C-e>'] = cmp.mapping.abort(), -- close completion window
|
||||||
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
['<CR>'] = cmp.mapping.confirm { select = true },
|
||||||
|
|
||||||
['<C-n>'] = cmp.mapping.select_next_item(),
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
||||||
['<C-p>'] = cmp.mapping.select_prev_item(),
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||||
|
|
@ -70,24 +75,29 @@ return {
|
||||||
luasnip.jump(-1)
|
luasnip.jump(-1)
|
||||||
end
|
end
|
||||||
end, { 'i', 's' }),
|
end, { 'i', 's' }),
|
||||||
}),
|
},
|
||||||
-- sources for autocompletion
|
-- sources for autocompletion
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources {
|
||||||
{ name = "nvim_lsp"},
|
{ name = 'nvim_lsp' },
|
||||||
{ name = "luasnip" }, -- snippets
|
{ name = 'luasnip' }, -- snippets
|
||||||
{ name = "buffer" }, -- text within current buffer
|
{ name = 'buffer' }, -- text within current buffer
|
||||||
{ name = "path" }, -- file system paths
|
{ name = 'path' }, -- file system paths
|
||||||
}),
|
},
|
||||||
|
-- sorting = {
|
||||||
|
-- comparators = {
|
||||||
|
-- cmp.config.compare.score,
|
||||||
|
-- cmp.config.compare.recently_used,
|
||||||
|
-- },
|
||||||
|
-- },
|
||||||
-- configure lspkind for vs-code like pictograms in completion menu
|
-- configure lspkind for vs-code like pictograms in completion menu
|
||||||
formatting = {
|
formatting = {
|
||||||
expandable_indicator = true,
|
expandable_indicator = true,
|
||||||
fields = { cmp.ItemField.Abbr, cmp.ItemField.Kind },
|
fields = { cmp.ItemField.Abbr, cmp.ItemField.Kind },
|
||||||
format = lspkind.cmp_format({
|
format = lspkind.cmp_format {
|
||||||
maxwidth = 50,
|
maxwidth = 50,
|
||||||
ellipsis_char = "...",
|
ellipsis_char = '...',
|
||||||
}),
|
},
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,50 +1,50 @@
|
||||||
return {
|
return {
|
||||||
"williamboman/mason.nvim",
|
'williamboman/mason.nvim',
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"williamboman/mason-lspconfig.nvim",
|
'williamboman/mason-lspconfig.nvim',
|
||||||
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
'WhoIsSethDaniel/mason-tool-installer.nvim',
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- import mason
|
-- import mason
|
||||||
local mason = require("mason")
|
local mason = require 'mason'
|
||||||
|
|
||||||
-- import mason-lspconfig
|
-- import mason-lspconfig
|
||||||
local mason_lspconfig = require("mason-lspconfig")
|
local mason_lspconfig = require 'mason-lspconfig'
|
||||||
|
|
||||||
local mason_tool_installer = require("mason-tool-installer")
|
local mason_tool_installer = require 'mason-tool-installer'
|
||||||
|
|
||||||
-- enable mason and configure icons
|
-- enable mason and configure icons
|
||||||
mason.setup({
|
mason.setup {
|
||||||
ui = {
|
ui = {
|
||||||
icons = {
|
icons = {
|
||||||
package_installed = "✓",
|
package_installed = '✓',
|
||||||
package_pending = "➜",
|
package_pending = '➜',
|
||||||
package_uninstalled = "✗",
|
package_uninstalled = '✗',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
|
||||||
mason_lspconfig.setup({
|
mason_lspconfig.setup {
|
||||||
-- list of servers for mason to install
|
-- list of servers for mason to install
|
||||||
ensure_installed = {
|
ensure_installed = {
|
||||||
"ts_ls",
|
'ts_ls',
|
||||||
"html",
|
'html',
|
||||||
"cssls",
|
'cssls',
|
||||||
"tailwindcss",
|
'tailwindcss',
|
||||||
"svelte",
|
'svelte',
|
||||||
"lua_ls",
|
'lua_ls',
|
||||||
"graphql",
|
'graphql',
|
||||||
-- "emmet_ls",
|
'emmet_language_server',
|
||||||
"prismals",
|
'prismals',
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
|
||||||
mason_tool_installer.setup({
|
mason_tool_installer.setup {
|
||||||
ensure_installed = {
|
ensure_installed = {
|
||||||
"prettier", -- prettier formatter
|
'prettier', -- prettier formatter
|
||||||
"stylua", -- lua formatter
|
'stylua', -- lua formatter
|
||||||
"eslint_d",
|
'eslint_d',
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ vim.keymap.set('n', '<leader>ff', vim.lsp.buf.format, { noremap = true, desc = '
|
||||||
vim.api.nvim_set_keymap('n', '<leader>yr', ":let @+=expand('%:.%:t')<CR>", { noremap = true, silent = true, desc = 'Copy Relative Path' })
|
vim.api.nvim_set_keymap('n', '<leader>yr', ":let @+=expand('%:.%:t')<CR>", { noremap = true, silent = true, desc = 'Copy Relative Path' })
|
||||||
vim.api.nvim_set_keymap('n', '<leader>ya', ":let @+=expand('%:P%:t')<CR>", { noremap = true, silent = true, desc = 'Copy Absolute Path' })
|
vim.api.nvim_set_keymap('n', '<leader>ya', ":let @+=expand('%:P%:t')<CR>", { noremap = true, silent = true, desc = 'Copy Absolute Path' })
|
||||||
|
|
||||||
vim.g.diagnostics_active = false
|
vim.g.diagnostics_active = true
|
||||||
function _G.toggle_diagnostics()
|
function _G.toggle_diagnostics()
|
||||||
if vim.g.diagnostics_active then
|
if vim.g.diagnostics_active then
|
||||||
vim.g.diagnostics_active = false
|
vim.g.diagnostics_active = false
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
local ls = require 'luasnip'
|
||||||
|
local s = ls.snippet
|
||||||
|
local t = ls.text_node
|
||||||
|
local i = ls.insert_node
|
||||||
|
|
||||||
|
ls.add_snippets('all', {
|
||||||
|
s('ter', {
|
||||||
|
-- equivalent to "${1:cond} ? ${2:then} : ${3:else}"
|
||||||
|
i(1, 'cond'),
|
||||||
|
t ' ? ',
|
||||||
|
i(2, 'then'),
|
||||||
|
t ' : ',
|
||||||
|
i(3, 'else'),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
local ls = require 'luasnip'
|
||||||
|
local s = ls.snippet
|
||||||
|
local t = ls.text_node
|
||||||
|
local i = ls.insert_node
|
||||||
|
|
||||||
|
ls.add_snippets('javascriptreact', {
|
||||||
|
-- set attributes to component
|
||||||
|
s('jk', {
|
||||||
|
i(1, 'attr'),
|
||||||
|
t '={',
|
||||||
|
i(2, 'value'),
|
||||||
|
t '}',
|
||||||
|
}),
|
||||||
|
})
|
||||||
Loading…
Reference in New Issue