mirror of
https://github.com/tiyn/dotfiles.git
synced 2026-05-09 14:01:35 +02:00
Nvim: Made Molten more robust
This commit is contained in:
@@ -22,13 +22,24 @@ return {
|
||||
vim.schedule(function()
|
||||
local kernels = vim.fn.MoltenAvailableKernels()
|
||||
local try_kernel_name = function()
|
||||
local metadata = vim.json.decode(io.open(e.file, "r"):read("a"))["metadata"]
|
||||
return metadata.kernelspec.name
|
||||
local f = io.open(e.file, "r")
|
||||
if not f then
|
||||
return nil
|
||||
end
|
||||
local content = f:read("*a")
|
||||
f:close()
|
||||
local ok, decoded = pcall(vim.json.decode, content)
|
||||
if not ok then
|
||||
return nil
|
||||
end
|
||||
return decoded.metadata
|
||||
and decoded.metadata.kernelspec
|
||||
and decoded.metadata.kernelspec.name
|
||||
end
|
||||
local ok, kernel_name = pcall(try_kernel_name)
|
||||
if not ok or not vim.tbl_contains(kernels, kernel_name) then
|
||||
kernel_name = nil
|
||||
local venv = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX")
|
||||
local venv = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") or ".venv"
|
||||
if venv ~= nil then
|
||||
kernel_name = string.match(venv, "/.+/(.+)")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user