Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow :LSClientFindActions with visual selection #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion autoload/lsc/edit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ function! lsc#edit#findCodeActions(...) abort
let ActionFilter = function("<SID>ActionMenu")
endif
call lsc#file#flushChanges()
let params = lsc#params#documentRange()
let l:usingRange = a:0 > 2 && (a:2 != 1 || a:3 != line('$'))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to check a:2 != 1 || a:3 != line('$')?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my hack to know whether we were called with a range. If we're called like :LSClientFindCodeActions then the -range=% at the command definition will fill in 1,$ and we're identifying that case here. If we're called like :'<,'>LSClientFindCodeActions then it shouldn't match 1,$ and we'd know to actually look at the visual selection marks.

It does mean you can't actually do :1,$LSClientFindCodeActions and pass the entire doc in the range to the server...

Copy link

@slonoed slonoed Apr 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be && instead of || then?

Also sending the whole document range can be useful. Example: wrapping code in IIFE.
Maybe it is better to expose function with argument isRange and use it in keybindings instead of command which tries to guess visual mode?
I use this one

vnoremap <silent> ga :call lsc#edit#findCodeActions(lsc#edit#filterActions(), 0, 0)<CR>

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,
Expand Down
12 changes: 9 additions & 3 deletions autoload/lsc/params.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions plugin/lsc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ command! -nargs=? LSClientShowHover call lsc#reference#hover()
command! LSClientDocumentSymbol call lsc#reference#documentSymbols()
command! -nargs=? LSClientWorkspaceSymbol
\ call lsc#search#workspaceSymbol(<args>)
command! -nargs=? LSClientFindCodeActions
\ call lsc#edit#findCodeActions(lsc#edit#filterActions(<args>))
command! -nargs=? -range=% LSClientFindCodeActions
\ call lsc#edit#findCodeActions(
\ lsc#edit#filterActions(<args>), <line1>, <line2>)
command! LSClientAllDiagnostics call lsc#diagnostics#showInQuickFix()
command! LSClientLineDiagnostics call lsc#diagnostics#echoForLine()
command! LSClientSignatureHelp call lsc#signaturehelp#getSignatureHelp()
Expand Down