diff --git a/files/nvim.conform.lua b/files/nvim.conform.lua deleted file mode 100644 index 801df29..0000000 --- a/files/nvim.conform.lua +++ /dev/null @@ -1,14 +0,0 @@ --- example of a project specific nvim configuration file using :exrc and conform - -local conform = require 'conform'; - -conform.setup { - formatters_by_ft = { - python = { 'isort', 'black' }, - javascript = { 'prettier', }, - }, - - format_on_save = { - lsp_format = 'never', - } -} diff --git a/files/nvim.lsp.lua b/files/nvim.lsp.lua deleted file mode 100644 index ff06a44..0000000 --- a/files/nvim.lsp.lua +++ /dev/null @@ -1,33 +0,0 @@ --- example of a project specific nvim configuration file using :exrc and lsp formatting - -local format_clients = { - 'ruff', - 'lua_ls', - 'bashls', - 'jsonls', - 'ts_ls', - 'ansiblels', - 'yamlls', - 'cssls', - 'html', -} - -vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('lsp', { clear = true }), - callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - - if client:supports_method('textDocument/formatting') - and vim.tbl_contains(format_clients, client.name) then - vim.api.nvim_create_autocmd('BufWritePre', { - buffer = args.buf, - callback = function() - vim.lsp.buf.format { - async = false, - id = args.data.client_id - } - end, - }) - end - end -}) diff --git a/files/tmux.sh b/files/tmux.sh index d98c41b..01e0223 100755 --- a/files/tmux.sh +++ b/files/tmux.sh @@ -2,6 +2,7 @@ session_name=${PWD##*/} project_directory="$HOME/development/$session_name" +enable_formatting="false" tmux has-session -t $session_name @@ -10,7 +11,8 @@ then tmux new-session \ -c $project_directory \ -ds $session_name \ - -e "project_dir=$project_directory" + -e "project_dir=$project_directory" \ + -e "enable_formatting=$enable_formatting" # FIRST WINDOW tmux send-keys -t $session_name:0 'source ./env/bin/activate' C-m diff --git a/group_vars/all/git.yml b/group_vars/all/git.yml index b44e7e1..4715cd3 100644 --- a/group_vars/all/git.yml +++ b/group_vars/all/git.yml @@ -1,8 +1,7 @@ ---- -dotfiles_repo: "git@forgejo.fudiggity.nl:sonny/dotfiles.git" +dotfiles_repo: 'git@forgejo.fudiggity.nl:sonny/dotfiles.git' -git_domain: "forgejo.fudiggity.nl" -git_host_key: "forgejo.fudiggity.nl ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBqEej87ukSK7KGi7e0q+oTrru4h7Fm6fK8GgiMtu01+" +git_domain: 'forgejo.fudiggity.nl' +git_host_key: 'forgejo.fudiggity.nl ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBqEej87ukSK7KGi7e0q+oTrru4h7Fm6fK8GgiMtu01+' git_name: Sonny Bakker git_email: sonny871@hotmail.com diff --git a/group_vars/all/neovim.yml b/group_vars/all/neovim.yml index 767a4b7..2e1e9ab 100644 --- a/group_vars/all/neovim.yml +++ b/group_vars/all/neovim.yml @@ -1,51 +1,46 @@ ---- neovim_plugins: - - url: "https://forgejo.fudiggity.nl/sonny/source-link.lua" - name: "source-link" - - url: "https://github.com/nvim-tree/nvim-tree.lua" - name: "nvim-tree" - - url: "https://github.com/nvim-tree/nvim-web-devicons" - name: "nvim-tree-icons" - - url: "https://github.com/neovim/nvim-lspconfig" - name: "nvim-lspconfig" - - url: "https://github.com/hrsh7th/nvim-cmp" - name: "nvim-cmp" - - url: "https://github.com/hrsh7th/cmp-buffer" - name: "cmp-buffer" - - url: "https://github.com/hrsh7th/cmp-path" - name: "cmp-path" - - url: "https://github.com/hrsh7th/cmp-omni" - name: "cmp-omni" - - url: "https://github.com/hrsh7th/cmp-nvim-lsp" - name: "cmp-nvim-lsp" - - url: "https://github.com/hrsh7th/cmp-nvim-lua" - name: "cmp-nvim-lua" - - url: "https://github.com/nvim-treesitter/nvim-treesitter" - name: "nvim-treesitter" - version: master # main seems broken? - - url: "https://github.com/nvim-lua/plenary.nvim" - name: "plenary.nvim" - - url: "https://github.com/nvim-telescope/telescope-fzf-native.nvim" - name: "telescope-fzf-native.nvim" - - url: "https://github.com/nvim-telescope/telescope.nvim" - name: "telescope.nvim" - version: "0.1.x" - - url: "https://github.com/L3MON4D3/LuaSnip" - name: "luasnip" - version: "v1.0.0" - - url: "https://github.com/lewis6991/gitsigns.nvim" - name: "gitsigns.nvim" - version: "v0.9.0" - - url: "https://github.com/nvim-lualine/lualine.nvim" - name: "lualine" - - url: "https://github.com/lukas-reineke/indent-blankline.nvim" - name: "indent-blankline.nvim" - version: "v3.7.2" - - url: "https://github.com/projekt0n/github-nvim-theme.git" - name: "github-colors" - version: "v1.1.2" - - url: "https://github.com/stevearc/conform.nvim.git" - name: "conform.nvim" - version: "v9.0.0" + - url: 'https://forgejo.fudiggity.nl/sonny/source-link.lua' + name: 'source-link' + - url: 'https://github.com/nvim-tree/nvim-tree.lua' + name: 'nvim-tree' + - url: 'https://github.com/nvim-tree/nvim-web-devicons' + name: 'nvim-tree-icons' + - url: 'https://github.com/neovim/nvim-lspconfig' + name: 'nvim-lspconfig' + - url: 'https://github.com/hrsh7th/nvim-cmp' + name: 'nvim-cmp' + - url: 'https://github.com/hrsh7th/cmp-buffer' + name: 'cmp-buffer' + - url: 'https://github.com/hrsh7th/cmp-path' + name: 'cmp-path' + - url: 'https://github.com/hrsh7th/cmp-omni' + name: 'cmp-omni' + - url: 'https://github.com/hrsh7th/cmp-nvim-lsp' + name: 'cmp-nvim-lsp' + - url: 'https://github.com/hrsh7th/cmp-nvim-lua' + name: 'cmp-nvim-lua' + - url: 'https://github.com/nvim-treesitter/nvim-treesitter' + name: 'nvim-treesitter' + - url: 'https://github.com/nvim-lua/plenary.nvim' + name: 'plenary.nvim' + - url: 'https://github.com/nvim-telescope/telescope-fzf-native.nvim' + name: 'telescope-fzf-native.nvim' + - url: 'https://github.com/nvim-telescope/telescope.nvim' + name: 'telescope.nvim' + version: '0.1.x' + - url: 'https://github.com/L3MON4D3/LuaSnip' + name: 'luasnip' + version: 'v1.0.0' + - url: 'https://github.com/lewis6991/gitsigns.nvim' + name: 'gitsigns.nvim' + version: 'v0.9.0' + - url: 'https://github.com/nvim-lualine/lualine.nvim' + name: 'lualine' + - url: 'https://github.com/lukas-reineke/indent-blankline.nvim' + name: 'indent-blankline.nvim' + version: 'v3.7.2' + - url: 'https://github.com/projekt0n/github-nvim-theme.git' + name: 'github-colors' + version: 'v1.1.2' language_servers: [] diff --git a/group_vars/all/system.yml b/group_vars/all/system.yml index d056de1..f57d500 100644 --- a/group_vars/all/system.yml +++ b/group_vars/all/system.yml @@ -1,5 +1,4 @@ ---- -xdg_config_dir: "{{ ansible_env.HOME }}/.config" -xdg_data_dir: "{{ ansible_env.HOME }}/.local/share" +xdg_config_dir: '{{ ansible_env.HOME }}/.config' +xdg_data_dir: '{{ ansible_env.HOME }}/.local/share' packages: [] diff --git a/group_vars/arch/aur.yml b/group_vars/arch/aur.yml index a14af3d..6f1c646 100644 --- a/group_vars/arch/aur.yml +++ b/group_vars/arch/aur.yml @@ -1,41 +1,40 @@ ---- aur_packages: - - url: "https://aur.archlinux.org/nvm.git" - name: "nvm" - package_name: "nvm" - version: "0.40.0-1" - arch: "any" + - url: 'https://aur.archlinux.org/nvm.git' + name: 'nvm' + package_name: 'nvm' + version: '0.40.0-1' + arch: 'any' -aur_build_dir: "/usr/local/src" -python_build_dir: "/usr/local/src" -python_install_dir: "/opt" +aur_build_dir: '/usr/local/src' +python_build_dir: '/usr/local/src' +python_install_dir: '/opt' -python_download_url: "https://www.python.org/ftp/python" +python_download_url: 'https://www.python.org/ftp/python' python_versions: - version: 3.12.9 - path: "python3.12" - binary: "python3.12" + path: 'python3.12' + binary: 'python3.12' - version: 3.11.9 - path: "python3.11" - binary: "python3.11" + path: 'python3.11' + binary: 'python3.11' - version: 3.10.0 - path: "python3.10" - binary: "python3.10" + path: 'python3.10' + binary: 'python3.10' - version: 3.9.14 - path: "python3.9" - binary: "python3.9" + path: 'python3.9' + binary: 'python3.9' - version: 3.8.14 - path: "python3.8" - binary: "python3.8" + path: 'python3.8' + binary: 'python3.8' - version: 3.7.14 - path: "python3.7" - binary: "python3.7" + path: 'python3.7' + binary: 'python3.7' - version: 3.6.15 - path: "python3.6" - binary: "python3.6" + path: 'python3.6' + binary: 'python3.6' diff --git a/group_vars/arch/neovim.yml b/group_vars/arch/neovim.yml index ef6fb27..de53353 100644 --- a/group_vars/arch/neovim.yml +++ b/group_vars/arch/neovim.yml @@ -1,49 +1,48 @@ ---- language_servers: - package: ansible-language-server - server_name: "ansiblels" + server_name: 'ansiblels' auto_setup: true - package: typescript-language-server - server_name: "ts_ls" + server_name: 'ts_ls' auto_setup: true - package: vscode-json-languageserver - server_name: "jsonls" + server_name: 'jsonls' auto_setup: true - package: vscode-css-languageserver - server_name: "cssls" + server_name: 'cssls' auto_setup: true - package: bash-language-server - server_name: "bashls" + server_name: 'bashls' auto_setup: true - package: marksman - server_name: "marksman" + server_name: 'marksman' auto_setup: true - package: esbonio - server_name: "esbonio" - auto_setup: false + server_name: 'esbonio' + auto_setup: true - package: lua-language-server - server_name: "lua_ls" + server_name: 'lua_ls' auto_setup: false - package: yaml-language-server - server_name: "yamlls" + server_name: 'yamlls' auto_setup: false - package: vscode-html-languageserver - server_name: "html" + server_name: 'html' auto_setup: false - - package: ruff - server_name: "ruff" - auto_setup: true + - package: ruff-lsp + server_name: 'ruff' + auto_setup: false - package: pyright - server_name: "pyright" + server_name: 'pyright' auto_setup: false diff --git a/group_vars/arch/system.yml b/group_vars/arch/system.yml index 0de7041..ae21d6d 100644 --- a/group_vars/arch/system.yml +++ b/group_vars/arch/system.yml @@ -1,4 +1,3 @@ ---- packages: - python - git @@ -15,12 +14,4 @@ packages: - slirp4netns - tree-sitter - ripgrep - - fd - uv - - fakeroot - - debugedit - - which - - gcc - - make - - esbonio - - marksman diff --git a/group_vars/debian/neovim.yml b/group_vars/debian/neovim.yml index cb53eb6..c5e5319 100644 --- a/group_vars/debian/neovim.yml +++ b/group_vars/debian/neovim.yml @@ -1,19 +1,18 @@ ---- # TODO: add lua language server, see https://github.com/LuaLS/lua-language-server? language_servers: - - package: "@ansible/ansible-language-server" - server_name: "ansiblels" + - package: '@ansible/ansible-language-server' + server_name: 'ansiblels' auto_setup: true - package: yaml-language-server - server_name: "yamlls" + server_name: 'yamlls' auto_setup: false - package: bash-language-server - server_name: "bashls" + server_name: 'bashls' auto_setup: true neovim: - version: "v0.11.4" - install_path: "/opt/nvim" - download_checksum: sha256:a74740047e73b2b380d63a474282814063d10650cd6cc95efa16d1713c7e616c + version: 'v0.10.4' + install_path: '/opt/nvim' + download_checksum: sha256:95aaa8e89473f5421114f2787c13ae0ec6e11ebbd1a13a1bd6fcf63420f8073f diff --git a/group_vars/debian/system.yml b/group_vars/debian/system.yml index 2660131..56be4aa 100644 --- a/group_vars/debian/system.yml +++ b/group_vars/debian/system.yml @@ -1,4 +1,3 @@ ---- packages: - python3 - git diff --git a/inventory.yml b/inventory.yml index 5f1897f..438697a 100644 --- a/inventory.yml +++ b/inventory.yml @@ -1,4 +1,3 @@ ---- personal: hosts: xps: &xps @@ -7,9 +6,6 @@ personal: desktop: &desktop ansible_connection: local ansible_become_method: community.general.run0 - htpc: &htpc - ansible_connection: local - ansible_become_method: community.general.run0 fudiggity: &fudiggity ansible_connection: local @@ -17,11 +13,10 @@ debian: hosts: fudiggity: <<: *fudiggity + arch: hosts: xps: <<: *xps desktop: <<: *desktop - htpc: - <<: *htpc diff --git a/playbook.yml b/playbook.yml index 3a63d77..2c644c2 100644 --- a/playbook.yml +++ b/playbook.yml @@ -1,44 +1,43 @@ ---- - name: Development provisioning hosts: - - personal - - arch - - debian + - xps + - desktop + - fudiggity pre_tasks: - name: Verifying that a limit is set ansible.builtin.fail: - msg: "This playbook cannot be run with no limit" + msg: 'This playbook cannot be run with no limit' run_once: true when: ansible_limit is not defined - name: Install packages become: true ansible.builtin.package: - name: "{{ item }}" + name: '{{ item }}' state: present - loop: "{{ packages }}" + loop: '{{ packages }}' - name: Add git forge to known hosts ansible.builtin.include_role: name: common - tasks_from: "known_hosts.yml" + tasks_from: 'known_hosts.yml' vars: - user: "{{ ansible_user_id }}" + user: '{{ ansible_user_id }}' items: - - domain: "{{ git_domain }}" - key: "{{ git_host_key }}" + - domain: '{{ git_domain }}' + key: '{{ git_host_key }}' when: ansible_hostname != 'fudiggity' tasks: - name: Setup dotfiles - ansible.builtin.import_tasks: "tasks/dotfiles.yml" + ansible.builtin.import_tasks: 'tasks/dotfiles.yml' tags: dotfiles - name: Include generic neovim tasks - ansible.builtin.import_tasks: "tasks/neovim.yml" + ansible.builtin.import_tasks: 'tasks/neovim.yml' tags: neovim - name: Include debian neovim tasks - ansible.builtin.import_tasks: "tasks/debian/neovim.yml" + ansible.builtin.import_tasks: 'tasks/debian/neovim.yml' when: "'debian' in group_names" tags: neovim @@ -50,23 +49,23 @@ manager: pacman - name: Include arch neovim tasks - ansible.builtin.import_tasks: "tasks/arch/neovim.yml" + ansible.builtin.import_tasks: 'tasks/arch/neovim.yml' when: "'arch' in group_names" tags: neovim - name: Install AUR packages - ansible.builtin.import_tasks: "tasks/arch/aur.yml" + ansible.builtin.import_tasks: 'tasks/arch/aur.yml' tags: aur - name: Setup docker - ansible.builtin.import_tasks: "tasks/arch/docker.yml" + ansible.builtin.import_tasks: 'tasks/arch/docker.yml' tags: docker - name: Setup python versions - ansible.builtin.include_tasks: "tasks/arch/python.yml" - loop: "{{ python_versions }}" + ansible.builtin.include_tasks: 'tasks/arch/python.yml' + loop: '{{ python_versions }}' tags: python - name: Setup NVM - ansible.builtin.import_tasks: "tasks/arch/nvm.yml" + ansible.builtin.import_tasks: 'tasks/arch/nvm.yml' tags: nvm diff --git a/requirements.yml b/requirements.yml index 7a0710c..ba54c45 100644 --- a/requirements.yml +++ b/requirements.yml @@ -1,5 +1,4 @@ ---- -- src: git+https://forgejo.fudiggity.nl/sonny/common-ansible.git +- src: git+https://git.fudiggity.nl/ansible/common.git name: common version: master scm: git diff --git a/tasks/arch/aur-package.yml b/tasks/arch/aur-package.yml index 8955b63..e00f8ab 100644 --- a/tasks/arch/aur-package.yml +++ b/tasks/arch/aur-package.yml @@ -1,10 +1,9 @@ ---- - name: Set package directory ansible.builtin.set_fact: - build_dir: "{{ aur_build_dir }}/{{ item.name }}" + build_dir: '{{ aur_build_dir }}/{{ item.name }}' -- name: "Retrieve package name for {{ item.name }}" - ansible.builtin.command: +- name: 'Retrieve package name for {{ item.name }}' + command: argv: - grep - --only-matching @@ -13,8 +12,8 @@ - "{{ build_dir }}/PKGBUILD" register: pkg_name -- name: "Retrieve package version for {{ item.name }}" - ansible.builtin.command: +- name: 'Retrieve package version for {{ item.name }}' + command: argv: - grep - --only-matching @@ -23,8 +22,8 @@ - "{{ build_dir }}/PKGBUILD" register: pkg_version -- name: "Retrieve package release for {{ item.name }}" - ansible.builtin.command: +- name: 'Retrieve package release for {{ item.name }}' + command: argv: - grep - --only-matching @@ -35,20 +34,20 @@ - name: Set package filename & version ansible.builtin.set_fact: - package_filename: "{{ pkg_name.stdout }}-{{ pkg_version.stdout }}-{{ pkg_release.stdout }}-{{ item.arch }}.pkg.tar.zst" + package_filename: '{{ pkg_name.stdout }}-{{ pkg_version.stdout }}-{{ pkg_release.stdout }}-{{ item.arch }}.pkg.tar.zst' installed_version: ansible_facts.packages[item.package_name].version|default('') -- name: "Build package {{ item.name }}" - ansible.builtin.command: "makepkg --syncdeps --rmdeps --clean --noconfirm --force" +- name: 'Build package {{ item.name }}' + ansible.builtin.command: 'makepkg --syncdeps --rmdeps --clean --noconfirm --force' args: - chdir: "{{ build_dir }}" - creates: "{{ build_dir }}/{{ package_filename }}" + chdir: '{{ build_dir }}' + creates: '{{ build_dir }}/{{ package_filename }}' register: package_build when: item.version != installed_version -- name: "Install {{ item.name }}" +- name: 'Install {{ item.name }}' become: true community.general.pacman: - name: "{{ build_dir }}/{{ package_filename }}" + name: '{{ build_dir }}/{{ package_filename }}' state: present when: item.version != installed_version diff --git a/tasks/arch/aur.yml b/tasks/arch/aur.yml index 14ce325..e31aab7 100644 --- a/tasks/arch/aur.yml +++ b/tasks/arch/aur.yml @@ -1,27 +1,26 @@ ---- - name: Retrieve directory stats ansible.builtin.stat: - path: "{{ aur_build_dir }}/{{ item.name }}" - loop: "{{ aur_packages }}" + path: '{{ aur_build_dir }}/{{ item.name }}' + loop: '{{ aur_packages }}' - name: Clone aur packages become: true ansible.builtin.git: - repo: "{{ item.url }}" - dest: "{{ aur_build_dir }}/{{ item.name }}" + repo: '{{ item.url }}' + dest: '{{ aur_build_dir }}/{{ item.name }}' update: true - loop: "{{ aur_packages }}" + loop: '{{ aur_packages }}' - name: Change aur package directories owner become: true ansible.builtin.file: - path: "{{ aur_build_dir }}/{{ item.name }}" + path: '{{ aur_build_dir }}/{{ item.name }}' state: directory - owner: "{{ ansible_user_id }}" - group: "{{ ansible_user_id }}" + owner: '{{ ansible_user_id }}' + group: '{{ ansible_user_id }}' recurse: true - loop: "{{ aur_packages }}" + loop: '{{ aur_packages }}' - name: Build & install aur packages - ansible.builtin.include_tasks: "tasks/arch/aur-package.yml" - loop: "{{ aur_packages }}" + ansible.builtin.include_tasks: 'tasks/arch/aur-package.yml' + loop: '{{ aur_packages }}' diff --git a/tasks/arch/docker.yml b/tasks/arch/docker.yml index fa96d20..c68a81f 100644 --- a/tasks/arch/docker.yml +++ b/tasks/arch/docker.yml @@ -1,8 +1,7 @@ ---- - name: Remove docker mapping files become: true ansible.builtin.file: - path: "{{ item }}" + path: '{{ item }}' state: absent loop: - /etc/subgid @@ -11,38 +10,38 @@ - name: Setup desktop configuration become: true ansible.builtin.file: - path: "files/desktop/docker-daemon.json" - dest: "/etc/docker/daemon.json" - mode: "0755" + path: 'files/desktop/docker-daemon.json' + dest: '/etc/docker/daemon.json' + mode: '0755' when: ansible_hostname == 'desktop' - name: Remove user setup desktop configuration ansible.builtin.file: - path: "{{ xdg_config_dir }}/docker/daemon.json" + path: '{{ xdg_config_dir }}/docker/daemon.json' state: absent when: ansible_hostname == 'desktop' - name: Check for .bashrc.override ansible.builtin.stat: - path: "{{ ansible_env.HOME }}/.bashrc.override" + path: '{{ ansible_env.HOME }}/.bashrc.override' register: bashrc_override - name: Create .bashrc.override ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.bashrc.override" + path: '{{ ansible_env.HOME }}/.bashrc.override' state: touch - mode: "0755" + mode: '0755' when: not bashrc_override.stat.exists - name: Remove rootless DOCKER_HOST variable assignment ansible.builtin.lineinfile: - path: "{{ ansible_env.HOME }}/.bashrc.override" - regexp: "^export DOCKER_HOST=" - line: "" + path: '{{ ansible_env.HOME }}/.bashrc.override' + regexp: '^export DOCKER_HOST=' + line: '' - name: Disable user docker socket ansible.builtin.systemd: - name: "{{ item }}" + name: '{{ item }}' state: stopped enabled: false scope: user diff --git a/tasks/arch/neovim.yml b/tasks/arch/neovim.yml index 6851bbb..0cccfa1 100644 --- a/tasks/arch/neovim.yml +++ b/tasks/arch/neovim.yml @@ -1,7 +1,6 @@ ---- - name: Install language servers become: true community.general.pacman: - name: "{{ item }}" + name: '{{ item }}' state: present loop: '{{ language_servers | map(attribute="package") | list }}' diff --git a/tasks/arch/nvm.yml b/tasks/arch/nvm.yml index 2a29236..b2f2e36 100644 --- a/tasks/arch/nvm.yml +++ b/tasks/arch/nvm.yml @@ -1,16 +1,15 @@ ---- - name: Set NVM install directory ansible.builtin.set_fact: - install_dir: "{{ xdg_config_dir }}/nvm" + install_dir: '{{ xdg_config_dir }}/nvm' - name: Remove manually installed nvm install directory ansible.builtin.file: - path: "{{ install_dir }}" + path: '{{ install_dir }}' state: absent - name: Remove nvm entry from bashrc ansible.builtin.lineinfile: - path: "{{ ansible_env.HOME }}/.bashrc.override" + path: '{{ ansible_env.HOME }}/.bashrc.override' line: > [ -s "{{ install_dir }}/nvm.sh" ] && \. "{{ install_dir }}/nvm.sh" # This loads nvm state: absent diff --git a/tasks/arch/python.yml b/tasks/arch/python.yml index ddc6fb4..72bfbff 100644 --- a/tasks/arch/python.yml +++ b/tasks/arch/python.yml @@ -1,66 +1,65 @@ ---- -- name: "Check for {{ item.binary }} binary" - ansible.builtin.command: "which {{ item.binary }}" +- name: 'check for {{ item.binary }} binary' + command: 'which {{ item.binary }}' changed_when: false failed_when: python_installed.rc not in [ 0, 1 ] register: python_installed -- name: "Check for {{ item.binary }} download" - ansible.builtin.stat: - path: "{{ python_build_dir }}/python-{{ item.version }}.tgz" +- name: 'check for {{ item.binary }} download' + stat: + path: '{{ python_build_dir }}/python-{{ item.version }}.tgz' register: python_download -- when: python_installed.rc not in [ 0 ] - block: +- block: # TODO: verify for checksum - - name: "Retrieve python {{ item.version }} source" + - name: 'retrieve python {{ item.version }} source' become: true - ansible.builtin.get_url: - url: "{{ python_download_url }}/{{ item.version }}/Python-{{ item.version }}.tgz" - dest: "{{ python_build_dir }}/python-{{ item.version }}.tgz" - owner: "{{ ansible_user_id }}" - group: "{{ ansible_user_id }}" + get_url: + url: '{{ python_download_url }}/{{ item.version }}/Python-{{ item.version }}.tgz' + dest: '{{ python_build_dir }}/python-{{ item.version }}.tgz' + owner: '{{ ansible_user_id }}' + group: '{{ ansible_user_id }}' when: not python_download.stat.exists - - name: "Extract python {{ item.version }} sources" + - name: 'extract python {{ item.version }} sources' become: true - ansible.builtin.unarchive: - src: "{{ python_build_dir }}/python-{{ item.version }}.tgz" - dest: "{{ python_build_dir }}" - include: "Python-{{ item.version }}" + unarchive: + src: '{{ python_build_dir }}/python-{{ item.version }}.tgz' + dest: '{{ python_build_dir }}' + include: 'Python-{{ item.version }}' - - name: Rename source directory + - name: rename source directory become: true - ansible.builtin.command: "mv {{ python_build_dir}}/Python-{{ item.version }} {{ python_build_dir }}/{{ item.path }}" + ansible.builtin.command: 'mv {{ python_build_dir}}/Python-{{ item.version }} {{ python_build_dir }}/{{ item.path }}' - - name: Set correct permissions + - name: set correct permissions become: true - ansible.builtin.file: - path: "{{ python_build_dir }}/{{ item.path }}" + file: + path: '{{ python_build_dir }}/{{ item.path }}' recurse: true - owner: "{{ ansible_user_id }}" - group: "{{ ansible_user_id }}" + owner: '{{ ansible_user_id }}' + group: '{{ ansible_user_id }}' state: directory - - name: Configure build - ansible.builtin.command: "sh ./configure --prefix={{ python_install_dir }}/{{ item.path }}" + - name: configure build + ansible.builtin.command: 'sh ./configure --prefix={{ python_install_dir }}/{{ item.path }}' args: - chdir: "{{ python_build_dir }}/{{ item.path }}/" + chdir: '{{ python_build_dir }}/{{ item.path }}/' - - name: Make build - ansible.builtin.command: "make" + - name: make build + ansible.builtin.command: 'make' args: - chdir: "{{ python_build_dir }}/{{ item.path }}/" + chdir: '{{ python_build_dir }}/{{ item.path }}/' - - name: Install build + - name: install build become: true - ansible.builtin.command: "make install" + ansible.builtin.command: 'make install' args: - chdir: "{{ python_build_dir }}/{{ item.path }}/" + chdir: '{{ python_build_dir }}/{{ item.path }}/' - - name: "Create symlink for python {{ item.version }}" + - name: 'create symlink for python {{ item.version }}' become: true - ansible.builtin.file: - src: "{{ python_install_dir }}/{{ item.path }}/bin/{{ item.binary }}" - dest: "/usr/bin/{{ item.binary }}" + file: + src: '{{ python_install_dir }}/{{ item.path }}/bin/{{ item.binary }}' + dest: '/usr/bin/{{ item.binary }}' state: link + when: python_installed.rc not in [ 0 ] diff --git a/tasks/debian/neovim.yml b/tasks/debian/neovim.yml index a9cd4b4..939a741 100644 --- a/tasks/debian/neovim.yml +++ b/tasks/debian/neovim.yml @@ -1,8 +1,7 @@ ---- - name: Install language servers on debian hosts become: true community.general.npm: - name: "{{ item }}" + name: '{{ item }}' global: true loop: '{{ language_servers | map(attribute="package") | list }}' @@ -10,16 +9,16 @@ become: true ansible.builtin.file: state: directory - path: "{{ neovim.install_path }}" - owner: "{{ ansible_user_id }}" - group: "{{ ansible_user_gid }}" - mode: "0755" + 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" + - '{{ neovim.install_path }}/bin/nvim' + - '--version' register: neovim_stats changed_when: false ignore_errors: true @@ -31,21 +30,21 @@ - name: Download neovim {{ neovim.version }} ansible.builtin.get_url: - url: "https://github.com/neovim/neovim/releases/download/{{ neovim.version }}/nvim-linux-x86_64.tar.gz" + url: 'https://github.com/neovim/neovim/releases/download/{{ neovim.version }}/nvim-linux-x86_64.tar.gz' dest: /tmp/nvim-linux64.tar.gz - mode: "0755" - checksum: "{{ neovim.download_checksum }}" + mode: '0755' + checksum: '{{ neovim.download_checksum }}' 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 }}" + dest: '{{ neovim.install_path }}' extra_opts: - - "--strip-components=1" - - "--show-stored-names" - - "--overwrite" + - '--strip-components=1' + - '--show-stored-names' + - '--overwrite' when: | neovim_download.state == 'file' and (neovim_installed_version is undefined or neovim_installed_version != neovim.version) @@ -53,6 +52,6 @@ - name: Add neovim to PATH become: true ansible.builtin.template: - src: "templates/debian/nvim.profile.j2" - dest: "/etc/profile.d/neovim.sh" - mode: "0755" + src: 'templates/debian/nvim.profile.j2' + dest: '/etc/profile.d/neovim.sh' + mode: '0755' diff --git a/tasks/dotfiles.yml b/tasks/dotfiles.yml index 470bda9..44445b2 100644 --- a/tasks/dotfiles.yml +++ b/tasks/dotfiles.yml @@ -1,70 +1,51 @@ ---- - name: Clone dotfiles ansible.builtin.git: - repo: "{{ dotfiles_repo }}" - dest: "{{ ansible_env.HOME }}/dotfiles" + repo: '{{ dotfiles_repo }}' + dest: '{{ ansible_env.HOME }}/dotfiles' version: master update: true - name: Create xdg configuration directories ansible.builtin.file: - path: "{{ item }}" + path: '{{ item }}' state: directory - mode: "0755" + mode: '0755' loop: - - "{{ xdg_config_dir }}/git" - - "{{ xdg_config_dir }}/tmux" + - '{{ xdg_config_dir }}/git' + - '{{ xdg_config_dir }}/tmux' - name: Remove previous dotfiles ansible.builtin.file: - path: "{{ item }}" + path: '{{ item }}' state: absent loop: - - "{{ ansible_env.HOME }}/.tmux.conf" - - "{{ ansible_env.HOME }}/.gitconfig" + - '{{ ansible_env.HOME }}/.tmux.conf' + - '{{ ansible_env.HOME }}/.gitconfig' - name: Setup dotfiles ansible.builtin.file: - path: "{{ item.dest }}" - src: "{{ item.src }}" + path: '{{ item.dest }}' + src: '{{ item.src }}' state: link force: true loop: - - src: "{{ ansible_env.HOME }}/dotfiles/.vimrc" - dest: "{{ ansible_env.HOME }}/.vimrc" + - src: '{{ ansible_env.HOME }}/dotfiles/.vimrc' + dest: '{{ ansible_env.HOME }}/.vimrc' - - src: "{{ ansible_env.HOME }}/dotfiles/.bashrc" - dest: "{{ ansible_env.HOME }}/.bashrc" + - src: '{{ ansible_env.HOME }}/dotfiles/.bashrc' + dest: '{{ ansible_env.HOME }}/.bashrc' - - src: "{{ ansible_env.HOME }}/dotfiles/.profile" - dest: "{{ ansible_env.HOME }}/.profile" + - src: '{{ ansible_env.HOME }}/dotfiles/.profile' + dest: '{{ ansible_env.HOME }}/.profile' - - src: "{{ ansible_env.HOME }}/dotfiles/tmux/tmux.conf" - dest: "{{ xdg_config_dir }}/tmux/tmux.conf" + - src: '{{ ansible_env.HOME }}/dotfiles/.tmux.conf' + dest: '{{ xdg_config_dir }}/tmux/tmux.conf' - - src: "{{ ansible_env.HOME }}/dotfiles/tmux/light.conf" - dest: "{{ xdg_config_dir }}/tmux/light.conf" - - - src: "{{ ansible_env.HOME }}/dotfiles/tmux/dark.conf" - dest: "{{ xdg_config_dir }}/tmux/dark.conf" - - - src: "{{ ansible_env.HOME }}/dotfiles/.gitignore" - dest: "{{ xdg_config_dir }}/git/ignore" + - src: '{{ ansible_env.HOME }}/dotfiles/.gitignore' + dest: '{{ xdg_config_dir }}/git/ignore' - name: Copy git configuration ansible.builtin.template: - src: "templates/gitconfig.j2" - dest: "{{ xdg_config_dir }}/git/config" - mode: "0755" - -- name: Create script directory - ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.local/bin" - state: directory - mode: "0755" - -- name: Copy tmux toggle script - ansible.builtin.template: - src: "templates/tmux-toggle.j2" - dest: "{{ ansible_env.HOME }}/.local/bin/tmux-toggle.sh" - mode: "0755" + src: 'templates/gitconfig.j2' + dest: '{{ xdg_config_dir }}/git/config' + mode: '0755' diff --git a/tasks/neovim.yml b/tasks/neovim.yml index 3303d3a..f6e0696 100644 --- a/tasks/neovim.yml +++ b/tasks/neovim.yml @@ -1,36 +1,35 @@ ---- - name: Ensure neovim configuration directories exist ansible.builtin.file: - path: "{{ item }}" + path: '{{ item }}' state: directory - mode: "0755" + mode: '0755' loop: - - "{{ xdg_config_dir }}/nvim/" - - "{{ xdg_config_dir }}/nvim/lua" - - "{{ xdg_config_dir }}/nvim/after" - - "{{ xdg_config_dir }}/nvim/after/ftplugin" - - "{{ xdg_data_dir }}/nvim/site" - - "{{ xdg_data_dir }}/nvim/site/pack" - - "{{ xdg_data_dir }}/nvim/site/pack/default" - - "{{ xdg_data_dir }}/nvim/site/pack/default/start" + - '{{ xdg_config_dir }}/nvim/' + - '{{ xdg_config_dir }}/nvim/lua' + - '{{ xdg_config_dir }}/nvim/after' + - '{{ xdg_config_dir }}/nvim/after/ftplugin' + - '{{ xdg_data_dir }}/nvim/site' + - '{{ xdg_data_dir }}/nvim/site/pack' + - '{{ xdg_data_dir }}/nvim/site/pack/default' + - '{{ xdg_data_dir }}/nvim/site/pack/default/start' - name: Remove old neovim packages ansible.builtin.file: - path: "{{ item }}" + path: '{{ item }}' state: absent loop: - - "{{ xdg_data_dir }}/nvim/site/pack/default/start/catpuccin" - - "{{ xdg_data_dir }}/nvim/site/pack/default/start/vim-colors-xcode" + - '{{ xdg_data_dir }}/nvim/site/pack/default/start/catpuccin' + - '{{ 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: - repo: "{{ item.url }}" - dest: "{{ xdg_data_dir }}/nvim/site/pack/default/start/{{ item.name }}" + repo: '{{ item.url }}' + dest: '{{ xdg_data_dir }}/nvim/site/pack/default/start/{{ item.name }}' update: true version: '{{ item.version | default("HEAD") }}' force: true # some maintainers overwrite existing tags :/ - loop: "{{ neovim_plugins }}" + loop: '{{ neovim_plugins }}' - name: Install neovim node package become: true @@ -40,93 +39,87 @@ - name: Remove old neovim configuration file ansible.builtin.file: - path: "{{ xdg_config_dir }}/nvim/init.vim" + path: '{{ xdg_config_dir }}/nvim/init.vim' state: absent - name: Remove coc.nvim extension ansible.builtin.file: - path: "{{ xdg_data_dir }}/nvim/site/pack/default/start/coc.nvim" + path: '{{ xdg_data_dir }}/nvim/site/pack/default/start/coc.nvim' state: absent - name: Setup neovim configuration files ansible.builtin.template: - dest: "{{ item.dest }}" - src: "{{ item.src }}" - mode: "0755" + 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/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/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/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/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/lua.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/lua.lua' - - src: "templates/nvim/ftplugin/markdown.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/after/ftplugin/markdown.lua" + - src: 'templates/nvim/ftplugin/python.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/python.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/rst.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/after/ftplugin/rst.lua" + - src: 'templates/nvim/ftplugin/sh.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/sh.lua' - - src: "templates/nvim/ftplugin/scss.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/after/ftplugin/scss.lua" + - src: 'templates/nvim/ftplugin/yaml.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/after/ftplugin/yaml.lua' - - src: "templates/nvim/ftplugin/sh.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/after/ftplugin/sh.lua" + - src: 'templates/nvim/init.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/init.lua' - - src: "templates/nvim/ftplugin/yaml.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/after/ftplugin/yaml.lua" + - src: 'templates/nvim/lua/lsp.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/lsp.lua' - - src: "templates/nvim/init.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/init.lua" + - src: 'templates/nvim/lua/options.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/options.lua' - - src: "templates/nvim/lua/lsp.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/lua/lsp.lua" + - src: 'templates/nvim/lua/tree-sitter.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/tree-sitter.lua' - - src: "templates/nvim/lua/options.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/lua/options.lua" + - src: 'templates/nvim/lua/git-signs.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/git-signs.lua' - - src: "templates/nvim/lua/tree-sitter.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/lua/tree-sitter.lua" + - src: 'templates/nvim/lua/lua-line.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/lua-line.lua' - - src: "templates/nvim/lua/git-signs.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/lua/git-signs.lua" + - src: 'templates/nvim/lua/telescope.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/_telescope.lua' - - src: "templates/nvim/lua/lua-line.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/lua/lua-line.lua" + - src: 'templates/nvim/lua/indent-blankline.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/indent-blankline.lua' - - src: "templates/nvim/lua/telescope.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/lua/_telescope.lua" + - src: 'templates/nvim/lua/nvim-tree.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/_nvim-tree.lua' - - src: "templates/nvim/lua/indent-blankline.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/lua/indent-blankline.lua" + - src: 'templates/nvim/lua/colorscheme.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/colorscheme.lua' - - src: "templates/nvim/lua/nvim-tree.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/lua/_nvim-tree.lua" + - src: 'templates/nvim/lua/source-link.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/_source-link.lua' - - src: "templates/nvim/lua/colorscheme.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/lua/colorscheme.lua" + - src: 'templates/nvim/lua/filetype.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/_filetype.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" - - - src: "templates/nvim/lua/diagnostic.lua.j2" - dest: "{{ xdg_config_dir }}/nvim/lua/diagnostic.lua" + - src: 'templates/nvim/lua/formatting.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/formatting.lua' diff --git a/templates/gitconfig.j2 b/templates/gitconfig.j2 index 3054313..84f97da 100644 --- a/templates/gitconfig.j2 +++ b/templates/gitconfig.j2 @@ -4,9 +4,6 @@ email = {{ git_email }} name = {{ git_name }} -[gpg] -format = ssh - [core] editor = nvim {% if ansible_facts['os_family'] == 'Archlinux' %} diff --git a/templates/nvim/ftplugin/markdown.lua.j2 b/templates/nvim/ftplugin/markdown.lua.j2 deleted file mode 100644 index 058970f..0000000 --- a/templates/nvim/ftplugin/markdown.lua.j2 +++ /dev/null @@ -1,7 +0,0 @@ --- {{ ansible_managed }} - -vim.opt.tabstop = 2 -vim.opt.softtabstop = 2 -vim.opt.shiftwidth = 2 -vim.opt.expandtab = true -vim.opt.autoindent = true diff --git a/templates/nvim/ftplugin/rst.lua.j2 b/templates/nvim/ftplugin/rst.lua.j2 deleted file mode 100644 index 058970f..0000000 --- a/templates/nvim/ftplugin/rst.lua.j2 +++ /dev/null @@ -1,7 +0,0 @@ --- {{ ansible_managed }} - -vim.opt.tabstop = 2 -vim.opt.softtabstop = 2 -vim.opt.shiftwidth = 2 -vim.opt.expandtab = true -vim.opt.autoindent = true diff --git a/templates/nvim/init.lua.j2 b/templates/nvim/init.lua.j2 index a18b81c..309c912 100644 --- a/templates/nvim/init.lua.j2 +++ b/templates/nvim/init.lua.j2 @@ -11,4 +11,4 @@ require('indent-blankline') require('_nvim-tree') require('lua-line') require('_source-link') -require('diagnostic') +require('formatting') diff --git a/templates/nvim/lua/colorscheme.lua.j2 b/templates/nvim/lua/colorscheme.lua.j2 index 9ae709f..4cbea41 100644 --- a/templates/nvim/lua/colorscheme.lua.j2 +++ b/templates/nvim/lua/colorscheme.lua.j2 @@ -4,7 +4,7 @@ local background_callback = function() if vim.o.background == 'dark' then vim.cmd('colorscheme github_dark_dimmed') else - vim.cmd('colorscheme github_light_tritanopia') + vim.cmd('colorscheme github_light') end -- force a full redraw: @@ -29,7 +29,7 @@ Use the `Introspect` option to inspect available options: dbus-send \ --session \ ---print-reply \ +--print-reply ] --reply-timeout=2000 \ --type=method_call \ --dest=org.freedesktop.portal.Desktop \ diff --git a/templates/nvim/lua/diagnostic.lua.j2 b/templates/nvim/lua/diagnostic.lua.j2 deleted file mode 100644 index 97baa9e..0000000 --- a/templates/nvim/lua/diagnostic.lua.j2 +++ /dev/null @@ -1,11 +0,0 @@ --- {{ ansible_managed }} - -vim.diagnostic.config { - float = { - suffix = function(diagnostic) - return (' %s | [%s]'):format(diagnostic.code, diagnostic.source) - end - }, - - virtual_text = { current_line = true } -} diff --git a/templates/nvim/lua/formatting.lua.j2 b/templates/nvim/lua/formatting.lua.j2 new file mode 100644 index 0000000..36a4279 --- /dev/null +++ b/templates/nvim/lua/formatting.lua.j2 @@ -0,0 +1,39 @@ +-- {{ ansible_managed }} + +local enable_formatting = vim.env.enable_formatting == 'true'; +local legacy_formatting = nil; + +-- TODO: move to utils file +-- TODO: add efm-languageserver to lsp.lua +if vim.env.VIRTUAL_ENV ~= nil and enable_formatting == true then + local formatters = vim.fs.find( + { 'isort', 'black' }, + { limit = 1, type = 'file', path = vim.fs.joinpath(vim.env.VIRTUAL_ENV, 'bin') } + ) + + legacy_formatting = #formatters > 0; +end + +if (enable_formatting) then + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('lsp', { clear = true }), + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + + if client.server_capabilities.documentFormattingProvider then + vim.api.nvim_create_autocmd('BufWritePre', { + buffer = args.buf, + callback = function() + vim.lsp.buf.format { + async = false, + id = args.data.client_id, + filter = function(format_client) + return format_client.name ~= 'ruff' or not legacy_formatting + end + } + end, + }) + end + end + }) +end diff --git a/templates/nvim/lua/lsp.lua.j2 b/templates/nvim/lua/lsp.lua.j2 index 83c1adc..78fd62f 100644 --- a/templates/nvim/lua/lsp.lua.j2 +++ b/templates/nvim/lua/lsp.lua.j2 @@ -7,29 +7,29 @@ local on_attach = function(client, bufnr) vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) - vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) - vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) - vim.keymap.set('n', 'la', vim.lsp.buf.code_action, opts) - vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) vim.keymap.set('n', 'wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) - + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) + vim.keymap.set('n', 'la', vim.lsp.buf.code_action, opts) + end + --enable some language servers with the additional completion capabilities --offered by nvim-cmp -local auto_setup_servers = { +local servers = { {% for item in language_servers %} {% if item.auto_setup and not loop.last %} '{{ item.server_name }}', @@ -43,8 +43,10 @@ local auto_setup_servers = { local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) -for _, lsp in ipairs(auto_setup_servers) do - vim.lsp.config[lsp] = { +local nvim_lsp = require('lspconfig') + +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { on_attach = on_attach, capabilities = capabilities, } @@ -53,45 +55,47 @@ end local util = require('lspconfig/util') {% if ansible_facts.os_family == 'Archlinux' %} +local python_root_dir = function(fname) + return util.root_pattern('.git', 'setup.cfg', 'requirements')(fname) or + util.path.dirname(fname) +end -vim.lsp.config['pyright'] = { +nvim_lsp.ruff.setup { on_attach = on_attach, capabilities = capabilities, + root_dir = python_root_dir +} + + +nvim_lsp.pyright.setup { settings = { pyright = { -- Using Ruff's import organizer - disableOrganizeImports = true, + disableOrganizeImports = true, }, - } + }, } local snippet_capabilities = vim.deepcopy(capabilities); snippet_capabilities.textDocument.completion.completionItem.snippetSupport = true -vim.lsp.config['html'] = { +nvim_lsp.html.setup { on_attach = on_attach, capabilities = snippet_capabilities, filetypes = { 'html', 'htmldjango' }, - settings = { - html = { - format = { - templating = true - } - } - } } -vim.lsp.config['cssls'] = { +nvim_lsp.cssls.setup { on_attach = on_attach, capabilities = snippet_capabilities, } -vim.lsp.config['jsonls'] = { +nvim_lsp.jsonls.setup { on_attach = on_attach, capabilities = snippet_capabilities, } -vim.lsp.config['lua_ls'] = { +nvim_lsp.lua_ls.setup { on_attach = on_attach, capabilities = snippet_capabilities, settings = { @@ -103,31 +107,13 @@ vim.lsp.config['lua_ls'] = { } } --- Use system binary for esbonio -vim.lsp.config['esbonio'] = { - on_attach = on_attach, - capabilities = capabilities, - cmd = { '/usr/bin/esbonio' } -} {% endif %} -vim.lsp.config['yamlls'] = { +nvim_lsp.yamlls.setup { on_attach = on_attach, capabilities = capabilities, filetypes = { 'yaml', 'yaml.ansible', 'yaml.docker-compose', 'yaml.gitlab' } } -local servers = { - {% for item in language_servers %} - {% if not loop.last %} - '{{ item.server_name }}', - {% else %} - '{{ item.server_name }}' - {% endif %} - {% endfor %} -} - -vim.lsp.enable { unpack(servers) } - local cmp = require('cmp') local luasnip = require('luasnip') @@ -193,3 +179,11 @@ cmp.setup { end, }, } + +vim.diagnostic.config { + float = { + suffix = function(diagnostic) + return (' %s | [%s]'):format(diagnostic.code, diagnostic.source) + end + }, +} diff --git a/templates/nvim/lua/options.lua.j2 b/templates/nvim/lua/options.lua.j2 index fe35a80..36bbe52 100644 --- a/templates/nvim/lua/options.lua.j2 +++ b/templates/nvim/lua/options.lua.j2 @@ -55,12 +55,5 @@ vim.o.termguicolors = true vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 --- load project specific configuration files -vim.o.exrc = true -vim.o.secure = true - --- disable mouse options -vim.opt.mouse = '' - -- python interpreter vim.g.python3_host_prog = '/usr/bin/python3' diff --git a/templates/nvim/lua/telescope.lua.j2 b/templates/nvim/lua/telescope.lua.j2 index 95c3bc0..b74a42f 100644 --- a/templates/nvim/lua/telescope.lua.j2 +++ b/templates/nvim/lua/telescope.lua.j2 @@ -5,34 +5,20 @@ local builtin = require('telescope.builtin') local opts = { noremap = true, silent = true } -local find_files_unignored = function() - builtin.find_files { hidden = true, no_ignore = true } -end - -local live_grep_unignored = function() - builtin.live_grep { additional_args = { '--unrestricted', '--unrestricted' } } -end - vim.keymap.set('n', 'ff', builtin.find_files, opts) -vim.keymap.set('n', 'fF', find_files_unignored, opts) vim.keymap.set('n', 'fg', builtin.live_grep, opts) -vim.keymap.set('n', 'fG', live_grep_unignored, opts) -vim.keymap.set('n', 'fb', builtin.current_buffer_fuzzy_find, opts) -vim.keymap.set('n', 'fB', builtin.buffers, opts) +vim.keymap.set('n', 'fb', builtin.buffers, opts) vim.keymap.set('n', 'fh', builtin.help_tags, opts) -vim.keymap.set('n', 'fd', builtin.diagnostics, opts) vim.keymap.set('n', 'fj', builtin.jumplist, opts) vim.keymap.set('n', 'fl', builtin.loclist, opts) vim.keymap.set('n', 'fq', builtin.quickfix, opts) vim.keymap.set('n', 'fm', builtin.marks, opts) -vim.keymap.set('n', 'ft', builtin.treesitter, opts) telescope.setup({ defaults = { layout_strategy = 'vertical', layout_config = { - prompt_position = 'bottom', - vertical = { width = 0.8, height = 0.9 } + vertical = { width = 0.5, height = 0.7 } }, }, }) diff --git a/templates/tmux-toggle.j2 b/templates/tmux-toggle.j2 deleted file mode 100644 index 3a2bda6..0000000 --- a/templates/tmux-toggle.j2 +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env sh -# -# {{ ansible_managed }} -# -# Toggle the current window (all panes) between light and dark themes. - -set -e - -current_window_style=$(tmux show -Av window-style) - -case $current_window_style in - 'fg=#000000,bg=#eff0f1') - tmux source-file ~/.config/tmux/dark.conf - ;; - *) - # Change back to the default window style. - tmux source-file ~/.config/tmux/light.conf - ;; -esac