Skip to content

Commit

Permalink
Fix rename, cd issue, etc...
Browse files Browse the repository at this point in the history
  • Loading branch information
Quramy committed Apr 2, 2015
1 parent e5410cb commit 6c7c0c7
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tsuquyomi

Tsuquyomi is a Vim plugin for TypeScript developers.
Tsuquyomi is a Vim plugin for TypeScript.

## Features

Expand Down
77 changes: 50 additions & 27 deletions autoload/tsuquyomi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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('.')

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -327,33 +345,38 @@ 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 }}}

" #### 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 }}}

" #### 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('.')

Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions autoload/tsuquyomi/bufManager.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion autoload/tsuquyomi/tsClient.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 23 additions & 11 deletions doc/tsuquyomi.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*tsuquyomi.txt* TypeScript editing plugin for Vim
*tsuquyomi* is a Vim plugin for TypeScript.

Version: 0.2.0
Author : Quramy <yosuke.kurami@gmail.com>
Expand Down Expand Up @@ -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.


==============================================================================
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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| .

Expand All @@ -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)
Expand All @@ -177,12 +189,12 @@ Normal mode key mappings.

*<Plug>(TsuquyomiDefinition)*
<Plug>(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|.

*<Plug>(TsuquyomiReferences)*
<Plug>(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|.

*<Plug>(TsuquyomiRenameSymbol)*
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions ftplugin/typescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ noremap <silent> <buffer> <Plug>(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
Expand Down
6 changes: 3 additions & 3 deletions plugin/tsuquyomi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions test/tsuquyomi/tsClient/tsCompletionEntryDetails.test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading

0 comments on commit 6c7c0c7

Please sign in to comment.