optional ltex languagetool secret

This commit is contained in:
Christoph J. Scherr 2024-03-17 09:51:01 -04:00
parent 7a5c8428c9
commit 44bb3db121
3 changed files with 81 additions and 70 deletions

View File

@ -52,12 +52,7 @@ M.ltex = {
"html",
"xhtml",
},
languageToolOrg = {
apiKey = require "custom.secret.languagetool_token",
username = "accounts@cscherr.de",
languageToolHttpServerUrl = "https://api.languagetoolplus.com/v2/",
},
languageToolHttpServerUrl = "https://api.languagetoolplus.com/v2/",
-- load token and additional languagetool items later
},
},
}
@ -170,4 +165,17 @@ M.textlsp = {
},
},
}
-- load secrets
-- the secret module should just return a string with the token
local available, token = require("custom.utils").try_require "custom.secret.languagetool_token"
if available then
M.ltex.languageToolOrg = {
apiKey = token,
username = "accounts@cscherr.de",
languageToolHttpServerUrl = "https://api.languagetoolplus.com/v2/",
}
M.ltex.languageToolHttpServerUrl = "https://api.languagetoolplus.com/v2/"
end
return M

View File

@ -30,38 +30,25 @@ M.treesitter = {
M.mason = {
ensure_installed = {
-- general purpose
"purpose",
-- lua stuff
"lua-language-server",
"stylua",
-- web dev stuff
"css-lsp",
"html-lsp",
"typescript-language-server",
"deno",
"prettier",
-- c/cpp stuff
"clangd",
"clang-format",
"cmake-language-server",
-- rust
"rust-analyzer",
"taplo",
-- python
"pyright",
-- english??
-- "write-good",
-- shell
"shellcheck",
"bash-language-server",
"ltex-ls",
"shellcheck",
"taplo",
},
}

View File

@ -5,44 +5,44 @@ local M = {}
--- @param raw string string of cli args that should be split
--- @return table tokens args as a table
M.tokenize_args = function(raw)
-- NOTE: string.gmatch is does not use regex, but a smaller pattern matcher!
-- A complete regex parser would be larger than lua itself. See
-- [Programming in Lua 20.2](https://www.lua.org/pil/20.2.html).
--
-- Notable differences:
-- '-' is ungreedy wildcard
-- '*?' does not work
-- '|' is not or
--
-- This means we're better of implementing the lexer with an algorithm.
local t = {}
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
if string.len(current) > 0 then
table.insert(t, current)
current = ""
end
elseif c == '"' and not in_str then
in_str = true
str_seek = '"'
elseif c == "'" and not in_str then
in_str = true
str_seek = "'"
elseif c == str_seek and in_str then
in_str = false
table.insert(t, current)
current = ""
else
current = current .. c
end
end
if string.len(current) > 0 then
-- NOTE: string.gmatch is does not use regex, but a smaller pattern matcher!
-- A complete regex parser would be larger than lua itself. See
-- [Programming in Lua 20.2](https://www.lua.org/pil/20.2.html).
--
-- Notable differences:
-- '-' is ungreedy wildcard
-- '*?' does not work
-- '|' is not or
--
-- This means we're better of implementing the lexer with an algorithm.
local t = {}
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
if string.len(current) > 0 then
table.insert(t, current)
current = ""
end
elseif c == '"' and not in_str then
in_str = true
str_seek = '"'
elseif c == "'" and not in_str then
in_str = true
str_seek = "'"
elseif c == str_seek and in_str then
in_str = false
table.insert(t, current)
current = ""
else
current = current .. c
end
return t
end
if string.len(current) > 0 then
table.insert(t, current)
end
return t
end
--- dumps a variable into a string, so it can be printed. This is meant for
@ -50,18 +50,34 @@ end
--- @param t any variable
--- @return string t_dumped t dumped to string
M.dump = function(t)
if type(t) == 'table' then
local s = '{ '
for k, v in pairs(t) do
if type(k) ~= 'number' then k = '"' .. k .. '"' end
if k ~= 1 then
s = s .. ', '
end
s = s .. '[' .. k .. '] = \'' .. M.dump(v) .. '\''
end
return s .. ' }'
else
return tostring(t)
if type(t) == "table" then
local s = "{ "
for k, v in pairs(t) do
if type(k) ~= "number" then
k = '"' .. k .. '"'
end
if k ~= 1 then
s = s .. ", "
end
s = s .. "[" .. k .. "] = '" .. M.dump(v) .. "'"
end
return s .. " }"
else
return tostring(t)
end
end
--- Try to require a module
--- @param module string module name
--- @return boolean available is the module available?
--- @return any loaded_module the loaded module if it is available
M.try_require = function(module)
local available, loaded_module = pcall(require, module)
if not available then
return available, nil
else
return available, loaded_module
end
end
return M