From 7064af4558f38eed92ab70d25ff7e74e44cd4d57 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Thu, 8 Jun 2023 16:31:50 +0200 Subject: [PATCH] Changed to nvchad --- config/nvim/lua/custom/chadrc.lua | 6 + config/nvim/lua/custom/configs/lspconfig.lua | 27 ++++ config/nvim/lua/custom/configs/null-ls.lua | 16 ++ config/nvim/lua/custom/configs/overrides.lua | 68 ++++++++ config/nvim/lua/custom/init.lua | 1 + config/nvim/lua/custom/mappings.lua | 30 ++++ config/nvim/lua/custom/plugins.lua | 161 +++++++++++++++++++ config/nvim/lua/user/init.lua | 46 ++++-- config/nvim/lua/user/mappings.lua | 2 +- config/nvim/lua/user/plugins/treesitter.lua | 1 + config/nvim/lua/user/plugins/user.lua | 1 + update.sh | 19 ++- 12 files changed, 354 insertions(+), 24 deletions(-) create mode 100644 config/nvim/lua/custom/chadrc.lua create mode 100644 config/nvim/lua/custom/configs/lspconfig.lua create mode 100644 config/nvim/lua/custom/configs/null-ls.lua create mode 100644 config/nvim/lua/custom/configs/overrides.lua create mode 100644 config/nvim/lua/custom/init.lua create mode 100644 config/nvim/lua/custom/mappings.lua create mode 100644 config/nvim/lua/custom/plugins.lua diff --git a/config/nvim/lua/custom/chadrc.lua b/config/nvim/lua/custom/chadrc.lua new file mode 100644 index 0000000..d597261 --- /dev/null +++ b/config/nvim/lua/custom/chadrc.lua @@ -0,0 +1,6 @@ +---@type ChadrcConfig +local M = {} +M.ui = {theme = 'tomorrow_night'} +M.plugins = 'custom.plugins' +M.mappings = require "custom.mappings" +return M diff --git a/config/nvim/lua/custom/configs/lspconfig.lua b/config/nvim/lua/custom/configs/lspconfig.lua new file mode 100644 index 0000000..c960e9d --- /dev/null +++ b/config/nvim/lua/custom/configs/lspconfig.lua @@ -0,0 +1,27 @@ +local on_attach = require("plugins.configs.lspconfig").on_attach +local capabilities = require("plugins.configs.lspconfig").capabilities + +local lspconfig = require("lspconfig") +local util = require "lspconfig/util" +local servers = { "html", "cssls", "clangd", "pyright"} + +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + on_attach = on_attach, + capabilities = capabilities, + } +end + +lspconfig.rust_analyzer.setup({ + on_attach = on_attach, + capabilities = capabilities, + filetypes = {"rust"}, + root_dir = util.root_pattern("Cargo.toml"), + settings = { + ['rust-analyzer'] = { + cargo = { + allFeatures = true, + }, + }, + }, +}) diff --git a/config/nvim/lua/custom/configs/null-ls.lua b/config/nvim/lua/custom/configs/null-ls.lua new file mode 100644 index 0000000..2a25470 --- /dev/null +++ b/config/nvim/lua/custom/configs/null-ls.lua @@ -0,0 +1,16 @@ +local null_ls = require "null-ls" + +local formatting = null_ls.builtins.formatting +local lint = null_ls.builtins.diagnostics + +local sources = { + formatting.prettier, + formatting.stylua, + + lint.shellcheck, +} + +null_ls.setup { + debug = true, + sources = sources, +} diff --git a/config/nvim/lua/custom/configs/overrides.lua b/config/nvim/lua/custom/configs/overrides.lua new file mode 100644 index 0000000..9cf0d1e --- /dev/null +++ b/config/nvim/lua/custom/configs/overrides.lua @@ -0,0 +1,68 @@ +local M = {} + +M.treesitter = { + ensure_installed = { + "vim", + "lua", + "html", + "css", + "javascript", + "typescript", + "tsx", + "c", + "cpp", + "rust", + "markdown", + "markdown_inline", + "python" + }, + indent = { + enable = true, + -- disable = { + -- "python" + -- }, + }, +} + +M.mason = { + ensure_installed = { + -- lua stuff + "lua-language-server", + "stylua", + + -- web dev stuff + "css-lsp", + "html-lsp", + "typescript-language-server", + "deno", + "prettier", + + -- c/cpp stuff + "clangd", + "clang-format", + + -- rust + "rust-analyzer", + + -- python + "pyright", + }, +} + +-- git support in nvimtree +M.nvimtree = { + git = { + enable = true, + }, + + renderer = { + highlight_git = true, + icons = { + show = { + git = true, + }, + }, + }, +} + +return M diff --git a/config/nvim/lua/custom/init.lua b/config/nvim/lua/custom/init.lua new file mode 100644 index 0000000..314c95f --- /dev/null +++ b/config/nvim/lua/custom/init.lua @@ -0,0 +1 @@ +vim.g.dap_virtual_text = true diff --git a/config/nvim/lua/custom/mappings.lua b/config/nvim/lua/custom/mappings.lua new file mode 100644 index 0000000..e2acf4b --- /dev/null +++ b/config/nvim/lua/custom/mappings.lua @@ -0,0 +1,30 @@ +local M = {} + +M.dap = { + plugin = true, + n = { + ["db"] = { " DapToggleBreakpoint " }, + ["dus"] = { + function () + local widgets = require('dap.ui.widgets'); + local sidebar = widgets.sidebar(widgets.scopes); + sidebar.open(); + end, + "Open debugging sidebar" + } + } +} + +M.crates = { + plugin = true, + n = { + ["rcu"] = { + function () + require('crates').upgrade_all_crates() + end, + "update crates" + } + } +} + +return M diff --git a/config/nvim/lua/custom/plugins.lua b/config/nvim/lua/custom/plugins.lua new file mode 100644 index 0000000..132d296 --- /dev/null +++ b/config/nvim/lua/custom/plugins.lua @@ -0,0 +1,161 @@ +local overrides = require("custom.configs.overrides") + +---@type NvPluginSpec[] +local plugins = { + -- Override plugin definition options + { + "neovim/nvim-lspconfig", + dependencies = { + "jose-elias-alvarez/null-ls.nvim", + config = function() + require "custom.configs.null-ls" + end, + }, + config = function() + require "plugins.configs.lspconfig" + require "custom.configs.lspconfig" + end, + }, + -- override plugin configs + { + "williamboman/mason.nvim", + opts = overrides.mason + }, + + { + "nvim-treesitter/nvim-treesitter", + opts = overrides.treesitter, + }, + + { + "nvim-tree/nvim-tree.lua", + opts = overrides.nvimtree, + }, + + -- Debugger + { + "mfussenegger/nvim-dap", + init = function() + require("core.utils").load_mappings("dap") + end + }, + + { + "theHamsta/nvim-dap-virtual-text", + lazy = false, + config = function(_, opts) + require("nvim-dap-virtual-text").setup() + end + }, + + -- Rust + -- { + -- "simrat39/rust-tools.nvim", + -- ft = "rust", + -- dependencies = "neovim/nvim-lspconfig", + -- opts = function () + -- return require "custom.configs.rust-tools" + -- end, + -- config = function(_, opts) + -- require('rust-tools').setup(opts) + -- end + -- }, + + -- { + -- 'saecki/crates.nvim', + -- ft = {"rust", "toml"}, + -- config = function(_, opts) + -- local crates = require('crates') + -- crates.setup(opts) + -- require('cmp').setup.buffer({ + -- sources = { { name = "crates" }} + -- }) + -- crates.show() + -- require("core.utils").load_mappings("crates") + -- end, + -- }, + + { + "rust-lang/rust.vim", + ft = "rust", + init = function () + vim.g.rustfmt_autosave = 1 + end + }, + + -- Better escape (jj/jk) + { + "max397574/better-escape.nvim", + event = "InsertEnter", + config = function() + require("better_escape").setup() + end, + }, + + -- Signatures plugin to show function signatures as you type them + { + "ray-x/lsp_signature.nvim", + event = "BufRead", + config = function() + require("lsp_signature").setup { + hint_enable = false, + } + end, + }, + + -- -- Rooter plugin to change directory to the project root + -- { + -- "notjedi/nvim-rooter.lua", + -- event = "UIEnter", + -- config = function() + -- require("nvim-rooter").setup { + -- rooter_patterns = { "Makefile", ".git", ".hg", ".svn" }, + -- trigger_patterns = { "*" }, + -- manual = false, + -- } + -- end, + -- }, + + -- Leap plugin to jump to any line in the file + { + "ggandor/leap.nvim", + event = "UIEnter", + config = function() require("leap").add_default_mappings() end, + }, + + -- Copilot plugin to autocomplete text + { + "zbirenbaum/copilot.lua", + cmd = "Copilot", + event = "InsertEnter", + config = function() + require("copilot").setup { + suggestion = { enabled = false }, + panel = { enabled = false }, + filetypes = { markdown = true }, + } + end, + }, + + -- Copilot CMP plugin to autocomplete text in the completion menu + { + "zbirenbaum/copilot-cmp", + dependencies = "zbirenbaum/copilot.lua", + event = "InsertEnter", + config = function() require("copilot_cmp").setup() end, + }, + -- { + -- "hrsh7th/nvim-cmp", + -- opts = function() + -- local M = require "plugins.configs.cmp" + -- M.completion.completeopt = "menu,menuone,noselect" + -- M.mapping[""] = cmp.mapping.confirm { + -- behavior = cmp.ConfirmBehavior.Insert, + -- select = false, + -- } + -- table.insert(M.sources, {name = "crates"}) + -- return M + -- end, + -- } +} +return plugins diff --git a/config/nvim/lua/user/init.lua b/config/nvim/lua/user/init.lua index 9ed4627..742d9b9 100644 --- a/config/nvim/lua/user/init.lua +++ b/config/nvim/lua/user/init.lua @@ -1,16 +1,16 @@ return { -- Configure AstroNvim updates updater = { - remote = "origin", -- remote to use - channel = "stable", -- "stable" or "nightly" - version = "latest", -- "latest", tag name, or regex search like "v1.*" to only do updates before v2 (STABLE ONLY) - branch = "nightly", -- branch name (NIGHTLY ONLY) - commit = nil, -- commit hash (NIGHTLY ONLY) - pin_plugins = nil, -- nil, true, false (nil will pin plugins on stable only) - skip_prompts = false, -- skip prompts about breaking changes + remote = "origin", -- remote to use + channel = "stable", -- "stable" or "nightly" + version = "latest", -- "latest", tag name, or regex search like "v1.*" to only do updates before v2 (STABLE ONLY) + branch = "nightly", -- branch name (NIGHTLY ONLY) + commit = nil, -- commit hash (NIGHTLY ONLY) + pin_plugins = nil, -- nil, true, false (nil will pin plugins on stable only) + skip_prompts = false, -- skip prompts about breaking changes show_changelog = true, -- show the changelog after performing an update - auto_quit = false, -- automatically quit the current session after a successful update - remotes = { -- easily add new remotes to track + auto_quit = false, -- automatically quit the current session after a successful update + remotes = { -- easily add new remotes to track }, }, @@ -18,17 +18,14 @@ return { colorscheme = "astrodark", -- Diagnostics configuration (for vim.diagnostics.config({...})) when diagnostics are on - diagnostics = { - virtual_text = true, - underline = true, - }, + diagnostics = { virtual_text = true, underline = true }, lsp = { -- customize lsp formatting options formatting = { -- control auto formatting on save format_on_save = { - enabled = false, -- enable or disable format on save globally + enabled = false, -- enable or disable format on save globally allow_filetypes = { -- enable format on save for specified filetypes only -- "go", }, @@ -57,7 +54,14 @@ return { performance = { rtp = { -- customize default disabled vim plugins - disabled_plugins = { "tohtml", "gzip", "matchit", "zipPlugin", "netrwPlugin", "tarPlugin" }, + disabled_plugins = { + "tohtml", + "gzip", + "matchit", + "zipPlugin", + "netrwPlugin", + "tarPlugin", + }, }, }, }, @@ -66,6 +70,18 @@ return { -- augroups/autocommands and custom filetypes also this just pure lua so -- anything that doesn't fit in the normal config locations above can go here polish = function() + local rt = require "rust-tools" + + rt.setup { + server = { + on_attach = function(_, bufnr) + -- Hover actions + vim.keymap.set("n", "", rt.hover_actions.hover_actions, { buffer = bufnr }) + -- Code action groups + vim.keymap.set("n", "a", rt.code_action_group.code_action_group, { buffer = bufnr }) + end, + }, + } -- Set up custom filetypes -- vim.filetype.add { -- extension = { diff --git a/config/nvim/lua/user/mappings.lua b/config/nvim/lua/user/mappings.lua index c96814e..a1fbeb0 100644 --- a/config/nvim/lua/user/mappings.lua +++ b/config/nvim/lua/user/mappings.lua @@ -35,7 +35,7 @@ return { -- Format code [""] = { ":Format" }, - + ["a"] = { ":lua require'rust-tools'.hover_actions.hover_actions()" }, -- Disable bindings ["n"] = false, }, diff --git a/config/nvim/lua/user/plugins/treesitter.lua b/config/nvim/lua/user/plugins/treesitter.lua index 1518f98..7a5157e 100644 --- a/config/nvim/lua/user/plugins/treesitter.lua +++ b/config/nvim/lua/user/plugins/treesitter.lua @@ -16,6 +16,7 @@ return { "python", "dockerfile", "cpp", + "rust", }) end, } diff --git a/config/nvim/lua/user/plugins/user.lua b/config/nvim/lua/user/plugins/user.lua index b3ea578..10f152d 100644 --- a/config/nvim/lua/user/plugins/user.lua +++ b/config/nvim/lua/user/plugins/user.lua @@ -50,4 +50,5 @@ return { event = "InsertEnter", config = function() require("copilot_cmp").setup() end, }, + 'simrat39/rust-tools.nvim' } diff --git a/update.sh b/update.sh index 7ca70da..0829954 100755 --- a/update.sh +++ b/update.sh @@ -113,12 +113,20 @@ cd ~ curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash - sudo apt install -y nodejs -# Install astronvim -printf -- '\033[33m Installing astronvim\n\033[37m' +# Install NvChad +printf -- '\033[33m Installing NvChad\n\033[37m' if [ ! -d ~/.config/nvim ]; -then git clone --depth 1 https://github.com/AstroNvim/AstroNvim ~/.config/nvim; +then git clone https://github.com/NvChad/NvChad ~/.config/nvim --depth 1 +ln -sf ~/code_server/config/nvim/lua/custom ~/.config/nvim/lua/custom fi +# Install astronvim +# printf -- '\033[33m Installing astronvim\n\033[37m' +# if [ ! -d ~/.config/nvim ]; +# then git clone --depth 1 https://github.com/AstroNvim/AstroNvim ~/.config/nvim; +# ln -sf ~/code_server/config/nvim/lua/user ~/.config/nvim/lua/user +# fi + # Install platformio printf -- '\033[33m Installing platformio\n\033[37m' pip3 install platformio @@ -143,11 +151,6 @@ ln -sf ~/code_server/tmux.conf ~/.tmux.conf printf -- '\033[33m Symlinking clang-format config\n\033[37m' ln -sf ~/code_server/clang-format ~/.clang-format -# Symlink nvim user folder -printf -- '\033[33m Symlinking nvim user folder\n\033[37m' -if [ -L ~/.config/nvim/lua/user ]; then rm ~/.config/nvim/lua/user; fi -ln -s ~/code_server/config/nvim/lua/user ~/.config/nvim/lua/user - # Symlink lazygit config printf -- '\033[33m Symlinking lazygit config\n\033[37m' ln -sf ~/code_server/config/lazygit/config.yml ~/.config/lazygit/config.yml