besser wirds licht denk ich

This commit is contained in:
cscherr 2025-06-23 17:25:07 +02:00
parent 505dd0dda0
commit 9388a41ff1
Signed by: cscherrNT
GPG key ID: 8E2B45BC51A27EA7
2 changed files with 25 additions and 19 deletions

View file

@ -27,6 +27,10 @@ local ltex_fts = {
'rst', 'rst',
} }
local map = function(keys, func, desc)
vim.keymap.set('n', keys, func, { buffer = vim.buf, desc = 'LSP[LTEX]: ' .. desc })
end
LTEX_SETTINGS = { LTEX_SETTINGS = {
capabilities = CAPABILITIES, capabilities = CAPABILITIES,
on_attach = function(client, bufnr) on_attach = function(client, bufnr)
@ -59,31 +63,34 @@ LTEX_SETTINGS = {
} }
-- load token and additional languagetool items later if specified -- 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' local has_api_key, apiKey = utils.try_require 'custom.secret.languagetool'
if has_api_key and apiKey ~= '' then if not do_not_use_api_key and has_api_key and apiKey ~= '' then
print(string.format('apiKey for ltex found: %s' % apiKey))
LTEX_SETTINGS = vim.tbl_deep_extend('keep', LTEX_SETTINGS, { LTEX_SETTINGS = vim.tbl_deep_extend('keep', LTEX_SETTINGS, {
settings = { settings = {
languageToolOrg = { languageToolOrg = {
apiKey = apiKey, apiKey = apiKey,
username = 'accounts@cscherr.de', username = 'accounts@cscherr.de',
languageToolHttpServerUrl = 'https://api.languagetoolplus.com/v2/',
}, },
languageToolHttpServerUrl = 'https://api.languagetoolplus.com/v2/', languageToolHttpServerUrl = 'https://api.languagetoolplus.com/',
}, },
}) })
else 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 end
return { return {
'barreiroleo/ltex_extra.nvim', 'barreiroleo/ltex_extra.nvim',
ft = { 'markdown', 'tex' }, ft = ltex_fts,
dependencies = { 'neovim/nvim-lspconfig' }, dependencies = { 'neovim/nvim-lspconfig' },
-- yes, you can use the opts field, just I'm showing the setup explicitly
config = function() config = function()
require('ltex_extra').setup { require('ltex_extra').setup {
server_opts = LTEX_SETTINGS, server_opts = LTEX_SETTINGS,
} }
map('<leader>tS', function()
vim.cmd 'LspStart ltex'
end, 'Enable spell checking with languagetool')
end, end,
} }

View file

@ -16,14 +16,14 @@ M.tokenize_args = function(raw)
-- --
-- This means we're better of implementing the lexer with an algorithm. -- This means we're better of implementing the lexer with an algorithm.
local t = {} local t = {}
local current = "" local current = ''
local in_str = false local in_str = false
local str_seek local str_seek
for c in string.gmatch(raw, ".") do -- iterate through all chars for c in string.gmatch(raw, '.') do -- iterate through all chars
if c == " " and not in_str then if c == ' ' and not in_str then
if string.len(current) > 0 then if string.len(current) > 0 then
table.insert(t, current) table.insert(t, current)
current = "" current = ''
end end
elseif c == '"' and not in_str then elseif c == '"' and not in_str then
in_str = true in_str = true
@ -34,7 +34,7 @@ M.tokenize_args = function(raw)
elseif c == str_seek and in_str then elseif c == str_seek and in_str then
in_str = false in_str = false
table.insert(t, current) table.insert(t, current)
current = "" current = ''
else else
current = current .. c current = current .. c
end end
@ -50,18 +50,18 @@ end
--- @param t any variable --- @param t any variable
--- @return string t_dumped t dumped to string --- @return string t_dumped t dumped to string
M.dump = function(t) M.dump = function(t)
if type(t) == "table" then if type(t) == 'table' then
local s = "{ " local s = '{ '
for k, v in pairs(t) do for k, v in pairs(t) do
if type(k) ~= "number" then if type(k) ~= 'number' then
k = '"' .. k .. '"' k = '"' .. k .. '"'
end end
if k ~= 1 then if k ~= 1 then
s = s .. ", " s = s .. ', '
end end
s = s .. "[" .. k .. "] = '" .. M.dump(v) .. "'" s = s .. '[' .. k .. "] = '" .. M.dump(v) .. "'\n"
end end
return s .. " }" return s .. ' }'
else else
return tostring(t) return tostring(t)
end end
@ -81,4 +81,3 @@ M.try_require = function(module)
end end
return M return M