diff options
author | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2020-02-10 10:58:01 +0900 |
---|---|---|
committer | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2020-02-10 10:58:01 +0900 |
commit | 94bda9483d386c592cc2e6a9ff2a87462124bd4a (patch) | |
tree | 6caaeb4dcb42b183f865dd7015f1bb3f04f8a30a /settings | |
parent | c62e905afc8006ebd45ccb9f51f363016f71daae (diff) | |
download | vim-lsp-settings-94bda9483d386c592cc2e6a9ff2a87462124bd4a.tar.gz vim-lsp-settings-94bda9483d386c592cc2e6a9ff2a87462124bd4a.tar.bz2 vim-lsp-settings-94bda9483d386c592cc2e6a9ff2a87462124bd4a.zip |
Add LspSwitchSourceHeader based on @kent-tri's patch
See https://github.com/prabirshrestha/vim-lsp/pull/703
Diffstat (limited to 'settings')
-rw-r--r-- | settings/clangd.vim | 72 | ||||
-rw-r--r-- | settings/metals.vim | 2 |
2 files changed, 73 insertions, 1 deletions
diff --git a/settings/clangd.vim b/settings/clangd.vim index a23bb1b..3f114a7 100644 --- a/settings/clangd.vim +++ b/settings/clangd.vim @@ -11,3 +11,75 @@ augroup vimlsp_settings_clangd \ 'workspace_config': lsp_settings#get('clangd', 'workspace_config', {}), \ } augroup END + +function! s:handle_switch_source_header(ctx, server, type, has_extension, data) abort "ctx = {counter, list, last_command_id} + if a:ctx['last_command_id'] != lsp#_last_command() + return + endif + + if lsp#client#is_error(a:data['response']) || !has_key(a:data['response'], 'result') + call lsp#utils#error('Failed to retrieve '. a:type . ' for ' . a:server . ': ' . lsp#client#error_message(a:data['response'])) + elseif type(a:data['response']['result']) ==# v:t_string + let a:ctx['list'] = a:ctx['list'] + [lsp#utils#uri_to_path(a:data['response']['result'])] + else + call lsp#utils#error('No switchable header file found') + return + endif + + if a:ctx['counter'] == a:has_extension + if empty(a:ctx['list']) + call lsp#utils#error('No ' . a:type .' found') + else + call lsp#utils#tagstack#_update() + + let l:loc = { + \ 'filename': a:ctx['list'][0], + \ 'lnum': 0, + \ 'col': 0, + \ } + + call lsp#utils#location#_open_vim_list_item(l:loc) + echo 'Retrieved ' . a:type + redraw + endif + endif +endfunction + +function! s:switch_source_header() abort + let l:servers = lsp#get_whitelisted_servers() + + let l:has_extension = 0 + for l:server in l:servers + if stridx(l:server, 'clangd') != -1 + let l:has_extension += 1 + endif + endfor + + let l:command_id = lsp#_new_command() + call setqflist([]) + + if l:has_extension == 0 + call lsp#utils#error('Switching between source/header not supported for '.&filetype) + return + endif + + let l:ctx = { 'counter': l:has_extension, 'list':[], 'last_command_id': l:command_id } + for l:server in l:servers + if stridx(l:server, 'clangd') == -1 + continue + endif + + call lsp#send_request(l:server, { + \ 'method': 'textDocument/switchSourceHeader', + \ 'params': { + \ 'uri': lsp#utils#get_buffer_uri(), + \ }, + \ 'on_notification': function('s:handle_switch_source_header', [l:ctx, l:server, 'header/source', l:has_extension]), + \ }) + endfor + + echo 'Switching between source/header ...' +endfunction + +command! LspSwitchSourceHeader call <SID>switch_source_header() +nnoremap <plug>(lsp-switch-source-header) :<c-u>call <SID>switch_source_header()<cr> diff --git a/settings/metals.vim b/settings/metals.vim index d0cdd53..376d5f5 100644 --- a/settings/metals.vim +++ b/settings/metals.vim @@ -7,7 +7,7 @@ augroup vimlsp_settings_metals \ 'initialization_options': lsp_settings#get('metals', 'initialization_options', v:null), \ 'whitelist': lsp_settings#get('metals', 'whitelist', ['scala', 'sbt']), \ 'blacklist': lsp_settings#get('metals', 'blacklist', []), - \ 'config': lsp_settings#get('metals', 'config', {'typed_pattern': '\k\zs'}), + \ 'config': lsp_settings#get('metals', 'config', {}), \ 'workspace_config': lsp_settings#get('metals', 'workspace_config', {}), \ } augroup END |