---
- name: Install packages (Archlinux)
  become: true
  pacman:
    name:
      - vim
      - python-pynvim
      - neovim
      - python-pylint
      - python-black
      - ansible-lint
      - base-devel
      - flake8
      - mypy
      - shellcheck
      - cmake
      - clang
      - npm
  when:
    ansible_facts['distribution'] == 'Archlinux'

- name: Install packages (Debian)
  become: true
  apt:
    name:
      - vim
      - python3-pynvim
      - neovim
      - build-essential
      - python3-dev
      - pylint3
      - ansible-lint
      - flake8
      - mypy
      - shellcheck
      - cmake
      - clang
      - npm
  when:
    ansible_facts['distribution'] == 'Debian'

# some Arch derivatives don't have the shellcheck package (arch32, archarm)
- name: Run shellcheck script
  script: scripts/shellcheck_binary_fix.sh
  register: shellcheck_script
  when: ansible_facts['distribution'] == 'Archlinux'
  changed_when: "'there is nothing to do' not in shellcheck_script.stdout"

- name: Install neovim with pip for Debian
  pip:
    name: neovim
    extra_args: --user
  when:
    ansible_facts['distribution'] == 'Debian'

- name: Install neovim-remote
  pip:
    name: neovim-remote
    extra_args: --user

- name: Make sure needed directories exist
  file: path={{ item.path }} state=directory mode={{ item.mode }}
  with_items:
    - {path: '~/.config/nvim', mode: '0755'}
    - {path: '~/.config/nvim/lua', mode: '0755'}

- name: Copy configs
  copy: src={{ item.src }} dest={{ item.dest }} mode=0644
  with_items:
    - {src: 'init.vim', dest: '~/.config/nvim/init.vim'}
    - {src: 'flake8', dest: '~/.flake8'}
    - {src: 'pylintrc', dest: '~/.pylintrc'}

- name: Copy lua configs
  copy:
    src: lua
    dest: ~/.config/nvim/

- name: Run PackerSync
  command:
    cmd: vim +'autocmd User PackerComplete quitall' +PackerSync  #TODO: make this work
    stdin: '\n'  # On error needs user input to continue