AstroNvim / AstroNvim

AstroNvim is an aesthetic and feature-rich neovim config that is extensible and easy to use with a great set of plugins
https://AstroNvim.com
GNU General Public License v3.0
12.57k stars 917 forks source link

2.8.0 AstroNvim lazy loading update broke Mason cmd #1374

Closed RayJameson closed 1 year ago

RayJameson commented 1 year ago

Checklist

AstroNvim version

2.8.0

Neovim version (>= 0.8)

0.8.1

Operating system/version

MacOS 12.5

Describe the bug

After update I can't call Mason UI using :Mason or <leader>pI when I try it, nothing happens, but commands like :MasonUpdateAll works fine. Seems like because of changes to plugin/ui lazy loading. I'm also using mason-nvim-dap.nvim plugin, and it's cmd :DapInstall does invoke Mason's UI.

As a workaround I added this to my polish function: vim.cmd [[command! Mason execute "lua require('mason.ui').open()"]]

Steps to Reproduce

  1. Update to 2.8.0
  2. Press <leader>pI

Expected behavior

Mason's UI invoked

Screenshots

No response

Additional Context

No response

RayJameson commented 1 year ago

Treesitter commands (:TS*) doesn't work either

RayJameson commented 1 year ago

I managed to fix Treesitter by deleting every occurrence of nvim-treesitter/nvim-treesitter in requires option of user plugins but Mason still doesn't pop up without vim.cmd [[command! Mason execute "lua require('mason.ui').open()"]] even though I don't have Mason in requires of any plugin.

mehalter commented 1 year ago

Have you made sure to sync packer and restart? If you have, could you do me a favor and try refreshing your cache? It should be somewhere like ~/.cache/nvim you can run ~/.cache/nvim ~/.cache/nvim.bak and restart the editor and see if it could be a caching problem

RayJameson commented 1 year ago

I sync packer quite often, so It's not the case. I refreshed cache as you recommend but it didn't help Here is my init.lua

init.lua ```lua -- AstroNvim Configuration Table All configuration changes should go inside of the table below You can think of a Lua "table" as a dictionary like data structure the -- normal format is "key = value". These also handle array like data structures -- where a value with no key simply has an implicit numeric key local config = { -- Configure AstroNvim updates updater = { remote = "origin", -- remote to use channel = "nightly", -- "stable" or "nightly" version = "latest", -- "latest", tag name, or regex search like "v1.*" to only do updates before v2 (STABLE ONLY) branch = "main", -- 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_reload = true, -- automatically reload and sync packer after a successful update auto_quit = false, -- automatically quit the current session after a successful update -- remotes = { -- easily add new remotes to track -- ["remote_name"] = "https://remote_url.come/repo.git", -- full remote url -- ["remote2"] = "github_user/repo", -- GitHub user/repo shortcut, -- ["remote3"] = "github_user", -- GitHub user assume AstroNvim fork -- }, }, -- Set colorscheme to use colorscheme = "default_theme", -- Add highlight groups in any theme -- highlights = { -- init = { -- this table overrides highlights in all themes -- Normal = { bg = "#000000" }, -- } -- duskfox = { -- a table of overrides/changes to the duskfox theme -- Normal = { bg = "#000000" }, -- }, -- }, vim.api.nvim_set_var("python3_host_prog", "$HOME/.pyenv/versions/neovim_base_venv/bin/python3"), -- set vim options here (vim.. = value) options = { opt = { -- set to true or false etc. relativenumber = true, -- sets vim.opt.relativenumber number = true, -- sets vim.opt.number spell = false, -- sets vim.opt.spell signcolumn = "auto", -- sets vim.opt.signcolumn to auto wrap = false, -- sets vim.opt.wrap ignorecase = true, smartcase = true, colorcolumn = "120", expandtab = true, tabstop = 4, softtabstop = 4, shiftwidth = 4, smarttab = true, clipboard = "", autoindent = true, smartindent = true, autochdir = false, list = true, showbreak = "↪ ", listchars = { tab = "→ ", eol = "↲", nbsp = "␣", trail = "•", extends = "⟩", precedes = "⟨", }, }, g = { mapleader = " ", -- sets vim.g.mapleader autoformat_enabled = false, -- enable or disable auto formatting at start (lsp.formatting.format_on_save must be enabled) cmp_enabled = true, -- enable completion at start autopairs_enabled = true, -- enable autopairs at start diagnostics_enabled = true, -- enable diagnostics at start status_diagnostics_enabled = true, -- enable diagnostics in statusline icons_enabled = true, -- disable icons in the UI (disable if no nerd font is available, requires :PackerSync after changing) ui_notifications_enabled = true, -- disable notifications when toggling UI elements }, }, -- If you need more control, you can use the function()...end notation -- options = function(local_vim) -- local_vim.g.mapleader = " " -- -- local_vim.opt.whichwrap = vim.opt.whichwrap - { 'b', 's' } -- removing option from list -- local_vim.opt.shortmess = vim.opt.shortmess + { I = true } -- add to option list -- -- return local_vim -- end, -- Set dashboard header header = { " █████ ███████ ████████ ██████ ██████", "██ ██ ██ ██ ██ ██ ██ ██", "███████ ███████ ██ ██████ ██ ██", "██ ██ ██ ██ ██ ██ ██ ██", "██ ██ ███████ ██ ██ ██ ██████", " ", " ███  ██ ██  ██ ██ ███  ███", " ████  ██ ██  ██ ██ ████  ████", " ██ ██  ██ ██  ██ ██ ██ ████ ██", " ██  ██ ██  ██  ██  ██ ██  ██  ██", " ██   ████   ████   ██ ██      ██", }, -- Default theme configuration default_theme = { -- Modify the color palette for the default theme colors = { fg = "#abb2bf", bg = "#1e222a", }, highlights = function(hl) -- or a function that returns a new table of colors to set local C = require "default_theme.colors" hl.TelescopeResultsVariable = { fg = C.fg } hl["@variable"] = { fg = C.fg } hl["@float"] = { fg = C.orange } hl["@boolean"] = { fg = "#1BF9C4" } hl["@type.builtin"] = { fg = C.blue_1 } hl["@function.builtin"] = { fg = C.blue_1 } hl.Normal = { fg = C.fg, bg = C.bg } -- New approach instead of diagnostic_style hl.DiagnosticError.italic = true hl.DiagnosticHint.italic = true hl.DiagnosticInfo.italic = true hl.DiagnosticWarn.italic = true return hl end, -- enable or disable highlighting for extra plugins plugins = { aerial = true, beacon = false, bufferline = true, cmp = true, dashboard = true, highlighturl = true, hop = false, indent_blankline = true, lightspeed = false, ["neo-tree"] = true, notify = true, ["nvim-tree"] = false, ["nvim-web-devicons"] = true, rainbow = true, symbols_outline = true, telescope = true, treesitter = true, vimwiki = false, ["which-key"] = true, }, }, -- Diagnostics configuration (for vim.diagnostics.config({...})) when diagnostics are on diagnostics = { virtual_text = true, underline = true, }, -- Extend LSP configuration lsp = { -- enable servers that you already have installed without mason servers = { -- "pyright" }, formatting = { -- control auto formatting on save format_on_save = { enabled = false, -- enable or disable format on save globally allow_filetypes = { -- enable format on save for specified filetypes only -- "go", }, ignore_filetypes = { -- disable format on save for specified filetypes -- "python", }, }, disabled = { -- disable formatting capabilities for the listed language servers "sumneko_lua", }, timeout_ms = 2000, -- default format timeout -- filter = function(client) -- fully override the default formatting function -- return true -- end }, -- easily add or disable built in mappings added during LSP attaching mappings = { n = { -- ["lf"] = false -- disable formatting keymap ["lF"] = { "FormatModifications", desc = "Format changed code" }, }, }, -- add to the global LSP on_attach function on_attach = function(client, bufnr) local lsp_format_modifications = require "lsp-format-modifications" lsp_format_modifications.attach(client, bufnr, { format_on_save = false }) end, -- override the mason server-registration function -- server_registration = function(server, opts) -- require("lspconfig")[server].setup(opts) -- end, -- Add overrides for LSP server settings, the keys are the name of the server ["server-settings"] = { pylsp = { settings = { pylsp = { plugins = { pyflakes = { enabled = true, }, pycodestyle = { enabled = true, maxLineLength = 120, }, flake8 = { enabled = false, maxLineLength = 120, }, pydocstyle = { enabled = false, }, pylint = { enabled = false, }, yapf = { enabled = false }, }, }, }, }, -- example for addings schemas to yamlls -- yamlls = { -- override table for require("lspconfig").yamlls.setup({...}) -- settings = { -- yaml = { -- schemas = { -- ["http://json.schemastore.org/github-workflow"] = ".github/workflows/*.{yml,yaml}", -- ["http://json.schemastore.org/github-action"] = ".github/action.{yml,yaml}", -- ["http://json.schemastore.org/ansible-stable-2.9"] = "roles/tasks/*.{yml,yaml}", -- }, -- }, -- }, -- }, }, }, -- Mapping data with "desc" stored directly by vim.keymap.set(). -- -- Please use this mappings table to set keyboard mapping since this is the -- lower level configuration and more robust one. (which-key will -- automatically pick-up stored data by this setting.) mappings = { -- first key is the mode n = { -- second key is the lefthand side of the map -- mappings seen under group name "Buffer" ["ll"] = { "LinterRestart", desc = "Linter restart" }, ["bb"] = { "tabnew", desc = "New tab" }, ["bc"] = { "BufferLinePickClose", desc = "Pick to close" }, ["bj"] = { "BufferLinePick", desc = "Pick to jump" }, ["bt"] = { "BufferLineSortByTabs", desc = "Sort by tabs" }, [""] = ":MoveLine(1)", [""] = ":MoveLine(-1)", [""] = ":MoveHChar(-1)", [""] = ":MoveHChar(1)", ["F"] = { ":%s/\\<\\>//gI", desc = "Find and replace", }, ["U"] = { "UndotreeToggle", desc = "Undotree toggle" }, -- quick save -- [""] = { ":w!", desc = "Save File" }, -- change description but the same command }, t = { -- setting a mapping to false will disable it -- [""] = "", }, v = { ["F"] = { '"fyiwgv:s/f/f/', desc = "Find and replace visual" }, [""] = ":MoveBlock(1)", [""] = ":MoveBlock(-1)", [""] = ":MoveHBlock(-1)", [""] = ":MoveHBlock(1)", }, }, -- Configure plugins plugins = { init = { ["Darazaki/indent-o-matic"] = { disable = true }, -- You can disable default plugins as follows: -- [] = { disable = true }, -- You can also add new plugins here as well: -- Add plugins, the packer syntax without the "use" -- { "andweeb/presence.nvim" }, { "ray-x/lsp_signature.nvim", event = "BufRead", config = function() require("lsp_signature").setup() end, }, { "andymass/vim-matchup", config = function() vim.g.matchup_matchparen_offscreen = { method = "popup" } end, }, { "f-person/git-blame.nvim", event = "BufRead", config = function() vim.cmd "highlight default link gitblame SpecialComment" vim.g.gitblame_enabled = 0 end, }, { "ellisonleao/glow.nvim", config = function() require("glow").setup { width = 250, } end, }, { "phaazon/hop.nvim", event = "BufRead", config = function() require("hop").setup() vim.api.nvim_set_keymap("n", "\\", "HopChar2", { silent = true }) end, }, { "fedepujol/move.nvim", }, { "folke/todo-comments.nvim", event = "BufRead", config = function() require("todo-comments").setup() end, }, -- { -- "tpope/vim-surround", -- keys = { "c", "d", "y" }, -- -- make sure to change the value of `timeoutlen` if it's not triggering correctly, see https://github.com/tpope/vim-surround/issues/117 -- setup = function() -- -- vim.o.timeoutlen = 500 -- end, -- }, { "kylechui/nvim-surround", tag = "*", -- Use for stability; omit to use `main` branch for the latest features config = function() require("nvim-surround").setup { -- Configuration here, or leave empty to use defaults } end, }, { "CRAG666/code_runner.nvim", config = function() require("code_runner").setup { -- put here the commands by filetype startinsert = false, filetype = { java = "cd $dir && javac $fileName && java $fileNameWithoutExt", python = "python3 -u", typescript = "deno run", rust = "cd $dir && rustc $fileName && $dir/$fileNameWithoutExt", javascript = "node", shellscript = "bash", }, } end, }, { "kevinhwang91/nvim-bqf", event = { "BufRead", "BufNew" }, config = function() require("bqf").setup { auto_enable = true, preview = { win_height = 12, win_vheight = 12, delay_syntax = 80, border_chars = { "┃", "┃", "━", "━", "┏", "┓", "┗", "┛", "█", }, }, func_map = { vsplit = "", ptogglemode = "z,", stoggleup = "", }, filter = { fzf = { action_for = { ["ctrl-s"] = "split" }, extra_opts = { "--bind", "ctrl-o:toggle-all", "--prompt", "> ", }, }, }, } end, }, { "folke/trouble.nvim", requires = "kyazdani42/nvim-web-devicons", config = function() require("trouble").setup { -- your configuration comes here -- or leave it empty to use the default settings -- refer to the configuration section below } end, }, { "mfussenegger/nvim-dap", }, { "mfussenegger/nvim-dap-python", config = function() require("dap-python").setup "~/.virtualenvs/debugpy/bin/python" end, ft = { "py" }, }, { "jayp0521/mason-nvim-dap.nvim", requires = { "mfussenegger/nvim-dap" }, config = function() require("mason-nvim-dap").setup { automatic_setup = true, } end, }, { "rcarriga/nvim-dap-ui", requires = "mfussenegger/nvim-dap", -- after = "nvim-dap", config = function() require("dapui").setup {} end, }, { "nvim-treesitter/nvim-treesitter-context", }, { "iamcco/markdown-preview.nvim", run = "cd app && npm install", setup = function() vim.g.mkdp_filetypes = { "markdown" } end, ft = { "markdown" }, }, { "ThePrimeagen/refactoring.nvim", config = function() require("telescope").load_extension "refactoring" end, cmd = "Refactoring", }, { "mbbill/undotree", }, { "navarasu/onedark.nvim", require("onedark").setup { style = "darker", }, }, { "m-demare/hlargs.nvim", require("hlargs").setup { color = "#FF7A00", --"#ef9062", paint_arg_usages = true, excluded_argnames = { declarations = { python = { "self", "cls" }, lua = { "self" }, }, usages = { python = { "self", "cls" }, lua = { "self" }, extras = { named_parameters = true, }, }, }, }, }, { "joechrisellis/lsp-format-modifications.nvim", }, { "WhoIsSethDaniel/mason-tool-installer.nvim", }, -- We also support a key value style plugin definition similar to NvChad: -- ["ray-x/lsp_signature.nvim"] = { -- event = "BufRead", -- config = function() -- require("lsp_signature").setup() -- end, -- }, }, -- All other entries override the require("").setup({...}) call for default plugins -- ["williamboman/mason.nvim"] = { module = "mason", config = function() require "configs.mason" end }, ["neo-tree"] = { window = { width = 50, }, }, ["null-ls"] = function(config) -- overrides `require("null-ls").setup(config)` -- config variable is the default configuration table for the setup function call local null_ls = require "null-ls" -- Check supported formatters and linters -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics config.sources = { -- Set a formatter null_ls.builtins.formatting.prettier, -- null_ls.builtins.formatting.usort, -- null_ls.builtins.formatting.yapf.with { -- extra_args = { "--style={based_on_style: google}" }, -- }, null_ls.builtins.formatting.stylua.with { extra_args = { "--indent-type=Spaces", "--indent-width=4", "--quote-style=AutoPreferDouble" }, }, null_ls.builtins.diagnostics.luacheck.with { command = "luacheck", extra_args = {}, filetypes = { "lua" }, -- force luacheck to find its '.luacheckrc' file cwd = function(params) -- falls back to root if return value is nil return params.root:match ".luacheckrc" end, -- cwd = nls_cache.by_bufnr(function(params) -- return root_pattern ".luacheckrc" (params.bufname) -- end), -- runtime_condition = nls_cache.by_bufnr(function(params) -- return path.exists(path.join(params.root, ".luacheckrc")) -- end), }, } return config -- return final config table end, ["heirline"] = function(config) -- the first element of the default configuration table is the statusline config[1] = { -- set the fg/bg of the statusline hl = { fg = "fg", bg = "bg" }, -- when adding the mode component, enable the mode text with padding to the left/right of it astronvim.status.component.mode { mode_text = { padding = { left = 1, right = 1 } }, }, -- add all the other components for the statusline astronvim.status.component.git_branch(), astronvim.status.component.file_info(), astronvim.status.component.git_diff(), astronvim.status.component.diagnostics(), astronvim.status.component.fill(), astronvim.status.component.macro_recording(), astronvim.status.component.fill(), astronvim.status.component.lsp(), astronvim.status.component.treesitter(), astronvim.status.component.nav(), } -- return the final configuration table return config end, treesitter = { -- overrides `require("treesitter").setup(...)` ensure_installed = { "lua" }, auto_install = true, }, -- use mason-lspconfig to configure LSP installations ["mason-lspconfig"] = { -- overrides `require("mason-lspconfig").setup(...)` ensure_installed = { "sumneko_lua" }, }, -- use mason-null-ls to configure Formatters/Linter installation for null-ls sources -- ["mason-null-ls"] = { -- overrides `require("mason-null-ls").setup(...)` -- ensure_installed = { "prettier", "stylua" }, -- }, whichkey = { presets = { operators = true, text_options = true, z = true, g = true, }, }, }, -- LuaSnip Options luasnip = { -- Extend filetypes filetype_extend = { -- javascript = { "javascriptreact" }, }, -- Configure luasnip loaders (vscode, lua, and/or snipmate) vscode = { -- Add paths for including more VS Code style snippets in luasnip paths = {}, }, }, -- CMP Source Priorities -- modify here the priorities of default cmp sources -- higher value == higher priority -- The value can also be set to a boolean for disabling default sources: -- false == disabled -- true == 1000 cmp = { source_priority = { nvim_lsp = 1000, luasnip = 750, buffer = 500, path = 250, }, }, -- Modify which-key registration (Use this with mappings table in the above.) ["which-key"] = { -- Add bindings which show up as group name register = { -- first key is the mode, n == normal mode n = { -- second key is the prefix, prefixes [""] = { -- third key is the key to bring up next level and its displayed -- group name in which-key top level menu ["y"] = { '"+y', "yank +clipboard" }, ["Y"] = { '"+y$', "Yank +clipboard" }, ["d"] = { '"_d', "delete noregister" }, ["b"] = { name = "Buffer" }, ["m"] = { name = "Markdown", ["M"] = { "Glow", "Markdown Glow" }, ["m"] = { "MarkdownPreview", "MarkdownPreview" }, ["t"] = { "MarkdownPreviewToggle", "MarkdownPreview Toggle" }, ["s"] = { "MarkdownPreviewStop", "MarkdownPreview Stop" }, }, ["r"] = { name = "Code runner", ["r"] = { ":RunCode", "Run code" }, ["f"] = { ":RunFile", "Run file" }, ["t"] = { ":RunFile tab", "Fun file tab" }, ["c"] = { ":RunClose", "Close runner" }, }, ["T"] = { name = "Trouble", ["r"] = { ":Trouble lsp_references", "References" }, ["f"] = { ":Trouble lsp_definitions", "Definitions" }, ["d"] = { ":Trouble document_diagnostics", "Diagnostics" }, ["q"] = { ":Trouble quickfix", "QuickFix" }, ["l"] = { ":Trouble loclist", "LocationList" }, ["w"] = { ":Trouble workspace_diagnostics", "Wordspace Diagnostics", }, }, ["D"] = { name = "Debug", ["b"] = { "lua require'dap'.toggle_breakpoint()", "Breakpoint" }, ["c"] = { "lua require'dap'.continue()", "Continue" }, ["i"] = { "lua require'dap'.step_into()", "Into" }, ["o"] = { "lua require'dap'.step_over()", "Over" }, ["O"] = { "lua require'dap'.step_out()", "Out" }, ["r"] = { "lua require'dap'.repl.toggle()", "Repl" }, ["l"] = { "lua require'dap'.run_last()", "Last" }, ["u"] = { "DapuiToggle", "UI" }, ["x"] = { "lua require'dap'.terminate()", "Exit" }, }, }, }, v = { [""] = { ["y"] = { '"+y', "yank +clipboard" }, ["Y"] = { '"+y', "Yank +clipboard" }, ["d"] = { '"_d', "delete noregister" }, ["D"] = { '"_D', "Delete noregister" }, ["r"] = { "Refactoring", "Refactoring" }, }, }, x = { [""] = { ["p"] = { '"_dP', "Paste noregister" }, }, }, }, }, -- This function is run last and is a good place to configuring -- 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() vim.cmd [[ au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=100} :set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz command! LinterRestart execute "lua require('null-ls.client')._reset()" | edit " command! Mason execute "lua require('mason.ui').open()" command! Refactoring execute "lua require('telescope').extensions.refactoring.refactors()" command! DapuiToggle execute "lua require'dapui'.toggle()" ]] -- Set up custom filetypes vim.filetype.add { filename = { ["poetry.lock"] = "toml", }, -- extension = { -- foo = "fooscript", -- }, -- pattern = { -- ["~/%.config/foo/.*"] = "fooscript", -- }, } local dap, dapui = require "dap", require "dapui" dap.listeners.after.event_initialized["dapui_config"] = function() dapui.open() end -- dap.listeners.before.event_terminated["dapui_config"] = function() dapui.close() end -- dap.listeners.before.event_exited["dapui_config"] = function() dapui.close() end require("alpha").setup(require("alpha.themes.startify").config) end, } return config ```
abigagli commented 1 year ago

I'm having a seemingly related problem: Sometimes at nvim startup, I get an error about not being able to spawn the language-server for the file being opened which I've debugged down to vim.env.PATH still not being set when the nvim's runtime function start_clientis executed. This is quite erratic (i.e. sometimes it work, sometimes it doesn't) and sometimes the problem even disappears if I just execute a PackerSync. If I first open nvim for the current folder with nvim . and then I open the file, it seems like it always works.

I'm no expert, but it sounds like some "racey" behaviour that depends on who-goes-first during startup

mehalter commented 1 year ago

@mishagantz I took a second to load up your config to see if I can replicate the behavior you are getting. I noticed that there are a ton of errors in the configuration causing a TON of weirdness. I can also replicate the behavior you are describing. I'm not sure exactly what is going on in your config to cause this. I can take a deeper look this week as well as fix all of the errors I see throughout everything to make it work more nicely. I am going to go ahead and remove the bug tag since this is unrelated to base AstroNvim code.

RayJameson commented 1 year ago

I feel ashamed now... I'm still figuring out Neovim, sorry you had to deal with this mess

mehalter commented 1 year ago

No worries! I will have some time this upcoming week to take a closer look @mishagantz !

mehalter commented 1 year ago

@mishagantz here is an updated init.lua. I improved some of the lazy loading, fixed some errors in your plugins.init table, moved some stuff out of your polish function which should be in your plugins table such as configuring alpha (moved to plugins.alpha) and setting up dap hooks which I configured with dapui. I also improved the installation of the markdown-preview plugin. After fixing these errors and making some improvements the Mason command seems to be working perfectly. I think what was happening is the errors in your packer.init table were causing the packer compiled file to be messing up and not properly setting up the lazy loading:

-- AstroNvim Configuration Table All configuration changes should go inside of the table below You can think of a Lua "table" as a dictionary like data structure the
-- normal format is "key = value". These also handle array like data structures
-- where a value with no key simply has an implicit numeric key
local config = {

  -- Configure AstroNvim updates
  updater = {
    remote = "origin", -- remote to use
    channel = "nightly", -- "stable" or "nightly"
    version = "latest", -- "latest", tag name, or regex search like "v1.*" to only do updates before v2 (STABLE ONLY)
    branch = "main", -- 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_reload = true, -- automatically reload and sync packer after a successful update
    auto_quit = false, -- automatically quit the current session after a successful update
    -- remotes = { -- easily add new remotes to track
    --   ["remote_name"] = "https://remote_url.come/repo.git", -- full remote url
    --   ["remote2"] = "github_user/repo", -- GitHub user/repo shortcut,
    --   ["remote3"] = "github_user", -- GitHub user assume AstroNvim fork
    -- },
  },

  -- Set colorscheme to use
  colorscheme = "default_theme",

  -- Add highlight groups in any theme
  -- highlights = {
  -- init = { -- this table overrides highlights in all themes
  --   Normal = { bg = "#000000" },
  -- }
  -- duskfox = { -- a table of overrides/changes to the duskfox theme
  --   Normal = { bg = "#000000" },
  -- },
  -- },

  vim.api.nvim_set_var("python3_host_prog", "$HOME/.pyenv/versions/neovim_base_venv/bin/python3"),
  -- set vim options here (vim.<first_key>.<second_key> = value)
  options = {
    opt = {
      -- set to true or false etc.
      relativenumber = true, -- sets vim.opt.relativenumber
      number = true, -- sets vim.opt.number
      spell = false, -- sets vim.opt.spell
      signcolumn = "auto", -- sets vim.opt.signcolumn to auto
      wrap = false, -- sets vim.opt.wrap
      ignorecase = true,
      smartcase = true,
      colorcolumn = "120",
      expandtab = true,
      tabstop = 4,
      softtabstop = 4,
      shiftwidth = 4,
      smarttab = true,
      clipboard = "",
      autoindent = true,
      smartindent = true,
      autochdir = false,
      list = true,
      showbreak = "↪ ",
      listchars = {
        tab = "→ ",
        eol = "↲",
        nbsp = "␣",
        trail = "•",
        extends = "⟩",
        precedes = "⟨",
      },
    },
    g = {
      mapleader = " ", -- sets vim.g.mapleader
      autoformat_enabled = false, -- enable or disable auto formatting at start (lsp.formatting.format_on_save must be enabled)
      cmp_enabled = true, -- enable completion at start
      autopairs_enabled = true, -- enable autopairs at start
      diagnostics_enabled = true, -- enable diagnostics at start
      status_diagnostics_enabled = true, -- enable diagnostics in statusline
      icons_enabled = true, -- disable icons in the UI (disable if no nerd font is available, requires :PackerSync after changing)
      ui_notifications_enabled = true, -- disable notifications when toggling UI elements
    },
  },
  -- If you need more control, you can use the function()...end notation
  -- options = function(local_vim)
  --   local_vim.g.mapleader = " "
  --   -- local_vim.opt.whichwrap = vim.opt.whichwrap - { 'b', 's' } -- removing option from list
  --   local_vim.opt.shortmess = vim.opt.shortmess + { I = true } -- add to option list
  --
  --   return local_vim
  -- end,

  -- Set dashboard header
  header = {
    " █████  ███████ ████████ ██████   ██████",
    "██   ██ ██         ██    ██   ██ ██    ██",
    "███████ ███████    ██    ██████  ██    ██",
    "██   ██      ██    ██    ██   ██ ██    ██",
    "██   ██ ███████    ██    ██   ██  ██████",
    " ",
    "    ███    ██ ██    ██ ██ ███    ███",
    "    ████   ██ ██    ██ ██ ████  ████",
    "    ██ ██  ██ ██    ██ ██ ██ ████ ██",
    "    ██  ██ ██  ██  ██  ██ ██  ██  ██",
    "    ██   ████   ████   ██ ██      ██",
  },

  -- Default theme configuration
  default_theme = {
    -- Modify the color palette for the default theme
    colors = {
      fg = "#abb2bf",
      bg = "#1e222a",
    },
    highlights = function(hl) -- or a function that returns a new table of colors to set
      local C = require "default_theme.colors"
      hl.TelescopeResultsVariable = { fg = C.fg }
      hl["@variable"] = { fg = C.fg }
      hl["@float"] = { fg = C.orange }
      hl["@boolean"] = { fg = "#1BF9C4" }
      hl["@type.builtin"] = { fg = C.blue_1 }
      hl["@function.builtin"] = { fg = C.blue_1 }
      hl.Normal = { fg = C.fg, bg = C.bg }

      -- New approach instead of diagnostic_style
      hl.DiagnosticError.italic = true
      hl.DiagnosticHint.italic = true
      hl.DiagnosticInfo.italic = true
      hl.DiagnosticWarn.italic = true

      return hl
    end,
    -- enable or disable highlighting for extra plugins
    plugins = {
      aerial = true,
      beacon = false,
      bufferline = true,
      cmp = true,
      dashboard = true,
      highlighturl = true,
      hop = false,
      indent_blankline = true,
      lightspeed = false,
      ["neo-tree"] = true,
      notify = true,
      ["nvim-tree"] = false,
      ["nvim-web-devicons"] = true,
      rainbow = true,
      symbols_outline = true,
      telescope = true,
      treesitter = true,
      vimwiki = false,
      ["which-key"] = true,
    },
  },

  -- Diagnostics configuration (for vim.diagnostics.config({...})) when diagnostics are on
  diagnostics = {
    virtual_text = true,
    underline = true,
  },

  -- Extend LSP configuration
  lsp = {
    -- enable servers that you already have installed without mason
    servers = {
      -- "pyright"
    },
    formatting = {
      -- control auto formatting on save
      format_on_save = {
        enabled = false, -- enable or disable format on save globally
        allow_filetypes = { -- enable format on save for specified filetypes only
          -- "go",
        },
        ignore_filetypes = { -- disable format on save for specified filetypes
          -- "python",
        },
      },
      disabled = { -- disable formatting capabilities for the listed language servers
        "sumneko_lua",
      },
      timeout_ms = 2000, -- default format timeout
      -- filter = function(client) -- fully override the default formatting function
      --   return true
      -- end
    },
    -- easily add or disable built in mappings added during LSP attaching
    mappings = {
      n = {
        -- ["<leader>lf"] = false -- disable formatting keymap
        ["<leader>lF"] = { "<cmd>FormatModifications<CR>", desc = "Format changed code" },
      },
    },
    -- add to the global LSP on_attach function
    on_attach = function(client, bufnr)
      local lsp_format_modifications = require "lsp-format-modifications"
      lsp_format_modifications.attach(client, bufnr, { format_on_save = false })
    end,

    -- override the mason server-registration function
    -- server_registration = function(server, opts)
    --   require("lspconfig")[server].setup(opts)
    -- end,

    -- Add overrides for LSP server settings, the keys are the name of the server
    ["server-settings"] = {
      pylsp = {
        settings = {
          pylsp = {
            plugins = {
              pyflakes = {
                enabled = true,
              },
              pycodestyle = {
                enabled = true,
                maxLineLength = 120,
              },
              flake8 = {
                enabled = false,
                maxLineLength = 120,
              },
              pydocstyle = {
                enabled = false,
              },
              pylint = {
                enabled = false,
              },
              yapf = {
                enabled = false,
              },
            },
          },
        },
      },
      -- example for addings schemas to yamlls
      -- yamlls = { -- override table for require("lspconfig").yamlls.setup({...})
      --   settings = {
      --     yaml = {
      --       schemas = {
      --         ["http://json.schemastore.org/github-workflow"] = ".github/workflows/*.{yml,yaml}",
      --         ["http://json.schemastore.org/github-action"] = ".github/action.{yml,yaml}",
      --         ["http://json.schemastore.org/ansible-stable-2.9"] = "roles/tasks/*.{yml,yaml}",
      --       },
      --     },
      --   },
      -- },
    },
  },
  -- Mapping data with "desc" stored directly by vim.keymap.set().
  --
  -- Please use this mappings table to set keyboard mapping since this is the
  -- lower level configuration and more robust one. (which-key will
  -- automatically pick-up stored data by this setting.)
  mappings = {
    -- first key is the mode
    n = {
      -- second key is the lefthand side of the map
      -- mappings seen under group name "Buffer"
      ["<leader>ll"] = { "<cmd>LinterRestart<CR>", desc = "Linter restart" },
      ["<leader>bb"] = { "<cmd>tabnew<CR>", desc = "New tab" },
      ["<leader>bc"] = { "<cmd>BufferLinePickClose<CR>", desc = "Pick to close" },
      ["<leader>bj"] = { "<cmd>BufferLinePick<CR>", desc = "Pick to jump" },
      ["<leader>bt"] = { "<cmd>BufferLineSortByTabs<CR>", desc = "Sort by tabs" },
      ["<A-j>"] = ":MoveLine(1)<CR>",
      ["<A-k>"] = ":MoveLine(-1)<CR>",
      ["<A-h>"] = ":MoveHChar(-1)<CR>",
      ["<A-l>"] = ":MoveHChar(1)<CR>",
      ["<leader>F"] = {
        ":%s/\\<<C-r><C-w>\\>/<C-r><C-w>/gI<Left><Left><Left>",
        desc = "Find and replace",
      },
      ["<leader>U"] = { "<cmd>UndotreeToggle<CR>", desc = "Undotree toggle" },
      -- quick save
      -- ["<C-s>"] = { ":w!<cr>", desc = "Save File" },  -- change description but the same command
    },
    t = {
      -- setting a mapping to false will disable it
      -- ["<esc>"] = "<C-\\><C-n>",
    },
    v = {
      ["<leader>F"] = { '<Esc>"fyiw<CR>gv:s/<C-r>f/<C-r>f/<Left>', desc = "Find and replace visual" },
      ["<A-j>"] = ":MoveBlock(1)<CR>",
      ["<A-k>"] = ":MoveBlock(-1)<CR>",
      ["<A-h>"] = ":MoveHBlock(-1)<CR>",
      ["<A-l>"] = ":MoveHBlock(1)<CR>",
    },
  },

  -- Configure plugins
  plugins = {
    init = {
      ["Darazaki/indent-o-matic"] = { disable = true },
      -- You can disable default plugins as follows:
      -- [] = { disable = true },

      -- You can also add new plugins here as well:
      -- Add plugins, the packer syntax without the "use"
      -- { "andweeb/presence.nvim" },
      {
        "ray-x/lsp_signature.nvim",
        opt = true,
        setup = function() table.insert(astronvim.file_plugins, "lsp_signature.nvim") end,
        config = function() require("lsp_signature").setup() end,
      },
      {
        "andymass/vim-matchup",
        config = function() vim.g.matchup_matchparen_offscreen = { method = "popup" } end,
      },
      {
        "f-person/git-blame.nvim",
        opt = true,
        setup = function() table.insert(astronvim.git_plugins, "git-blame.nvim") end,
        config = function()
          vim.cmd "highlight default link gitblame SpecialComment"
          vim.g.gitblame_enabled = 0
        end,
      },
      {
        "ellisonleao/glow.nvim",
        config = function()
          require("glow").setup {
            width = 250,
          }
        end,
      },
      {
        "phaazon/hop.nvim",
        opt = true,
        setup = function() table.insert(astronvim.file_plugins, "hop.nvim") end,
        config = function()
          require("hop").setup()
          vim.api.nvim_set_keymap("n", "\\", "<cmd>HopChar2<cr>", { silent = true })
        end,
      },
      {
        "fedepujol/move.nvim",
      },
      {
        "folke/todo-comments.nvim",
        opt = true,
        setup = function() table.insert(astronvim.file_plugins, "todo-comments.nvim") end,
        config = function() require("todo-comments").setup() end,
      },
      -- {
      --   "tpope/vim-surround",
      --   keys = { "c", "d", "y" },
      --   -- make sure to change the value of `timeoutlen` if it's not triggering correctly, see https://github.com/tpope/vim-surround/issues/117
      --   setup = function()
      --     -- vim.o.timeoutlen = 500
      --   end,
      -- },
      {
        "kylechui/nvim-surround",
        tag = "*", -- Use for stability; omit to use `main` branch for the latest features
        config = function()
          require("nvim-surround").setup {
            -- Configuration here, or leave empty to use defaults
          }
        end,
      },
      {
        "CRAG666/code_runner.nvim",
        config = function()
          require("code_runner").setup {
            -- put here the commands by filetype
            startinsert = false,
            filetype = {
              java = "cd $dir && javac $fileName && java $fileNameWithoutExt",
              python = "python3 -u",
              typescript = "deno run",
              rust = "cd $dir && rustc $fileName && $dir/$fileNameWithoutExt",
              javascript = "node",
              shellscript = "bash",
            },
          }
        end,
      },
      {
        "kevinhwang91/nvim-bqf",
        event = { "BufRead", "BufNew" },
        config = function()
          require("bqf").setup {
            auto_enable = true,
            preview = {
              win_height = 12,
              win_vheight = 12,
              delay_syntax = 80,
              border_chars = {
                "┃",
                "┃",
                "━",
                "━",
                "┏",
                "┓",
                "┗",
                "┛",
                "█",
              },
            },
            func_map = {
              vsplit = "",
              ptogglemode = "z,",
              stoggleup = "",
            },
            filter = {
              fzf = {
                action_for = { ["ctrl-s"] = "split" },
                extra_opts = {
                  "--bind",
                  "ctrl-o:toggle-all",
                  "--prompt",
                  "> ",
                },
              },
            },
          }
        end,
      },
      {
        "folke/trouble.nvim",
        config = function()
          require("trouble").setup {
            -- your configuration comes here
            -- or leave it empty to use the default settings
            -- refer to the configuration section below
          }
        end,
      },
      {
        "mfussenegger/nvim-dap",
        opt = true,
      },
      {
        "mfussenegger/nvim-dap-python",
        after = "mason-nvim-dap.nvim",
        config = function() require("dap-python").setup "~/.virtualenvs/debugpy/bin/python" end,
      },
      {
        "jayp0521/mason-nvim-dap.nvim",
        after = { "mason.nvim", "nvim-dap" },
        config = function()
          require("mason-nvim-dap").setup {
            automatic_setup = true,
          }
        end,
      },
      {
        "rcarriga/nvim-dap-ui",
        after = "nvim-dap",
        config = function()
          local dap, dapui = require "dap", require "dapui"

          dapui.setup {}

          dap.listeners.after.event_initialized["dapui_config"] = function() dapui.open() end
          -- dap.listeners.before.event_terminated["dapui_config"] = function() dapui.close() end
          -- dap.listeners.before.event_exited["dapui_config"] = function() dapui.close() end
        end,
      },
      {
        "nvim-treesitter/nvim-treesitter-context",
        after = "nvim-treesitter",
      },
      {
        "iamcco/markdown-preview.nvim",
        run = function() vim.fn["mkdp#util#install"]() end,
        ft = { "markdown" },
      },
      {
        "ThePrimeagen/refactoring.nvim",
        config = function() require("telescope").load_extension "refactoring" end,
        cmd = "Refactoring",
      },
      {
        "mbbill/undotree",
      },
      {
        "navarasu/onedark.nvim",
        config = function()
          require("onedark").setup {
            style = "darker",
          }
        end,
      },
      {
        "m-demare/hlargs.nvim",
        config = function()
          require("hlargs").setup {
            color = "#FF7A00", --"#ef9062",
            paint_arg_usages = true,
            excluded_argnames = {
              declarations = {
                python = { "self", "cls" },
                lua = { "self" },
              },
              usages = {
                python = { "self", "cls" },
                lua = { "self" },
                extras = {
                  named_parameters = true,
                },
              },
            },
          }
        end,
      },
      {
        "joechrisellis/lsp-format-modifications.nvim",
        module = "lsp-format-modifications",
      },
      {
        "WhoIsSethDaniel/mason-tool-installer.nvim",
      },
      -- We also support a key value style plugin definition similar to NvChad:
      -- ["ray-x/lsp_signature.nvim"] = {
      --   event = "BufRead",
      --   config = function()
      --     require("lsp_signature").setup()
      --   end,
      -- },
    },
    alpha = function() return require("alpha.themes.startify").config end,
    -- All other entries override the require("<key>").setup({...}) call for default plugins
    -- ["williamboman/mason.nvim"] = { module = "mason", config = function() require "configs.mason" end },
    ["neo-tree"] = {
      window = {
        width = 50,
      },
    },
    ["null-ls"] = function(config) -- overrides `require("null-ls").setup(config)`
      -- config variable is the default configuration table for the setup function call
      local null_ls = require "null-ls"

      -- Check supported formatters and linters
      -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting
      -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
      config.sources = {
        -- Set a formatter
        null_ls.builtins.formatting.prettier,
        -- null_ls.builtins.formatting.usort,
        -- null_ls.builtins.formatting.yapf.with {
        --     extra_args = { "--style={based_on_style: google}" },
        -- },
        null_ls.builtins.formatting.stylua.with {
          extra_args = { "--indent-type=Spaces", "--indent-width=4", "--quote-style=AutoPreferDouble" },
        },
        null_ls.builtins.diagnostics.luacheck.with {
          command = "luacheck",
          extra_args = {},
          filetypes = { "lua" },

          -- force luacheck to find its '.luacheckrc' file
          cwd = function(params)
            -- falls back to root if return value is nil
            return params.root:match ".luacheckrc"
          end,

          -- cwd = nls_cache.by_bufnr(function(params)
          --   return root_pattern ".luacheckrc" (params.bufname)
          -- end),

          -- runtime_condition = nls_cache.by_bufnr(function(params)
          --   return path.exists(path.join(params.root, ".luacheckrc"))
          -- end),
        },
      }
      return config -- return final config table
    end,
    ["heirline"] = function(config)
      -- the first element of the default configuration table is the statusline
      config[1] = {
        -- set the fg/bg of the statusline
        hl = { fg = "fg", bg = "bg" },
        -- when adding the mode component, enable the mode text with padding to the left/right of it
        astronvim.status.component.mode {
          mode_text = { padding = { left = 1, right = 1 } },
        },
        -- add all the other components for the statusline
        astronvim.status.component.git_branch(),
        astronvim.status.component.file_info(),
        astronvim.status.component.git_diff(),
        astronvim.status.component.diagnostics(),
        astronvim.status.component.fill(),
        astronvim.status.component.macro_recording(),
        astronvim.status.component.fill(),
        astronvim.status.component.lsp(),
        astronvim.status.component.treesitter(),
        astronvim.status.component.nav(),
      }
      -- return the final configuration table
      return config
    end,
    treesitter = { -- overrides `require("treesitter").setup(...)`
      ensure_installed = { "lua" },
      auto_install = true,
    },
    -- use mason-lspconfig to configure LSP installations
    ["mason-lspconfig"] = { -- overrides `require("mason-lspconfig").setup(...)`
      ensure_installed = { "sumneko_lua" },
    },
    -- use mason-null-ls to configure Formatters/Linter installation for null-ls sources
    -- ["mason-null-ls"] = { -- overrides `require("mason-null-ls").setup(...)`
    --     ensure_installed = { "prettier", "stylua" },
    -- },
    whichkey = {
      presets = {
        operators = true,
        text_options = true,
        z = true,
        g = true,
      },
    },
  },

  -- LuaSnip Options
  luasnip = {
    -- Extend filetypes
    filetype_extend = {
      -- javascript = { "javascriptreact" },
    },
    -- Configure luasnip loaders (vscode, lua, and/or snipmate)
    vscode = {
      -- Add paths for including more VS Code style snippets in luasnip
      paths = {},
    },
  },

  -- CMP Source Priorities
  -- modify here the priorities of default cmp sources
  -- higher value == higher priority
  -- The value can also be set to a boolean for disabling default sources:
  -- false == disabled
  -- true == 1000
  cmp = {
    source_priority = {
      nvim_lsp = 1000,
      luasnip = 750,
      buffer = 500,
      path = 250,
    },
  },

  -- Modify which-key registration (Use this with mappings table in the above.)
  ["which-key"] = {
    -- Add bindings which show up as group name
    register = {
      -- first key is the mode, n == normal mode
      n = {
        -- second key is the prefix, <leader> prefixes
        ["<leader>"] = {
          -- third key is the key to bring up next level and its displayed
          -- group name in which-key top level menu
          ["y"] = { '"+y', "yank +clipboard" },
          ["Y"] = { '"+y$', "Yank +clipboard" },
          ["d"] = { '"_d', "delete noregister" },
          ["b"] = { name = "Buffer" },
          ["m"] = {
            name = "Markdown",
            ["M"] = { "<cmd>Glow<CR>", "Markdown Glow" },
            ["m"] = { "<cmd>MarkdownPreview<CR>", "MarkdownPreview" },
            ["t"] = { "<cmd>MarkdownPreviewToggle<CR>", "MarkdownPreview Toggle" },
            ["s"] = { "<cmd>MarkdownPreviewStop<CR>", "MarkdownPreview Stop" },
          },
          ["r"] = {
            name = "Code runner",
            ["r"] = { ":RunCode<CR>", "Run code" },
            ["f"] = { ":RunFile<CR>", "Run file" },
            ["t"] = { ":RunFile tab<CR>", "Fun file tab" },
            ["c"] = { ":RunClose<CR>", "Close runner" },
          },
          ["T"] = {
            name = "Trouble",
            ["r"] = { ":Trouble lsp_references<CR>", "References" },
            ["f"] = { ":Trouble lsp_definitions<CR>", "Definitions" },
            ["d"] = { ":Trouble document_diagnostics<CR>", "Diagnostics" },
            ["q"] = { ":Trouble quickfix<CR>", "QuickFix" },
            ["l"] = { ":Trouble loclist<CR>", "LocationList" },
            ["w"] = {
              ":Trouble workspace_diagnostics<cr>",
              "Wordspace Diagnostics",
            },
          },
          ["D"] = {
            name = "Debug",
            ["b"] = { "<cmd>lua require'dap'.toggle_breakpoint()<CR>", "Breakpoint" },
            ["c"] = { "<cmd>lua require'dap'.continue()<CR>", "Continue" },
            ["i"] = { "<cmd>lua require'dap'.step_into()<CR>", "Into" },
            ["o"] = { "<cmd>lua require'dap'.step_over()<CR>", "Over" },
            ["O"] = { "<cmd>lua require'dap'.step_out()<CR>", "Out" },
            ["r"] = { "<cmd>lua require'dap'.repl.toggle()<CR>", "Repl" },
            ["l"] = { "<cmd>lua require'dap'.run_last()<CR>", "Last" },
            ["u"] = { "<cmd>DapuiToggle<CR>", "UI" },
            ["x"] = { "<cmd>lua require'dap'.terminate()<CR>", "Exit" },
          },
        },
      },
      v = {
        ["<leader>"] = {
          ["y"] = { '"+y', "yank +clipboard" },
          ["Y"] = { '"+y', "Yank +clipboard" },
          ["d"] = { '"_d', "delete noregister" },
          ["D"] = { '"_D', "Delete noregister" },
          ["r"] = { "<Esc><cmd>Refactoring<CR>", "Refactoring" },
        },
      },
      x = {
        ["<leader>"] = {
          ["p"] = { '"_dP', "Paste noregister" },
        },
      },
    },
  },
  -- This function is run last and is a good place to configuring
  -- 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()
    vim.cmd [[
    au TextYankPost * silent! lua vim.highlight.on_yank {higroup="IncSearch", timeout=100}
    :set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz
    command! LinterRestart execute "lua require('null-ls.client')._reset()" | edit
    " command! Mason execute "lua require('mason.ui').open()"
    command! Refactoring execute "lua require('telescope').extensions.refactoring.refactors()"
    command! DapuiToggle execute "lua require'dapui'.toggle()"
    ]]
    -- Set up custom filetypes
    vim.filetype.add {
      filename = {
        ["poetry.lock"] = "toml",
      },
      -- extension = {
      --   foo = "fooscript",
      -- },
      -- pattern = {
      --   ["~/%.config/foo/.*"] = "fooscript",
      -- },
    }
  end,
}

return config
RayJameson commented 1 year ago

@mehalter thank you very much for your time. Appreciate your work on this wonderful config. I tried LunarVim before and I like AstroNvim better