Switch language in Ltex

This commit is contained in:
Thomas Avé 2023-04-29 12:01:29 +02:00
parent ee179a6150
commit 3332489a02
5 changed files with 47 additions and 2 deletions

View File

@ -107,7 +107,7 @@ require('lspconfig').clangd.setup {
capabilities = capabilities,
-- root_dir = function()
-- return require('lspconfig').util.root_pattern({'.clang-format', 'build/', 'compile_flags.txt'})
-- end
-- end,
cmd = {
"clangd",
"--background-index",

View File

@ -9,6 +9,24 @@ local default_opts = {
M.opts = {}
local ltex_languages = {
"en-GB",
"nl-BE",
"en-US",
"fr",
"auto",
}
local register_user_cmds = function()
vim.api.nvim_create_user_command("LtexSwitchLang", function()
vim.ui.select(ltex_languages, {
prompt = "Select language:",
}, function(choice)
require("ltex_extra.src.commands-lsp").switchLanguage(choice)
end)
end, { desc = "ltex_extra.nvim: Switch sever language" })
end
M.setup = function(opts)
log.trace("Merge options")
M.opts = opts or default_opts
@ -19,6 +37,7 @@ M.setup = function(opts)
end
log.trace("Add commands to lsp")
register_user_cmds()
vim.lsp.commands['_ltex.addToDictionary'] = require("ltex_extra.src.commands-lsp").addToDictionary
vim.lsp.commands['_ltex.hideFalsePositives'] = require("ltex_extra.src.commands-lsp").hideFalsePositives
vim.lsp.commands['_ltex.disableRules'] = require("ltex_extra.src.commands-lsp").disableRules

View File

@ -7,7 +7,8 @@ local loadFile = require("ltex_extra.src.utils").readFile
local types = {
["dict"] = "dictionary",
["dRules"] = "disabledRules",
["hRules"] = "hiddenFalsePositives"
["hRules"] = "hiddenFalsePositives",
["language"] = "language"
}
local function catch_ltex()
@ -20,6 +21,16 @@ local function catch_ltex()
return client
end
local function update_language(client, lang)
log.trace("update_language")
if not client.config.settings.ltex.language then
client.config.settings.ltex.language = {}
end
client.config.settings.ltex.language = lang
log.debug(vim.inspect(client.config.settings.ltex.language))
return client.notify("workspace/didChangeConfiguration", client.config.settings)
end
local function update_dictionary(client, lang)
log.trace("update_dictionary")
if not client.config.settings.ltex.dictionary then
@ -62,6 +73,8 @@ M.updateConfig = function(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")
@ -113,4 +126,14 @@ M.hideFalsePositives = function(command)
end
end
function M.switchLanguage(lang)
log.trace("language")
local client = catch_ltex()
if client then
M.updateConfig(types.language, lang)
else
return error("Error catching ltex client", 1)
end
end
return M

View File

@ -4,6 +4,8 @@ vim.api.nvim_set_keymap("n", "k", "gk", {})
vim.api.nvim_set_keymap("n", "<S-k>", "<Nop>", {})
vim.api.nvim_set_keymap("n", "<C-U>", "<C-O>", { noremap = true })
vim.api.nvim_set_keymap("n", "<C-E>", "<C-U>", { noremap = true })
vim.api.nvim_set_keymap("n", "<C-I>", "<C-I>", { noremap = true })
vim.api.nvim_set_keymap("n", "<Tab>", "<Nop>", { noremap = true })
vim.api.nvim_set_keymap("n", "<leader><space>", ":noh<cr>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "gn", ":n<cr>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>d", ":TroubleToggle<cr>", { noremap = true, silent = true })

View File

@ -7,3 +7,4 @@
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Q2 Conv.\\E$"}
{"rule":"ALLOW_TO","sentence":"^\\QA footnote says that in theory certain intelligent monstrosities could also train to become more powerful and throw off the bindings of age.\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QA quest: Book with golden hard-cover, located in a tower between Pan's village and Weathar.\\E$"}
{"rule":"EN_COMPOUNDS","sentence":"^\\Q\\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q take this approach for a multi-task policy distillation, where a single agent is trained based on several teachers that are each specialized in a single task, with the goal of training a single student that is able to perform all tasks.\\E$"}