commit d29b22ab34070c254e75ae4755c57b12ca87c9fd
parent 719f205be45abf1ee33b3fe1e0321d56c2f65e09
Author: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
Date: Sun, 12 Jun 2022 18:25:59 +0200
Use ltex-ls.nvim as a plugin
Diffstat:
2 files changed, 23 insertions(+), 115 deletions(-)
diff --git a/lua/lsp_config.lua b/lua/lsp_config.lua
@@ -137,54 +137,6 @@ local function texlab_attach(client, bufnr)
on_attach(client, bufnr)
end
-local function ltex_refresh(client, uri)
- client.notify("workspace/didChangeConfiguration")
- client.request("workspace/executeCommand", { command = "_ltex.checkDocument", arguments = { { uri = uri } } })
-end
-local function ltex_execute_command(err, actions, ctx)
- local client = vim.lsp.get_client_by_id(ctx.client_id)
- if ctx.method ~= "workspace/executeCommand" or client.name ~= "ltex" then
- error "LTeX command handler invalid usage"
- end
-
- local ltex_settings = client.config.settings.ltex
-
- local command_name = ctx.params.command
- local args = ctx.params.arguments
- if command_name == "_ltex.addToDictionary" then
- for lang, words in pairs(args[1].words) do
- for _, fpath in ipairs(vim.api.nvim_get_runtime_file("dict/" .. lang .. ".txt", false)) do
- local file = io.open(fpath, "a")
- if not file then
- error("Could not open" .. fpath)
- end
- file:write(table.concat(words, "\n") .. "\n")
- file:close()
- vim.list_extend(ltex_settings.dictionary[lang] or {}, words)
- end
- end
- ltex_refresh(client, args[1].uri)
- elseif command_name == "_ltex.hideFalsePositives" then
- local cache_path = vim.fn.fnamemodify(vim.uri_to_fname(args[1].uri), ":p:h") .. "/.ltex_fp.json"
- if not ltex_settings.hiddenFalsePositives then
- ltex_settings.hiddenFalsePositives = {}
- end
- for lang, words in pairs(args[1].falsePositives) do
- if ltex_settings.hiddenFalsePositives[lang] then
- vim.list_extend(ltex_settings.hiddenFalsePositives[lang], words)
- else
- ltex_settings.hiddenFalsePositives[lang] = words
- end
- end
- local cache = io.open(cache_path, "w")
- cache:write(vim.fn.json_encode(ltex_settings.hiddenFalsePositives))
- cache:close()
- ltex_refresh(client, args[1].uri)
- end
-
- vim.lsp.handlers[ctx.method](err, actions, ctx)
-end
-
-- System lsps
local capabilities = vim.lsp.protocol.make_client_capabilities()
@@ -272,76 +224,31 @@ local lsps = {
}
},
},
- ltex = {
- on_attach = on_attach,
- capabilities = capabilities,
- filetypes = { "latex", "tex", "bib", "markdown", "gitcommit" },
- on_init = function(client)
- -- Read false positives cache if present
- local cache_path = vim.fn.expand "%:p:h" .. "/.ltex_fp.json"
- print(cache_path)
- local cache = io.open(cache_path, "r")
- if cache then
- local content = cache:read("*a")
- cache:close()
- client.config.settings.ltex.hiddenFalsePositives = vim.fn.json_decode(content)
- end
+}
- -- Set up language if spellang is set
- local langs = vim.opt.spellang:get()
- if #langs > 0 then
- client.config.settings.ltex.language = langs[1]
- else
- client.config.settings.ltex.language = "auto"
- end
- client.notify("workspace/didChangeConfiguration")
- return true
- end,
- handlers = {
- ["workspace/executeCommand"] = ltex_execute_command
- },
- settings = {
- ltex = {
- enabled = { "latex", "tex", "bib", "markdown", },
- language = "auto",
- diagnosticSeverity = "information",
- dictionary = (function()
- local files = {}
- for _, file in ipairs(vim.api.nvim_get_runtime_file("dict/*", true)) do
- local lang = vim.fn.fnamemodify(file, ":t:r")
- local fullpath = vim.fn.fnamemodify(file, ":p")
- files[lang] = {}
- for line in io.lines(fullpath) do
- table.insert(files[lang], line)
- end
- end
+for lname, config in pairs(lsps) do
+ lsp[lname].setup(config)
+end
- if files.default then
- for lang, _ in pairs(files) do
- if lang ~= "default" then
- vim.list_extend(files[lang], files.default)
- end
- end
- files.default = nil
- end
- return files
- end)(),
- checkFrequency = "save",
- sentenceCacheSize = 2000,
- additionalRules = {
- enablePickyRules = true,
- motherTongue = "fr",
- },
- disabledRules = {
- fr = { "APOS_TYP", "FRENCH_WHITESPACE" }
- },
- trace = { server = "verbose" },
- hiddenFalsePositives = {},
+require 'ltex-ls'.setup {
+ on_attach = on_attach,
+ capabilities = capabilities,
+ filetypes = { "latex", "tex", "bib", "markdown", "gitcommit" },
+ settings = {
+ ltex = {
+ enabled = { "latex", "tex", "bib", "markdown", },
+ language = "auto",
+ diagnosticSeverity = "information",
+ checkFrequency = "save",
+ sentenceCacheSize = 2000,
+ additionalRules = {
+ enablePickyRules = true,
+ motherTongue = "fr",
+ },
+ disabledRules = {
+ fr = { "APOS_TYP", "FRENCH_WHITESPACE" }
},
+ trace = { server = "verbose" },
},
},
}
-
-for lname, config in pairs(lsps) do
- lsp[lname].setup(config)
-end
diff --git a/lua/plugins.lua b/lua/plugins.lua
@@ -48,6 +48,7 @@ return packer.startup(function(use)
-- LSP related
use {'neovim/nvim-lspconfig', requires = "williamboman/nvim-lsp-installer"}
+ localuse { 'vigoux/ltex-ls.nvim', requires = 'neovim/nvim-lspconfig'}
-- Treesitter related
localuse 'nvim-treesitter/nvim-treesitter'