From 1607814d6332edd2f1fed7207b25a758b28c7f7a Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sun, 1 Mar 2020 20:18:51 +0900 Subject: Add client-side commands --- settings/eclipse-jdt-ls.vim | 7 +++++++ settings/rust-analyzer.vim | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/settings/eclipse-jdt-ls.vim b/settings/eclipse-jdt-ls.vim index 1307b0e..987fd79 100644 --- a/settings/eclipse-jdt-ls.vim +++ b/settings/eclipse-jdt-ls.vim @@ -12,3 +12,10 @@ augroup vimlsp_settings_eclipse_jdt_ls \ 'semantic_highlight': lsp_settings#get('eclipse-jdt-ls', 'semantic_highlight', {}), \ } augroup END + +function! s:eclipse_jdt_ls_java_apply_workspaceEdit(context) + let l:command = get(a:context, 'command', {}) + + call lsp#utils#workspace_edit#apply_workspace_edit(l:command['arguments'][0]) +endfunction +call lsp#register_command('java.apply.workspaceEdit', function('s:eclipse_jdt_ls_java_apply_workspaceEdit')) diff --git a/settings/rust-analyzer.vim b/settings/rust-analyzer.vim index 993add9..b0f25ce 100644 --- a/settings/rust-analyzer.vim +++ b/settings/rust-analyzer.vim @@ -12,3 +12,18 @@ augroup vimlsp_settings_rust-analyzer \ 'semantic_highlight': lsp_settings#get('rust-analyzer', 'semantic_highlight', {}), \ } augroup END + +function! s:rust_analyzer_apply_source_change(context) + let l:command = get(a:context, 'command', {}) + + let l:workspace_edit = get(l:command['arguments'][0], 'workspaceEdit', {}) + if !empty(l:workspace_edit) + call lsp#utils#workspace_edit#apply_workspace_edit(l:workspace_edit) + endif + + let l:cursor_position = get(l:command['arguments'][0], 'cursorPosition', {}) + if !empty(l:cursor_position) + call cursor(lsp#utils#position#_lsp_to_vim('%', l:cursor_position)) + endif +endfunction +call lsp#register_command('rust-analyzer.applySourceChange', function('s:rust_analyzer_apply_source_change')) -- cgit v1.2.3-54-g00ecf From f9a2fa867bb8cc14b09a1dc40ad06d0224d45d10 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sun, 1 Mar 2020 22:31:39 +0900 Subject: Check lsp#register_command() exists --- settings/eclipse-jdt-ls.vim | 12 ++++++++++-- settings/rust-analyzer.vim | 13 +++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/settings/eclipse-jdt-ls.vim b/settings/eclipse-jdt-ls.vim index 987fd79..2fbaf02 100644 --- a/settings/eclipse-jdt-ls.vim +++ b/settings/eclipse-jdt-ls.vim @@ -11,11 +11,19 @@ augroup vimlsp_settings_eclipse_jdt_ls \ 'workspace_config': lsp_settings#get('eclipse-jdt-ls', 'workspace_config', {}), \ 'semantic_highlight': lsp_settings#get('eclipse-jdt-ls', 'semantic_highlight', {}), \ } + autocmd User lsp_setup call s:register_command() augroup END function! s:eclipse_jdt_ls_java_apply_workspaceEdit(context) let l:command = get(a:context, 'command', {}) - call lsp#utils#workspace_edit#apply_workspace_edit(l:command['arguments'][0]) endfunction -call lsp#register_command('java.apply.workspaceEdit', function('s:eclipse_jdt_ls_java_apply_workspaceEdit')) + +function! s:register_command() + augroup vimlsp_settings_eclipse_jdt_ls + au! + augroup END + if exists('*lsp#register_command') + call lsp#register_command('java.apply.workspaceEdit', function('s:eclipse_jdt_ls_java_apply_workspaceEdit')) + endif +endfunction diff --git a/settings/rust-analyzer.vim b/settings/rust-analyzer.vim index b0f25ce..14dd9d9 100644 --- a/settings/rust-analyzer.vim +++ b/settings/rust-analyzer.vim @@ -1,4 +1,4 @@ -augroup vimlsp_settings_rust-analyzer +augroup vimlsp_settings_rust_analyzer au! LspRegisterServer { \ 'name': 'rust-analyzer', @@ -11,6 +11,7 @@ augroup vimlsp_settings_rust-analyzer \ 'workspace_config': lsp_settings#get('rust-analyzer', 'workspace_config', {}), \ 'semantic_highlight': lsp_settings#get('rust-analyzer', 'semantic_highlight', {}), \ } + autocmd User lsp_setup call s:register_command() augroup END function! s:rust_analyzer_apply_source_change(context) @@ -26,4 +27,12 @@ function! s:rust_analyzer_apply_source_change(context) call cursor(lsp#utils#position#_lsp_to_vim('%', l:cursor_position)) endif endfunction -call lsp#register_command('rust-analyzer.applySourceChange', function('s:rust_analyzer_apply_source_change')) + +function! s:register_command() + augroup vimlsp_settings_rust_analyzer + au! + augroup END + if exists('*lsp#register_command') + call lsp#register_command('rust-analyzer.applySourceChange', function('s:rust_analyzer_apply_source_change')) + endif +endfunction -- cgit v1.2.3-54-g00ecf From b93a7cf76b01219ab3e5ea58623f7f3afdfc7dc6 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 2 Mar 2020 09:30:46 +0900 Subject: Fix for review --- settings/rust-analyzer.vim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/settings/rust-analyzer.vim b/settings/rust-analyzer.vim index 14dd9d9..223b4d9 100644 --- a/settings/rust-analyzer.vim +++ b/settings/rust-analyzer.vim @@ -17,14 +17,17 @@ augroup END function! s:rust_analyzer_apply_source_change(context) let l:command = get(a:context, 'command', {}) - let l:workspace_edit = get(l:command['arguments'][0], 'workspaceEdit', {}) + let l:arguments = get(l:command, 'arguments', []) + let l:argument = get(l:arguments, 0, {}) + + let l:workspace_edit = get(l:argument, 'workspaceEdit', {}) if !empty(l:workspace_edit) call lsp#utils#workspace_edit#apply_workspace_edit(l:workspace_edit) endif - let l:cursor_position = get(l:command['arguments'][0], 'cursorPosition', {}) + let l:cursor_position = get(l:argument, 'cursorPosition', {}) if !empty(l:cursor_position) - call cursor(lsp#utils#position#_lsp_to_vim('%', l:cursor_position)) + call cursor(lsp#utils#position#lsp_to_vim('%', l:cursor_position)) endif endfunction -- cgit v1.2.3-54-g00ecf