diff --git a/CHANGELOG.md b/CHANGELOG.md index c6bc1a9c..699f06c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/autoload/lsc/edit.vim b/autoload/lsc/edit.vim index b2e01923..df180c56 100644 --- a/autoload/lsc/edit.vim +++ b/autoload/lsc/edit.vim @@ -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()}, diff --git a/autoload/lsc/server.vim b/autoload/lsc/server.vim index 8810b654..9ce883fa 100644 --- a/autoload/lsc/server.vim +++ b/autoload/lsc/server.vim @@ -185,6 +185,11 @@ function! s:ClientCapabilities() abort \ 'snippetSupport': v:false, \ }, \ 'definition': {'dynamicRegistration': v:false}, + \ 'codeAction': { + \ 'codeActionLiteralSupport': { + \ 'codeActionKind': {'valueSet': ['quickfix', 'refactor', 'source']} + \ } + \ }, \ } \} endfunction