From 681fd85056170aec02459cd70e670e607867a200 Mon Sep 17 00:00:00 2001 From: y-kurami Date: Tue, 5 May 2015 00:54:31 +0900 Subject: [PATCH] [#14] Modify definition and goBack commands --- autoload/tsuquyomi.vim | 18 +++++++++++++----- autoload/tsuquyomi/bufManager.vim | 18 ++++++++++++++++++ doc/tsuquyomi.jax | 15 +++++++-------- doc/tsuquyomi.txt | 13 ++++++------- package.json | 2 +- plugin/tsuquyomi.vim | 2 +- 6 files changed, 46 insertions(+), 22 deletions(-) diff --git a/autoload/tsuquyomi.vim b/autoload/tsuquyomi.vim index 9e09228..d3c91da 100644 --- a/autoload/tsuquyomi.vim +++ b/autoload/tsuquyomi.vim @@ -317,13 +317,16 @@ 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. @@ -331,11 +334,16 @@ function! tsuquyomi#definition() 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 diff --git a/autoload/tsuquyomi/bufManager.vim b/autoload/tsuquyomi/bufManager.vim index fce2eac..7f1560b 100644 --- a/autoload/tsuquyomi/bufManager.vim +++ b/autoload/tsuquyomi/bufManager.vim @@ -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 diff --git a/doc/tsuquyomi.jax b/doc/tsuquyomi.jax index 629d264..3e5f7e4 100644 --- a/doc/tsuquyomi.jax +++ b/doc/tsuquyomi.jax @@ -1,6 +1,6 @@ *tsuquyomi* はTypeScript向けのVim plugin です. -Version: 0.4.1 +Version: 0.4.2 Author : Quramy License: MIT license {{{ Permission is hereby granted, free of charge, to any person obtaining @@ -133,10 +133,6 @@ Prompt: :TsuquyomiDefinition *:TsuquyomiDefinition* シンボルが定義された場所へ遷移させます. - 定義箇所がカレントバッファに存在する場合はそこにカーソルを - 移動させます. - そうでない場合, 定義箇所を含むファイルを|split|で開いてから - カーソルを移動します. :TsuquyomiGoBack *:TsuquyomiGoBack* カーソルを最後に|:TsuquyomiDefinition|を実行した箇所へ @@ -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* diff --git a/doc/tsuquyomi.txt b/doc/tsuquyomi.txt index 34d5d38..43e2c8f 100644 --- a/doc/tsuquyomi.txt +++ b/doc/tsuquyomi.txt @@ -1,6 +1,6 @@ *tsuquyomi* is a Vim plugin for TypeScript. -Version: 0.4.1 +Version: 0.4.2 Author : Quramy License: MIT license {{{ Permission is hereby granted, free of charge, to any person obtaining @@ -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 @@ -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* diff --git a/package.json b/package.json index d9b710c..0636cd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tsuquyomi", - "version": "0.4.1", + "version": "0.4.2", "description": "Vim plugin for typescript", "main": "index.js", "directories": { diff --git a/plugin/tsuquyomi.vim b/plugin/tsuquyomi.vim index e717979..694ca1d 100644 --- a/plugin/tsuquyomi.vim +++ b/plugin/tsuquyomi.vim @@ -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