ad LspRustOpenDocs

This commit is contained in:
Prabir Shrestha
2022-01-02 22:31:30 +00:00
committed by mattn
parent 5f202b6ded
commit d0012d24e9
3 changed files with 46 additions and 12 deletions

View File

@@ -24,18 +24,8 @@ function! s:open() abort
for l:conf in l:settings[l:ft]
if l:conf.command ==# l:command
let l:cmd = ''
if exists('g:loaded_openbrowser') && g:loaded_openbrowser
call openbrowser#open(l:conf.url)
elseif has('win32') || has('win64')
silent! exec printf('!start rundll32 url.dll,FileProtocolHandler %s', l:conf.url)
elseif has('mac') || has('macunix') || has('gui_macvim') || system('uname') =~? '^darwin'
call system(printf('open "%s"', l:conf.url))
elseif executable('xdg-open')
call system(printf('xdg-open "%s"', l:conf.url))
elseif executable('firefox')
call system(printf('firefox "%s"', l:conf.url))
else
return
if !lsp_settings#utils#open_url(l:conf.url)
return
endif
break
endif

View File

@@ -159,3 +159,20 @@ function! lsp_settings#utils#shellescape(path) abort
let l:quote = &shellxquote ==# '"' ? "'" : '"'
return l:quote . a:path . l:quote
endfunction
function! lsp_settings#utils#open_url(url) abort
if exists('g:loaded_openbrowser') && g:loaded_openbrowser
call openbrowser#open(l:conf.url)
elseif has('win32') || has('win64')
silent! exec printf('!start rundll32 url.dll,FileProtocolHandler %s', l:conf.url)
elseif has('mac') || has('macunix') || has('gui_macvim') || system('uname') =~? '^darwin'
call system(printf('open "%s"', l:conf.url))
elseif executable('xdg-open')
call system(printf('xdg-open "%s"', l:conf.url))
elseif executable('firefox')
call system(printf('firefox "%s"', l:conf.url))
else
return v:false
endif
return v:true
endfunction

View File

@@ -34,6 +34,9 @@ function! s:on_lsp_buffer_enabled() abort
command! -buffer LspRustFindMatchingBrace call <SID>find_matching_brace()
nnoremap <buffer> <plug>(lsp-rsut-find-matching-brace) :<c-u>call <SID>find_matching_brace()<cr>
command! -buffer LspRustOpenDocs call <SID>open_docs()
nnoremap <buffer> <plug>(lsp-rust-open-docs) :<c-u>call <SID>open_docs()<cr>
endfunction
function! s:open_cargo_toml() abort
@@ -156,6 +159,30 @@ function! s:on_find_matching_brace(x) abort
endif
endfunction
function! s:open_docs() abort
echo 'Opening docs...'
call lsp#callbag#pipe(
\ lsp#request('rust-analyzer', {
\ 'method': 'experimental/externalDocs',
\ 'params': {
\ 'textDocument': lsp#get_text_document_identifier(),
\ 'position': lsp#get_position(),
\ },
\ }),
\ lsp#callbag#subscribe({
\ 'next': {x->s:on_open_docs(x)},
\ 'error': {e->lsp_settings#utils#error(e)},
\ })
\ )
endfunction
function! s:on_open_docs(x) abort
if lsp#client#is_error(a:x['response']) | echom 'Failed to find docs' | endif
let l:url = a:x['response']['result']
call lsp_settings#utils#open_url(l:url)
echo ''
endfunction
function! s:rust_analyzer_apply_source_change(context) abort
let l:command = get(a:context, 'command', {})