From 0f46dcad2851e2986550ef444e55faef4335a7c1 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 17 Jun 2024 15:28:09 +0200 Subject: [PATCH] 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. --- nvim/.config/nvim/lua/plugins/ui.lua | 37 +++++++++++++++++++--------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/ui.lua b/nvim/.config/nvim/lua/plugins/ui.lua index 7026909..73c1a4c 100644 --- a/nvim/.config/nvim/lua/plugins/ui.lua +++ b/nvim/.config/nvim/lua/plugins/ui.lua @@ -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" }, },