Skip to content

Commit

Permalink
fix: don't refetch crate with incorrect crate name case
Browse files Browse the repository at this point in the history
  • Loading branch information
saecki committed Jul 23, 2024
1 parent 33fc70d commit 6aee4a2
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lua/crates/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
---@field search_cache SearchCache
---@field visible boolean
local State = {
api_cache = {},
buf_cache = {},
search_cache = {
results = {},
Expand All @@ -14,6 +13,35 @@ local State = {
visible = true,
}

---@param name string
---@return string
local function normalize_crate_name(name)
return name:lower():gsub("-", "_")
end

local ApiCache = {}

function ApiCache.new()
return setmetatable({}, ApiCache)
end

function ApiCache:__index(key)
local val = rawget(self, key)
if val then
return val
end

local id = normalize_crate_name(key)
return rawget(self, id)
end

function ApiCache:__newindex(key, value)
local id = normalize_crate_name(key)
return rawset(self, id, value)
end

State.api_cache = ApiCache.new()

---@class BufCache
---@field crates table<string,TomlCrate>
---@field info table<string,CrateInfo>
Expand Down

0 comments on commit 6aee4a2

Please sign in to comment.