diff --git a/README.md b/README.md index 183307b..8c501bb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Tsuquyomi -Tsuquyomi is a Vim plugin for TypeScript developers. +Tsuquyomi is a Vim plugin for TypeScript. ## Features diff --git a/autoload/tsuquyomi.vim b/autoload/tsuquyomi.vim index b23495a..72a491b 100644 --- a/autoload/tsuquyomi.vim +++ b/autoload/tsuquyomi.vim @@ -45,8 +45,8 @@ endfunction " Save current buffer to a temp file, and emit to reload TSServer. " This function may be called for conversation with TSServer after user's change buffer. function! s:flash() - if tsuquyomi#bufManager#isDirty(expand('%')) - let file_name = expand('%') + if tsuquyomi#bufManager#isDirty(expand('%:p')) + let file_name = expand('%:p') call tsuquyomi#bufManager#saveTmp(file_name) call tsuquyomi#tsClient#tsReload(file_name, tsuquyomi#bufManager#tmpfile(file_name)) call tsuquyomi#bufManager#setDirty(file_name, 0) @@ -65,15 +65,31 @@ function! tsuquyomi#rootDir() return s:root_dir endfunction +" #### Server operations {{{ +function! tsuquyomi#startServer() + return tsuquyomi#tsClient#startTss() +endfunction + +function! tsuquyomi#stopServer() + call tsuquyomi#bufManager#clearMap() + return tsuquyomi#tsClient#stopTss() +endfunction + +function! tsuquyomi#statusServer() + return tsuquyomi#tsClient#statusTss() +endfunction + +" #### Server operations }}} + " #### Notify changed {{{ function! tsuquyomi#letDirty() - return tsuquyomi#bufManager#setDirty(expand('%'), 1) + return tsuquyomi#bufManager#setDirty(expand('%:p'), 1) endfunction " #### Notify changed }}} " #### File operations {{{ function! tsuquyomi#open(...) - let filelist = a:0 ? map(range(1, a:{0}), 'expand(a:{v:val})') : [expand('%')] + let filelist = a:0 ? map(range(1, a:{0}), 'expand(a:{v:val})') : [expand('%:p')] for file in filelist if file == '' continue @@ -85,7 +101,7 @@ function! tsuquyomi#open(...) endfunction function! tsuquyomi#close(...) - let filelist = a:0 ? map(range(1, a:{0}), 'expand(a:{v:val})') : [expand('%')] + let filelist = a:0 ? map(range(1, a:{0}), 'expand(a:{v:val})') : [expand('%:p')] let file_count = 0 for file in filelist if tsuquyomi#bufManager#isOpened(file) @@ -113,12 +129,12 @@ function! s:reloadFromList(filelist) endfunction function! tsuquyomi#reload(...) - let filelist = a:0 ? map(range(1, a:{0}), 'expand(a:{v:val})') : [expand('%')] + let filelist = a:0 ? map(range(1, a:{0}), 'expand(a:{v:val})') : [expand('%:p')] return s:reloadFromList(filelist) endfunction function! tsuquyomi#dump(...) - let filelist = a:0 ? map(range(1, a:{0}), 'expand(a:{v:val})') : [expand('%')] + let filelist = a:0 ? map(range(1, a:{0}), 'expand(a:{v:val})') : [expand('%:p')] let [opend, not_opend] = s:checkOpenAndMessage(filelist) for file in opend @@ -148,7 +164,7 @@ endfunction function! tsuquyomi#complete(findstart, base) - if len(s:checkOpenAndMessage([expand('%')])[1]) + if len(s:checkOpenAndMessage([expand('%:p')])[1]) return endif @@ -166,7 +182,7 @@ function! tsuquyomi#complete(findstart, base) call s:flash() return l:start - 1 else - let l:file = expand('%') + let l:file = expand('%:p') let l:res_dict = {'words': []} let l:res_list = tsuquyomi#tsClient#tsCompletions(l:file, l:line, l:start, a:base) @@ -209,13 +225,13 @@ endfunction " #### Definition {{{ function! tsuquyomi#definition() - if len(s:checkOpenAndMessage([expand('%')])[1]) + if len(s:checkOpenAndMessage([expand('%:p')])[1]) return endif call s:flash() - let l:file = s:normalizePath(expand('%')) + let l:file = s:normalizePath(expand('%:p')) let l:line = line('.') let l:offset = col('.') let l:res_list = tsuquyomi#tsClient#tsDefinition(l:file, l:line, l:offset) @@ -240,13 +256,13 @@ endfunction " Show reference on a location window. function! tsuquyomi#references() - if len(s:checkOpenAndMessage([expand('%')])[1]) + if len(s:checkOpenAndMessage([expand('%:p')])[1]) return endif call s:flash() - let l:file = expand('%') + let l:file = expand('%:p') let l:line = line('.') let l:offset = col('.') @@ -278,11 +294,13 @@ endfunction " #### Geterr {{{ function! tsuquyomi#geterr() - if len(s:checkOpenAndMessage([expand('%')])[1]) + if len(s:checkOpenAndMessage([expand('%:p')])[1]) return endif - let l:files = [expand('%')] + call s:flash() + + let l:files = [expand('%:p')] let l:delayMsec = 50 "TODO export global option " 1. Fetch error information from TSServer. @@ -327,7 +345,10 @@ function! tsuquyomi#geterr() endfunction function! tsuquyomi#reloadAndGeterr() - return tsuquyomi#reload() && tsuquyomi#geterr() + if tsuquyomi#tsClient#statusTss() != 'undefined' + return tsuquyomi#geterr() + "return tsuquyomi#reload() && tsuquyomi#geterr() + endif endfunction " #### Geterr }}} @@ -335,11 +356,13 @@ endfunction " #### Balloon {{{ function! tsuquyomi#balloonexpr() - call s:flash() - let l:filename = buffer_name(v:beval_bufnr) - let res = tsuquyomi#tsClient#tsQuickinfo(l:filename, v:beval_lnum, v:beval_col) - if has_key(res, 'displayString') - return res.displayString + if tsuquyomi#tsClient#tsReload() != 'undefined' + call s:flash() + let l:filename = buffer_name(v:beval_bufnr) + let res = tsuquyomi#tsClient#tsQuickinfo(l:filename, v:beval_lnum, v:beval_col) + if has_key(res, 'displayString') + return res.displayString + endif endif endfunction " #### Balloon }}} @@ -347,13 +370,13 @@ endfunction " #### Rename {{{ function! tsuquyomi#renameSymbol() - if len(s:checkOpenAndMessage([expand('%')])[1]) + if len(s:checkOpenAndMessage([expand('%:p')])[1]) return endif call s:flash() - let l:filename = expand('%') + let l:filename = expand('%:p') let l:line = line('.') let l:offset = col('.') @@ -373,7 +396,7 @@ function! tsuquyomi#renameSymbol() " TODO to be able to change multiple buffer. " " * Check affection only current buffer. - if len(l:res_dict.locs) != 1 || s:normalizePath(expand('%')) != l:res_dict.locs[0].file + if len(l:res_dict.locs) != 1 || s:normalizePath(expand('%:p')) != l:res_dict.locs[0].file let file_list = map(copy(l:res_dict.locs), 'v:val.file') let dirty_file_list = tsuquyomi#bufManager#whichDirty(file_list) @@ -430,7 +453,7 @@ function! tsuquyomi#renameSymbol() let buffer_name = tsuquyomi#bufManager#bufName(fileLoc.file) let s:locs_dict[buffer_name] = fileLoc.locs let changed_count = 0 - if buffer_name != expand('%') + if buffer_name != expand('%:p') call add(other_buf_list, buffer_name) continue endif @@ -453,8 +476,8 @@ endfunction function! s:renameLocal() let changed_count = 0 - let filename = expand('%') - let locations_in_buf = s:locs_dict[expand('%')] + let filename = expand('%:p') + let locations_in_buf = s:locs_dict[expand('%:p')] let renameTo = s:rename_to for span in locations_in_buf if span.start.line != span.end.line diff --git a/autoload/tsuquyomi/bufManager.vim b/autoload/tsuquyomi/bufManager.vim index 492afc4..289c24c 100644 --- a/autoload/tsuquyomi/bufManager.vim +++ b/autoload/tsuquyomi/bufManager.vim @@ -18,6 +18,9 @@ endfunction function! tsuquyomi#bufManager#open(file_name) + if bufnr(a:file_name) == -1 + return 0 + endif let info = { \'is_opened': 1, \'is_dirty': 0, @@ -27,6 +30,15 @@ function! tsuquyomi#bufManager#open(file_name) return info endfunction +function! tsuquyomi#bufManager#opendFiles() + return copy(s:buf_info_map) +endfunction + +function! tsuquyomi#bufManager#clearMap() + let s:buf_info_map = {} + return 1 +endfunction + function! tsuquyomi#bufManager#bufName(file_name) let name = s:normalize(a:file_name) if !has_key(s:buf_info_map, name) diff --git a/autoload/tsuquyomi/tsClient.vim b/autoload/tsuquyomi/tsClient.vim index c6a648b..568c475 100644 --- a/autoload/tsuquyomi/tsClient.vim +++ b/autoload/tsuquyomi/tsClient.vim @@ -139,7 +139,7 @@ endfunction function! tsuquyomi#tsClient#sendCommandSyncEvents(cmd, args, delay, length) let l:input = s:JSON.encode({'command': a:cmd, 'arguments': a:args, 'type': 'request', 'seq': s:request_seq}) let l:stdout_list = tsuquyomi#tsClient#sendRequest(l:input, a:delay, 200, a:length) - echo l:stdout_list + "echo l:stdout_list let l:length = len(l:stdout_list) let l:result_list = [] if l:length > 0 diff --git a/doc/tsuquyomi.txt b/doc/tsuquyomi.txt index e4d04dc..8b0056b 100644 --- a/doc/tsuquyomi.txt +++ b/doc/tsuquyomi.txt @@ -1,4 +1,4 @@ -*tsuquyomi.txt* TypeScript editing plugin for Vim +*tsuquyomi* is a Vim plugin for TypeScript. Version: 0.2.0 Author : Quramy @@ -35,7 +35,14 @@ Interface |tsuquyomi-interface| ============================================================================== INTRODUCTION *tsuquyomi-introduction* -Tsuquyomi supports you to edit TypeScript source files using TSServer. +Tsuquyomi works as a client for TSServer(which is an editor service bundled into TypeScript). + +This plugin provides the following functions: + ++ Functions to fetch information of your source codes from TSServer. + (compeletions, locations of definition or references, error, etc...) + ++ Functions to start or stop the TSServer process. ============================================================================== @@ -70,15 +77,15 @@ INTERFACE *tsuquyomi-interface* ------------------------------------------------------------------------------ COMMANDS *tsuquyomi-commands* -:TsuquyomiStartTss *:TsuquyomiStartTss* +:TsuquyomiStartServer *:TsuquyomiStartServer* Start TSServer process using |vimproc|. If already the process is running, this command does not anything. -:TsuquyomiStopTss *:TsuquyomiStopTss* +:TsuquyomiStopServer *:TsuquyomiStopServer* Stop TSServer process if it exists. -:TsuquyomiStatusTss *:TsuquyomiStatusTss* +:TsuquyomiStatusServer *:TsuquyomiStatusServer* Show TSServer status. When TSServer is running, the message 'reading' will be displayed. @@ -139,9 +146,14 @@ g:tsuquyomi_auto_open (default 1) *g:tsuquyomi_use_dev_node_module* g:tsuquyomi_use_dev_node_module (default 0) Whether to use `tsserver.js` that was installed manually. - * 0: Tsuquyomi uses `tsserver` command(default). + * 0: Tsuquyomi uses global installed `tsserver` command(default). * 1: Tsuquyomi uses `tsuquyomi/node_modules/typescript/bin/tsserver.js` . + If you use this mode, exec the following: +> + :cd ~/.vim/bundle/tsuquyomi + :!npm install +< * 2: Tsuquyomi uses `tsserver.js` whose path is |g:tsuquyomi_tsserver_path| . @@ -158,7 +170,7 @@ g:tsuquyomi_tsserver_path (default `''`) *g:tsuquyomi_nodejs_path* g:tsuquyomi_nodejs_path (default 'node') - Node.js's path that Tsuquyomi exec. + A path to Node.js. *g:tsuquyomi_waittime_after_open* g:tsuquyomi_waittime_after_open (default 0.05) @@ -177,12 +189,12 @@ Normal mode key mappings. *(TsuquyomiDefinition)* (TsuquyomiDefinition) - Navigates to the location where the symbol on the cursor is + Navigate to the location where the symbol on the cursor is defined. See |:TsuquyomiDefinition|. *(TsuquyomiReferences)* (TsuquyomiReferences) - Shows a list of locations where the symbol on the cursor is + Show a list of locations where the symbol on the cursor is referenced. See |:TsuquyomiReferences|. *(TsuquyomiRenameSymbol)* @@ -202,9 +214,9 @@ Normal mode default mappings. FUNCTIONS *tsuquyomi-functions* tsuquyomi#balloonexpr *tsuquyomi#balloonexpr* - Returns informations about symbol under mouse pointer for + Returns information about symbol under then mouse cursor for tooltip popover window. - This is used as rhs for |balloon-expr|. + This is used as the rhs for |balloon-expr|. For example, > set ballooneval diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim index ad893cc..576e7e3 100644 --- a/ftplugin/typescript.vim +++ b/ftplugin/typescript.vim @@ -39,8 +39,6 @@ noremap (TsuquyomiRenameSymbol) :TsuquyomiRenameSymbol augroup tsuquyomi_defaults autocmd! - autocmd BufNewFile,BufRead *.ts setlocal omnifunc=tsuquyomi#complete - "autocmd BufWritePost *.ts silent! call tsuquyomi#reload() autocmd BufWritePost *.ts silent! call tsuquyomi#reloadAndGeterr() autocmd TextChanged,TextChangedI *.ts silent! call tsuquyomi#letDirty() augroup END diff --git a/plugin/tsuquyomi.vim b/plugin/tsuquyomi.vim index 20d3138..df6ff63 100644 --- a/plugin/tsuquyomi.vim +++ b/plugin/tsuquyomi.vim @@ -41,9 +41,9 @@ let g:tsuquyomi_completion_chank_size = " augroup END " Define commands to operate TSServer -command! TsuquyomiStartTss : call tsuquyomi#tsClient#startTss() -command! TsuquyomiStatusTss : echom tsuquyomi#tsClient#statusTss() -command! TsuquyomiStopTss : call tsuquyomi#tsClient#stopTss() +command! TsuquyomiStartServer : call tsuquyomi#startServer() +command! TsuquyomiStatusServer : echom tsuquyomi#statusServer() +command! TsuquyomiStopServer : call tsuquyomi#stopServer() let &cpo = s:save_cpo unlet s:save_cpo diff --git a/test/tsuquyomi/tsClient/tsCompletionEntryDetails.test.vim b/test/tsuquyomi/tsClient/tsCompletionEntryDetails.test.vim index 4b236b9..675bd9f 100644 --- a/test/tsuquyomi/tsClient/tsCompletionEntryDetails.test.vim +++ b/test/tsuquyomi/tsClient/tsCompletionEntryDetails.test.vim @@ -10,8 +10,9 @@ let s:Filepath = s:V.import('System.Filepath') let s:script_dir = tsuquyomi#rootDir() "TODO remove later -let g:tsuquyomi_use_dev_node_module = 2 -let g:tsuquyomi_tsserver_path = s:Filepath.join(s:script_dir, '../../git/typescript/built/local/tsserver.js') +let g:tsuquyomi_use_dev_node_module = 0 +"let g:tsuquyomi_tsserver_path = s:Filepath.join(s:script_dir, '/git/typescript/built/local/tsserver.js') +"let g:tsuquyomi_tsserver_path = s:Filepath.join(s:script_dir, '/git/typescript/built/local/tsserver.js') function! s:test1() let l:file = s:Filepath.join(s:script_dir, 'test/resources/SimpleModule_writing.ts') diff --git a/test/tsuquyomi/tsClient/tsCompletions.test.vim b/test/tsuquyomi/tsClient/tsCompletions.test.vim index d9af8b2..08c9da7 100644 --- a/test/tsuquyomi/tsClient/tsCompletions.test.vim +++ b/test/tsuquyomi/tsClient/tsCompletions.test.vim @@ -2,7 +2,7 @@ scriptencoding utf-8 UTSuite [tsuquyomi#tsClient#tsCompletions] tsCompletions -let g:tsuquyomi_use_dev_node_module=1 +"let g:tsuquyomi_use_dev_node_module=1 let g:tsuquyomi_waittime_after_open=0.001 let s:V = vital#of('tsuquyomi') @@ -10,8 +10,8 @@ let s:Filepath = s:V.import('System.Filepath') let s:script_dir = tsuquyomi#rootDir() "TODO remove later -let g:tsuquyomi_use_dev_node_module = 2 -let g:tsuquyomi_tsserver_path = s:Filepath.join(s:script_dir, '../../git/typescript/built/local/tsserver.js') +"let g:tsuquyomi_use_dev_node_module = 2 +"let g:tsuquyomi_tsserver_path = s:Filepath.join(s:script_dir, '../../git/typescript/built/local/tsserver.js') function! s:test1() let l:file = s:Filepath.join(s:script_dir, 'test/resources/SimpleModule.ts') diff --git a/test/tsuquyomi/tsClient/tsGeterr.test.vim b/test/tsuquyomi/tsClient/tsGeterr.test.vim index dd424d2..b8ec484 100644 --- a/test/tsuquyomi/tsClient/tsGeterr.test.vim +++ b/test/tsuquyomi/tsClient/tsGeterr.test.vim @@ -2,7 +2,7 @@ scriptencoding utf-8 UTSuite [tsuquyomi#tsClient#tsGeterr] tsGeterr -let g:tsuquyomi_use_dev_node_module=1 +"let g:tsuquyomi_use_dev_node_module=1 let g:tsuquyomi_waittime_after_open=0.001 let s:V = vital#of('tsuquyomi')