File tree Expand file tree Collapse file tree 9 files changed +66
-0
lines changed
Expand file tree Collapse file tree 9 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 11vim .bo .commentstring = " # %s"
22vim .wo .conceallevel = 0
33
4+ local dotenv = require (" rest-nvim.dotenv" )
5+
46vim .b ._rest_nvim_count = 1
7+ vim .b ._rest_nvim_env_file = dotenv .find_relevent_env_file ()
Original file line number Diff line number Diff line change @@ -71,6 +71,35 @@ function M.find_env_files()
7171 return files
7272end
7373
74+ --- @return string ? dotenv file
75+ function M .find_relevent_env_file ()
76+ local filename = vim .fn .expand (" %:t:r" )
77+ if filename == " " then
78+ return nil
79+ end
80+ filename = filename :gsub (" %.http$" , " " )
81+ --- @type string ?
82+ local env_file
83+ -- search for `/same/path/filename.env`
84+ env_file = vim .fs .find (filename .. " .env" , { type = " file" })[1 ]
85+ if env_file then
86+ return env_file
87+ end
88+ -- search upward for `.env` file
89+ env_file = vim .fs .find (function (name , _ )
90+ return name == " .env"
91+ end , {
92+ path = vim .fn .expand (" %:h" ),
93+ upward = true ,
94+ stop = vim .fn .getcwd (),
95+ type = " file" ,
96+ limit = math.huge ,
97+ })[1 ]
98+ if env_file then
99+ return env_file
100+ end
101+ end
102+
74103--- @param bufnr number ? buffer identifier , default to current buffer
75104--- @return string ? path
76105function M .select_file (bufnr )
Original file line number Diff line number Diff line change 1+ --- @module ' luassert'
2+
3+ require (" spec.minimum_init" )
4+
5+ local dotenv = require (" rest-nvim.dotenv" )
6+
7+ local function open (path )
8+ vim .cmd .edit (path )
9+ vim .cmd .source (" ftplugin/http.lua" )
10+ return 0
11+ end
12+
13+ local function remove_cwd (path )
14+ path = path :gsub (vim .pesc (vim .fn .getcwd ()) .. " /" , " " )
15+ return path
16+ end
17+
18+ describe (" dotenv" , function ()
19+ it (" find dotenv file with same name to http file" , function ()
20+ open (" spec/examples/dotenv/with_dotenv.http" )
21+ assert .same (
22+ " spec/examples/dotenv/with_dotenv.env" ,
23+ remove_cwd (vim .b ._rest_nvim_env_file )
24+ )
25+ end )
26+ it (" find dotenv file in parent dir" , function ()
27+ open (" spec/examples/dotenv/without_dotenv.http" )
28+ assert .same (
29+ " spec/examples/.env" ,
30+ remove_cwd (vim .b ._rest_nvim_env_file )
31+ )
32+ end )
33+ end )
Original file line number Diff line number Diff line change 1+ # dotenv file for `example/dotenv/without_dotenv.http` example
You can’t perform that action at this time.
0 commit comments