Skip to content

Commit

Permalink
[#14] Modify definition and goBack commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Quramy committed May 4, 2015
1 parent 19aff42 commit 681fd85
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
18 changes: 13 additions & 5 deletions autoload/tsuquyomi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -317,25 +317,33 @@ function! tsuquyomi#definition()
let l:info = l:res_list[0]
if l:file == l:info.file
" Same file
call tsuquyomi#bufManager#pushNavDef(l:file, {'line': l:line, 'col': l:offset})
call tsuquyomi#bufManager#winPushNavDef(bufwinnr(bufnr('%')), l:file, {'line': l:line, 'col': l:offset})
call cursor(l:info.start.line, l:info.start.offset)
elseif g:tsuquyomi_definition_split == 0
call tsuquyomi#bufManager#winPushNavDef(bufwinnr(bufnr('%')), l:file, {'line': l:line, 'col': l:offset})
execute 'edit +call\ cursor('.l:info.start.line.','.l:info.start.offset.') '.l:info.file
else
elseif g:tsuquyomi_definition_split == 1
" If other file, split window
execute 'split +call\ cursor('.l:info.start.line.','.l:info.start.offset.') '.l:info.file
elseif g:tsuquyomi_definition_split == 2
execute 'vsplit +call\ cursor('.l:info.start.line.','.l:info.start.offset.') '.l:info.file
endif
else
" If don't get result, do nothing.
endif
endfunction

function! tsuquyomi#goBack()
let loc = tsuquyomi#bufManager#popNavDef(expand('%:p'))
if has_key(loc, 'line')
let [type, result] = tsuquyomi#bufManager#winPopNavDef(bufwinnr(bufnr('%')))
if !type
echom '[Tsuquyomi] No items in navigation stack...'
return
endif
let [file_name, loc] = [result.file_name, result.loc]
if expand('%:p') == file_name
call cursor(loc.line, loc.col)
else
echom '[Tsuquyomi] No items in navigation stack...'
execute 'edit +call\ cursor('.loc.line.','.loc.col.') '.file_name
endif
endfunction

Expand Down
18 changes: 18 additions & 0 deletions autoload/tsuquyomi/bufManager.vim
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,23 @@ function! tsuquyomi#bufManager#popNavDef(file_name)
endif
endfunction

let s:win_nav_map = {}
function! tsuquyomi#bufManager#winPushNavDef(winnm, file_name, loc)
if !has_key(s:win_nav_map, a:winnm)
let s:win_nav_map[a:winnm] = []
endif
call add(s:win_nav_map[a:winnm], {'file_name': a:file_name, 'loc': a:loc})
endfunction

function! tsuquyomi#bufManager#winPopNavDef(winnm)
if !has_key(s:win_nav_map, a:winnm)
return [0, {}]
endif
if !len(s:win_nav_map[a:winnm])
return [0, {}]
endif
return [1, remove(s:win_nav_map[a:winnm], -1)]
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
15 changes: 7 additions & 8 deletions doc/tsuquyomi.jax
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*tsuquyomi* はTypeScript向けのVim plugin です.

Version: 0.4.1
Version: 0.4.2
Author : Quramy <yosuke.kurami@gmail.com>
License: MIT license {{{
Permission is hereby granted, free of charge, to any person obtaining
Expand Down Expand Up @@ -133,10 +133,6 @@ Prompt:

:TsuquyomiDefinition *:TsuquyomiDefinition*
シンボルが定義された場所へ遷移させます.
定義箇所がカレントバッファに存在する場合はそこにカーソルを
移動させます.
そうでない場合, 定義箇所を含むファイルを|split|で開いてから
カーソルを移動します.

:TsuquyomiGoBack *:TsuquyomiGoBack*
カーソルを最後に|:TsuquyomiDefinition|を実行した箇所へ
Expand Down Expand Up @@ -204,9 +200,12 @@ g:tsuquyomi_nodejs_path (デフォルト値 'node')
Node.js の実行パス.

*g:tsuquyomi_definition_split*
g:tsuquyomi_definition_split (デフォルト値 1)
別ファイル定義への遷移時, ウィンドウを分割するかどうか.
|:TsuquyomiDefinition| も参考のこと.
g:tsuquyomi_definition_split (デフォルト値 0)
|:TsuquyomiDefinition| にて別ファイル定義への遷移時,
ウィンドウを分割するかどうか.
* 0: |:edit|
* 1: |:split|
* 2: |:vsplit|

------------------------------------------------------------------------------
キーマッピング *tsuquyomi-key-mappings*
Expand Down
13 changes: 6 additions & 7 deletions doc/tsuquyomi.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*tsuquyomi* is a Vim plugin for TypeScript.

Version: 0.4.1
Version: 0.4.2
Author : Quramy <yosuke.kurami@gmail.com>
License: MIT license {{{
Permission is hereby granted, free of charge, to any person obtaining
Expand Down Expand Up @@ -132,10 +132,6 @@ COMMANDS *tsuquyomi-commands*

:TsuquyomiDefinition *:TsuquyomiDefinition*
Navigate to the location where the symbol is defined.
If the location of definition is in the current buffer,
move the cursor.
Otherwise, |split| the current window and open the file which
contains the definition.

:TsuquyomiGoBack *:TsuquyomiGoBack*
Move the cursor position to the location where
Expand Down Expand Up @@ -200,9 +196,12 @@ g:tsuquyomi_nodejs_path (default 'node')


*g:tsuquyomi_definition_split*
g:tsuquyomi_definition_split (default 1)
g:tsuquyomi_definition_split (default 0)
Whether to open a new split when navigating to definition in
another file. See |:TsuquyomiDefinition|.
another file when calling |:TsuquyomiDefinition|.
* 0: |:edit|
* 1: |:split|
* 2: |:vplit|

------------------------------------------------------------------------------
KEY MAPPINGS *tsuquyomi-key-mappings*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsuquyomi",
"version": "0.4.1",
"version": "0.4.2",
"description": "Vim plugin for typescript",
"main": "index.js",
"directories": {
Expand Down
2 changes: 1 addition & 1 deletion plugin/tsuquyomi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let g:tsuquyomi_waittime_after_open=
let g:tsuquyomi_completion_chank_size =
\ get(g:, 'tsuquyomi_completion_chank_size', 15)
let g:tsuquyomi_definition_split =
\ get(g:, 'tsuquyomi_definition_split', 1)
\ get(g:, 'tsuquyomi_definition_split', 0)
" Global options defintion. }}}

" augroup tsuquyomi_global_command_group
Expand Down

0 comments on commit 681fd85

Please sign in to comment.