nvim: Fix molten statusline icon

Fixed issue when pynvim did not exist in the environment but we tried to
invoke a molten-nvim command. Now we first fire up python to check for
pynvim existence. This takes a moment so we do it asynchronously and
cache the result for the rest of the program runtime.

Also we only show the molten icon if we are actually connected to a
running kernel.
This commit is contained in:
Marty Oehme 2024-06-17 15:28:09 +02:00
parent 2d513ad74b
commit 0f46dcad28
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -4,16 +4,31 @@ return {
"nvim-lualine/lualine.nvim",
dependencies = { { "nvim-tree/nvim-web-devicons", config = true } },
config = function()
-- FIXME: Errors out on no pynvim installed
-- local function molten()
-- if
-- require("core.util").is_available("molten.status")
-- and require("molten.status").initialized() ~= ""
-- then
-- return "󱪄"
-- end
-- return ""
-- end
local has_pynvim = -1
-- if molten exists, is initialized and connected to a kernel
-- show it in the statusline
local function molten()
local function checked_pynvim(_, exitcode)
if exitcode == 0 then
has_pynvim = 1
else
has_pynvim = 0
end
end
if has_pynvim == 0 then
return ""
elseif has_pynvim == -1 then
vim.fn.jobstart({ "python", "-c", "from neovim import VERSION" }, { on_exit = checked_pynvim })
end
if
has_pynvim == 1
and require("core.util").is_available("molten.status")
and require("molten.status").kernels() ~= ""
then
return "󱪄"
end
return ""
end
require("lualine").setup({
options = {
icons_enabled = true,
@ -27,7 +42,7 @@ return {
lualine_a = { "mode" },
lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = { "filename" },
lualine_x = { "encoding", "fileformat", "filetype", "molten" },
lualine_x = { "encoding", "fileformat", "filetype", molten },
lualine_y = { "progress" },
lualine_z = { "location" },
},