frostplexx / mason-bridge.nvim

Automatically register linters and formatters installed in mason.nvim
MIT License
32 stars 2 forks source link

get_linters always returns empty table #9

Open ilan-schemoul opened 3 months ago

ilan-schemoul commented 3 months ago

EDIT: maybe I don't understand "lazy" because if I add a timer it works nvim-lint

  return {
  "mfussenegger/nvim-lint",
  priority = 0,
  dependencies = {
    "frostplexx/mason-bridge.nvim",
  },
  config = function()
    local timer = vim.uv.new_timer()
    local ms = 1
    -- Only way to make it work is a timer
    timer:start(1000 * ms, 0, vim.schedule_wrap(function()
      print(vim.inspect(require("mason-bridge").get_linters()))
    end))

  end,
}

mason-bridge.lua

return {
  "frostplexx/mason-bridge.nvim",
  dependencies = {
    "williamboman/mason.nvim",
  },
  opts = {},
}

mason.lua

return {
  "williamboman/mason.nvim",
  opts = {
    automatic_installation = true
  },
}
kevmuko commented 1 month ago

This seems to always return an empty table because on mason-bridge setup the associations are loaded async. So it's not ready by the time you need it when you call lint/conform setup.

Seems like the options forward:

  1. Make the load_associations_async synchronous, but then you'd experience a hang on startup
  2. Use the dynamic loading autocmds in the README
  3. Support callbacks in this plugin to update the lint.linters_by_ft and conform.formatters_by_ft

I think I would prefer callbacks to prevent the need to add autocmds