From 747a1fe584d98708c3fc35e344da974f27e2c14c Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Tue, 18 Mar 2025 19:44:22 +0100 Subject: [PATCH 1/6] Replace formatting code --- templates/nvim/lua/lsp.lua.j2 | 45 +++++++++++------------------------ 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/templates/nvim/lua/lsp.lua.j2 b/templates/nvim/lua/lsp.lua.j2 index b76afc8..815f14a 100644 --- a/templates/nvim/lua/lsp.lua.j2 +++ b/templates/nvim/lua/lsp.lua.j2 @@ -176,7 +176,7 @@ vim.diagnostic.config { }, } -local enable_formatting = os.getenv("ENABLE_FORMATTING") +local enable_formatting = os.getenv("enable_formatting") == 'true'; -- format buffers before saving for specific LSPs if (enable_formatting) then @@ -185,38 +185,21 @@ if (enable_formatting) then 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() - local formatting_clients = vim.lsp.get_clients { - bufnr = args.buf, - method = 'textDocument/formatting' - } + local client = vim.lsp.get_client_by_id(args.data.client_id) - local filtered_clients = {} + if vim.list_contains(excluded_clients, client.name) then return end; - for _, client in pairs(formatting_clients) do - if vim.list_contains(excluded_clients, client.name) then - goto skip - end - - table.insert(filtered_clients, client.name) - ::skip:: - end - - if #filtered_clients == 0 then - return - end - - vim.lsp.buf.format { - filter = function(client) - return vim.list_contains(filtered_clients, client.name) - end, - async = false, - id = args.data.client_id - } - end, - }) + 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 + } + end, + }) + end end }) end From d174718477a33626cf1a3bacde12bf59fd8c5b01 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Tue, 18 Mar 2025 19:50:29 +0100 Subject: [PATCH 2/6] Include tmux project init script --- files/tmux.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 files/tmux.sh diff --git a/files/tmux.sh b/files/tmux.sh new file mode 100755 index 0000000..5bcc267 --- /dev/null +++ b/files/tmux.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +session_name=${PWD##*/} +project_directory="$HOME/development/$session_name" +enable_formatting="" + +tmux has-session -t $session_name + +if [ $? != 0 ]; +then + tmux new-session \ + -c $project_directory \ + -ds $session_name \ + -e "project_dir=$project_directory" + + # FIRST WINDOW + tmux send-keys -t $session_name:0 'source ./env/bin/activate' C-m + tmux send-keys -t $session_name:0 'nvim' C-m + + # SECOND WINDOW + tmux new-window -t $session_name + + # THIRD WINDOW + tmux new-window -t $session_name + + # FOURTH WINDOW + tmux new-window -t $session_name + + # SELECT DEFAULT PANE AFTER OPENING + tmux select-window -t $session_name:0 +fi + +tmux attach -t $session_name From 0dc654ae2e0373b219b777295ab48b9cf49beec8 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Tue, 18 Mar 2025 19:56:11 +0100 Subject: [PATCH 3/6] Remove excluded clients Should be disabled in LSP configuration --- templates/nvim/lua/lsp.lua.j2 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/templates/nvim/lua/lsp.lua.j2 b/templates/nvim/lua/lsp.lua.j2 index 815f14a..8a09c38 100644 --- a/templates/nvim/lua/lsp.lua.j2 +++ b/templates/nvim/lua/lsp.lua.j2 @@ -180,15 +180,11 @@ local enable_formatting = os.getenv("enable_formatting") == 'true'; -- 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) local client = vim.lsp.get_client_by_id(args.data.client_id) - if vim.list_contains(excluded_clients, client.name) then return end; - if client.server_capabilities.documentFormattingProvider then vim.api.nvim_create_autocmd('BufWritePre', { buffer = args.buf, From 6adb1f506f472174d5c4d9c226f824c676b0bff9 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Tue, 18 Mar 2025 20:16:43 +0100 Subject: [PATCH 4/6] Add additional configuration for lua lsp --- group_vars/arch/neovim.yml | 2 +- templates/nvim/lua/lsp.lua.j2 | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/group_vars/arch/neovim.yml b/group_vars/arch/neovim.yml index 6963cd8..de53353 100644 --- a/group_vars/arch/neovim.yml +++ b/group_vars/arch/neovim.yml @@ -29,7 +29,7 @@ language_servers: - package: lua-language-server server_name: 'lua_ls' - auto_setup: true + auto_setup: false - package: yaml-language-server server_name: 'yamlls' diff --git a/templates/nvim/lua/lsp.lua.j2 b/templates/nvim/lua/lsp.lua.j2 index 8a09c38..7e9c221 100644 --- a/templates/nvim/lua/lsp.lua.j2 +++ b/templates/nvim/lua/lsp.lua.j2 @@ -95,6 +95,18 @@ nvim_lsp.jsonls.setup { capabilities = snippet_capabilities, } +nvim_lsp.lua_ls.setup { + on_attach = on_attach, + capabilities = snippet_capabilities, + settings = { + Lua = { + diagnostics = { + globals = { 'vim' } + } + } + } +} + {% endif %} nvim_lsp.yamlls.setup { on_attach = on_attach, From 6d801bcb4e98a6537a975992fc4fa7c94864d3d7 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Tue, 18 Mar 2025 21:51:14 +0100 Subject: [PATCH 5/6] Move formatting configuration to separate file --- tasks/neovim.yml | 3 +++ templates/nvim/init.lua.j2 | 2 +- templates/nvim/lua/formatting.lua.j2 | 22 ++++++++++++++++++++++ templates/nvim/lua/lsp.lua.j2 | 24 ------------------------ 4 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 templates/nvim/lua/formatting.lua.j2 diff --git a/tasks/neovim.yml b/tasks/neovim.yml index b647b8d..f6e0696 100644 --- a/tasks/neovim.yml +++ b/tasks/neovim.yml @@ -120,3 +120,6 @@ - src: 'templates/nvim/lua/filetype.lua.j2' dest: '{{ xdg_config_dir }}/nvim/lua/_filetype.lua' + + - src: 'templates/nvim/lua/formatting.lua.j2' + dest: '{{ xdg_config_dir }}/nvim/lua/formatting.lua' diff --git a/templates/nvim/init.lua.j2 b/templates/nvim/init.lua.j2 index 84788ee..309c912 100644 --- a/templates/nvim/init.lua.j2 +++ b/templates/nvim/init.lua.j2 @@ -1,6 +1,5 @@ -- {{ ansible_managed }} --- TODO: load environment vars from .env files require('options') require('_filetype') require('colorscheme') @@ -12,3 +11,4 @@ require('indent-blankline') require('_nvim-tree') require('lua-line') require('_source-link') +require('formatting') diff --git a/templates/nvim/lua/formatting.lua.j2 b/templates/nvim/lua/formatting.lua.j2 new file mode 100644 index 0000000..a6a4ff0 --- /dev/null +++ b/templates/nvim/lua/formatting.lua.j2 @@ -0,0 +1,22 @@ +local enable_formatting = os.getenv("enable_formatting") == 'true'; + +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 + } + end, + }) + end + end + }) +end diff --git a/templates/nvim/lua/lsp.lua.j2 b/templates/nvim/lua/lsp.lua.j2 index 7e9c221..78fd62f 100644 --- a/templates/nvim/lua/lsp.lua.j2 +++ b/templates/nvim/lua/lsp.lua.j2 @@ -187,27 +187,3 @@ vim.diagnostic.config { end }, } - -local enable_formatting = os.getenv("enable_formatting") == 'true'; - --- format buffers before saving for specific LSPs -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 - } - end, - }) - end - end - }) -end From b6222e368260f6f5531b40dafce732f39900aab6 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Tue, 18 Mar 2025 21:52:08 +0100 Subject: [PATCH 6/6] Add delta styling for moved code --- templates/gitconfig.j2 | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/gitconfig.j2 b/templates/gitconfig.j2 index 0696fb1..84f97da 100644 --- a/templates/gitconfig.j2 +++ b/templates/gitconfig.j2 @@ -50,4 +50,5 @@ autocorrect = prompt navigate = true hyperlinks = true line-numbers = true +map-styles = bold purple => syntax magenta, bold cyan => syntax blue, bold yellow => syntax yellow {% endif %}