From b9cf3aadef6bfbe35a61c54ed60c1ad2c726b9d4 Mon Sep 17 00:00:00 2001 From: Oliver Hartmann Date: Mon, 30 Jan 2023 21:27:17 +0100 Subject: [PATCH] check for pyrightconfig.json in dap --- lua/plugins/dap.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lua/plugins/dap.lua b/lua/plugins/dap.lua index 6e85027..16c7747 100644 --- a/lua/plugins/dap.lua +++ b/lua/plugins/dap.lua @@ -98,6 +98,25 @@ return { end end + local function getVenvFromJson(jsonfile) + if not vim.fn.filereadable(jsonfile) then + return nil + end + local f = io.open(jsonfile, 'r') + if not f then + return nil + end + local data = f:read('*a') + f:close() + if data then + local jdata = vim.json.decode(data) + if jdata['venvPath'] ~= nil and jdata['venv'] ~= nil then + return jdata['venvPath'] .. '/' .. jdata['venv'] + end + end + return nil + end + local function getPythonEnv() local venv = os.getenv('VIRTUAL_ENV') if venv ~= nil then @@ -109,6 +128,12 @@ return { end local cwd = vim.fn.getcwd() + + local jsonVenv = getVenvFromJson(cwd .. '/pyrightconfig.json') + if jsonVenv ~= nil then + return jsonVenv + end + if vim.fn.executable(cwd .. '/venv/' .. getVenvSuffix()) == 1 then return cwd .. '/venv/' .. getVenvSuffix() elseif vim.fn.executable(cwd .. '/.venv/' .. getVenvSuffix()) == 1 then