diff --git a/settings/rust-analyzer.vim b/settings/rust-analyzer.vim index b013fab..faf1d78 100644 --- a/settings/rust-analyzer.vim +++ b/settings/rust-analyzer.vim @@ -25,6 +25,9 @@ function! s:on_lsp_buffer_enabled() abort command! -buffer LspCargoReload call reload_workspace() nnoremap (lsp-cargo-reload) :call reload_workspace() + + command! -buffer LspRustAnalyzerStatus call rust_analyzer_status() + nnoremap (lsp-rust-analyzer-status) :call rust_analyzer_status() endfunction function! s:open_cargo_toml() abort @@ -54,6 +57,41 @@ function! s:reload_workspace() abort \ ) endfunction +function! s:rust_analyzer_status() abort + echo 'Retrieving rust-analyzer status' + call lsp#callbag#pipe( + \ lsp#request('rust-analyzer', { + \ 'method': 'rust-analyzer/analyzerStatus', + \ 'params': { 'textDocument': lsp#get_text_document_identifier() } + \ }), + \ lsp#callbag#subscribe({ + \ 'next': {x->s:on_rust_analyzer_status(x)}, + \ 'error': {e->lsp_settings#utils#error(e)}, + \ }) + \ ) +endfunction + +function! s:on_rust_analyzer_status(x) abort + let l:contents = a:x['response']['result'] + let l:lines = lsp#utils#_split_by_eol(l:contents) + let l:view = winsaveview() + let l:alternate=@# + silent! pclose + sp LspRustAnalyzerStatusPreview + execute 'resize '.min([len(l:lines), &previewheight]) + set previewwindow + setlocal conceallevel=2 + setlocal bufhidden=hide + setlocal nobuflisted + setlocal buftype=nofile + setlocal noswapfile + %d + call setline(1, l:lines) + execute "normal \p" + call winrestview(l:view) + let @#=l:alternate +endfunction + function! s:rust_analyzer_apply_source_change(context) abort let l:command = get(a:context, 'command', {})