Skip to content

Commit

Permalink
Add support for CodeAction literals
Browse files Browse the repository at this point in the history
Closes #94

- Advertise support with the client capabilities. It's not clear what
  the server is meant to do with the `CodeActionKind` config so the
  top-level values are used.
- Check whether the results look like a `CodeAction` or a `Command` and
  either apply the edit or execute the command as appropriate. When a
  `CodeAction` has both an `edit` and a `command` they are both applied
  in that order.
  • Loading branch information
natebosch committed Jul 7, 2018
1 parent b5b2163 commit e4c263e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
one action has a `title` that matches the pattern it will be run
automatically.
- Bug fix: Handle workspace edits that have double quotes.
- Add support for `CodeAction` literals.

# 0.3.0

Expand Down
25 changes: 19 additions & 6 deletions autoload/lsc/edit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,28 @@ function! s:SelectAction(result, action_filter) abort
call lsc#message#show('No actions available')
return
endif
let choice = a:action_filter(a:result)
if type(choice) == v:t_dict
call lsc#server#userCall('workspace/executeCommand',
\ {'command': choice['command'],
\ 'arguments': choice['arguments']},
\ {_->0})
let l:choice = a:action_filter(a:result)
if type(l:choice) == v:t_dict
if has_key(l:choice, 'command') && type(l:choice.command) == v:t_string
call s:ExecuteCommand(l:choice)
else
if has_key(l:choice, 'edit') && type(l:choice.edit) == v:t_dict
call lsc#edit#apply(l:choice.edit)
endif
if has_key(l:choice, 'command') && type(l:choice.command) == v:t_dict
call s:ExecuteCommand(l:choice.command)
endif
endif
endif
endfunction

function! s:ExecuteCommand(command) abort
call lsc#server#userCall('workspace/executeCommand',
\ {'command': a:command.command,
\ 'arguments': a:command.arguments},
\ {_->0})
endfunction

" TODO - handle visual selection for range
function! s:TextDocumentRangeParams() abort
return { 'textDocument': {'uri': lsc#uri#documentUri()},
Expand Down
5 changes: 5 additions & 0 deletions autoload/lsc/server.vim
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ function! s:ClientCapabilities() abort
\ 'snippetSupport': v:false,
\ },
\ 'definition': {'dynamicRegistration': v:false},
\ 'codeAction': {
\ 'codeActionLiteralSupport': {
\ 'codeActionKind': {'valueSet': ['quickfix', 'refactor', 'source']}
\ }
\ },
\ }
\}
endfunction
Expand Down

0 comments on commit e4c263e

Please sign in to comment.