Feature/variable management
This pull request satisfies #180.
It adds two ways of dealing with variables from within the script tag.
- Global environment variables
Same syntax as before, however, with the option to persist the data to the currently selected Env file. If persist is false (the default) then the variable is available until the editor is closed. If persist is true then the variable is updated/written to the env file, this logic is the same as the current logic.
{%
local body = context.json_decode(context.result.body)
-- written to file
context.set_env("postTitle", context.json_encode(body.title), { persist=true })
-- saved in session memory
context.set_env("userId", body.userId)
%}
- Buffer variables
Buffer variables are only available in the current buffer, and implemented using
vim.api.nvim_buf_get_var
{%
local body = context.json_decode(context.result.body)
context.set_buffer_variable("postId", body.id)
%}
you should have pinged me I just see it. will have a look later
you've updated the tests and all, that's great.
I also wonder if instead of having dedicated functions like context.set_buffer_variable( we shouldn't have several contexts:
bcontext (buffer) and gcontext (global) so that both can have the same interface aka bcontext.set_variable and gcontext.set_variable (gcontext could be just context, also it's a bit verbose so we could even shorten it to ctx maybe).
Another possibility would be to use context.set_variable(..., { buffer = true}) but it is more verbose.
What do you think ?
Another possibility would be to use
context.set_variable(..., { buffer = true})but it is more verbose.
I personally prefer this as I think it's easier to understand what it does. It also looks like many other neovim functions in use. The only thing that might bit confusing is the writing to env file. If set_env is combined with set_variable then buffer = true wouldn't do anything if a set_env = true flag is set because set_env would always be global. Here's what I am thinking in code:
-- Sets a variable for the current buffer only.
context.set_variable("key", value.item, { buffer = true})
-- Sets a global runtime variable.
context.set_variable("key", value.item, { buffer = false})
-- Writes to the currently selected env file. Here the "buffer" flag does nothing.
context.set_variable("key", value.item, { buffer = false, set_env_file = true})
Closing this due to v3 release. rest.nvim will follow the api of intellij’s http client.
Now rest.nvim provides three types of variables:
- environment variables (variables from your current shell session)
- in-place variables (variables defined in file with @name=value syntax)
- client/request variables (variables defined from request/response handler scripts)