Skip to content

Commit

Permalink
Use params.vim from more places
Browse files Browse the repository at this point in the history
- Update existing places constructing position params to call the shared
  utility.
- Migrate an implementation of Range params into the shared params.vim
- Remove the optional argument from `lsc#params#textDocument` since it
  was never called with an argument.
  • Loading branch information
natebosch committed Jan 16, 2019
1 parent 2d7b65b commit c6d088d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 36 deletions.
4 changes: 1 addition & 3 deletions autoload/lsc/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ function! s:startCompletion(isAuto) abort
let s:completion_canceled = v:false
call s:MarkCompleting(&filetype)
call lsc#file#flushChanges()
let params = { 'textDocument': {'uri': lsc#uri#documentUri()},
\ 'position': {'line': line('.') - 1, 'character': col('.') - 1}
\ }
let params = lsc#params#documentPosition()
call lsc#server#call(&filetype, 'textDocument/completion', params,
\ lsc#util#gateResult('Complete',
\ function('<SID>OnResult', [a:isAuto]), function('<SID>OnSkip')))
Expand Down
4 changes: 1 addition & 3 deletions autoload/lsc/cursor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ function! s:HighlightReferences(force_in_highlight) abort
endif
let s:pending[&filetype] = v:true
let s:highlights_request += 1
let params = { 'textDocument': {'uri': lsc#uri#documentUri()},
\ 'position': {'line': line('.') - 1, 'character': col('.') - 1}
\ }
let params = lsc#params#documentPosition()
call lsc#server#call(&filetype, 'textDocument/documentHighlight', params,
\ funcref('<SID>HandleHighlights',
\ [s:highlights_request, getcurpos(), bufnr('%'), &filetype]))
Expand Down
25 changes: 5 additions & 20 deletions autoload/lsc/edit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ function! lsc#edit#findCodeActions(...) abort
let ActionFilter = function("<SID>ActionMenu")
endif
call lsc#file#flushChanges()
call lsc#server#userCall('textDocument/codeAction',
\ s:TextDocumentRangeParams(),
let params = lsc#params#documentRange()
let params.context = {'diagnostics':
\ lsc#diagnostics#forLine(expand('%:p'), line('.'))}
call lsc#server#userCall('textDocument/codeAction', params,
\ lsc#util#gateResult('CodeActions', function('<SID>SelectAction'),
\ v:null, [ActionFilter]))
endfunction
Expand Down Expand Up @@ -38,17 +40,6 @@ function! s:ExecuteCommand(command) abort
\ {_->0})
endfunction

" TODO - handle visual selection for range
function! s:TextDocumentRangeParams() abort
return { 'textDocument': {'uri': lsc#uri#documentUri()},
\ 'range': {
\ 'start': {'line': line('.') - 1, 'character': col('.') - 1},
\ 'end': {'line': line('.') - 1, 'character': col('.')}},
\ 'context': {'diagnostics':
\ lsc#diagnostics#forLine(expand('%:p'), line('.'))}
\}
endfunction

" Returns a function which can filter actions against a patter and select when
" exactly 1 matches or show a menu for the matching actions.
function! lsc#edit#filterActions(...) abort
Expand Down Expand Up @@ -90,18 +81,12 @@ function! lsc#edit#rename(...) abort
else
let new_name = input('Enter a new name: ')
endif
let params = s:TextDocumentPositionParams()
let params = lsc#params#documentPosition()
let params.newName = new_name
call lsc#server#userCall('textDocument/rename', params,
\ lsc#util#gateResult('Rename', function('lsc#edit#apply')))
endfunction

function! s:TextDocumentPositionParams() abort
return { 'textDocument': {'uri': lsc#uri#documentUri()},
\ 'position': {'line': line('.') - 1, 'character': col('.') - 1}
\ }
endfunction

" Applies a workspace edit and returns `v:true` if it was successful.
function! lsc#edit#apply(workspace_edit) abort
if (exists('g:lsc_enable_apply_edit')
Expand Down
17 changes: 10 additions & 7 deletions autoload/lsc/params.vim
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
function! lsc#params#textDocument(...) abort
if a:0 >= 1
let file_path = a:1
else
let file_path = expand('%:p')
endif
return {'textDocument': {'uri': lsc#uri#documentUri(file_path)}}
function! lsc#params#textDocument() abort
return {'textDocument': {'uri': lsc#uri#documentUri()}}
endfunction

function! lsc#params#documentPosition() abort
return { 'textDocument': {'uri': lsc#uri#documentUri()},
\ 'position': {'line': line('.') - 1, 'character': col('.') - 1}
\ }
endfunction

function! lsc#params#documentRange() abort
return { 'textDocument': {'uri': lsc#uri#documentUri()},
\ 'range': {
\ 'start': {'line': line('.') - 1, 'character': col('.') - 1},
\ 'end': {'line': line('.') - 1, 'character': col('.')}},
\ }
endfunction
4 changes: 1 addition & 3 deletions autoload/lsc/signaturehelp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ endif

function! lsc#signaturehelp#getSignatureHelp() abort
call lsc#file#flushChanges()
let params = { 'textDocument': {'uri': lsc#uri#documentUri()},
\ 'position': {'line': line('.') - 1, 'character': col('.') - 1}
\ }
let params = lsc#params#documentPosition()
call lsc#server#call(&filetype, 'textDocument/signatureHelp', params,
\ lsc#util#gateResult('SignatureHelp', function('<SID>ShowSignatureHelp')))
endfunction
Expand Down

0 comments on commit c6d088d

Please sign in to comment.