From 1dc08d4e6342454d960fb461248f8732c13b630f Mon Sep 17 00:00:00 2001 From: Yosuke Kurami Date: Thu, 2 Apr 2015 05:45:31 +0900 Subject: [PATCH] Fix pre configure check --- autoload/tsuquyomi/config.vim | 73 +++++++++++++++++++++++++++++++++ autoload/tsuquyomi/tsClient.vim | 42 +++---------------- ftplugin/typescript.vim | 4 ++ plugin/tsuquyomi.vim | 1 - 4 files changed, 82 insertions(+), 38 deletions(-) create mode 100644 autoload/tsuquyomi/config.vim diff --git a/autoload/tsuquyomi/config.vim b/autoload/tsuquyomi/config.vim new file mode 100644 index 0000000..87b0e45 --- /dev/null +++ b/autoload/tsuquyomi/config.vim @@ -0,0 +1,73 @@ +"============================================================================ +" FILE: config.vim +" AUTHOR: Quramy +"============================================================================ +" +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(':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 diff --git a/autoload/tsuquyomi/tsClient.vim b/autoload/tsuquyomi/tsClient.vim index 6a34c30..c6a648b 100644 --- a/autoload/tsuquyomi/tsClient.vim +++ b/autoload/tsuquyomi/tsClient.vim @@ -8,22 +8,14 @@ scriptencoding utf-8 let s:save_cpo = &cpo set cpo&vim -let s:script_dir = expand(':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(':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' @@ -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 {{{ @@ -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, []) diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim index bfd14b4..ad893cc 100644 --- a/ftplugin/typescript.vim +++ b/ftplugin/typescript.vim @@ -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') diff --git a/plugin/tsuquyomi.vim b/plugin/tsuquyomi.vim index 80a2977..20d3138 100644 --- a/plugin/tsuquyomi.vim +++ b/plugin/tsuquyomi.vim @@ -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