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')
|
||||
|
||||
vim.cmd [[set shortmess+=c]]
|
||||
utils.opt('o', 'completeopt', 'menuone,noselect')
|
||||
|
||||
local cmp = require('cmp')
|
||||
|
@ -50,13 +49,13 @@ cmp.setup({
|
|||
end
|
||||
},
|
||||
snippet = {
|
||||
-- REQUIRED - you must specify a snippet engine
|
||||
expand = function(args)
|
||||
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
|
||||
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
||||
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
|
||||
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
|
||||
end,
|
||||
expand = function(args)
|
||||
local luasnip = require("luasnip")
|
||||
if not luasnip then
|
||||
return
|
||||
end
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
window = {
|
||||
completion = cmp.config.window.bordered(),
|
||||
|
@ -74,10 +73,7 @@ cmp.setup({
|
|||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'vsnip' }, -- For vsnip users.
|
||||
-- { name = 'luasnip' }, -- For luasnip users.
|
||||
-- { name = 'ultisnips' }, -- For ultisnips users.
|
||||
-- { name = 'snippy' }, -- For snippy users.
|
||||
{ name = 'luasnip' }, -- For luasnip users.
|
||||
}, {
|
||||
{ name = 'buffer' },
|
||||
})
|
||||
|
|
|
@ -32,10 +32,15 @@ require('packer').startup(function()
|
|||
{ 'hrsh7th/cmp-buffer' },
|
||||
{ 'hrsh7th/cmp-path' },
|
||||
{ '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
|
||||
use { 'vim-airline/vim-airline' }
|
||||
|
@ -46,7 +51,7 @@ require('packer').startup(function()
|
|||
use { 'weilbith/nvim-code-action-menu', cmd = 'CodeActionMenu' }
|
||||
use { 'folke/trouble.nvim' } -- lsp diagnostics
|
||||
|
||||
-- Languages
|
||||
-- Languages that need a plugin to extend default lsp
|
||||
use { 'cespare/vim-toml' }
|
||||
use { 'gleam-lang/gleam.vim' }
|
||||
use { 'rust-lang/rust.vim' }
|
||||
|
@ -71,6 +76,7 @@ require('packer').startup(function()
|
|||
|
||||
end)
|
||||
|
||||
require('plugins.luasnip')
|
||||
require('plugins.cmp')
|
||||
require('plugins.gitsigns')
|
||||
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 builtin = require('telescope.builtin')
|
||||
|
||||
local luasnip = require('luasnip')
|
||||
local lst = telescope.extensions.luasnip
|
||||
|
||||
telescope.setup {
|
||||
defaults = {
|
||||
layout_strategy = "vertical",
|
||||
|
@ -31,10 +34,22 @@ telescope.setup {
|
|||
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>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>bb', builtin.buffers, {})
|
||||
vim.keymap.set('n', '<leader>hh', builtin.help_tags, {})
|
||||
|
|
Loading…
Reference in a new issue