nvim: Simplify molten statusline function

Instead of doing all kinds of security checks beforehand, we simply wrap
the molten kernel check into a lua protected call and return an empty
result if we would error. We only return the symbol if we don't error
and we have an active kernel.
This commit is contained in:
Marty Oehme 2024-08-12 11:27:31 +02:00
parent 38bdf74954
commit be842ce622
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -8,26 +8,28 @@ return {
-- if molten exists, is initialized and connected to a kernel -- if molten exists, is initialized and connected to a kernel
-- show it in the statusline -- show it in the statusline
local function molten() local function molten()
local function checked_pynvim(_, exitcode) -- we don't have access to python, disregard element
if exitcode == 0 then
has_pynvim = 1
else
has_pynvim = 0
end
end
if has_pynvim == 0 then if has_pynvim == 0 then
return "" return ""
elseif has_pynvim == -1 then elseif has_pynvim == 1 then
vim.fn.jobstart({ "python", "-c", "from neovim import VERSION" }, { on_exit = checked_pynvim }) local status_ok, res = pcall(function()
return require("molten.status").kernels() ~= ""
end)
if status_ok and res then
return "󱪄"
end
return ""
-- we don't know if we have python yet, start a check
else
vim.system({ "poetry", "env", "info", "-p" }, { text = true }, function(_, exitcode)
if exitcode == 0 then
has_pynvim = 1
else
has_pynvim = 0
end
end)
has_pynvim = 0
end end
if
has_pynvim == 1
and require("core.util").is_available("molten.status")
and require("molten.status").kernels() ~= ""
then
return "󱪄"
end
return ""
end end
-- count number of selected lines and characters -- count number of selected lines and characters