use luasnip in cmp and telescope
This commit is contained in:
parent
97128cf6e7
commit
07d13e67ae
4 changed files with 37 additions and 15 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
local utils = require('utils')
|
local utils = require('utils')
|
||||||
|
|
||||||
vim.cmd [[set shortmess+=c]]
|
|
||||||
utils.opt('o', 'completeopt', 'menuone,noselect')
|
utils.opt('o', 'completeopt', 'menuone,noselect')
|
||||||
|
|
||||||
local cmp = require('cmp')
|
local cmp = require('cmp')
|
||||||
|
@ -50,12 +49,12 @@ cmp.setup({
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
snippet = {
|
snippet = {
|
||||||
-- REQUIRED - you must specify a snippet engine
|
|
||||||
expand = function(args)
|
expand = function(args)
|
||||||
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
|
local luasnip = require("luasnip")
|
||||||
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
if not luasnip then
|
||||||
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
|
return
|
||||||
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
|
end
|
||||||
|
luasnip.lsp_expand(args.body)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
window = {
|
window = {
|
||||||
|
@ -74,10 +73,7 @@ cmp.setup({
|
||||||
}),
|
}),
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{ name = 'nvim_lsp' },
|
{ name = 'nvim_lsp' },
|
||||||
{ name = 'vsnip' }, -- For vsnip users.
|
{ name = 'luasnip' }, -- For luasnip users.
|
||||||
-- { name = 'luasnip' }, -- For luasnip users.
|
|
||||||
-- { name = 'ultisnips' }, -- For ultisnips users.
|
|
||||||
-- { name = 'snippy' }, -- For snippy users.
|
|
||||||
}, {
|
}, {
|
||||||
{ name = 'buffer' },
|
{ name = 'buffer' },
|
||||||
})
|
})
|
||||||
|
|
|
@ -32,10 +32,15 @@ require('packer').startup(function()
|
||||||
{ 'hrsh7th/cmp-buffer' },
|
{ 'hrsh7th/cmp-buffer' },
|
||||||
{ 'hrsh7th/cmp-path' },
|
{ 'hrsh7th/cmp-path' },
|
||||||
{ 'hrsh7th/cmp-cmdline' },
|
{ 'hrsh7th/cmp-cmdline' },
|
||||||
{ 'hrsh7th/vim-vsnip' },
|
|
||||||
{ 'hrsh7th/vim-vsnip-integ' },
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
use { 'L3MON4D3/LuaSnip' }
|
||||||
|
use { "rafamadriz/friendly-snippets" }
|
||||||
|
use { 'saadparwaiz1/cmp_luasnip' }
|
||||||
|
use {
|
||||||
|
"benfowler/telescope-luasnip.nvim",
|
||||||
|
module = "telescope._extensions.luasnip", -- if you wish to lazy-load
|
||||||
|
}
|
||||||
|
|
||||||
-- Statusbar, colors and syntax
|
-- Statusbar, colors and syntax
|
||||||
use { 'vim-airline/vim-airline' }
|
use { 'vim-airline/vim-airline' }
|
||||||
|
@ -46,7 +51,7 @@ require('packer').startup(function()
|
||||||
use { 'weilbith/nvim-code-action-menu', cmd = 'CodeActionMenu' }
|
use { 'weilbith/nvim-code-action-menu', cmd = 'CodeActionMenu' }
|
||||||
use { 'folke/trouble.nvim' } -- lsp diagnostics
|
use { 'folke/trouble.nvim' } -- lsp diagnostics
|
||||||
|
|
||||||
-- Languages
|
-- Languages that need a plugin to extend default lsp
|
||||||
use { 'cespare/vim-toml' }
|
use { 'cespare/vim-toml' }
|
||||||
use { 'gleam-lang/gleam.vim' }
|
use { 'gleam-lang/gleam.vim' }
|
||||||
use { 'rust-lang/rust.vim' }
|
use { 'rust-lang/rust.vim' }
|
||||||
|
@ -71,6 +76,7 @@ require('packer').startup(function()
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
require('plugins.luasnip')
|
||||||
require('plugins.cmp')
|
require('plugins.cmp')
|
||||||
require('plugins.gitsigns')
|
require('plugins.gitsigns')
|
||||||
require('plugins.neogit')
|
require('plugins.neogit')
|
||||||
|
|
5
lua/plugins/luasnip.lua
Normal file
5
lua/plugins/luasnip.lua
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
local languages = {
|
||||||
|
'python',
|
||||||
|
'rust',
|
||||||
|
}
|
||||||
|
require('luasnip.loaders.from_vscode').load({ include = languages }) -- Load only python snippets
|
|
@ -2,6 +2,9 @@ local telescope = require('telescope')
|
||||||
local actions = require('telescope.actions')
|
local actions = require('telescope.actions')
|
||||||
local builtin = require('telescope.builtin')
|
local builtin = require('telescope.builtin')
|
||||||
|
|
||||||
|
local luasnip = require('luasnip')
|
||||||
|
local lst = telescope.extensions.luasnip
|
||||||
|
|
||||||
telescope.setup {
|
telescope.setup {
|
||||||
defaults = {
|
defaults = {
|
||||||
layout_strategy = "vertical",
|
layout_strategy = "vertical",
|
||||||
|
@ -31,10 +34,22 @@ telescope.setup {
|
||||||
previewer = false,
|
previewer = false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
extensions = {
|
||||||
|
luasnip = {
|
||||||
|
search = function(entry)
|
||||||
|
return lst.filter_null(entry.context.trigger) .. " " ..
|
||||||
|
lst.filter_null(entry.context.name) .. " " ..
|
||||||
|
entry.ft .. " " ..
|
||||||
|
lst.filter_description(entry.context.name, entry.context.description) ..
|
||||||
|
lst.get_docstring(luasnip, entry.ft, entry.context)[1]
|
||||||
|
end
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
|
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
|
||||||
vim.keymap.set('n', '<leader>fg', builtin.git_files, {})
|
vim.keymap.set('n', '<leader>fg', builtin.git_files, {})
|
||||||
|
vim.keymap.set('n', '<leader>fs', telescope.extensions.luasnip.luasnip, {})
|
||||||
vim.keymap.set('n', '<leader>gg', builtin.live_grep, {})
|
vim.keymap.set('n', '<leader>gg', builtin.live_grep, {})
|
||||||
vim.keymap.set('n', '<leader>bb', builtin.buffers, {})
|
vim.keymap.set('n', '<leader>bb', builtin.buffers, {})
|
||||||
vim.keymap.set('n', '<leader>hh', builtin.help_tags, {})
|
vim.keymap.set('n', '<leader>hh', builtin.help_tags, {})
|
||||||
|
|
Reference in a new issue