Skip to content

Commit ec8cbb2

Browse files
fix: add logs & limits to dotenv module (#456)
1 parent b4353fb commit ec8cbb2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lua/rest-nvim/dotenv.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local M = {}
44

55
local dotenv_parser = require("rest-nvim.parser.dotenv")
66
local config = require("rest-nvim.config")
7+
local logger = require("rest-nvim.logger")
78

89
---load dotenv file
910
---This function will set environment variables in current editor session.
@@ -85,11 +86,20 @@ function M.find_relevent_env_file()
8586
---@type string?
8687
local env_file
8788
-- search for `/same/path/filename.env`
88-
env_file = vim.fs.find(filename .. ".env", { type = "file" })[1]
89+
logger.debug("searching for " .. filename .. ".env file")
90+
env_file = vim.fs.find(filename .. ".env", {
91+
path = vim.fn.expand("%:h"),
92+
upward = true,
93+
stop = vim.fn.getcwd(),
94+
type = "file",
95+
limit = math.huge,
96+
})[1]
8997
if env_file then
98+
logger.debug("found .env file:", env_file)
9099
return env_file
91100
end
92101
-- search upward for `.env` file
102+
logger.debug("searching for .env file")
93103
env_file = vim.fs.find(function(name, _)
94104
return name == ".env"
95105
end, {
@@ -100,7 +110,10 @@ function M.find_relevent_env_file()
100110
limit = math.huge,
101111
})[1]
102112
if env_file then
113+
logger.debug("found .env file:", env_file)
103114
return env_file
115+
else
116+
logger.debug("no .env file found")
104117
end
105118
end
106119

0 commit comments

Comments
 (0)