mistweaverco/kulala.nvim

Environment variables will not load correctly

Closed this issue · 1 comments

Let's assume you have a simple structure like this:

C:\temp\k
|
+---p1
|    |-- http-client.env.json
|    \-- p1.http
|
\---p2
    |-- http-client.env.json
    \-- p2.http

and you open nvim from a different dir.

When starting nvim require('kulala').setup() is called which itselfs requires env.lua (and calls load_envs).
While loading env.lua the file based vars are calculated once

local FS = require("kulala.utils.fs")
local GLOBAL_STORE = require("kulala.global_store")
local DYNAMIC_VARS = require("kulala.parser.dynamic_vars")
local DB = require("kulala.db")

local M = {}

local http_client_env_json = FS.find_file_in_parent_dirs("http-client.env.json")
local dotenv = FS.find_file_in_parent_dirs(".env")

M.get_env = function()
  local env = {}
  for key, value in pairs(vim.fn.environ()) do
    env[key] = value

that means http_client_env_json is fixed to the file found (or not in case opening vim from a different dir).
If called from "p1" dir it is set to that env file.

When loading another buffer and running a kulala with env variables used, they will be parsed and get_env is called.
But here http_client_env_json is been used which still stays on the content calculated at the startup.

Maybe the filepath where the variables are once calculated must be stored, too, and when differs in get_env they need to be calculated again.

This is indeed a bug, it should load the http-client.env.json next to the *.http file.

And on switching buffers, it might reload that file, you're totally right!