NvChad / ui

Lightweight & high performance UI plugin for nvchad
GNU General Public License v3.0
208 stars 124 forks source link

:MasonInstallAll command wrong implementation after last update #305

Closed alexandr-martirosyan closed 2 months ago

alexandr-martirosyan commented 2 months ago

The recent commit has relocated the :MasonInstallAll command implementation from the NvChad plugin settings to the NvChad/ui repository. However, there appears to be a bug in the get_pkgs() function.

From this comment, it is implied that the code snippet is intended to remove duplicate packages. However, the actual behavior of the code diverges significantly; it only adds package-name from tools to pkgs if there is a corresponding package available in the Mason registry. Consequently, the function only adds from data to pkgs only those packages whose name matches the name in the Mason registry.

It seems likely that the intended functionality was different and perhaps the developer inadvertently left the code incomplete. Below is a version of the get_pkgs() function that I believe was intended.

PR

local get_pkgs = function(data)
  local tools = {}

  local lsps = require("lspconfig.util").available_servers()
  tools = vim.list_extend(tools, lsps)

  local conform_exists, conform = pcall(require, "conform")

  if conform_exists then
    local formatters = conform.list_all_formatters()

    local formatters_names = vim.tbl_map(function(formatter)
      return formatter.name
    end, formatters)

    tools = vim.list_extend(tools, formatters_names)
  end

  local lint_exists, lint = pcall(require, "lint")

  if lint_exists then
    local linters = lint.linters_by_ft

    for _, v in pairs(linters) do
      table.insert(tools, v[1])
    end
  end

  local pkgs = {}

  -- add data to pkgs and remove duplicates
  if data then
    for _, v in pairs(data) do
      if not (vim.tbl_contains(pkgs, v)) then
        table.insert(pkgs, v)
      end
    end
  end

  -- add tools corresponding packages to pkgs
  for _, v in pairs(tools) do
    if not (vim.tbl_contains(pkgs, masonames[v])) then
      table.insert(pkgs, masonames[v])
    end
  end

  return pkgs
end