yaegassy / coc-ansible

ansible-language-server extension for coc.nvim
https://www.npmjs.com/package/@yaegassy/coc-ansible
MIT License
71 stars 3 forks source link
ansible coc coc-extension cocnvim neovim vim

coc-ansible

ansible-language-server extension for coc.nvim

coc-ansible-demo

Install

CocInstall:

:CocInstall @yaegassy/coc-ansible

scoped packages

vim-plug:

Plug 'yaegassy/coc-ansible', {'do': 'yarn install --frozen-lockfile'}

Note

[!! Very important !!] Filetype related

  1. The "filetype" must be yaml.ansible for this extension to work.

    If you install ansible's vim plugin, yaml.ansible filetype will be added automatically, which is very useful (e.g. pearofducks/ansible-vim or sheerun/vim-polyglot).

  2. You also need to set g:coc_filetype_map in .vimrc/init.vim.

    let g:coc_filetype_map = {
     \ 'yaml.ansible': 'ansible',
     \ }

Requirements (Tools)

If you also install yamllint, ansible-lint will detect it and incorporate into the linting process. Any findings reported by yamllint will be exposed in coc.nvim as errors/warnings.

Bult-in install

coc-ansible allows you to create an extension-only "venv" and install ansible, ansible-lint and yamllint.

yamllint will be installed by setting ansible.builtin.isWithYamllint to true (default: false).

You can also specify the version of each tool. (setting: ansible.bultin.ansibleVersion, ansible.bultin.ansibleLintVersion, ansible.bultin.yamllintVersion)


The first time you use coc-ansible, if ansible, ansible-lint is not detected, you will be prompted to do a built-in installation.

You can also run the installation command manually.

:CocCommand ansible.builtin.installRequirementsTools

Configuration options

Commands

Command List:

:CocCommand [CommandName]

e.g. :CocCommand ansible.server.restart

Example of command key mapping:

" Quickly view a list of all coc.nvim commands
nnoremap <silent> <C-p> :<C-u>CocCommand<CR>

Code Actions

Example key mapping (Code Action related):

nmap <silent> ga <Plug>(coc-codeaction-line)

Usage:

In the line with diagnostic message, enter the mapped key (e.g. ga) and you will see a list of code actions that can be performed.

Actions:

Thanks

License

MIT


This extension is built with create-coc-extension