Skip to content

Commit

Permalink
Add scroll keymapping (#1058)
Browse files Browse the repository at this point in the history
* Add lsp#scroll function

* Update README.md

* Add example setting to docs
  • Loading branch information
hrsh7th authored Feb 22, 2021
1 parent 6f8dfe1 commit 6a2b97c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ function! s:on_lsp_buffer_enabled() abort
nmap <buffer> gi <plug>(lsp-implementation)
nmap <buffer> gt <plug>(lsp-type-definition)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> [g <Plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <Plug>(lsp-next-diagnostic)
nmap <buffer> [g <plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <plug>(lsp-next-diagnostic)
nmap <buffer> K <plug>(lsp-hover)
inoremap <buffer> <expr><c-f> lsp#scroll(+4)
inoremap <buffer> <expr><c-d> lsp#scroll(-4)
let g:lsp_format_sync_timeout = 1000
autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
Expand Down
17 changes: 17 additions & 0 deletions autoload/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,23 @@ function! lsp#get_progress() abort
return lsp#internal#work_done_progress#get_progress()
endfunction

"
" Scroll vim-lsp related windows.
"
" NOTE: This method can be used to <expr> mapping.
"
function! lsp#scroll(count) abort
let l:ctx = {}
function! l:ctx.callback(count) abort
let l:Window = vital#lsp#import('VS.Vim.Window')
for l:winid in l:Window.find({ winid -> l:Window.is_floating(winid) })
call l:Window.scroll(l:winid, l:Window.info(l:winid).topline + a:count)
endfor
endfunction
call timer_start(0, { -> l:ctx.callback(a:count) })
return "\<Ignore>"
endfunction

function! s:merge_dict(dict_old, dict_new) abort
for l:key in keys(a:dict_new)
if has_key(a:dict_old, l:key) && type(a:dict_old[l:key]) == v:t_dict && type(a:dict_new[l:key]) == v:t_dict
Expand Down
8 changes: 8 additions & 0 deletions doc/vim-lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,14 @@ lsp#get_progress() *lsp#get_progress()*
Type: |Number|
0 - 100 or not exist

lsp#scroll(count) *lsp#scroll()*

Scroll current displayed floating/popup window with specified count.

Example: >
inoremap <buffer> <expr><c-f> lsp#scroll(+4)
inoremap <buffer> <expr><c-d> lsp#scroll(-4)
==============================================================================
Commands *vim-lsp-commands*

Expand Down

0 comments on commit 6a2b97c

Please sign in to comment.