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.29k stars 915 forks source link

Diagnostics config does not work because of ray-x/go.nvim #1339

Closed tri-cao closed 1 year ago

tri-cao commented 1 year ago

Question

After updating astronvim diagnostic config does not work.

I try config in both user/init.lua and user/diagnostics.lua but no changes: image image

User Configuration

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

  -- 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 = false, -- 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
    -- },
  },

  -- add new user interface icon
  icons = {
    VimIcon = "",
  },
  -- modify variables used by heirline but not defined in the setup call directly
  heirline = {
    -- define the separators between each section
    separators = {
      left = { "", " " }, -- separator for the left side of the statusline
      right = { " ", "" }, -- separator for the right side of the statusline
    },
    -- add new colors that can be used by heirline
    colors = function(hl)
      -- use helper function to get highlight group properties
      hl.blank_bg = astronvim.get_hlgroup("Folded").fg
      hl.file_info_bg = astronvim.get_hlgroup("Visual").bg
      hl.nav_icon_bg = astronvim.get_hlgroup("String").fg
      hl.folder_icon_bg = astronvim.get_hlgroup("Error").fg
      return hl
    end,
  },

  diagnostics = {
    virtual_text = false,
    underline = true,
  },
  lsp = {
    mappings = {
      n = {
        ["K"] = {
          function()
            if vim.bo.filetype == "rust" then
              require("rust-tools").hover_actions.hover_actions()
            else
              vim.lsp.buf.hover()
            end
          end,
          desc = "Hover",
        },

        ["gr"] = {
          function() require("telescope.builtin").lsp_references() end,
          desc = "lsp references",
        },

        ["gd"] = {
          function() require("telescope.builtin").lsp_definitions() end,
          desc = "lsp references",
        },

        ["gi"] = {
          function() require("telescope.builtin").lsp_implementations() end,
          desc = "Telescope lsp_implementation",
        },

        ["<leader>lf"] = {
          function()
            if vim.bo.filetype == "python" then
              vim.lsp.buf.format { async = true }
              vim.cmd "PyrightOrganizeImports"
            elseif vim.bo.filetype == "typescript" then
              vim.lsp.buf.format { async = true }
              require("typescript").actions.addMissingImports()
              require("typescript").actions.organizeImports()
            else
              vim.lsp.buf.format { async = true }
            end
          end,
          desc = "lsp formatting",
        },
      },
    },
    skip_setup = { "rust_analyzer", "tsserver", "gopls" }, -- skip lsp setup because rust-tools will do it itself
    server_registration = function(server, opts)
      local util = require "lspconfig/util"

      if server ~= "pyright" then -- don't call setup for tsserver
        require("lspconfig")[server].setup(opts)
      end

      if server == "pyright" then -- don't call setup for tsserver
        require("lspconfig")[server].setup {
          on_attach = astronvim.lsp.on_attach,
          capabilities = astronvim.lsp.capabilities,

          root_dir = function(fname)
            return util.root_pattern(
              -- ".git",
              "setup.py",
              "setup.cfg",
              "pyproject.toml",
              "requirements.txt",
              "environment.yaml"
            )(fname) or util.path.dirname(fname)
          end,

          settings = {
            python = {
              analysis = {
                autoSearchPaths = true,
                diagnosticMode = "workspace",
                useLibraryCodeForTypes = true,
                typeCheckingMode = "off",
                extraPaths = { "/Users/nix/project/airflow/intrepid-airflow/dags" },
              },
            },
          },
        }
      end
    end,
    -- ["server-settings"] = {
    --   pyright = {
    --     settings = {
    --       python = {
    --         analysis = {
    --           autoSearchPaths = true,
    --           diagnosticMode = "workspace",
    --           useLibraryCodeForTypes = true,
    --           typeCheckingMode = "off",
    --           extraPaths = { "/Users/nix/project/airflow/intrepid-airflow/dags" },
    --         },
    --       },
    --     },
    --   },
    -- },
  },
  plugins = {
    init = {
      {
        "simrat39/rust-tools.nvim",
        after = "mason-lspconfig.nvim", -- make sure to load after mason-lspconfig
        config = function()
          require("rust-tools").setup {
            server = {
              on_attach = astronvim.lsp.on_attach,
              capabilities = astronvim.lsp.capabilities,
              settings = {
                ["rust-analyzer"] = {
                  checkOnSave = {
                    command = "clippy",
                  },
                  lens = {
                    enable = true,
                  },
                  procMacro = {
                    enable = true,
                  },
                  cargo = {
                    buildScripts = {
                      enable = true,
                    },
                  },
                },
              },
            },
            tools = {
              inlay_hints = {
                auto = true,

                -- Only show inlay hints for the current line
                only_current_line = false,

                -- whether to show parameter hints with the inlay hints or not
                -- default: true
                show_parameter_hints = true,

                -- prefix for parameter hints
                -- default: "<-"
                parameter_hints_prefix = "<- ",

                -- prefix for all the other hints (type, chaining)
                -- default: "=>"
                other_hints_prefix = "=> ",
              },
              on_initialized = function()
                vim.api.nvim_create_autocmd({ "BufWritePost", "BufEnter", "CursorHold", "InsertLeave" }, {
                  pattern = { "*.rs" },
                  callback = function() vim.lsp.codelens.refresh() end,
                })
              end,
            },
          }
        end,
      },
      {
        "jose-elias-alvarez/typescript.nvim",
        after = "mason-lspconfig.nvim", -- make sure to load after mason-lspconfig
        config = function()
          require("typescript").setup {
            disable_commands = false, -- prevent the plugin from creating Vim commands
            debug = false, -- enable debug logging for commands
            go_to_source_definition = {
              fallback = false, -- fall back to standard LSP definition on failure
            },
            server = astronvim.lsp.server_settings "tsserver",
          }
        end,
      },
      {
        "ray-x/go.nvim",
        after = "mason-lspconfig.nvim", -- make sure to load after mason-lspconfig
        config = function()
          require("go").setup {
            go = "go", -- set to go1.18beta1 if necessary
            goimport = "goimports", -- if set to 'gopls' will use gopls format, also goimport
            fillstruct = "gopls",
            gofmt = "gofumpt", -- if set to gopls will use gopls format
            null_ls_document_formatting_disable = false,
            lsp_gofumpt = true,
            lsp_codelens = true,
            lsp_document_formatting = false,
            -- other setups ....
            lsp_cfg = {
              on_attach = astronvim.lsp.on_attach,
              capabilities = astronvim.lsp.capabilities,
              -- other setups
            },
          }
        end,
      },
      {
        "danymat/neogen",
        config = function() require("neogen").setup {} end,
      },
      {
        "tpope/vim-surround",
      },
      {
        "petertriho/nvim-scrollbar",
        config = function() require("scrollbar").setup() end,
      },
      {
        "nvim-treesitter/nvim-treesitter-textobjects",
      },
      {
        "nvim-telescope/telescope-live-grep-args.nvim",
      },
      ["max397574/better-escape.nvim"] = { disable = true },
      ["nvim-neorg/neorg"] = {
        config = function()
          require("neorg").setup {
            load = {
              ["core.defaults"] = {},
              ["core.norg.concealer"] = {},
              ["core.norg.completion"] = {
                config = {
                  engine = "nvim-cmp",
                },
              },
              ["core.norg.dirman"] = {
                config = {
                  workspaces = {
                    work = "~/Documents/Notes/work",
                    home = "~/Documents/Notes/home",
                    brain = "~/Documents/Notes/brain",
                    gtd = "~/Documents/Notes/brain/gtd",
                  },
                },
              },
              ["core.gtd.base"] = {
                config = {
                  workspace = "gtd",
                },
              },
            },
          }
        end,
        requires = {
          { "nvim-lua/plenary.nvim" },
        },
      },
      ["stevearc/aerial.nvim"] = { disable = true },
      {
        "ray-x/lsp_signature.nvim",
        config = function()
          require("lsp_signature").setup {
            hint_enable = false,
          }
        end,
      },
      {
        "TimUntersberger/neogit",
        config = function()
          require("neogit").setup {
            integrations = {
              diffview = true,
            },
          }
        end,
      },
      {
        "sindrets/diffview.nvim",
        requires = {
          { "nvim-lua/plenary.nvim" },
        },
        config = function()
          require("diffview").setup {
            merge_tool = {
              -- Config for conflicted files in diff views during a merge or rebase.
              layout = "diff1_plain",
              disable_diagnostics = true, -- Temporarily disable diagnostics for conflict buffers while in the view.
            },
          }
        end,
      },
      { "mbledkowski/neuleetcode.vim" },
      ["neo-tree"] = { disable = true },
      ["nvim-tree/nvim-tree.lua"] = {
        config = function()
          local node_relative_path = function(node) return vim.fn.fnamemodify(node.absolute_path, ":~:.") end

          local find_in_path = function(node)
            local opts = {}
            opts.default_text = '-g"' .. node_relative_path(node) .. '/**" "'
            require("telescope").extensions.live_grep_args.live_grep_args(opts)
          end

          require("nvim-tree").setup {
            filters = {
              dotfiles = false,
              custom = { "^.git$" },
            },
            disable_netrw = true,
            hijack_netrw = true,
            open_on_setup = false,
            ignore_ft_on_setup = { "alpha" },
            hijack_cursor = true,
            hijack_unnamed_buffer_when_opening = false,
            update_cwd = true,
            update_focused_file = {
              enable = true,
              update_cwd = false,
            },
            view = {
              adaptive_size = false,
              side = "left",
              width = 38,
              hide_root_folder = false,
              mappings = {
                list = {
                  { key = "f", action = "find in path", action_cb = find_in_path },
                },
              },
            },
            git = {
              enable = false,
              ignore = true,
            },
            filesystem_watchers = {
              enable = true,
            },
            actions = {
              open_file = {
                resize_window = true,
              },
            },
            renderer = {
              highlight_git = false,
              highlight_opened_files = "none",

              indent_markers = {
                enable = true,
                inline_arrows = true,
              },

              icons = {
                show = {
                  file = true,
                  folder = true,
                  folder_arrow = true,
                  git = false,
                },

                glyphs = {
                  default = "",
                  symlink = "",
                  folder = {
                    default = "",
                    empty = "",
                    empty_open = "",
                    open = "",
                    symlink = "",
                    symlink_open = "",
                    arrow_open = "",
                    arrow_closed = "",
                  },
                  git = {
                    unstaged = "✗",
                    staged = "✓",
                    unmerged = "",
                    renamed = "➜",
                    untracked = "★",
                    deleted = "",
                    ignored = "◌",
                  },
                },
              },
            },
          }
        end,
      },
    },
    ["cmp"] = {
      mapping = {
        ["<C-p>"] = require("cmp").mapping.select_prev_item(),
        ["<C-n>"] = require("cmp").mapping.select_next_item(),
      },
    },
    ["telescope"] = {
      extensions = { "live_grep_args" },
      defaults = {
        mappings = {
          i = {
            ["<C-j>"] = require("telescope.actions").cycle_history_next,
            ["<C-k>"] = require("telescope.actions").cycle_history_prev,

            ["<C-n>"] = require("telescope.actions").move_selection_next,
            ["<C-p>"] = require("telescope.actions").move_selection_previous,

            ["<c-q>"] = require("telescope.actions").smart_send_to_qflist + require("telescope.actions").open_qflist,
          },
          n = {
            ["<c-q>"] = require("telescope.actions").smart_send_to_qflist + require("telescope.actions").open_qflist,
          },
        },
      },
      pickers = {
        buffers = {
          ignore_current_buffer = true,
          sort_mru = true,
          mappings = {
            i = {
              ["<c-x>"] = require("telescope.actions").delete_buffer,
            },
            n = {
              ["d"] = "delete_buffer",
            },
          },
        },
      },
    },
    ["treesitter"] = {
      textobjects = {
        select = {
          enable = true,
          -- Automatically jump forward to textobj, similar to targets.vim
          lookahead = true,
          keymaps = {
            -- You can use the capture groups defined in textobjects.scm
            ["af"] = "@function.outer",
            ["if"] = "@function.inner",
            ["ac"] = "@class.outer",
            ["ic"] = "@class.inner",
            ["ia"] = "@parameter.inner",
            ["aa"] = "@parameter.outer",
          },
        },
        -- swap = {
        --   enable = true,
        --   swap_next = {
        --     ["<leader>a"] = "@parameter.inner",
        --   },
        --   swap_previous = {
        --     ["<leader>A"] = "@parameter.inner",
        --   },
        -- },
        move = {
          enable = true,
          set_jumps = true,
          goto_next_start = {
            ["]f"] = "@function.outer",
            ["]c"] = "@class.outer",
            ["]a"] = "@parameter.inner",
          },
          goto_next_end = {
            ["]F"] = "@function.outer",
            ["]C"] = "@class.outer",
          },
          goto_previous_start = {
            ["[f"] = "@function.outer",
            ["[c"] = "@class.outer",
            ["[a"] = "@parameter.inner",
          },
          goto_previous_end = {
            ["[F"] = "@function.outer",
            ["[C"] = "@class.outer",
          },
        },
      },
    },
    ["mason-lspconfig"] = {
      ensure_installed = {
        "rust_analyzer",
        "pyright",
      }, -- install rust_analyzer","
    },
    ["null-ls"] = function(config)
      local null_ls = require "null-ls"
      config.sources = { -- set null-ls sources
        -- Lua
        null_ls.builtins.formatting.stylua,

        -- python
        null_ls.builtins.formatting.black,

        -- js, ts
        null_ls.builtins.formatting.prettierd,

        -- rust
        null_ls.builtins.formatting.rustfmt,

        -- go
        null_ls.builtins.formatting.goimports,
        null_ls.builtins.formatting.gofumpt,
      }
    end,
    -- ["neo-tree"] = {
    --   window = {
    --     position = "left",
    --     width = 38,
    --   },
    --   filesystem = {
    --     filtered_items = {
    --       visible = true,
    --     },
    --     use_libuv_file_watcher = false,
    --   },
    --   enable_git_status = false,
    --   enable_diagnostics = false,
    --   resize_timer_interval = -1,
    -- },
    ["bufferline"] = {
      options = {
        offsets = {
          { filetype = "NvimTree", text = "-- Tree --", padding = 1 },
          { filetype = "neo-tree", text = "-- Tree --", padding = 1 },
          { filetype = "Outline", text = "-- Outline --", padding = 1 },
        },
        separator_style = "slant",
      },
    },

    gitsigns = {
      signs = {
        untracked = { text = "▎" },
      },
    },

    -- override the heirline setup call
    heirline = function(config)
      -- the first element of the configuration table is the statusline
      config[1] = {
        -- default highlight for the entire statusline
        hl = { fg = "fg", bg = "bg" },
        -- each element following is a component in astronvim.status module

        -- add the vim mode component
        astronvim.status.component.mode {
          -- enable mode text with padding as well as an icon before it
          mode_text = { icon = { kind = "VimIcon", padding = { right = 1, left = 1 } } },
          -- define the highlight color for the text
          hl = { fg = "bg" },
          -- surround the component with a separators
          surround = {
            -- it's a left element, so use the left separator
            separator = "left",
            -- set the color of the surrounding based on the current mode using astronvim.status module
            color = function() return { main = astronvim.status.hl.mode_bg(), right = "blank_bg" } end,
          },
        },
        -- we want an empty space here so we can use the component builder to make a new section with just an empty string
        astronvim.status.component.builder {
          { provider = "" },
          -- define the surrounding separator and colors to be used inside of the component
          -- and the color to the right of the separated out section
          surround = { separator = "left", color = { main = "blank_bg", right = "file_info_bg" } },
        },
        -- add a section for the currently opened file information
        astronvim.status.component.file_info {
          -- enable the file_icon and disable the highlighting based on filetype
          file_icon = { highlight = false, padding = { left = 0 } },
          -- add padding
          padding = { right = 1 },
          -- define the section separator
          surround = { separator = "left", condition = false },
        },
        -- add a component for the current git branch if it exists and use no separator for the sections
        astronvim.status.component.git_branch { surround = { separator = "none" } },
        -- add a component for the current git diff if it exists and use no separator for the sections
        astronvim.status.component.git_diff { padding = { left = 1 }, surround = { separator = "none" } },
        -- fill the rest of the statusline
        -- the elements after this will appear in the middle of the statusline
        astronvim.status.component.fill(),
        -- add a component to display if the LSP is loading, disable showing running client names, and use no separator
        astronvim.status.component.lsp { lsp_client_names = false, surround = { separator = "none", color = "bg" } },
        -- fill the rest of the statusline
        -- the elements after this will appear on the right of the statusline
        astronvim.status.component.fill(),
        -- add a component for the current diagnostics if it exists and use the right separator for the section
        astronvim.status.component.diagnostics { surround = { separator = "right" } },
        -- add a component to display LSP clients, disable showing LSP progress, and use the right separator
        astronvim.status.component.lsp { lsp_progress = false, surround = { separator = "right" } },
        -- NvChad has some nice icons to go along with information, so we can create a parent component to do this
        -- all of the children of this table will be treated together as a single component
        {
          -- define a simple component where the provider is just a folder icon
          astronvim.status.component.builder {
            -- astronvim.get_icon gets the user interface icon for a closed folder with a space after it
            { provider = astronvim.get_icon "FolderClosed" },
            -- add padding after icon
            padding = { right = 1 },
            -- set the foreground color to be used for the icon
            hl = { fg = "bg" },
            -- use the right separator and define the background color
            surround = { separator = "right", color = "folder_icon_bg" },
          },
          -- add a file information component and only show the current working directory name
          astronvim.status.component.file_info {
            -- we only want filename to be used and we can change the fname
            -- function to get the current working directory name
            filename = { fname = function() return vim.fn.getcwd() end, padding = { left = 1 } },
            -- disable all other elements of the file_info component
            file_icon = false,
            file_modified = false,
            file_read_only = false,
            -- use no separator for this part but define a background color
            surround = { separator = "none", color = "file_info_bg" },
          },
        },
        -- the final component of the NvChad statusline is the navigation section
        -- this is very similar to the previous current working directory section with the icon
        { -- make nav section with icon border
          -- define a custom component with just a file icon
          astronvim.status.component.builder {
            { provider = astronvim.get_icon "DefaultFile" },
            -- add padding after icon
            padding = { right = 1 },
            -- set the icon foreground
            hl = { fg = "bg" },
            -- use the right separator and define the background color
            -- as well as the color to the left of the separator
            surround = { separator = "right", color = { main = "nav_icon_bg", left = "file_info_bg" } },
          },
          -- add a navigation component and just display the percentage of progress in the file
          astronvim.status.component.nav {
            -- add some padding for the percentage provider
            percentage = { padding = { left = 1, right = 1 } },
            -- disable all other providers
            ruler = false,
            scrollbar = false,
            -- define the foreground color
            hl = { fg = "nav_icon_bg" },
            -- use no separator and define the background color
            surround = { separator = "none", color = "file_info_bg" },
          },
        },
      }

      -- a second element in the heirline setup would override the winbar
      -- by only providing a single element we will only override the statusline
      -- and use the default winbar in AstroNvim

      -- Disable winbar
      config[2] = nil

      -- return the final confiuration table
      return config
    end,
  },
  mappings = {
    i = {},
    n = {
      ["<A-;>"] = {
        "<cmd> lua if vim.api.nvim_get_current_line():sub(-1) ~= ';' then vim.api.nvim_set_current_line(vim.api.nvim_get_current_line() .. ';') elseif vim.api.nvim_get_current_line():sub(-1) == ';' then vim.api.nvim_set_current_line(vim.api.nvim_get_current_line():sub(0, -2)) end <CR>",
        desc = "Add or remove semi colon add the end of line",
      },

      ["<leader>fg"] = {
        "<cmd>lua require('telescope').extensions.live_grep_args.live_grep_args()<CR>",
        desc = "live grep args",
      },
      ["<A-i>"] = { "<cmd>ToggleTerm<cr>", desc = "Toggle terminal" },
      ["<C-_>"] = {
        function() require("Comment.api").toggle.linewise.current() end,
        desc = "toggle comment",
      },

      ["<leader>e"] = { "<cmd> NvimTreeToggle <CR>", desc = "toggle nvimtree" },

      ["<leader>fq"] = { "<cmd> Telescope quickfix <CR>", desc = "telescope quickfix list" },

      ["<leader>gg"] = { '<cmd> lua require("neogit").open({ kind = "split" }) <CR>', desc = "open neogit" },

      ["<leader>ln"] = { '<cmd> lua require("neogen").generate() <CR>', desc = "generate docs with neogen" },

      ["<leader>tf"] = { function() astronvim.toggle_term_cmd "lf" end, desc = "ToggleTerm lf" },
    },
    t = {
      ["<A-i>"] = { "<cmd>ToggleTerm<cr>", desc = "Toggle terminal" },
    },
    v = {
      ["<C-_>"] = {
        "<ESC><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<CR>",
        desc = "toggle comment",
      },
    },
  },
  options = {
    opt = {
      cmdheight = 1,
      wrap = true, -- Enable wrapping of lines longer than the width of window
      foldenable = false,
      foldexpr = "nvim_treesitter#foldexpr()", -- set Treesitter based folding
      foldmethod = "expr",
      ttyfast = true,
      lazyredraw = true,
    },
  },
  cmp = {
    source_priority = {
      nvim_lsp = 1000,
      luasnip = 750,
      buffer = 500,
      path = 250,
    },
  },
  polish = function()
    -- diagnostic
    -- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
    --   virtual_text = false,
    -- })
    -- vim.diagnostic.config {
    --   virtual_text = false,
    --   signs = true,
    --   update_in_insert = true,
    --   underline = true,
    --   severity_sort = false,
    --   float = {
    --     border = "rounded",
    --     source = "always",
    --     header = "",
    --     prefix = "",
    --   },
    -- }

    local keymapset = vim.keymap.set
    keymapset({ "n", "x" }, "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true })
    keymapset({ "n", "x" }, "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true })

    if vim.fn.executable "nvr" == 1 then vim.env.GIT_EDITOR = "nvr -cc split --remote-wait +'set bufhidden=wipe'" end

    -- leetcode
    vim.g["leetcode_solution_filetype"] = "python3"
    vim.g["leetcode_browser"] = "brave"
    vim.g["leetcode_china"] = 0

    -- nvim tree
    vim.cmd "hi NvimTreeWinSeparator guibg=#1F2229 guifg=#1F2229"
    vim.cmd "hi NvimTreeNormalNC guibg=#1C1F27"
    vim.cmd "hi NvimTreeNormal guibg=#1C1F27"
  end,
}

return config
mehalter commented 1 year ago

@tri-cao , I'm not sure what's going on, but it looks like go.nvim is breaking vim.diagnostic.config. I have not idea what it's doing, but it makes vim.diagnostic.config() do absolutely nothing. This seems like a bug somewhere in their plugin

tri-cao commented 1 year ago

go.nvim has an option that let it hook to diagnostics. After disabling it everything works fine

          require("go").setup {
            go = "go",
            lsp_diag_hdlr = false,
            ...
          }

Thank you