From 65d6e269fbfcaf26cc252c7262296b46800613d7 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Tue, 16 Apr 2024 10:13:40 +0200 Subject: [PATCH] minor neovim config refactor --- .config/nvim/init.lua | 2 +- .config/nvim/lua/config/init.lua | 17 ++++++++++++ .../nvim/lua/{custom => config}/language.lua | 11 +++----- .config/nvim/lua/config/options.lua | 1 + .config/nvim/lua/config/secrets.lua | 6 +++++ .../nvim/lua/{custom => config}/shortcuts.lua | 2 +- .config/nvim/lua/{custom => config}/ui.lua | 2 +- .config/nvim/lua/custom/init.lua | 18 ------------- .config/nvim/lua/lib.lua | 2 +- .config/nvim/lua/plugins/editor.lua | 26 +++++++++++-------- .config/nvim/lua/plugins/language.lua | 16 ++++++------ .config/nvim/lua/plugins/ui.lua | 4 +-- .local/bin/shortcuts | 4 +-- 13 files changed, 58 insertions(+), 53 deletions(-) create mode 100644 .config/nvim/lua/config/init.lua rename .config/nvim/lua/{custom => config}/language.lua (94%) create mode 100644 .config/nvim/lua/config/secrets.lua rename .config/nvim/lua/{custom => config}/shortcuts.lua (96%) rename .config/nvim/lua/{custom => config}/ui.lua (99%) delete mode 100644 .config/nvim/lua/custom/init.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 3bda8bed8..ed2ca8406 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,4 +1,4 @@ -_G.Custom = require("custom") +_G.Config = require("config") _G.Lib = require("lib") require("config.lazy") diff --git a/.config/nvim/lua/config/init.lua b/.config/nvim/lua/config/init.lua new file mode 100644 index 000000000..959bf0061 --- /dev/null +++ b/.config/nvim/lua/config/init.lua @@ -0,0 +1,17 @@ +---@class config +---@field ui config.ui +---@field language config.language +---@field shortcuts config.shortcuts +---@field secrets? config.secrets +local M = {} + +setmetatable(M, { + __index = function(_, k) + local ok, mod = pcall(require, "config." .. k) + if ok then + return mod + end + end, +}) + +return M diff --git a/.config/nvim/lua/custom/language.lua b/.config/nvim/lua/config/language.lua similarity index 94% rename from .config/nvim/lua/custom/language.lua rename to .config/nvim/lua/config/language.lua index d76967c71..51b524bb0 100644 --- a/.config/nvim/lua/custom/language.lua +++ b/.config/nvim/lua/config/language.lua @@ -1,11 +1,12 @@ ---@diagnostic disable: missing-fields ----@class custom.language +---@class config.language local M = {} ---@type table M.formatters_by_ft = { lua = { "stylua" }, sh = { "shfmt" }, + python = { "black" }, } ---@type table @@ -158,16 +159,10 @@ M.lsp_setup = { LazyVim.lsp.on_attach(function(client, _) if client.name == "ruff_lsp" then client.server_capabilities.hoverProvider = false + client.server_capabilities.renameProvider = false end end) end, - -- marksman = function() - -- LazyVim.lsp.on_attach(function(client, _) - -- if client.name == "marksman" then - -- client.server_capabilities.hoverProvider = false - -- end - -- end) - -- end, rust_analyzer = function() return true end, diff --git a/.config/nvim/lua/config/options.lua b/.config/nvim/lua/config/options.lua index ae8f5528b..fd9917bec 100644 --- a/.config/nvim/lua/config/options.lua +++ b/.config/nvim/lua/config/options.lua @@ -14,3 +14,4 @@ g.loaded_node_provider = 0 g.loaded_perl_provider = 0 g.loaded_python3_provider = 0 g.loaded_ruby_provider = 0 +g.autoformat = false diff --git a/.config/nvim/lua/config/secrets.lua b/.config/nvim/lua/config/secrets.lua new file mode 100644 index 000000000..d1b3936c2 --- /dev/null +++ b/.config/nvim/lua/config/secrets.lua @@ -0,0 +1,6 @@ +---@class config.secrets +return { + sourcery = "user_qHOjfe6w58Xeuw7_wij5zh7CCRGzPXQKJE7nJwiYlcnAQ1_mGN4AKSL9q1I", + intelephense = "00QRJLHV4WVNB1E", + openai = "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", +} diff --git a/.config/nvim/lua/custom/shortcuts.lua b/.config/nvim/lua/config/shortcuts.lua similarity index 96% rename from .config/nvim/lua/custom/shortcuts.lua rename to .config/nvim/lua/config/shortcuts.lua index ebc1d8ca5..471ba0d9a 100644 --- a/.config/nvim/lua/custom/shortcuts.lua +++ b/.config/nvim/lua/config/shortcuts.lua @@ -1,5 +1,5 @@ -- NOTE: Managed by shortcuts script ----@class custom.shortcuts +---@class config.shortcuts return { gh = "/home/luca", gch = "/home/luca/.cache", diff --git a/.config/nvim/lua/custom/ui.lua b/.config/nvim/lua/config/ui.lua similarity index 99% rename from .config/nvim/lua/custom/ui.lua rename to .config/nvim/lua/config/ui.lua index 787dbc861..4b8630198 100644 --- a/.config/nvim/lua/custom/ui.lua +++ b/.config/nvim/lua/config/ui.lua @@ -1,4 +1,4 @@ ----@class custom.ui +---@class config.ui local M = {} ---@type Array diff --git a/.config/nvim/lua/custom/init.lua b/.config/nvim/lua/custom/init.lua deleted file mode 100644 index 6b23a77a6..000000000 --- a/.config/nvim/lua/custom/init.lua +++ /dev/null @@ -1,18 +0,0 @@ ----@class custom ----@field ui custom.ui ----@field language custom.language ----@field shortcuts custom.shortcuts ----@field prompts custom.prompts ----@field secrets? custom.secrets -local M = {} - -setmetatable(M, { - __index = function(_, k) - local ok, mod = pcall(require, "custom." .. k) - if ok then - return mod - end - end, -}) - -return M diff --git a/.config/nvim/lua/lib.lua b/.config/nvim/lua/lib.lua index 2fbcd26ba..d772d4a88 100644 --- a/.config/nvim/lua/lib.lua +++ b/.config/nvim/lua/lib.lua @@ -2,7 +2,7 @@ local M = {} ---@return table function M.generate_shortcut_maps() - local shortcuts = Custom.shortcuts + local shortcuts = Config.shortcuts local fs = require("neo-tree.sources.filesystem") local maps = {} for map, path in pairs(shortcuts) do diff --git a/.config/nvim/lua/plugins/editor.lua b/.config/nvim/lua/plugins/editor.lua index f08d52803..f04696adc 100644 --- a/.config/nvim/lua/plugins/editor.lua +++ b/.config/nvim/lua/plugins/editor.lua @@ -1,5 +1,9 @@ ---@type LazySpec return { + { + "ggandor/flit.nvim", + enabled = false, + }, { "CopilotC-Nvim/CopilotChat.nvim", dependencies = { @@ -12,14 +16,14 @@ return { }, }, keys = { - { "acc", "CopilotChatToggle", desc = "Toggle Chat", mode = { "n", "v" } }, - { "acx", "CopilotChatReset", desc = "Reset Chat", mode = { "n", "v" } }, - { "acf", "CopilotChatFix", desc = "Fix Selection", mode = { "v" } }, - { "ace", "CopilotChatExplain", desc = "Explain Selection", mode = { "v" } }, - { "acr", "CopilotChatExplain", desc = "Review Selection", mode = { "v" } }, + { "acc", "CopilotChatToggle", desc = "Toggle Chat", mode = { "n", "v" } }, + { "acx", "CopilotChatReset", desc = "Reset Chat", mode = { "n", "v" } }, + { "acf", "CopilotChatFix", desc = "Fix Selection", mode = { "v" } }, + { "ace", "CopilotChatExplain", desc = "Explain Selection", mode = { "v" } }, + { "acr", "CopilotChatExplain", desc = "Review Selection", mode = { "v" } }, { "aco", "CopilotChatOptimize", desc = "Optimize Selection", mode = { "v" } }, - { "acd", "CopilotChatDocs", desc = "Document Selection", mode = { "v" } }, - { "act", "CopilotChatTests", desc = "Unittest Selection", mode = { "v" } }, + { "acd", "CopilotChatDocs", desc = "Document Selection", mode = { "v" } }, + { "act", "CopilotChatTests", desc = "Unittest Selection", mode = { "v" } }, }, opts = { window = { @@ -226,13 +230,13 @@ return { }, { "nvim-neo-tree/neo-tree.nvim", - opts = function(_, opts) - opts.filesystem = { + opts = { + filesystem = { window = { mappings = Lib.generate_shortcut_maps(), }, - } - end, + }, + }, }, { "folke/todo-comments.nvim", diff --git a/.config/nvim/lua/plugins/language.lua b/.config/nvim/lua/plugins/language.lua index 372be203c..a3335c20d 100644 --- a/.config/nvim/lua/plugins/language.lua +++ b/.config/nvim/lua/plugins/language.lua @@ -4,7 +4,7 @@ return { "nvim-treesitter/nvim-treesitter", opts = { auto_install = true, - ensure_installed = Custom.language.treesitter_install, + ensure_installed = Config.language.treesitter_install, highlight = { additional_vim_regex_highlighting = { "markdown" }, }, @@ -13,28 +13,28 @@ return { { "stevearc/conform.nvim", opts = { - formatters_by_ft = Custom.language.formatters_by_ft, - formatters = Custom.language.formatters, + formatters_by_ft = Config.language.formatters_by_ft, + formatters = Config.language.formatters, }, }, { "neovim/nvim-lspconfig", opts = { - servers = Custom.language.lsp, - setup = Custom.language.lsp_setup, + servers = Config.language.lsp, + setup = Config.language.lsp_setup, }, }, { "mfussenegger/nvim-lint", opts = { - linters_by_ft = Custom.language.linters_by_ft, - linters = Custom.language.linters, + linters_by_ft = Config.language.linters_by_ft, + linters = Config.language.linters, }, }, { "williamboman/mason.nvim", opts = { - ensure_installed = Custom.language.mason_install, + ensure_installed = Config.language.mason_install, registries = { "github:mason-org/mason-registry", }, diff --git a/.config/nvim/lua/plugins/ui.lua b/.config/nvim/lua/plugins/ui.lua index 8275728d6..5afbf2020 100644 --- a/.config/nvim/lua/plugins/ui.lua +++ b/.config/nvim/lua/plugins/ui.lua @@ -22,8 +22,8 @@ return { { "nvimdev/dashboard-nvim", opts = function(_, opts) - local center = Custom.ui.buttons - local banners = Custom.ui.banners + local center = Config.ui.buttons + local banners = Config.ui.banners for _, button in ipairs(center) do button.desc = button.desc .. string.rep(" ", 43 - #button.desc) button.key_format = " %s" diff --git a/.local/bin/shortcuts b/.local/bin/shortcuts index bc0ad9de6..8a9ab6546 100755 --- a/.local/bin/shortcuts +++ b/.local/bin/shortcuts @@ -2,12 +2,12 @@ zsh=$ZDOTDIR/configs/hashes lf=$XDG_CONFIG_HOME/lf/shortcuts -nvim=$XDG_CONFIG_HOME/nvim/lua/custom/shortcuts.lua +nvim=$XDG_CONFIG_HOME/nvim/lua/config/shortcuts.lua clean() { echo "# NOTE: Managed by shortcuts script" >"$zsh" echo "# NOTE: Managed by shortcuts script" >"$lf" - printf "%s\n%s\n%s\n" "-- NOTE: Managed by shortcuts script" "---@class custom.shortcuts" "return {" >"$nvim" + printf "%s\n%s\n%s\n" "-- NOTE: Managed by shortcuts script" "---@class config.shortcuts" "return {" >"$nvim" } finalize() {