-
Notifications
You must be signed in to change notification settings - Fork 73
Vim Usage
- Install the coc.nvim LSP client for Vim/Neovim.
- Install the sourcery-cli pypi package
pip install --user sourcery-cli
. Note down the full command path with
which sourcery
. - Sign up for Sourcery on the website and get your token.
- In Vim, run
:CocConfig
and this to your settings:
{
"languageserver": {
"sourcery": {
"command": "<Command to run Sourcery>",
"args": [
"lsp"
],
"filetypes": [
"python"
],
"initializationOptions": {
"token": "<Your Token Here>",
"extension_version": "coc.vim",
"editor_version": "vim"
},
"settings": {
"sourcery": {
"token": "<Your Token Here>", # This will not be needed as a duplicate soon
"metricsEnabled": true
}
}
}
}
}
- Optionally you can set up key bindings:
nnoremap <leader>cl :CocDiagnostics<cr>
nnoremap <leader>cf :CocFix<cr>
nnoremap <leader>ch :call CocAction('doHover')<cr>
Sourcery scans the currently open Python file. If it finds improvements in your code it highlights the relevant lines of code. To show all the Sourcery suggestions from the scanned file run :CocDiagnostics
and they will appear in the location list.
When on a suggestion line, you can run :call CocAction('doHover')
to view a description of the refactoring along with a diff. Then you can run :CocFix
to either make the suggested change or to disable it.
The extension can also show you inline code metrics, giving you an instant view of your code quality.
Run :call CocAction('doHover')
on a function's definition to get an instant view of its code quality, and
functions with very low quality will additionally be highlighted as warnings.
See the Sourcery Tutorial for more detailed info.
Please see the Sourcery configuration section for details.
Please visit our newer docs at https://docs.sourcery.ai