-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Stocker
authored and
Jan Stocker
committed
Sep 6, 2024
1 parent
f5b0a69
commit 32d4e53
Showing
11 changed files
with
113 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,57 @@ | ||
local CONFIG = require("kulala.config") | ||
|
||
local M = {} | ||
|
||
M.data = { | ||
selected_env = nil, -- string - name of selected env | ||
http_client_env = nil, -- table of envs from http-client.env.json | ||
http_client_env_base = nil, -- table of base env values which should be applied to all requests | ||
env = {}, -- table of envs from document sources | ||
} | ||
M.data = nil | ||
|
||
local function default_data() | ||
return { | ||
selected_env = nil, -- string - name of selected env | ||
http_client_env = nil, -- table of envs from http-client.env.json | ||
http_client_env_base = nil, -- table of base env values which should be applied to all requests | ||
env = {}, -- table of envs from document sources | ||
scope_nr = nil, -- number - buffer number of the current scope | ||
} | ||
end | ||
|
||
local function get_current_scope_nr() | ||
if CONFIG.get().environment_scope == "b" then | ||
return vim.fn.bufnr() | ||
elseif CONFIG.get().environment_scope == "g" then | ||
return 0 | ||
end | ||
end | ||
|
||
local function load_data() | ||
if CONFIG.get().environment_scope == "b" then | ||
M.data = vim.b.kulala_data or default_data() | ||
elseif CONFIG.get().environment_scope == "g" then | ||
-- keep in lua only | ||
if not M.data then | ||
M.data = default_data() | ||
end | ||
end | ||
M.data.scope_nr = get_current_scope_nr() | ||
end | ||
|
||
local function save_data() | ||
if CONFIG.get().environment_scope == "b" then | ||
if vim.fn.bufexists(M.data.scope_nr) ~= -1 then | ||
vim.b[M.data.scope_nr].kulala_data = M.data | ||
end | ||
elseif CONFIG.get().environment_scope == "g" then | ||
-- keep in lua only | ||
end | ||
end | ||
|
||
M.get = function() | ||
if not M.data or not M.data.scope_nr then | ||
load_data() | ||
elseif M.data.scope_nr ~= get_current_scope_nr() then | ||
save_data() | ||
load_data() | ||
end | ||
return M.data | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters