Skip to content

Commit

Permalink
Merge pull request #2 from frostplexx/fix_async
Browse files Browse the repository at this point in the history
fix async loading
  • Loading branch information
frostplexx authored May 23, 2024
2 parents ec02275 + 8f4b95f commit 3fe9863
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lua/mason-bridge/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local M = {}

-- Table to hold cached associations
local cached_associations = {}
local associations_loaded = false

local DEFAULT_SETTINGS = {
-- A table of filetypes with the respective tool (or tools) to be used
Expand All @@ -24,19 +25,35 @@ M.setup = function(opts)
cached_associations.formatters =
vim.tbl_deep_extend('force', cached_associations.formatters, opts.overrides.formatters)
cached_associations.linters = vim.tbl_deep_extend('force', cached_associations.linters, opts.overrides.linters)
-- Set the flag to indicate associations are loaded
associations_loaded = true
end)
end

-- Helper function to block until associations are loaded
local function wait_until_loaded()
while not associations_loaded do
vim.wait(0.1)
-- this is not ideal but fixes cases where .get_formatters is called before .setup
M.setup()
end
end

-- Returns a table of formatters
M.get_formatters = function()
wait_until_loaded()
-- Return the cached formatters
return cached_associations.formatters or {}
return cached_associations.formatters
end

-- Returns a table of linters
M.get_linters = function()
wait_until_loaded()
-- Return the cached linters
return cached_associations.linters or {}
return cached_associations.linters
end

--
-- Returns the language to filetype mappings
M.get_mappings = function()
-- Return the cached mappings
return require 'util.mappings'
Expand Down

0 comments on commit 3fe9863

Please sign in to comment.