Skip to content

Commit

Permalink
Update Vital modules
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Jun 11, 2020
1 parent 5307148 commit 33f0fab
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion autoload/vital/_fern/Async/File.vim
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ else
endfunction
" freedesktop
" https://www.freedesktop.org/wiki/Specifications/trash-spec/
function! s:trash(path) abort
function! s:trash(path, ...) abort
throw 'vital: Async.File: trash(): Not supported platform.'
endfunction
endif
Expand Down
19 changes: 13 additions & 6 deletions autoload/vital/_fern/Async/Promise.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_fern#Async#Promise#import() abort', printf("return map({'resolve': '', '_vital_depends': '', 'wait': '', '_vital_created': '', 'all': '', 'noop': '', 'is_promise': '', 'race': '', 'is_available': '', 'reject': '', 'new': '', '_vital_loaded': ''}, \"vital#_fern#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
execute join(['function! vital#_fern#Async#Promise#import() abort', printf("return map({'resolve': '', '_vital_depends': '', 'wait': '', '_vital_created': '', 'all': '', 'noop': '', 'on_unhandled_rejection': '', 'is_promise': '', 'race': '', 'is_available': '', 'reject': '', 'new': '', '_vital_loaded': ''}, \"vital#_fern#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction s:_SID
" ___vital___
" ECMAScript like Promise library for asynchronous operations.
Expand Down Expand Up @@ -35,18 +35,15 @@ function! s:_vital_depends() abort
return ['Async.Later']
endfunction

" @vimlint(EVL103, 1, a:resolve)
" @vimlint(EVL103, 1, a:reject)
function! s:noop(resolve, reject) abort
function! s:noop(...) abort
endfunction
" @vimlint(EVL103, 0, a:resolve)
" @vimlint(EVL103, 0, a:reject)
let s:NOOP = funcref('s:noop')

" Internal APIs

let s:PROMISE = {
\ '_state': s:PENDING,
\ '_has_floating_child': v:false,
\ '_children': [],
\ '_fulfillments': [],
\ '_rejections': [],
Expand Down Expand Up @@ -99,6 +96,9 @@ function! s:_publish(promise, ...) abort
endif

if empty(a:promise._children)
if settled == s:REJECTED && !a:promise._has_floating_child
call s:_on_unhandled_rejection(a:promise._result)
endif
return
endif

Expand Down Expand Up @@ -279,15 +279,22 @@ function! s:wait(promise, ...) abort
endif
endfunction

let s:_on_unhandled_rejection = s:NOOP
function! s:on_unhandled_rejection(on_unhandled_rejection) abort
let s:_on_unhandled_rejection = a:on_unhandled_rejection
endfunction

function! s:_promise_then(...) dict abort
let parent = self
let state = parent._state
let child = s:new(s:NOOP)
let l:Res = a:0 > 0 ? a:1 : v:null
let l:Rej = a:0 > 1 ? a:2 : v:null
if state == s:FULFILLED
let parent._has_floating_child = v:true
call s:Later.call(funcref('s:_invoke_callback', [state, child, Res, parent._result]))
elseif state == s:REJECTED
let parent._has_floating_child = v:true
call s:Later.call(funcref('s:_invoke_callback', [state, child, Rej, parent._result]))
else
call s:_subscribe(parent, child, Res, Rej)
Expand Down
17 changes: 14 additions & 3 deletions autoload/vital/_fern/System/Filepath.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_fern#System#Filepath#import() abort', printf("return map({'path_separator': '', 'is_case_tolerant': '', 'dirname': '', 'abspath': '', 'relpath': '', 'realpath': '', 'unify_separator': '', 'to_slash': '', 'is_root_directory': '', 'split': '', 'path_extensions': '', 'unixpath': '', 'which': '', 'winpath': '', 'from_slash': '', 'join': '', 'separator': '', 'is_relative': '', 'basename': '', 'remove_last_separator': '', 'is_absolute': '', 'contains': ''}, \"vital#_fern#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
execute join(['function! vital#_fern#System#Filepath#import() abort', printf("return map({'path_separator': '', 'is_case_tolerant': '', 'dirname': '', 'abspath': '', 'relpath': '', 'realpath': '', 'unify_separator': '', 'to_slash': '', 'is_root_directory': '', 'split': '', 'path_extensions': '', 'unixpath': '', 'which': '', 'winpath': '', 'from_slash': '', 'join': '', 'expand_home': '', 'separator': '', 'is_relative': '', 'basename': '', 'remove_last_separator': '', 'is_absolute': '', 'contains': ''}, \"vital#_fern#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction s:_SID
" ___vital___
" You should check the following related builtin functions.
Expand Down Expand Up @@ -206,12 +206,23 @@ function! s:is_case_tolerant() abort
endfunction


function! s:expand_home(path) abort
if a:path[:0] !=# '~'
return a:path
endif
let post_home_idx = match(a:path, s:path_sep_pattern)
return post_home_idx is# -1
\ ? s:remove_last_separator(expand(a:path))
\ : s:remove_last_separator(expand(a:path[0 : post_home_idx - 1]))
\ . a:path[post_home_idx :]
endfunction

function! s:abspath(path) abort
if s:is_absolute(a:path)
return a:path
endif
" Note:
" the behavior of ':p' for non existing file path/directory is not defined
" NOTE: The behavior of ':p' for a non existing file/directory path
" is not defined.
return (filereadable(a:path) || isdirectory(a:path))
\ ? fnamemodify(a:path, ':p')
\ : s:join(fnamemodify(getcwd(), ':p'), a:path)
Expand Down
2 changes: 1 addition & 1 deletion autoload/vital/fern.vital
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fern
2f39c1dac08f8239f0ea776b857e3c9b9d3e5fdb
8043f4d0f577ffb654cab9cfe629312b36c5342d

App.Spinner
Async.CancellationTokenSource
Expand Down

0 comments on commit 33f0fab

Please sign in to comment.