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", "html",
"xhtml", "xhtml",
}, },
languageToolOrg = { -- load token and additional languagetool items later
apiKey = require "custom.secret.languagetool_token",
username = "accounts@cscherr.de",
languageToolHttpServerUrl = "https://api.languagetoolplus.com/v2/",
},
languageToolHttpServerUrl = "https://api.languagetoolplus.com/v2/",
}, },
}, },
} }
@ -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 return M

View File

@ -30,38 +30,25 @@ M.treesitter = {
M.mason = { M.mason = {
ensure_installed = { ensure_installed = {
-- general purpose
"purpose", "purpose",
-- lua stuff
"lua-language-server", "lua-language-server",
"stylua", "stylua",
-- web dev stuff
"css-lsp", "css-lsp",
"html-lsp", "html-lsp",
"typescript-language-server", "typescript-language-server",
"deno", "deno",
"prettier", "prettier",
-- c/cpp stuff
"clangd", "clangd",
"clang-format", "clang-format",
"cmake-language-server", "cmake-language-server",
-- rust
"rust-analyzer", "rust-analyzer",
"taplo", "taplo",
-- python
"pyright", "pyright",
-- english??
-- "write-good",
-- shell
"shellcheck", "shellcheck",
"bash-language-server", "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 --- @param raw string string of cli args that should be split
--- @return table tokens args as a table --- @return table tokens args as a table
M.tokenize_args = function(raw) M.tokenize_args = function(raw)
-- NOTE: string.gmatch is does not use regex, but a smaller pattern matcher! -- NOTE: string.gmatch is does not use regex, but a smaller pattern matcher!
-- A complete regex parser would be larger than lua itself. See -- A complete regex parser would be larger than lua itself. See
-- [Programming in Lua 20.2](https://www.lua.org/pil/20.2.html). -- [Programming in Lua 20.2](https://www.lua.org/pil/20.2.html).
-- --
-- Notable differences: -- Notable differences:
-- '-' is ungreedy wildcard -- '-' is ungreedy wildcard
-- '*?' does not work -- '*?' does not work
-- '|' is not or -- '|' is not or
-- --
-- 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)
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
table.insert(t, current) 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
return t end
if string.len(current) > 0 then
table.insert(t, current)
end
return t
end end
--- dumps a variable into a string, so it can be printed. This is meant for --- dumps a variable into a string, so it can be printed. This is meant for
@ -50,18 +50,34 @@ 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 k = '"' .. k .. '"' end if type(k) ~= "number" then
if k ~= 1 then k = '"' .. k .. '"'
s = s .. ', ' end
end if k ~= 1 then
s = s .. '[' .. k .. '] = \'' .. M.dump(v) .. '\'' s = s .. ", "
end end
return s .. ' }' s = s .. "[" .. k .. "] = '" .. M.dump(v) .. "'"
else
return tostring(t)
end end
return s .. " }"
else
return tostring(t)
end
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 return M