From 7b1de43c650ad1c6a18f0c6190032c07a51653ca Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Mon, 22 Apr 2019 16:29:19 -0700 Subject: [PATCH] Allow :LSClientFindActions with visual selection Towards #178 Uses a hack to try to figure out if the user is likely to have set reasonable marks for the range and is running from a visual selection so that lines were passed with `:'<,'>LSClientFindCodeActions`. --- autoload/lsc/edit.vim | 3 ++- autoload/lsc/params.vim | 12 +++++++++--- plugin/lsc.vim | 5 +++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/autoload/lsc/edit.vim b/autoload/lsc/edit.vim index 23c7b25b..fd6155cf 100644 --- a/autoload/lsc/edit.vim +++ b/autoload/lsc/edit.vim @@ -5,7 +5,8 @@ function! lsc#edit#findCodeActions(...) abort let ActionFilter = function("ActionMenu") endif call lsc#file#flushChanges() - let params = lsc#params#documentRange() + let l:usingRange = a:0 > 2 && (a:2 != 1 || a:3 != line('$')) + let params = lsc#params#documentRange(l:usingRange) let params.context = {'diagnostics': \ lsc#diagnostics#forLine(lsc#file#fullPath(), line('.'))} call lsc#server#userCall('textDocument/codeAction', params, diff --git a/autoload/lsc/params.vim b/autoload/lsc/params.vim index 782527f3..9f2c343e 100644 --- a/autoload/lsc/params.vim +++ b/autoload/lsc/params.vim @@ -8,10 +8,16 @@ function! lsc#params#documentPosition() abort \ } endfunction -function! lsc#params#documentRange() abort +function! lsc#params#documentRange(usingRange) abort + let l:mode = mode() + let l:start = a:usingRange ? getpos("'<") : getpos('.') + let l:end = a:usingRange ? getpos("'>") : getpos('.') + " Fallback if range marks didn't exist + let l:start = l:start[1] == 0 ? getpos('.') : l:start + let l:end = l:end[1] == 0 ? getpos('.') : l:end return { 'textDocument': {'uri': lsc#uri#documentUri()}, \ 'range': { - \ 'start': {'line': line('.') - 1, 'character': col('.') - 1}, - \ 'end': {'line': line('.') - 1, 'character': col('.')}}, + \ 'start': {'line': l:start[1] - 1, 'character': l:start[2] - 1}, + \ 'end': {'line': l:end[1] - 1, 'character': l:end[2]}}, \ } endfunction diff --git a/plugin/lsc.vim b/plugin/lsc.vim index 14020dff..1a951a7b 100644 --- a/plugin/lsc.vim +++ b/plugin/lsc.vim @@ -29,8 +29,9 @@ command! -nargs=? LSClientShowHover call lsc#reference#hover() command! LSClientDocumentSymbol call lsc#reference#documentSymbols() command! -nargs=? LSClientWorkspaceSymbol \ call lsc#search#workspaceSymbol() -command! -nargs=? LSClientFindCodeActions - \ call lsc#edit#findCodeActions(lsc#edit#filterActions()) +command! -nargs=? -range=% LSClientFindCodeActions + \ call lsc#edit#findCodeActions( + \ lsc#edit#filterActions(), , ) command! LSClientAllDiagnostics call lsc#diagnostics#showInQuickFix() command! LSClientLineDiagnostics call lsc#diagnostics#echoForLine() command! LSClientSignatureHelp call lsc#signaturehelp#getSignatureHelp()