diff --git a/archlinux.yml b/archlinux.yml index 722ff76..e951a69 100644 --- a/archlinux.yml +++ b/archlinux.yml @@ -24,11 +24,9 @@ manager: pacman - import_tasks: 'tasks/aur.yml' - import_tasks: 'tasks/docker.yml' - - name: setup python versions include_tasks: 'tasks/python.yml' loop: '{{ python_versions }}' - - import_tasks: 'tasks/nvm.yml' vars_files: - 'vars/main.yml' diff --git a/tasks/neovim.yml b/tasks/neovim.yml index b1b1e9d..3779c71 100644 --- a/tasks/neovim.yml +++ b/tasks/neovim.yml @@ -1,8 +1,7 @@ -- name: Ensure neovim configuration directories exist - ansible.builtin.file: +- name: ensure neovim configuration directories exist + file: path: '{{ item }}' state: directory - mode: '0755' loop: - '{{ xdg_config_dir }}/nvim/' - '{{ xdg_config_dir }}/nvim/lua' @@ -13,8 +12,8 @@ - '{{ xdg_data_dir }}/nvim/site/pack/default' - '{{ xdg_data_dir }}/nvim/site/pack/default/start' -- name: Remove old neovim packages - ansible.builtin.file: +- name: remove old neovim packages + file: path: '{{ item }}' state: absent loop: @@ -22,171 +21,185 @@ - '{{ xdg_data_dir }}/nvim/site/pack/default/start/vim-colors-xcode' # Note that helptags may need to be regenerated (see `:h helptags`) -- name: Clone neovim packages - ansible.builtin.git: +- name: clone neovim packages + git: repo: '{{ item.url }}' dest: '{{ xdg_data_dir }}/nvim/site/pack/default/start/{{ item.name }}' update: true - version: '{{ item.version | default("HEAD") }}' + version: '{{ item.version|default("HEAD") }}' force: true # some maintainers overwrite existing tags :/ loop: '{{ neovim_plugins }}' -- name: Install neovim node package +- name: install neovim node package become: true - community.general.npm: + npm: name: neovim global: true -- name: Install language servers +- name: install language servers become: true - ansible.builtin.package: + package: name: '{{ item }}' state: present loop: '{{ language_servers | map(attribute="package") | list }}' when: ansible_facts['os_family'] == 'Archlinux' -- name: Install language servers on debian hosts +- name: install language servers on debian hosts become: true - community.general.npm: + npm: name: '{{ item }}' global: true loop: '{{ language_servers | map(attribute="package") | list }}' when: ansible_facts['os_family'] == 'Debian' -- name: Remove old neovim configuration file - ansible.builtin.file: +- name: remove old neovim configuration file + file: path: '{{ xdg_config_dir }}/nvim/init.vim' state: absent -- name: Remove coc.nvim extension - ansible.builtin.file: +- name: remove coc.nvim extension + file: path: '{{ xdg_data_dir }}/nvim/site/pack/default/start/coc.nvim' state: absent -- name: Setup neovim configuration files - ansible.builtin.template: +- name: setup neovim configuration files + template: dest: '{{ item.dest }}' src: '{{ item.src }}' - mode: '0755' loop: - - src: 'templates/nvim/ftplugin/bash.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/bash.lua' + - { + src: 'templates/nvim/ftplugin/bash.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/bash.lua', + } + - { + src: 'templates/nvim/ftplugin/css.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/css.lua', + } + - { + src: 'templates/nvim/ftplugin/html.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/html.lua', + } + - { + src: 'templates/nvim/ftplugin/htmldjango.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/htmldjango.lua', + } + - { + src: 'templates/nvim/ftplugin/javascript.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/javascript.lua', + } + - { + src: 'templates/nvim/ftplugin/json.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/json.lua', + } + - { + src: 'templates/nvim/ftplugin/lua.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/lua.lua', + } + - { + src: 'templates/nvim/ftplugin/python.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/python.lua', + } + - { + src: 'templates/nvim/ftplugin/scss.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/scss.lua', + } + - { + src: 'templates/nvim/ftplugin/sh.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/sh.lua', + } + - { + src: 'templates/nvim/ftplugin/yaml.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/yaml.lua', + } + - { src: 'templates/nvim/init.lua.j2', dest: '{{ xdg_config_dir }}/nvim/init.lua' } + - { + src: 'templates/nvim/lua/lsp.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/lua/lsp.lua', + } + - { + src: 'templates/nvim/lua/options.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/lua/options.lua', + } + - { + src: 'templates/nvim/lua/tree-sitter.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/lua/tree-sitter.lua', + } + - { + src: 'templates/nvim/lua/git-signs.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/lua/git-signs.lua', + } + - { + src: 'templates/nvim/lua/lua-line.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/lua/lua-line.lua', + } + - { + src: 'templates/nvim/lua/telescope.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/lua/_telescope.lua', + } + - { + src: 'templates/nvim/lua/indent-blankline.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/lua/indent-blankline.lua', + } + - { + src: 'templates/nvim/lua/nvim-tree.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/lua/_nvim-tree.lua', + } + - { + src: 'templates/nvim/lua/colorscheme.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/lua/colorscheme.lua', + } + - { + src: 'templates/nvim/lua/source-link.lua.j2', + dest: '{{ xdg_config_dir }}/nvim/lua/_source-link.lua', + } - - src: 'templates/nvim/ftplugin/css.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/css.lua' - - src: 'templates/nvim/ftplugin/html.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/html.lua' - - src: 'templates/nvim/ftplugin/htmldjango.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/htmldjango.lua' - - src: 'templates/nvim/ftplugin/javascript.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/javascript.lua' +- block: + - name: create neovim install directory + become: true + file: + state: directory + path: '{{ neovim.install_path }}' + owner: '{{ ansible_user_id }}' + group: '{{ ansible_user_gid }}' - - src: 'templates/nvim/ftplugin/json.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/json.lua' + - name: register the current neovim version + command: + argv: + - '{{ neovim.install_path }}/bin/nvim' + - '--version' + register: neovim_stats + ignore_errors: true - - src: 'templates/nvim/ftplugin/lua.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/lua.lua' + - name: parse the current neovim version + set_fact: + neovim_installed_version: neovim_stats.stdout_lines[0] | regex_search('(v\d+\.\d+\.\d+)') + when: neovim_stats.rc == 0 - - src: 'templates/nvim/ftplugin/python.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/python.lua' + # TODO: verify checksum + - name: download neovim {{ neovim.version }} + get_url: + url: 'https://github.com/neovim/neovim/releases/download/{{ neovim.version }}/nvim-linux64.tar.gz' + dest: /tmp/nvim-linux64.tar.gz + when: neovim_stats.rc > 0 or neovim_installed_version != neovim.version + register: neovim_download - - src: 'templates/nvim/ftplugin/scss.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/scss.lua' + - name: extract downloaded neovim version + unarchive: + src: /tmp/nvim-linux64.tar.gz + dest: '{{ neovim.install_path }}' + extra_opts: + - '--strip-components=1' + - '--show-stored-names' + - '--overwrite' + when: neovim_download.state == 'file' and + (neovim_installed_version is undefined or neovim_installed_version != neovim.version) - - src: 'templates/nvim/ftplugin/sh.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/sh.lua' + - name: add neovim to PATH + become: true + template: + src: 'templates/nvim.profile.j2' + dest: '/etc/profile.d/neovim.sh' - - src: 'templates/nvim/ftplugin/yaml.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/yaml.lua' - - - src: 'templates/nvim/init.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/init.lua' - - - src: 'templates/nvim/lua/lsp.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/lua/lsp.lua' - - - src: 'templates/nvim/lua/options.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/lua/options.lua' - - - src: 'templates/nvim/lua/tree-sitter.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/lua/tree-sitter.lua' - - - src: 'templates/nvim/lua/git-signs.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/lua/git-signs.lua' - - - src: 'templates/nvim/lua/lua-line.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/lua/lua-line.lua' - - - src: 'templates/nvim/lua/telescope.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/lua/_telescope.lua' - - - src: 'templates/nvim/lua/indent-blankline.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/lua/indent-blankline.lua' - - - src: 'templates/nvim/lua/nvim-tree.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/lua/_nvim-tree.lua' - - - src: 'templates/nvim/lua/colorscheme.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/lua/colorscheme.lua' - - - src: 'templates/nvim/lua/source-link.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/lua/_source-link.lua' - - - src: 'templates/nvim/lua/filetype.lua.j2' - dest: '{{ xdg_config_dir }}/nvim/lua/_filetype.lua' - -- name: Install neovim from archive when: ansible_facts['os_family'] == 'Debian' - block: - - name: Create neovim install directory - become: true - ansible.builtin.file: - state: directory - path: '{{ neovim.install_path }}' - owner: '{{ ansible_user_id }}' - group: '{{ ansible_user_gid }}' - mode: '0755' - - - name: Register the current neovim version - ansible.builtin.command: - argv: - - '{{ neovim.install_path }}/bin/nvim' - - '--version' - register: neovim_stats - changed_when: false - ignore_errors: true - - - name: Parse the current neovim version - ansible.builtin.set_fact: - neovim_installed_version: neovim_stats.stdout_lines[0] | regex_search('(v\d+\.\d+\.\d+)') - when: neovim_stats.rc == 0 - - # TODO: verify checksum - - name: Download neovim {{ neovim.version }} - ansible.builtin.get_url: - url: 'https://github.com/neovim/neovim/releases/download/{{ neovim.version }}/nvim-linux64.tar.gz' - dest: /tmp/nvim-linux64.tar.gz - mode: '0755' - when: neovim_stats.rc > 0 or neovim_installed_version != neovim.version - register: neovim_download - - - name: Extract downloaded neovim version - ansible.builtin.unarchive: - src: /tmp/nvim-linux64.tar.gz - dest: '{{ neovim.install_path }}' - extra_opts: - - '--strip-components=1' - - '--show-stored-names' - - '--overwrite' - when: | - neovim_download.state == 'file' - and (neovim_installed_version is undefined or neovim_installed_version != neovim.version) - - - name: Add neovim to PATH - become: true - ansible.builtin.template: - src: 'templates/nvim.profile.j2' - dest: '/etc/profile.d/neovim.sh' - mode: '0755' diff --git a/templates/nvim/init.lua.j2 b/templates/nvim/init.lua.j2 index 84788ee..d12f92b 100644 --- a/templates/nvim/init.lua.j2 +++ b/templates/nvim/init.lua.j2 @@ -1,8 +1,6 @@ -- {{ ansible_managed }} --- TODO: load environment vars from .env files require('options') -require('_filetype') require('colorscheme') require('lsp') require('tree-sitter') diff --git a/templates/nvim/lua/filetype.lua.j2 b/templates/nvim/lua/filetype.lua.j2 deleted file mode 100644 index f117509..0000000 --- a/templates/nvim/lua/filetype.lua.j2 +++ /dev/null @@ -1,40 +0,0 @@ -local ansible_keywords = { - 'hosts', - 'tasks', - 'vars', - 'vars_files', - 'vars_prompt', - 'handlers', - 'roles', - 'import_tasks', - 'import_playbook', - 'import_role', -} - -vim.filetype.add { - pattern = { - ['playbook*.y(a?)ml'] = 'yaml.ansible', - ['site*.y(a?)ml'] = 'yaml.ansible', - ['inventory*.y(a?)ml'] = 'yaml.ansible', - ['task*.y(a?)ml'] = 'yaml.ansible', - ['requirement*.y(a?)ml'] = 'yaml.ansible', - - - ['.*/tasks/.*.y(a?)ml'] = 'yaml.ansible', - ['.*/vars/.*.y(a?)ml'] = 'yaml.ansible', - ['.*/playbooks/.*.y(a?)ml'] = 'yaml.ansible', - - ['*.ansible.y(a?)ml'] = 'yaml.ansible', - - ['.*.y(a?)ml'] = { - function(path, bufnr) - local content = vim.api.nvim_buf_get_lines(bufnr, 0, 1, false)[1] or '' - - for _, keyword in pairs(ansible_keywords) do - local pattern = string.format('^- %s:', keyword) - if content:match(pattern) then return 'yaml.ansible' end - end - end, - }, - }, -} diff --git a/templates/nvim/lua/lsp.lua.j2 b/templates/nvim/lua/lsp.lua.j2 index ec1b85b..a90237a 100644 --- a/templates/nvim/lua/lsp.lua.j2 +++ b/templates/nvim/lua/lsp.lua.j2 @@ -156,29 +156,3 @@ vim.diagnostic.config({ border = border }, }) - -local enable_formatting = os.getenv("ENABLE_FORMATTING", False) - --- TODO: fix error message: [LSP] Format request failed, no matching language servers. --- format buffers before saving for specific LSPs -if (enable_formatting) then - local excluded_clients = { 'pyright' } - - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('lsp', { clear = true }), - callback = function(args) - vim.api.nvim_create_autocmd('BufWritePre', { - buffer = args.buf, - callback = function() - vim.lsp.buf.format { - filter = function(client) - return not vim.list_contains(excluded_clients, client.name) - end, - async = false, - id = args.data.client_id - } - end, - }) - end - }) -end diff --git a/templates/nvim/lua/lua-line.lua.j2 b/templates/nvim/lua/lua-line.lua.j2 index 43f10c9..5821a00 100644 --- a/templates/nvim/lua/lua-line.lua.j2 +++ b/templates/nvim/lua/lua-line.lua.j2 @@ -2,7 +2,6 @@ local lualine = require('lualine'); --- TODO: show attached LSP count lualine.setup { sections = { lualine_a = {'mode'}, diff --git a/templates/nvim/lua/tree-sitter.lua.j2 b/templates/nvim/lua/tree-sitter.lua.j2 index d1730ad..50a0fdc 100644 --- a/templates/nvim/lua/tree-sitter.lua.j2 +++ b/templates/nvim/lua/tree-sitter.lua.j2 @@ -7,10 +7,8 @@ local tree_sitter_config = require('nvim-treesitter.configs') tree_sitter_config.setup { ensure_installed = { - 'lua', 'yaml', 'bash', 'python', 'javascript', 'typescript', 'css', 'scss', - 'html', 'htmldjango', 'sql', 'json', 'dockerfile', 'markdown', 'rst', 'tmux', - 'xml', 'toml', 'editorconfig', 'diff', 'gitcommit', 'git_config', 'gitignore', - 'gitattributes', 'make', 'nginx', 'vim', 'vimdoc', 'passwd', 'regex' + 'lua', 'yaml', 'bash', 'python', 'javascript', 'css', 'scss', 'html', + 'htmldjango', 'json', 'dockerfile', 'markdown', }, auto_install = true, highlight = { diff --git a/vars/archlinux.yml b/vars/archlinux.yml index 8361533..7bbc6e9 100644 --- a/vars/archlinux.yml +++ b/vars/archlinux.yml @@ -102,7 +102,6 @@ language_servers: python_download_url: 'https://www.python.org/ftp/python' python_versions: - - { version: 3.12.9, path: 'python3.12', binary: 'python3.12' } - { version: 3.11.9, path: 'python3.11', binary: 'python3.11' } - { version: 3.10.0, path: 'python3.10', binary: 'python3.10' } - { version: 3.9.14, path: 'python3.9', binary: 'python3.9' }