Skip to content

Commit

Permalink
Fix pre configure check
Browse files Browse the repository at this point in the history
  • Loading branch information
Quramy committed Apr 1, 2015
1 parent 4a80700 commit 1dc08d4
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 38 deletions.
73 changes: 73 additions & 0 deletions autoload/tsuquyomi/config.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"============================================================================
" FILE: config.vim
" AUTHOR: Quramy <yosuke.kurami@gmail.com>
"============================================================================
"
scriptencoding utf-8

let s:save_cpo = &cpo
set cpo&vim

let s:V = vital#of('tsuquyomi')
let s:P = s:V.import('ProcessManager')
let s:Filepath = s:V.import('System.Filepath')
let s:script_dir = expand('<sfile>:p:h')

let s:tss_cmd = ''

function! tsuquyomi#config#preconfig()

if !exists('g:tsuquyomi_is_available')
if !s:P.is_available()
" 1. vimproc installation check
let g:tsuquyomi_is_available = 0
call s:deleteCommand()
echom '[Tsuquyomi] Shougo/vimproc.vim is not installed. Please install it.'
else
" 2. tsserver installation check
let s:tss_cmd = tsuquyomi#config#tsscmd()
if s:tss_cmd == ''
let g:tsuquyomi_is_available = 0
call s:deleteCommand()
else
let g:tsuquyomi_is_available = 1
endif
endif
endif

return g:tsuquyomi_is_available
endfunction

function! s:deleteCommand()
delc TsuquyomiStartTss
delc TsuquyomiStopTss
delc TsuquyomiStatusTss
endfunction

function! tsuquyomi#config#tsscmd()
if g:tsuquyomi_use_dev_node_module == 0
let l:cmd = 'tsserver'
if !executable(l:cmd)
echom '[Tsuquyomi] tsserver is not installed. Try "npm -g install git://Microsoft/typescript".'
return ''
endif
else
if g:tsuquyomi_use_dev_node_module == 1
let l:path = s:Filepath.join(s:script_dir, '../../../node_modules/typescript/bin/tsserver.js')
elseif g:tsuquyomi_use_dev_node_module == 2
let l:path = g:tsuquyomi_tsserver_path
else
echom '[Tsuquyomi] Invalid option value "g:tsuquyomi_use_dev_node_module".'
return ''
endif
if filereadable(l:path) != 1
echom '[Tsuquyomi] tsserver.js does not exist. Try "npm install"., '.l:path
return ''
endif
let l:cmd = g:tsuquyomi_nodejs_path.' "'.l:path.'"'
endif
return l:cmd
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
42 changes: 5 additions & 37 deletions autoload/tsuquyomi/tsClient.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,14 @@ scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim

let s:script_dir = expand('<sfile>:p:h')

let s:V = vital#of('tsuquyomi')
let s:P = s:V.import('ProcessManager')

if(!exists(g:tsuquyomi_is_available) && !s:P.is_available())
let g:tsuquyomi_is_available = 0
echom '[Tsuquyomi] Shougo/vimproc.vim is not installed. Please install it.'
finish
endif
if(!g:tsuquyomi_is_available)
if !tsuquyomi#config#preconfig()
finish
endif

let g:tsuquyomi_is_available = 1
let s:script_dir = expand('<sfile>:p:h')

let s:V = vital#of('tsuquyomi')
let s:P = s:V.import('ProcessManager')
let s:JSON = s:V.import('Web.JSON')
let s:Filepath = s:V.import('System.Filepath')
let s:tsq = 'tsuquyomiTSServer'
Expand All @@ -38,29 +30,6 @@ endfunction
function! s:waitTss(sec)
call s:P.read_wait(s:tsq, a:sec, [])
endfunction

function! s:createTssPath()
if g:tsuquyomi_use_dev_node_module == 0
let l:cmd = 'tsserver'
if !executable(l:cmd)
call s:error('tsserver is not installed. Try "npm -g install typescript".')
endif
else
if g:tsuquyomi_use_dev_node_module == 1
let l:path = s:Filepath.join(s:script_dir, '../../node_modules/typescript/bin/tsserver.js')
elseif g:tsuquyomi_use_dev_node_module == 2
let l:path = g:tsuquyomi_tsserver_path
else
call s:error('Invalid option value "g:tsuquyomi_use_dev_node_module".')
endif
if filereadable(l:path) != 1
call s:error('tsserver.js does not exist. Try "npm install"., '.l:path)
endif
let l:cmd = g:tsuquyomi_nodejs_path.' "'.l:path.'"'
endif
return l:cmd
endfunction

" ### Utilites }}}

" ### Core Functions {{{
Expand All @@ -70,8 +39,7 @@ function! tsuquyomi#tsClient#startTss()
if s:P.state(s:tsq) == 'existing'
return 'existing'
endif
let l:cmd = substitute(s:createTssPath(), '\\', '\\\\', 'g')
"echo l:cmd
let l:cmd = substitute(tsuquyomi#config#tsscmd(), '\\', '\\\\', 'g')
let l:is_new = s:P.touch(s:tsq, l:cmd)
if l:is_new == 'new'
let [out, err, type] = s:P.read_wait(s:tsq, 0.1, [])
Expand Down
4 changes: 4 additions & 0 deletions ftplugin/typescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

scriptencoding utf-8

if !tsuquyomi#config#preconfig()
finish
endif

let s:V = vital#of('tsuquyomi')
let s:P = s:V.import('ProcessManager')

Expand Down
1 change: 0 additions & 1 deletion plugin/tsuquyomi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ elseif v:version < 704
endif

let g:loaded_tsuquyomi = 1
let g:tsuquyomi_is_available = 1

let s:save_cpo = &cpo
set cpo&vim
Expand Down

0 comments on commit 1dc08d4

Please sign in to comment.