From 9388a41ff1cbdc8873f92431a53663d8793fa129 Mon Sep 17 00:00:00 2001 From: cscherr Date: Mon, 23 Jun 2025 17:25:07 +0200 Subject: [PATCH] besser wirds licht denk ich --- lua/custom/plugins/ltex.lua | 21 ++++++++++++++------- lua/custom/utils.lua | 23 +++++++++++------------ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lua/custom/plugins/ltex.lua b/lua/custom/plugins/ltex.lua index a2574fd..6fc10d9 100644 --- a/lua/custom/plugins/ltex.lua +++ b/lua/custom/plugins/ltex.lua @@ -27,6 +27,10 @@ local ltex_fts = { 'rst', } +local map = function(keys, func, desc) + vim.keymap.set('n', keys, func, { buffer = vim.buf, desc = 'LSP[LTEX]: ' .. desc }) +end + LTEX_SETTINGS = { capabilities = CAPABILITIES, on_attach = function(client, bufnr) @@ -59,31 +63,34 @@ LTEX_SETTINGS = { } -- load token and additional languagetool items later if specified +local do_not_use_api_key = true local has_api_key, apiKey = utils.try_require 'custom.secret.languagetool' -if has_api_key and apiKey ~= '' then - print(string.format('apiKey for ltex found: %s' % apiKey)) +if not do_not_use_api_key and has_api_key and apiKey ~= '' then LTEX_SETTINGS = vim.tbl_deep_extend('keep', LTEX_SETTINGS, { settings = { languageToolOrg = { apiKey = apiKey, username = 'accounts@cscherr.de', - languageToolHttpServerUrl = 'https://api.languagetoolplus.com/v2/', }, - languageToolHttpServerUrl = 'https://api.languagetoolplus.com/v2/', + languageToolHttpServerUrl = 'https://api.languagetoolplus.com/', }, }) else - print 'apiKey for ltex/languagetool is not specified' + if not do_not_use_api_key then + print 'apiKey for ltex/languagetool is not specified' + end end return { 'barreiroleo/ltex_extra.nvim', - ft = { 'markdown', 'tex' }, + ft = ltex_fts, dependencies = { 'neovim/nvim-lspconfig' }, - -- yes, you can use the opts field, just I'm showing the setup explicitly config = function() require('ltex_extra').setup { server_opts = LTEX_SETTINGS, } + map('tS', function() + vim.cmd 'LspStart ltex' + end, 'Enable spell checking with languagetool') end, } diff --git a/lua/custom/utils.lua b/lua/custom/utils.lua index d9edb54..545dcf1 100644 --- a/lua/custom/utils.lua +++ b/lua/custom/utils.lua @@ -16,14 +16,14 @@ M.tokenize_args = function(raw) -- -- This means we're better of implementing the lexer with an algorithm. local t = {} - local current = "" + local current = '' local in_str = false local str_seek - for c in string.gmatch(raw, ".") do -- iterate through all chars - if c == " " and not in_str then + for c in string.gmatch(raw, '.') do -- iterate through all chars + if c == ' ' and not in_str then if string.len(current) > 0 then table.insert(t, current) - current = "" + current = '' end elseif c == '"' and not in_str then in_str = true @@ -34,7 +34,7 @@ M.tokenize_args = function(raw) elseif c == str_seek and in_str then in_str = false table.insert(t, current) - current = "" + current = '' else current = current .. c end @@ -50,18 +50,18 @@ end --- @param t any variable --- @return string t_dumped t dumped to string M.dump = function(t) - if type(t) == "table" then - local s = "{ " + if type(t) == 'table' then + local s = '{ ' for k, v in pairs(t) do - if type(k) ~= "number" then + if type(k) ~= 'number' then k = '"' .. k .. '"' end if k ~= 1 then - s = s .. ", " + s = s .. ', ' end - s = s .. "[" .. k .. "] = '" .. M.dump(v) .. "'" + s = s .. '[' .. k .. "] = '" .. M.dump(v) .. "'\n" end - return s .. " }" + return s .. ' }' else return tostring(t) end @@ -81,4 +81,3 @@ M.try_require = function(module) end return M -