Fix #340 cache error
This commit is contained in:
parent
e5a11a5a5c
commit
ce3c3d209c
@ -181,6 +181,13 @@ function! neosnippet#helpers#substitute_selected_text(type, text) abort "{{{
|
||||
endtry
|
||||
endfunction"}}}
|
||||
|
||||
function! neosnippet#helpers#vim2json(expr) abort "{{{
|
||||
return has('patch-7.4.1498') ? js_encode(a:expr) : string(a:expr)
|
||||
endfunction "}}}
|
||||
function! neosnippet#helpers#json2vim(expr) abort "{{{
|
||||
sandbox return has('patch-7.4.1498') ? js_decode(a:expr) : eval(a:expr)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_beginning_of_line(cur_text) abort "{{{
|
||||
let keyword_pattern = '\S\+'
|
||||
let cur_keyword_str = matchstr(a:cur_text, keyword_pattern.'$')
|
||||
|
@ -36,15 +36,21 @@ function! neosnippet#parser#_parse_snippets(filename) abort "{{{
|
||||
endif
|
||||
|
||||
let cache_dir = neosnippet#variables#data_dir()
|
||||
if s:Cache.check_old_cache(cache_dir, a:filename)
|
||||
let snippets = {}
|
||||
if !s:Cache.check_old_cache(cache_dir, a:filename)
|
||||
try
|
||||
let snippets = neosnippet#helpers#json2vim(
|
||||
\ s:Cache.readfile(cache_dir, a:filename)[0])
|
||||
catch
|
||||
endtry
|
||||
endif
|
||||
if empty(snippets) || s:Cache.check_old_cache(cache_dir, a:filename)
|
||||
let [snippets, sourced] = s:parse(a:filename)
|
||||
if len(snippets) > 5 && !neosnippet#util#is_sudo() && !sourced
|
||||
call s:Cache.writefile(
|
||||
\ cache_dir, a:filename, [string(snippets)])
|
||||
\ cache_dir, a:filename,
|
||||
\ [neosnippet#helpers#vim2json(snippets)])
|
||||
endif
|
||||
else
|
||||
sandbox let snippets = eval(
|
||||
\ s:Cache.readfile(cache_dir, a:filename)[0])
|
||||
endif
|
||||
|
||||
return snippets
|
||||
|
Loading…
Reference in New Issue
Block a user