Skip to content

Commit 5a297cf

Browse files
committed
fix(config): normalize mappings when running setup
1 parent f85e64d commit 5a297cf

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lua/astrolsp/init.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,29 @@ function M.lsp_opts(server_name)
203203
return opts
204204
end
205205

206+
local key_cache = {} ---@type { [string]: string }
207+
208+
---@param mappings AstroLSPMappings?
209+
local function normalize_mappings(mappings)
210+
if not mappings then return end
211+
for _, mode_maps in pairs(mappings) do
212+
for key, _ in pairs(mode_maps) do
213+
if not key_cache[key] then
214+
key_cache[key] = vim.fn.keytrans(vim.api.nvim_replace_termcodes(key, true, true, true))
215+
end
216+
local normkey = key_cache[key]
217+
if key ~= normkey then
218+
mode_maps[normkey], mode_maps[key] = mode_maps[key], nil
219+
end
220+
end
221+
end
222+
end
223+
206224
--- Setup and configure AstroLSP
207225
---@param opts AstroLSPOpts options passed by the user to configure AstroLSP
208226
function M.setup(opts)
227+
normalize_mappings(M.config.mappings)
228+
normalize_mappings(opts.mappings)
209229
M.config = vim.tbl_deep_extend("force", M.config, opts)
210230

211231
-- enable necessary capabilities for enabled LSP file operations

0 commit comments

Comments
 (0)