Open browser

This commit is contained in:
Yasuhiro Matsumoto
2021-12-22 12:47:34 +09:00
committed by mattn
parent 1c0dfc0a26
commit 428e78dbab

View File

@@ -13,6 +13,52 @@ function! s:install_or_update() abort
call lsp_settings#install_server(l:languages[0], l:command) call lsp_settings#install_server(l:languages[0], l:command)
endfunction endfunction
function! s:open() abort
let l:command = substitute(getline('.'), '\[.\] \(\S\+\).*', '\1', '')
if empty(l:command)
return
endif
let l:settings = lsp_settings#settings()
for l:ft in sort(keys(l:settings))
for l:conf in l:settings[l:ft]
if l:conf.command ==# l:command
let l:cmd = ''
if 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
endif
break
endif
endfor
endfor
endfunction
function! s:help() abort
let l:command = substitute(getline('.'), '\[.\] \(\S\+\).*', '\1', '')
if empty(l:command)
return
endif
let l:settings = lsp_settings#settings()
for l:ft in sort(keys(l:settings))
for l:conf in l:settings[l:ft]
if l:conf.command ==# l:command
echomsg l:conf.url
echomsg l:conf.description
break
endif
endfor
endfor
endfunction
function! s:uninstall() abort function! s:uninstall() abort
let l:command = substitute(getline('.'), '\[.\] \(\S\+\).*', '\1', '') let l:command = substitute(getline('.'), '\[.\] \(\S\+\).*', '\1', '')
if empty(l:command) if empty(l:command)
@@ -68,7 +114,9 @@ function! lsp_settings#ui#open() abort
call s:update() call s:update()
nnoremap <buffer> i :call <SID>install_or_update()<cr> nnoremap <buffer> i :call <SID>install_or_update()<cr>
nnoremap <buffer> x :call <SID>uninstall()<cr> nnoremap <buffer> x :call <SID>uninstall()<cr>
nnoremap <buffer> b :call <SID>open()<cr>
nnoremap <buffer> ? :call <SID>help()<cr>
nnoremap q :bw<cr> nnoremap q :bw<cr>
redraw redraw
echomsg 'Type i to install, or x to uninstall' echomsg 'Type i to install, or x to uninstall, b to open browser, ? to show description'
endfunction endfunction