Skip to content

Commit

Permalink
fix: add logs & limits to dotenv module (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
boltlessengineer committed Sep 12, 2024
1 parent b4353fb commit ec8cbb2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lua/rest-nvim/dotenv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local M = {}

local dotenv_parser = require("rest-nvim.parser.dotenv")
local config = require("rest-nvim.config")
local logger = require("rest-nvim.logger")

---load dotenv file
---This function will set environment variables in current editor session.
Expand Down Expand Up @@ -85,11 +86,20 @@ function M.find_relevent_env_file()
---@type string?
local env_file
-- search for `/same/path/filename.env`
env_file = vim.fs.find(filename .. ".env", { type = "file" })[1]
logger.debug("searching for " .. filename .. ".env file")
env_file = vim.fs.find(filename .. ".env", {
path = vim.fn.expand("%:h"),
upward = true,
stop = vim.fn.getcwd(),
type = "file",
limit = math.huge,
})[1]
if env_file then
logger.debug("found .env file:", env_file)
return env_file
end
-- search upward for `.env` file
logger.debug("searching for .env file")
env_file = vim.fs.find(function(name, _)
return name == ".env"
end, {
Expand All @@ -100,7 +110,10 @@ function M.find_relevent_env_file()
limit = math.huge,
})[1]
if env_file then
logger.debug("found .env file:", env_file)
return env_file
else
logger.debug("no .env file found")
end
end

Expand Down

0 comments on commit ec8cbb2

Please sign in to comment.