-
-
Notifications
You must be signed in to change notification settings - Fork 148
feat: Add option for json env and allow manipulating env files during the session #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I had started writing a similar script but instead of the
the test script is ignored because the current code is looking for the post processing script in /home/teto/Simple.json while I would rather keep it in the test.http file EDIT: I can get it to work by modifying the get_current_request_function to
i.e., looking for the script_str regardless of the body |
another complaint is that I would like utils.replace_vars to be able to use the variables set via
with
|
Thank you for the feedback. I have updated the pull request so that the script works with external body's. I can't currently recreate your second problem, here is the http file i am using.
Context.set_env sets "new_var" in my Do you have an env file set for context.set_env to write to? Or do you have a http file that i can use for testing? |
For the second issue, I would like utils.replace_vars to take into account the updated "context", rest.nvim/lua/rest-nvim/request/init.lua Line 70 in 3c49a8c
Would you mind rebasing please ? I get errors about "b:current_syntax" that should be fixed on main |
I see, yes I think that is a good idea. Are you happy for me to edit that on this pull request? As it’s actually code that was in use before. |
sure ! |
I have added an optional vars table to replace_vars and in get body moved the read_variables out side the loop for performance reasons. If no vars table is passed it will call read_variables inside replace_vars. |
Just a note to myself, it would be nice to have a command to dump the env seen by rest-nvim. As for this MR, I think I have an issue: I have several |
Yes I do, It is to do with the way I am finding the start script line. I am finding the script_start relative to the header end. Eg. If your headers end on buffer line 40 then the script starts on line 45 the script start line will be 5. I am also looking into an issue when an env_variable has a newline character in. Not sure if this is a general issue or related to this PR. |
just so you know, I am looking forward to merging if not all at least parts of the MR, but I would like to make it possible to add some tests first, with this #159 being the first part of the plan |
No problem, thats a great idea, I am happy add tests once 159 is merged in. I am also happy to help with any other part. I will continue to update this branch as it is the branch i personally use daily. Unfortunately I had to add a json_encode to line 88 of request/init.lua as nested json bodies were not sending properly. I realise this is out of the scope of this PR. |
can you :
@NTBBloodbath is https://github.com/rest-nvim/tree-sitter-http supposed to be some pure http stuff or could we add support to catch the script |
We can add support to it in the parser as it already covers some rest.nvim specific features. I'll probably make a pure http parser later in another branch of the parser repo too. |
will do, it might take a few days as I am away at the moment |
Seems like this was not rebased correctly ? I've just tested it and found an issue when there are multiple queries with no payload, rest-nvim uses the query delimiter |
hmm interesting, I am not seeing any conflicts on github's sync branch. There have been a lot of updates to this pull request since it's inception as main has changed a lot, does a merge --squash have conflicts? I also noticed the "---" bug when testing, but as you say I didn't want to adjust the tests that i hadn't written. |
well I can't do anything from the github UI, and anyway there are 19 commits in the MR which is a bit much. Can you try a git fetch --all && git rebase -i origin/main ? |
0f7b39d
to
8c1d031
Compare
|
ahh yeah, sorry, that was a left over from the rebase |
feat: running a response script to set env
8c1d031
to
b83ea48
Compare
so I did not notice before but this rewrites the .env file ? that's kind of annoying for my usecase since it records errors in my carefully handcrafted .env. Is there a way to disable that behavior ? |
Yes currently the set_env function takes what was previously in the env file, updates the one you are setting then writes it back to the file. There are currently no session env variables to add to, each request reads the env file separately which is why updating the variables there seamed useful, also this is the way I do it when using postman. As for your issue, what do you think about introducing something like a "session_env" where you could call "set_session_var" this could save the variable to the users config/in-memory table? |
Maybe just dont call Drawback is you lose the automatic update of the env. Other options could be:
NB: I've been playing with treesitter it's very promising and should make the plugin much robust than what we have right now ! |
Okay, I understand. The problem right now is that without Also do you mind sharing the shape of the env that was overridden as I think that sounds like an unintended bug which should be fixed. The Great news about treesitter. |
This addresses #110 as well as allowing the env files to be updated using a lua script inside {% script %} tags, similar to the intellij rest client. The lua code in the script tag will is passed a context table which includes the response, json_decode and a function to write/set environment variables. This is mostly useful for myself when I am working with authenticated apis.
example:
Environment files can also easily be swapped using the :RestSelectEnv command meaning you can have a .env.staging and a .env.production or a staging.env.json and a production.env.json.