---
- name: Dependencies
  ansible.builtin.package:
    name:
      - autoconf
      - automake
      - cmake
      - curl
      - doxygen
      - g++
      - gettext
      - libtool
      - libtool-bin
      - ninja-build
      - pkg-config
      - unzip
    state: latest
  become: yes

- name: Clone
  ansible.builtin.git:
    clone: yes
    depth: 1
    dest: "{{ ansible_user_dir }}/neovim"
    repo: https://github.com/neovim/neovim.git
    # single_branch: yes
    update: yes
    version: "{{ neovim_version | default('master') }}"
  register: clone

- name: Build
  make:
    chdir: "{{ ansible_user_dir }}/neovim"
    params:
      CMAKE_BUILD_TYPE: RelWithDebInfo
  when: clone.changed

- name: Install
  make:
    chdir: "{{ ansible_user_dir }}/neovim"
    target: install
  become: yes
  when: clone.changed

- name: Remove build folder
  ansible.builtin.file:
    path: "{{ ansible_user_dir }}/neovim/build"
    state: absent
  become: yes

- name: Create .config/nvim directory
  ansible.builtin.file:
    path: "{{ ansible_user_dir }}/.config/nvim"
    state: directory

- name: Configuration files
  ansible.builtin.file:
    src: "{{ role_path }}/files/{{ item }}"
    dest: "{{ ansible_user_dir }}/.config/nvim/{{ item }}"
    state: link
  with_items:
    - after
    - autoload
    - init.lua
    - lua