Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,31 @@ let g:lightline = {
\ },
\ }
```
### Show the nearest method/function's scope in the statusline

```vim
function! NearestScope() abort
let info = get(b:, 'vista_cursor_info', {})
return get(info, 'scope', '')
endfunction

set statusline+=%{NearestScope()}
```
#### [lightline.vim](https://github.com/itchyny/lightline.vim)

```vim
let g:lightline = {
\...
\ 'active': {
\ 'left': [ [...],
\ [ ..., 'scope', 'method'] ]
\ },
\ 'component_function': {
\ ...
\ 'scope': 'NearestScope',
\ },
\ }
```

### Commands

Expand Down
3 changes: 3 additions & 0 deletions autoload/vista/autocmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,8 @@ function! vista#autocmd#InitMOF() abort
augroup VistaMOF
autocmd!
autocmd CursorMoved * call vista#cursor#FindNearestMethodOrFunction()
if g:vista_update_scope_on_cursor_move
autocmd CursorMoved * call vista#cursor#FindDetailWithDelay()
endif
augroup END
endfunction
47 changes: 47 additions & 0 deletions autoload/vista/cursor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ scriptencoding utf8

let s:find_timer = -1
let s:cursor_timer = -1
let s:find_detail_timer = -1
let s:highlight_timer = -1

let s:echo_cursor_opts = ['echo', 'floating_win', 'scroll', 'both']
Expand All @@ -28,6 +29,10 @@ function! s:StopCursorTimer() abort
call s:GenericStopTimer('s:cursor_timer')
endfunction

function! s:StopFindDetailTimer() abort
call s:GenericStopTimer('s:find_detail_timer')
endfunction

function! s:StopHighlightTimer() abort
call s:GenericStopTimer('s:highlight_timer')
endfunction
Expand Down Expand Up @@ -203,6 +208,48 @@ function! vista#cursor#ShowDetailWithDelay() abort
\ )
endfunction

" Show the detail of current tag/symbol under cursor.
function! vista#cursor#FindDetail(_timer) abort
if empty(getline('.'))
\ || !exists('g:vista')
\ || !has_key(g:vista, 'functions')
\ || !has_key(g:vista, 'source')
call setbufvar(g:vista.source.bufnr, 'vista_cursor_info', {})
return
endif

let found = vista#util#BinarySearch(g:vista.raw, line('.'), 'line', '')
Copy link
Copy Markdown
Owner

@liuchengxu liuchengxu Sep 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that we actually don't need the further processing, just providing the found should be enough, which contains everything, it's up to the API user how to use it, namely call setbufvar(g:vista.source.bufnr, 'vista_cursor_info', found). I don't want to introduce another API because someone wants the signature info later.

if empty(found)
let found = {}
endif

"echo found
let scope = vista#util#Trim(get(found, 'scope', ''))
if !empty(scope)
let scopeKind = get(found, 'scopeKind', '')
if !empty(scopeKind)
let scope = scopeKind.' '.scope
endif
let access = get(found, 'access', '')
if !empty(access)
let scope = scope.' '.access
endif
else
let scope = vista#util#Trim(get(found, 'namespace', '').' '.get(found, 'class', ''))
endif
let symbolname = vista#util#Trim(get(found, 'name', ''))
call setbufvar(g:vista.source.bufnr, 'vista_cursor_info', {'scope': scope, 'symbol': symbolname})

endfunction

function! vista#cursor#FindDetailWithDelay() abort
call s:StopFindDetailTimer()
let s:find_detail_timer = timer_start(
\ g:vista_update_scope_delay,
\ function('vista#cursor#FindDetail'),
\ )
endfunction

" This happens on calling `:Vista show` but the vista window is still invisible.
function! vista#cursor#ShowTagFor(lnum) abort
if !s:HasVlnum()
Expand Down
2 changes: 2 additions & 0 deletions plugin/vista.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ let g:vista_fold_toggle_icons = get(g:, 'vista_fold_toggle_icons', ['▼', '▶'
let g:vista_update_on_text_changed = get(g:, 'vista_update_on_text_changed', 0)
let g:vista_update_on_text_changed_delay = get(g:, 'vista_update_on_text_changed_delay', 500)
let g:vista_echo_cursor = get(g:, 'vista_echo_cursor', 1)
let g:vista_update_scope_on_cursor_move = get(g:, 'vista_update_scope_on_cursor_move', 1)
let g:vista_update_scope_delay = get(g:, 'vista_update_scope_delay', 300)
let g:vista_no_mappings = get(g:, 'vista_no_mappings', 0)
let g:vista_stay_on_open = get(g:, 'vista_stay_on_open', 1)
let g:vista_close_on_jump = get(g:, 'vista_close_on_jump', 0)
Expand Down