setup-cockpit/roles/neovim/tasks/main.yml

212 lines
7.1 KiB
YAML

---
- name: Fail if still using init.vim
ansible.builtin.stat:
path: ~/.config/nvim/init.vim
register: init_vim
failed_when: init_vim.stat.exists
- name: Install (Archlinux)
when:
ansible_facts['distribution'] == 'Archlinux'
block:
- name: Install things with pacman (Archlinux)
become: true
community.general.pacman:
name:
- neovim
- python-pynvim
- base-devel
- cmake
- clang
- npm
- ripgrep
- rsync # for 'synchronize' module
- ansible-lint
- flake8
- mypy
- python-pylint
- python-black
- shellcheck
- bash-language-server
- jedi-language-server
- lua-language-server
- texlab
- rust-analyzer
- name: Install things with npm (Archlinux)
become: true
community.general.npm:
name: "{{ item }}"
global: true
with_items:
- '@ansible/ansible-language-server'
- diagnostic-languageserver
- name: Install (Debian)
when:
ansible_facts['distribution'] == 'Debian'
block:
- name: Find latest neovim version
ansible.builtin.uri:
url: https://github.com/neovim/neovim/releases/latest
register: latest_http_content
- name: Set latest neovim version
ansible.builtin.set_fact:
neovim_version: "{{ latest_http_content.url | split('/') | last }}"
- name: Get latest neovim deb package
ansible.builtin.get_url:
url: "https://github.com/neovim/neovim/releases/download/{{ neovim_version }}/nvim-linux64.deb"
checksum: "sha256:https://github.com/neovim/neovim/releases/download/{{ neovim_version }}/nvim-linux64.deb.sha256sum"
dest: /tmp/nvim-linux64.deb
mode: 0644
- name: Install neovim deb package (Debian)
become: true
ansible.builtin.apt:
deb: /tmp/nvim-linux64.deb
- name: Install things with apt (Debian)
become: true
ansible.builtin.apt:
name:
- ansible-lint
- python3-pynvim
- build-essential
- python3-dev
- cmake
- clang
- clangd
- npm
- ripgrep
- rsync # for 'synchronize' module
- flake8
- mypy
- pylint3
- shellcheck
- name: Install things with pip (Debian)
ansible.builtin.pip:
name:
- jedi-language-server
extra_args: --user
- name: Install things with npm (Debian)
become: true
community.general.npm:
name: "{{ item }}"
global: true
with_items:
- '@ansible/ansible-language-server'
- bash-language-server
- diagnostic-languageserver
- name: Find latest texlab version
ansible.builtin.uri:
url: https://github.com/latex-lsp/texlab/releases/latest
register: latest_http_content
- name: Set latest texlab version
ansible.builtin.set_fact:
texlab_version: "{{ latest_http_content.url | split('/') | last }}"
- name: Get latest texlab binary
ansible.builtin.unarchive:
src: "https://github.com/latex-lsp/texlab/releases/download/{{ texlab_version }}/texlab-{{ ansible_facts.architecture }}-linux.tar.gz"
remote_src: true
dest: ~/.local/bin/
mode: 0755
- name: Find latest lua-language-server version
ansible.builtin.uri:
url: https://github.com/luals/lua-language-server/releases/latest
register: latest_http_content
- name: Set latest lua-language-server version
ansible.builtin.set_fact:
lua_lsp_version: "{{ latest_http_content.url | split('/') | last }}"
- name: Create tempdir for extracting lua-language-server
ansible.builtin.file:
path: /tmp/lualsp
state: directory
mode: 0755
changed_when: false
- name: Get latest lua-lsp archive
ansible.builtin.unarchive:
src: "https://github.com/luals/lua-language-server/releases/download/{{ lua_lsp_version }}/lua-language-server-{{ lua_lsp_version }}-linux-x64.tar.gz"
remote_src: true
dest: /tmp/lualsp/
changed_when: false
- name: Copy lua-lsp binary
ansible.builtin.copy:
src: /tmp/lualsp/bin/lua-language-server
remote_src: true
dest: ~/.local/bin/
mode: 0755
- name: Find latest rust-analyzer version
ansible.builtin.uri:
url: https://github.com/rust-lang/rust-analyzer/releases/latest
register: latest_http_content
- name: Set latest rust-analyzer version
ansible.builtin.set_fact:
rust_analyzer_version: "{{ latest_http_content.url | split('/') | last }}"
- name: Create tempdir for extracting rust-analyzer
ansible.builtin.file:
path: /tmp/rust-analyzer
state: directory
mode: 0755
changed_when: false
- name: Get latest rust-analyzer compressed binary
ansible.builtin.get_url:
url: "https://github.com/rust-lang/rust-analyzer/releases/download/{{ rust_analyzer_version }}/rust-analyzer-x86_64-unknown-linux-gnu.gz"
dest: /tmp/rust-analyzer/
mode: 0644
changed_when: false
- name: Decompress rust-analyzer binary
ansible.builtin.command:
cmd: gzip -fd /tmp/rust-analyzer/rust-analyzer-x86_64-unknown-linux-gnu.gz
chdir: /tmp/rust-analyzer
changed_when: false
- name: Copy rust-analyzer binary
ansible.builtin.copy:
src: /tmp/rust-analyzer/rust-analyzer-x86_64-unknown-linux-gnu
remote_src: true
dest: ~/.local/bin/rust-analyzer
mode: 0755
- name: Grab marksman (LSP server) binary
block:
- name: Find latest marksman version
ansible.builtin.uri:
url: https://github.com/artempyanykh/marksman/releases/latest
register: latest_http_content
- name: Set latest marksman version
ansible.builtin.set_fact:
marksman_version: "{{ latest_http_content.url | split('/') | last }}"
- name: Get latest marksman binary
ansible.builtin.get_url:
url: "https://github.com/artempyanykh/marksman/releases/download/{{ marksman_version }}/marksman-linux"
dest: ~/.local/bin/marksman
mode: 0755
- name: Make sure needed directories exist
ansible.builtin.file: path={{ item.path }} state=directory mode={{ item.mode }}
with_items:
- {path: '~/.config/nvim', mode: '0755'}
- {path: '~/.config/nvim/lua', mode: '0755'}
- {path: '~/.config/nvim/after', mode: '0755'}
- name: Copy configs
ansible.builtin.copy: src={{ item.src }} dest={{ item.dest }} mode=0644
with_items:
- {src: 'init.lua', dest: '~/.config/nvim/init.lua'}
- {src: 'flake8', dest: '~/.flake8'}
- {src: 'pylintrc', dest: '~/.pylintrc'}
- name: Copy lua configs
ansible.posix.synchronize:
src: "{{ item }}"
dest: ~/.config/nvim/
recursive: true
delete: true
with_items:
- lua
- after
- name: Run PackerSync
ansible.builtin.command: nvim --headless -c 'autocmd User PackerComplete quitall' -c PackerSync
# TODO: changed_when
changed_when: false
- name: Run TSUpdate
ansible.builtin.command: nvim --headless -c TSUpdate -c quitall
changed_when: false