1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-04-14 07:09:11 +08:00

pref(neosnippet): update bundle neosnippet

This commit is contained in:
wsdjeg 2022-04-25 12:30:38 +08:00
parent 2ad0bb02b3
commit e4c3fa7210
14 changed files with 213 additions and 94 deletions

View File

@ -21,6 +21,7 @@ In `bundle/` directory, there are two kinds of plugins: forked plugins without c
- [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig/tree/507f8a570ac2b8b8dabdd0f62da3b3194bf822f8)
- [deoplete-lsp](https://github.com/deoplete-plugins/deoplete-lsp/tree/c466c955e85d995984a8135e16da71463712e5e5)
- [nvim-cmp](https://github.com/hrsh7th/nvim-cmp/tree/3192a0c57837c1ec5bf298e4f3ec984c7d2d60c0)
- [coc-neosnippet](https://github.com/notomo/cmp-neosnippet/tree/2d14526af3f02dcea738b4cea520e6ce55c09979)
- [cmp-neosnippet](https://github.com/notomo/cmp-neosnippet/tree/2d14526af3f02dcea738b4cea520e6ce55c09979)
- [deoplete](https://github.com/Shougo/deoplete.nvim/tree/1c40f648d2b00e70beb4c473b7c0e32b633bd9ae)
- [vim-scala@7657218](https://github.com/derekwyatt/vim-scala/tree/7657218f14837395a4e6759f15289bad6febd1b4)
- [neosnippet.vim@5973e80](https://github.com/Shougo/neosnippet.vim/tree/5973e801e7ad38a01e888cb794d74e076a35ea9b)

View File

@ -0,0 +1,12 @@
# These are supported funding model platforms
github: Shougo # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@ -16,7 +16,7 @@ let s:source = {
\}
function! s:source.gather_candidates(context) abort
let snippets = values(neosnippet#helpers#get_completion_snippets())
let snippets = neosnippet#helpers#get_completion_snippets()
if matchstr(a:context.input, '\S\+$') !=#
\ matchstr(a:context.input, '\w\+$')
" Word filtering

View File

@ -53,8 +53,8 @@ function! neosnippet#helpers#get_snippets(...) abort
return snippets
endfunction
function! neosnippet#helpers#get_completion_snippets() abort
return filter(neosnippet#helpers#get_snippets(),
\ "!get(v:val.options, 'oneshot', 0)")
return values(filter(neosnippet#helpers#get_snippets(),
\ "!get(v:val.options, 'oneshot', 0)"))
endfunction
function! neosnippet#helpers#get_snippets_directory(...) abort
@ -216,3 +216,39 @@ function! neosnippet#helpers#get_snippet_files(filetype) abort
endfor
return s:get_list().uniq(snippet_files)
endfunction
function! neosnippet#helpers#get_user_data(completed_item) abort
if !has_key(a:completed_item, 'user_data')
return {}
endif
let user_data = {}
if type(a:completed_item.user_data) ==# v:t_dict
let user_data = a:completed_item.user_data
else
silent! let user_data = json_decode(a:completed_item.user_data)
endif
if type(user_data) !=# v:t_dict || empty(user_data)
return {}
endif
return user_data
endfunction
function! neosnippet#helpers#get_lspitem(user_data) abort
if has_key(a:user_data, 'lspitem') && type(a:user_data.lspitem) == v:t_dict
" For vim-lsp
let lspitem = a:user_data.lspitem
elseif has_key(a:user_data, 'nvim')
\ && type(a:user_data.nvim) == v:t_dict
\ && has_key(a:user_data.nvim, 'lsp')
\ && type(a:user_data.nvim.lsp) == v:t_dict
\ && has_key(a:user_data.nvim.lsp, 'completion_item')
\ && type(a:user_data.nvim.lsp.completion_item) == v:t_dict
" For nvim-lsp
let lspitem = a:user_data.nvim.lsp.completion_item
else
let lspitem = {}
endif
return lspitem
endfunction

View File

@ -71,6 +71,7 @@ function! s:initialize_others() abort
if g:neosnippet#enable_complete_done
autocmd neosnippet CompleteDone * call neosnippet#complete_done()
autocmd neosnippet User PumCompleteDone call neosnippet#complete_done()
endif
if g:neosnippet#enable_snipmate_compatibility

View File

@ -123,7 +123,7 @@ endfunction
function! neosnippet#mappings#_anonymous(snippet) abort
let [cur_text, col, expr] = neosnippet#mappings#_pre_trigger()
let expr .= printf("\<ESC>:call neosnippet#view#_insert(%s, {}, %s, %d)\<CR>",
let expr .= printf("\<C-c>:call neosnippet#view#_insert(%s, {}, %s, %d)\<CR>",
\ string(a:snippet), string(cur_text), col)
return expr
@ -131,7 +131,7 @@ endfunction
function! neosnippet#mappings#_expand(trigger) abort
let [cur_text, col, expr] = neosnippet#mappings#_pre_trigger()
let expr .= printf("\<ESC>:call neosnippet#view#_expand(%s, %d, %s)\<CR>",
let expr .= printf("\<C-c>:call neosnippet#view#_expand(%s, %d, %s)\<CR>",
\ string(cur_text), col, string(a:trigger))
return expr
@ -151,12 +151,12 @@ function! s:snippets_expand(cur_text, col) abort
return 1
endfunction
function! s:get_completed_snippets(cur_text, col) abort
if empty(get(v:, 'completed_item', {}))
let completed_item = neosnippet#util#get_completed_item()
if empty(completed_item)
return []
endif
let user_data = get(v:completed_item, 'user_data', '')
if user_data !=# ''
if has_key(completed_item, 'user_data')
let ret = s:get_user_data(a:cur_text)
if !empty(ret)
return [ret[0], ret[1], ret[2]]
@ -165,7 +165,7 @@ function! s:get_completed_snippets(cur_text, col) abort
if g:neosnippet#enable_completed_snippet
let snippet = neosnippet#parser#_get_completed_snippet(
\ v:completed_item, a:cur_text, neosnippet#util#get_next_text())
\ completed_item, a:cur_text, neosnippet#util#get_next_text())
if snippet !=# ''
return [a:cur_text, snippet, {}]
endif
@ -174,41 +174,45 @@ function! s:get_completed_snippets(cur_text, col) abort
return []
endfunction
function! s:get_user_data(cur_text) abort
let user_data = json_decode(v:completed_item.user_data)
if type(user_data) !=# v:t_dict
let completed_item = neosnippet#util#get_completed_item()
let user_data = neosnippet#helpers#get_user_data(completed_item)
if type(completed_item.user_data) ==# v:t_dict
let user_data = completed_item.user_data
else
silent! let user_data = json_decode(completed_item.user_data)
endif
if type(user_data) !=# v:t_dict || empty(user_data)
return []
endif
let cur_text = a:cur_text
let has_lspitem = has_key(user_data, 'lspitem')
let snippet_trigger = ''
let snippet = ''
let snippet_trigger = completed_item.word
if has_lspitem && type(user_data.lspitem) == v:t_dict
let lspitem = user_data.lspitem
let lspitem = neosnippet#helpers#get_lspitem(user_data)
let has_lspitem = v:false
if !empty(lspitem)
if has_key(lspitem, 'textEdit') && type(lspitem.textEdit) == v:t_dict
let snippet = lspitem.textEdit.newText
let snippet_trigger = v:completed_item.word
let has_lspitem = v:true
elseif get(lspitem, 'insertTextFormat', -1) == 2
let snippet = lspitem.insertText
let snippet_trigger = v:completed_item.word
let snippet = get(lspitem, 'insertText', lspitem.label)
let has_lspitem = v:true
endif
elseif get(user_data, 'snippet', '') !=# ''
let snippet = user_data.snippet
let snippet_trigger = get(user_data, 'snippet_trigger',
\ v:completed_item.word)
endif
if snippet_trigger !=# ''
" Substitute $0, $1, $2,... to ${0}, ${1}, ${2}...
let snippet = substitute(snippet, '\$\(\d\+\)', '${\1}', 'g')
" Substitute quotes
let snippet = substitute(snippet, "'", "''", 'g')
let cur_text = cur_text[: -1-len(snippet_trigger)]
return [cur_text, snippet, {'lspitem': has_lspitem}]
if snippet ==# ''
return []
endif
return []
" Substitute $0, $1, $2,... to ${0}, ${1}, ${2}...
let snippet = substitute(snippet, '\$\(\d\+\)', '${\1}', 'g')
let cur_text = cur_text[: -1-len(snippet_trigger)]
return [cur_text, snippet, {'lspitem': has_lspitem}]
endfunction
function! neosnippet#mappings#_complete_done(cur_text, col) abort
let ret = s:get_completed_snippets(a:cur_text, a:col)
@ -253,7 +257,7 @@ function! neosnippet#mappings#_trigger(function) abort
let [cur_text, col, expr] = neosnippet#mappings#_pre_trigger()
let expr .= printf("\<ESC>:call %s(%s,%d)\<CR>",
let expr .= printf("\<C-c>:call %s(%s,%d)\<CR>",
\ a:function, string(cur_text), col)
return expr

View File

@ -238,7 +238,6 @@ function! s:set_snippet_dict(snippet_dict, snippets, dup_check, snippets_file) a
if exists('*json_encode')
let alias_snippet.user_data = json_encode({
\ 'snippet': alias_snippet.snip,
\ 'snippet_trigger': alias,
\ })
endif
@ -274,7 +273,6 @@ function! neosnippet#parser#_initialize_snippet(dict, path, line, pattern, name)
if exists('*json_encode')
let snippet.user_data = json_encode({
\ 'snippet': a:dict.word,
\ 'snippet_trigger': a:dict.name,
\ })
endif
@ -296,6 +294,19 @@ function! neosnippet#parser#_initialize_snippet_options() abort
\ }
endfunction
function! s:include_snippets(globs) abort
let snippets = {}
for glob in a:globs
let snippets_dir = neosnippet#helpers#get_snippets_directory(
\ fnamemodify(glob, ':r'))
for file in split(globpath(join(snippets_dir, ','), glob), '\n')
call extend(snippets, neosnippet#parser#_parse_snippets(file))
endfor
endfor
return snippets
endfunction
function! neosnippet#parser#_get_completed_snippet(completed_item, cur_text, next_text) abort
let item = a:completed_item
@ -318,14 +329,12 @@ function! neosnippet#parser#_get_completed_snippet(completed_item, cur_text, nex
call add(abbrs, item.word)
endif
if get(item, 'user_data', '') !=# ''
let user_data = json_decode(item.user_data)
if type(user_data) ==# v:t_dict && has_key(user_data, 'lspitem')
" Use lspitem userdata
let lspitem = user_data.lspitem
if has_key(lspitem, 'label')
call add(abbrs, lspitem.label)
endif
let completed_item = neosnippet#util#get_completed_item()
let user_data = neosnippet#helpers#get_user_data(completed_item)
if !empty(user_data)
let lspitem = neosnippet#helpers#get_lspitem(user_data)
if has_key(lspitem, 'label')
call add(abbrs, lspitem.label)
endif
endif
@ -452,16 +461,3 @@ function! neosnippet#parser#_conceal_argument(arg, cnt, args) abort
endif
return printf('%s${%d:#:%s%s}', outside, a:cnt, inside, escape(a:arg, '{}'))
endfunction
function! s:include_snippets(globs) abort
let snippets = {}
for glob in a:globs
let snippets_dir = neosnippet#helpers#get_snippets_directory(
\ fnamemodify(glob, ':r'))
for file in split(globpath(join(snippets_dir, ','), glob), '\n')
call extend(snippets, neosnippet#parser#_parse_snippets(file))
endfor
endfor
return snippets
endfunction

View File

@ -161,3 +161,8 @@ function! neosnippet#util#uniq(list) abort
endwhile
return list
endfunction
function! neosnippet#util#get_completed_item() abort
return exists('g:pum#completed_item')?
\ g:pum#completed_item : get(v:, 'completed_item', {})
endfunction

View File

@ -28,7 +28,7 @@ function! s:source.hooks.on_init(args, context) abort
let a:context.source__cur_keyword_pos =
\ s:get_keyword_pos(neosnippet#util#get_cur_text())
let a:context.source__snippets =
\ sort(values(neosnippet#helpers#get_completion_snippets()))
\ sort(neosnippet#helpers#get_completion_snippets())
endfunction
function! s:source.gather_candidates(args, context) abort

View File

@ -0,0 +1,48 @@
import {
BaseSource,
Candidate,
Context,
} from "https://deno.land/x/ddc_vim@v0.13.0/types.ts";
import { Denops, fn } from "https://deno.land/x/ddc_vim@v0.13.0/deps.ts#^";
export class Source extends BaseSource<{}> {
async gatherCandidates(args: {
denops: Denops;
context: Context;
}): Promise<Candidate[]> {
const snippets = await args.denops.call(
"neosnippet#helpers#get_completion_snippets",
) as Record<
string,
unknown
>[];
if (!snippets) {
return [];
}
const wordMatch = /\w+$/.exec(args.context.input);
const charsMatch = /\S+$/.exec(args.context.input);
const isWord = wordMatch && charsMatch && wordMatch[0] == charsMatch[0];
const ret: Record<string, Candidate> = {} as Record<string, Candidate>;
for (const key in snippets) {
const val = snippets[key];
const options = val.options as Record<string, Candidate>;
if (
(!options.head || /^\s*\S+$/.test(args.context.input)) &&
(!options.word || isWord) &&
(!val.regexp ||
await fn.matchstr(args.denops, args.context.input, val.regexp) != "")
) {
const word = val.word as string;
if (!(word in ret)) {
ret[word] = { word, menu: val.menu_abbr as string, };
}
}
}
return Object.values(ret);
}
params(): {} { return {}; }
}

View File

@ -40,11 +40,9 @@ Default snippets files are available in neosnippet-snippets.
https://github.com/Shougo/neosnippet-snippets
Note: Installing the default snippets is optional. If you choose not to
install them, you must set |g:neosnippet#disable_runtime_snippets|. >
them, you must set |g:neosnippet#disable_runtime_snippets|. >
let g:neosnippet#disable_runtime_snippets = {
\ '_' : 1,
\ }
install them, you must set |g:neosnippet#disable_runtime_snippets| like so:
>
let g:neosnippet#disable_runtime_snippets = {'_' : 1}
Extra snippets files are also available. e.g.:
https://github.com/honza/vim-snippets
@ -218,15 +216,16 @@ g:neosnippet#enable_conceal_markers
g:neosnippet#enable_completed_snippet
If this variable is not 0, neosnippet can expand the function
prototype.
Note: It supports |vim-lsp| or |nvim-lsp| snippets.
The default value is 0.
*g:neosnippet#enable_complete_done*
g:neosnippet#enable_complete_done
If this variable is not 0, neosnippet can expand on
|CompleteDone|.
|CompleteDone| or |PumCompleteDone|for |pum.vim|.
Note: If the feature is enabled, you cannot expand snippet
trigger manually when |pumvisible()|to prevent conflicts with
trigger manually when |pumvisible()| to prevent conflicts with
|CompleteDone| expand.
The default value is 0.
@ -443,9 +442,9 @@ Example:
alias [aliases]
regexp [pattern]
options [options]
if ${1:condition}
${2}
endif
if ${1:condition}
${2}
endif
The snippet syntax is close to the one of |snipMate|. Each snippet starts with
some keywords that define the name and modify the expansion and treatment of
@ -480,19 +479,12 @@ Snippet Keywords:
A pattern can be defined via a regular expression. The snippet expands
only when the expression pattern is matched.
Note: [pattern] must be quoted by "'" or '"'.
Note: It does not mean auto expand feature.
Example
>
regexp '^% '
<
This snippet works same as "options head".
>
snippet if
regexp '^\s*'
if ${1:condition}
${2}
endif
<
- options [options] (Optional)
@ -515,9 +507,9 @@ Snippet Keywords:
>
snippet if
options head
if ${1:condition}
${2}
endif
if ${1:condition}
${2}
endif
<
+ indent The horizontal position of the snippet will be adjusted
@ -545,9 +537,9 @@ The structure of a placeholder can be:
>
snippet if
if ${1:condition}
${2}
endif
if ${1:condition}
${2}
endif
<
- ${number:#:optional placeholder text}
@ -560,9 +552,9 @@ The structure of a placeholder can be:
>
snippet if
if ${1:#:condition}
${2}
endif
if ${1:condition}
${2}
endif
<
- ${number:TARGET}
@ -581,9 +573,9 @@ The structure of a placeholder can be:
>
snippet if
if ${1:#:condition}
${2:TARGET}
endif
if ${1:condition}
${2}
endif
<
- ${number}
@ -596,11 +588,11 @@ The structure of a placeholder can be:
>
snippet if
if ${1:#:condition}
${2:do}
endif
if ${1:condition}
${2}
endif
${3}
${3}
<
- $number
@ -808,8 +800,17 @@ neosnippet *neosnippet-unite-action-neosnippet*
expand Expand snippet (default action)
edit Edit snippet
preview View snippet definition
==============================================================================
FAQ *neosnippet-faq*
Q: How to donate money to you?
A: I have started github sponsorship to spend more time for Vim/neovim
plugins. You can donate money to help me!
https://github.com/sponsors/Shougo
Q: What if I want to expand a snippet trigger after (, [, " etc...:
A: You should use "options word" in the snippet definition. This changes the
@ -876,10 +877,25 @@ Note: It works in "func(arg1, arg2, ...)" prototypes only.
Note: It is experiental feature.
Note: |v:completed_item| feature is needed.
Q: I want to auto complete with parameters.
Q: I want to expand auto completed parameters.
Q: I want to use |vim-lsp| or |nvim-lsp| snippets with neosnippet.
A: >
let g:neosnippet#enable_completed_snippet = 1
let g:neosnippet#enable_complete_done = 1
Q. How to enable neosnippet the completion in ddc.vim?
A. >
call ddc#custom#patch_global('sources', ['neosnippet'])
call ddc#custom#patch_global('sourceOptions', {
\ '_': {
\ 'matchers': ['matcher_head'],
\ 'sorters': ['sorter_rank']
\ },
\ 'neosnippet': {'mark': 'ns', 'dup': v:true},
\ })
<
==============================================================================
vim:tw=78:ts=8:ft=help:norl:noet:fen:noet:

View File

@ -1,5 +1,5 @@
"=============================================================================
" FILE: snippets.vim
" FILE: neosnippet.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
" License: MIT license
"=============================================================================

View File

@ -19,7 +19,7 @@ class Source(Base):
def on_init(self, context):
self._snippets = self.vim.eval(
'values(neosnippet#helpers#get_completion_snippets())')
'neosnippet#helpers#get_completion_snippets()')
def gather_candidates(self, context):
candidates = []

View File

@ -19,7 +19,7 @@ class Source(Base):
def on_event(self, context):
self.__cache[context['filetype']] = self.vim.eval(
'values(neosnippet#helpers#get_completion_snippets())')
'neosnippet#helpers#get_completion_snippets()')
for candidate in self.__cache[context['filetype']]:
candidate['dup'] = 1
candidate['menu'] = candidate['menu_abbr']