@@ -4,6 +4,7 @@ local random = math.random
44math.randomseed (os.time ())
55
66local M = {}
7+ local contexts = {}
78
89M .binary_content_types = {
910 " octet-stream" ,
@@ -30,6 +31,16 @@ M.set_env = function(key, value)
3031 M .write_env_file (variables )
3132end
3233
34+ -- set_context sets a context variable for the current file
35+ -- @param key The key to set
36+ -- @param value The value to set
37+ M .set_context = function (key , value )
38+ local env_file = " /" .. (config .get (" env_file" ) or " .env" )
39+ local context = contexts [env_file ] or {}
40+ context [key ] = value
41+ contexts [env_file ] = context
42+ end
43+
3344M .write_env_file = function (variables )
3445 local env_file = " /" .. (config .get (" env_file" ) or " .env" )
3546
@@ -142,6 +153,11 @@ M.get_env_variables = function()
142153 return variables
143154end
144155
156+ M .get_context_variables = function ()
157+ local env_file = " /" .. (config .get (" env_file" ) or " .env" )
158+ return contexts [env_file ] or {}
159+ end
160+
145161-- get_variables Reads the environment variables found in the env_file option
146162-- (default: .env) specified in configuration or from the files being read
147163-- with variables beginning with @ and returns a table with the variables
@@ -229,10 +245,11 @@ end
229245
230246M .read_variables = function ()
231247 local first = M .get_variables ()
232- local second = M .read_dynamic_variables ()
233- local third = M .read_document_variables ()
248+ local second = M .get_context_variables ()
249+ local third = M .read_dynamic_variables ()
250+ local fourth = M .read_document_variables ()
234251
235- return vim .tbl_extend (" force" , first , second , third )
252+ return vim .tbl_extend (" force" , first , second , third , fourth )
236253end
237254
238255-- replace_vars replaces the env variables fields in the provided string
0 commit comments