Skip to content

Commit

Permalink
Implement switchLanguage() in commands-lsp module.
Browse files Browse the repository at this point in the history
The function follows the same methodology as the other commands: it
changes the server spec and notifies the client of the change.
  • Loading branch information
jkorb committed Apr 24, 2023
1 parent 3ceb240 commit ad2aa19
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lua/ltex_extra/commands-lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local types = {
["dict"] = "dictionary",
["dRules"] = "disabledRules",
["hRules"] = "hiddenFalsePositives",
["language"] = "language",
}

local function get_settings(client)
Expand Down Expand Up @@ -45,6 +46,14 @@ local function update_hiddenFalsePositive(client, lang)
return client.notify("workspace/didChangeConfiguration", settings)
end

local function update_language(client, lang)
log.trace("update_language")
local settings = get_settings(client)
settings.ltex.language = lang
log.debug(vim.inspect(settings.ltex.language))
return client.notify("workspace/didChangeConfiguration", settings)
end

local M = {}

function M.catch_ltex()
Expand All @@ -66,12 +75,14 @@ function M.updateConfig(configtype, lang)
update_disabledRules(client, lang)
elseif configtype == types.hRules then
update_hiddenFalsePositive(client, lang)
elseif configtype == types.language then
update_language(client, lang)
else
log.fmt_error("Config type unknown")
return vim.notify("Config type unknown")
end
else
return error("Error catching ltex client",1)
return error("Error catching ltex client", 1)
end
end

Expand Down Expand Up @@ -124,4 +135,14 @@ function M.hideFalsePositives(command)
end
end

return M
function M.switchLanguage(lang)
log.trace("language")
local client = M.catch_ltex()
if client then
M.updateConfig(types.language, lang)
else
return error("Error catching ltex client", 1)
end
end

return Meturn M

0 comments on commit ad2aa19

Please sign in to comment.