Skip to content

Commit

Permalink
feat(plugin): add <Plug>(coc-codeaction-line)
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed May 21, 2020
1 parent 52dd23a commit d792515
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/coc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,10 @@ normal mode, `v_` works for visual mode.

Get and run code action(s) for current file.

<Plug>(coc-codeaction-line) *n_coc-codeaction-line*

Get and run code action(s) for current line.

<Plug>(coc-codeaction-selected) *n_coc-codeaction-selected*
*v_coc-codeaction-selected*

Expand Down
1 change: 1 addition & 0 deletions plugin/coc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ vnoremap <Plug>(coc-format-selected) :<C-u>call CocActionAsync('form
vnoremap <Plug>(coc-codeaction-selected) :<C-u>call CocActionAsync('codeAction', visualmode())<CR>
nnoremap <Plug>(coc-codeaction-selected) :<C-u>set operatorfunc=<SID>CodeActionFromSelected<CR>g@
nnoremap <Plug>(coc-codeaction) :<C-u>call CocActionAsync('codeAction', '')<CR>
nnoremap <Plug>(coc-codeaction-line) :<C-u>call CocActionAsync('codeAction', 'n')<CR>
nnoremap <Plug>(coc-rename) :<C-u>call CocActionAsync('rename')<CR>
nnoremap <Plug>(coc-format-selected) :<C-u>set operatorfunc=<SID>FormatFromSelected<CR>g@
nnoremap <Plug>(coc-format) :<C-u>call CocActionAsync('format')<CR>
Expand Down
6 changes: 6 additions & 0 deletions src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,12 @@ export class Workspace implements IWorkspace {
*/
public async getSelectedRange(mode: string, document: Document): Promise<Range | null> {
let { nvim } = this
if (mode == 'n') {
let line = await nvim.call('line', ['.'])
let content = document.getline(line - 1)
if (!content.length) return null
return Range.create(line - 1, 0, line - 1, content.length)
}
if (!['v', 'V', 'char', 'line', '\x16'].includes(mode)) {
throw new Error(`Mode '${mode}' not supported`)
}
Expand Down

0 comments on commit d792515

Please sign in to comment.